aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-07-30 20:39:46 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-08-04 09:03:55 +0000
commit73d4fc94dff31477e7882286784001956b170863 (patch)
treeca3b470398ed02563d5704d1c9583836c1d489e1 /src/main/java/com/google/devtools
parentd0d29795787a12a1594dcb1581bc2d2448d9a7d9 (diff)
Add "warm" starting to mobile-install.
This introduces a new way to stop applications when deploying incremental changes that saves the current app state for the next run. This allows things like the back stack, and View/Fragment/Activity saved state to be restored when the app next launches, making it easier to quickly iterate on code changes. It adds a "--start" flag to mobile-install that replaces "--start_app". --start accepts an argument describing the mode: no, cold, or warm. "no" is now the equivalent of "--nostart_app", "cold" is the equivalent of "--start_app", and "warm" is the new start mode. Note that this is only useful with incremental installs, as Android clears out any previously saved state when an APK is replaced. -- MOS_MIGRATED_REVID=99508790
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/WriteAdbArgsAction.java41
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/MobileInstallCommand.java9
2 files changed, 45 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/WriteAdbArgsAction.java b/src/main/java/com/google/devtools/build/lib/rules/android/WriteAdbArgsAction.java
index 41b2111ed4..8f5c677029 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/WriteAdbArgsAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/WriteAdbArgsAction.java
@@ -21,6 +21,7 @@ import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.analysis.actions.AbstractFileWriteAction;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.util.Fingerprint;
+import com.google.devtools.common.options.EnumConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;
@@ -67,11 +68,20 @@ public class WriteAdbArgsAction extends AbstractFileWriteAction {
help = "The verbosity for incremental install. Set to 1 for debug logging.")
public String incrementalInstallVerbosity;
+ @Option(name = "start",
+ category = "mobile-install",
+ converter = StartTypeConverter.class,
+ defaultValue = "NO",
+ help = "How the app should be started after installing it. Set to WARM to preserve "
+ + "and restore application state on incremental installs.")
+ public StartType start;
+
@Option(name = "start_app",
category = "mobile-install",
- defaultValue = "false",
- help = "Whether to start the app after installing it.")
- public boolean startApp;
+ defaultValue = "null",
+ help = "Whether to start the app after installing it.",
+ expansion = {"--start=COLD"})
+ public Void startApp;
}
public WriteAdbArgsAction(ActionOwner owner, Artifact outputFile) {
@@ -86,7 +96,7 @@ public class WriteAdbArgsAction extends AbstractFileWriteAction {
final String adb = options.adb;
final int adbJobs = options.adbJobs;
final String incrementalInstallVerbosity = options.incrementalInstallVerbosity;
- final boolean startApp = options.startApp;
+ final StartType start = options.start;
final String userHomeDirectory = executor.getContext(
WriteAdbArgsActionContext.class).getUserHomeDirectory();
@@ -109,7 +119,8 @@ public class WriteAdbArgsAction extends AbstractFileWriteAction {
ps.printf("--verbosity=%s\n", incrementalInstallVerbosity);
}
- ps.printf("--start_app=%s\n", startApp);
+ ps.printf("--start=%s\n", start.name().toLowerCase());
+
if (userHomeDirectory != null) {
ps.printf("--user_home_dir=%s\n", userHomeDirectory);
@@ -140,4 +151,24 @@ public class WriteAdbArgsAction extends AbstractFileWriteAction {
.addString(GUID)
.hexDigestAndReset();
}
+
+ /** Specifies how the app should be started/stopped. */
+ public enum StartType {
+ /** The app will not be restarted after install. */
+ NO,
+ /** The app will be restarted from a clean state after install. */
+ COLD,
+ /**
+ * The app will save its state before installing, and be restored from that state after
+ * installing.
+ */
+ WARM
+ }
+
+ /** Converter for the --start option. */
+ public static class StartTypeConverter extends EnumConverter<StartType> {
+ public StartTypeConverter() {
+ super(StartType.class, "start type");
+ }
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/MobileInstallCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/MobileInstallCommand.java
index b68adb859e..13e2837dff 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/MobileInstallCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/MobileInstallCommand.java
@@ -16,7 +16,9 @@ package com.google.devtools.build.lib.runtime.commands;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.OutputGroupProvider;
import com.google.devtools.build.lib.buildtool.BuildRequest;
+import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.rules.android.WriteAdbArgsAction;
+import com.google.devtools.build.lib.rules.android.WriteAdbArgsAction.StartType;
import com.google.devtools.build.lib.runtime.BlazeCommand;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
import com.google.devtools.build.lib.runtime.Command;
@@ -64,6 +66,13 @@ public class MobileInstallCommand implements BlazeCommand {
@Override
public ExitCode exec(BlazeRuntime runtime, OptionsProvider options) {
+ Options mobileInstallOptions = options.getOptions(Options.class);
+ WriteAdbArgsAction.Options adbOptions = options.getOptions(WriteAdbArgsAction.Options.class);
+ if (adbOptions.start == StartType.WARM && !mobileInstallOptions.incremental) {
+ runtime.getReporter().handle(Event.warn(
+ "Warm start is enabled, but will have no effect on a non-incremental build"));
+ }
+
List<String> targets = ProjectFileSupport.getTargets(runtime, options);
BuildRequest request = BuildRequest.create(
this.getClass().getAnnotation(Command.class).name(), options,