Merge "Fixed some issues with resuming already resumed activity" into nyc-dev

This commit is contained in:
TreeHugger Robot
2016-05-03 00:15:49 +00:00
committed by Android (Google) Code Review
2 changed files with 38 additions and 16 deletions

View File

@@ -74,6 +74,7 @@ import static com.android.server.am.ActivityRecord.STARTING_WINDOW_REMOVED;
import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN; import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; import static com.android.server.am.ActivityStackSupervisor.FindTaskResult;
import static com.android.server.am.ActivityStackSupervisor.MOVING; import static com.android.server.am.ActivityStackSupervisor.MOVING;
import static com.android.server.am.ActivityStackSupervisor.ON_TOP;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_CLOSE; import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_CLOSE;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN; import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN;
@@ -220,6 +221,17 @@ final class ActivityStack {
// activities and there is a specific combination of stacks. // activities and there is a specific combination of stacks.
static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2; static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2;
/* The various modes for the method {@link #removeTask}. */
// Task is being completely removed from all stacks in the system.
static final int REMOVE_TASK_MODE_DESTROYING = 0;
// Task is being removed from this stack so we can add it to another stack. In the case we are
// moving we don't want to perform some operations on the task like removing it from window
// manager or recents.
static final int REMOVE_TASK_MODE_MOVING = 1;
// Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new
// stack and the new stack will be on top of all stacks.
static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2;
final ActivityManagerService mService; final ActivityManagerService mService;
final WindowManagerService mWindowManager; final WindowManagerService mWindowManager;
private final RecentTasks mRecentTasks; private final RecentTasks mRecentTasks;
@@ -4919,18 +4931,18 @@ final class ActivityStack {
} }
void removeTask(TaskRecord task, String reason) { void removeTask(TaskRecord task, String reason) {
removeTask(task, reason, !MOVING); removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING);
} }
/** /**
* Removes the input task from this stack. * Removes the input task from this stack.
* @param task to remove. * @param task to remove.
* @param reason for removal. * @param reason for removal.
* @param moving task to another stack. In the case we are moving we don't want to perform * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING},
* some operations on the task like removing it from window manager or recents. * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}.
*/ */
void removeTask(TaskRecord task, String reason, boolean moving) { void removeTask(TaskRecord task, String reason, int mode) {
if (!moving) { if (mode == REMOVE_TASK_MODE_DESTROYING) {
mStackSupervisor.removeLockedTaskLocked(task); mStackSupervisor.removeLockedTaskLocked(task);
mWindowManager.removeTask(task.taskId); mWindowManager.removeTask(task.taskId);
if (!StackId.persistTaskBounds(mStackId)) { if (!StackId.persistTaskBounds(mStackId)) {
@@ -4956,7 +4968,7 @@ final class ActivityStack {
mTaskHistory.remove(task); mTaskHistory.remove(task);
updateTaskMovement(task, true); updateTaskMovement(task, true);
if (!moving && task.mActivities.isEmpty()) { if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) {
// TODO: VI what about activity? // TODO: VI what about activity?
final boolean isVoiceSession = task.voiceSession != null; final boolean isVoiceSession = task.voiceSession != null;
if (isVoiceSession) { if (isVoiceSession) {
@@ -4975,8 +4987,10 @@ final class ActivityStack {
if (mTaskHistory.isEmpty()) { if (mTaskHistory.isEmpty()) {
if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this);
// We only need to adjust focused stack if this stack is in focus. // We only need to adjust focused stack if this stack is in focus and we are not in the
if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) { // process of moving the task to the top of the stack that will be focused.
if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP
&& mStackSupervisor.isFocusedStack(this)) {
String myReason = reason + " leftTaskHistoryEmpty"; String myReason = reason + " leftTaskHistoryEmpty";
if (mFullscreen if (mFullscreen
|| !adjustFocusToNextFocusableStackLocked( || !adjustFocusToNextFocusableStackLocked(
@@ -5024,7 +5038,7 @@ final class ActivityStack {
} }
void addTask(final TaskRecord task, final boolean toTop, String reason) { void addTask(final TaskRecord task, final boolean toTop, String reason) {
final ActivityStack prevStack = preAddTask(task, reason); final ActivityStack prevStack = preAddTask(task, reason, toTop);
task.stack = this; task.stack = this;
if (toTop) { if (toTop) {
@@ -5039,7 +5053,7 @@ final class ActivityStack {
void positionTask(final TaskRecord task, int position) { void positionTask(final TaskRecord task, int position) {
final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); final ActivityRecord topRunningActivity = task.topRunningActivityLocked();
final boolean wasResumed = topRunningActivity == task.stack.mResumedActivity; final boolean wasResumed = topRunningActivity == task.stack.mResumedActivity;
final ActivityStack prevStack = preAddTask(task, "positionTask"); final ActivityStack prevStack = preAddTask(task, "positionTask", ON_TOP);
task.stack = this; task.stack = this;
insertTaskAtPosition(task, position); insertTaskAtPosition(task, position);
postAddTask(task, prevStack); postAddTask(task, prevStack);
@@ -5053,10 +5067,11 @@ final class ActivityStack {
} }
} }
private ActivityStack preAddTask(TaskRecord task, String reason) { private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) {
final ActivityStack prevStack = task.stack; final ActivityStack prevStack = task.stack;
if (prevStack != null && prevStack != this) { if (prevStack != null && prevStack != this) {
prevStack.removeTask(task, reason, MOVING); prevStack.removeTask(task, reason,
toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING);
} }
return prevStack; return prevStack;
} }

View File

@@ -167,6 +167,7 @@ import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
import static com.android.server.am.ActivityStack.ActivityState.RESUMED; import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
import static com.android.server.am.ActivityStack.ActivityState.STOPPED; import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
import static com.android.server.am.ActivityStack.ActivityState.STOPPING; import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
import static com.android.server.am.ActivityStack.STACK_INVISIBLE; import static com.android.server.am.ActivityStack.STACK_INVISIBLE;
import static com.android.server.am.ActivityStack.STACK_VISIBLE; import static com.android.server.am.ActivityStack.STACK_VISIBLE;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
@@ -1785,7 +1786,10 @@ public final class ActivityStackSupervisor implements DisplayListener {
if (targetStack != null && isFocusedStack(targetStack)) { if (targetStack != null && isFocusedStack(targetStack)) {
return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions);
} }
mFocusedStack.resumeTopActivityUncheckedLocked(null, null); final ActivityRecord r = mFocusedStack.topRunningActivityLocked();
if (r == null || r.state != RESUMED) {
mFocusedStack.resumeTopActivityUncheckedLocked(null, null);
}
return false; return false;
} }
@@ -2134,8 +2138,11 @@ public final class ActivityStackSupervisor implements DisplayListener {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
moveTaskToStackLocked(tasks.get(i).taskId, moveTaskToStackLocked(tasks.get(i).taskId,
FULLSCREEN_WORKSPACE_STACK_ID, onTop, onTop /*forceFocus*/, FULLSCREEN_WORKSPACE_STACK_ID, onTop, onTop /*forceFocus*/,
"moveTasksToFullscreenStack", ANIMATE); "moveTasksToFullscreenStack", ANIMATE, DEFER_RESUME);
} }
ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS);
resumeFocusedStackTopActivityLocked();
} else { } else {
for (int i = size - 1; i >= 0; i--) { for (int i = size - 1; i >= 0; i--) {
positionTaskInStackLocked(tasks.get(i).taskId, positionTaskInStackLocked(tasks.get(i).taskId,
@@ -2338,7 +2345,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
} }
// Remove current stack association, so we can re-associate the task with the // Remove current stack association, so we can re-associate the task with the
// right stack below. // right stack below.
task.stack.removeTask(task, "restoreRecentTaskLocked", MOVING); task.stack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING);
} }
final ActivityStack stack = final ActivityStack stack =
@@ -2381,7 +2388,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
+ "support multi-window task=" + task + " to stackId=" + stackId); + "support multi-window task=" + task + " to stackId=" + stackId);
} }
final ActivityRecord r = task.getTopActivity(); final ActivityRecord r = task.topRunningActivityLocked();
final ActivityStack prevStack = task.stack; final ActivityStack prevStack = task.stack;
final boolean wasFocused = isFocusedStack(prevStack) && (topRunningActivityLocked() == r); final boolean wasFocused = isFocusedStack(prevStack) && (topRunningActivityLocked() == r);
final boolean wasResumed = prevStack.mResumedActivity == r; final boolean wasResumed = prevStack.mResumedActivity == r;