Merge "Changed some parts of the code to prepare it for script support that will come in later commit."
diff --git a/tests/DumpRenderTree2/AndroidManifest.xml b/tests/DumpRenderTree2/AndroidManifest.xml
index 9f6097a..e4bfd59 100644
--- a/tests/DumpRenderTree2/AndroidManifest.xml
+++ b/tests/DumpRenderTree2/AndroidManifest.xml
@@ -25,8 +25,15 @@
             </intent-filter>
         </activity>
 
+        <!-- android:launchMode="singleTask" is there so we only have a one instance
+             of this activity. However, it doesn't seem to work exactly like described in the
+             documentation, because the behaviour of the application suggest
+             there is only a single task for all 3 activities. We don't understand
+             how exactly it all works, but at the moment it works just fine.
+             It can lead to some weird behaviour in the future. -->
         <activity android:name=".TestsListActivity"
-                  android:label="Tests' list activity">
+                  android:label="Tests' list activity"
+                  android:launchMode="singleTask">
         </activity>
 
         <activity android:name=".LayoutTestsExecutor"
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java
index 3bbfb89..a8695a0 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java
@@ -93,6 +93,11 @@
 
                 case MSG_ALL_TESTS_FINISHED:
                     mSummarizer.summarize();
+                    Intent intent = new Intent(ManagerService.this, TestsListActivity.class);
+                    intent.setAction(Intent.ACTION_SHUTDOWN);
+                    /** This flag is needed because we send the intent from the service */
+                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    startActivity(intent);
                     break;
             }
         }
@@ -166,7 +171,8 @@
 
         Intent intent = new Intent(this, TestsListActivity.class);
         intent.setAction(Intent.ACTION_REBOOT);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+        /** This flag is needed because we send the intent from the service */
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         intent.putExtra("crashedTestIndex", mCurrentlyRunningTestIndex);
         startActivity(intent);
     }
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListActivity.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListActivity.java
index c21463b..982fe10 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListActivity.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListActivity.java
@@ -85,6 +85,15 @@
         new TestsListPreloaderThread(path, doneMsg).start();
     }
 
+    @Override
+    protected void onNewIntent(Intent intent) {
+        if (intent.getAction().equals(Intent.ACTION_REBOOT)) {
+            onCrashIntent(intent);
+        } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
+            onEverythingFinishedIntent(intent);
+        }
+    }
+
     /**
      * This method handles an intent that comes from ManageService when crash is detected.
      * The intent contains an index in mTestsList of the test that crashed. TestsListActivity
@@ -94,18 +103,17 @@
      * LayoutTestExecutor runs then as usual, sending reports to ManagerService. If it
      * detects the crash it sends a new intent and the flow repeats.
      */
-    @Override
-    protected void onNewIntent(Intent intent) {
-        if (!intent.getAction().equals(Intent.ACTION_REBOOT)) {
-            return;
-        }
-
+    private void onCrashIntent(Intent intent) {
         int nextTestToRun = intent.getIntExtra("crashedTestIndex", -1) + 1;
         if (nextTestToRun > 0 && nextTestToRun <= mTotalTestCount) {
             restartExecutor(nextTestToRun);
         }
     }
 
+    private void onEverythingFinishedIntent(Intent intent) {
+        /** TODO: Show some kind of summary to the user */
+    }
+
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         outState.putStringArrayList("testsList", mTestsList);