Merge "When removing a task that was on home, put home on top." into klp-dev
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 456a0a7..a510c64 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -3466,7 +3466,7 @@
         }
 
         // Remove this application's activities from active lists.
-        boolean hasVisibleActivities = mStackSupervisor.handleAppDiedLocked(app, restarting);
+        boolean hasVisibleActivities = mStackSupervisor.handleAppDiedLocked(app);
 
         app.activities.clear();
 
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 066989b..525b7e1 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -2629,6 +2629,9 @@
             if (DEBUG_STACK) Slog.i(TAG,
                     "removeActivityFromHistoryLocked: last activity removed from " + this);
             mStackSupervisor.removeTask(task);
+            if (task.mOnTopOfHome) {
+                mStackSupervisor.moveHomeToTop();
+            }
         }
         r.takeFromHistory();
         removeTimeoutsForActivityLocked(r);
diff --git a/services/java/com/android/server/am/ActivityStackSupervisor.java b/services/java/com/android/server/am/ActivityStackSupervisor.java
index d758cd4..040f0ac 100644
--- a/services/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/java/com/android/server/am/ActivityStackSupervisor.java
@@ -278,12 +278,16 @@
         }
     }
 
-    boolean resumeHomeActivity(ActivityRecord prev) {
+    void moveHomeToTop() {
         moveHomeStack(true);
+        mHomeStack.moveHomeTaskToTop();
+    }
+
+    boolean resumeHomeActivity(ActivityRecord prev) {
+        moveHomeToTop();
         if (prev != null) {
             prev.task.mOnTopOfHome = false;
         }
-        mHomeStack.moveHomeTaskToTop();
         ActivityRecord r = mHomeStack.topRunningActivityLocked(null);
         if (r != null && r.isHomeActivity()) {
             mService.setFocusedActivityLocked(r);
@@ -625,7 +629,7 @@
     }
 
     void startHomeActivity(Intent intent, ActivityInfo aInfo) {
-        moveHomeStack(true);
+        moveHomeToTop();
         startActivityLocked(null, intent, null, aInfo, null, null, 0, 0, 0, null, 0,
                 null, false, null);
     }
@@ -1906,7 +1910,7 @@
         return r;
     }
 
-    boolean handleAppDiedLocked(ProcessRecord app, boolean restarting) {
+    boolean handleAppDiedLocked(ProcessRecord app) {
         boolean hasVisibleActivities = false;
         for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
             hasVisibleActivities |= mStacks.get(stackNdx).handleAppDiedLocked(app);