final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming,
boolean dontWait) {
if (mPausingActivity != null) {
- Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity);
- completePauseLocked(false);
+ Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity
+ + " state=" + mPausingActivity.state);
+ if (!mService.isSleeping()) {
+ // Avoid recursion among check for sleep and complete pause during sleeping.
+ // Because activity will be paused immediately after resume, just let pause
+ // be completed by the order of activity paused from clients.
+ completePauseLocked(false);
+ }
}
ActivityRecord prev = mResumedActivity;
if (prev == null) {
r.userId, System.identityHashCode(r), r.shortComponentName,
mPausingActivity != null
? mPausingActivity.shortComponentName : "(none)");
+ if (r.finishing && r.state == ActivityState.PAUSING) {
+ if (DEBUG_PAUSE) Slog.v(TAG,
+ "Executing finish of failed to pause activity: " + r);
+ finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false);
+ }
}
}
}
mStackSupervisor.mGoingToSleepActivities.remove(next);
next.sleeping = false;
mStackSupervisor.mWaitingVisibleActivities.remove(next);
+ next.waitingVisible = false;
if (DEBUG_SWITCH) Slog.v(TAG, "Resuming " + next);
return true;
}
+ private TaskRecord getNextTask(TaskRecord targetTask) {
+ final int index = mTaskHistory.indexOf(targetTask);
+ if (index >= 0) {
+ final int numTasks = mTaskHistory.size();
+ for (int i = index + 1; i < numTasks; ++i) {
+ TaskRecord task = mTaskHistory.get(i);
+ if (task.userId == targetTask.userId) {
+ return task;
+ }
+ }
+ }
+ return null;
+ }
+
private void insertTaskAtTop(TaskRecord task) {
+ // If the moving task is over home stack, transfer its return type to next task
+ if (task.isOverHomeStack()) {
+ final TaskRecord nextTask = getNextTask(task);
+ if (nextTask != null) {
+ nextTask.setTaskToReturnTo(task.getTaskToReturnTo());
+ }
+ }
+
// If this is being moved to the top by another activity or being launched from the home
- // activity, set mOnTopOfHome accordingly.
+ // activity, set mTaskToReturnTo accordingly.
if (isOnHomeDisplay()) {
ActivityStack lastStack = mStackSupervisor.getLastStack();
final boolean fromHome = lastStack.isHomeStack();
// In this case, we want to finish this activity
// and everything above it, so be sneaky and pretend
// like these are all in the reply chain.
- end = numActivities - 1;
+ end = activities.size() - 1;
} else if (replyChainEnd < 0) {
end = i;
} else {
}
int taskNdx = mTaskHistory.indexOf(task);
- do {
- taskTop = mTaskHistory.get(taskNdx--).getTopActivity();
- } while (taskTop == null && taskNdx >= 0);
+ if (taskNdx >= 0) {
+ do {
+ taskTop = mTaskHistory.get(taskNdx--).getTopActivity();
+ } while (taskTop == null && taskNdx >= 0);
+ }
if (topOptions != null) {
// If we got some ActivityOptions from an activity on top that
mStackSupervisor.mStoppingActivities.remove(r);
mStackSupervisor.mGoingToSleepActivities.remove(r);
mStackSupervisor.mWaitingVisibleActivities.remove(r);
+ r.waitingVisible = false;
if (mResumedActivity == r) {
mResumedActivity = null;
}
// down to the max limit while they are still waiting to finish.
mStackSupervisor.mFinishingActivities.remove(r);
mStackSupervisor.mWaitingVisibleActivities.remove(r);
+ r.waitingVisible = false;
// Remove any pending results.
if (r.finishing && r.pendingResults != null) {
if (DEBUG_CLEANUP) Slog.v(
TAG, "Record #" + i + " " + r + ": app=" + r.app);
if (r.app == app) {
+ if (r.visible) {
+ hasVisibleActivities = true;
+ }
boolean remove;
if ((!r.haveState && !r.stateNotNeeded) || r.finishing) {
// Don't currently have state for the activity, or
// it can be restarted later when needed.
if (localLOGV) Slog.v(
TAG, "Keeping entry, setting app to null");
- if (r.visible) {
- hasVisibleActivities = true;
- }
if (DEBUG_APP) Slog.v(TAG, "Clearing app during removeHistory for activity "
+ r);
r.app = null;
if (DEBUG_TRANSITION) Slog.v(TAG,
"Prepare to back transition: task=" + taskId);
+ boolean prevIsHome = false;
+ if (tr.isOverHomeStack()) {
+ final TaskRecord nextTask = getNextTask(tr);
+ if (nextTask != null) {
+ nextTask.setTaskToReturnTo(tr.getTaskToReturnTo());
+ } else {
+ prevIsHome = true;
+ }
+ }
mTaskHistory.remove(tr);
mTaskHistory.add(0, tr);
updateTaskMovement(tr, false);
}
final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null;
- if (task == tr && tr.isOverHomeStack() || numTasks <= 1 && isOnHomeDisplay()) {
+ if (prevIsHome || task == tr && tr.isOverHomeStack()
+ || numTasks <= 1 && isOnHomeDisplay()) {
if (!mService.mBooting && !mService.mBooted) {
// Not ready yet!
return false;
}
void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) {
+ boolean focusedStack = mStackSupervisor.getFocusedStack() == this;
+ boolean topTask = true;
for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
final TaskRecord task = mTaskHistory.get(taskNdx);
+ if (task.getTopActivity() == null) {
+ continue;
+ }
ActivityRecord r = null;
ActivityRecord top = null;
int numActivities = 0;
int numRunning = 0;
final ArrayList<ActivityRecord> activities = task.mActivities;
- if (activities.isEmpty()) {
- continue;
- }
if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) {
continue;
}
ci.baseActivity = r.intent.getComponent();
ci.topActivity = top.intent.getComponent();
ci.lastActiveTime = task.lastActiveTime;
+ if (focusedStack && topTask) {
+ // Give the latest time to ensure foreground task can be sorted
+ // at the first, because lastActiveTime of creating task is 0.
+ ci.lastActiveTime = System.currentTimeMillis();
+ topTask = false;
+ }
if (top.task != null) {
ci.description = top.task.lastDescription;
}
ci.numActivities = numActivities;
ci.numRunning = numRunning;
- //System.out.println(
- // "#" + maxNum + ": " + " descr=" + ci.description);
list.add(ci);
}
}