OSDN Git Service

Revert to jb-mr2 handling of app died.
authorCraig Mautner <cmautner@google.com>
Sat, 5 Oct 2013 07:03:53 +0000 (00:03 -0700)
committerCraig Mautner <cmautner@google.com>
Sun, 6 Oct 2013 17:39:31 +0000 (10:39 -0700)
Trying to span all potential stacks looking for apps was too complex
and error-prone. Extending the jb-mr2 method across multiple stacks.

Fixes bug 11080696.

Change-Id: I6391ceae4ad6a0955a409c3fb27472219fd5bf6b

services/java/com/android/server/am/ActivityManagerService.java
services/java/com/android/server/am/ActivityStack.java
services/java/com/android/server/am/ActivityStackSupervisor.java

index f23bcba..152cd7d 100644 (file)
@@ -3464,7 +3464,8 @@ public final class ActivityManagerService extends ActivityManagerNative
             clearProfilerLocked();
         }
 
-        mStackSupervisor.handleAppDiedLocked(app, restarting);
+        // Remove this application's activities from active lists.
+        boolean hasVisibleActivities = mStackSupervisor.handleAppDiedLocked(app, restarting);
 
         app.activities.clear();
 
@@ -3475,6 +3476,19 @@ public final class ActivityManagerService extends ActivityManagerNative
             info.putString("shortMsg", "Process crashed.");
             finishInstrumentationLocked(app, Activity.RESULT_CANCELED, info);
         }
+
+        if (!restarting) {
+            if (!mStackSupervisor.resumeTopActivitiesLocked()) {
+                // If there was nothing to resume, and we are not already
+                // restarting this process, but there is a visible activity that
+                // is hosted by the process...  then make sure all visible
+                // activities are running, taking care of restarting this
+                // process.
+                if (hasVisibleActivities) {
+                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
+                }
+            }
+        }
     }
 
     private final int getLRURecordIndexForAppLocked(IApplicationThread thread) {
index 45b30f1..11a058e 100644 (file)
@@ -3421,13 +3421,9 @@ final class ActivityStack {
     /**
      * Reset local parameters because an app's activity died.
      * @param app The app of the activity that died.
-     * @return true if home should be launched next.
+     * @return result from removeHistoryRecordsForAppLocked.
      */
     boolean handleAppDiedLocked(ProcessRecord app) {
-        if (!containsApp(app)) {
-            return false;
-        }
-
         if (mPausingActivity != null && mPausingActivity.app == app) {
             if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG,
                     "App died while pausing: " + mPausingActivity);
@@ -3438,30 +3434,7 @@ final class ActivityStack {
             mLastNoHistoryActivity = null;
         }
 
-        // Determine if the top task is exiting and should return to home. Do this before it gets
-        // removed in removeHistoryRecordsForAppsLocked.
-        boolean launchHomeNext = false;
-        TaskRecord topTask = mTaskHistory.get(mTaskHistory.size() - 1);
-        ArrayList<ActivityRecord> activities = topTask.mActivities;
-        int activityNdx;
-        for (activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-            ActivityRecord r = activities.get(activityNdx);
-            if (r.finishing) {
-                continue;
-            }
-            if (r.app != app) {
-                // This is the dying activity.
-                break;
-            }
-        }
-        if (activityNdx < 0) {
-            // All activities in task belong to app. Set launchHomeNext to task's value.
-            launchHomeNext = topTask.mOnTopOfHome;
-        }
-
-        removeHistoryRecordsForAppLocked(app);
-
-        return launchHomeNext;
+        return removeHistoryRecordsForAppLocked(app);
     }
 
     void handleAppCrashLocked(ProcessRecord app) {
index 2b69a4e..75f3ce2 100644 (file)
@@ -1926,30 +1926,12 @@ public final class ActivityStackSupervisor {
         return r;
     }
 
-    void handleAppDiedLocked(ProcessRecord app, boolean restarting) {
-        boolean launchHomeTaskNext = false;
-        final ActivityStack focusedStack = getFocusedStack();
-        final int numStacks = mStacks.size();
-        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            // Only update launchHomeTaskNext for the focused stack.
-            launchHomeTaskNext |= (stack.handleAppDiedLocked(app) && stack == focusedStack);
-        }
-
-        if (!restarting) {
-            if (launchHomeTaskNext) {
-                resumeHomeActivity(null);
-            } else {
-                if (!resumeTopActivitiesLocked(focusedStack, null, null)) {
-                    // If there was nothing to resume, and we are not already
-                    // restarting this process, but there is a visible activity that
-                    // is hosted by the process...  then make sure all visible
-                    // activities are running, taking care of restarting this
-                    // process.
-                    ensureActivitiesVisibleLocked(null, 0);
-                }
-            }
+    boolean handleAppDiedLocked(ProcessRecord app, boolean restarting) {
+        boolean hasVisibleActivities = false;
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            hasVisibleActivities |= mStacks.get(stackNdx).handleAppDiedLocked(app);
         }
+        return hasVisibleActivities;
     }
 
     void closeSystemDialogsLocked() {