From 7de0535701351d76b634ab18577269e8130749ea Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Fri, 12 Dec 2014 15:21:33 -0800 Subject: Don't restore persistent task to a stack until needed. On boot-up we restore all persistent tasks to an activity stack. This can cause issues with the activity stack supervisor when it tries to make restored tasks with activities visiable when they shouldn't be. Which ends up messing up the order of the recents list. Now we don't restore persistent tasks to an activity stack on boot-up. Instead we add the task to the stack when it is needed. Also, fixes issue with not been able to launch task records with activity records that were restored from an other device. Bug: 18692762 Change-Id: Iad0e6635f8c5d1dab4d341feb3e7b06291a94739 --- .../android/server/am/ActivityManagerService.java | 26 ++------ .../android/server/am/ActivityStackSupervisor.java | 77 +++++++++++++++++----- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index c0fc890..022ef44 100755 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -8182,17 +8182,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } - private TaskRecord taskForIdLocked(int id) { - final TaskRecord task = recentTaskForIdLocked(id); - if (task != null) { - return task; - } - - // Don't give up. Sometimes it just hasn't made it to recents yet. - return mStackSupervisor.anyTaskForIdLocked(id); - } - - private TaskRecord recentTaskForIdLocked(int id) { + TaskRecord recentTaskForIdLocked(int id) { final int N = mRecentTasks.size(); for (int i=0; i tasks) { - int stackId = createStackOnDisplay(getNextStackId(), Display.DEFAULT_DISPLAY); - final ActivityStack stack = getStack(stackId); - for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { - final TaskRecord task = tasks.get(taskNdx); - stack.addTask(task, false, false); - final int taskId = task.taskId; - final ArrayList activities = task.mActivities; - for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { - final ActivityRecord r = activities.get(activityNdx); - mWindowManager.addAppToken(0, r.appToken, taskId, stackId, - r.info.screenOrientation, r.fullscreen, - (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, - r.userId, r.info.configChanges, task.voiceSession != null, - r.mLaunchTaskBehind); + private boolean restoreRecentTaskLocked(TaskRecord task) { + ActivityStack stack = null; + // Determine stack to restore task to. + if (mLeanbackOnlyDevice) { + // There is only one stack for lean back devices. + stack = mHomeStack; + } else { + // Look for the top stack on the home display that isn't the home stack. + final ArrayList homeDisplayStacks = mHomeStack.mStacks; + for (int stackNdx = homeDisplayStacks.size() - 1; stackNdx >= 0; --stackNdx) { + final ActivityStack tmpStack = homeDisplayStacks.get(stackNdx); + if (!tmpStack.isHomeStack()) { + stack = tmpStack; + break; + } } } + + if (stack == null) { + // We couldn't find a stack to restore the task to. Possible if are restoring recents + // before an application stack is created...Go ahead and create one on the default + // display. + stack = getStack(createStackOnDisplay(getNextStackId(), Display.DEFAULT_DISPLAY)); + if (DEBUG_RECENTS) + Slog.v(TAG, "Created stack=" + stack + " for recents restoration."); + } + + if (stack == null) { + // What does this mean??? Not sure how we would get here... + if (DEBUG_RECENTS) + Slog.v(TAG, "Unable to find/create stack to restore recent task=" + task); + return false; + } + + stack.addTask(task, false, false); + if (DEBUG_RECENTS) + Slog.v(TAG, "Added restored task=" + task + " to stack=" + stack); + final ArrayList activities = task.mActivities; + for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { + final ActivityRecord r = activities.get(activityNdx); + mWindowManager.addAppToken(0, r.appToken, task.taskId, stack.mStackId, + r.info.screenOrientation, r.fullscreen, + (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, + r.userId, r.info.configChanges, task.voiceSession != null, + r.mLaunchTaskBehind); + } + return true; } void moveTaskToStack(int taskId, int stackId, boolean toTop) { -- cgit v1.1