From 3f24e2cc5bfc9fac7c1cfd6ab0dc9b0880e879ea Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Date: Mon, 19 May 2014 11:00:47 +0200
Subject: [PATCH] androiddeployqt: Add option to reinstall apk

Mainly for consistency with the old deployment method in Qt Creator,
androiddeployqt will uninstall any previously installed instances
of the application before installing it. This will remove any caches
or user data stored by the application. In many cases (most) it
would be more convenient to just overwrite the existing instance,
but keep all caches intact. This patch adds the --reinstall option,
symmetrical to --install. If enabled, the uninstall step will be
skipped.

[ChangeLog][androiddeployqt] Added option to install an APK without
uninstalling previous instances of same application.

Task-number: QTBUG-35845
Change-Id: I93bed4fefda6ed5295f333002a4958654b3f911c
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
---
 src/androiddeployqt/main.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/androiddeployqt/main.cpp b/src/androiddeployqt/main.cpp
index cfb4617df..f81f77e37 100644
--- a/src/androiddeployqt/main.cpp
+++ b/src/androiddeployqt/main.cpp
@@ -90,6 +90,7 @@ struct Options
         , sectionsOnly(false)
         , protectedAuthenticationPath(false)
         , installApk(false)
+        , uninstallApk(false)
         , fetchedRemoteModificationDates(false)
     {}
 
@@ -159,6 +160,7 @@ struct Options
 
     // Installation information
     bool installApk;
+    bool uninstallApk;
     QString installLocation;
 
     // Collected information
@@ -266,6 +268,10 @@ Options parseOptions()
                 options.inputFileName = arguments.at(++i);
         } else if (argument.compare(QLatin1String("--install"), Qt::CaseInsensitive) == 0) {
             options.installApk = true;
+            options.uninstallApk = true;
+        } else if (argument.compare(QLatin1String("--reinstall"), Qt::CaseInsensitive) == 0) {
+            options.installApk = true;
+            options.uninstallApk = false;
         } else if (argument.compare(QLatin1String("--android-platform"), Qt::CaseInsensitive) == 0) {
             if (i + 1 == arguments.size())
                 options.helpRequested = true;
@@ -402,7 +408,12 @@ void printHelp()
                     "       ministro: Use the Ministro service to manage Qt files.\n"
                     "       debug: Copy Qt files to device for quick debugging.\n"
                     "    --install: Installs apk to device/emulator. By default this step is\n"
-                    "       not taken.\n"
+                    "       not taken. If the application has previously been installed on\n"
+                    "       the device, it will be uninstalled first.\n"
+                    "    --reinstall: Installs apk to device/emulator. By default this step\n"
+                    "       is not taken. If the application has previously been installed on\n"
+                    "       the device, it will be overwritten, but its data will be left\n"
+                    "       intact.\n"
                     "    --device [device ID]: Use specified device for deployment. Default\n"
                     "       is the device selected by default by adb.\n"
                     "    --android-platform <platform>: Builds against the given android\n"
@@ -1896,7 +1907,8 @@ QString apkName(const Options &options)
 bool installApk(const Options &options)
 {
     // Uninstall if necessary
-    uninstallApk(options);
+    if (options.uninstallApk)
+        uninstallApk(options);
 
     if (options.verbose)
         fprintf(stdout, "Installing Android package to device.\n");
-- 
GitLab