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
This commit is contained in:
@@ -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<N; i++) {
|
||||
TaskRecord tr = mRecentTasks.get(i);
|
||||
@@ -8208,7 +8198,7 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
synchronized (this) {
|
||||
enforceCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
|
||||
"getTaskThumbnail()");
|
||||
TaskRecord tr = recentTaskForIdLocked(id);
|
||||
TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(id);
|
||||
if (tr != null) {
|
||||
return tr.getTaskThumbnailLocked();
|
||||
}
|
||||
@@ -8453,7 +8443,7 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
* @return Returns true if the given task was found and removed.
|
||||
*/
|
||||
private boolean removeTaskByIdLocked(int taskId, boolean killProcess) {
|
||||
TaskRecord tr = taskForIdLocked(taskId);
|
||||
TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(taskId);
|
||||
if (tr != null) {
|
||||
tr.removeTaskActivitiesLocked();
|
||||
cleanUpRemovedTaskLocked(tr, killProcess);
|
||||
@@ -8529,7 +8519,7 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
"moveTaskToBack()");
|
||||
|
||||
synchronized(this) {
|
||||
TaskRecord tr = taskForIdLocked(taskId);
|
||||
TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(taskId);
|
||||
if (tr != null) {
|
||||
if (tr == mStackSupervisor.mLockTaskModeTask) {
|
||||
mStackSupervisor.showLockTaskToast();
|
||||
@@ -8721,7 +8711,7 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
synchronized (this) {
|
||||
TaskRecord tr = taskForIdLocked(taskId);
|
||||
TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(taskId);
|
||||
return tr != null && tr.stack != null && tr.stack.isHomeStack();
|
||||
}
|
||||
} finally {
|
||||
@@ -11177,9 +11167,6 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
if (mRecentTasks == null) {
|
||||
mRecentTasks = mTaskPersister.restoreTasksLocked();
|
||||
mTaskPersister.restoreTasksFromOtherDeviceLocked();
|
||||
if (!mRecentTasks.isEmpty()) {
|
||||
mStackSupervisor.createStackForRestoredTaskHistory(mRecentTasks);
|
||||
}
|
||||
cleanupRecentTasksLocked(UserHandle.USER_ALL);
|
||||
mTaskPersister.startPersisting();
|
||||
}
|
||||
@@ -11196,8 +11183,7 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
mDidUpdate = true;
|
||||
}
|
||||
writeLastDonePreBootReceivers(doneReceivers);
|
||||
showBootMessage(mContext.getText(
|
||||
R.string.android_upgrading_complete),
|
||||
showBootMessage(mContext.getText(R.string.android_upgrading_complete),
|
||||
false);
|
||||
systemReady(goingCallback);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import static com.android.server.am.ActivityManagerService.localLOGV;
|
||||
import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION;
|
||||
import static com.android.server.am.ActivityManagerService.DEBUG_FOCUS;
|
||||
import static com.android.server.am.ActivityManagerService.DEBUG_PAUSE;
|
||||
import static com.android.server.am.ActivityManagerService.DEBUG_RECENTS;
|
||||
import static com.android.server.am.ActivityManagerService.DEBUG_RESULTS;
|
||||
import static com.android.server.am.ActivityManagerService.DEBUG_STACK;
|
||||
import static com.android.server.am.ActivityManagerService.DEBUG_SWITCH;
|
||||
@@ -460,7 +461,21 @@ public final class ActivityStackSupervisor implements DisplayListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
// Don't give up! Look in recents.
|
||||
if (DEBUG_RECENTS) Slog.v(TAG, "Looking for task id=" + id + " in recents");
|
||||
TaskRecord task = mService.recentTaskForIdLocked(id);
|
||||
if (task == null) {
|
||||
if (DEBUG_RECENTS) Slog.d(TAG, "\tDidn't find task id=" + id + " in recents");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!restoreRecentTaskLocked(task)) {
|
||||
if (DEBUG_RECENTS) Slog.w(TAG, "Couldn't restore task id=" + id + " found in recents");
|
||||
return null;
|
||||
}
|
||||
if (DEBUG_RECENTS) Slog.w(TAG, "Restored task id=" + id + " from in recents");
|
||||
return task;
|
||||
}
|
||||
|
||||
ActivityRecord isInAnyStackLocked(IBinder token) {
|
||||
@@ -2590,23 +2605,53 @@ public final class ActivityStackSupervisor implements DisplayListener {
|
||||
return mLastStackId;
|
||||
}
|
||||
|
||||
void createStackForRestoredTaskHistory(ArrayList<TaskRecord> 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<ActivityRecord> 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<ActivityStack> 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<ActivityRecord> 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) {
|
||||
|
||||
Reference in New Issue
Block a user