Merge "Add wrapper in scheduler, refactor the QuitRunnable"
diff --git a/src/com/android/tradefed/command/CommandScheduler.java b/src/com/android/tradefed/command/CommandScheduler.java
index c20c8f8..534032e 100644
--- a/src/com/android/tradefed/command/CommandScheduler.java
+++ b/src/com/android/tradefed/command/CommandScheduler.java
@@ -185,6 +185,8 @@
             + " when Invocation become interruptible. (Default behavior).", isTimeVal = true)
     private long mShutdownTimeout = 0;
 
+    private HostState mHostState = HostState.UNKNOWN;
+
     private enum CommandState {
         WAITING_FOR_DEVICE("Wait_for_device"),
         EXECUTING("Executing"),
@@ -201,6 +203,22 @@
         }
     }
 
+    /** Enums of different status of host */
+    public enum HostState {
+        UNKNOWN,
+        RUNNING,
+        QUITTING,
+        KILLING;
+    }
+
+    private void setHostState(HostState state) {
+        mHostState = state;
+    }
+
+    public HostState getHostState() {
+        return mHostState;
+    }
+
     /**
      * Represents one active command added to the scheduler. Will track total execution time of all
      * instances of this command
@@ -845,6 +863,7 @@
             mStarted = true;
         }
         super.start();
+        setHostState(HostState.RUNNING);
     }
 
     /**
@@ -1564,6 +1583,11 @@
      */
     @Override
     public synchronized void shutdown() {
+        setHostState(HostState.QUITTING);
+        doShutdown();
+    }
+
+    private synchronized void doShutdown() {
         assertStarted();
         if (!isShuttingDown()) {
             CLog.d("initiating shutdown");
@@ -1584,6 +1608,7 @@
     @Override
     public synchronized void shutdownOnEmpty() {
         assertStarted();
+        setHostState(HostState.QUITTING);
         if (!isShuttingDown()) {
             CLog.d("initiating shutdown on empty");
             mShutdownOnEmpty = true;
@@ -1715,8 +1740,8 @@
      */
     @Override
     public synchronized void shutdownHard() {
-        shutdown();
-
+        setHostState(HostState.KILLING);
+        doShutdown();
         CLog.logAndDisplay(LogLevel.WARN, "Stopping invocation threads...");
         for (InvocationThread thread : mInvocationThreadMap.values()) {
             thread.disableReporters();
diff --git a/src/com/android/tradefed/command/Console.java b/src/com/android/tradefed/command/Console.java
index cb05850..a908246 100644
--- a/src/com/android/tradefed/command/Console.java
+++ b/src/com/android/tradefed/command/Console.java
@@ -114,9 +114,7 @@
         }
     }
 
-    /**
-     * A {@link Runnable} with a {@code run} method that can take an argument
-     */
+    /** A {@link Runnable} with a {@code run} method that can take an argument */
     protected abstract static class ArgRunnable<T> implements Runnable {
         @Override
         public void run() {
@@ -140,7 +138,6 @@
                 "only exit after all commands have executed ")
         private boolean mExitOnEmpty = false;
 
-
         @Override
         public void run(CaptureList args) {
             try {
@@ -184,7 +181,6 @@
     private class ForceQuitRunnable extends QuitRunnable {
         @Override
         public void run(CaptureList args) {
-            super.run(args);
             mScheduler.shutdownHard();
         }
     }