Add an option to bit to not restart.

Test: build & restart
Change-Id: Ia925053f04046d7fb91a47cfd5fd17a5d4fecf10
diff --git a/tools/bit/main.cpp b/tools/bit/main.cpp
index 4974a44..868d90a 100644
--- a/tools/bit/main.cpp
+++ b/tools/bit/main.cpp
@@ -79,6 +79,7 @@
     string tabPattern;
 
     // For build/install/test
+    bool noRestart;
     bool reboot;
     vector<Target*> targets;
 
@@ -89,6 +90,7 @@
 Options::Options()
     :runHelp(false),
      runTab(false),
+     noRestart(false),
      reboot(false),
      targets()
 {
@@ -285,6 +287,7 @@
     fprintf(out, "  -i     Install the targets\n");
     fprintf(out, "  -t     Run the tests\n");
     fprintf(out, "\n");
+    fprintf(out, "  -n     Don't reboot or restart\n");
     fprintf(out, "  -r     If the runtime needs to be restarted, do a full reboot\n");
     fprintf(out, "         instead\n");
     fprintf(out, "\n");
@@ -431,6 +434,9 @@
                         flagTest = true;
                         anyPhases = true;
                         break;
+                    case 'n':
+                        options->noRestart = true;
+                        break;
                     case 'r':
                         options->reboot = true;
                         break;
@@ -558,7 +564,7 @@
  * Run the build, install, and test actions.
  */
 void
-run_phases(vector<Target*> targets, bool reboot)
+run_phases(vector<Target*> targets, const Options& options)
 {
     int err = 0;
 
@@ -676,40 +682,44 @@
             check_device_property("ro.build.id", buildId);
 
             // Stop & Sync
-            err = run_adb("shell", "stop", NULL);
-            check_error(err);
+            if (!options.noRestart) {
+                err = run_adb("shell", "stop", NULL);
+                check_error(err);
+            }
             err = run_adb("remount", NULL);
             check_error(err);
             err = run_adb("sync", "system", NULL);
             check_error(err);
 
-            if (reboot) {
-                print_status("Rebooting");
+            if (!options.noRestart) {
+                if (options.reboot) {
+                    print_status("Rebooting");
 
-                err = run_adb("reboot", NULL);
-                check_error(err);
-                err = run_adb("wait-for-device", NULL);
-                check_error(err);
-            } else {
-                print_status("Restarting the runtime");
+                    err = run_adb("reboot", NULL);
+                    check_error(err);
+                    err = run_adb("wait-for-device", NULL);
+                    check_error(err);
+                } else {
+                    print_status("Restarting the runtime");
 
-                err = run_adb("shell", "setprop", "sys.boot_completed", "0", NULL);
-                check_error(err);
-                err = run_adb("shell", "start", NULL);
-                check_error(err);
-            }
-
-            while (true) {
-                string completed = get_system_property("sys.boot_completed", &err);
-                check_error(err);
-                if (completed == "1") {
-                    break;
+                    err = run_adb("shell", "setprop", "sys.boot_completed", "0", NULL);
+                    check_error(err);
+                    err = run_adb("shell", "start", NULL);
+                    check_error(err);
                 }
-                sleep(2);
+
+                while (true) {
+                    string completed = get_system_property("sys.boot_completed", &err);
+                    check_error(err);
+                    if (completed == "1") {
+                        break;
+                    }
+                    sleep(2);
+                }
+                sleep(1);
+                err = run_adb("shell", "wm", "dismiss-keyguard", NULL);
+                check_error(err);
             }
-            sleep(1);
-            err = run_adb("shell", "wm", "dismiss-keyguard", NULL);
-            check_error(err);
         }
     }
 
@@ -976,7 +986,7 @@
         exit(0);
     } else {
         // Normal run
-        run_phases(options.targets, options.reboot);
+        run_phases(options.targets, options);
     }
 
     return 0;