diff options
| author | 2020-07-09 17:39:59 +0800 | |
|---|---|---|
| committer | 2020-07-20 10:37:14 +0800 | |
| commit | b7f02a3e1d16620ccc2305f3db9d0000762cf0fe (patch) | |
| tree | 5cca0e4433f245b5d1d970f2d6925da094d81edd | |
| parent | 4cc7111329edcc0d89a3f352669127decdbd8a0a (diff) | |
Merge ActivityStack into Task
Remove ActivityStack and merge it into Task.
The `stack` term still exists in lots of variables/methods/comments
which will be cleaned up by other CLs.
Bug: 157876447
Test: existing test pass
Change-Id: I9ae0823ad1cbfd34bef004925700451c6071c542
71 files changed, 4125 insertions, 4198 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java index 189b21fb81a6..7565d8f9647c 100644 --- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java @@ -396,8 +396,7 @@ class ActivityMetricsLogger { mLastLogTimeSecs = now; mWindowState = WINDOW_STATE_INVALID; - ActivityStack stack = - mSupervisor.mRootWindowContainer.getTopDisplayFocusedStack(); + Task stack = mSupervisor.mRootWindowContainer.getTopDisplayFocusedStack(); if (stack == null) { return; } diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index a3acc1d90862..b7bb92496d0e 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -136,18 +136,6 @@ import static com.android.server.wm.ActivityRecordProto.VISIBLE; import static com.android.server.wm.ActivityRecordProto.VISIBLE_REQUESTED; import static com.android.server.wm.ActivityRecordProto.VISIBLE_SET_FROM_TRANSFERRED_STARTING_WINDOW; import static com.android.server.wm.ActivityRecordProto.WINDOW_TOKEN; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; -import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; -import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.ActivityState.RESTARTING_PROCESS; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.ActivityState.STARTED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_APP; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; @@ -192,6 +180,18 @@ import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION; +import static com.android.server.wm.Task.ActivityState.DESTROYED; +import static com.android.server.wm.Task.ActivityState.DESTROYING; +import static com.android.server.wm.Task.ActivityState.FINISHING; +import static com.android.server.wm.Task.ActivityState.INITIALIZING; +import static com.android.server.wm.Task.ActivityState.PAUSED; +import static com.android.server.wm.Task.ActivityState.PAUSING; +import static com.android.server.wm.Task.ActivityState.RESTARTING_PROCESS; +import static com.android.server.wm.Task.ActivityState.RESUMED; +import static com.android.server.wm.Task.ActivityState.STARTED; +import static com.android.server.wm.Task.ActivityState.STOPPED; +import static com.android.server.wm.Task.ActivityState.STOPPING; +import static com.android.server.wm.Task.STACK_VISIBILITY_VISIBLE; import static com.android.server.wm.TaskPersister.DEBUG; import static com.android.server.wm.TaskPersister.IMAGE_EXTENSION; import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; @@ -309,8 +309,8 @@ import com.android.server.protolog.common.ProtoLog; import com.android.server.uri.NeededUriGrants; import com.android.server.uri.UriPermissionOwner; import com.android.server.wm.ActivityMetricsLogger.TransitionInfoSnapshot; -import com.android.server.wm.ActivityStack.ActivityState; import com.android.server.wm.SurfaceAnimator.AnimationType; +import com.android.server.wm.Task.ActivityState; import com.android.server.wm.WindowManagerService.H; import com.android.server.wm.utils.InsetUtils; @@ -1155,7 +1155,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } void updateMultiWindowMode() { - if (task == null || task.getStack() == null || !attachedToProcess()) { + if (task == null || task.getRootTask() == null || !attachedToProcess()) { return; } @@ -1180,7 +1180,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } void updatePictureInPictureMode(Rect targetStackBounds, boolean forceUpdate) { - if (task == null || task.getStack() == null || !attachedToProcess()) { + if (task == null || task.getRootTask() == null || !attachedToProcess()) { return; } @@ -1221,8 +1221,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A this.task = task; } - ActivityStack getStack() { - return task != null ? task.getStack() : null; + Task getStack() { + return task != null ? task.getRootTask() : null; } @Override @@ -1269,10 +1269,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (getDisplayContent() != null) { getDisplayContent().mClosingApps.remove(this); } - } else if (mLastParent != null && mLastParent.getStack() != null) { - task.getStack().mExitingActivities.remove(this); + } else if (mLastParent != null && mLastParent.getRootTask() != null) { + task.getRootTask().mExitingActivities.remove(this); } - final ActivityStack stack = getStack(); + final Task stack = getStack(); // If we reparent, make sure to remove ourselves from the old animation registry. if (mAnimatingActivityRegistry != null) { @@ -2125,8 +2125,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } /** @return Root task of this activity, null if there is no task. */ - ActivityStack getRootTask() { - return task != null ? (ActivityStack) task.getRootTask() : null; + Task getRootTask() { + return task != null ? task.getRootTask() : null; } int getRootTaskId() { @@ -2134,7 +2134,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } DisplayContent getDisplay() { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); return stack != null ? stack.getDisplay() : null; } @@ -2204,7 +2204,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } boolean isInStackLocked() { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); return stack != null && stack.isInTask(this) != null; } @@ -2414,7 +2414,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return false; } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack == null) { Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: activity=" + this + " task=" + task); @@ -2546,7 +2546,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return FINISH_RESULT_CANCELLED; } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); final boolean mayAdjustTop = (isState(RESUMED) || stack.mResumedActivity == null) && stack.isFocusedStackOnDisplay(); final boolean shouldAdjustGlobalFocus = mayAdjustTop @@ -2576,7 +2576,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // We are finishing the top focused activity and its task has nothing to be focused so // the next focusable task should be focused. - if (mayAdjustTop && ((ActivityStack) task).topRunningActivity(true /* focusableOnly */) + if (mayAdjustTop && task.topRunningActivity(true /* focusableOnly */) == null) { task.adjustFocusToNextFocusableTask("finish-top", false /* allowFocusSelf */, shouldAdjustGlobalFocus); @@ -2705,7 +2705,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A final boolean isCurrentVisible = mVisibleRequested || isState(PAUSED); if (isCurrentVisible) { - final ActivityStack stack = getStack(); + final Task stack = getStack(); final ActivityRecord activity = stack.mResumedActivity; boolean ensureVisibility = false; if (activity != null && !activity.occludesParent()) { @@ -2775,7 +2775,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Make sure the record is cleaned out of other places. mStackSupervisor.mStoppingActivities.remove(this); - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); final TaskDisplayArea taskDisplayArea = getDisplayArea(); // TODO(b/137329632): Exclude current activity when looking for the next one with // DisplayContent#topRunningActivity(). @@ -2935,7 +2935,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A boolean safelyDestroy(String reason) { if (isDestroyable()) { if (DEBUG_SWITCH) { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); Slog.v(TAG_SWITCH, "Safely destroying " + this + " in state " + getState() + " resumed=" + stack.mResumedActivity + " pausing=" + stack.mPausingActivity @@ -3229,7 +3229,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A getDisplayContent().mNoAnimationNotifyOnTransitionFinished.add(token); } - final ActivityStack stack = getStack(); + final Task stack = getStack(); if (delayed && !isEmpty()) { // set the token aside because it has an active animation to be finished ProtoLog.v(WM_DEBUG_ADD_REMOVE, @@ -3743,7 +3743,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } final boolean isSleeping() { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); return stack != null ? stack.shouldSleepActivities() : mAtmService.isSleepingLocked(); } @@ -4578,7 +4578,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return visibleIgnoringKeyguard; } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack == null) { return false; } @@ -4615,7 +4615,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } boolean shouldBeVisible() { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack == null) { return false; } @@ -4636,7 +4636,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // If this activity is paused, tell it to now show its window. if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making visible and scheduling visibility: " + this); - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); try { if (stack.mTranslucentActivityWaiting != null) { updateOptionsLocked(returningOptions); @@ -4913,7 +4913,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A mStackSupervisor.reportResumedActivityLocked(this); resumeKeyDispatchingLocked(); - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); mStackSupervisor.mNoAnimActivities.clear(); // Mark the point when the activity is resuming @@ -4941,7 +4941,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity paused: token=" + appToken + ", timeout=" + timeout); - final ActivityStack stack = getStack(); + final Task stack = getStack(); if (stack != null) { removePauseTimeout(); @@ -5006,7 +5006,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A void stopIfPossible() { if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + this); - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (isNoHistory()) { if (!finishing) { if (!stack.shouldSleepActivities()) { @@ -5063,7 +5063,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A void activityStopped(Bundle newIcicle, PersistableBundle newPersistentState, CharSequence description) { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); final boolean isStopping = mState == STOPPING; if (!isStopping && mState != RESTARTING_PROCESS) { Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this); @@ -5113,7 +5113,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A mStackSupervisor.mStoppingActivities.add(this); } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); // If we already have a few activities waiting to stop, then give up on things going idle // and start clearing them out. Or if r is the last of activity of the last task the stack // will be empty and must be cleared immediately. @@ -5149,7 +5149,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return false; } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack == null) { return false; } @@ -5165,7 +5165,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A void finishLaunchTickingLocked() { launchTickTime = 0; - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack == null) { return; } @@ -5596,7 +5596,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // First find the real culprit... if this activity has stopped, then the key dispatching // timeout should not be caused by this. if (stopped) { - final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); + final Task stack = mRootWindowContainer.getTopDisplayFocusedStack(); if (stack == null) { return this; } @@ -5660,7 +5660,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return (r != null) ? r.getRootTask().isInTask(r) : null; } - static ActivityStack getStackLocked(IBinder token) { + static Task getStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.isInStackLocked(token); if (r != null) { return r.getRootTask(); @@ -5673,7 +5673,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * {@link android.view.Display#INVALID_DISPLAY} if not attached. */ int getDisplayId() { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack == null) { return INVALID_DISPLAY; } @@ -5685,7 +5685,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // This would be redundant. return false; } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (isState(RESUMED) || stack == null || this == stack.mPausingActivity || !mHaveState || !stopped) { // We're not ready for this kind of thing. @@ -6007,7 +6007,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A getTransit(), task)) { task.getBounds(mTmpRect); } else { - final ActivityStack stack = getStack(); + final Task stack = getStack(); if (stack == null) { return; } @@ -6830,7 +6830,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A private void applyAspectRatio(Rect outBounds, Rect containingAppBounds, Rect containingBounds) { final float maxAspectRatio = info.maxAspectRatio; - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); final float minAspectRatio = info.minAspectRatio; if (task == null || stack == null || (inMultiWindowMode() && !shouldUseSizeCompatMode()) @@ -6936,7 +6936,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A */ boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow, boolean ignoreVisibility) { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack.mConfigWillChange) { if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Skipping config check (will change): " + this); @@ -7487,7 +7487,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (!getTurnScreenOnFlag()) { return false; } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); return stack != null && !stack.inMultiWindowMode() && stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, diff --git a/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java b/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java index 5dfc261480f2..8540fa7cf347 100644 --- a/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java +++ b/services/core/java/com/android/server/wm/ActivityServiceConnectionsHolder.java @@ -16,10 +16,10 @@ package com.android.server.wm; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; +import static com.android.server.wm.Task.ActivityState.PAUSING; +import static com.android.server.wm.Task.ActivityState.RESUMED; import android.util.ArraySet; import android.util.Slog; diff --git a/services/core/java/com/android/server/wm/ActivityStack.java b/services/core/java/com/android/server/wm/ActivityStack.java deleted file mode 100644 index 9f0bf052ecad..000000000000 --- a/services/core/java/com/android/server/wm/ActivityStack.java +++ /dev/null @@ -1,3264 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wm; - -import static android.app.ActivityTaskManager.INVALID_TASK_ID; -import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; -import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; -import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; -import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; -import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; -import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; -import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; -import static android.app.WindowConfiguration.activityTypeToString; -import static android.app.WindowConfiguration.windowingModeToString; -import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; -import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING; -import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; -import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; -import static android.view.Display.DEFAULT_DISPLAY; -import static android.view.Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; -import static android.view.Display.INVALID_DISPLAY; -import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; -import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; -import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; -import static android.view.WindowManager.TRANSIT_NONE; -import static android.view.WindowManager.TRANSIT_SHOW_SINGLE_TASK_DISPLAY; -import static android.view.WindowManager.TRANSIT_TASK_CLOSE; -import static android.view.WindowManager.TRANSIT_TASK_OPEN; -import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND; -import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; -import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; - -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.ActivityState.STARTED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; -import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; -import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; -import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList; -import static com.android.server.wm.ActivityStackSupervisor.printThisActivity; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_APP; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TRANSITION; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_USER_LEAVING; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_ADD_REMOVE; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_APP; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CLEANUP; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_PAUSE; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RELEASE; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RESULTS; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TRANSITION; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_LEAVING; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; -import static com.android.server.wm.ActivityTaskManagerService.H.FIRST_ACTIVITY_STACK_MSG; -import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; -import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; -import static com.android.server.wm.TaskProto.ACTIVITY_TYPE; -import static com.android.server.wm.TaskProto.ANIMATING_BOUNDS; -import static com.android.server.wm.TaskProto.BOUNDS; -import static com.android.server.wm.TaskProto.CREATED_BY_ORGANIZER; -import static com.android.server.wm.TaskProto.DISPLAY_ID; -import static com.android.server.wm.TaskProto.FILLS_PARENT; -import static com.android.server.wm.TaskProto.LAST_NON_FULLSCREEN_BOUNDS; -import static com.android.server.wm.TaskProto.MIN_HEIGHT; -import static com.android.server.wm.TaskProto.MIN_WIDTH; -import static com.android.server.wm.TaskProto.ORIG_ACTIVITY; -import static com.android.server.wm.TaskProto.REAL_ACTIVITY; -import static com.android.server.wm.TaskProto.RESIZE_MODE; -import static com.android.server.wm.TaskProto.RESUMED_ACTIVITY; -import static com.android.server.wm.TaskProto.ROOT_TASK_ID; -import static com.android.server.wm.TaskProto.SURFACE_HEIGHT; -import static com.android.server.wm.TaskProto.SURFACE_WIDTH; -import static com.android.server.wm.TaskProto.WINDOW_CONTAINER; -import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; -import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; -import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; - -import static java.lang.Integer.MAX_VALUE; - -import android.annotation.IntDef; -import android.annotation.Nullable; -import android.app.Activity; -import android.app.ActivityManager; -import android.app.ActivityManagerInternal; -import android.app.ActivityOptions; -import android.app.AppGlobals; -import android.app.IActivityController; -import android.app.RemoteAction; -import android.app.ResultInfo; -import android.app.servertransaction.ActivityResultItem; -import android.app.servertransaction.ClientTransaction; -import android.app.servertransaction.NewIntentItem; -import android.app.servertransaction.PauseActivityItem; -import android.app.servertransaction.ResumeActivityItem; -import android.content.ComponentName; -import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.content.res.Configuration; -import android.graphics.Point; -import android.graphics.Rect; -import android.os.Binder; -import android.os.Debug; -import android.os.Handler; -import android.os.IBinder; -import android.os.Looper; -import android.os.Message; -import android.os.RemoteException; -import android.os.SystemClock; -import android.os.Trace; -import android.os.UserHandle; -import android.service.voice.IVoiceInteractionSession; -import android.util.Log; -import android.util.Slog; -import android.util.proto.ProtoOutputStream; -import android.view.Display; -import android.view.DisplayInfo; - -import com.android.internal.annotations.GuardedBy; -import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.app.IVoiceInteractor; -import com.android.internal.os.logging.MetricsLoggerWrapper; -import com.android.internal.util.function.pooled.PooledConsumer; -import com.android.internal.util.function.pooled.PooledFunction; -import com.android.internal.util.function.pooled.PooledLambda; -import com.android.server.Watchdog; -import com.android.server.am.ActivityManagerService; -import com.android.server.am.ActivityManagerService.ItemMatcher; -import com.android.server.am.AppTimeTracker; -import com.android.server.uri.NeededUriGrants; - -import java.io.FileDescriptor; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; - -/** - * State and management of a single stack of activities. - */ -class ActivityStack extends Task { - private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_ATM; - static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; - private static final String TAG_APP = TAG + POSTFIX_APP; - static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; - private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; - private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; - private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; - private static final String TAG_STACK = TAG + POSTFIX_STACK; - private static final String TAG_STATES = TAG + POSTFIX_STATES; - private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; - static final String TAG_TASKS = TAG + POSTFIX_TASKS; - private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; - private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; - static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; - - // Set to false to disable the preview that is shown while a new activity - // is being started. - private static final boolean SHOW_APP_STARTING_PREVIEW = true; - - // How long to wait for all background Activities to redraw following a call to - // convertToTranslucent(). - private static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; - - @IntDef(prefix = {"STACK_VISIBILITY"}, value = { - STACK_VISIBILITY_VISIBLE, - STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, - STACK_VISIBILITY_INVISIBLE, - }) - @interface StackVisibility {} - - /** Stack is visible. No other stacks on top that fully or partially occlude it. */ - static final int STACK_VISIBILITY_VISIBLE = 0; - - /** Stack is partially occluded by other translucent stack(s) on top of it. */ - static final int STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT = 1; - - /** Stack is completely invisible. */ - static final int STACK_VISIBILITY_INVISIBLE = 2; - - enum ActivityState { - INITIALIZING, - STARTED, - RESUMED, - PAUSING, - PAUSED, - STOPPING, - STOPPED, - FINISHING, - DESTROYING, - DESTROYED, - RESTARTING_PROCESS - } - - // The topmost Activity passed to convertToTranslucent(). When non-null it means we are - // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they - // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the - // Activity in mTranslucentActivityWaiting is notified via - // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last - // background activity being drawn then the same call will be made with a true value. - ActivityRecord mTranslucentActivityWaiting = null; - ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); - - /** - * Set when we know we are going to be calling updateConfiguration() - * soon, so want to skip intermediate config checks. - */ - boolean mConfigWillChange; - - /** - * Used to keep resumeTopActivityUncheckedLocked() from being entered recursively - */ - boolean mInResumeTopActivity = false; - - int mCurrentUser; - - /** For comparison with DisplayContent bounds. */ - private Rect mTmpRect = new Rect(); - private Rect mTmpRect2 = new Rect(); - - // If this is true, we are in the bounds animating mode. The task will be down or upscaled to - // perfectly fit the region it would have been cropped to. We may also avoid certain logic we - // would otherwise apply while resizing, while resizing in the bounds animating mode. - private boolean mBoundsAnimating = false; - // Set when an animation has been requested but has not yet started from the UI thread. This is - // cleared when the animation actually starts. - private boolean mBoundsAnimatingRequested = false; - private Rect mBoundsAnimationTarget = new Rect(); - private Rect mBoundsAnimationSourceHintBounds = new Rect(); - - Rect mPreAnimationBounds = new Rect(); - - private final AnimatingActivityRegistry mAnimatingActivityRegistry = - new AnimatingActivityRegistry(); - - private boolean mTopActivityOccludesKeyguard; - private ActivityRecord mTopDismissingKeyguardActivity; - - private static final int TRANSLUCENT_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 1; - - private final Handler mHandler; - - private class ActivityStackHandler extends Handler { - - ActivityStackHandler(Looper looper) { - super(looper); - } - - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case TRANSLUCENT_TIMEOUT_MSG: { - synchronized (mAtmService.mGlobalLock) { - notifyActivityDrawnLocked(null); - } - } break; - } - } - } - - private static final ResetTargetTaskHelper sResetTargetTaskHelper = new ResetTargetTaskHelper(); - private final EnsureActivitiesVisibleHelper mEnsureActivitiesVisibleHelper = - new EnsureActivitiesVisibleHelper(this); - private final EnsureVisibleActivitiesConfigHelper mEnsureVisibleActivitiesConfigHelper = - new EnsureVisibleActivitiesConfigHelper(); - private class EnsureVisibleActivitiesConfigHelper { - private boolean mUpdateConfig; - private boolean mPreserveWindow; - private boolean mBehindFullscreen; - - void reset(boolean preserveWindow) { - mPreserveWindow = preserveWindow; - mUpdateConfig = false; - mBehindFullscreen = false; - } - - void process(ActivityRecord start, boolean preserveWindow) { - if (start == null || !start.mVisibleRequested) { - return; - } - reset(preserveWindow); - - final PooledFunction f = PooledLambda.obtainFunction( - EnsureVisibleActivitiesConfigHelper::processActivity, this, - PooledLambda.__(ActivityRecord.class)); - forAllActivities(f, start, true /*includeBoundary*/, true /*traverseTopToBottom*/); - f.recycle(); - - if (mUpdateConfig) { - // Ensure the resumed state of the focus activity if we updated the configuration of - // any activity. - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - } - - boolean processActivity(ActivityRecord r) { - mUpdateConfig |= r.ensureActivityConfiguration(0 /*globalChanges*/, mPreserveWindow); - mBehindFullscreen |= r.occludesParent(); - return mBehindFullscreen; - } - } - - // TODO: Can we just loop through WindowProcessController#mActivities instead of doing this? - private final RemoveHistoryRecordsForApp mRemoveHistoryRecordsForApp = - new RemoveHistoryRecordsForApp(); - private class RemoveHistoryRecordsForApp { - private boolean mHasVisibleActivities; - private boolean mIsProcessRemoved; - private WindowProcessController mApp; - private ArrayList<ActivityRecord> mToRemove = new ArrayList<>(); - - boolean process(WindowProcessController app) { - mToRemove.clear(); - mHasVisibleActivities = false; - mApp = app; - mIsProcessRemoved = app.isRemoved(); - if (mIsProcessRemoved) { - // The package of the died process should be force-stopped, so make its activities - // as finishing to prevent the process from being started again if the next top - // (or being visible) activity also resides in the same process. - app.makeFinishingForProcessRemoved(); - } - - final PooledConsumer c = PooledLambda.obtainConsumer( - RemoveHistoryRecordsForApp::addActivityToRemove, this, - PooledLambda.__(ActivityRecord.class)); - forAllActivities(c); - c.recycle(); - - while (!mToRemove.isEmpty()) { - processActivity(mToRemove.remove(0)); - } - - mApp = null; - return mHasVisibleActivities; - } - - private void addActivityToRemove(ActivityRecord r) { - if (r.app == mApp) { - mToRemove.add(r); - } - } - - private void processActivity(ActivityRecord r) { - if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record " + r + ": app=" + r.app); - - if (r.app != mApp) { - return; - } - if (r.isVisible() || r.mVisibleRequested) { - // While an activity launches a new activity, it's possible that the old - // activity is already requested to be hidden (mVisibleRequested=false), but - // this visibility is not yet committed, so isVisible()=true. - mHasVisibleActivities = true; - } - final boolean remove; - if ((r.mRelaunchReason == RELAUNCH_REASON_WINDOWING_MODE_RESIZE - || r.mRelaunchReason == RELAUNCH_REASON_FREE_RESIZE) - && r.launchCount < 3 && !r.finishing) { - // If the process crashed during a resize, always try to relaunch it, unless - // it has failed more than twice. Skip activities that's already finishing - // cleanly by itself. - remove = false; - } else if ((!r.hasSavedState() && !r.stateNotNeeded - && !r.isState(ActivityState.RESTARTING_PROCESS)) || r.finishing) { - // Don't currently have state for the activity, or - // it is finishing -- always remove it. - remove = true; - } else if (!r.mVisibleRequested && r.launchCount > 2 - && r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { - // We have launched this activity too many times since it was - // able to run, so give up and remove it. - // (Note if the activity is visible, we don't remove the record. - // We leave the dead window on the screen but the process will - // not be restarted unless user explicitly tap on it.) - remove = true; - } else { - // The process may be gone, but the activity lives on! - remove = false; - } - if (remove) { - if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, - "Removing activity " + r + " from stack " - + ": hasSavedState=" + r.hasSavedState() - + " stateNotNeeded=" + r.stateNotNeeded - + " finishing=" + r.finishing - + " state=" + r.getState() + " callers=" + Debug.getCallers(5)); - if (!r.finishing || mIsProcessRemoved) { - Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); - EventLogTags.writeWmFinishActivity(r.mUserId, - System.identityHashCode(r), r.getTask().mTaskId, - r.shortComponentName, "proc died without state saved"); - } - } else { - // We have the current state for this activity, so - // it can be restarted later when needed. - if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); - if (DEBUG_APP) Slog.v(TAG_APP, - "Clearing app during removeHistory for activity " + r); - r.app = null; - // Set nowVisible to previous visible state. If the app was visible while - // it died, we leave the dead window on screen so it's basically visible. - // This is needed when user later tap on the dead window, we need to stop - // other apps when user transfers focus to the restarted activity. - r.nowVisible = r.mVisibleRequested; - } - r.cleanUp(true /* cleanServices */, true /* setState */); - if (remove) { - r.removeFromHistory("appDied"); - } - } - } - - ActivityStack(ActivityTaskManagerService atmService, int id, int activityType, - ActivityInfo info, Intent intent, boolean createdByOrganizer) { - this(atmService, id, info, intent, null /*voiceSession*/, null /*voiceInteractor*/, - null /*taskDescription*/, null /*stack*/); - mCreatedByOrganizer = createdByOrganizer; - setActivityType(activityType); - } - - ActivityStack(ActivityTaskManagerService atmService, int id, ActivityInfo info, Intent _intent, - IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, - ActivityManager.TaskDescription _taskDescription, ActivityStack stack) { - this(atmService, id, _intent, null /*_affinityIntent*/, null /*_affinity*/, - null /*_rootAffinity*/, null /*_realActivity*/, null /*_origActivity*/, - false /*_rootWasReset*/, false /*_autoRemoveRecents*/, false /*_askedCompatMode*/, - UserHandle.getUserId(info.applicationInfo.uid), 0 /*_effectiveUid*/, - null /*_lastDescription*/, System.currentTimeMillis(), - true /*neverRelinquishIdentity*/, - _taskDescription != null ? _taskDescription : new ActivityManager.TaskDescription(), - id, INVALID_TASK_ID, INVALID_TASK_ID, - info.applicationInfo.uid, info.packageName, null, info.resizeMode, - info.supportsPictureInPicture(), false /*_realActivitySuspended*/, - false /*userSetupComplete*/, INVALID_MIN_SIZE, INVALID_MIN_SIZE, info, - _voiceSession, _voiceInteractor, stack); - } - - ActivityStack(ActivityTaskManagerService atmService, int id, Intent _intent, - Intent _affinityIntent, String _affinity, String _rootAffinity, - ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset, - boolean _autoRemoveRecents, boolean _askedCompatMode, int _userId, int _effectiveUid, - String _lastDescription, long lastTimeMoved, boolean neverRelinquishIdentity, - ActivityManager.TaskDescription _lastTaskDescription, int taskAffiliation, - int prevTaskId, int nextTaskId, int callingUid, - String callingPackage, @Nullable String callingFeatureId, int resizeMode, - boolean supportsPictureInPicture, boolean _realActivitySuspended, - boolean userSetupComplete, int minWidth, int minHeight, - ActivityInfo info, IVoiceInteractionSession _voiceSession, - IVoiceInteractor _voiceInteractor, ActivityStack stack) { - super(atmService, id, _intent, _affinityIntent, _affinity, _rootAffinity, - _realActivity, _origActivity, _rootWasReset, _autoRemoveRecents, _askedCompatMode, - _userId, _effectiveUid, _lastDescription, lastTimeMoved, neverRelinquishIdentity, - _lastTaskDescription, taskAffiliation, prevTaskId, nextTaskId, - callingUid, callingPackage, callingFeatureId, resizeMode, supportsPictureInPicture, - _realActivitySuspended, userSetupComplete, minWidth, minHeight, info, _voiceSession, - _voiceInteractor, stack); - - EventLogTags.writeWmStackCreated(id); - mHandler = new ActivityStackHandler(mStackSupervisor.mLooper); - mCurrentUser = mAtmService.mAmInternal.getCurrentUserId(); - } - - @Override - public void onConfigurationChanged(Configuration newParentConfig) { - // Calling Task#onConfigurationChanged() for leaf task since the ops in this method are - // particularly for ActivityStack, like preventing bounds changes when inheriting certain - // windowing mode. - if (!isRootTask()) { - super.onConfigurationChanged(newParentConfig); - return; - } - - final int prevWindowingMode = getWindowingMode(); - final boolean prevIsAlwaysOnTop = isAlwaysOnTop(); - final int prevRotation = getWindowConfiguration().getRotation(); - final Rect newBounds = mTmpRect; - // Initialize the new bounds by previous bounds as the input and output for calculating - // override bounds in pinned (pip) or split-screen mode. - getBounds(newBounds); - - super.onConfigurationChanged(newParentConfig); - - final TaskDisplayArea taskDisplayArea = getDisplayArea(); - if (taskDisplayArea == null) { - return; - } - - if (prevWindowingMode != getWindowingMode()) { - taskDisplayArea.onStackWindowingModeChanged(this); - } - - final DisplayContent display = getDisplay(); - if (display == null ) { - return; - } - - final boolean windowingModeChanged = prevWindowingMode != getWindowingMode(); - final int overrideWindowingMode = getRequestedOverrideWindowingMode(); - // Update bounds if applicable - boolean hasNewOverrideBounds = false; - // Use override windowing mode to prevent extra bounds changes if inheriting the mode. - if ((overrideWindowingMode != WINDOWING_MODE_PINNED) - && !getRequestedOverrideBounds().isEmpty()) { - // If the parent (display) has rotated, rotate our bounds to best-fit where their - // bounds were on the pre-rotated display. - final int newRotation = getWindowConfiguration().getRotation(); - final boolean rotationChanged = prevRotation != newRotation; - if (rotationChanged) { - display.mDisplayContent.rotateBounds( - newParentConfig.windowConfiguration.getBounds(), prevRotation, newRotation, - newBounds); - hasNewOverrideBounds = true; - } - } - - if (windowingModeChanged) { - taskDisplayArea.onStackWindowingModeChanged(this); - } - if (hasNewOverrideBounds) { - if (inSplitScreenWindowingMode()) { - setBounds(newBounds); - } else if (overrideWindowingMode != WINDOWING_MODE_PINNED) { - // For pinned stack, resize is now part of the {@link WindowContainerTransaction} - resize(new Rect(newBounds), PRESERVE_WINDOWS, true /* deferResume */); - } - } - if (prevIsAlwaysOnTop != isAlwaysOnTop()) { - // Since always on top is only on when the stack is freeform or pinned, the state - // can be toggled when the windowing mode changes. We must make sure the stack is - // placed properly when always on top state changes. - taskDisplayArea.positionStackAtTop(this, false /* includingParents */); - } - } - - @Override - public void setWindowingMode(int windowingMode) { - // Reset the cached result of toString() - stringName = null; - - // Calling Task#setWindowingMode() for leaf task since this is the a specialization of - // {@link #setWindowingMode(int)} for ActivityStack. - if (!isRootTask()) { - super.setWindowingMode(windowingMode); - return; - } - - setWindowingMode(windowingMode, false /* creating */); - } - - /** - * Specialization of {@link #setWindowingMode(int)} for this subclass. - * - * @param preferredWindowingMode the preferred windowing mode. This may not be honored depending - * on the state of things. For example, WINDOWING_MODE_UNDEFINED will resolve to the - * previous non-transient mode if this stack is currently in a transient mode. - * @param creating {@code true} if this is being run during ActivityStack construction. - */ - void setWindowingMode(int preferredWindowingMode, boolean creating) { - mWmService.inSurfaceTransaction(() -> setWindowingModeInSurfaceTransaction( - preferredWindowingMode, creating)); - } - - private void setWindowingModeInSurfaceTransaction(int preferredWindowingMode, - boolean creating) { - final TaskDisplayArea taskDisplayArea = getDisplayArea(); - if (taskDisplayArea == null) { - Slog.d(TAG, "taskDisplayArea is null, bail early"); - return; - } - final int currentMode = getWindowingMode(); - final int currentOverrideMode = getRequestedOverrideWindowingMode(); - final Task topTask = getTopMostTask(); - int windowingMode = preferredWindowingMode; - - // Need to make sure windowing mode is supported. If we in the process of creating the stack - // no need to resolve the windowing mode again as it is already resolved to the right mode. - if (!creating) { - if (!taskDisplayArea.isValidWindowingMode(windowingMode, null /* ActivityRecord */, - topTask, getActivityType())) { - windowingMode = WINDOWING_MODE_UNDEFINED; - } - } - - final boolean alreadyInSplitScreenMode = taskDisplayArea.isSplitScreenModeActivated(); - - if (creating && alreadyInSplitScreenMode && windowingMode == WINDOWING_MODE_FULLSCREEN - && isActivityTypeStandardOrUndefined()) { - // If the stack is being created explicitly in fullscreen mode, dismiss split-screen - // and display a warning toast about it. - mAtmService.getTaskChangeNotificationController() - .notifyActivityDismissingDockedStack(); - taskDisplayArea.onSplitScreenModeDismissed(this); - } - - if (currentMode == windowingMode) { - // You are already in the window mode, so we can skip most of the work below. However, - // it's possible that we have inherited the current windowing mode from a parent. So, - // fulfill this method's contract by setting the override mode directly. - getRequestedOverrideConfiguration().windowConfiguration.setWindowingMode(windowingMode); - return; - } - - final ActivityRecord topActivity = getTopNonFinishingActivity(); - - // For now, assume that the Stack's windowing mode is what will actually be used - // by it's activities. In the future, there may be situations where this doesn't - // happen; so at that point, this message will need to handle that. - int likelyResolvedMode = windowingMode; - if (windowingMode == WINDOWING_MODE_UNDEFINED) { - final ConfigurationContainer parent = getParent(); - likelyResolvedMode = parent != null ? parent.getWindowingMode() - : WINDOWING_MODE_FULLSCREEN; - } - if (currentMode == WINDOWING_MODE_PINNED) { - mAtmService.getTaskChangeNotificationController().notifyActivityUnpinned(); - } - if (likelyResolvedMode == WINDOWING_MODE_PINNED - && taskDisplayArea.getRootPinnedTask() != null) { - // Can only have 1 pip at a time, so replace an existing pip - taskDisplayArea.getRootPinnedTask().dismissPip(); - } - if (likelyResolvedMode != WINDOWING_MODE_FULLSCREEN - && topActivity != null && !topActivity.noDisplay - && topActivity.isNonResizableOrForcedResizable(likelyResolvedMode)) { - // Inform the user that they are starting an app that may not work correctly in - // multi-window mode. - final String packageName = topActivity.info.applicationInfo.packageName; - mAtmService.getTaskChangeNotificationController().notifyActivityForcedResizable( - topTask.mTaskId, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN, packageName); - } - - mAtmService.deferWindowLayout(); - try { - if (topActivity != null) { - mStackSupervisor.mNoAnimActivities.add(topActivity); - } - super.setWindowingMode(windowingMode); - // setWindowingMode triggers an onConfigurationChanged cascade which can result in a - // different resolved windowing mode (usually when preferredWindowingMode is UNDEFINED). - windowingMode = getWindowingMode(); - - if (creating) { - // Nothing else to do if we don't have a window container yet. E.g. call from ctor. - return; - } - - if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && alreadyInSplitScreenMode) { - // We already have a split-screen stack in this display, so just move the tasks over. - // TODO: Figure-out how to do all the stuff in - // AMS.setTaskWindowingModeSplitScreenPrimary - throw new IllegalArgumentException("Setting primary split-screen windowing mode" - + " while there is already one isn't currently supported"); - //return; - } - } finally { - mAtmService.continueWindowLayout(); - } - - mRootWindowContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS); - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - - @Override - public boolean isCompatible(int windowingMode, int activityType) { - // TODO: Should we just move this to ConfigurationContainer? - if (activityType == ACTIVITY_TYPE_UNDEFINED) { - // Undefined activity types end up in a standard stack once the stack is created on a - // display, so they should be considered compatible. - activityType = ACTIVITY_TYPE_STANDARD; - } - return super.isCompatible(windowingMode, activityType); - } - - /** Resume next focusable stack after reparenting to another display. */ - void postReparent() { - adjustFocusToNextFocusableTask("reparent", true /* allowFocusSelf */, - true /* moveDisplayToTop */); - mRootWindowContainer.resumeFocusedStacksTopActivities(); - // Update visibility of activities before notifying WM. This way it won't try to resize - // windows that are no longer visible. - mRootWindowContainer.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, - !PRESERVE_WINDOWS); - } - - DisplayContent getDisplay() { - return getDisplayContent(); - } - - /** @return true if the stack can only contain one task */ - boolean isSingleTaskInstance() { - final DisplayContent display = getDisplay(); - return display != null && display.isSingleTaskInstance(); - } - - final boolean isHomeOrRecentsStack() { - return isActivityTypeHome() || isActivityTypeRecents(); - } - - final boolean isOnHomeDisplay() { - return getDisplayId() == DEFAULT_DISPLAY; - } - - void moveToFront(String reason) { - moveToFront(reason, null); - } - - /** - * @param reason The reason for moving the stack to the front. - * @param task If non-null, the task will be moved to the top of the stack. - * */ - void moveToFront(String reason, Task task) { - if (!isAttached()) { - return; - } - - final TaskDisplayArea taskDisplayArea = getDisplayArea(); - - if (inSplitScreenSecondaryWindowingMode()) { - // If the stack is in split-screen secondary mode, we need to make sure we move the - // primary split-screen stack forward in the case it is currently behind a fullscreen - // stack so both halves of the split-screen appear on-top and the fullscreen stack isn't - // cutting between them. - // TODO(b/70677280): This is a workaround until we can fix as part of b/70677280. - final ActivityStack topFullScreenStack = - taskDisplayArea.getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); - if (topFullScreenStack != null) { - final ActivityStack primarySplitScreenStack = - taskDisplayArea.getRootSplitScreenPrimaryTask(); - if (primarySplitScreenStack != null - && taskDisplayArea.getIndexOf(topFullScreenStack) - > taskDisplayArea.getIndexOf(primarySplitScreenStack)) { - primarySplitScreenStack.moveToFront(reason + " splitScreenToTop"); - } - } - } - - if (!isActivityTypeHome() && returnsToHomeStack()) { - // Make sure the home stack is behind this stack since that is where we should return to - // when this stack is no longer visible. - taskDisplayArea.moveHomeStackToFront(reason + " returnToHome"); - } - - if (isRootTask()) { - taskDisplayArea.positionStackAtTop(this, false /* includingParents */, reason); - } - if (task == null) { - task = this; - } - task.getParent().positionChildAt(POSITION_TOP, task, true /* includingParents */); - } - - /** - * This moves 'task' to the back of this task and also recursively moves this task to the back - * of its parents (if applicable). - * - * @param reason The reason for moving the stack to the back. - * @param task If non-null, the task will be moved to the bottom of the stack. - **/ - void moveToBack(String reason, Task task) { - if (!isAttached()) { - return; - } - final TaskDisplayArea displayArea = getDisplayArea(); - if (!mCreatedByOrganizer) { - // If this is just a normal task, so move to back of parent and then move 'task' to - // back of this. - final WindowContainer parent = getParent(); - final Task parentTask = parent != null ? parent.asTask() : null; - if (parentTask != null) { - ((ActivityStack) parentTask).moveToBack(reason, this); - } else { - displayArea.positionStackAtBottom(this, reason); - } - if (task != null && task != this) { - positionChildAtBottom(task); - } - return; - } - if (task == null || task == this) { - return; - } - // This is a created-by-organizer task. In this case, let the organizer deal with this - // task's ordering. However, we still need to move 'task' to back. The intention is that - // this ends up behind the home-task so that it is made invisible; so, if the home task - // is not a child of this, reparent 'task' to the back of the home task's actual parent. - displayArea.positionTaskBehindHome((ActivityStack) task); - } - - // TODO: Should each user have there own stacks? - @Override - void switchUser(int userId) { - if (mCurrentUser == userId) { - return; - } - mCurrentUser = userId; - - super.switchUser(userId); - forAllLeafTasks((t) -> { - if (t.showToCurrentUser() && t != this) { - mChildren.remove(t); - mChildren.add(t); - } - }, true /* traverseTopToBottom */); - } - - void minimalResumeActivityLocked(ActivityRecord r) { - if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" - + " callers=" + Debug.getCallers(5)); - r.setState(RESUMED, "minimalResumeActivityLocked"); - r.completeResumeLocked(); - } - - private void clearLaunchTime(ActivityRecord r) { - // Make sure that there is no activity waiting for this to launch. - if (!mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { - mStackSupervisor.removeIdleTimeoutForActivity(r); - mStackSupervisor.scheduleIdleTimeout(r); - } - } - - void awakeFromSleepingLocked() { - // Ensure activities are no longer sleeping. - forAllActivities((Consumer<ActivityRecord>) (r) -> r.setSleeping(false)); - if (mPausingActivity != null) { - Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); - mPausingActivity.activityPaused(true); - } - } - - void checkReadyForSleep() { - if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) { - mStackSupervisor.checkReadyForSleepLocked(true /* allowDelay */); - } - } - - /** - * Tries to put the activities in the stack to sleep. - * - * If the stack is not in a state where its activities can be put to sleep, this function will - * start any necessary actions to move the stack into such a state. It is expected that this - * function get called again when those actions complete. - * - * @param shuttingDown true when the called because the device is shutting down. - * @return true if the stack finished going to sleep, false if the stack only started the - * process of going to sleep (checkReadyForSleep will be called when that process finishes). - */ - boolean goToSleepIfPossible(boolean shuttingDown) { - boolean shouldSleep = true; - - if (mResumedActivity != null) { - // Still have something resumed; can't sleep until it is paused. - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); - if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, - "Sleep => pause with userLeaving=false"); - - startPausingLocked(false /* userLeaving */, true /* uiSleeping */, null /* resuming */); - shouldSleep = false ; - } else if (mPausingActivity != null) { - // Still waiting for something to pause; can't sleep yet. - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still waiting to pause " + mPausingActivity); - shouldSleep = false; - } - - if (!shuttingDown) { - if (containsActivityFromStack(mStackSupervisor.mStoppingActivities)) { - // Still need to tell some activities to stop; can't sleep yet. - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " - + mStackSupervisor.mStoppingActivities.size() + " activities"); - - mStackSupervisor.scheduleIdle(); - shouldSleep = false; - } - } - - if (shouldSleep) { - goToSleep(); - } - - return shouldSleep; - } - - void goToSleep() { - // Make sure all visible activities are now sleeping. This will update the activity's - // visibility and onStop() will be called. - forAllActivities((r) -> { - if (r.isState(STARTED, RESUMED, PAUSING, PAUSED, STOPPING, STOPPED)) { - r.setSleeping(true); - } - }); - - // Ensure visibility after updating sleep states without updating configuration, - // as activities are about to be sent to sleep. - ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, - !PRESERVE_WINDOWS); - } - - private boolean containsActivityFromStack(List<ActivityRecord> rs) { - for (ActivityRecord r : rs) { - if (r.getRootTask() == this) { - return true; - } - } - return false; - } - - /** - * Start pausing the currently resumed activity. It is an error to call this if there - * is already an activity being paused or there is no resumed activity. - * - * @param userLeaving True if this should result in an onUserLeaving to the current activity. - * @param uiSleeping True if this is happening with the user interface going to sleep (the - * screen turning off). - * @param resuming The activity we are currently trying to resume or null if this is not being - * called as part of resuming the top activity, so we shouldn't try to instigate - * a resume here if not null. - * @return Returns true if an activity now is in the PAUSING state, and we are waiting for - * it to tell us when it is done. - */ - final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, - ActivityRecord resuming) { - if (mPausingActivity != null) { - Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity - + " state=" + mPausingActivity.getState()); - if (!shouldSleepActivities()) { - // 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, resuming); - } - } - ActivityRecord prev = mResumedActivity; - - if (prev == null) { - if (resuming == null) { - Slog.wtf(TAG, "Trying to pause when nothing is resumed"); - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - return false; - } - - if (prev == resuming) { - Slog.wtf(TAG, "Trying to pause activity that is in process of being resumed"); - return false; - } - - if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); - else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); - mPausingActivity = prev; - mLastPausedActivity = prev; - mLastNoHistoryActivity = prev.isNoHistory() ? prev : null; - prev.setState(PAUSING, "startPausingLocked"); - prev.getTask().touchActiveTime(); - clearLaunchTime(prev); - - mAtmService.updateCpuStats(); - - boolean pauseImmediately = false; - if (resuming != null && (resuming.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0) { - // If the flag RESUME_WHILE_PAUSING is set, then continue to schedule the previous - // activity to be paused, while at the same time resuming the new resume activity - // only if the previous activity can't go into Pip since we want to give Pip - // activities a chance to enter Pip before resuming the next activity. - final boolean lastResumedCanPip = prev != null && prev.checkEnterPictureInPictureState( - "shouldResumeWhilePausing", userLeaving); - if (!lastResumedCanPip) { - pauseImmediately = true; - } - } - - if (prev.attachedToProcess()) { - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); - try { - EventLogTags.writeWmPauseActivity(prev.mUserId, System.identityHashCode(prev), - prev.shortComponentName, "userLeaving=" + userLeaving); - - mAtmService.getLifecycleManager().scheduleTransaction(prev.app.getThread(), - prev.appToken, PauseActivityItem.obtain(prev.finishing, userLeaving, - prev.configChangeFlags, pauseImmediately)); - } catch (Exception e) { - // Ignore exception, if process died other code will cleanup. - Slog.w(TAG, "Exception thrown during pause", e); - mPausingActivity = null; - mLastPausedActivity = null; - mLastNoHistoryActivity = null; - } - } else { - mPausingActivity = null; - mLastPausedActivity = null; - mLastNoHistoryActivity = null; - } - - // If we are not going to sleep, we want to ensure the device is - // awake until the next activity is started. - if (!uiSleeping && !mAtmService.isSleepingOrShuttingDownLocked()) { - mStackSupervisor.acquireLaunchWakelock(); - } - - if (mPausingActivity != null) { - // Have the window manager pause its key dispatching until the new - // activity has started. If we're pausing the activity just because - // the screen is being turned off and the UI is sleeping, don't interrupt - // key dispatch; the same activity will pick it up again on wakeup. - if (!uiSleeping) { - prev.pauseKeyDispatchingLocked(); - } else if (DEBUG_PAUSE) { - Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); - } - - if (pauseImmediately) { - // If the caller said they don't want to wait for the pause, then complete - // the pause now. - completePauseLocked(false, resuming); - return false; - - } else { - prev.schedulePauseTimeout(); - return true; - } - - } else { - // This activity failed to schedule the - // pause, so just treat it as being paused now. - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); - if (resuming == null) { - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - return false; - } - } - - @VisibleForTesting - void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { - ActivityRecord prev = mPausingActivity; - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); - - if (prev != null) { - prev.setWillCloseOrEnterPip(false); - final boolean wasStopping = prev.isState(STOPPING); - prev.setState(PAUSED, "completePausedLocked"); - if (prev.finishing) { - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); - prev = prev.completeFinishing("completePausedLocked"); - } else if (prev.hasProcess()) { - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev - + " wasStopping=" + wasStopping - + " visibleRequested=" + prev.mVisibleRequested); - if (prev.deferRelaunchUntilPaused) { - // Complete the deferred relaunch that was waiting for pause to complete. - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); - prev.relaunchActivityLocked(prev.preserveWindowOnDeferredRelaunch); - } else if (wasStopping) { - // We are also stopping, the stop request must have gone soon after the pause. - // We can't clobber it, because the stop confirmation will not be handled. - // We don't need to schedule another stop, we only need to let it happen. - prev.setState(STOPPING, "completePausedLocked"); - } else if (!prev.mVisibleRequested || shouldSleepOrShutDownActivities()) { - // Clear out any deferred client hide we might currently have. - prev.setDeferHidingClient(false); - // If we were visible then resumeTopActivities will release resources before - // stopping. - prev.addToStopping(true /* scheduleIdle */, false /* idleDelayed */, - "completePauseLocked"); - } - } else { - if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "App died during pause, not stopping: " + prev); - prev = null; - } - // It is possible the activity was freezing the screen before it was paused. - // In that case go ahead and remove the freeze this activity has on the screen - // since it is no longer visible. - if (prev != null) { - prev.stopFreezingScreenLocked(true /*force*/); - } - mPausingActivity = null; - } - - if (resumeNext) { - final ActivityStack topStack = mRootWindowContainer.getTopDisplayFocusedStack(); - if (topStack != null && !topStack.shouldSleepOrShutDownActivities()) { - mRootWindowContainer.resumeFocusedStacksTopActivities(topStack, prev, null); - } else { - checkReadyForSleep(); - final ActivityRecord top = topStack != null ? topStack.topRunningActivity() : null; - if (top == null || (prev != null && top != prev)) { - // If there are no more activities available to run, do resume anyway to start - // something. Also if the top activity on the stack is not the just paused - // activity, we need to go ahead and resume it to ensure we complete an - // in-flight app switch. - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - } - } - - if (prev != null) { - prev.resumeKeyDispatchingLocked(); - - if (prev.hasProcess() && prev.cpuTimeAtResume > 0) { - final long diff = prev.app.getCpuTime() - prev.cpuTimeAtResume; - if (diff > 0) { - final Runnable r = PooledLambda.obtainRunnable( - ActivityManagerInternal::updateForegroundTimeIfOnBattery, - mAtmService.mAmInternal, prev.info.packageName, - prev.info.applicationInfo.uid, - diff); - mAtmService.mH.post(r); - } - } - prev.cpuTimeAtResume = 0; // reset it - } - - mRootWindowContainer.ensureActivitiesVisible(resuming, 0, !PRESERVE_WINDOWS); - - // Notify when the task stack has changed, but only if visibilities changed (not just - // focus). Also if there is an active pinned stack - we always want to notify it about - // task stack changes, because its positioning may depend on it. - if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause - || (getDisplayArea() != null && getDisplayArea().hasPinnedTask())) { - mAtmService.getTaskChangeNotificationController().notifyTaskStackChanged(); - mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; - } - } - - boolean isTopStackInDisplayArea() { - final TaskDisplayArea taskDisplayArea = getDisplayArea(); - return taskDisplayArea != null && taskDisplayArea.isTopStack(this); - } - - /** - * @return {@code true} if this is the focused stack on its current display, {@code false} - * otherwise. - */ - boolean isFocusedStackOnDisplay() { - final DisplayContent display = getDisplay(); - return display != null && this == display.getFocusedStack(); - } - - /** - * Make sure that all activities that need to be visible in the stack (that is, they - * currently can be seen by the user) actually are and update their configuration. - * @param starting The top most activity in the task. - * The activity is either starting or resuming. - * Caller should ensure starting activity is visible. - * @param preserveWindows Flag indicating whether windows should be preserved when updating - * configuration in {@link mEnsureActivitiesVisibleHelper}. - * @param configChanges Parts of the configuration that changed for this activity for evaluating - * if the screen should be frozen as part of - * {@link mEnsureActivitiesVisibleHelper}. - * - */ - void ensureActivitiesVisible(@Nullable ActivityRecord starting, int configChanges, - boolean preserveWindows) { - ensureActivitiesVisible(starting, configChanges, preserveWindows, true /* notifyClients */); - } - - /** - * Ensure visibility with an option to also update the configuration of visible activities. - * @see #ensureActivitiesVisible(ActivityRecord, int, boolean) - * @see RootWindowContainer#ensureActivitiesVisible(ActivityRecord, int, boolean) - * @param starting The top most activity in the task. - * The activity is either starting or resuming. - * Caller should ensure starting activity is visible. - * @param notifyClients Flag indicating whether the visibility updates should be sent to the - * clients in {@link mEnsureActivitiesVisibleHelper}. - * @param preserveWindows Flag indicating whether windows should be preserved when updating - * configuration in {@link mEnsureActivitiesVisibleHelper}. - * @param configChanges Parts of the configuration that changed for this activity for evaluating - * if the screen should be frozen as part of - * {@link mEnsureActivitiesVisibleHelper}. - */ - // TODO: Should be re-worked based on the fact that each task as a stack in most cases. - void ensureActivitiesVisible(@Nullable ActivityRecord starting, int configChanges, - boolean preserveWindows, boolean notifyClients) { - mTopActivityOccludesKeyguard = false; - mTopDismissingKeyguardActivity = null; - mStackSupervisor.beginActivityVisibilityUpdate(); - try { - mEnsureActivitiesVisibleHelper.process( - starting, configChanges, preserveWindows, notifyClients); - - if (mTranslucentActivityWaiting != null && - mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { - // Nothing is getting drawn or everything was already visible, don't wait for timeout. - notifyActivityDrawnLocked(null); - } - } finally { - mStackSupervisor.endActivityVisibilityUpdate(); - } - } - - /** - * @return true if the top visible activity wants to occlude the Keyguard, false otherwise - */ - boolean topActivityOccludesKeyguard() { - return mTopActivityOccludesKeyguard; - } - - /** - * Returns true if this stack should be resized to match the bounds specified by - * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack. - */ - boolean shouldResizeStackWithLaunchBounds() { - return inPinnedWindowingMode(); - } - - // TODO(NOW!) - /** - * Returns {@code true} if this is the top-most split-screen-primary or - * split-screen-secondary stack, {@code false} otherwise. - */ - boolean isTopSplitScreenStack() { - return inSplitScreenWindowingMode() - && this == getDisplayArea().getTopStackInWindowingMode(getWindowingMode()); - } - - /** - * @return the top most visible activity that wants to dismiss Keyguard - */ - ActivityRecord getTopDismissingKeyguardActivity() { - return mTopDismissingKeyguardActivity; - } - - /** - * Checks whether {@param r} should be visible depending on Keyguard state and updates - * {@link #mTopActivityOccludesKeyguard} and {@link #mTopDismissingKeyguardActivity} if - * necessary. - * - * @return true if {@param r} is visible taken Keyguard state into account, false otherwise - */ - boolean checkKeyguardVisibility(ActivityRecord r, boolean shouldBeVisible, boolean isTop) { - int displayId = getDisplayId(); - if (displayId == INVALID_DISPLAY) displayId = DEFAULT_DISPLAY; - - final boolean keyguardOrAodShowing = mStackSupervisor.getKeyguardController() - .isKeyguardOrAodShowing(displayId); - final boolean keyguardLocked = mStackSupervisor.getKeyguardController().isKeyguardLocked(); - final boolean showWhenLocked = r.canShowWhenLocked(); - final boolean dismissKeyguard = r.containsDismissKeyguardWindow(); - if (shouldBeVisible) { - if (dismissKeyguard && mTopDismissingKeyguardActivity == null) { - mTopDismissingKeyguardActivity = r; - } - - // Only the top activity may control occluded, as we can't occlude the Keyguard if the - // top app doesn't want to occlude it. - if (isTop) { - mTopActivityOccludesKeyguard |= showWhenLocked; - } - - final boolean canShowWithKeyguard = canShowWithInsecureKeyguard() - && mStackSupervisor.getKeyguardController().canDismissKeyguard(); - if (canShowWithKeyguard) { - return true; - } - } - if (keyguardOrAodShowing) { - // If keyguard is showing, nothing is visible, except if we are able to dismiss Keyguard - // right away and AOD isn't visible. - return shouldBeVisible && mStackSupervisor.getKeyguardController() - .canShowActivityWhileKeyguardShowing(r, dismissKeyguard); - } else if (keyguardLocked) { - return shouldBeVisible && mStackSupervisor.getKeyguardController().canShowWhileOccluded( - dismissKeyguard, showWhenLocked); - } else { - return shouldBeVisible; - } - } - - /** - * Check if the display to which this stack is attached has - * {@link Display#FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD} applied. - */ - boolean canShowWithInsecureKeyguard() { - final DisplayContent displayContent = getDisplay(); - if (displayContent == null) { - throw new IllegalStateException("Stack is not attached to any display, stackId=" - + getRootTaskId()); - } - - final int flags = displayContent.mDisplay.getFlags(); - return (flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0; - } - - void checkTranslucentActivityWaiting(ActivityRecord top) { - if (mTranslucentActivityWaiting != top) { - mUndrawnActivitiesBelowTopTranslucent.clear(); - if (mTranslucentActivityWaiting != null) { - // Call the callback with a timeout indication. - notifyActivityDrawnLocked(null); - mTranslucentActivityWaiting = null; - } - mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); - } - } - - void convertActivityToTranslucent(ActivityRecord r) { - mTranslucentActivityWaiting = r; - mUndrawnActivitiesBelowTopTranslucent.clear(); - mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); - } - - /** - * Called as activities below the top translucent activity are redrawn. When the last one is - * redrawn notify the top activity by calling - * {@link Activity#onTranslucentConversionComplete}. - * - * @param r The most recent background activity to be drawn. Or, if r is null then a timeout - * occurred and the activity will be notified immediately. - */ - void notifyActivityDrawnLocked(ActivityRecord r) { - if ((r == null) - || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && - mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { - // The last undrawn activity below the top has just been drawn. If there is an - // opaque activity at the top, notify it that it can become translucent safely now. - final ActivityRecord waitingActivity = mTranslucentActivityWaiting; - mTranslucentActivityWaiting = null; - mUndrawnActivitiesBelowTopTranslucent.clear(); - mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); - - if (waitingActivity != null) { - mWmService.setWindowOpaqueLocked(waitingActivity.appToken, false); - if (waitingActivity.attachedToProcess()) { - try { - waitingActivity.app.getThread().scheduleTranslucentConversionComplete( - waitingActivity.appToken, r != null); - } catch (RemoteException e) { - } - } - } - } - } - - /** - * Ensure that the top activity in the stack is resumed. - * - * @param prev The previously resumed activity, for when in the process - * of pausing; can be null to call from elsewhere. - * @param options Activity options. - * - * @return Returns true if something is being resumed, or false if - * nothing happened. - * - * NOTE: It is not safe to call this method directly as it can cause an activity in a - * non-focused stack to be resumed. - * Use {@link RootWindowContainer#resumeFocusedStacksTopActivities} to resume the - * right activity for the current system state. - */ - @GuardedBy("mService") - boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { - if (mInResumeTopActivity) { - // Don't even start recursing. - return false; - } - - boolean result = false; - try { - // Protect against recursion. - mInResumeTopActivity = true; - result = resumeTopActivityInnerLocked(prev, options); - - // When resuming the top activity, it may be necessary to pause the top activity (for - // example, returning to the lock screen. We suppress the normal pause logic in - // {@link #resumeTopActivityUncheckedLocked}, since the top activity is resumed at the - // end. We call the {@link ActivityStackSupervisor#checkReadyForSleepLocked} again here - // to ensure any necessary pause logic occurs. In the case where the Activity will be - // shown regardless of the lock screen, the call to - // {@link ActivityStackSupervisor#checkReadyForSleepLocked} is skipped. - final ActivityRecord next = topRunningActivity(true /* focusableOnly */); - if (next == null || !next.canTurnScreenOn()) { - checkReadyForSleep(); - } - } finally { - mInResumeTopActivity = false; - } - - return result; - } - - @GuardedBy("mService") - private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { - if (!mAtmService.isBooting() && !mAtmService.isBooted()) { - // Not ready yet! - return false; - } - - // Find the next top-most activity to resume in this stack that is not finishing and is - // focusable. If it is not focusable, we will fall into the case below to resume the - // top activity in the next focusable task. - ActivityRecord next = topRunningActivity(true /* focusableOnly */); - - final boolean hasRunningActivity = next != null; - - // TODO: Maybe this entire condition can get removed? - if (hasRunningActivity && !isAttached()) { - return false; - } - - mRootWindowContainer.cancelInitializingActivities(); - - // Remember how we'll process this pause/resume situation, and ensure - // that the state is reset however we wind up proceeding. - boolean userLeaving = mStackSupervisor.mUserLeaving; - mStackSupervisor.mUserLeaving = false; - - if (!hasRunningActivity) { - // There are no activities left in the stack, let's look somewhere else. - return resumeNextFocusableActivityWhenStackIsEmpty(prev, options); - } - - next.delayedResume = false; - final TaskDisplayArea taskDisplayArea = getDisplayArea(); - - // If the top activity is the resumed one, nothing to do. - if (mResumedActivity == next && next.isState(RESUMED) - && taskDisplayArea.allResumedActivitiesComplete()) { - // Make sure we have executed any pending transitions, since there - // should be nothing left to do at this point. - executeAppTransition(options); - if (DEBUG_STATES) Slog.d(TAG_STATES, - "resumeTopActivityLocked: Top activity resumed " + next); - return false; - } - - if (!next.canResumeByCompat()) { - return false; - } - - // If we are currently pausing an activity, then don't do anything until that is done. - final boolean allPausedComplete = mRootWindowContainer.allPausedActivitiesComplete(); - if (!allPausedComplete) { - if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) { - Slog.v(TAG_PAUSE, "resumeTopActivityLocked: Skip resume: some activity pausing."); - } - return false; - } - - // If we are sleeping, and there is no resumed activity, and the top activity is paused, - // well that is the state we want. - if (shouldSleepOrShutDownActivities() - && mLastPausedActivity == next - && mRootWindowContainer.allPausedActivitiesComplete()) { - // If the current top activity may be able to occlude keyguard but the occluded state - // has not been set, update visibility and check again if we should continue to resume. - boolean nothingToResume = true; - if (!mAtmService.mShuttingDown) { - final boolean canShowWhenLocked = !mTopActivityOccludesKeyguard - && next.canShowWhenLocked(); - final boolean mayDismissKeyguard = mTopDismissingKeyguardActivity != next - && next.containsDismissKeyguardWindow(); - - if (canShowWhenLocked || mayDismissKeyguard) { - ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, - !PRESERVE_WINDOWS); - nothingToResume = shouldSleepActivities(); - } else if (next.currentLaunchCanTurnScreenOn() && next.canTurnScreenOn()) { - nothingToResume = false; - } - } - if (nothingToResume) { - // Make sure we have executed any pending transitions, since there - // should be nothing left to do at this point. - executeAppTransition(options); - if (DEBUG_STATES) Slog.d(TAG_STATES, - "resumeTopActivityLocked: Going to sleep and all paused"); - return false; - } - } - - // Make sure that the user who owns this activity is started. If not, - // we will just leave it as is because someone should be bringing - // another user's activities to the top of the stack. - if (!mAtmService.mAmInternal.hasStartedUserState(next.mUserId)) { - Slog.w(TAG, "Skipping resume of top activity " + next - + ": user " + next.mUserId + " is stopped"); - return false; - } - - // The activity may be waiting for stop, but that is no longer - // appropriate for it. - mStackSupervisor.mStoppingActivities.remove(next); - next.setSleeping(false); - - if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); - - // If we are currently pausing an activity, then don't do anything until that is done. - if (!mRootWindowContainer.allPausedActivitiesComplete()) { - if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, - "resumeTopActivityLocked: Skip resume: some activity pausing."); - - return false; - } - - mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); - - ActivityRecord lastResumed = null; - final ActivityStack lastFocusedStack = taskDisplayArea.getLastFocusedStack(); - if (lastFocusedStack != null && lastFocusedStack != this) { - // So, why aren't we using prev here??? See the param comment on the method. prev doesn't - // represent the last resumed activity. However, the last focus stack does if it isn't null. - lastResumed = lastFocusedStack.mResumedActivity; - if (userLeaving && inMultiWindowMode() && lastFocusedStack.shouldBeVisible(next)) { - // The user isn't leaving if this stack is the multi-window mode and the last - // focused stack should still be visible. - if(DEBUG_USER_LEAVING) Slog.i(TAG_USER_LEAVING, "Overriding userLeaving to false" - + " next=" + next + " lastResumed=" + lastResumed); - userLeaving = false; - } - } - - boolean pausing = taskDisplayArea.pauseBackStacks(userLeaving, next); - if (mResumedActivity != null) { - if (DEBUG_STATES) Slog.d(TAG_STATES, - "resumeTopActivityLocked: Pausing " + mResumedActivity); - pausing |= startPausingLocked(userLeaving, false /* uiSleeping */, next); - } - if (pausing) { - if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, - "resumeTopActivityLocked: Skip resume: need to start pausing"); - // At this point we want to put the upcoming activity's process - // at the top of the LRU list, since we know we will be needing it - // very soon and it would be a waste to let it get killed if it - // happens to be sitting towards the end. - if (next.attachedToProcess()) { - next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, - true /* activityChange */, false /* updateOomAdj */, - false /* addPendingTopUid */); - } else if (!next.isProcessRunning()) { - // Since the start-process is asynchronous, if we already know the process of next - // activity isn't running, we can start the process earlier to save the time to wait - // for the current activity to be paused. - final boolean isTop = this == taskDisplayArea.getFocusedStack(); - mAtmService.startProcessAsync(next, false /* knownToBeDead */, isTop, - isTop ? "pre-top-activity" : "pre-activity"); - } - if (lastResumed != null) { - lastResumed.setWillCloseOrEnterPip(true); - } - return true; - } else if (mResumedActivity == next && next.isState(RESUMED) - && taskDisplayArea.allResumedActivitiesComplete()) { - // It is possible for the activity to be resumed when we paused back stacks above if the - // next activity doesn't have to wait for pause to complete. - // So, nothing else to-do except: - // Make sure we have executed any pending transitions, since there - // should be nothing left to do at this point. - executeAppTransition(options); - if (DEBUG_STATES) Slog.d(TAG_STATES, - "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); - return true; - } - - // If the most recent activity was noHistory but was only stopped rather - // than stopped+finished because the device went to sleep, we need to make - // sure to finish it as we're making a new activity topmost. - if (shouldSleepActivities() && mLastNoHistoryActivity != null && - !mLastNoHistoryActivity.finishing) { - if (DEBUG_STATES) Slog.d(TAG_STATES, - "no-history finish of " + mLastNoHistoryActivity + " on new resume"); - mLastNoHistoryActivity.finishIfPossible("resume-no-history", false /* oomAdj */); - mLastNoHistoryActivity = null; - } - - if (prev != null && prev != next && next.nowVisible) { - - // The next activity is already visible, so hide the previous - // activity's windows right now so we can show the new one ASAP. - // We only do this if the previous is finishing, which should mean - // it is on top of the one being resumed so hiding it quickly - // is good. Otherwise, we want to do the normal route of allowing - // the resumed activity to be shown so we can decide if the - // previous should actually be hidden depending on whether the - // new one is found to be full-screen or not. - if (prev.finishing) { - prev.setVisibility(false); - if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, - "Not waiting for visible to hide: " + prev - + ", nowVisible=" + next.nowVisible); - } else { - if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, - "Previous already visible but still waiting to hide: " + prev - + ", nowVisible=" + next.nowVisible); - } - - } - - // Launching this app's activity, make sure the app is no longer - // considered stopped. - try { - mAtmService.getPackageManager().setPackageStoppedState( - next.packageName, false, next.mUserId); /* TODO: Verify if correct userid */ - } catch (RemoteException e1) { - } catch (IllegalArgumentException e) { - Slog.w(TAG, "Failed trying to unstop package " - + next.packageName + ": " + e); - } - - // We are starting up the next activity, so tell the window manager - // that the previous one will be hidden soon. This way it can know - // to ignore it when computing the desired screen orientation. - boolean anim = true; - final DisplayContent dc = taskDisplayArea.mDisplayContent; - if (prev != null) { - if (prev.finishing) { - if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, - "Prepare close transition: prev=" + prev); - if (mStackSupervisor.mNoAnimActivities.contains(prev)) { - anim = false; - dc.prepareAppTransition(TRANSIT_NONE, false); - } else { - dc.prepareAppTransition( - prev.getTask() == next.getTask() ? TRANSIT_ACTIVITY_CLOSE - : TRANSIT_TASK_CLOSE, false); - } - prev.setVisibility(false); - } else { - if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, - "Prepare open transition: prev=" + prev); - if (mStackSupervisor.mNoAnimActivities.contains(next)) { - anim = false; - dc.prepareAppTransition(TRANSIT_NONE, false); - } else { - dc.prepareAppTransition( - prev.getTask() == next.getTask() ? TRANSIT_ACTIVITY_OPEN - : next.mLaunchTaskBehind ? TRANSIT_TASK_OPEN_BEHIND - : TRANSIT_TASK_OPEN, false); - } - } - } else { - if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); - if (mStackSupervisor.mNoAnimActivities.contains(next)) { - anim = false; - dc.prepareAppTransition(TRANSIT_NONE, false); - } else { - dc.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); - } - } - - if (anim) { - next.applyOptionsLocked(); - } else { - next.clearOptionsLocked(); - } - - mStackSupervisor.mNoAnimActivities.clear(); - - if (next.attachedToProcess()) { - if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next - + " stopped=" + next.stopped - + " visibleRequested=" + next.mVisibleRequested); - - // If the previous activity is translucent, force a visibility update of - // the next activity, so that it's added to WM's opening app list, and - // transition animation can be set up properly. - // For example, pressing Home button with a translucent activity in focus. - // Launcher is already visible in this case. If we don't add it to opening - // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a - // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. - final boolean lastActivityTranslucent = lastFocusedStack != null - && (lastFocusedStack.inMultiWindowMode() - || (lastFocusedStack.mLastPausedActivity != null - && !lastFocusedStack.mLastPausedActivity.occludesParent())); - - // This activity is now becoming visible. - if (!next.mVisibleRequested || next.stopped || lastActivityTranslucent) { - next.setVisibility(true); - } - - // schedule launch ticks to collect information about slow apps. - next.startLaunchTickingLocked(); - - ActivityRecord lastResumedActivity = - lastFocusedStack == null ? null : lastFocusedStack.mResumedActivity; - final ActivityState lastState = next.getState(); - - mAtmService.updateCpuStats(); - - if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next - + " (in existing)"); - - next.setState(RESUMED, "resumeTopActivityInnerLocked"); - - next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, - true /* activityChange */, true /* updateOomAdj */, - true /* addPendingTopUid */); - - // Have the window manager re-evaluate the orientation of - // the screen based on the new activity order. - boolean notUpdated = true; - - // Activity should also be visible if set mLaunchTaskBehind to true (see - // ActivityRecord#shouldBeVisibleIgnoringKeyguard()). - if (shouldBeVisible(next)) { - // We have special rotation behavior when here is some active activity that - // requests specific orientation or Keyguard is locked. Make sure all activity - // visibilities are set correctly as well as the transition is updated if needed - // to get the correct rotation behavior. Otherwise the following call to update - // the orientation may cause incorrect configurations delivered to client as a - // result of invisible window resize. - // TODO: Remove this once visibilities are set correctly immediately when - // starting an activity. - notUpdated = !mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(), - true /* markFrozenIfConfigChanged */, false /* deferResume */); - } - - if (notUpdated) { - // The configuration update wasn't able to keep the existing - // instance of the activity, and instead started a new one. - // We should be all done, but let's just make sure our activity - // is still at the top and schedule another run if something - // weird happened. - ActivityRecord nextNext = topRunningActivity(); - if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, - "Activity config changed during resume: " + next - + ", new next: " + nextNext); - if (nextNext != next) { - // Do over! - mStackSupervisor.scheduleResumeTopActivities(); - } - if (!next.mVisibleRequested || next.stopped) { - next.setVisibility(true); - } - next.completeResumeLocked(); - return true; - } - - try { - final ClientTransaction transaction = - ClientTransaction.obtain(next.app.getThread(), next.appToken); - // Deliver all pending results. - ArrayList<ResultInfo> a = next.results; - if (a != null) { - final int N = a.size(); - if (!next.finishing && N > 0) { - if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, - "Delivering results to " + next + ": " + a); - transaction.addCallback(ActivityResultItem.obtain(a)); - } - } - - if (next.newIntents != null) { - transaction.addCallback( - NewIntentItem.obtain(next.newIntents, true /* resume */)); - } - - // Well the app will no longer be stopped. - // Clear app token stopped state in window manager if needed. - next.notifyAppResumed(next.stopped); - - EventLogTags.writeWmResumeActivity(next.mUserId, System.identityHashCode(next), - next.getTask().mTaskId, next.shortComponentName); - - next.setSleeping(false); - mAtmService.getAppWarningsLocked().onResumeActivity(next); - next.app.setPendingUiCleanAndForceProcessStateUpTo(mAtmService.mTopProcessState); - next.clearOptionsLocked(); - transaction.setLifecycleStateRequest( - ResumeActivityItem.obtain(next.app.getReportedProcState(), - dc.isNextTransitionForward())); - mAtmService.getLifecycleManager().scheduleTransaction(transaction); - - if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " - + next); - } catch (Exception e) { - // Whoops, need to restart this activity! - if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " - + lastState + ": " + next); - next.setState(lastState, "resumeTopActivityInnerLocked"); - - // lastResumedActivity being non-null implies there is a lastStack present. - if (lastResumedActivity != null) { - lastResumedActivity.setState(RESUMED, "resumeTopActivityInnerLocked"); - } - - Slog.i(TAG, "Restarting because process died: " + next); - if (!next.hasBeenLaunched) { - next.hasBeenLaunched = true; - } else if (SHOW_APP_STARTING_PREVIEW && lastFocusedStack != null - && lastFocusedStack.isTopStackInDisplayArea()) { - next.showStartingWindow(null /* prev */, false /* newTask */, - false /* taskSwitch */); - } - mStackSupervisor.startSpecificActivity(next, true, false); - return true; - } - - // From this point on, if something goes wrong there is no way - // to recover the activity. - try { - next.completeResumeLocked(); - } catch (Exception e) { - // If any exception gets thrown, toss away this - // activity and try the next one. - Slog.w(TAG, "Exception thrown during resume of " + next, e); - next.finishIfPossible("resume-exception", true /* oomAdj */); - return true; - } - } else { - // Whoops, need to restart this activity! - if (!next.hasBeenLaunched) { - next.hasBeenLaunched = true; - } else { - if (SHOW_APP_STARTING_PREVIEW) { - next.showStartingWindow(null /* prev */, false /* newTask */, - false /* taskSwich */); - } - if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); - } - if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); - mStackSupervisor.startSpecificActivity(next, true, true); - } - - return true; - } - - /** - * Resume the next eligible activity in a focusable stack when this one does not have any - * running activities left. The focus will be adjusted to the next focusable stack and - * top running activities will be resumed in all focusable stacks. However, if the current stack - * is a home stack - we have to keep it focused, start and resume a home activity on the current - * display instead to make sure that the display is not empty. - */ - private boolean resumeNextFocusableActivityWhenStackIsEmpty(ActivityRecord prev, - ActivityOptions options) { - final String reason = "noMoreActivities"; - - if (!isActivityTypeHome()) { - final ActivityStack nextFocusedStack = adjustFocusToNextFocusableTask(reason); - if (nextFocusedStack != null) { - // Try to move focus to the next visible stack with a running activity if this - // stack is not covering the entire screen or is on a secondary display with no home - // stack. - return mRootWindowContainer.resumeFocusedStacksTopActivities(nextFocusedStack, - prev, null /* targetOptions */); - } - } - - // If the current stack is a home stack, or if focus didn't switch to a different stack - - // just start up the Launcher... - ActivityOptions.abort(options); - if (DEBUG_STATES) Slog.d(TAG_STATES, - "resumeNextFocusableActivityWhenStackIsEmpty: " + reason + ", go home"); - return mRootWindowContainer.resumeHomeActivity(prev, reason, getDisplayArea()); - } - - void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, - boolean newTask, boolean keepCurTransition, ActivityOptions options) { - Task rTask = r.getTask(); - final boolean allowMoveToFront = options == null || !options.getAvoidMoveToFront(); - final boolean isOrhasTask = rTask == this || hasChild(rTask); - // mLaunchTaskBehind tasks get placed at the back of the task stack. - if (!r.mLaunchTaskBehind && allowMoveToFront && (!isOrhasTask || newTask)) { - // Last activity in task had been removed or ActivityManagerService is reusing task. - // Insert or replace. - // Might not even be in. - positionChildAtTop(rTask); - } - Task task = null; - if (!newTask && isOrhasTask) { - // Starting activity cannot be occluding activity, otherwise starting window could be - // remove immediately without transferring to starting activity. - final ActivityRecord occludingActivity = getOccludingActivityAbove(r); - if (occludingActivity != null) { - // Here it is! Now, if this is not yet visible (occluded by another task) to the - // user, then just add it without starting; it will get started when the user - // navigates back to it. - if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " + task, - new RuntimeException("here").fillInStackTrace()); - rTask.positionChildAtTop(r); - ActivityOptions.abort(options); - return; - } - } - - // Place a new activity at top of stack, so it is next to interact with the user. - - // If we are not placing the new activity frontmost, we do not want to deliver the - // onUserLeaving callback to the actual frontmost activity - final Task activityTask = r.getTask(); - if (task == activityTask && mChildren.indexOf(task) != (getChildCount() - 1)) { - mStackSupervisor.mUserLeaving = false; - if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, - "startActivity() behind front, mUserLeaving=false"); - } - - task = activityTask; - - // Slot the activity into the history stack and proceed - if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to stack to task " + task, - new RuntimeException("here").fillInStackTrace()); - task.positionChildAtTop(r); - - // The transition animation and starting window are not needed if {@code allowMoveToFront} - // is false, because the activity won't be visible. - if ((!isHomeOrRecentsStack() || hasActivity()) && allowMoveToFront) { - final DisplayContent dc = getDisplay().mDisplayContent; - if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, - "Prepare open transition: starting " + r); - if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { - dc.prepareAppTransition(TRANSIT_NONE, keepCurTransition); - mStackSupervisor.mNoAnimActivities.add(r); - } else { - int transit = TRANSIT_ACTIVITY_OPEN; - if (newTask) { - if (r.mLaunchTaskBehind) { - transit = TRANSIT_TASK_OPEN_BEHIND; - } else if (getDisplay().isSingleTaskInstance()) { - // If a new task is being launched in a single task display, we don't need - // to play normal animation, but need to trigger a callback when an app - // transition is actually handled. So ignore already prepared activity, and - // override it. - transit = TRANSIT_SHOW_SINGLE_TASK_DISPLAY; - keepCurTransition = false; - } else { - // If a new task is being launched, then mark the existing top activity as - // supporting picture-in-picture while pausing only if the starting activity - // would not be considered an overlay on top of the current activity - // (eg. not fullscreen, or the assistant) - if (canEnterPipOnTaskSwitch(focusedTopActivity, - null /* toFrontTask */, r, options)) { - focusedTopActivity.supportsEnterPipOnTaskSwitch = true; - } - transit = TRANSIT_TASK_OPEN; - } - } - dc.prepareAppTransition(transit, keepCurTransition); - mStackSupervisor.mNoAnimActivities.remove(r); - } - boolean doShow = true; - if (newTask) { - // Even though this activity is starting fresh, we still need - // to reset it to make sure we apply affinities to move any - // existing activities from other tasks in to it. - // If the caller has requested that the target task be - // reset, then do so. - if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { - resetTaskIfNeeded(r, r); - doShow = topRunningNonDelayedActivityLocked(null) == r; - } - } else if (options != null && options.getAnimationType() - == ActivityOptions.ANIM_SCENE_TRANSITION) { - doShow = false; - } - if (r.mLaunchTaskBehind) { - // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we - // tell WindowManager that r is visible even though it is at the back of the stack. - r.setVisibility(true); - ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); - // Go ahead to execute app transition for this activity since the app transition - // will not be triggered through the resume channel. - getDisplay().mDisplayContent.executeAppTransition(); - } else if (SHOW_APP_STARTING_PREVIEW && doShow) { - // Figure out if we are transitioning from another activity that is - // "has the same starting icon" as the next one. This allows the - // window manager to keep the previous window it had previously - // created, if it still had one. - Task prevTask = r.getTask(); - ActivityRecord prev = prevTask.topActivityWithStartingWindow(); - if (prev != null) { - // We don't want to reuse the previous starting preview if: - // (1) The current activity is in a different task. - if (prev.getTask() != prevTask) { - prev = null; - } - // (2) The current activity is already displayed. - else if (prev.nowVisible) { - prev = null; - } - } - r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity)); - } - } else { - // If this is the first activity, don't do any fancy animations, - // because there is nothing for it to animate on top of. - ActivityOptions.abort(options); - } - } - - /** - * @return Whether the switch to another task can trigger the currently running activity to - * enter PiP while it is pausing (if supported). Only one of {@param toFrontTask} or - * {@param toFrontActivity} should be set. - */ - private boolean canEnterPipOnTaskSwitch(ActivityRecord pipCandidate, - Task toFrontTask, ActivityRecord toFrontActivity, ActivityOptions opts) { - if (opts != null && opts.disallowEnterPictureInPictureWhileLaunching()) { - // Ensure the caller has requested not to trigger auto-enter PiP - return false; - } - if (pipCandidate == null || pipCandidate.inPinnedWindowingMode()) { - // Ensure that we do not trigger entering PiP an activity on the pinned stack - return false; - } - final ActivityStack targetStack = toFrontTask != null - ? toFrontTask.getStack() : toFrontActivity.getRootTask(); - if (targetStack != null && targetStack.isActivityTypeAssistant()) { - // Ensure the task/activity being brought forward is not the assistant - return false; - } - return true; - } - - private boolean isTaskSwitch(ActivityRecord r, ActivityRecord topFocusedActivity) { - return topFocusedActivity != null && r.getTask() != topFocusedActivity.getTask(); - } - - /** - * Reset the task by reparenting the activities that have same affinity to the task or - * reparenting the activities that have different affinityies out of the task, while these - * activities allow task reparenting. - * - * @param taskTop Top activity of the task might be reset. - * @param newActivity The activity that going to be started. - * @return The non-finishing top activity of the task after reset or the original task top - * activity if all activities within the task are finishing. - */ - ActivityRecord resetTaskIfNeeded(ActivityRecord taskTop, ActivityRecord newActivity) { - final boolean forceReset = - (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; - final Task task = taskTop.getTask(); - - // If ActivityOptions are moved out and need to be aborted or moved to taskTop. - final ActivityOptions topOptions = sResetTargetTaskHelper.process(task, forceReset); - - if (mChildren.contains(task)) { - final ActivityRecord newTop = task.getTopNonFinishingActivity(); - if (newTop != null) { - taskTop = newTop; - } - } - - if (topOptions != null) { - // If we got some ActivityOptions from an activity on top that - // was removed from the task, propagate them to the new real top. - taskTop.updateOptionsLocked(topOptions); - } - - return taskTop; - } - - /** - * Finish the topmost activity that belongs to the crashed app. We may also finish the activity - * that requested launch of the crashed one to prevent launch-crash loop. - * @param app The app that crashed. - * @param reason Reason to perform this action. - * @return The task that was finished in this stack, {@code null} if top running activity does - * not belong to the crashed app. - */ - final Task finishTopCrashedActivityLocked(WindowProcessController app, String reason) { - final ActivityRecord r = topRunningActivity(); - if (r == null || r.app != app) { - return null; - } - if (r.isActivityTypeHome() && mAtmService.mHomeProcess == app) { - // Home activities should not be force-finished as we have nothing else to go - // back to. AppErrors will get to it after two crashes in MIN_CRASH_INTERVAL. - Slog.w(TAG, " Not force finishing home activity " - + r.intent.getComponent().flattenToShortString()); - return null; - } - Slog.w(TAG, " Force finishing activity " - + r.intent.getComponent().flattenToShortString()); - Task finishedTask = r.getTask(); - getDisplay().mDisplayContent.prepareAppTransition( - TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); - r.finishIfPossible(reason, false /* oomAdj */); - - // Also terminate any activities below it that aren't yet stopped, to avoid a situation - // where one will get re-start our crashing activity once it gets resumed again. - final ActivityRecord activityBelow = getActivityBelow(r); - if (activityBelow != null) { - if (activityBelow.isState(STARTED, RESUMED, PAUSING, PAUSED)) { - if (!activityBelow.isActivityTypeHome() - || mAtmService.mHomeProcess != activityBelow.app) { - Slog.w(TAG, " Force finishing activity " - + activityBelow.intent.getComponent().flattenToShortString()); - activityBelow.finishIfPossible(reason, false /* oomAdj */); - } - } - } - - return finishedTask; - } - - void finishVoiceTask(IVoiceInteractionSession session) { - final PooledConsumer c = PooledLambda.obtainConsumer(ActivityStack::finishIfVoiceTask, - PooledLambda.__(Task.class), session.asBinder()); - forAllLeafTasks(c, true /* traverseTopToBottom */); - c.recycle(); - } - - private static void finishIfVoiceTask(Task tr, IBinder binder) { - if (tr.voiceSession != null && tr.voiceSession.asBinder() == binder) { - tr.forAllActivities((r) -> { - if (r.finishing) return; - r.finishIfPossible("finish-voice", false /* oomAdj */); - tr.mAtmService.updateOomAdj(); - }); - } else { - // Check if any of the activities are using voice - final PooledFunction f = PooledLambda.obtainFunction( - ActivityStack::finishIfVoiceActivity, PooledLambda.__(ActivityRecord.class), - binder); - tr.forAllActivities(f); - f.recycle(); - } - } - - private static boolean finishIfVoiceActivity(ActivityRecord r, IBinder binder) { - if (r.voiceSession == null || r.voiceSession.asBinder() != binder) return false; - // Inform of cancellation - r.clearVoiceSessionLocked(); - try { - r.app.getThread().scheduleLocalVoiceInteractionStarted(r.appToken, null); - } catch (RemoteException re) { - // Ok Boomer... - } - r.mAtmService.finishRunningVoiceLocked(); - return true; - } - - /** Finish all activities in the stack without waiting. */ - void finishAllActivitiesImmediately() { - if (!hasChild()) { - removeIfPossible(); - return; - } - forAllActivities((r) -> { - Slog.d(TAG, "finishAllActivitiesImmediatelyLocked: finishing " + r); - r.destroyIfPossible("finishAllActivitiesImmediately"); - }); - } - - /** @return true if the stack behind this one is a standard activity type. */ - private boolean inFrontOfStandardStack() { - final TaskDisplayArea taskDisplayArea = getDisplayArea(); - if (taskDisplayArea == null) { - return false; - } - final int index = taskDisplayArea.getIndexOf(this); - if (index == 0) { - return false; - } - final ActivityStack stackBehind = taskDisplayArea.getChildAt(index - 1); - return stackBehind.isActivityTypeStandard(); - } - - boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { - // Basic case: for simple app-centric recents, we need to recreate - // the task if the affinity has changed. - - final String affinity = ActivityRecord.getTaskAffinityWithUid(destAffinity, srec.getUid()); - if (srec == null || srec.getTask().affinity == null - || !srec.getTask().affinity.equals(affinity)) { - return true; - } - // Document-centric case: an app may be split in to multiple documents; - // they need to re-create their task if this current activity is the root - // of a document, unless simply finishing it will return them to the the - // correct app behind. - final Task task = srec.getTask(); - if (srec.isRootOfTask() && task.getBaseIntent() != null - && task.getBaseIntent().isDocument()) { - // Okay, this activity is at the root of its task. What to do, what to do... - if (!inFrontOfStandardStack()) { - // Finishing won't return to an application, so we need to recreate. - return true; - } - // We now need to get the task below it to determine what to do. - final Task prevTask = getTaskBelow(task); - if (prevTask == null) { - Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); - return false; - } - if (!task.affinity.equals(prevTask.affinity)) { - // These are different apps, so need to recreate. - return true; - } - } - return false; - } - - boolean navigateUpTo(ActivityRecord srec, Intent destIntent, NeededUriGrants destGrants, - int resultCode, Intent resultData, NeededUriGrants resultGrants) { - if (!srec.attachedToProcess()) { - // Nothing to do if the caller is not attached, because this method should be called - // from an alive activity. - return false; - } - final Task task = srec.getTask(); - if (!srec.isDescendantOf(this)) { - return false; - } - - ActivityRecord parent = task.getActivityBelow(srec); - boolean foundParentInTask = false; - final ComponentName dest = destIntent.getComponent(); - if (task.getBottomMostActivity() != srec && dest != null) { - final ActivityRecord candidate = task.getActivity((ar) -> - ar.info.packageName.equals(dest.getPackageName()) && - ar.info.name.equals(dest.getClassName()), srec, false /*includeBoundary*/, - true /*traverseTopToBottom*/); - if (candidate != null) { - parent = candidate; - foundParentInTask = true; - } - } - - // TODO: There is a dup. of this block of code in ActivityTaskManagerService.finishActivity - // We should consolidate. - IActivityController controller = mAtmService.mController; - if (controller != null) { - ActivityRecord next = topRunningActivity(srec.appToken, INVALID_TASK_ID); - if (next != null) { - // ask watcher if this is allowed - boolean resumeOK = true; - try { - resumeOK = controller.activityResuming(next.packageName); - } catch (RemoteException e) { - mAtmService.mController = null; - Watchdog.getInstance().setActivityController(null); - } - - if (!resumeOK) { - return false; - } - } - } - final long origId = Binder.clearCallingIdentity(); - - final int[] resultCodeHolder = new int[1]; - resultCodeHolder[0] = resultCode; - final Intent[] resultDataHolder = new Intent[1]; - resultDataHolder[0] = resultData; - final NeededUriGrants[] resultGrantsHolder = new NeededUriGrants[1]; - resultGrantsHolder[0] = resultGrants; - final ActivityRecord finalParent = parent; - task.forAllActivities((ar) -> { - if (ar == finalParent) return true; - - ar.finishIfPossible(resultCodeHolder[0], resultDataHolder[0], resultGrantsHolder[0], - "navigate-up", true /* oomAdj */); - // Only return the supplied result for the first activity finished - resultCodeHolder[0] = Activity.RESULT_CANCELED; - resultDataHolder[0] = null; - return false; - }, srec, true, true); - resultCode = resultCodeHolder[0]; - resultData = resultDataHolder[0]; - - if (parent != null && foundParentInTask) { - final int callingUid = srec.info.applicationInfo.uid; - final int parentLaunchMode = parent.info.launchMode; - final int destIntentFlags = destIntent.getFlags(); - if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || - parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || - parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || - (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { - parent.deliverNewIntentLocked(callingUid, destIntent, destGrants, srec.packageName); - } else { - try { - ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( - destIntent.getComponent(), ActivityManagerService.STOCK_PM_FLAGS, - srec.mUserId); - // TODO(b/64750076): Check if calling pid should really be -1. - final int res = mAtmService.getActivityStartController() - .obtainStarter(destIntent, "navigateUpTo") - .setCaller(srec.app.getThread()) - .setActivityInfo(aInfo) - .setResultTo(parent.appToken) - .setCallingPid(-1) - .setCallingUid(callingUid) - .setCallingPackage(srec.packageName) - .setCallingFeatureId(parent.launchedFromFeatureId) - .setRealCallingPid(-1) - .setRealCallingUid(callingUid) - .setComponentSpecified(true) - .execute(); - foundParentInTask = res == ActivityManager.START_SUCCESS; - } catch (RemoteException e) { - foundParentInTask = false; - } - parent.finishIfPossible(resultCode, resultData, resultGrants, - "navigate-top", true /* oomAdj */); - } - } - Binder.restoreCallingIdentity(origId); - return foundParentInTask; - } - - void removeLaunchTickMessages() { - forAllActivities(ActivityRecord::removeLaunchTickRunnable); - } - - private void updateTransitLocked(int transit, ActivityOptions options, boolean forceOverride) { - if (options != null) { - ActivityRecord r = topRunningActivity(); - if (r != null && !r.isState(RESUMED)) { - r.updateOptionsLocked(options); - } else { - ActivityOptions.abort(options); - } - } - getDisplay().mDisplayContent.prepareAppTransition(transit, false, - 0 /* flags */, forceOverride); - } - - final void moveTaskToFront(Task tr, boolean noAnimation, ActivityOptions options, - AppTimeTracker timeTracker, String reason) { - moveTaskToFront(tr, noAnimation, options, timeTracker, !DEFER_RESUME, reason); - } - - final void moveTaskToFront(Task tr, boolean noAnimation, ActivityOptions options, - AppTimeTracker timeTracker, boolean deferResume, String reason) { - if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); - - final ActivityStack topStack = getDisplayArea().getTopStack(); - final ActivityRecord topActivity = topStack != null - ? topStack.getTopNonFinishingActivity() : null; - - if (tr != this && !tr.isDescendantOf(this)) { - // nothing to do! - if (noAnimation) { - ActivityOptions.abort(options); - } else if (isSingleTaskInstance()) { - // When a task is moved front on the display which can only contain one task, start - // a special transition. - // {@link AppTransitionController#handleAppTransitionReady} later picks up the - // transition, and schedules - // {@link ITaskStackListener#onSingleTaskDisplayDrawn} callback which is triggered - // after contents are drawn on the display. - updateTransitLocked(TRANSIT_SHOW_SINGLE_TASK_DISPLAY, options, - true /* forceOverride */); - } else { - updateTransitLocked(TRANSIT_TASK_TO_FRONT, options, false /* forceOverride */); - } - return; - } - - if (timeTracker != null) { - // The caller wants a time tracker associated with this task. - final PooledConsumer c = PooledLambda.obtainConsumer(ActivityRecord::setAppTimeTracker, - PooledLambda.__(ActivityRecord.class), timeTracker); - tr.forAllActivities(c); - c.recycle(); - } - - try { - // Defer updating the IME target since the new IME target will try to get computed - // before updating all closing and opening apps, which can cause the ime target to - // get calculated incorrectly. - getDisplay().deferUpdateImeTarget(); - - // Shift all activities with this task up to the top - // of the stack, keeping them in the same internal order. - positionChildAtTop(tr); - - // Don't refocus if invisible to current user - final ActivityRecord top = tr.getTopNonFinishingActivity(); - if (top == null || !top.okToShowLocked()) { - if (top != null) { - mStackSupervisor.mRecentTasks.add(top.getTask()); - } - ActivityOptions.abort(options); - return; - } - - // Set focus to the top running activity of this stack. - final ActivityRecord r = topRunningActivity(); - if (r != null) { - r.moveFocusableActivityToTop(reason); - } - - if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); - if (noAnimation) { - getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_NONE, false); - if (r != null) { - mStackSupervisor.mNoAnimActivities.add(r); - } - ActivityOptions.abort(options); - } else if (isSingleTaskInstance()) { - updateTransitLocked(TRANSIT_SHOW_SINGLE_TASK_DISPLAY, options, - true /* forceOverride */); - } else { - updateTransitLocked(TRANSIT_TASK_TO_FRONT, options, false /* forceOverride */); - } - - // If a new task is moved to the front, then mark the existing top activity as - // supporting - - // picture-in-picture while paused only if the task would not be considered an oerlay - // on top - // of the current activity (eg. not fullscreen, or the assistant) - if (canEnterPipOnTaskSwitch(topActivity, tr, null /* toFrontActivity */, - options)) { - topActivity.supportsEnterPipOnTaskSwitch = true; - } - - if (!deferResume) { - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - EventLogTags.writeWmTaskToFront(tr.mUserId, tr.mTaskId); - mAtmService.getTaskChangeNotificationController() - .notifyTaskMovedToFront(tr.getTaskInfo()); - } finally { - getDisplay().continueUpdateImeTarget(); - } - } - - /** - * Worker method for rearranging history stack. Implements the function of moving all - * activities for a specific task (gathering them if disjoint) into a single group at the - * bottom of the stack. - * - * If a watcher is installed, the action is preflighted and the watcher has an opportunity - * to premeptively cancel the move. - * - * @param tr The task to collect and move to the bottom. - * @return Returns true if the move completed, false if not. - */ - boolean moveTaskToBack(Task tr) { - Slog.i(TAG, "moveTaskToBack: " + tr); - - // In LockTask mode, moving a locked task to the back of the stack may expose unlocked - // ones. Therefore we need to check if this operation is allowed. - if (!mAtmService.getLockTaskController().canMoveTaskToBack(tr)) { - return false; - } - - // If we have a watcher, preflight the move before committing to it. First check - // for *other* available tasks, but if none are available, then try again allowing the - // current task to be selected. - if (isTopStackInDisplayArea() && mAtmService.mController != null) { - ActivityRecord next = topRunningActivity(null, tr.mTaskId); - if (next == null) { - next = topRunningActivity(null, INVALID_TASK_ID); - } - if (next != null) { - // ask watcher if this is allowed - boolean moveOK = true; - try { - moveOK = mAtmService.mController.activityResuming(next.packageName); - } catch (RemoteException e) { - mAtmService.mController = null; - Watchdog.getInstance().setActivityController(null); - } - if (!moveOK) { - return false; - } - } - } - - if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to back transition: task=" - + tr.mTaskId); - - getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); - moveToBack("moveTaskToBackLocked", tr); - - if (inPinnedWindowingMode()) { - mStackSupervisor.removeStack(this); - return true; - } - - mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */, - getDisplay().mDisplayId, false /* markFrozenIfConfigChanged */, - false /* deferResume */); - - ActivityRecord topActivity = getDisplayArea().topRunningActivity(); - ActivityStack topStack = topActivity.getRootTask(); - if (topStack != null && topStack != this && topActivity.isState(RESUMED)) { - // Usually resuming a top activity triggers the next app transition, but nothing's got - // resumed in this case, so we need to execute it explicitly. - getDisplay().mDisplayContent.executeAppTransition(); - } else { - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - return true; - } - - /** - * Ensures all visible activities at or below the input activity have the right configuration. - */ - void ensureVisibleActivitiesConfiguration(ActivityRecord start, boolean preserveWindow) { - mEnsureVisibleActivitiesConfigHelper.process(start, preserveWindow); - } - - // TODO: Can only be called from special methods in ActivityStackSupervisor. - // Need to consolidate those calls points into this resize method so anyone can call directly. - void resize(Rect displayedBounds, boolean preserveWindows, boolean deferResume) { - Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "stack.resize_" + getRootTaskId()); - mAtmService.deferWindowLayout(); - try { - // TODO: Why not just set this on the stack directly vs. on each tasks? - // Update override configurations of all tasks in the stack. - final PooledConsumer c = PooledLambda.obtainConsumer( - ActivityStack::processTaskResizeBounds, PooledLambda.__(Task.class), - displayedBounds); - forAllTasks(c, true /* traverseTopToBottom */); - c.recycle(); - - if (mBoundsAnimating) { - // Force to update task surface bounds and relayout windows, since configBounds - // remains unchanged during bounds animation. - updateSurfaceBounds(); - getDisplay().setLayoutNeeded(); - mWmService.requestTraversal(); - } - - if (!deferResume) { - ensureVisibleActivitiesConfiguration(topRunningActivity(), preserveWindows); - } - } finally { - mAtmService.continueWindowLayout(); - Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); - } - } - - private static void processTaskResizeBounds(Task task, Rect displayedBounds) { - if (!task.isResizeable()) return; - - task.setBounds(displayedBounds); - } - - /** - * Until we can break this "set task bounds to same as stack bounds" behavior, this - * basically resizes both stack and task bounds to the same bounds. - */ - private void setTaskBounds(Rect bounds) { - final PooledConsumer c = PooledLambda.obtainConsumer(ActivityStack::setTaskBounds, - PooledLambda.__(Task.class), bounds); - forAllLeafTasks(c, true /* traverseTopToBottom */); - c.recycle(); - } - - private static void setTaskBounds(Task task, Rect bounds) { - task.setBounds(task.isResizeable() ? bounds : null); - } - - boolean willActivityBeVisible(IBinder token) { - final ActivityRecord r = ActivityRecord.forTokenLocked(token); - if (r == null) { - return false; - } - - // See if there is an occluding activity on-top of this one. - final ActivityRecord occludingActivity = getOccludingActivityAbove(r); - if (occludingActivity != null) return false; - - if (r.finishing) Slog.e(TAG, "willActivityBeVisible: Returning false," - + " would have returned true for r=" + r); - return !r.finishing; - } - - void unhandledBackLocked() { - final ActivityRecord topActivity = getTopMostActivity(); - if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, - "Performing unhandledBack(): top activity: " + topActivity); - if (topActivity != null) { - topActivity.finishIfPossible("unhandled-back", true /* oomAdj */); - } - } - - /** - * Reset local parameters because an app's activity died. - * @param app The app of the activity that died. - * @return result from removeHistoryRecordsForAppLocked. - */ - boolean handleAppDied(WindowProcessController app) { - if (mPausingActivity != null && mPausingActivity.app == app) { - if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, - "App died while pausing: " + mPausingActivity); - mPausingActivity = null; - } - if (mLastPausedActivity != null && mLastPausedActivity.app == app) { - mLastPausedActivity = null; - mLastNoHistoryActivity = null; - } - - mStackSupervisor.removeHistoryRecords(app); - return mRemoveHistoryRecordsForApp.process(app); - } - - boolean dump(FileDescriptor fd, PrintWriter pw, boolean dumpAll, boolean dumpClient, - String dumpPackage, final boolean needSep) { - Runnable headerPrinter = () -> { - if (needSep) { - pw.println(); - } - pw.println(" Stack #" + getRootTaskId() - + ": type=" + activityTypeToString(getActivityType()) - + " mode=" + windowingModeToString(getWindowingMode())); - pw.println(" isSleeping=" + shouldSleepActivities()); - pw.println(" mBounds=" + getRequestedOverrideBounds()); - }; - - boolean printed = false; - - if (dumpPackage == null) { - // If we are not filtering by package, we want to print absolutely everything, - // so always print the header even if there are no tasks/activities inside. - headerPrinter.run(); - headerPrinter = null; - printed = true; - } - - printed |= printThisActivity(pw, mPausingActivity, dumpPackage, false, - " mPausingActivity: ", null); - printed |= printThisActivity(pw, getResumedActivity(), dumpPackage, false, - " mResumedActivity: ", null); - if (dumpAll) { - printed |= printThisActivity(pw, mLastPausedActivity, dumpPackage, false, - " mLastPausedActivity: ", null); - printed |= printThisActivity(pw, mLastNoHistoryActivity, dumpPackage, - false, " mLastNoHistoryActivity: ", null); - } - - printed |= dumpActivities(fd, pw, dumpAll, dumpClient, dumpPackage, false, headerPrinter); - - return printed; - } - - private boolean dumpActivities(FileDescriptor fd, PrintWriter pw, boolean dumpAll, - boolean dumpClient, String dumpPackage, boolean needSep, Runnable header) { - if (!hasChild()) { - return false; - } - final AtomicBoolean printedHeader = new AtomicBoolean(false); - final AtomicBoolean printed = new AtomicBoolean(false); - forAllLeafTasks((task) -> { - final String prefix = " "; - Runnable headerPrinter = () -> { - printed.set(true); - if (!printedHeader.get()) { - if (needSep) { - pw.println(""); - } - if (header != null) { - header.run(); - } - printedHeader.set(true); - } - pw.print(prefix); pw.print("* "); pw.println(task); - pw.print(prefix); pw.print(" mBounds="); - pw.println(task.getRequestedOverrideBounds()); - pw.print(prefix); pw.print(" mMinWidth="); pw.print(task.mMinWidth); - pw.print(" mMinHeight="); pw.println(task.mMinHeight); - if (mLastNonFullscreenBounds != null) { - pw.print(prefix); - pw.print(" mLastNonFullscreenBounds="); - pw.println(task.mLastNonFullscreenBounds); - } - task.dump(pw, prefix + " "); - }; - if (dumpPackage == null) { - // If we are not filtering by package, we want to print absolutely everything, - // so always print the header even if there are no activities inside. - headerPrinter.run(); - headerPrinter = null; - } - final ArrayList<ActivityRecord> activities = new ArrayList<>(); - // Add activities by traversing the hierarchy from bottom to top, since activities - // are dumped in reverse order in {@link ActivityStackSupervisor#dumpHistoryList()}. - task.forAllActivities((Consumer<ActivityRecord>) activities::add, - false /* traverseTopToBottom */); - dumpHistoryList(fd, pw, activities, prefix, "Hist", true, !dumpAll, dumpClient, - dumpPackage, false, headerPrinter, task); - }, true /* traverseTopToBottom */); - return printed.get(); - } - - ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { - ArrayList<ActivityRecord> activities = new ArrayList<>(); - - if ("all".equals(name)) { - forAllActivities((Consumer<ActivityRecord>) activities::add); - } else if ("top".equals(name)) { - final ActivityRecord topActivity = getTopMostActivity(); - if (topActivity != null) { - activities.add(topActivity); - } - } else { - ItemMatcher matcher = new ItemMatcher(); - matcher.build(name); - - forAllActivities((r) -> { - if (matcher.match(r, r.intent.getComponent())) { - activities.add(r); - } - }); - } - - return activities; - } - - ActivityRecord restartPackage(String packageName) { - ActivityRecord starting = topRunningActivity(); - - // All activities that came from the package must be - // restarted as if there was a config change. - PooledConsumer c = PooledLambda.obtainConsumer(ActivityStack::restartPackage, - PooledLambda.__(ActivityRecord.class), starting, packageName); - forAllActivities(c); - c.recycle(); - - return starting; - } - - private static void restartPackage( - ActivityRecord r, ActivityRecord starting, String packageName) { - if (r.info.packageName.equals(packageName)) { - r.forceNewConfig = true; - if (starting != null && r == starting && r.mVisibleRequested) { - r.startFreezingScreenLocked(CONFIG_SCREEN_LAYOUT); - } - } - } - - Task reuseOrCreateTask(ActivityInfo info, Intent intent, boolean toTop) { - return reuseOrCreateTask(info, intent, null /*voiceSession*/, null /*voiceInteractor*/, - toTop, null /*activity*/, null /*source*/, null /*options*/); - } - // TODO: Can be removed once we change callpoints creating stacks to be creating tasks. - /** Either returns this current task to be re-used or creates a new child task. */ - Task reuseOrCreateTask(ActivityInfo info, Intent intent, IVoiceInteractionSession voiceSession, - IVoiceInteractor voiceInteractor, boolean toTop, ActivityRecord activity, - ActivityRecord source, ActivityOptions options) { - - Task task; - if (DisplayContent.alwaysCreateStack(getWindowingMode(), getActivityType())) { - // This stack will only contain one task, so just return itself since all stacks ara now - // tasks and all tasks are now stacks. - task = reuseAsLeafTask(voiceSession, voiceInteractor, intent, info, activity); - } else { - // Create child task since this stack can contain multiple tasks. - final int taskId = activity != null - ? mStackSupervisor.getNextTaskIdForUser(activity.mUserId) - : mStackSupervisor.getNextTaskIdForUser(); - task = new ActivityStack(mAtmService, taskId, info, intent, voiceSession, - voiceInteractor, null /* taskDescription */, this); - - // add the task to stack first, mTaskPositioner might need the stack association - addChild(task, toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); - } - - int displayId = getDisplayId(); - if (displayId == INVALID_DISPLAY) displayId = DEFAULT_DISPLAY; - final boolean isLockscreenShown = mAtmService.mStackSupervisor.getKeyguardController() - .isKeyguardOrAodShowing(displayId); - if (!mStackSupervisor.getLaunchParamsController() - .layoutTask(task, info.windowLayout, activity, source, options) - && !getRequestedOverrideBounds().isEmpty() - && task.isResizeable() && !isLockscreenShown) { - task.setBounds(getRequestedOverrideBounds()); - } - - return task; - } - - void addChild(WindowContainer child, final boolean toTop, boolean showForAllUsers) { - if (isSingleTaskInstance() && hasChild()) { - throw new IllegalStateException("Can only have one child on stack=" + this); - } - - Task task = child.asTask(); - try { - if (task != null) { - task.setForceShowForAllUsers(showForAllUsers); - } - // We only want to move the parents to the parents if we are creating this task at the - // top of its stack. - addChild(child, toTop ? MAX_VALUE : 0, toTop /*moveParents*/); - } finally { - if (task != null) { - task.setForceShowForAllUsers(false); - } - } - } - - void positionChildAt(Task task, int position) { - if (task.getStack() != this) { - throw new IllegalArgumentException("AS.positionChildAt: task=" + task - + " is not a child of stack=" + this + " current parent=" + task.getStack()); - } - - task.updateOverrideConfigurationForStack(this); - - final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); - final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity; - - boolean toTop = position >= getChildCount(); - boolean includingParents = toTop || getDisplayArea().getNextFocusableStack(this, - true /* ignoreCurrent */) == null; - if (WindowManagerDebugConfig.DEBUG_STACK) { - Slog.i(TAG_WM, "positionChildAt: positioning task=" + task + " at " + position); - } - positionChildAt(position, task, includingParents); - task.updateTaskMovement(toTop); - getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); - - - // TODO: Investigate if this random code is really needed. - if (task.voiceSession != null) { - try { - task.voiceSession.taskStarted(task.intent, task.mTaskId); - } catch (RemoteException e) { - } - } - - if (wasResumed) { - if (mResumedActivity != null) { - Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" - + " other stack to this stack mResumedActivity=" + mResumedActivity - + " other mResumedActivity=" + topRunningActivity); - } - topRunningActivity.setState(RESUMED, "positionChildAt"); - } - - // The task might have already been running and its visibility needs to be synchronized with - // the visibility of the stack / windows. - ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); - mRootWindowContainer.resumeFocusedStacksTopActivities(); - } - - public void setAlwaysOnTop(boolean alwaysOnTop) { - if (isAlwaysOnTop() == alwaysOnTop) { - return; - } - super.setAlwaysOnTop(alwaysOnTop); - final TaskDisplayArea taskDisplayArea = getDisplayArea(); - // positionChildAtTop() must be called even when always on top gets turned off because we - // need to make sure that the stack is moved from among always on top windows to below other - // always on top windows. Since the position the stack should be inserted into is calculated - // properly in {@link DisplayContent#getTopInsertPosition()} in both cases, we can just - // request that the stack is put at top here. - taskDisplayArea.positionStackAtTop(this, false /* includingParents */); - } - - /** NOTE: Should only be called from {@link Task#reparent}. */ - void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume, - boolean setPause, String reason) { - if (!moveToFront) { - return; - } - - final ActivityState origState = r.getState(); - // If the activity owns the last resumed activity, transfer that together, - // so that we don't resume the same activity again in the new stack. - // Apps may depend on onResume()/onPause() being called in pairs. - if (setResume) { - r.setState(RESUMED, "moveToFrontAndResumeStateIfNeeded"); - } - // If the activity was previously pausing, then ensure we transfer that as well - if (setPause) { - mPausingActivity = r; - r.schedulePauseTimeout(); - } - // Move the stack in which we are placing the activity to the front. - moveToFront(reason); - // If the original state is resumed, there is no state change to update focused app. - // So here makes sure the activity focus is set if it is the top. - if (origState == RESUMED && r == mRootWindowContainer.getTopResumedActivity()) { - mAtmService.setResumedActivityUncheckLocked(r, reason); - } - } - - void dismissPip() { - if (!isActivityTypeStandardOrUndefined()) { - throw new IllegalArgumentException( - "You can't move tasks from non-standard stacks."); - } - if (getWindowingMode() != WINDOWING_MODE_PINNED) { - throw new IllegalArgumentException( - "Can't exit pinned mode if it's not pinned already."); - } - - mWmService.inSurfaceTransaction(() -> { - final Task task = getBottomMostTask(); - setWindowingMode(WINDOWING_MODE_UNDEFINED); - - getDisplayArea().positionStackAtTop(this, false /* includingParents */); - - mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, this); - MetricsLoggerWrapper.logPictureInPictureFullScreen(mAtmService.mContext, - task.effectiveUid, task.realActivity.flattenToString()); - }); - } - - void prepareFreezingTaskBounds() { - forAllLeafTasks(Task::prepareFreezingBounds, true /* traverseTopToBottom */); - } - - @Override - public int setBounds(Rect bounds) { - // Calling Task#setBounds() for leaf task since this is the a specialization of - // {@link #setBounds(int)} for ActivityStack. - if (!isRootTask()) { - return super.setBounds(bounds); - } else { - return setBounds(getRequestedOverrideBounds(), bounds); - } - } - - private int setBounds(Rect existing, Rect bounds) { - if (equivalentBounds(existing, bounds)) { - return BOUNDS_CHANGE_NONE; - } - - final int result = super.setBounds(!inMultiWindowMode() ? null : bounds); - - updateSurfaceBounds(); - return result; - } - - /** Bounds of the stack without adjusting for other factors in the system like visibility - * of docked stack. - * Most callers should be using {@link ConfigurationContainer#getRequestedOverrideBounds} a - * it takes into consideration other system factors. */ - void getRawBounds(Rect out) { - out.set(getRawBounds()); - } - - private Rect getRawBounds() { - return super.getBounds(); - } - - @Override - public void getBounds(Rect bounds) { - bounds.set(getBounds()); - } - - /** - * @return the final bounds for the bounds animation. - */ - void getFinalAnimationBounds(Rect outBounds) { - outBounds.set(mBoundsAnimationTarget); - } - - /** - * @return the final source bounds for the bounds animation. - */ - void getFinalAnimationSourceHintBounds(Rect outBounds) { - outBounds.set(mBoundsAnimationSourceHintBounds); - } - - /** Bounds of the stack with other system factors taken into consideration. */ - void getDimBounds(Rect out) { - getBounds(out); - } - - /** - * Put a Task in this stack. Used for adding only. - * When task is added to top of the stack, the entire branch of the hierarchy (including stack - * and display) will be brought to top. - * @param child The child to add. - * @param position Target position to add the task to. - */ - private void addChild(WindowContainer child, int position, boolean moveParents) { - // Add child task. - addChild(child, null); - - // Move child to a proper position, as some restriction for position might apply. - positionChildAt(position, child, moveParents /* includingParents */); - } - - void positionChildAtTop(Task child) { - if (child == null) { - // TODO: Fix the call-points that cause this to happen. - return; - } - - if (child == this) { - // TODO: Fix call-points - moveToFront("positionChildAtTop"); - return; - } - - positionChildAt(POSITION_TOP, child, true /* includingParents */); - child.updateTaskMovement(true); - - final DisplayContent displayContent = getDisplayContent(); - displayContent.layoutAndAssignWindowLayersIfNeeded(); - } - - void positionChildAtBottom(Task child) { - // If there are other focusable stacks on the display, the z-order of the display should not - // be changed just because a task was placed at the bottom. E.g. if it is moving the topmost - // task to bottom, the next focusable stack on the same display should be focused. - final ActivityStack nextFocusableStack = getDisplayArea().getNextFocusableStack( - child.getStack(), true /* ignoreCurrent */); - positionChildAtBottom(child, nextFocusableStack == null /* includingParents */); - child.updateTaskMovement(true); - } - - @VisibleForTesting - void positionChildAtBottom(Task child, boolean includingParents) { - if (child == null) { - // TODO: Fix the call-points that cause this to happen. - return; - } - - positionChildAt(POSITION_BOTTOM, child, includingParents); - getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); - } - - @Override - void onChildPositionChanged(WindowContainer child) { - if (isOrganized()) { - mAtmService.mTaskOrganizerController.dispatchTaskInfoChanged(this, false /* force */); - } - - if (!mChildren.contains(child)) { - return; - } - - final boolean isTop = getTopChild() == child; - - final Task task = child.asTask(); - if (task != null) { - task.updateTaskMovement(isTop); - } - - if (isTop) { - final DisplayContent displayContent = getDisplayContent(); - displayContent.layoutAndAssignWindowLayersIfNeeded(); - } - } - - @Override - void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { - final DisplayContent display = newParent != null - ? ((WindowContainer) newParent).getDisplayContent() : null; - final DisplayContent oldDisplay = oldParent != null - ? ((WindowContainer) oldParent).getDisplayContent() : null; - super.onParentChanged(newParent, oldParent); - - // Resume next focusable stack after reparenting to another display if we aren't removing - // the prevous display. - if (oldDisplay != null && oldDisplay.isRemoving()) { - postReparent(); - } - } - - void reparent(TaskDisplayArea newParent, boolean onTop) { - reparent(newParent, onTop ? POSITION_TOP : POSITION_BOTTOM); - } - - private void updateSurfaceBounds() { - updateSurfaceSize(getSyncTransaction()); - updateSurfacePosition(); - scheduleAnimation(); - } - - @Override - void getRelativePosition(Point outPos) { - super.getRelativePosition(outPos); - final int outset = getTaskOutset(); - outPos.x -= outset; - outPos.y -= outset; - } - - @Override - void onDisplayChanged(DisplayContent dc) { - super.onDisplayChanged(dc); - if (isRootTask()) { - updateSurfaceBounds(); - } - } - - boolean shouldIgnoreInput() { - if (inSplitScreenPrimaryWindowingMode() && !isFocusable()) { - return true; - } - if (mAtmService.mHasLeanbackFeature && inPinnedWindowingMode() - && !isFocusedStackOnDisplay()) { - // Preventing Picture-in-Picture stack from receiving input on TVs. - return true; - } - return false; - } - - @Override - void dump(PrintWriter pw, String prefix, boolean dumpAll) { - super.dump(pw, prefix, dumpAll); - if (!mExitingActivities.isEmpty()) { - pw.println(); - pw.println(prefix + "Exiting application tokens:"); - final String doublePrefix = prefix + " "; - for (int i = mExitingActivities.size() - 1; i >= 0; i--) { - WindowToken token = mExitingActivities.get(i); - pw.print(doublePrefix + "Exiting App #" + i); - pw.print(' '); pw.print(token); - pw.println(':'); - token.dump(pw, doublePrefix, dumpAll); - } - pw.println(); - } - mAnimatingActivityRegistry.dump(pw, "AnimatingApps:", prefix); - } - - /** - * Sets the current picture-in-picture aspect ratio. - */ - void setPictureInPictureAspectRatio(float aspectRatio) { - if (!mWmService.mAtmService.mSupportsPictureInPicture) { - return; - } - - final DisplayContent displayContent = getDisplayContent(); - if (displayContent == null) { - return; - } - - if (!inPinnedWindowingMode()) { - return; - } - - final PinnedStackController pinnedStackController = - getDisplayContent().getPinnedStackController(); - - if (Float.compare(aspectRatio, pinnedStackController.getAspectRatio()) == 0) { - return; - } - - // Notify the pinned stack controller about aspect ratio change. - // This would result a callback delivered from SystemUI to WM to start animation, - // if the bounds are ought to be altered due to aspect ratio change. - pinnedStackController.setAspectRatio( - pinnedStackController.isValidPictureInPictureAspectRatio(aspectRatio) - ? aspectRatio : -1f); - } - - /** - * Sets the current picture-in-picture actions. - */ - void setPictureInPictureActions(List<RemoteAction> actions) { - if (!mWmService.mAtmService.mSupportsPictureInPicture) { - return; - } - - if (!inPinnedWindowingMode()) { - return; - } - - getDisplayContent().getPinnedStackController().setActions(actions); - } - - public boolean isForceScaled() { - return mBoundsAnimating; - } - - /** Returns true if a removal action is still being deferred. */ - boolean handleCompleteDeferredRemoval() { - if (isAnimating(TRANSITION | CHILDREN)) { - return true; - } - - return super.handleCompleteDeferredRemoval(); - } - - public DisplayInfo getDisplayInfo() { - return mDisplayContent.getDisplayInfo(); - } - - AnimatingActivityRegistry getAnimatingActivityRegistry() { - return mAnimatingActivityRegistry; - } - - void executeAppTransition(ActivityOptions options) { - getDisplay().mDisplayContent.executeAppTransition(); - ActivityOptions.abort(options); - } - - boolean shouldSleepActivities() { - final DisplayContent display = getDisplay(); - - // Do not sleep activities in this stack if we're marked as focused and the keyguard - // is in the process of going away. - if (isFocusedStackOnDisplay() - && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) { - return false; - } - - return display != null ? display.isSleeping() : mAtmService.isSleepingLocked(); - } - - boolean shouldSleepOrShutDownActivities() { - return shouldSleepActivities() || mAtmService.mShuttingDown; - } - - @Override - public void dumpDebug(ProtoOutputStream proto, long fieldId, - @WindowTraceLogLevel int logLevel) { - if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { - return; - } - - final long token = proto.start(fieldId); - super.dumpDebug(proto, WINDOW_CONTAINER, logLevel); - - proto.write(TaskProto.ID, mTaskId); - proto.write(DISPLAY_ID, getDisplayId()); - proto.write(ROOT_TASK_ID, getRootTaskId()); - - if (mResumedActivity != null) { - mResumedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); - } - if (realActivity != null) { - proto.write(REAL_ACTIVITY, realActivity.flattenToShortString()); - } - if (origActivity != null) { - proto.write(ORIG_ACTIVITY, origActivity.flattenToShortString()); - } - proto.write(ACTIVITY_TYPE, getActivityType()); - proto.write(RESIZE_MODE, mResizeMode); - proto.write(MIN_WIDTH, mMinWidth); - proto.write(MIN_HEIGHT, mMinHeight); - - proto.write(FILLS_PARENT, matchParentBounds()); - getRawBounds().dumpDebug(proto, BOUNDS); - - if (mLastNonFullscreenBounds != null) { - mLastNonFullscreenBounds.dumpDebug(proto, LAST_NON_FULLSCREEN_BOUNDS); - } - - proto.write(ANIMATING_BOUNDS, mBoundsAnimating); - - if (mSurfaceControl != null) { - proto.write(SURFACE_WIDTH, mSurfaceControl.getWidth()); - proto.write(SURFACE_HEIGHT, mSurfaceControl.getHeight()); - } - - proto.write(CREATED_BY_ORGANIZER, mCreatedByOrganizer); - - proto.end(token); - } -} diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java index 8666a9efaeeb..0cd7ffce2ed4 100644 --- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java @@ -46,9 +46,6 @@ import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.TYPE_VIRTUAL; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.TAG_CLEANUP; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IDLE; @@ -74,11 +71,14 @@ import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_OR_ import static com.android.server.wm.RootWindowContainer.TAG_STATES; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_RECENTS; +import static com.android.server.wm.Task.ActivityState.PAUSED; +import static com.android.server.wm.Task.ActivityState.PAUSING; import static com.android.server.wm.Task.FLAG_FORCE_HIDDEN_FOR_PINNED_TASK; import static com.android.server.wm.Task.LOCK_TASK_AUTH_LAUNCHABLE; import static com.android.server.wm.Task.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; import static com.android.server.wm.Task.LOCK_TASK_AUTH_WHITELISTED; import static com.android.server.wm.Task.REPARENT_KEEP_STACK_AT_FRONT; +import static com.android.server.wm.Task.TAG_CLEANUP; import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; import static com.android.server.wm.WindowContainer.POSITION_TOP; @@ -380,12 +380,12 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { final ActivityRecord r; final ActivityRecord sourceRecord; final int startFlags; - final ActivityStack stack; + final Task stack; final WindowProcessController callerApp; final NeededUriGrants intentGrants; PendingActivityLaunch(ActivityRecord r, ActivityRecord sourceRecord, - int startFlags, ActivityStack stack, WindowProcessController callerApp, + int startFlags, Task stack, WindowProcessController callerApp, NeededUriGrants intentGrants) { this.r = r; this.sourceRecord = sourceRecord; @@ -493,7 +493,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { } void moveRecentsStackToFront(String reason) { - final ActivityStack recentsStack = mRootWindowContainer.getDefaultTaskDisplayArea() + final Task recentsStack = mRootWindowContainer.getDefaultTaskDisplayArea() .getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); if (recentsStack != null) { recentsStack.moveToFront(reason); @@ -729,7 +729,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { } final Task task = r.getTask(); - final ActivityStack stack = task.getStack(); + final Task rootTask = task.getRootTask(); beginDeferResume(); @@ -905,7 +905,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { if (andResume && readyToResume()) { // As part of the process of launching, ActivityThread also performs // a resume. - stack.minimalResumeActivityLocked(r); + rootTask.minimalResumeActivityLocked(r); } else { // This activity is not starting in the resumed state... which should look like we asked // it to pause+stop (but remain visible), and it has done so and reported back the @@ -923,7 +923,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { // launching the initial activity (that is, home), so that it can have // a chance to initialize itself while in the background, making the // switch back to it faster and look better. - if (mRootWindowContainer.isTopDisplayFocusedStack(stack)) { + if (mRootWindowContainer.isTopDisplayFocusedStack(rootTask)) { mService.getActivityStartController().startSetupActivity(); } @@ -990,7 +990,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { int requestCode, int callingPid, int callingUid, String callingPackage, @Nullable String callingFeatureId, boolean ignoreTargetSecurity, boolean launchingInTask, WindowProcessController callerApp, ActivityRecord resultRecord, - ActivityStack resultStack) { + Task resultStack) { final boolean isCallerRecents = mService.getRecentTasks() != null && mService.getRecentTasks().isCallerRecents(callingUid); final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, @@ -1332,7 +1332,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { /** This doesn't just find a task, it also moves the task to front. */ void findTaskToMoveToFront(Task task, int flags, ActivityOptions options, String reason, boolean forceNonResizeable) { - ActivityStack currentStack = task.getStack(); + Task currentStack = task.getRootTask(); if (currentStack == null) { Slog.e(TAG, "findTaskToMoveToFront: can't move task=" + task + " to front. Stack is null"); @@ -1349,7 +1349,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { final Rect bounds = options.getLaunchBounds(); task.setBounds(bounds); - ActivityStack stack = + Task stack = mRootWindowContainer.getLaunchStack(null, options, task, ON_TOP); if (stack != currentStack) { @@ -1388,7 +1388,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { private void moveHomeStackToFrontIfNeeded(int flags, TaskDisplayArea taskDisplayArea, String reason) { - final ActivityStack focusedStack = taskDisplayArea.getFocusedStack(); + final Task focusedStack = taskDisplayArea.getFocusedStack(); if ((taskDisplayArea.getWindowingMode() == WINDOWING_MODE_FULLSCREEN && (flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) @@ -1423,7 +1423,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { mWindowManager.setDockedStackResizing(resizing); } - private void removePinnedStackInSurfaceTransaction(ActivityStack stack) { + private void removePinnedStackInSurfaceTransaction(Task stack) { /** * Workaround: Force-stop all the activities in the pinned stack before we reparent them * to the fullscreen stack. This is to guarantee that when we are removing a stack, @@ -1459,7 +1459,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { } } - private void removeStackInSurfaceTransaction(ActivityStack stack) { + private void removeStackInSurfaceTransaction(Task stack) { if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { removePinnedStackInSurfaceTransaction(stack); } else { @@ -1479,7 +1479,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but * instead moved back onto the fullscreen stack. */ - void removeStack(ActivityStack stack) { + void removeStack(Task stack) { mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); } @@ -1597,7 +1597,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { * @return true if the task has been restored successfully. */ boolean restoreRecentTaskLocked(Task task, ActivityOptions aOptions, boolean onTop) { - final ActivityStack stack = + final Task stack = mRootWindowContainer.getLaunchStack(null, aOptions, task, onTop); final WindowContainer parent = task.getParent(); @@ -1639,8 +1639,8 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { * the various checks on tasks that are going to be reparented from one stack to another. */ // TODO: Look into changing users to this method to DisplayContent.resolveWindowingMode() - ActivityStack getReparentTargetStack(Task task, ActivityStack stack, boolean toTop) { - final ActivityStack prevStack = task.getStack(); + Task getReparentTargetStack(Task task, Task stack, boolean toTop) { + final Task prevStack = task.getRootTask(); final int rootTaskId = stack.mTaskId; final boolean inMultiWindowMode = stack.inMultiWindowMode(); @@ -1769,7 +1769,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { // A resumed activity cannot be stopping. remove from list mStoppingActivities.remove(r); - final ActivityStack stack = r.getRootTask(); + final Task stack = r.getRootTask(); if (stack.getDisplayArea().allResumedActivitiesComplete()) { mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); // Make sure activity & window visibility should be identical @@ -1783,15 +1783,15 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { // Called when WindowManager has finished animating the launchingBehind activity to the back. private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { final Task task = r.getTask(); - final ActivityStack stack = task.getStack(); + final Task rootTask = task.getRootTask(); mRecentTasks.add(task); mService.getTaskChangeNotificationController().notifyTaskStackChanged(); - stack.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); + rootTask.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); // When launching tasks behind, update the last active time of the top task after the new // task has been shown briefly - final ActivityRecord top = stack.getTopNonFinishingActivity(); + final ActivityRecord top = rootTask.getTopNonFinishingActivity(); if (top != null) { top.getTask().touchActiveTime(); } @@ -2028,7 +2028,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { */ void updateTopResumedActivityIfNeeded() { final ActivityRecord prevTopActivity = mTopResumedActivity; - final ActivityStack topStack = mRootWindowContainer.getTopDisplayFocusedStack(); + final Task topStack = mRootWindowContainer.getTopDisplayFocusedStack(); if (topStack == null || topStack.mResumedActivity == prevTopActivity) { return; } @@ -2124,13 +2124,13 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { } void handleNonResizableTaskIfNeeded(Task task, int preferredWindowingMode, - TaskDisplayArea preferredTaskDisplayArea, ActivityStack actualStack) { + TaskDisplayArea preferredTaskDisplayArea, Task actualStack) { handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredTaskDisplayArea, actualStack, false /* forceNonResizable */); } void handleNonResizableTaskIfNeeded(Task task, int preferredWindowingMode, - TaskDisplayArea preferredTaskDisplayArea, ActivityStack actualStack, + TaskDisplayArea preferredTaskDisplayArea, Task actualStack, boolean forceNonResizable) { final boolean isSecondaryDisplayPreferred = preferredTaskDisplayArea != null && preferredTaskDisplayArea.getDisplayId() != DEFAULT_DISPLAY; @@ -2186,7 +2186,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { // split-screen in split-screen. mService.getTaskChangeNotificationController() .notifyActivityDismissingDockedStack(); - taskDisplayArea.onSplitScreenModeDismissed((ActivityStack) task); + taskDisplayArea.onSplitScreenModeDismissed(task); taskDisplayArea.mDisplayContent.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS, true /* notifyClients */); } @@ -2242,14 +2242,14 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { } } - void scheduleUpdatePictureInPictureModeIfNeeded(Task task, ActivityStack prevStack) { - final ActivityStack stack = task.getStack(); - if ((prevStack == null || (prevStack != stack - && !prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode()))) { + void scheduleUpdatePictureInPictureModeIfNeeded(Task task, Task prevStack) { + final Task rootTask = task.getRootTask(); + if ((prevStack == null || (prevStack != rootTask + && !prevStack.inPinnedWindowingMode() && !rootTask.inPinnedWindowingMode()))) { return; } - scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getRequestedOverrideBounds()); + scheduleUpdatePictureInPictureModeIfNeeded(task, rootTask.getRequestedOverrideBounds()); } private void scheduleUpdatePictureInPictureModeIfNeeded(Task task, Rect targetStackBounds) { @@ -2281,7 +2281,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { final PooledConsumer c = PooledLambda.obtainConsumer( ActivityRecord::updatePictureInPictureMode, PooledLambda.__(ActivityRecord.class), targetStackBounds, forceUpdate); - task.getStack().setBounds(targetStackBounds); + task.getRootTask().setBounds(targetStackBounds); task.forAllActivities(c); c.recycle(); } @@ -2349,7 +2349,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { int uid = 0; synchronized (mService.mGlobalLock) { if (r.attachedToProcess() - && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { + && r.isState(Task.ActivityState.RESTARTING_PROCESS)) { processName = r.app.mName; uid = r.app.mUid; } @@ -2516,7 +2516,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { mService.getActivityStartController().postStartActivityProcessingForLastStarter( task.getTopNonFinishingActivity(), ActivityManager.START_TASK_TO_FRONT, - task.getStack()); + task.getRootTask()); return ActivityManager.START_TASK_TO_FRONT; } callingPackage = task.mCallingPackage; diff --git a/services/core/java/com/android/server/wm/ActivityStartController.java b/services/core/java/com/android/server/wm/ActivityStartController.java index 16ca60d1519b..e944faed6494 100644 --- a/services/core/java/com/android/server/wm/ActivityStartController.java +++ b/services/core/java/com/android/server/wm/ActivityStartController.java @@ -164,7 +164,7 @@ public class ActivityStartController { * last starter for an arbitrary task record. Re-evaluate whether we can remove. */ void postStartActivityProcessingForLastStarter(ActivityRecord r, int result, - ActivityStack targetStack) { + Task targetStack) { if (mLastStarter == null) { return; } @@ -190,7 +190,7 @@ public class ActivityStartController { // The home activity will be started later, defer resuming to avoid unneccerary operations // (e.g. start home recursively) when creating home stack. mSupervisor.beginDeferResume(); - final ActivityStack homeStack; + final Task homeStack; try { // Make sure home stack exists on display area. homeStack = taskDisplayArea.getOrCreateRootHomeTask(ON_TOP); diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index a8818b2775e2..751d0c8be24a 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -56,7 +56,6 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Process.INVALID_UID; import static android.view.Display.DEFAULT_DISPLAY; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; @@ -76,6 +75,7 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLAS import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_BOUNDS; import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_DISPLAY; +import static com.android.server.wm.Task.ActivityState.RESUMED; import static com.android.server.wm.Task.REPARENT_MOVE_STACK_TO_FRONT; import static com.android.server.wm.WindowContainer.POSITION_TOP; @@ -180,8 +180,8 @@ class ActivityStarter { private ActivityInfo mNewTaskInfo; private Intent mNewTaskIntent; - private ActivityStack mSourceStack; - private ActivityStack mTargetStack; + private Task mSourceStack; + private Task mTargetStack; // The task that the last activity was started into. We currently reset the actual start // activity's task and as a result may not have a reference to the task in all cases private Task mTargetTask; @@ -651,7 +651,7 @@ class ActivityStarter { synchronized (mService.mGlobalLock) { final boolean globalConfigWillChange = mRequest.globalConfig != null && mService.getGlobalConfiguration().diff(mRequest.globalConfig) != 0; - final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); + final Task stack = mRootWindowContainer.getTopDisplayFocusedStack(); if (stack != null) { stack.mConfigWillChange = globalConfigWillChange; } @@ -984,7 +984,7 @@ class ActivityStarter { } } - final ActivityStack resultStack = resultRecord == null + final Task resultStack = resultRecord == null ? null : resultRecord.getRootTask(); if (err != START_SUCCESS) { @@ -1122,7 +1122,7 @@ class ActivityStarter { null /*profilerInfo*/); if (DEBUG_PERMISSIONS_REVIEW) { - final ActivityStack focusedStack = + final Task focusedStack = mRootWindowContainer.getTopDisplayFocusedStack(); Slog.i(TAG, "START u" + userId + " {" + intent.toShortString(true, true, true, false) + "} from uid " + callingUid + " on display " @@ -1163,7 +1163,7 @@ class ActivityStarter { r.appTimeTracker = sourceRecord.appTimeTracker; } - final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); + final Task stack = mRootWindowContainer.getTopDisplayFocusedStack(); // If we are starting an activity that is not from the same uid as the currently resumed // one, check whether app switches are allowed. @@ -1445,7 +1445,7 @@ class ActivityStarter { } void postStartActivityProcessing(ActivityRecord r, int result, - ActivityStack startedActivityStack) { + Task startedActivityStack) { if (!ActivityManager.isStartResultSuccessful(result)) { if (mFrozeTaskList) { // If we specifically froze the task list as part of starting an activity, then @@ -1479,7 +1479,7 @@ class ActivityStarter { // The activity was already running so it wasn't started, but either brought to the // front or the new intent was delivered to it since it was already in front. Notify // anyone interested in this piece of information. - final ActivityStack homeStack = targetTask.getDisplayArea().getRootHomeTask(); + final Task homeStack = targetTask.getDisplayArea().getRootHomeTask(); final boolean homeTaskVisible = homeStack != null && homeStack.shouldBeVisible(null); mService.getTaskChangeNotificationController().notifyActivityRestartAttempt( targetTask.getTaskInfo(), homeTaskVisible, clearedTask, @@ -1514,7 +1514,7 @@ class ActivityStarter { int startFlags, boolean doResume, ActivityOptions options, Task inTask, boolean restrictedBgActivity, NeededUriGrants intentGrants) { int result = START_CANCELED; - final ActivityStack startedActivityStack; + final Task startedActivityStack; try { mService.deferWindowLayout(); Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "startActivityInner"); @@ -1537,9 +1537,9 @@ class ActivityStarter { * * @return the stack where the successful started activity resides. */ - private @Nullable ActivityStack handleStartResult(@NonNull ActivityRecord started, int result) { - final ActivityStack currentStack = started.getRootTask(); - ActivityStack startedActivityStack = currentStack != null ? currentStack : mTargetStack; + private @Nullable Task handleStartResult(@NonNull ActivityRecord started, int result) { + final Task currentStack = started.getRootTask(); + Task startedActivityStack = currentStack != null ? currentStack : mTargetStack; if (ActivityManager.isStartResultSuccessful(result)) { if (startedActivityStack != null) { @@ -1559,7 +1559,7 @@ class ActivityStarter { // If we are not able to proceed, disassociate the activity from the task. Leaving an // activity in an incomplete state can lead to issues, such as performing operations // without a window container. - final ActivityStack stack = mStartActivity.getRootTask(); + final Task stack = mStartActivity.getRootTask(); if (stack != null) { mStartActivity.finishIfPossible("startActivity", true /* oomAdj */); } @@ -1634,7 +1634,7 @@ class ActivityStarter { // If the activity being launched is the same as the one currently at the top, then // we need to check if it should only be launched once. - final ActivityStack topStack = mRootWindowContainer.getTopDisplayFocusedStack(); + final Task topStack = mRootWindowContainer.getTopDisplayFocusedStack(); if (topStack != null) { startResult = deliverToCurrentTopIfNeeded(topStack, intentGrants); if (startResult != START_SUCCESS) { @@ -1659,7 +1659,7 @@ class ActivityStarter { } if (!mAvoidMoveToFront && mDoResume) { - mTargetStack.getStack().moveToFront("reuseOrNewTask", targetTask); + mTargetStack.getRootTask().moveToFront("reuseOrNewTask", targetTask); if (mOptions != null) { if (mOptions.getTaskAlwaysOnTop()) { mTargetStack.setAlwaysOnTop(true); @@ -1752,7 +1752,7 @@ class ActivityStarter { } else if (mInTask != null) { return mInTask; } else { - final ActivityStack stack = getLaunchStack(mStartActivity, mLaunchFlags, + final Task stack = getLaunchStack(mStartActivity, mLaunchFlags, null /* task */, mOptions); final ActivityRecord top = stack.getTopNonFinishingActivity(); if (top != null) { @@ -1767,7 +1767,7 @@ class ActivityStarter { private void computeLaunchParams(ActivityRecord r, ActivityRecord sourceRecord, Task targetTask) { - final ActivityStack sourceStack = mSourceStack != null ? mSourceStack + final Task sourceStack = mSourceStack != null ? mSourceStack : mRootWindowContainer.getTopDisplayFocusedStack(); if (sourceStack != null && sourceStack.inSplitScreenWindowingMode() && (mOptions == null @@ -1851,7 +1851,7 @@ class ActivityStarter { // Should not recycle task which is from a different user, just adding the starting // activity to the task. if (targetTask.mUserId != mStartActivity.mUserId) { - mTargetStack = targetTask.getStack(); + mTargetStack = targetTask.getRootTask(); mAddingToTask = true; return START_SUCCESS; } @@ -1949,7 +1949,7 @@ class ActivityStarter { * Check if the activity being launched is the same as the one currently at the top and it * should only be launched once. */ - private int deliverToCurrentTopIfNeeded(ActivityStack topStack, NeededUriGrants intentGrants) { + private int deliverToCurrentTopIfNeeded(Task topStack, NeededUriGrants intentGrants) { final ActivityRecord top = topStack.topRunningNonDelayedActivityLocked(mNotTop); final boolean dontStart = top != null && mStartActivity.resultTo == null && top.mActivityComponent.equals(mStartActivity.mActivityComponent) @@ -2042,7 +2042,7 @@ class ActivityStarter { // running, and the caller has asked to clear the current task to have this // activity at the top. mAddingToTask = true; - if (targetTask.getStack() == null) { + if (targetTask.getRootTask() == null) { // Target stack got cleared when we all activities were removed above. // Go ahead and reset it. mTargetStack = @@ -2262,7 +2262,7 @@ class ActivityStarter { if ((startFlags & START_FLAG_ONLY_IF_NEEDED) != 0) { ActivityRecord checkedCaller = sourceRecord; if (checkedCaller == null) { - ActivityStack topFocusedStack = mRootWindowContainer.getTopDisplayFocusedStack(); + Task topFocusedStack = mRootWindowContainer.getTopDisplayFocusedStack(); if (topFocusedStack != null) { checkedCaller = topFocusedStack.topRunningNonDelayedActivityLocked(mNotTop); } @@ -2299,7 +2299,7 @@ class ActivityStarter { private void computeLaunchingTaskFlags() { // If the caller is not coming from another activity, but has given us an explicit task into // which they would like us to launch the new activity, then let's see about doing that. - if (mSourceRecord == null && mInTask != null && mInTask.getStack() != null) { + if (mSourceRecord == null && mInTask != null && mInTask.getRootTask() != null) { final Intent baseIntent = mInTask.getBaseIntent(); final ActivityRecord root = mInTask.getRootActivity(); if (baseIntent == null) { @@ -2482,7 +2482,7 @@ class ActivityStarter { // to the front if the caller is not itself in the front. final boolean differentTopTask; if (mTargetStack.getDisplayArea() == mPreferredTaskDisplayArea) { - final ActivityStack focusStack = mTargetStack.getDisplay().getFocusedStack(); + final Task focusStack = mTargetStack.getDisplay().getFocusedStack(); final ActivityRecord curTop = (focusStack == null) ? null : focusStack.topRunningNonDelayedActivityLocked(mNotTop); final Task topTask = curTop != null ? curTop.getTask() : null; @@ -2503,7 +2503,7 @@ class ActivityStarter { intentActivity.setTaskToAffiliateWith(mSourceRecord.getTask()); } - final ActivityStack launchStack = + final Task launchStack = getLaunchStack(mStartActivity, mLaunchFlags, intentTask, mOptions); if (launchStack == null || launchStack == mTargetStack) { // Do not set mMovedToFront to true below for split-screen-top stack, or @@ -2616,11 +2616,11 @@ class ActivityStarter { return launchFlags; } - private ActivityStack getLaunchStack(ActivityRecord r, int launchFlags, Task task, + private Task getLaunchStack(ActivityRecord r, int launchFlags, Task task, ActivityOptions aOptions) { // We are reusing a task, keep the stack! if (mReuseTask != null) { - return mReuseTask.getStack(); + return mReuseTask.getRootTask(); } final boolean onTop = diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 4e1d789bebd8..5dc0a108b92d 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -86,8 +86,6 @@ import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Scr import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; import static com.android.server.am.EventLogTags.writeBootProgressEnableScreen; import static com.android.server.am.EventLogTags.writeConfigurationChanged; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; @@ -120,6 +118,8 @@ import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_P import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_ONLY; import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS; +import static com.android.server.wm.Task.ActivityState.DESTROYED; +import static com.android.server.wm.Task.ActivityState.DESTROYING; import static com.android.server.wm.Task.LOCK_TASK_AUTH_DONT_LOCK; import static com.android.server.wm.Task.REPARENT_KEEP_STACK_AT_FRONT; import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE; @@ -1119,7 +1119,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { synchronized (mGlobalLock) { // If this is coming from the currently resumed activity, it is // effectively saying that app switches are allowed at this point. - final ActivityStack stack = getTopDisplayFocusedStack(); + final Task stack = getTopDisplayFocusedStack(); if (stack != null && stack.mResumedActivity != null && stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { mAppSwitchesAllowedTime = 0; @@ -1868,7 +1868,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { r = ActivityRecord.isInStackLocked(token); if (r != null) { if (r.attachedToProcess() - && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { + && r.isState(Task.ActivityState.RESTARTING_PROCESS)) { // The activity was requested to restart from // {@link #restartActivityProcessIfVisible}. restartingName = r.app.mName; @@ -1996,7 +1996,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { public boolean isTopActivityImmersive() { enforceNotIsolatedCaller("isTopActivityImmersive"); synchronized (mGlobalLock) { - final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); + final Task topFocusedStack = getTopDisplayFocusedStack(); if (topFocusedStack == null) { return false; } @@ -2018,7 +2018,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { final long origId = Binder.clearCallingIdentity(); if (self.isState( - ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { + Task.ActivityState.RESUMED, Task.ActivityState.PAUSING)) { self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( packageName, enterAnim, exitAnim, null, null); } @@ -2031,7 +2031,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { public int getFrontActivityScreenCompatMode() { enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); synchronized (mGlobalLock) { - final ActivityStack stack = getTopDisplayFocusedStack(); + final Task stack = getTopDisplayFocusedStack(); final ActivityRecord r = stack != null ? stack.topRunningActivity() : null; if (r == null) { return ActivityManager.COMPAT_MODE_UNKNOWN; @@ -2046,7 +2046,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { "setFrontActivityScreenCompatMode"); ApplicationInfo ai; synchronized (mGlobalLock) { - final ActivityStack stack = getTopDisplayFocusedStack(); + final Task stack = getTopDisplayFocusedStack(); final ActivityRecord r = stack != null ? stack.topRunningActivity() : null; if (r == null) { Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); @@ -2143,7 +2143,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { @Override public int getDisplayId(IBinder activityToken) throws RemoteException { synchronized (mGlobalLock) { - final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); + final Task stack = ActivityRecord.getStackLocked(activityToken); if (stack != null) { final int displayId = stack.getDisplayId(); return displayId != INVALID_DISPLAY ? displayId : DEFAULT_DISPLAY; @@ -2158,7 +2158,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { long ident = Binder.clearCallingIdentity(); try { synchronized (mGlobalLock) { - ActivityStack focusedStack = getTopDisplayFocusedStack(); + Task focusedStack = getTopDisplayFocusedStack(); if (focusedStack != null) { return mRootWindowContainer.getStackInfo(focusedStack.mTaskId); } @@ -2176,7 +2176,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { final long callingId = Binder.clearCallingIdentity(); try { synchronized (mGlobalLock) { - final ActivityStack stack = mRootWindowContainer.getStack(stackId); + final Task stack = mRootWindowContainer.getStack(stackId); if (stack == null) { Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); return; @@ -2393,7 +2393,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { + windowingMode); } - final ActivityStack stack = task.getStack(); + final Task stack = task.getRootTask(); if (toTop) { stack.moveToFront("setTaskWindowingMode", task); } @@ -2453,7 +2453,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { synchronized (mGlobalLock) { final long origId = Binder.clearCallingIdentity(); try { - final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); + final Task topFocusedStack = getTopDisplayFocusedStack(); if (topFocusedStack != null) { topFocusedStack.unhandledBackLocked(); } @@ -2470,7 +2470,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { if (r == null) { return; } - ActivityStack stack = r.getRootTask(); + Task stack = r.getRootTask(); final TaskOrganizerController taskOrgController = mWindowOrganizerController.mTaskOrganizerController; if (taskOrgController.handleInterceptBackPressedOnTaskRoot(stack)) { @@ -2727,7 +2727,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { @Override public boolean willActivityBeVisible(IBinder token) { synchronized (mGlobalLock) { - ActivityStack stack = ActivityRecord.getStackLocked(token); + Task stack = ActivityRecord.getStackLocked(token); if (stack != null) { return stack.willActivityBeVisible(token); } @@ -2750,7 +2750,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId + " to stackId=" + stackId + " toTop=" + toTop); - final ActivityStack stack = mRootWindowContainer.getStack(stackId); + final Task stack = mRootWindowContainer.getStack(stackId); if (stack == null) { throw new IllegalStateException( "moveTaskToStack: No stack for stackId=" + stackId); @@ -2829,7 +2829,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { void moveTaskToSplitScreenPrimaryTask(Task task, boolean toTop) { final TaskDisplayArea taskDisplayArea = task.getDisplayArea(); - final ActivityStack primarySplitTask = taskDisplayArea.getRootSplitScreenPrimaryTask(); + final Task primarySplitTask = taskDisplayArea.getRootSplitScreenPrimaryTask(); if (primarySplitTask == null) { throw new IllegalStateException("Can't enter split without associated organized task"); } @@ -2841,8 +2841,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { WindowContainerTransaction wct = new WindowContainerTransaction(); // Clear out current windowing mode before reparenting to split taks. wct.setWindowingMode( - task.getStack().mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_UNDEFINED); - wct.reparent(task.getStack().mRemoteToken.toWindowContainerToken(), + task.getRootTask().mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_UNDEFINED); + wct.reparent(task.getRootTask().mRemoteToken.toWindowContainerToken(), primarySplitTask.mRemoteToken.toWindowContainerToken(), toTop); mWindowOrganizerController.applyTransaction(wct); } @@ -2990,7 +2990,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } // When starting lock task mode the stack must be in front and focused - task.getStack().moveToFront("startSystemLockTaskMode"); + task.getRootTask().moveToFront("startSystemLockTaskMode"); startLockTaskModeLocked(task, true /* isSystemCaller */); } } finally { @@ -3025,7 +3025,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { return; } - final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); + final Task stack = mRootWindowContainer.getTopDisplayFocusedStack(); if (stack == null || task != stack.getTopMostTask()) { throw new IllegalArgumentException("Invalid task, not in foreground"); } @@ -3299,7 +3299,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); } - final ActivityStack stack = r.getRootTask(); + final Task stack = r.getRootTask(); final Task task = stack.getDisplayArea().createStack(stack.getWindowingMode(), stack.getActivityType(), !ON_TOP, ainfo, intent, false /* createdByOrganizer */); @@ -3460,7 +3460,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { synchronized (mGlobalLock) { final long ident = Binder.clearCallingIdentity(); try { - final ActivityStack stack = mRootWindowContainer.getStack(stackId); + final Task stack = mRootWindowContainer.getStack(stackId); if (stack == null) { Slog.w(TAG, "removeStack: No stack with id=" + stackId); return; @@ -3504,7 +3504,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { + token); } - final ActivityStack stack = r.getRootTask(); + final Task stack = r.getRootTask(); if (stack == null) { throw new IllegalStateException("toggleFreeformWindowingMode: the activity " + "doesn't have a stack"); @@ -3668,7 +3668,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { "enqueueAssistContext()"); synchronized (mGlobalLock) { - final ActivityStack stack = getTopDisplayFocusedStack(); + final Task stack = getTopDisplayFocusedStack(); ActivityRecord activity = stack != null ? stack.getTopNonFinishingActivity() : null; if (activity == null) { Slog.w(TAG, "getAssistContextExtras failed: no top activity"); @@ -3797,7 +3797,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { public boolean isAssistDataAllowedOnCurrentActivity() { int userId; synchronized (mGlobalLock) { - final ActivityStack focusedStack = getTopDisplayFocusedStack(); + final Task focusedStack = getTopDisplayFocusedStack(); if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { return false; } @@ -3970,7 +3970,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { + taskId); } - final ActivityStack stack = mRootWindowContainer.getStack(stackId); + final Task stack = mRootWindowContainer.getStack(stackId); if (stack == null) { throw new IllegalArgumentException("positionTaskInStack: no stack for id=" @@ -3983,7 +3983,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { // TODO: Have the callers of this API call a separate reparent method if that is // what they intended to do vs. having this method also do reparenting. - if (task.getStack() == stack) { + if (task.getRootTask() == stack) { // Change position in current stack. stack.positionChildAt(task, position); } else { @@ -4089,7 +4089,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); mRootWindowContainer.moveActivityToPinnedStack( r, "enterPictureInPictureMode"); - final ActivityStack stack = r.getRootTask(); + final Task stack = r.getRootTask(); stack.setPictureInPictureAspectRatio(aspectRatio); stack.setPictureInPictureActions(actions); MetricsLoggerWrapper.logPictureInPictureEnter(mContext, @@ -4134,7 +4134,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { // If the activity is already in picture-in-picture, update the pinned stack now // if it is not already expanding to fullscreen. Otherwise, the arguments will // be used the next time the activity enters PiP - final ActivityStack stack = r.getRootTask(); + final Task stack = r.getRootTask(); stack.setPictureInPictureAspectRatio( r.pictureInPictureArgs.getAspectRatio()); stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); @@ -4798,7 +4798,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } } - ActivityStack getTopDisplayFocusedStack() { + Task getTopDisplayFocusedStack() { return mRootWindowContainer.getTopDisplayFocusedStack(); } @@ -5769,7 +5769,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { /** Applies latest configuration and/or visibility updates if needed. */ boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { boolean kept = true; - final ActivityStack mainStack = mRootWindowContainer.getTopDisplayFocusedStack(); + final Task mainStack = mRootWindowContainer.getTopDisplayFocusedStack(); // mainStack is null during startup. if (mainStack != null) { if (changes != 0 && starting == null) { @@ -7024,7 +7024,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { mRootWindowContainer.dumpDisplayConfigs(pw, " "); } if (dumpAll) { - final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); + final Task topFocusedStack = getTopDisplayFocusedStack(); if (dumpPackage == null && topFocusedStack != null) { pw.println(" mConfigWillChange: " + topFocusedStack.mConfigWillChange); } @@ -7107,7 +7107,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { synchronized (mGlobalLock) { if (dumpPackage == null) { getGlobalConfiguration().dumpDebug(proto, GLOBAL_CONFIGURATION); - final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); + final Task topFocusedStack = getTopDisplayFocusedStack(); if (topFocusedStack != null) { proto.write(CONFIG_WILL_CHANGE, topFocusedStack.mConfigWillChange); } diff --git a/services/core/java/com/android/server/wm/CompatModePackages.java b/services/core/java/com/android/server/wm/CompatModePackages.java index 320ca65d215b..167afab9db0e 100644 --- a/services/core/java/com/android/server/wm/CompatModePackages.java +++ b/services/core/java/com/android/server/wm/CompatModePackages.java @@ -22,20 +22,6 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFI import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; - -import com.android.internal.util.FastXmlSerializer; - import android.app.ActivityManager; import android.app.AppGlobals; import android.content.pm.ApplicationInfo; @@ -51,6 +37,20 @@ import android.util.Slog; import android.util.SparseArray; import android.util.Xml; +import com.android.internal.util.FastXmlSerializer; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlSerializer; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + public final class CompatModePackages { private static final String TAG = TAG_WITH_CLASS_NAME ? "CompatModePackages" : TAG_ATM; private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; @@ -321,7 +321,7 @@ public final class CompatModePackages { scheduleWrite(); - final ActivityStack stack = mService.getTopDisplayFocusedStack(); + final Task stack = mService.getTopDisplayFocusedStack(); ActivityRecord starting = stack.restartPackage(packageName); // Tell all processes that loaded this package about the change. diff --git a/services/core/java/com/android/server/wm/DisplayArea.java b/services/core/java/com/android/server/wm/DisplayArea.java index fbb2fcb15aee..546c5d4c29de 100644 --- a/services/core/java/com/android/server/wm/DisplayArea.java +++ b/services/core/java/com/android/server/wm/DisplayArea.java @@ -93,7 +93,7 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> { // Verify that we have proper ordering Type.checkChild(mType, Type.typeOf(child)); - if (child instanceof ActivityStack) { + if (child instanceof Task) { // TODO(display-area): ActivityStacks are type ANY, but are allowed to have siblings. // They might need a separate type. return; @@ -487,7 +487,7 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> { return ((DisplayArea) c).mType; } else if (c instanceof WindowToken && !(c instanceof ActivityRecord)) { return typeOf((WindowToken) c); - } else if (c instanceof ActivityStack) { + } else if (c instanceof Task) { return ANY; } else { throw new IllegalArgumentException("Unknown container: " + c); diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 8fff81a1e8c4..936dbdfd4d37 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -78,7 +78,6 @@ import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_A import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; import static com.android.server.wm.DisplayContentProto.APP_TRANSITION; import static com.android.server.wm.DisplayContentProto.CLOSING_APPS; @@ -103,6 +102,7 @@ import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_IME; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_SCREEN_ON; import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS; +import static com.android.server.wm.Task.ActivityState.RESUMED; import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; import static com.android.server.wm.WindowContainerChildProto.DISPLAY_CONTENT; @@ -2193,13 +2193,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp * activity type. Null is no compatible stack on the display. */ @Nullable - ActivityStack getStack(int windowingMode, int activityType) { + Task getStack(int windowingMode, int activityType) { return getItemFromTaskDisplayAreas(taskDisplayArea -> taskDisplayArea.getStack(windowingMode, activityType)); } @Nullable - ActivityStack getStack(int rootTaskId) { + Task getStack(int rootTaskId) { return getItemFromTaskDisplayAreas(taskDisplayArea -> taskDisplayArea.getStack(rootTaskId)); } @@ -2211,7 +2211,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp @VisibleForTesting @Nullable - ActivityStack getTopStack() { + Task getTopStack() { return getItemFromTaskDisplayAreas(TaskDisplayArea::getTopStack); } @@ -2831,7 +2831,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp } proto.write(SINGLE_TASK_INSTANCE, mSingleTaskInstance); - final ActivityStack focusedStack = getFocusedStack(); + final Task focusedStack = getFocusedStack(); if (focusedStack != null) { proto.write(FOCUSED_ROOT_TASK_ID, focusedStack.getRootTaskId()); final ActivityRecord focusedActivity = focusedStack.getDisplayArea() @@ -2956,26 +2956,26 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp pw.println(); // Dump stack references - final ActivityStack homeStack = getDefaultTaskDisplayArea().getRootHomeTask(); + final Task homeStack = getDefaultTaskDisplayArea().getRootHomeTask(); if (homeStack != null) { pw.println(prefix + "homeStack=" + homeStack.getName()); } - final ActivityStack pinnedStack = getDefaultTaskDisplayArea().getRootPinnedTask(); + final Task pinnedStack = getDefaultTaskDisplayArea().getRootPinnedTask(); if (pinnedStack != null) { pw.println(prefix + "pinnedStack=" + pinnedStack.getName()); } - final ActivityStack splitScreenPrimaryStack = getDefaultTaskDisplayArea() + final Task splitScreenPrimaryStack = getDefaultTaskDisplayArea() .getRootSplitScreenPrimaryTask(); if (splitScreenPrimaryStack != null) { pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName()); } // TODO: Support recents on non-default task containers - final ActivityStack recentsStack = getDefaultTaskDisplayArea().getStack( + final Task recentsStack = getDefaultTaskDisplayArea().getStack( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); if (recentsStack != null) { pw.println(prefix + "recentsStack=" + recentsStack.getName()); } - final ActivityStack dreamStack = + final Task dreamStack = getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_DREAM); if (dreamStack != null) { pw.println(prefix + "dreamStack=" + dreamStack.getName()); @@ -4139,7 +4139,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp } private boolean processTask(Task task) { - if (!task.getStack().getWindowConfiguration().canResizeTask()) { + if (!task.getRootTask().getWindowConfiguration().canResizeTask()) { return true; } @@ -4953,7 +4953,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp } @Nullable - ActivityStack getFocusedStack() { + Task getFocusedStack() { return getItemFromTaskDisplayAreas(TaskDisplayArea::getFocusedStack); } @@ -5150,12 +5150,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp void remove() { mRemoving = true; - ActivityStack lastReparentedStack; + Task lastReparentedStack; mRootWindowContainer.mStackSupervisor.beginDeferResume(); try { lastReparentedStack = reduceOnAllTaskDisplayAreas((taskDisplayArea, stack) -> { - final ActivityStack lastReparentedStackFromArea = taskDisplayArea.remove(); + final Task lastReparentedStackFromArea = taskDisplayArea.remove(); if (lastReparentedStackFromArea != null) { return lastReparentedStackFromArea; } @@ -5191,7 +5191,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp if (taskDisplayArea.getStackCount() != 1) { return true; } - final ActivityStack stack = taskDisplayArea.getStackAt(0); + final Task stack = taskDisplayArea.getStackAt(0); return !stack.isActivityTypeHome() || stack.hasChild(); }); if (!hasNonEmptyHomeStack) { @@ -5294,7 +5294,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp + this); } if (stackCount > 0) { - final ActivityStack stack = getDefaultTaskDisplayArea().getStackAt(0); + final Task stack = getDefaultTaskDisplayArea().getStackAt(0); if (stack.getChildCount() > 1) { throw new IllegalArgumentException("Display stack already has multiple tasks." + " display=" + this + " stack=" + stack); @@ -5311,7 +5311,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp @VisibleForTesting void removeAllTasks() { - forAllTasks((t) -> { t.getStack().removeChild(t, "removeAllTasks"); }); + forAllTasks((t) -> { t.getRootTask().removeChild(t, "removeAllTasks"); }); } /** diff --git a/services/core/java/com/android/server/wm/DragResizeMode.java b/services/core/java/com/android/server/wm/DragResizeMode.java index 71beb5032914..eb27b046b9ab 100644 --- a/services/core/java/com/android/server/wm/DragResizeMode.java +++ b/services/core/java/com/android/server/wm/DragResizeMode.java @@ -35,7 +35,7 @@ class DragResizeMode { */ static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1; - static boolean isModeAllowedForStack(ActivityStack stack, int mode) { + static boolean isModeAllowedForStack(Task stack, int mode) { switch (mode) { case DRAG_RESIZE_MODE_FREEFORM: return stack.getWindowingMode() == WINDOWING_MODE_FREEFORM; diff --git a/services/core/java/com/android/server/wm/EnsureActivitiesVisibleHelper.java b/services/core/java/com/android/server/wm/EnsureActivitiesVisibleHelper.java index c4e03f5c65f5..c7cba77f6797 100644 --- a/services/core/java/com/android/server/wm/EnsureActivitiesVisibleHelper.java +++ b/services/core/java/com/android/server/wm/EnsureActivitiesVisibleHelper.java @@ -18,8 +18,8 @@ package com.android.server.wm; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; -import static com.android.server.wm.ActivityStack.TAG_VISIBILITY; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; +import static com.android.server.wm.Task.TAG_VISIBILITY; import android.annotation.Nullable; import android.util.Slog; @@ -29,7 +29,7 @@ import com.android.internal.util.function.pooled.PooledLambda; /** Helper class to ensure activities are in the right visible state for a container. */ class EnsureActivitiesVisibleHelper { - private final ActivityStack mContiner; + private final Task mContiner; private ActivityRecord mTop; private ActivityRecord mStarting; private boolean mAboveTop; @@ -39,7 +39,7 @@ class EnsureActivitiesVisibleHelper { private boolean mPreserveWindows; private boolean mNotifyClients; - EnsureActivitiesVisibleHelper(ActivityStack container) { + EnsureActivitiesVisibleHelper(Task container) { mContiner = container; } @@ -69,7 +69,7 @@ class EnsureActivitiesVisibleHelper { /** * Ensure visibility with an option to also update the configuration of visible activities. - * @see ActivityStack#ensureActivitiesVisible(ActivityRecord, int, boolean) + * @see Task#ensureActivitiesVisible(ActivityRecord, int, boolean) * @see RootWindowContainer#ensureActivitiesVisible(ActivityRecord, int, boolean) * @param starting The top most activity in the task. * The activity is either starting or resuming. diff --git a/services/core/java/com/android/server/wm/KeyguardController.java b/services/core/java/com/android/server/wm/KeyguardController.java index 76f236534b69..aea36d2ccdad 100644 --- a/services/core/java/com/android/server/wm/KeyguardController.java +++ b/services/core/java/com/android/server/wm/KeyguardController.java @@ -475,7 +475,7 @@ class KeyguardController { mOccluded = false; mDismissingKeyguardActivity = null; - final ActivityStack stack = getStackForControllingOccluding(display); + final Task stack = getStackForControllingOccluding(display); if (stack != null) { final ActivityRecord topDismissing = stack.getTopDismissingKeyguardActivity(); mOccluded = stack.topActivityOccludesKeyguard() || (topDismissing != null @@ -516,10 +516,10 @@ class KeyguardController { * occlusion state. */ @Nullable - private ActivityStack getStackForControllingOccluding(DisplayContent display) { + private Task getStackForControllingOccluding(DisplayContent display) { return display.getItemFromTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); if (stack != null && stack.isFocusableAndVisible() && !stack.inPinnedWindowingMode()) { return stack; diff --git a/services/core/java/com/android/server/wm/LaunchParamsController.java b/services/core/java/com/android/server/wm/LaunchParamsController.java index 513be7a6becc..56e1187d51da 100644 --- a/services/core/java/com/android/server/wm/LaunchParamsController.java +++ b/services/core/java/com/android/server/wm/LaunchParamsController.java @@ -145,10 +145,10 @@ class LaunchParamsController { } if (mTmpParams.hasWindowingMode() - && mTmpParams.mWindowingMode != task.getStack().getWindowingMode()) { + && mTmpParams.mWindowingMode != task.getRootTask().getWindowingMode()) { final int activityType = activity != null ? activity.getActivityType() : task.getActivityType(); - task.getStack().setWindowingMode(task.getDisplayArea().validateWindowingMode( + task.getRootTask().setWindowingMode(task.getDisplayArea().validateWindowingMode( mTmpParams.mWindowingMode, activity, task, activityType)); } @@ -156,7 +156,7 @@ class LaunchParamsController { return false; } - if (task.getStack().inFreeformWindowingMode()) { + if (task.getRootTask().inFreeformWindowingMode()) { // Only set bounds if it's in freeform mode. task.setBounds(mTmpParams.mBounds); return true; diff --git a/services/core/java/com/android/server/wm/LockTaskController.java b/services/core/java/com/android/server/wm/LockTaskController.java index 892ee717e21f..c7a438d527ad 100644 --- a/services/core/java/com/android/server/wm/LockTaskController.java +++ b/services/core/java/com/android/server/wm/LockTaskController.java @@ -151,7 +151,7 @@ public class LockTaskController { * The first task in the list, which started the current LockTask session, is called the root * task. It coincides with the Home task in a typical multi-app kiosk deployment. When there are * more than one locked tasks, the root task can't be finished. Nor can it be moved to the back - * of the stack by {@link ActivityStack#moveTaskToBack(Task)}; + * of the stack by {@link Task#moveTaskToBack(Task)}; * * Calling {@link Activity#stopLockTask()} on the root task will finish all tasks but itself in * this list, and the device will exit LockTask mode. @@ -252,7 +252,7 @@ public class LockTaskController { /** * @return whether the given task can be moved to the back of the stack with - * {@link ActivityStack#moveTaskToBack(Task)} + * {@link Task#moveTaskToBack(Task)} * @see #mLockTaskModeTasks */ boolean canMoveTaskToBack(Task task) { @@ -617,14 +617,14 @@ public class LockTaskController { mSupervisor.findTaskToMoveToFront(task, 0, null, reason, lockTaskModeState != LOCK_TASK_MODE_NONE); mSupervisor.mRootWindowContainer.resumeFocusedStacksTopActivities(); - final ActivityStack stack = task.getStack(); - if (stack != null) { - stack.getDisplay().mDisplayContent.executeAppTransition(); + final Task rootTask = task.getRootTask(); + if (rootTask != null) { + rootTask.getDisplay().mDisplayContent.executeAppTransition(); } } else if (lockTaskModeState != LOCK_TASK_MODE_NONE) { mSupervisor.handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, mSupervisor.mRootWindowContainer.getDefaultTaskDisplayArea(), - task.getStack(), true /* forceNonResizable */); + task.getRootTask(), true /* forceNonResizable */); } } diff --git a/services/core/java/com/android/server/wm/RecentTasks.java b/services/core/java/com/android/server/wm/RecentTasks.java index 851b533a550d..ba2c0b6dc0ac 100644 --- a/services/core/java/com/android/server/wm/RecentTasks.java +++ b/services/core/java/com/android/server/wm/RecentTasks.java @@ -215,7 +215,7 @@ class RecentTasks { final RootWindowContainer rac = mService.mRootWindowContainer; final DisplayContent dc = rac.getDisplayContent(displayId).mDisplayContent; if (dc.pointWithinAppWindow(x, y)) { - final ActivityStack stack = mService.getTopDisplayFocusedStack(); + final Task stack = mService.getTopDisplayFocusedStack(); final Task topTask = stack != null ? stack.getTopMostTask() : null; resetFreezeTaskListReordering(topTask); } @@ -323,7 +323,7 @@ class RecentTasks { @VisibleForTesting void resetFreezeTaskListReorderingOnTimeout() { synchronized (mService.mGlobalLock) { - final ActivityStack focusedStack = mService.getTopDisplayFocusedStack(); + final Task focusedStack = mService.getTopDisplayFocusedStack(); final Task topTask = focusedStack != null ? focusedStack.getTopMostTask() : null; resetFreezeTaskListReordering(topTask); } @@ -520,9 +520,9 @@ class RecentTasks { * Kicks off the task persister to write any pending tasks to disk. */ void notifyTaskPersisterLocked(Task task, boolean flush) { - final ActivityStack stack = task != null ? task.getStack() : null; - if (stack != null && stack.isHomeOrRecentsStack()) { - // Never persist the home or recents stack. + final Task rootTask = task != null ? task.getRootTask() : null; + if (rootTask != null && rootTask.isHomeOrRecentsStack()) { + // Never persist the home or recents task. return; } syncPersistentTaskIdsLocked(); @@ -554,8 +554,8 @@ class RecentTasks { } private static boolean shouldPersistTaskLocked(Task task) { - final ActivityStack stack = task.getStack(); - return task.isPersistable && (stack == null || !stack.isHomeOrRecentsStack()); + final Task rootTask = task.getRootTask(); + return task.isPersistable && (rootTask == null || !rootTask.isHomeOrRecentsStack()); } void onSystemReadyLocked() { @@ -975,9 +975,9 @@ class RecentTasks { final Task task = mTasks.get(i); if (TaskPersister.DEBUG) Slog.d(TAG, "LazyTaskWriter: task=" + task + " persistable=" + task.isPersistable); - final ActivityStack stack = task.getStack(); + final Task rootTask = task.getRootTask(); if ((task.isPersistable || task.inRecents) - && (stack == null || !stack.isHomeOrRecentsStack())) { + && (rootTask == null || !rootTask.isHomeOrRecentsStack())) { if (TaskPersister.DEBUG) Slog.d(TAG, "adding to persistentTaskIds task=" + task); persistentTaskIds.add(task.mTaskId); } else { @@ -1325,10 +1325,10 @@ class RecentTasks { return false; case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: if (DEBUG_RECENTS_TRIM_TASKS) { - Slog.d(TAG, "\ttop=" + task.getStack().getTopMostTask()); + Slog.d(TAG, "\ttop=" + task.getRootTask().getTopMostTask()); } - final ActivityStack stack = task.getStack(); - if (stack != null && stack.getTopMostTask() == task) { + final Task rootTask = task.getRootTask(); + if (rootTask != null && rootTask.getTopMostTask() == task) { // Only the non-top task of the primary split screen mode is visible return false; } @@ -1344,9 +1344,9 @@ class RecentTasks { // Tasks managed by/associated with an ActivityView should be excluded from recents. // singleTaskInstance is set on the VirtualDisplay managed by ActivityView // TODO(b/126185105): Find a different signal to use besides isSingleTaskInstance - final ActivityStack stack = task.getStack(); - if (stack != null) { - DisplayContent display = stack.getDisplay(); + final Task rootTask = task.getRootTask(); + if (rootTask != null) { + DisplayContent display = rootTask.getDisplay(); if (display != null && display.isSingleTaskInstance()) { return false; } @@ -1400,21 +1400,21 @@ class RecentTasks { /** @return whether the given task can be trimmed even if it is outside the visible range. */ protected boolean isTrimmable(Task task) { - final ActivityStack stack = task.getStack(); + final Task rootTask = task.getRootTask(); // No stack for task, just trim it - if (stack == null) { + if (rootTask == null) { return true; } // Ignore tasks from different displays // TODO (b/115289124): No Recents on non-default displays. - if (!stack.isOnHomeDisplay()) { + if (!rootTask.isOnHomeDisplay()) { return false; } - final ActivityStack rootHomeTask = stack.getDisplayArea().getRootHomeTask(); - // Home stack does not exist. Don't trim the task. + final Task rootHomeTask = rootTask.getDisplayArea().getRootHomeTask(); + // Home task does not exist. Don't trim the task. if (rootHomeTask == null) { return false; } diff --git a/services/core/java/com/android/server/wm/RecentsAnimation.java b/services/core/java/com/android/server/wm/RecentsAnimation.java index 00272ad57be4..d7b43bc5537d 100644 --- a/services/core/java/com/android/server/wm/RecentsAnimation.java +++ b/services/core/java/com/android/server/wm/RecentsAnimation.java @@ -76,7 +76,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, private ActivityRecord mLaunchedTargetActivity; // The stack to restore the target stack behind when the animation is finished - private ActivityStack mRestoreTargetBehindStack; + private Task mRestoreTargetBehindStack; RecentsAnimation(ActivityTaskManagerService atm, ActivityStackSupervisor stackSupervisor, ActivityStartController activityStartController, WindowManagerService wm, @@ -107,7 +107,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, void preloadRecentsActivity() { ProtoLog.d(WM_DEBUG_RECENTS_ANIMATIONS, "Preload recents with %s", mTargetIntent); - ActivityStack targetStack = mDefaultTaskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED, + Task targetStack = mDefaultTaskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED, mTargetActivityType); ActivityRecord targetActivity = getTargetActivity(targetStack); if (targetActivity != null) { @@ -150,8 +150,8 @@ class RecentsAnimation implements RecentsAnimationCallbacks, // Invisible activity should be stopped. If the recents activity is alive and its doesn't // need to relaunch by current configuration, then it may be already in stopped state. - if (!targetActivity.isState(ActivityStack.ActivityState.STOPPING, - ActivityStack.ActivityState.STOPPED)) { + if (!targetActivity.isState(Task.ActivityState.STOPPING, + Task.ActivityState.STOPPED)) { // Add to stopping instead of stop immediately. So the client has the chance to perform // traversal in non-stopped state (ViewRootImpl.mStopped) that would initialize more // things (e.g. the measure can be done earlier). The actual stop will be performed when @@ -166,7 +166,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "RecentsAnimation#startRecentsActivity"); // If the activity is associated with the recents stack, then try and get that first - ActivityStack targetStack = mDefaultTaskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED, + Task targetStack = mDefaultTaskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED, mTargetActivityType); ActivityRecord targetActivity = getTargetActivity(targetStack); final boolean hasExistingActivity = targetActivity != null; @@ -299,7 +299,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, try { mWindowManager.cleanupRecentsAnimation(reorderMode); - final ActivityStack targetStack = mDefaultTaskDisplayArea.getStack( + final Task targetStack = mDefaultTaskDisplayArea.getStack( WINDOWING_MODE_UNDEFINED, mTargetActivityType); // Prefer to use the original target activity instead of top activity because // we may have moved another task to top (starting 3p launcher). @@ -333,7 +333,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, } if (WM_DEBUG_RECENTS_ANIMATIONS.isLogToAny()) { - final ActivityStack topStack = getTopNonAlwaysOnTopStack(); + final Task topStack = getTopNonAlwaysOnTopStack(); if (topStack != targetStack) { ProtoLog.w(WM_DEBUG_RECENTS_ANIMATIONS, "Expected target stack=%s" @@ -347,7 +347,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, taskDisplayArea.moveStackBehindStack(targetStack, mRestoreTargetBehindStack); if (WM_DEBUG_RECENTS_ANIMATIONS.isLogToAny()) { - final ActivityStack aboveTargetStack = getStackAbove(targetStack); + final Task aboveTargetStack = getStackAbove(targetStack); if (mRestoreTargetBehindStack != null && aboveTargetStack != mRestoreTargetBehindStack) { ProtoLog.w(WM_DEBUG_RECENTS_ANIMATIONS, @@ -411,7 +411,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, } @Override - public void onStackOrderChanged(ActivityStack stack) { + public void onStackOrderChanged(Task stack) { ProtoLog.d(WM_DEBUG_RECENTS_ANIMATIONS, "onStackOrderChanged(): stack=%s", stack); if (mDefaultTaskDisplayArea.getIndexOf(stack) == -1 || !stack.shouldBeVisible(null)) { // The stack is not visible, so ignore this change @@ -466,9 +466,9 @@ class RecentsAnimation implements RecentsAnimationCallbacks, /** * @return The top stack that is not always-on-top. */ - private ActivityStack getTopNonAlwaysOnTopStack() { + private Task getTopNonAlwaysOnTopStack() { for (int i = mDefaultTaskDisplayArea.getStackCount() - 1; i >= 0; i--) { - final ActivityStack s = mDefaultTaskDisplayArea.getStackAt(i); + final Task s = mDefaultTaskDisplayArea.getStackAt(i); if (s.getWindowConfiguration().isAlwaysOnTop()) { continue; } @@ -481,7 +481,7 @@ class RecentsAnimation implements RecentsAnimationCallbacks, * @return the top activity in the {@param targetStack} matching the {@param component}, or just * the top activity of the top task if no task matches the component. */ - private ActivityRecord getTargetActivity(ActivityStack targetStack) { + private ActivityRecord getTargetActivity(Task targetStack) { if (targetStack == null) { return null; } diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java index 55bca2ee2791..f5bd4cd866a6 100644 --- a/services/core/java/com/android/server/wm/RecentsAnimationController.java +++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java @@ -362,7 +362,7 @@ public class RecentsAnimationController implements DeathRecipient { // TODO(b/153090560): Support Recents on multiple task display areas final ArrayList<Task> visibleTasks = mDisplayContent.getDefaultTaskDisplayArea() .getVisibleTasks(); - final ActivityStack targetStack = mDisplayContent.getDefaultTaskDisplayArea() + final Task targetStack = mDisplayContent.getDefaultTaskDisplayArea() .getStack(WINDOWING_MODE_UNDEFINED, targetActivityType); if (targetStack != null) { final PooledConsumer c = PooledLambda.obtainConsumer((t, outList) -> @@ -406,7 +406,7 @@ public class RecentsAnimationController implements DeathRecipient { } // Save the minimized home height - final ActivityStack rootHomeTask = + final Task rootHomeTask = mDisplayContent.getDefaultTaskDisplayArea().getRootHomeTask(); mMinimizedHomeBounds = rootHomeTask != null ? rootHomeTask.getBounds() : null; diff --git a/services/core/java/com/android/server/wm/ResetTargetTaskHelper.java b/services/core/java/com/android/server/wm/ResetTargetTaskHelper.java index 32de699eaae9..cc5ed36e0f47 100644 --- a/services/core/java/com/android/server/wm/ResetTargetTaskHelper.java +++ b/services/core/java/com/android/server/wm/ResetTargetTaskHelper.java @@ -16,10 +16,10 @@ package com.android.server.wm; -import static com.android.server.wm.ActivityStack.TAG_ADD_REMOVE; -import static com.android.server.wm.ActivityStack.TAG_TASKS; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; +import static com.android.server.wm.Task.TAG_ADD_REMOVE; +import static com.android.server.wm.Task.TAG_TASKS; import android.app.ActivityOptions; import android.content.Intent; @@ -37,7 +37,7 @@ import java.util.ArrayList; class ResetTargetTaskHelper { private Task mTask; private Task mTargetTask; - private ActivityStack mTargetStack; + private Task mTargetStack; private ActivityRecord mRoot; private boolean mForceReset; private boolean mCanMoveOptions; @@ -61,7 +61,7 @@ class ResetTargetTaskHelper { mForceReset = forceReset; mTargetTask = targetTask; mTargetTaskFound = false; - mTargetStack = targetTask.getStack(); + mTargetStack = targetTask.getRootTask(); mActivityReparentPosition = -1; final PooledConsumer c = PooledLambda.obtainConsumer( diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index 50ae4ea2f627..424196861769 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -44,11 +44,6 @@ import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; import static com.android.server.policy.PhoneWindowManager.SYSTEM_DIALOG_REASON_ASSIST; import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; -import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList; @@ -74,6 +69,11 @@ import static com.android.server.wm.RootWindowContainerProto.IS_HOME_RECENTS_COM import static com.android.server.wm.RootWindowContainerProto.KEYGUARD_CONTROLLER; import static com.android.server.wm.RootWindowContainerProto.PENDING_ACTIVITIES; import static com.android.server.wm.RootWindowContainerProto.WINDOW_CONTAINER; +import static com.android.server.wm.Task.ActivityState.FINISHING; +import static com.android.server.wm.Task.ActivityState.PAUSED; +import static com.android.server.wm.Task.ActivityState.RESUMED; +import static com.android.server.wm.Task.ActivityState.STOPPED; +import static com.android.server.wm.Task.ActivityState.STOPPING; import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE; import static com.android.server.wm.Task.REPARENT_MOVE_STACK_TO_FRONT; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; @@ -314,7 +314,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * Returns the top activity in any existing task matching the given Intent in the input * result. Returns null if no such task is found. */ - void process(ActivityRecord target, ActivityStack parent) { + void process(ActivityRecord target, Task parent) { mTarget = target; intent = target.intent; @@ -1475,7 +1475,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> boolean fromHomeKey) { // Fallback to top focused display or default display if the displayId is invalid. if (displayId == INVALID_DISPLAY) { - final ActivityStack stack = getTopDisplayFocusedStack(); + final Task stack = getTopDisplayFocusedStack(); displayId = stack != null ? stack.getDisplayId() : DEFAULT_DISPLAY; } @@ -1501,7 +1501,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> boolean allowInstrumenting, boolean fromHomeKey) { // Fallback to top focused display area if the provided one is invalid. if (taskDisplayArea == null) { - final ActivityStack stack = getTopDisplayFocusedStack(); + final Task stack = getTopDisplayFocusedStack(); taskDisplayArea = stack != null ? stack.getDisplayArea() : getDefaultTaskDisplayArea(); } @@ -1818,12 +1818,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent> */ List<IBinder> getTopVisibleActivities() { final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); - final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); + final Task topFocusedStack = getTopDisplayFocusedStack(); // Traverse all displays. forAllTaskDisplayAreas(taskDisplayArea -> { // Traverse all stacks on a display area. for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); // Get top activity from a visible stack and add it to the list. if (stack.shouldBeVisible(null /* starting */)) { final ActivityRecord top = stack.getTopNonFinishingActivity(); @@ -1841,9 +1841,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } @Nullable - ActivityStack getTopDisplayFocusedStack() { + Task getTopDisplayFocusedStack() { for (int i = getChildCount() - 1; i >= 0; --i) { - final ActivityStack focusedStack = getChildAt(i).getFocusedStack(); + final Task focusedStack = getChildAt(i).getFocusedStack(); if (focusedStack != null) { return focusedStack; } @@ -1853,7 +1853,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> @Nullable ActivityRecord getTopResumedActivity() { - final ActivityStack focusedStack = getTopDisplayFocusedStack(); + final Task focusedStack = getTopDisplayFocusedStack(); if (focusedStack == null) { return null; } @@ -1866,7 +1866,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> return getItemFromTaskDisplayAreas(TaskDisplayArea::getFocusedActivity); } - boolean isTopDisplayFocusedStack(ActivityStack stack) { + boolean isTopDisplayFocusedStack(Task stack) { return stack != null && stack == getTopDisplayFocusedStack(); } @@ -1879,7 +1879,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> // foreground. WindowProcessController fgApp = reduceOnAllTaskDisplayAreas((taskDisplayArea, app) -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); if (isTopDisplayFocusedStack(stack)) { final ActivityRecord resumedActivity = stack.getResumedActivity(); if (resumedActivity != null) { @@ -1907,7 +1907,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> boolean didSomething = false; for (int displayNdx = getChildCount() - 1; displayNdx >= 0; --displayNdx) { final DisplayContent display = getChildAt(displayNdx); - final ActivityStack stack = display.getFocusedStack(); + final Task stack = display.getFocusedStack(); if (stack == null) { continue; } @@ -1984,7 +1984,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } boolean switchUser(int userId, UserState uss) { - final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); + final Task topFocusedStack = getTopDisplayFocusedStack(); final int focusStackId = topFocusedStack != null ? topFocusedStack.getRootTaskId() : INVALID_TASK_ID; // We dismiss the docked stack whenever we switch users. @@ -2002,13 +2002,13 @@ class RootWindowContainer extends WindowContainer<DisplayContent> mStackSupervisor.mStartingUsers.add(uss); forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); stack.switchUser(userId); } }); final int restoreStackId = mUserStackInFront.get(userId); - ActivityStack stack = getStack(restoreStackId); + Task stack = getStack(restoreStackId); if (stack == null) { stack = getDefaultTaskDisplayArea().getOrCreateRootHomeTask(); } @@ -2030,7 +2030,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * Update the last used stack id for non-current user (current user's last * used stack is the focused stack) */ - void updateUserStack(int userId, ActivityStack stack) { + void updateUserStack(int userId, Task stack) { if (userId != mCurrentUser) { if (stack == null) { stack = getDefaultTaskDisplayArea().getOrCreateRootHomeTask(); @@ -2047,7 +2047,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * @param onTop Indicates whether container should be place on top or on bottom. */ void moveStackToTaskDisplayArea(int stackId, TaskDisplayArea taskDisplayArea, boolean onTop) { - final ActivityStack stack = getStack(stackId); + final Task stack = getStack(stackId); if (stack == null) { throw new IllegalArgumentException("moveStackToTaskDisplayArea: Unknown stackId=" + stackId); @@ -2096,7 +2096,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } boolean moveTopStackActivityToPinnedStack(int stackId) { - final ActivityStack stack = getStack(stackId); + final Task stack = getStack(stackId); if (stack == null) { throw new IllegalArgumentException( "moveTopStackActivityToPinnedStack: Unknown stackId=" + stackId); @@ -2126,7 +2126,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> try { final Task task = r.getTask(); - final ActivityStack pinnedStack = taskDisplayArea.getRootPinnedTask(); + final Task pinnedStack = taskDisplayArea.getRootPinnedTask(); // This will change the pinned stack's windowing mode to its original mode, ensuring // we only have one stack that is in pinned mode. @@ -2139,9 +2139,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> r.getDisplayContent().prepareAppTransition(TRANSIT_NONE, false); final boolean singleActivity = task.getChildCount() == 1; - final ActivityStack stack; + final Task stack; if (singleActivity) { - stack = (ActivityStack) task; + stack = task; } else { // In the case of multiple activities, we will create a new task for it and then // move the PIP activity into the task. @@ -2248,13 +2248,13 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * @return The task id that was finished in this stack, or INVALID_TASK_ID if none was finished. */ int finishTopCrashedActivities(WindowProcessController app, String reason) { - ActivityStack focusedStack = getTopDisplayFocusedStack(); + Task focusedStack = getTopDisplayFocusedStack(); Task finishedTask = reduceOnAllTaskDisplayAreas((taskDisplayArea, task) -> { // It is possible that request to finish activity might also remove its task and // stack, so we need to be careful with indexes in the loop and check child count // every time. for (int stackNdx = 0; stackNdx < taskDisplayArea.getStackCount(); ++stackNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(stackNdx); + final Task stack = taskDisplayArea.getStackAt(stackNdx); final Task t = stack.finishTopCrashedActivityLocked(app, reason); if (stack == focusedStack || task == null) { task = t; @@ -2270,7 +2270,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } boolean resumeFocusedStacksTopActivities( - ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { + Task targetStack, ActivityRecord target, ActivityOptions targetOptions) { if (!mStackSupervisor.readyToResume()) { return false; @@ -2292,7 +2292,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> boolean resumedOnDisplay = display.reduceOnAllTaskDisplayAreas( (taskDisplayArea, resumed) -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); final ActivityRecord topRunningActivity = stack.topRunningActivity(); if (!stack.isFocusableAndVisible() || topRunningActivity == null) { continue; @@ -2322,7 +2322,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> // crashed) it's possible that nothing was resumed on a display. Requesting resume // of top activity in focused stack explicitly will make sure that at least home // activity is started and resumed, and no recursion occurs. - final ActivityStack focusedStack = display.getFocusedStack(); + final Task focusedStack = display.getFocusedStack(); if (focusedStack != null) { result |= focusedStack.resumeTopActivityUncheckedLocked(target, targetOptions); } else if (targetStack == null) { @@ -2352,7 +2352,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> // Set the sleeping state of the stacks on the display. display.forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); if (displayShouldSleep) { stack.goToSleepIfPossible(false /* shuttingDown */); } else { @@ -2393,9 +2393,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } } - protected ActivityStack getStack(int stackId) { + protected Task getStack(int stackId) { for (int i = getChildCount() - 1; i >= 0; --i) { - final ActivityStack stack = getChildAt(i).getStack(stackId); + final Task stack = getChildAt(i).getStack(stackId); if (stack != null) { return stack; } @@ -2404,9 +2404,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } /** @see DisplayContent#getStack(int, int) */ - ActivityStack getStack(int windowingMode, int activityType) { + Task getStack(int windowingMode, int activityType) { for (int i = getChildCount() - 1; i >= 0; --i) { - final ActivityStack stack = getChildAt(i).getStack(windowingMode, activityType); + final Task stack = getChildAt(i).getStack(windowingMode, activityType); if (stack != null) { return stack; } @@ -2414,7 +2414,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> return null; } - private ActivityStack getStack(int windowingMode, int activityType, + private Task getStack(int windowingMode, int activityType, int displayId) { DisplayContent display = getDisplayContent(displayId); if (display == null) { @@ -2423,7 +2423,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> return display.getStack(windowingMode, activityType); } - private ActivityManager.StackInfo getStackInfo(ActivityStack stack) { + private ActivityManager.StackInfo getStackInfo(Task stack) { final TaskDisplayArea taskDisplayArea = stack.getDisplayArea(); ActivityManager.StackInfo info = new ActivityManager.StackInfo(); stack.getBounds(info.bounds); @@ -2469,7 +2469,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } ActivityManager.StackInfo getStackInfo(int stackId) { - ActivityStack stack = getStack(stackId); + Task stack = getStack(stackId); if (stack != null) { return getStackInfo(stack); } @@ -2477,12 +2477,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { - final ActivityStack stack = getStack(windowingMode, activityType); + final Task stack = getStack(windowingMode, activityType); return (stack != null) ? getStackInfo(stack) : null; } ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType, int displayId) { - final ActivityStack stack = getStack(windowingMode, activityType, displayId); + final Task stack = getStack(windowingMode, activityType, displayId); return (stack != null) ? getStackInfo(stack) : null; } @@ -2492,7 +2492,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> if (displayId == INVALID_DISPLAY) { forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); list.add(getStackInfo(stack)); } }); @@ -2504,7 +2504,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } display.forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); list.add(getStackInfo(stack)); } }); @@ -2576,7 +2576,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); } - ActivityStack findStackBehind(ActivityStack stack) { + Task findStackBehind(Task stack) { final TaskDisplayArea taskDisplayArea = stack.getDisplayArea(); if (taskDisplayArea != null) { for (int i = taskDisplayArea.getStackCount() - 1; i >= 0; i--) { @@ -2716,7 +2716,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> if (sNdx >= taskDisplayArea.getStackCount()) { continue; } - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); if (allowDelay) { result &= stack.goToSleepIfPossible(shuttingDown); } else { @@ -2787,7 +2787,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> return false; } - ActivityStack getLaunchStack(@Nullable ActivityRecord r, + Task getLaunchStack(@Nullable ActivityRecord r, @Nullable ActivityOptions options, @Nullable Task candidateTask, boolean onTop) { return getLaunchStack(r, options, candidateTask, onTop, null /* launchParams */, -1 /* no realCallingPid */, -1 /* no realCallingUid */); @@ -2805,7 +2805,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * * @return The stack to use for the launch or INVALID_STACK_ID. */ - ActivityStack getLaunchStack(@Nullable ActivityRecord r, + Task getLaunchStack(@Nullable ActivityRecord r, @Nullable ActivityOptions options, @Nullable Task candidateTask, boolean onTop, @Nullable LaunchParamsController.LaunchParams launchParams, int realCallingPid, int realCallingUid) { @@ -2831,12 +2831,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent> MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); options.setLaunchTaskId(taskId); if (task != null) { - return task.getStack(); + return task.getRootTask(); } } final int activityType = resolveActivityType(r, options, candidateTask); - ActivityStack stack = null; + Task stack = null; // Next preference for stack goes to the taskDisplayArea candidate. if (launchParams != null && launchParams.mPreferredTaskDisplayArea != null) { @@ -2858,7 +2858,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> realCallingPid, realCallingUid, r.info); if (canLaunchOnDisplayFromStartRequest || canLaunchOnDisplay(r, tdaDisplayId)) { if (r != null) { - final ActivityStack result = getValidLaunchStackInTaskDisplayArea( + final Task result = getValidLaunchStackInTaskDisplayArea( taskDisplayArea, r, candidateTask, options, launchParams); if (result != null) { return result; @@ -2878,7 +2878,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> // mode we want to launch into. TaskDisplayArea container = null; if (candidateTask != null) { - stack = candidateTask.getStack(); + stack = candidateTask.getRootTask(); } if (stack == null && r != null) { stack = r.getRootTask(); @@ -2940,7 +2940,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. */ @VisibleForTesting - ActivityStack getValidLaunchStackInTaskDisplayArea(@NonNull TaskDisplayArea taskDisplayArea, + Task getValidLaunchStackInTaskDisplayArea(@NonNull TaskDisplayArea taskDisplayArea, @NonNull ActivityRecord r, @Nullable Task candidateTask, @Nullable ActivityOptions options, @Nullable LaunchParamsController.LaunchParams launchParams) { @@ -2956,12 +2956,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent> final TaskDisplayArea attachedTaskDisplayArea = r.getTask() != null ? r.getTask().getDisplayArea() : r.getDisplayArea(); if (attachedTaskDisplayArea == null || attachedTaskDisplayArea == taskDisplayArea) { - return candidateTask.getStack(); + return candidateTask.getRootTask(); } // Or the candidate task is already a root task that can be reused by reparenting // it to the target display. if (candidateTask.isRootTask()) { - final ActivityStack stack = candidateTask.getStack(); + final Task stack = candidateTask.getRootTask(); stack.reparent(taskDisplayArea, true /* onTop */); return stack; } @@ -2982,7 +2982,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> // Return the topmost valid stack on the display. for (int i = taskDisplayArea.getStackCount() - 1; i >= 0; --i) { - final ActivityStack stack = taskDisplayArea.getStackAt(i); + final Task stack = taskDisplayArea.getStackAt(i); if (isValidLaunchStack(stack, r, windowingMode)) { return stack; } @@ -3002,7 +3002,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> } // TODO: Can probably be consolidated into getLaunchStack()... - private boolean isValidLaunchStack(ActivityStack stack, ActivityRecord r, int windowingMode) { + private boolean isValidLaunchStack(Task stack, ActivityRecord r, int windowingMode) { switch (stack.getActivityType()) { case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); @@ -3050,9 +3050,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> * @param currentFocus The stack that previously had focus. * @param ignoreCurrent If we should ignore {@param currentFocus} when searching for next * candidate. - * @return Next focusable {@link ActivityStack}, {@code null} if not found. + * @return Next focusable {@link Task}, {@code null} if not found. */ - ActivityStack getNextFocusableStack(@NonNull ActivityStack currentFocus, + Task getNextFocusableStack(@NonNull Task currentFocus, boolean ignoreCurrent) { // First look for next focusable stack on the same display TaskDisplayArea preferredDisplayArea = currentFocus.getDisplayArea(); @@ -3062,7 +3062,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> preferredDisplayArea = getDisplayContent(currentFocus.mPrevDisplayId) .getDefaultTaskDisplayArea(); } - final ActivityStack preferredFocusableStack = preferredDisplayArea.getNextFocusableStack( + final Task preferredFocusableStack = preferredDisplayArea.getNextFocusableStack( currentFocus, ignoreCurrent); if (preferredFocusableStack != null) { return preferredFocusableStack; @@ -3081,7 +3081,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> // We've already checked this one continue; } - final ActivityStack nextFocusableStack = display.getDefaultTaskDisplayArea() + final Task nextFocusableStack = display.getDefaultTaskDisplayArea() .getNextFocusableStack(currentFocus, ignoreCurrent); if (nextFocusableStack != null) { return nextFocusableStack; @@ -3094,7 +3094,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> boolean handleAppDied(WindowProcessController app) { return reduceOnAllTaskDisplayAreas((taskDisplayArea, result) -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); result |= stack.handleAppDied(app); } return result; @@ -3218,7 +3218,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> forAllTaskDisplayAreas(taskDisplayArea -> { final int numStacks = taskDisplayArea.getStackCount(); for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(stackNdx); + final Task stack = taskDisplayArea.getStackAt(stackNdx); stack.finishVoiceTask(session); } }); @@ -3261,7 +3261,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> // If the focused stack is not null or not empty, there should have some activities // resuming or resumed. Make sure these activities are idle. - final ActivityStack stack = display.getFocusedStack(); + final Task stack = display.getFocusedStack(); if (stack == null || !stack.hasActivity()) { continue; } @@ -3284,7 +3284,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> final boolean foundInvisibleResumedActivity = forAllTaskDisplayAreas( taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); final ActivityRecord r = stack.getResumedActivity(); if (r != null) { if (!r.nowVisible) { @@ -3306,7 +3306,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> final boolean hasActivityNotCompleted = forAllTaskDisplayAreas( taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); final ActivityRecord r = stack.mPausingActivity; if (r != null && !r.isState(PAUSED, STOPPED, STOPPING, FINISHING)) { if (DEBUG_STATES) { @@ -3412,9 +3412,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> if (aOptions != null) { // Resolve the stack the task should be placed in now based on options // and reparent if needed. - final ActivityStack launchStack = + final Task launchStack = getLaunchStack(null, aOptions, task, onTop); - if (launchStack != null && task.getStack() != launchStack) { + if (launchStack != null && task.getRootTask() != launchStack) { final int reparentMode = onTop ? REPARENT_MOVE_STACK_TO_FRONT : REPARENT_LEAVE_STACK_IN_PLACE; task.reparent(launchStack, onTop, reparentMode, ANIMATE, DEFER_RESUME, @@ -3526,7 +3526,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> ArrayList<ActivityRecord> getDumpActivities(String name, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { if (dumpFocusedStackOnly) { - final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); + final Task topFocusedStack = getTopDisplayFocusedStack(); if (topFocusedStack != null) { return topFocusedStack.getDumpActivitiesLocked(name); } else { @@ -3536,7 +3536,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> ArrayList<ActivityRecord> activities = new ArrayList<>(); forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { activities.addAll(stack.getDumpActivitiesLocked(name)); } @@ -3585,7 +3585,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> pw.println(" (activities from top to bottom):"); displayContent.forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); if (needSep[0]) { pw.println(); } diff --git a/services/core/java/com/android/server/wm/RunningTasks.java b/services/core/java/com/android/server/wm/RunningTasks.java index 3509ba72d058..6cf9432089b4 100644 --- a/services/core/java/com/android/server/wm/RunningTasks.java +++ b/services/core/java/com/android/server/wm/RunningTasks.java @@ -48,7 +48,7 @@ class RunningTasks { private ArraySet<Integer> mProfileIds; private boolean mAllowed; private boolean mFilterOnlyVisibleRecents; - private ActivityStack mTopDisplayFocusStack; + private Task mTopDisplayFocusStack; private RecentTasks mRecentTasks; void getTasks(int maxNum, List<RunningTaskInfo> list, boolean filterOnlyVisibleRecents, @@ -114,7 +114,7 @@ class RunningTasks { return; } - final ActivityStack stack = task.getStack(); + final Task stack = task.getRootTask(); if (stack == mTopDisplayFocusStack && stack.getTopMostTask() == task) { // For the focused stack top task, update the last stack active time so that it can be // used to determine the order of the tasks (it may not be set for newly created tasks) diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 970520aff81f..83fff262d321 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -19,6 +19,7 @@ package com.android.server.wm; import static android.app.ActivityTaskManager.INVALID_TASK_ID; import static android.app.ActivityTaskManager.RESIZE_MODE_FORCED; import static android.app.ActivityTaskManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION; +import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; @@ -28,6 +29,7 @@ import static android.app.WindowConfiguration.PINNED_WINDOWING_MODE_ELEVATION_IN import static android.app.WindowConfiguration.ROTATION_UNDEFINED; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; +import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; @@ -37,7 +39,10 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS; import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME; +import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; +import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING; +import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; @@ -55,36 +60,91 @@ import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.ORIENTATION_UNDEFINED; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; import static android.provider.Settings.Secure.USER_SETUP_COMPLETE; +import static android.view.Display.DEFAULT_DISPLAY; +import static android.view.Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; import static android.view.Display.INVALID_DISPLAY; import static android.view.SurfaceControl.METADATA_TASK_ID; +import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; +import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; +import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; +import static android.view.WindowManager.TRANSIT_NONE; +import static android.view.WindowManager.TRANSIT_SHOW_SINGLE_TASK_DISPLAY; import static android.view.WindowManager.TRANSIT_TASK_CHANGE_WINDOWING_MODE; +import static android.view.WindowManager.TRANSIT_TASK_CLOSE; +import static android.view.WindowManager.TRANSIT_TASK_OPEN; +import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND; +import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; +import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; import static com.android.internal.policy.DecorView.DECOR_SHADOW_FOCUSED_HEIGHT_IN_DIP; import static com.android.internal.policy.DecorView.DECOR_SHADOW_UNFOCUSED_HEIGHT_IN_DIP; import static com.android.server.wm.ActivityRecord.STARTING_WINDOW_SHOWN; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_INVISIBLE; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; +import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; +import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList; +import static com.android.server.wm.ActivityStackSupervisor.printThisActivity; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_APP; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TRANSITION; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_USER_LEAVING; import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_ADD_REMOVE; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_APP; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CLEANUP; import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_PAUSE; import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RECENTS; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RESULTS; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TRANSITION; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_LEAVING; +import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; -import static com.android.server.wm.ActivityTaskManagerService.TAG_STACK; +import static com.android.server.wm.ActivityTaskManagerService.H.FIRST_ACTIVITY_STACK_MSG; +import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; +import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; import static com.android.server.wm.IdentifierProto.HASH_CODE; import static com.android.server.wm.IdentifierProto.TITLE; import static com.android.server.wm.IdentifierProto.USER_ID; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_RECENTS_ANIMATIONS; +import static com.android.server.wm.Task.ActivityState.PAUSED; +import static com.android.server.wm.Task.ActivityState.PAUSING; +import static com.android.server.wm.Task.ActivityState.RESUMED; +import static com.android.server.wm.Task.ActivityState.STARTED; +import static com.android.server.wm.Task.ActivityState.STOPPED; +import static com.android.server.wm.Task.ActivityState.STOPPING; +import static com.android.server.wm.TaskProto.ACTIVITY_TYPE; +import static com.android.server.wm.TaskProto.ANIMATING_BOUNDS; +import static com.android.server.wm.TaskProto.BOUNDS; +import static com.android.server.wm.TaskProto.CREATED_BY_ORGANIZER; +import static com.android.server.wm.TaskProto.DISPLAY_ID; +import static com.android.server.wm.TaskProto.FILLS_PARENT; +import static com.android.server.wm.TaskProto.LAST_NON_FULLSCREEN_BOUNDS; +import static com.android.server.wm.TaskProto.MIN_HEIGHT; +import static com.android.server.wm.TaskProto.MIN_WIDTH; +import static com.android.server.wm.TaskProto.ORIG_ACTIVITY; +import static com.android.server.wm.TaskProto.REAL_ACTIVITY; +import static com.android.server.wm.TaskProto.RESIZE_MODE; +import static com.android.server.wm.TaskProto.RESUMED_ACTIVITY; +import static com.android.server.wm.TaskProto.ROOT_TASK_ID; +import static com.android.server.wm.TaskProto.SURFACE_HEIGHT; +import static com.android.server.wm.TaskProto.SURFACE_WIDTH; +import static com.android.server.wm.TaskProto.WINDOW_CONTAINER; import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; import static com.android.server.wm.WindowContainerChildProto.TASK; @@ -103,11 +163,20 @@ import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.TaskDescription; import android.app.ActivityManager.TaskSnapshot; +import android.app.ActivityManagerInternal; import android.app.ActivityOptions; import android.app.ActivityTaskManager; import android.app.AppGlobals; +import android.app.IActivityController; +import android.app.RemoteAction; +import android.app.ResultInfo; import android.app.TaskInfo; import android.app.WindowConfiguration; +import android.app.servertransaction.ActivityResultItem; +import android.app.servertransaction.ClientTransaction; +import android.app.servertransaction.NewIntentItem; +import android.app.servertransaction.PauseActivityItem; +import android.app.servertransaction.ResumeActivityItem; import android.content.ComponentName; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -117,8 +186,12 @@ import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.Point; import android.graphics.Rect; +import android.os.Binder; import android.os.Debug; +import android.os.Handler; import android.os.IBinder; +import android.os.Looper; +import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.os.Trace; @@ -127,8 +200,10 @@ import android.provider.Settings; import android.service.voice.IVoiceInteractionSession; import android.util.ArraySet; import android.util.DisplayMetrics; +import android.util.Log; import android.util.Slog; import android.util.proto.ProtoOutputStream; +import android.view.Display; import android.view.DisplayInfo; import android.view.RemoteAnimationAdapter; import android.view.RemoteAnimationTarget; @@ -137,36 +212,54 @@ import android.view.SurfaceControl; import android.view.WindowManager; import android.window.ITaskOrganizer; +import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.IVoiceInteractor; +import com.android.internal.os.logging.MetricsLoggerWrapper; import com.android.internal.util.XmlUtils; import com.android.internal.util.function.pooled.PooledConsumer; import com.android.internal.util.function.pooled.PooledFunction; import com.android.internal.util.function.pooled.PooledLambda; import com.android.internal.util.function.pooled.PooledPredicate; +import com.android.server.Watchdog; +import com.android.server.am.ActivityManagerService; +import com.android.server.am.AppTimeTracker; import com.android.server.protolog.common.ProtoLog; -import com.android.server.wm.ActivityStack.ActivityState; +import com.android.server.uri.NeededUriGrants; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; +import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; +import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; class Task extends WindowContainer<WindowContainer> { private static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_ATM; - private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; + static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; - private static final String TAG_TASKS = TAG + POSTFIX_TASKS; + static final String TAG_TASKS = TAG + POSTFIX_TASKS; + private static final String TAG_APP = TAG + POSTFIX_APP; + static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; + private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; + private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; + private static final String TAG_STACK = TAG + POSTFIX_STACK; + private static final String TAG_STATES = TAG + POSTFIX_STATES; + private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; + private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; + private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; + static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; private static final String ATTR_TASKID = "task_id"; private static final String TAG_INTENT = "intent"; @@ -202,6 +295,14 @@ class Task extends WindowContainer<WindowContainer> { private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version"; private static final String ATTR_WINDOW_LAYOUT_AFFINITY = "window_layout_affinity"; + // Set to false to disable the preview that is shown while a new activity + // is being started. + private static final boolean SHOW_APP_STARTING_PREVIEW = true; + + // How long to wait for all background Activities to redraw following a call to + // convertToTranslucent(). + private static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; + // Current version of the task record we persist. Used to check if we need to run any upgrade // code. static final int PERSIST_TASK_VERSION = 1; @@ -226,6 +327,58 @@ class Task extends WindowContainer<WindowContainer> { // Do not move the stack as a part of reparenting static final int REPARENT_LEAVE_STACK_IN_PLACE = 2; + @IntDef(prefix = {"STACK_VISIBILITY"}, value = { + STACK_VISIBILITY_VISIBLE, + STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, + STACK_VISIBILITY_INVISIBLE, + }) + @interface StackVisibility {} + + /** Stack is visible. No other stacks on top that fully or partially occlude it. */ + static final int STACK_VISIBILITY_VISIBLE = 0; + + /** Stack is partially occluded by other translucent stack(s) on top of it. */ + static final int STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT = 1; + + /** Stack is completely invisible. */ + static final int STACK_VISIBILITY_INVISIBLE = 2; + + enum ActivityState { + INITIALIZING, + STARTED, + RESUMED, + PAUSING, + PAUSED, + STOPPING, + STOPPED, + FINISHING, + DESTROYING, + DESTROYED, + RESTARTING_PROCESS + } + + // The topmost Activity passed to convertToTranslucent(). When non-null it means we are + // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they + // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the + // Activity in mTranslucentActivityWaiting is notified via + // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last + // background activity being drawn then the same call will be made with a true value. + ActivityRecord mTranslucentActivityWaiting = null; + ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); + + /** + * Set when we know we are going to be calling updateConfiguration() + * soon, so want to skip intermediate config checks. + */ + boolean mConfigWillChange; + + /** + * Used to keep resumeTopActivityUncheckedLocked() from being entered recursively + */ + boolean mInResumeTopActivity = false; + + int mCurrentUser; + String affinity; // The affinity name for this task, or null; may change identity. String rootAffinity; // Initial base affinity, or null; does not change from initial root. String mWindowLayoutAffinity; // Launch param affinity of this task or null. Used when saving @@ -447,6 +600,274 @@ class Task extends WindowContainer<WindowContainer> { SurfaceControl.Transaction mMainWindowSizeChangeTransaction; Task mMainWindowSizeChangeTask; + // If this is true, we are in the bounds animating mode. The task will be down or upscaled to + // perfectly fit the region it would have been cropped to. We may also avoid certain logic we + // would otherwise apply while resizing, while resizing in the bounds animating mode. + private boolean mBoundsAnimating = false; + // Set when an animation has been requested but has not yet started from the UI thread. This is + // cleared when the animation actually starts. + private boolean mBoundsAnimatingRequested = false; + private Rect mBoundsAnimationTarget = new Rect(); + private Rect mBoundsAnimationSourceHintBounds = new Rect(); + + Rect mPreAnimationBounds = new Rect(); + + private final AnimatingActivityRegistry mAnimatingActivityRegistry = + new AnimatingActivityRegistry(); + + private boolean mTopActivityOccludesKeyguard; + private ActivityRecord mTopDismissingKeyguardActivity; + + private static final int TRANSLUCENT_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 1; + + private final Handler mHandler; + + private class ActivityStackHandler extends Handler { + + ActivityStackHandler(Looper looper) { + super(looper); + } + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case TRANSLUCENT_TIMEOUT_MSG: { + synchronized (mAtmService.mGlobalLock) { + notifyActivityDrawnLocked(null); + } + } break; + } + } + } + + private static final ResetTargetTaskHelper sResetTargetTaskHelper = new ResetTargetTaskHelper(); + private final EnsureActivitiesVisibleHelper mEnsureActivitiesVisibleHelper = + new EnsureActivitiesVisibleHelper(this); + private final EnsureVisibleActivitiesConfigHelper mEnsureVisibleActivitiesConfigHelper = + new EnsureVisibleActivitiesConfigHelper(); + private class EnsureVisibleActivitiesConfigHelper { + private boolean mUpdateConfig; + private boolean mPreserveWindow; + private boolean mBehindFullscreen; + + void reset(boolean preserveWindow) { + mPreserveWindow = preserveWindow; + mUpdateConfig = false; + mBehindFullscreen = false; + } + + void process(ActivityRecord start, boolean preserveWindow) { + if (start == null || !start.mVisibleRequested) { + return; + } + reset(preserveWindow); + + final PooledFunction f = PooledLambda.obtainFunction( + EnsureVisibleActivitiesConfigHelper::processActivity, this, + PooledLambda.__(ActivityRecord.class)); + forAllActivities(f, start, true /*includeBoundary*/, true /*traverseTopToBottom*/); + f.recycle(); + + if (mUpdateConfig) { + // Ensure the resumed state of the focus activity if we updated the configuration of + // any activity. + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + } + + boolean processActivity(ActivityRecord r) { + mUpdateConfig |= r.ensureActivityConfiguration(0 /*globalChanges*/, mPreserveWindow); + mBehindFullscreen |= r.occludesParent(); + return mBehindFullscreen; + } + } + + private final CheckBehindFullscreenActivityHelper mCheckBehindFullscreenActivityHelper = + new CheckBehindFullscreenActivityHelper(); + private class CheckBehindFullscreenActivityHelper { + private boolean mAboveTop; + private boolean mBehindFullscreenActivity; + private ActivityRecord mToCheck; + private Consumer<ActivityRecord> mHandleBehindFullscreenActivity; + private boolean mHandlingOccluded; + + private void reset(ActivityRecord toCheck, + Consumer<ActivityRecord> handleBehindFullscreenActivity) { + mToCheck = toCheck; + mHandleBehindFullscreenActivity = handleBehindFullscreenActivity; + mAboveTop = true; + mBehindFullscreenActivity = false; + + if (!shouldBeVisible(null)) { + // The stack is not visible, so no activity in it should be displaying a starting + // window. Mark all activities below top and behind fullscreen. + mAboveTop = false; + mBehindFullscreenActivity = true; + } + + mHandlingOccluded = mToCheck == null && mHandleBehindFullscreenActivity != null; + } + + boolean process(ActivityRecord toCheck, + Consumer<ActivityRecord> handleBehindFullscreenActivity) { + reset(toCheck, handleBehindFullscreenActivity); + + if (!mHandlingOccluded && mBehindFullscreenActivity) { + return true; + } + + final ActivityRecord topActivity = topRunningActivity(); + final PooledFunction f = PooledLambda.obtainFunction( + CheckBehindFullscreenActivityHelper::processActivity, this, + PooledLambda.__(ActivityRecord.class), topActivity); + forAllActivities(f); + f.recycle(); + + return mBehindFullscreenActivity; + } + + /** Returns {@code true} to stop the outer loop and indicate the result is computed. */ + private boolean processActivity(ActivityRecord r, ActivityRecord topActivity) { + if (mAboveTop) { + if (r == topActivity) { + if (r == mToCheck) { + // It is the top activity in a visible stack. + mBehindFullscreenActivity = false; + return true; + } + mAboveTop = false; + } + mBehindFullscreenActivity |= r.occludesParent(); + return false; + } + + if (mHandlingOccluded) { + // Iterating through all occluded activities. + if (mBehindFullscreenActivity) { + mHandleBehindFullscreenActivity.accept(r); + } + } else if (r == mToCheck) { + return true; + } else if (mBehindFullscreenActivity) { + // It is occluded before {@param toCheck} is found. + return true; + } + mBehindFullscreenActivity |= r.occludesParent(); + return false; + } + } + + // TODO: Can we just loop through WindowProcessController#mActivities instead of doing this? + private final RemoveHistoryRecordsForApp mRemoveHistoryRecordsForApp = + new RemoveHistoryRecordsForApp(); + private class RemoveHistoryRecordsForApp { + private boolean mHasVisibleActivities; + private boolean mIsProcessRemoved; + private WindowProcessController mApp; + private ArrayList<ActivityRecord> mToRemove = new ArrayList<>(); + + boolean process(WindowProcessController app) { + mToRemove.clear(); + mHasVisibleActivities = false; + mApp = app; + mIsProcessRemoved = app.isRemoved(); + if (mIsProcessRemoved) { + // The package of the died process should be force-stopped, so make its activities + // as finishing to prevent the process from being started again if the next top + // (or being visible) activity also resides in the same process. + app.makeFinishingForProcessRemoved(); + } + + final PooledConsumer c = PooledLambda.obtainConsumer( + RemoveHistoryRecordsForApp::addActivityToRemove, this, + PooledLambda.__(ActivityRecord.class)); + forAllActivities(c); + c.recycle(); + + while (!mToRemove.isEmpty()) { + processActivity(mToRemove.remove(0)); + } + + mApp = null; + return mHasVisibleActivities; + } + + private void addActivityToRemove(ActivityRecord r) { + if (r.app == mApp) { + mToRemove.add(r); + } + } + + private void processActivity(ActivityRecord r) { + if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record " + r + ": app=" + r.app); + + if (r.app != mApp) { + return; + } + if (r.isVisible() || r.mVisibleRequested) { + // While an activity launches a new activity, it's possible that the old + // activity is already requested to be hidden (mVisibleRequested=false), but + // this visibility is not yet committed, so isVisible()=true. + mHasVisibleActivities = true; + } + final boolean remove; + if ((r.mRelaunchReason == RELAUNCH_REASON_WINDOWING_MODE_RESIZE + || r.mRelaunchReason == RELAUNCH_REASON_FREE_RESIZE) + && r.launchCount < 3 && !r.finishing) { + // If the process crashed during a resize, always try to relaunch it, unless + // it has failed more than twice. Skip activities that's already finishing + // cleanly by itself. + remove = false; + } else if ((!r.hasSavedState() && !r.stateNotNeeded + && !r.isState(ActivityState.RESTARTING_PROCESS)) || r.finishing) { + // Don't currently have state for the activity, or + // it is finishing -- always remove it. + remove = true; + } else if (!r.mVisibleRequested && r.launchCount > 2 + && r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { + // We have launched this activity too many times since it was + // able to run, so give up and remove it. + // (Note if the activity is visible, we don't remove the record. + // We leave the dead window on the screen but the process will + // not be restarted unless user explicitly tap on it.) + remove = true; + } else { + // The process may be gone, but the activity lives on! + remove = false; + } + if (remove) { + if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, + "Removing activity " + r + " from stack " + + ": hasSavedState=" + r.hasSavedState() + + " stateNotNeeded=" + r.stateNotNeeded + + " finishing=" + r.finishing + + " state=" + r.getState() + " callers=" + Debug.getCallers(5)); + if (!r.finishing || mIsProcessRemoved) { + Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); + EventLogTags.writeWmFinishActivity(r.mUserId, + System.identityHashCode(r), r.getTask().mTaskId, + r.shortComponentName, "proc died without state saved"); + } + } else { + // We have the current state for this activity, so + // it can be restarted later when needed. + if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); + if (DEBUG_APP) Slog.v(TAG_APP, + "Clearing app during removeHistory for activity " + r); + r.app = null; + // Set nowVisible to previous visible state. If the app was visible while + // it died, we leave the dead window on screen so it's basically visible. + // This is needed when user later tap on the dead window, we need to stop + // other apps when user transfers focus to the restarted activity. + r.nowVisible = r.mVisibleRequested; + } + r.cleanUp(true /* cleanServices */, true /* setState */); + if (remove) { + r.removeFromHistory("appDied"); + } + } + } + private final FindRootHelper mFindRootHelper = new FindRootHelper(); private class FindRootHelper { private ActivityRecord mRoot; @@ -507,12 +928,22 @@ class Task extends WindowContainer<WindowContainer> { boolean mCreatedByOrganizer; /** - * Don't use constructor directly. Use {@link #create(ActivityTaskManagerService, int, - * ActivityInfo, Intent, TaskDescription)} instead. + * Don't use constructor directly. Use {@link TaskDisplayArea#createStackUnchecked()} instead. + */ + Task(ActivityTaskManagerService atmService, int id, int activityType, + ActivityInfo info, Intent intent, boolean createdByOrganizer) { + this(atmService, id, info, intent, null /*voiceSession*/, null /*voiceInteractor*/, + null /*taskDescription*/, null /*stack*/); + mCreatedByOrganizer = createdByOrganizer; + setActivityType(activityType); + } + + /** + * Don't use constructor directly. Use {@link Task#reuseOrCreateTask()} instead. */ Task(ActivityTaskManagerService atmService, int _taskId, ActivityInfo info, Intent _intent, IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, - TaskDescription _taskDescription, ActivityStack stack) { + TaskDescription _taskDescription, Task stack) { this(atmService, _taskId, _intent, null /*_affinityIntent*/, null /*_affinity*/, null /*_rootAffinity*/, null /*_realActivity*/, null /*_origActivity*/, false /*_rootWasReset*/, false /*_autoRemoveRecents*/, false /*_askedCompatMode*/, @@ -538,7 +969,7 @@ class Task extends WindowContainer<WindowContainer> { @Nullable String callingFeatureId, int resizeMode, boolean supportsPictureInPicture, boolean _realActivitySuspended, boolean userSetupComplete, int minWidth, int minHeight, ActivityInfo info, IVoiceInteractionSession _voiceSession, - IVoiceInteractor _voiceInteractor, ActivityStack stack) { + IVoiceInteractor _voiceInteractor, Task stack) { super(atmService.mWindowManager); EventLogTags.writeWmTaskCreated(_taskId, stack != null ? getRootTaskId() : INVALID_TASK_ID); @@ -587,6 +1018,8 @@ class Task extends WindowContainer<WindowContainer> { mMinHeight = minHeight; } mAtmService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity); + mHandler = new ActivityStackHandler(mStackSupervisor.mLooper); + mCurrentUser = mAtmService.mAmInternal.getCurrentUserId(); } Task reuseAsLeafTask(IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, @@ -727,7 +1160,7 @@ class Task extends WindowContainer<WindowContainer> { } /** Convenience method to reparent a task to the top or bottom position of the stack. */ - boolean reparent(ActivityStack preferredStack, boolean toTop, + boolean reparent(Task preferredStack, boolean toTop, @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, String reason) { return reparent(preferredStack, toTop ? MAX_VALUE : 0, moveStackMode, animate, deferResume, @@ -738,7 +1171,7 @@ class Task extends WindowContainer<WindowContainer> { * Convenience method to reparent a task to the top or bottom position of the stack, with * an option to skip scheduling the picture-in-picture mode change. */ - boolean reparent(ActivityStack preferredStack, boolean toTop, + boolean reparent(Task preferredStack, boolean toTop, @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange, String reason) { return reparent(preferredStack, toTop ? MAX_VALUE : 0, moveStackMode, animate, @@ -746,7 +1179,7 @@ class Task extends WindowContainer<WindowContainer> { } /** Convenience method to reparent a task to a specific position of the stack. */ - boolean reparent(ActivityStack preferredStack, int position, + boolean reparent(Task preferredStack, int position, @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, String reason) { return reparent(preferredStack, position, moveStackMode, animate, deferResume, @@ -772,14 +1205,14 @@ class Task extends WindowContainer<WindowContainer> { */ // TODO: Inspect all call sites and change to just changing windowing mode of the stack vs. // re-parenting the task. Can only be done when we are no longer using static stack Ids. - boolean reparent(ActivityStack preferredStack, int position, + boolean reparent(Task preferredStack, int position, @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange, String reason) { final ActivityStackSupervisor supervisor = mStackSupervisor; final RootWindowContainer root = mRootWindowContainer; final WindowManagerService windowManager = mAtmService.mWindowManager; - final ActivityStack sourceStack = getStack(); - final ActivityStack toStack = supervisor.getReparentTargetStack(this, preferredStack, + final Task sourceStack = getRootTask(); + final Task toStack = supervisor.getReparentTargetStack(this, preferredStack, position == MAX_VALUE); if (toStack == sourceStack) { return false; @@ -1172,6 +1605,12 @@ class Task extends WindowContainer<WindowContainer> { } mRootWindowContainer.updateUIDsPresentOnDisplay(); + + // Resume next focusable stack after reparenting to another display if we aren't removing + // the prevous display. + if (oldDisplay != null && oldDisplay.isRemoving()) { + postReparent(); + } } void cleanUpActivityReferences(ActivityRecord r) { @@ -1370,7 +1809,7 @@ class Task extends WindowContainer<WindowContainer> { // A rootable task that is now being added to be the child of an organized task. Making // sure the stack references is keep updated. if (mTaskOrganizer != null && mCreatedByOrganizer && child.asTask() != null) { - getDisplayArea().addStackReferenceIfNeeded((ActivityStack) child); + getDisplayArea().addStackReferenceIfNeeded((Task) child); } // Make sure the list of display UID whitelists is updated @@ -1420,7 +1859,7 @@ class Task extends WindowContainer<WindowContainer> { // A rootable child task that is now being removed from an organized task. Making sure // the stack references is keep updated. if (mCreatedByOrganizer && r.asTask() != null) { - getDisplayArea().removeStackReferenceIfNeeded((ActivityStack) r); + getDisplayArea().removeStackReferenceIfNeeded((Task) r); } if (!mChildren.contains(r)) { Slog.e(TAG, "removeChild: r=" + r + " not found in t=" + this); @@ -1460,7 +1899,7 @@ class Task extends WindowContainer<WindowContainer> { // Remove entire task if it doesn't have any activity left and it isn't marked for reuse // or created by task organizer. if (!isRootTask()) { - getStack().removeChild(this, reason); + getRootTask().removeChild(this, reason); } EventLogTags.writeWmTaskRemoved(mTaskId, "removeChild: last r=" + r + " in t=" + this); @@ -1502,7 +1941,7 @@ class Task extends WindowContainer<WindowContainer> { /** Completely remove all activities associated with an existing task. */ void performClearTask(String reason) { // Broken down into to cases to avoid object create due to capturing mStack. - if (getStack() == null) { + if (getRootTask() == null) { forAllActivities((r) -> { if (r.finishing) return; // Task was restored from persistent storage. @@ -1881,8 +2320,7 @@ class Task extends WindowContainer<WindowContainer> { } } - @Override - public void onConfigurationChanged(Configuration newParentConfig) { + private void onConfigurationChangedInner(Configuration newParentConfig) { // Check if the new configuration supports persistent bounds (eg. is Freeform) and if so // restore the last recorded non-fullscreen bounds. final boolean prevPersistTaskBounds = getWindowConfiguration().persistTaskBounds(); @@ -1910,7 +2348,7 @@ class Task extends WindowContainer<WindowContainer> { final boolean pipChanging = wasInPictureInPicture != inPinnedWindowingMode(); if (pipChanging) { - mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, getStack()); + mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, getRootTask()); } else if (wasInMultiWindowMode != inMultiWindowMode()) { mStackSupervisor.scheduleUpdateMultiWindowMode(this); } @@ -1959,6 +2397,78 @@ class Task extends WindowContainer<WindowContainer> { } } + @Override + public void onConfigurationChanged(Configuration newParentConfig) { + // Calling Task#onConfigurationChanged() for leaf task since the ops in this method are + // particularly for ActivityStack, like preventing bounds changes when inheriting certain + // windowing mode. + if (!isRootTask()) { + onConfigurationChangedInner(newParentConfig); + return; + } + + final int prevWindowingMode = getWindowingMode(); + final boolean prevIsAlwaysOnTop = isAlwaysOnTop(); + final int prevRotation = getWindowConfiguration().getRotation(); + final Rect newBounds = mTmpRect; + // Initialize the new bounds by previous bounds as the input and output for calculating + // override bounds in pinned (pip) or split-screen mode. + getBounds(newBounds); + + onConfigurationChangedInner(newParentConfig); + + final TaskDisplayArea taskDisplayArea = getDisplayArea(); + if (taskDisplayArea == null) { + return; + } + + if (prevWindowingMode != getWindowingMode()) { + taskDisplayArea.onStackWindowingModeChanged(this); + } + + final DisplayContent display = getDisplay(); + if (display == null ) { + return; + } + + final boolean windowingModeChanged = prevWindowingMode != getWindowingMode(); + final int overrideWindowingMode = getRequestedOverrideWindowingMode(); + // Update bounds if applicable + boolean hasNewOverrideBounds = false; + // Use override windowing mode to prevent extra bounds changes if inheriting the mode. + if ((overrideWindowingMode != WINDOWING_MODE_PINNED) + && !getRequestedOverrideBounds().isEmpty()) { + // If the parent (display) has rotated, rotate our bounds to best-fit where their + // bounds were on the pre-rotated display. + final int newRotation = getWindowConfiguration().getRotation(); + final boolean rotationChanged = prevRotation != newRotation; + if (rotationChanged) { + display.mDisplayContent.rotateBounds( + newParentConfig.windowConfiguration.getBounds(), prevRotation, newRotation, + newBounds); + hasNewOverrideBounds = true; + } + } + + if (windowingModeChanged) { + taskDisplayArea.onStackWindowingModeChanged(this); + } + if (hasNewOverrideBounds) { + if (inSplitScreenWindowingMode()) { + setBounds(newBounds); + } else if (overrideWindowingMode != WINDOWING_MODE_PINNED) { + // For pinned stack, resize is now part of the {@link WindowContainerTransaction} + resize(new Rect(newBounds), PRESERVE_WINDOWS, true /* deferResume */); + } + } + if (prevIsAlwaysOnTop != isAlwaysOnTop()) { + // Since always on top is only on when the stack is freeform or pinned, the state + // can be toggled when the windowing mode changes. We must make sure the stack is + // placed properly when always on top state changes. + taskDisplayArea.positionStackAtTop(this, false /* includingParents */); + } + } + /** * Initializes a change transition. See {@link SurfaceFreezer} for more information. */ @@ -2191,10 +2701,11 @@ class Task extends WindowContainer<WindowContainer> { DisplayInfo displayInfo) { outNonDecorBounds.set(bounds); outStableBounds.set(bounds); - if (getStack() == null || getStack().getDisplay() == null) { + final Task rootTask = getRootTask(); + if (rootTask == null || rootTask.getDisplay() == null) { return; } - DisplayPolicy policy = getStack().getDisplay().mDisplayContent.getDisplayPolicy(); + DisplayPolicy policy = rootTask.getDisplay().mDisplayContent.getDisplayPolicy(); if (policy == null) { return; } @@ -2533,8 +3044,8 @@ class Task extends WindowContainer<WindowContainer> { /** Updates the task's bounds and override configuration to match what is expected for the * input stack. */ - void updateOverrideConfigurationForStack(ActivityStack inStack) { - final ActivityStack stack = getStack(); + void updateOverrideConfigurationForStack(Task inStack) { + final Task stack = getRootTask(); if (stack != null && stack == inStack) { return; @@ -2547,7 +3058,7 @@ class Task extends WindowContainer<WindowContainer> { /** Returns the bounds that should be used to launch this task. */ Rect getLaunchBounds() { - final ActivityStack stack = getStack(); + final Task stack = getRootTask(); if (stack == null) { return null; } @@ -2582,7 +3093,7 @@ class Task extends WindowContainer<WindowContainer> { @Override DisplayContent getDisplayContent() { // TODO: Why aren't we just using our own display content vs. parent's??? - final ActivityStack stack = getStack(); + final Task stack = getRootTask(); return stack != null && stack != this ? stack.getDisplayContent() : super.getDisplayContent(); } @@ -2592,11 +3103,6 @@ class Task extends WindowContainer<WindowContainer> { return dc != null ? dc.mDisplayId : INVALID_DISPLAY; } - // TODO: Migrate callers to getRootTask() - ActivityStack getStack() { - return (ActivityStack) getRootTask(); - } - /** @return Id of root task. */ int getRootTaskId() { return getRootTask().mTaskId; @@ -2637,7 +3143,7 @@ class Task extends WindowContainer<WindowContainer> { * Find next proper focusable stack and make it focused. * @return The stack that now got the focus, {@code null} if none found. */ - ActivityStack adjustFocusToNextFocusableTask(String reason) { + Task adjustFocusToNextFocusableTask(String reason) { return adjustFocusToNextFocusableTask(reason, false /* allowFocusSelf */, true /* moveDisplayToTop */); } @@ -2650,7 +3156,7 @@ class Task extends WindowContainer<WindowContainer> { } final Task focusableTask = parent.getTask((task) -> (allowFocusSelf || task != this) - && ((ActivityStack) task).isFocusableAndVisible()); + && ((Task) task).isFocusableAndVisible()); if (focusableTask == null && parent.asTask() != null) { return parent.asTask().getNextFocusableTask(allowFocusSelf); } else { @@ -2665,18 +3171,17 @@ class Task extends WindowContainer<WindowContainer> { * @param moveDisplayToTop Whether to move display to top while making the task focused. * @return The root task that now got the focus, {@code null} if none found. */ - ActivityStack adjustFocusToNextFocusableTask(String reason, boolean allowFocusSelf, + Task adjustFocusToNextFocusableTask(String reason, boolean allowFocusSelf, boolean moveDisplayToTop) { - ActivityStack focusableTask = (ActivityStack) getNextFocusableTask(allowFocusSelf); + Task focusableTask = getNextFocusableTask(allowFocusSelf); if (focusableTask == null) { - focusableTask = mRootWindowContainer.getNextFocusableStack((ActivityStack) this, - !allowFocusSelf); + focusableTask = mRootWindowContainer.getNextFocusableStack(this, !allowFocusSelf); } if (focusableTask == null) { return null; } - final ActivityStack rootTask = (ActivityStack) focusableTask.getRootTask(); + final Task rootTask = focusableTask.getRootTask(); if (!moveDisplayToTop) { // There may be multiple task layers above this task, so when relocating the task to the // top, we should move this task and each of its parent task that below display area to @@ -2807,7 +3312,7 @@ class Task extends WindowContainer<WindowContainer> { // No reason to defer removal of a Task that doesn't have any child. return false; } - return hasWindowsAlive() && getStack().isAnimating(TRANSITION | CHILDREN); + return hasWindowsAlive() && getRootTask().isAnimating(TRANSITION | CHILDREN); } @Override @@ -2826,9 +3331,9 @@ class Task extends WindowContainer<WindowContainer> { } // TODO: Consolidate this with Task.reparent() - void reparent(ActivityStack stack, int position, boolean moveParents, String reason) { + void reparent(Task stack, int position, boolean moveParents, String reason) { if (DEBUG_STACK) Slog.i(TAG, "reParentTask: removing taskId=" + mTaskId - + " from stack=" + getStack()); + + " from stack=" + getRootTask()); EventLogTags.writeWmTaskRemoved(mTaskId, "reParentTask:" + reason); reparent(stack, position); @@ -2855,9 +3360,13 @@ class Task extends WindowContainer<WindowContainer> { /** Set the task bounds. Passing in null sets the bounds to fullscreen. */ @Override public int setBounds(Rect bounds) { + if (isRootTask()) { + return setBounds(getRequestedOverrideBounds(), bounds); + } + int rotation = Surface.ROTATION_0; - final DisplayContent displayContent = getStack() != null - ? getStack().getDisplayContent() : null; + final DisplayContent displayContent = getRootTask() != null + ? getRootTask().getDisplayContent() : null; if (displayContent != null) { rotation = displayContent.getDisplayInfo().rotation; } @@ -2869,6 +3378,17 @@ class Task extends WindowContainer<WindowContainer> { } @Override + public boolean isCompatible(int windowingMode, int activityType) { + // TODO: Should we just move this to ConfigurationContainer? + if (activityType == ACTIVITY_TYPE_UNDEFINED) { + // Undefined activity types end up in a standard stack once the stack is created on a + // display, so they should be considered compatible. + activityType = ACTIVITY_TYPE_STANDARD; + } + return super.isCompatible(windowingMode, activityType); + } + + @Override public boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, ConfigurationContainer requestingContainer) { if (super.onDescendantOrientationChanged(freezeDisplayToken, requestingContainer)) { @@ -2902,6 +3422,9 @@ class Task extends WindowContainer<WindowContainer> { mWmService.mAtmService.getTaskChangeNotificationController().notifyTaskDisplayChanged( mTaskId, displayId); } + if (isRootTask()) { + updateSurfaceBounds(); + } } boolean isResizeable(boolean checkSupportsPip) { @@ -2992,7 +3515,13 @@ class Task extends WindowContainer<WindowContainer> { /** Bounds of the task to be used for dimming, as well as touch related tests. */ void getDimBounds(Rect out) { - final DisplayContent displayContent = getStack().getDisplayContent(); + if (isRootTask()) { + getBounds(out); + return; + } + + final Task rootTask = getRootTask(); + final DisplayContent displayContent = rootTask.getDisplayContent(); // It doesn't matter if we in particular are part of the resize, since we couldn't have // a DimLayer anyway if we weren't visible. final boolean dockedResizing = displayContent != null @@ -3016,9 +3545,9 @@ class Task extends WindowContainer<WindowContainer> { // stack bounds and so we don't even want to use them. Even if the app should not be // resized the Dim should keep up with the divider. if (dockedResizing) { - getStack().getBounds(out); + rootTask.getBounds(out); } else { - getStack().getBounds(mTmpRect); + rootTask.getBounds(mTmpRect); mTmpRect.intersect(getBounds()); out.set(mTmpRect); } @@ -3031,7 +3560,8 @@ class Task extends WindowContainer<WindowContainer> { void setDragResizing(boolean dragResizing, int dragResizeMode) { if (mDragResizing != dragResizing) { // No need to check if the mode is allowed if it's leaving dragResize - if (dragResizing && !DragResizeMode.isModeAllowedForStack(getStack(), dragResizeMode)) { + if (dragResizing + && !DragResizeMode.isModeAllowedForStack(getRootTask(), dragResizeMode)) { throw new IllegalArgumentException("Drag resize mode not allow for stack stackId=" + getRootTaskId() + " dragResizeMode=" + dragResizeMode); } @@ -3221,9 +3751,9 @@ class Task extends WindowContainer<WindowContainer> { @Override Rect getAnimationBounds(int appStackClipMode) { // TODO(b/131661052): we should remove appStackClipMode with hierarchical animations. - if (appStackClipMode == STACK_CLIP_BEFORE_ANIM && getStack() != null) { + if (appStackClipMode == STACK_CLIP_BEFORE_ANIM && getRootTask() != null) { // Using the stack bounds here effectively applies the clipping before animation. - return getStack().getBounds(); + return getRootTask().getBounds(); } return super.getAnimationBounds(appStackClipMode); } @@ -3573,6 +4103,20 @@ class Task extends WindowContainer<WindowContainer> { child.dump(pw, doublePrefix, dumpAll); } } + + if (!mExitingActivities.isEmpty()) { + pw.println(); + pw.println(prefix + "Exiting application tokens:"); + for (int i = mExitingActivities.size() - 1; i >= 0; i--) { + WindowToken token = mExitingActivities.get(i); + pw.print(doublePrefix + "Exiting App #" + i); + pw.print(' '); pw.print(token); + pw.println(':'); + token.dump(pw, doublePrefix, dumpAll); + } + pw.println(); + } + mAnimatingActivityRegistry.dump(pw, "AnimatingApps:", prefix); } @@ -3668,7 +4212,7 @@ class Task extends WindowContainer<WindowContainer> { * * @param starting The currently starting activity or null if there is none. */ - @ActivityStack.StackVisibility + @Task.StackVisibility int getVisibility(ActivityRecord starting) { if (!isAttached() || isForceHidden()) { return STACK_VISIBILITY_INVISIBLE; @@ -4289,7 +4833,7 @@ class Task extends WindowContainer<WindowContainer> { } } - final Task task = new ActivityStack(stackSupervisor.mService, taskId, intent, + final Task task = new Task(stackSupervisor.mService, taskId, intent, affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset, autoRemoveRecents, askedCompatMode, userId, effectiveUid, lastDescription, lastTimeOnTop, neverRelinquishIdentity, taskDescription, taskAffiliation, @@ -4604,4 +5148,2656 @@ class Task extends WindowContainer<WindowContainer> { return TASK; } + @Override + public void setWindowingMode(int windowingMode) { + // Reset the cached result of toString() + stringName = null; + + // Calling Task#setWindowingMode() for leaf task since this is the a specialization of + // {@link #setWindowingMode(int)} for ActivityStack. + if (!isRootTask()) { + super.setWindowingMode(windowingMode); + return; + } + + setWindowingMode(windowingMode, false /* creating */); + } + + /** + * Specialization of {@link #setWindowingMode(int)} for this subclass. + * + * @param preferredWindowingMode the preferred windowing mode. This may not be honored depending + * on the state of things. For example, WINDOWING_MODE_UNDEFINED will resolve to the + * previous non-transient mode if this stack is currently in a transient mode. + * @param creating {@code true} if this is being run during ActivityStack construction. + */ + void setWindowingMode(int preferredWindowingMode, boolean creating) { + mWmService.inSurfaceTransaction(() -> setWindowingModeInSurfaceTransaction( + preferredWindowingMode, creating)); + } + + private void setWindowingModeInSurfaceTransaction(int preferredWindowingMode, + boolean creating) { + final TaskDisplayArea taskDisplayArea = getDisplayArea(); + if (taskDisplayArea == null) { + Slog.d(TAG, "taskDisplayArea is null, bail early"); + return; + } + final int currentMode = getWindowingMode(); + final int currentOverrideMode = getRequestedOverrideWindowingMode(); + final Task topTask = getTopMostTask(); + int windowingMode = preferredWindowingMode; + + // Need to make sure windowing mode is supported. If we in the process of creating the stack + // no need to resolve the windowing mode again as it is already resolved to the right mode. + if (!creating) { + if (!taskDisplayArea.isValidWindowingMode(windowingMode, null /* ActivityRecord */, + topTask, getActivityType())) { + windowingMode = WINDOWING_MODE_UNDEFINED; + } + } + + final boolean alreadyInSplitScreenMode = taskDisplayArea.isSplitScreenModeActivated(); + + if (creating && alreadyInSplitScreenMode && windowingMode == WINDOWING_MODE_FULLSCREEN + && isActivityTypeStandardOrUndefined()) { + // If the stack is being created explicitly in fullscreen mode, dismiss split-screen + // and display a warning toast about it. + mAtmService.getTaskChangeNotificationController() + .notifyActivityDismissingDockedStack(); + taskDisplayArea.onSplitScreenModeDismissed(this); + } + + if (currentMode == windowingMode) { + // You are already in the window mode, so we can skip most of the work below. However, + // it's possible that we have inherited the current windowing mode from a parent. So, + // fulfill this method's contract by setting the override mode directly. + getRequestedOverrideConfiguration().windowConfiguration.setWindowingMode(windowingMode); + return; + } + + final ActivityRecord topActivity = getTopNonFinishingActivity(); + + // For now, assume that the Stack's windowing mode is what will actually be used + // by it's activities. In the future, there may be situations where this doesn't + // happen; so at that point, this message will need to handle that. + int likelyResolvedMode = windowingMode; + if (windowingMode == WINDOWING_MODE_UNDEFINED) { + final ConfigurationContainer parent = getParent(); + likelyResolvedMode = parent != null ? parent.getWindowingMode() + : WINDOWING_MODE_FULLSCREEN; + } + if (currentMode == WINDOWING_MODE_PINNED) { + mAtmService.getTaskChangeNotificationController().notifyActivityUnpinned(); + } + if (likelyResolvedMode == WINDOWING_MODE_PINNED + && taskDisplayArea.getRootPinnedTask() != null) { + // Can only have 1 pip at a time, so replace an existing pip + taskDisplayArea.getRootPinnedTask().dismissPip(); + } + if (likelyResolvedMode != WINDOWING_MODE_FULLSCREEN + && topActivity != null && !topActivity.noDisplay + && topActivity.isNonResizableOrForcedResizable(likelyResolvedMode)) { + // Inform the user that they are starting an app that may not work correctly in + // multi-window mode. + final String packageName = topActivity.info.applicationInfo.packageName; + mAtmService.getTaskChangeNotificationController().notifyActivityForcedResizable( + topTask.mTaskId, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN, packageName); + } + + mAtmService.deferWindowLayout(); + try { + if (topActivity != null) { + mStackSupervisor.mNoAnimActivities.add(topActivity); + } + super.setWindowingMode(windowingMode); + // setWindowingMode triggers an onConfigurationChanged cascade which can result in a + // different resolved windowing mode (usually when preferredWindowingMode is UNDEFINED). + windowingMode = getWindowingMode(); + + if (creating) { + // Nothing else to do if we don't have a window container yet. E.g. call from ctor. + return; + } + + if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && alreadyInSplitScreenMode) { + // We already have a split-screen stack in this display, so just move the tasks over. + // TODO: Figure-out how to do all the stuff in + // AMS.setTaskWindowingModeSplitScreenPrimary + throw new IllegalArgumentException("Setting primary split-screen windowing mode" + + " while there is already one isn't currently supported"); + //return; + } + } finally { + mAtmService.continueWindowLayout(); + } + + mRootWindowContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS); + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + + /** Resume next focusable stack after reparenting to another display. */ + void postReparent() { + adjustFocusToNextFocusableTask("reparent", true /* allowFocusSelf */, + true /* moveDisplayToTop */); + mRootWindowContainer.resumeFocusedStacksTopActivities(); + // Update visibility of activities before notifying WM. This way it won't try to resize + // windows that are no longer visible. + mRootWindowContainer.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, + !PRESERVE_WINDOWS); + } + + DisplayContent getDisplay() { + return getDisplayContent(); + } + + /** @return true if the stack can only contain one task */ + boolean isSingleTaskInstance() { + final DisplayContent display = getDisplay(); + return display != null && display.isSingleTaskInstance(); + } + + final boolean isHomeOrRecentsStack() { + return isActivityTypeHome() || isActivityTypeRecents(); + } + + final boolean isOnHomeDisplay() { + return getDisplayId() == DEFAULT_DISPLAY; + } + + void moveToFront(String reason) { + moveToFront(reason, null); + } + + /** + * @param reason The reason for moving the stack to the front. + * @param task If non-null, the task will be moved to the top of the stack. + */ + void moveToFront(String reason, Task task) { + if (!isAttached()) { + return; + } + + final TaskDisplayArea taskDisplayArea = getDisplayArea(); + + if (inSplitScreenSecondaryWindowingMode()) { + // If the stack is in split-screen secondary mode, we need to make sure we move the + // primary split-screen stack forward in the case it is currently behind a fullscreen + // stack so both halves of the split-screen appear on-top and the fullscreen stack isn't + // cutting between them. + // TODO(b/70677280): This is a workaround until we can fix as part of b/70677280. + final Task topFullScreenStack = + taskDisplayArea.getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); + if (topFullScreenStack != null) { + final Task primarySplitScreenStack = + taskDisplayArea.getRootSplitScreenPrimaryTask(); + if (primarySplitScreenStack != null + && taskDisplayArea.getIndexOf(topFullScreenStack) + > taskDisplayArea.getIndexOf(primarySplitScreenStack)) { + primarySplitScreenStack.moveToFront(reason + " splitScreenToTop"); + } + } + } + + if (!isActivityTypeHome() && returnsToHomeStack()) { + // Make sure the home stack is behind this stack since that is where we should return to + // when this stack is no longer visible. + taskDisplayArea.moveHomeStackToFront(reason + " returnToHome"); + } + + if (isRootTask()) { + taskDisplayArea.positionStackAtTop(this, false /* includingParents */, reason); + } + if (task == null) { + task = this; + } + task.getParent().positionChildAt(POSITION_TOP, task, true /* includingParents */); + } + + /** + * This moves 'task' to the back of this task and also recursively moves this task to the back + * of its parents (if applicable). + * + * @param reason The reason for moving the stack to the back. + * @param task If non-null, the task will be moved to the bottom of the stack. + **/ + void moveToBack(String reason, Task task) { + if (!isAttached()) { + return; + } + final TaskDisplayArea displayArea = getDisplayArea(); + if (!mCreatedByOrganizer) { + // If this is just a normal task, so move to back of parent and then move 'task' to + // back of this. + final WindowContainer parent = getParent(); + final Task parentTask = parent != null ? parent.asTask() : null; + if (parentTask != null) { + parentTask.moveToBack(reason, this); + } else { + displayArea.positionStackAtBottom(this, reason); + } + if (task != null && task != this) { + positionChildAtBottom(task); + } + return; + } + if (task == null || task == this) { + return; + } + // This is a created-by-organizer task. In this case, let the organizer deal with this + // task's ordering. However, we still need to move 'task' to back. The intention is that + // this ends up behind the home-task so that it is made invisible; so, if the home task + // is not a child of this, reparent 'task' to the back of the home task's actual parent. + displayArea.positionTaskBehindHome(task); + } + + // TODO: Should each user have there own stacks? + @Override + void switchUser(int userId) { + if (mCurrentUser == userId) { + return; + } + mCurrentUser = userId; + + super.switchUser(userId); + forAllLeafTasks((t) -> { + if (t.showToCurrentUser() && t != this) { + mChildren.remove(t); + mChildren.add(t); + } + }, true /* traverseTopToBottom */); + } + + void minimalResumeActivityLocked(ActivityRecord r) { + if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" + + " callers=" + Debug.getCallers(5)); + r.setState(RESUMED, "minimalResumeActivityLocked"); + r.completeResumeLocked(); + } + + private void clearLaunchTime(ActivityRecord r) { + // Make sure that there is no activity waiting for this to launch. + if (!mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { + mStackSupervisor.removeIdleTimeoutForActivity(r); + mStackSupervisor.scheduleIdleTimeout(r); + } + } + + void awakeFromSleepingLocked() { + // Ensure activities are no longer sleeping. + forAllActivities((Consumer<ActivityRecord>) (r) -> r.setSleeping(false)); + if (mPausingActivity != null) { + Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); + mPausingActivity.activityPaused(true); + } + } + + void checkReadyForSleep() { + if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) { + mStackSupervisor.checkReadyForSleepLocked(true /* allowDelay */); + } + } + + /** + * Tries to put the activities in the stack to sleep. + * + * If the stack is not in a state where its activities can be put to sleep, this function will + * start any necessary actions to move the stack into such a state. It is expected that this + * function get called again when those actions complete. + * + * @param shuttingDown true when the called because the device is shutting down. + * @return true if the stack finished going to sleep, false if the stack only started the + * process of going to sleep (checkReadyForSleep will be called when that process finishes). + */ + boolean goToSleepIfPossible(boolean shuttingDown) { + boolean shouldSleep = true; + + if (mResumedActivity != null) { + // Still have something resumed; can't sleep until it is paused. + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); + if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, + "Sleep => pause with userLeaving=false"); + + startPausingLocked(false /* userLeaving */, true /* uiSleeping */, null /* resuming */); + shouldSleep = false ; + } else if (mPausingActivity != null) { + // Still waiting for something to pause; can't sleep yet. + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still waiting to pause " + mPausingActivity); + shouldSleep = false; + } + + if (!shuttingDown) { + if (containsActivityFromStack(mStackSupervisor.mStoppingActivities)) { + // Still need to tell some activities to stop; can't sleep yet. + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " + + mStackSupervisor.mStoppingActivities.size() + " activities"); + + mStackSupervisor.scheduleIdle(); + shouldSleep = false; + } + } + + if (shouldSleep) { + goToSleep(); + } + + return shouldSleep; + } + + void goToSleep() { + // Make sure all visible activities are now sleeping. This will update the activity's + // visibility and onStop() will be called. + forAllActivities((r) -> { + if (r.isState(STARTED, RESUMED, PAUSING, PAUSED, STOPPING, STOPPED)) { + r.setSleeping(true); + } + }); + + // Ensure visibility after updating sleep states without updating configuration, + // as activities are about to be sent to sleep. + ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, + !PRESERVE_WINDOWS); + } + + private boolean containsActivityFromStack(List<ActivityRecord> rs) { + for (ActivityRecord r : rs) { + if (r.getRootTask() == this) { + return true; + } + } + return false; + } + + /** + * Start pausing the currently resumed activity. It is an error to call this if there + * is already an activity being paused or there is no resumed activity. + * + * @param userLeaving True if this should result in an onUserLeaving to the current activity. + * @param uiSleeping True if this is happening with the user interface going to sleep (the + * screen turning off). + * @param resuming The activity we are currently trying to resume or null if this is not being + * called as part of resuming the top activity, so we shouldn't try to instigate + * a resume here if not null. + * @return Returns true if an activity now is in the PAUSING state, and we are waiting for + * it to tell us when it is done. + */ + final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, + ActivityRecord resuming) { + if (mPausingActivity != null) { + Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity + + " state=" + mPausingActivity.getState()); + if (!shouldSleepActivities()) { + // 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, resuming); + } + } + ActivityRecord prev = mResumedActivity; + + if (prev == null) { + if (resuming == null) { + Slog.wtf(TAG, "Trying to pause when nothing is resumed"); + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + return false; + } + + if (prev == resuming) { + Slog.wtf(TAG, "Trying to pause activity that is in process of being resumed"); + return false; + } + + if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); + else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); + mPausingActivity = prev; + mLastPausedActivity = prev; + mLastNoHistoryActivity = prev.isNoHistory() ? prev : null; + prev.setState(PAUSING, "startPausingLocked"); + prev.getTask().touchActiveTime(); + clearLaunchTime(prev); + + mAtmService.updateCpuStats(); + + boolean pauseImmediately = false; + if (resuming != null && (resuming.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0) { + // If the flag RESUME_WHILE_PAUSING is set, then continue to schedule the previous + // activity to be paused, while at the same time resuming the new resume activity + // only if the previous activity can't go into Pip since we want to give Pip + // activities a chance to enter Pip before resuming the next activity. + final boolean lastResumedCanPip = prev != null && prev.checkEnterPictureInPictureState( + "shouldResumeWhilePausing", userLeaving); + if (!lastResumedCanPip) { + pauseImmediately = true; + } + } + + if (prev.attachedToProcess()) { + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); + try { + EventLogTags.writeWmPauseActivity(prev.mUserId, System.identityHashCode(prev), + prev.shortComponentName, "userLeaving=" + userLeaving); + + mAtmService.getLifecycleManager().scheduleTransaction(prev.app.getThread(), + prev.appToken, PauseActivityItem.obtain(prev.finishing, userLeaving, + prev.configChangeFlags, pauseImmediately)); + } catch (Exception e) { + // Ignore exception, if process died other code will cleanup. + Slog.w(TAG, "Exception thrown during pause", e); + mPausingActivity = null; + mLastPausedActivity = null; + mLastNoHistoryActivity = null; + } + } else { + mPausingActivity = null; + mLastPausedActivity = null; + mLastNoHistoryActivity = null; + } + + // If we are not going to sleep, we want to ensure the device is + // awake until the next activity is started. + if (!uiSleeping && !mAtmService.isSleepingOrShuttingDownLocked()) { + mStackSupervisor.acquireLaunchWakelock(); + } + + if (mPausingActivity != null) { + // Have the window manager pause its key dispatching until the new + // activity has started. If we're pausing the activity just because + // the screen is being turned off and the UI is sleeping, don't interrupt + // key dispatch; the same activity will pick it up again on wakeup. + if (!uiSleeping) { + prev.pauseKeyDispatchingLocked(); + } else if (DEBUG_PAUSE) { + Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); + } + + if (pauseImmediately) { + // If the caller said they don't want to wait for the pause, then complete + // the pause now. + completePauseLocked(false, resuming); + return false; + + } else { + prev.schedulePauseTimeout(); + return true; + } + + } else { + // This activity failed to schedule the + // pause, so just treat it as being paused now. + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); + if (resuming == null) { + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + return false; + } + } + + @VisibleForTesting + void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { + ActivityRecord prev = mPausingActivity; + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); + + if (prev != null) { + prev.setWillCloseOrEnterPip(false); + final boolean wasStopping = prev.isState(STOPPING); + prev.setState(PAUSED, "completePausedLocked"); + if (prev.finishing) { + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); + prev = prev.completeFinishing("completePausedLocked"); + } else if (prev.hasProcess()) { + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev + + " wasStopping=" + wasStopping + + " visibleRequested=" + prev.mVisibleRequested); + if (prev.deferRelaunchUntilPaused) { + // Complete the deferred relaunch that was waiting for pause to complete. + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); + prev.relaunchActivityLocked(prev.preserveWindowOnDeferredRelaunch); + } else if (wasStopping) { + // We are also stopping, the stop request must have gone soon after the pause. + // We can't clobber it, because the stop confirmation will not be handled. + // We don't need to schedule another stop, we only need to let it happen. + prev.setState(STOPPING, "completePausedLocked"); + } else if (!prev.mVisibleRequested || shouldSleepOrShutDownActivities()) { + // Clear out any deferred client hide we might currently have. + prev.setDeferHidingClient(false); + // If we were visible then resumeTopActivities will release resources before + // stopping. + prev.addToStopping(true /* scheduleIdle */, false /* idleDelayed */, + "completePauseLocked"); + } + } else { + if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "App died during pause, not stopping: " + prev); + prev = null; + } + // It is possible the activity was freezing the screen before it was paused. + // In that case go ahead and remove the freeze this activity has on the screen + // since it is no longer visible. + if (prev != null) { + prev.stopFreezingScreenLocked(true /*force*/); + } + mPausingActivity = null; + } + + if (resumeNext) { + final Task topStack = mRootWindowContainer.getTopDisplayFocusedStack(); + if (topStack != null && !topStack.shouldSleepOrShutDownActivities()) { + mRootWindowContainer.resumeFocusedStacksTopActivities(topStack, prev, null); + } else { + checkReadyForSleep(); + final ActivityRecord top = topStack != null ? topStack.topRunningActivity() : null; + if (top == null || (prev != null && top != prev)) { + // If there are no more activities available to run, do resume anyway to start + // something. Also if the top activity on the stack is not the just paused + // activity, we need to go ahead and resume it to ensure we complete an + // in-flight app switch. + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + } + } + + if (prev != null) { + prev.resumeKeyDispatchingLocked(); + + if (prev.hasProcess() && prev.cpuTimeAtResume > 0) { + final long diff = prev.app.getCpuTime() - prev.cpuTimeAtResume; + if (diff > 0) { + final Runnable r = PooledLambda.obtainRunnable( + ActivityManagerInternal::updateForegroundTimeIfOnBattery, + mAtmService.mAmInternal, prev.info.packageName, + prev.info.applicationInfo.uid, + diff); + mAtmService.mH.post(r); + } + } + prev.cpuTimeAtResume = 0; // reset it + } + + mRootWindowContainer.ensureActivitiesVisible(resuming, 0, !PRESERVE_WINDOWS); + + // Notify when the task stack has changed, but only if visibilities changed (not just + // focus). Also if there is an active pinned stack - we always want to notify it about + // task stack changes, because its positioning may depend on it. + if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause + || (getDisplayArea() != null && getDisplayArea().hasPinnedTask())) { + mAtmService.getTaskChangeNotificationController().notifyTaskStackChanged(); + mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; + } + } + + boolean isTopStackInDisplayArea() { + final TaskDisplayArea taskDisplayArea = getDisplayArea(); + return taskDisplayArea != null && taskDisplayArea.isTopStack(this); + } + + /** + * @return {@code true} if this is the focused stack on its current display, {@code false} + * otherwise. + */ + boolean isFocusedStackOnDisplay() { + final DisplayContent display = getDisplay(); + return display != null && this == display.getFocusedStack(); + } + + /** + * Make sure that all activities that need to be visible in the stack (that is, they + * currently can be seen by the user) actually are and update their configuration. + * @param starting The top most activity in the task. + * The activity is either starting or resuming. + * Caller should ensure starting activity is visible. + * @param preserveWindows Flag indicating whether windows should be preserved when updating + * configuration in {@link mEnsureActivitiesVisibleHelper}. + * @param configChanges Parts of the configuration that changed for this activity for evaluating + * if the screen should be frozen as part of + * {@link mEnsureActivitiesVisibleHelper}. + * + */ + void ensureActivitiesVisible(@Nullable ActivityRecord starting, int configChanges, + boolean preserveWindows) { + ensureActivitiesVisible(starting, configChanges, preserveWindows, true /* notifyClients */); + } + + /** + * Ensure visibility with an option to also update the configuration of visible activities. + * @see #ensureActivitiesVisible(ActivityRecord, int, boolean) + * @see RootWindowContainer#ensureActivitiesVisible(ActivityRecord, int, boolean) + * @param starting The top most activity in the task. + * The activity is either starting or resuming. + * Caller should ensure starting activity is visible. + * @param notifyClients Flag indicating whether the visibility updates should be sent to the + * clients in {@link mEnsureActivitiesVisibleHelper}. + * @param preserveWindows Flag indicating whether windows should be preserved when updating + * configuration in {@link mEnsureActivitiesVisibleHelper}. + * @param configChanges Parts of the configuration that changed for this activity for evaluating + * if the screen should be frozen as part of + * {@link mEnsureActivitiesVisibleHelper}. + */ + // TODO: Should be re-worked based on the fact that each task as a stack in most cases. + void ensureActivitiesVisible(@Nullable ActivityRecord starting, int configChanges, + boolean preserveWindows, boolean notifyClients) { + mTopActivityOccludesKeyguard = false; + mTopDismissingKeyguardActivity = null; + mStackSupervisor.beginActivityVisibilityUpdate(); + try { + mEnsureActivitiesVisibleHelper.process( + starting, configChanges, preserveWindows, notifyClients); + + if (mTranslucentActivityWaiting != null && + mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { + // Nothing is getting drawn or everything was already visible, don't wait for timeout. + notifyActivityDrawnLocked(null); + } + } finally { + mStackSupervisor.endActivityVisibilityUpdate(); + } + } + + /** + * @return true if the top visible activity wants to occlude the Keyguard, false otherwise + */ + boolean topActivityOccludesKeyguard() { + return mTopActivityOccludesKeyguard; + } + + /** + * Returns true if this stack should be resized to match the bounds specified by + * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack. + */ + boolean shouldResizeStackWithLaunchBounds() { + return inPinnedWindowingMode(); + } + + // TODO(NOW!) + /** + * Returns {@code true} if this is the top-most split-screen-primary or + * split-screen-secondary stack, {@code false} otherwise. + */ + boolean isTopSplitScreenStack() { + return inSplitScreenWindowingMode() + && this == getDisplayArea().getTopStackInWindowingMode(getWindowingMode()); + } + + /** + * @return the top most visible activity that wants to dismiss Keyguard + */ + ActivityRecord getTopDismissingKeyguardActivity() { + return mTopDismissingKeyguardActivity; + } + + /** + * Checks whether {@param r} should be visible depending on Keyguard state and updates + * {@link #mTopActivityOccludesKeyguard} and {@link #mTopDismissingKeyguardActivity} if + * necessary. + * + * @return true if {@param r} is visible taken Keyguard state into account, false otherwise + */ + boolean checkKeyguardVisibility(ActivityRecord r, boolean shouldBeVisible, boolean isTop) { + int displayId = getDisplayId(); + if (displayId == INVALID_DISPLAY) displayId = DEFAULT_DISPLAY; + + final boolean keyguardOrAodShowing = mStackSupervisor.getKeyguardController() + .isKeyguardOrAodShowing(displayId); + final boolean keyguardLocked = mStackSupervisor.getKeyguardController().isKeyguardLocked(); + final boolean showWhenLocked = r.canShowWhenLocked(); + final boolean dismissKeyguard = r.containsDismissKeyguardWindow(); + if (shouldBeVisible) { + if (dismissKeyguard && mTopDismissingKeyguardActivity == null) { + mTopDismissingKeyguardActivity = r; + } + + // Only the top activity may control occluded, as we can't occlude the Keyguard if the + // top app doesn't want to occlude it. + if (isTop) { + mTopActivityOccludesKeyguard |= showWhenLocked; + } + + final boolean canShowWithKeyguard = canShowWithInsecureKeyguard() + && mStackSupervisor.getKeyguardController().canDismissKeyguard(); + if (canShowWithKeyguard) { + return true; + } + } + if (keyguardOrAodShowing) { + // If keyguard is showing, nothing is visible, except if we are able to dismiss Keyguard + // right away and AOD isn't visible. + return shouldBeVisible && mStackSupervisor.getKeyguardController() + .canShowActivityWhileKeyguardShowing(r, dismissKeyguard); + } else if (keyguardLocked) { + return shouldBeVisible && mStackSupervisor.getKeyguardController().canShowWhileOccluded( + dismissKeyguard, showWhenLocked); + } else { + return shouldBeVisible; + } + } + + /** + * Check if the display to which this stack is attached has + * {@link Display#FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD} applied. + */ + boolean canShowWithInsecureKeyguard() { + final DisplayContent displayContent = getDisplay(); + if (displayContent == null) { + throw new IllegalStateException("Stack is not attached to any display, stackId=" + + getRootTaskId()); + } + + final int flags = displayContent.mDisplay.getFlags(); + return (flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0; + } + + void checkTranslucentActivityWaiting(ActivityRecord top) { + if (mTranslucentActivityWaiting != top) { + mUndrawnActivitiesBelowTopTranslucent.clear(); + if (mTranslucentActivityWaiting != null) { + // Call the callback with a timeout indication. + notifyActivityDrawnLocked(null); + mTranslucentActivityWaiting = null; + } + mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); + } + } + + void convertActivityToTranslucent(ActivityRecord r) { + mTranslucentActivityWaiting = r; + mUndrawnActivitiesBelowTopTranslucent.clear(); + mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); + } + + /** + * Called as activities below the top translucent activity are redrawn. When the last one is + * redrawn notify the top activity by calling + * {@link Activity#onTranslucentConversionComplete}. + * + * @param r The most recent background activity to be drawn. Or, if r is null then a timeout + * occurred and the activity will be notified immediately. + */ + void notifyActivityDrawnLocked(ActivityRecord r) { + if ((r == null) + || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && + mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { + // The last undrawn activity below the top has just been drawn. If there is an + // opaque activity at the top, notify it that it can become translucent safely now. + final ActivityRecord waitingActivity = mTranslucentActivityWaiting; + mTranslucentActivityWaiting = null; + mUndrawnActivitiesBelowTopTranslucent.clear(); + mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); + + if (waitingActivity != null) { + mWmService.setWindowOpaqueLocked(waitingActivity.appToken, false); + if (waitingActivity.attachedToProcess()) { + try { + waitingActivity.app.getThread().scheduleTranslucentConversionComplete( + waitingActivity.appToken, r != null); + } catch (RemoteException e) { + } + } + } + } + } + + /** @see ActivityRecord#cancelInitializing() */ + void cancelInitializingActivities() { + // We don't want to clear starting window for activities that aren't behind fullscreen + // activities as we need to display their starting window until they are done initializing. + checkBehindFullscreenActivity(null /* toCheck */, ActivityRecord::cancelInitializing); + } + + /** + * If an activity {@param toCheck} is given, this method returns {@code true} if the activity + * is occluded by any fullscreen activity. If there is no {@param toCheck} and the handling + * function {@param handleBehindFullscreenActivity} is given, this method will pass all occluded + * activities to the function. + */ + boolean checkBehindFullscreenActivity(ActivityRecord toCheck, + Consumer<ActivityRecord> handleBehindFullscreenActivity) { + return mCheckBehindFullscreenActivityHelper.process( + toCheck, handleBehindFullscreenActivity); + } + + /** + * Ensure that the top activity in the stack is resumed. + * + * @param prev The previously resumed activity, for when in the process + * of pausing; can be null to call from elsewhere. + * @param options Activity options. + * + * @return Returns true if something is being resumed, or false if + * nothing happened. + * + * NOTE: It is not safe to call this method directly as it can cause an activity in a + * non-focused stack to be resumed. + * Use {@link RootWindowContainer#resumeFocusedStacksTopActivities} to resume the + * right activity for the current system state. + */ + @GuardedBy("mService") + boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { + if (mInResumeTopActivity) { + // Don't even start recursing. + return false; + } + + boolean result = false; + try { + // Protect against recursion. + mInResumeTopActivity = true; + result = resumeTopActivityInnerLocked(prev, options); + + // When resuming the top activity, it may be necessary to pause the top activity (for + // example, returning to the lock screen. We suppress the normal pause logic in + // {@link #resumeTopActivityUncheckedLocked}, since the top activity is resumed at the + // end. We call the {@link ActivityStackSupervisor#checkReadyForSleepLocked} again here + // to ensure any necessary pause logic occurs. In the case where the Activity will be + // shown regardless of the lock screen, the call to + // {@link ActivityStackSupervisor#checkReadyForSleepLocked} is skipped. + final ActivityRecord next = topRunningActivity(true /* focusableOnly */); + if (next == null || !next.canTurnScreenOn()) { + checkReadyForSleep(); + } + } finally { + mInResumeTopActivity = false; + } + + return result; + } + + @GuardedBy("mService") + private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { + if (!mAtmService.isBooting() && !mAtmService.isBooted()) { + // Not ready yet! + return false; + } + + // Find the next top-most activity to resume in this stack that is not finishing and is + // focusable. If it is not focusable, we will fall into the case below to resume the + // top activity in the next focusable task. + ActivityRecord next = topRunningActivity(true /* focusableOnly */); + + final boolean hasRunningActivity = next != null; + + // TODO: Maybe this entire condition can get removed? + if (hasRunningActivity && !isAttached()) { + return false; + } + + mRootWindowContainer.cancelInitializingActivities(); + + // Remember how we'll process this pause/resume situation, and ensure + // that the state is reset however we wind up proceeding. + boolean userLeaving = mStackSupervisor.mUserLeaving; + mStackSupervisor.mUserLeaving = false; + + if (!hasRunningActivity) { + // There are no activities left in the stack, let's look somewhere else. + return resumeNextFocusableActivityWhenStackIsEmpty(prev, options); + } + + next.delayedResume = false; + final TaskDisplayArea taskDisplayArea = getDisplayArea(); + + // If the top activity is the resumed one, nothing to do. + if (mResumedActivity == next && next.isState(RESUMED) + && taskDisplayArea.allResumedActivitiesComplete()) { + // Make sure we have executed any pending transitions, since there + // should be nothing left to do at this point. + executeAppTransition(options); + if (DEBUG_STATES) Slog.d(TAG_STATES, + "resumeTopActivityLocked: Top activity resumed " + next); + return false; + } + + if (!next.canResumeByCompat()) { + return false; + } + + // If we are currently pausing an activity, then don't do anything until that is done. + final boolean allPausedComplete = mRootWindowContainer.allPausedActivitiesComplete(); + if (!allPausedComplete) { + if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) { + Slog.v(TAG_PAUSE, "resumeTopActivityLocked: Skip resume: some activity pausing."); + } + return false; + } + + // If we are sleeping, and there is no resumed activity, and the top activity is paused, + // well that is the state we want. + if (shouldSleepOrShutDownActivities() + && mLastPausedActivity == next + && mRootWindowContainer.allPausedActivitiesComplete()) { + // If the current top activity may be able to occlude keyguard but the occluded state + // has not been set, update visibility and check again if we should continue to resume. + boolean nothingToResume = true; + if (!mAtmService.mShuttingDown) { + final boolean canShowWhenLocked = !mTopActivityOccludesKeyguard + && next.canShowWhenLocked(); + final boolean mayDismissKeyguard = mTopDismissingKeyguardActivity != next + && next.containsDismissKeyguardWindow(); + + if (canShowWhenLocked || mayDismissKeyguard) { + ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, + !PRESERVE_WINDOWS); + nothingToResume = shouldSleepActivities(); + } else if (next.currentLaunchCanTurnScreenOn() && next.canTurnScreenOn()) { + nothingToResume = false; + } + } + if (nothingToResume) { + // Make sure we have executed any pending transitions, since there + // should be nothing left to do at this point. + executeAppTransition(options); + if (DEBUG_STATES) Slog.d(TAG_STATES, + "resumeTopActivityLocked: Going to sleep and all paused"); + return false; + } + } + + // Make sure that the user who owns this activity is started. If not, + // we will just leave it as is because someone should be bringing + // another user's activities to the top of the stack. + if (!mAtmService.mAmInternal.hasStartedUserState(next.mUserId)) { + Slog.w(TAG, "Skipping resume of top activity " + next + + ": user " + next.mUserId + " is stopped"); + return false; + } + + // The activity may be waiting for stop, but that is no longer + // appropriate for it. + mStackSupervisor.mStoppingActivities.remove(next); + next.setSleeping(false); + + if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); + + // If we are currently pausing an activity, then don't do anything until that is done. + if (!mRootWindowContainer.allPausedActivitiesComplete()) { + if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, + "resumeTopActivityLocked: Skip resume: some activity pausing."); + + return false; + } + + mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); + + ActivityRecord lastResumed = null; + final Task lastFocusedStack = taskDisplayArea.getLastFocusedStack(); + if (lastFocusedStack != null && lastFocusedStack != this) { + // So, why aren't we using prev here??? See the param comment on the method. prev + // doesn't represent the last resumed activity. However, the last focus stack does if + // it isn't null. + lastResumed = lastFocusedStack.mResumedActivity; + if (userLeaving && inMultiWindowMode() && lastFocusedStack.shouldBeVisible(next)) { + // The user isn't leaving if this stack is the multi-window mode and the last + // focused stack should still be visible. + if(DEBUG_USER_LEAVING) Slog.i(TAG_USER_LEAVING, "Overriding userLeaving to false" + + " next=" + next + " lastResumed=" + lastResumed); + userLeaving = false; + } + } + + boolean pausing = taskDisplayArea.pauseBackStacks(userLeaving, next); + if (mResumedActivity != null) { + if (DEBUG_STATES) Slog.d(TAG_STATES, + "resumeTopActivityLocked: Pausing " + mResumedActivity); + pausing |= startPausingLocked(userLeaving, false /* uiSleeping */, next); + } + if (pausing) { + if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, + "resumeTopActivityLocked: Skip resume: need to start pausing"); + // At this point we want to put the upcoming activity's process + // at the top of the LRU list, since we know we will be needing it + // very soon and it would be a waste to let it get killed if it + // happens to be sitting towards the end. + if (next.attachedToProcess()) { + next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, + true /* activityChange */, false /* updateOomAdj */, + false /* addPendingTopUid */); + } else if (!next.isProcessRunning()) { + // Since the start-process is asynchronous, if we already know the process of next + // activity isn't running, we can start the process earlier to save the time to wait + // for the current activity to be paused. + final boolean isTop = this == taskDisplayArea.getFocusedStack(); + mAtmService.startProcessAsync(next, false /* knownToBeDead */, isTop, + isTop ? "pre-top-activity" : "pre-activity"); + } + if (lastResumed != null) { + lastResumed.setWillCloseOrEnterPip(true); + } + return true; + } else if (mResumedActivity == next && next.isState(RESUMED) + && taskDisplayArea.allResumedActivitiesComplete()) { + // It is possible for the activity to be resumed when we paused back stacks above if the + // next activity doesn't have to wait for pause to complete. + // So, nothing else to-do except: + // Make sure we have executed any pending transitions, since there + // should be nothing left to do at this point. + executeAppTransition(options); + if (DEBUG_STATES) Slog.d(TAG_STATES, + "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); + return true; + } + + // If the most recent activity was noHistory but was only stopped rather + // than stopped+finished because the device went to sleep, we need to make + // sure to finish it as we're making a new activity topmost. + if (shouldSleepActivities() && mLastNoHistoryActivity != null && + !mLastNoHistoryActivity.finishing) { + if (DEBUG_STATES) Slog.d(TAG_STATES, + "no-history finish of " + mLastNoHistoryActivity + " on new resume"); + mLastNoHistoryActivity.finishIfPossible("resume-no-history", false /* oomAdj */); + mLastNoHistoryActivity = null; + } + + if (prev != null && prev != next && next.nowVisible) { + + // The next activity is already visible, so hide the previous + // activity's windows right now so we can show the new one ASAP. + // We only do this if the previous is finishing, which should mean + // it is on top of the one being resumed so hiding it quickly + // is good. Otherwise, we want to do the normal route of allowing + // the resumed activity to be shown so we can decide if the + // previous should actually be hidden depending on whether the + // new one is found to be full-screen or not. + if (prev.finishing) { + prev.setVisibility(false); + if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, + "Not waiting for visible to hide: " + prev + + ", nowVisible=" + next.nowVisible); + } else { + if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, + "Previous already visible but still waiting to hide: " + prev + + ", nowVisible=" + next.nowVisible); + } + + } + + // Launching this app's activity, make sure the app is no longer + // considered stopped. + try { + mAtmService.getPackageManager().setPackageStoppedState( + next.packageName, false, next.mUserId); /* TODO: Verify if correct userid */ + } catch (RemoteException e1) { + } catch (IllegalArgumentException e) { + Slog.w(TAG, "Failed trying to unstop package " + + next.packageName + ": " + e); + } + + // We are starting up the next activity, so tell the window manager + // that the previous one will be hidden soon. This way it can know + // to ignore it when computing the desired screen orientation. + boolean anim = true; + final DisplayContent dc = taskDisplayArea.mDisplayContent; + if (prev != null) { + if (prev.finishing) { + if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, + "Prepare close transition: prev=" + prev); + if (mStackSupervisor.mNoAnimActivities.contains(prev)) { + anim = false; + dc.prepareAppTransition(TRANSIT_NONE, false); + } else { + dc.prepareAppTransition( + prev.getTask() == next.getTask() ? TRANSIT_ACTIVITY_CLOSE + : TRANSIT_TASK_CLOSE, false); + } + prev.setVisibility(false); + } else { + if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, + "Prepare open transition: prev=" + prev); + if (mStackSupervisor.mNoAnimActivities.contains(next)) { + anim = false; + dc.prepareAppTransition(TRANSIT_NONE, false); + } else { + dc.prepareAppTransition( + prev.getTask() == next.getTask() ? TRANSIT_ACTIVITY_OPEN + : next.mLaunchTaskBehind ? TRANSIT_TASK_OPEN_BEHIND + : TRANSIT_TASK_OPEN, false); + } + } + } else { + if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); + if (mStackSupervisor.mNoAnimActivities.contains(next)) { + anim = false; + dc.prepareAppTransition(TRANSIT_NONE, false); + } else { + dc.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); + } + } + + if (anim) { + next.applyOptionsLocked(); + } else { + next.clearOptionsLocked(); + } + + mStackSupervisor.mNoAnimActivities.clear(); + + if (next.attachedToProcess()) { + if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next + + " stopped=" + next.stopped + + " visibleRequested=" + next.mVisibleRequested); + + // If the previous activity is translucent, force a visibility update of + // the next activity, so that it's added to WM's opening app list, and + // transition animation can be set up properly. + // For example, pressing Home button with a translucent activity in focus. + // Launcher is already visible in this case. If we don't add it to opening + // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a + // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. + final boolean lastActivityTranslucent = lastFocusedStack != null + && (lastFocusedStack.inMultiWindowMode() + || (lastFocusedStack.mLastPausedActivity != null + && !lastFocusedStack.mLastPausedActivity.occludesParent())); + + // This activity is now becoming visible. + if (!next.mVisibleRequested || next.stopped || lastActivityTranslucent) { + next.setVisibility(true); + } + + // schedule launch ticks to collect information about slow apps. + next.startLaunchTickingLocked(); + + ActivityRecord lastResumedActivity = + lastFocusedStack == null ? null : lastFocusedStack.mResumedActivity; + final ActivityState lastState = next.getState(); + + mAtmService.updateCpuStats(); + + if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next + + " (in existing)"); + + next.setState(RESUMED, "resumeTopActivityInnerLocked"); + + next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, + true /* activityChange */, true /* updateOomAdj */, + true /* addPendingTopUid */); + + // Have the window manager re-evaluate the orientation of + // the screen based on the new activity order. + boolean notUpdated = true; + + // Activity should also be visible if set mLaunchTaskBehind to true (see + // ActivityRecord#shouldBeVisibleIgnoringKeyguard()). + if (shouldBeVisible(next)) { + // We have special rotation behavior when here is some active activity that + // requests specific orientation or Keyguard is locked. Make sure all activity + // visibilities are set correctly as well as the transition is updated if needed + // to get the correct rotation behavior. Otherwise the following call to update + // the orientation may cause incorrect configurations delivered to client as a + // result of invisible window resize. + // TODO: Remove this once visibilities are set correctly immediately when + // starting an activity. + notUpdated = !mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(), + true /* markFrozenIfConfigChanged */, false /* deferResume */); + } + + if (notUpdated) { + // The configuration update wasn't able to keep the existing + // instance of the activity, and instead started a new one. + // We should be all done, but let's just make sure our activity + // is still at the top and schedule another run if something + // weird happened. + ActivityRecord nextNext = topRunningActivity(); + if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, + "Activity config changed during resume: " + next + + ", new next: " + nextNext); + if (nextNext != next) { + // Do over! + mStackSupervisor.scheduleResumeTopActivities(); + } + if (!next.mVisibleRequested || next.stopped) { + next.setVisibility(true); + } + next.completeResumeLocked(); + return true; + } + + try { + final ClientTransaction transaction = + ClientTransaction.obtain(next.app.getThread(), next.appToken); + // Deliver all pending results. + ArrayList<ResultInfo> a = next.results; + if (a != null) { + final int N = a.size(); + if (!next.finishing && N > 0) { + if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, + "Delivering results to " + next + ": " + a); + transaction.addCallback(ActivityResultItem.obtain(a)); + } + } + + if (next.newIntents != null) { + transaction.addCallback( + NewIntentItem.obtain(next.newIntents, true /* resume */)); + } + + // Well the app will no longer be stopped. + // Clear app token stopped state in window manager if needed. + next.notifyAppResumed(next.stopped); + + EventLogTags.writeWmResumeActivity(next.mUserId, System.identityHashCode(next), + next.getTask().mTaskId, next.shortComponentName); + + next.setSleeping(false); + mAtmService.getAppWarningsLocked().onResumeActivity(next); + next.app.setPendingUiCleanAndForceProcessStateUpTo(mAtmService.mTopProcessState); + next.clearOptionsLocked(); + transaction.setLifecycleStateRequest( + ResumeActivityItem.obtain(next.app.getReportedProcState(), + dc.isNextTransitionForward())); + mAtmService.getLifecycleManager().scheduleTransaction(transaction); + + if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + + next); + } catch (Exception e) { + // Whoops, need to restart this activity! + if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " + + lastState + ": " + next); + next.setState(lastState, "resumeTopActivityInnerLocked"); + + // lastResumedActivity being non-null implies there is a lastStack present. + if (lastResumedActivity != null) { + lastResumedActivity.setState(RESUMED, "resumeTopActivityInnerLocked"); + } + + Slog.i(TAG, "Restarting because process died: " + next); + if (!next.hasBeenLaunched) { + next.hasBeenLaunched = true; + } else if (SHOW_APP_STARTING_PREVIEW && lastFocusedStack != null + && lastFocusedStack.isTopStackInDisplayArea()) { + next.showStartingWindow(null /* prev */, false /* newTask */, + false /* taskSwitch */); + } + mStackSupervisor.startSpecificActivity(next, true, false); + return true; + } + + // From this point on, if something goes wrong there is no way + // to recover the activity. + try { + next.completeResumeLocked(); + } catch (Exception e) { + // If any exception gets thrown, toss away this + // activity and try the next one. + Slog.w(TAG, "Exception thrown during resume of " + next, e); + next.finishIfPossible("resume-exception", true /* oomAdj */); + return true; + } + } else { + // Whoops, need to restart this activity! + if (!next.hasBeenLaunched) { + next.hasBeenLaunched = true; + } else { + if (SHOW_APP_STARTING_PREVIEW) { + next.showStartingWindow(null /* prev */, false /* newTask */, + false /* taskSwich */); + } + if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); + } + if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); + mStackSupervisor.startSpecificActivity(next, true, true); + } + + return true; + } + + /** + * Resume the next eligible activity in a focusable stack when this one does not have any + * running activities left. The focus will be adjusted to the next focusable stack and + * top running activities will be resumed in all focusable stacks. However, if the current stack + * is a home stack - we have to keep it focused, start and resume a home activity on the current + * display instead to make sure that the display is not empty. + */ + private boolean resumeNextFocusableActivityWhenStackIsEmpty(ActivityRecord prev, + ActivityOptions options) { + final String reason = "noMoreActivities"; + + if (!isActivityTypeHome()) { + final Task nextFocusedStack = adjustFocusToNextFocusableTask(reason); + if (nextFocusedStack != null) { + // Try to move focus to the next visible stack with a running activity if this + // stack is not covering the entire screen or is on a secondary display with no home + // stack. + return mRootWindowContainer.resumeFocusedStacksTopActivities(nextFocusedStack, + prev, null /* targetOptions */); + } + } + + // If the current stack is a home stack, or if focus didn't switch to a different stack - + // just start up the Launcher... + ActivityOptions.abort(options); + if (DEBUG_STATES) Slog.d(TAG_STATES, + "resumeNextFocusableActivityWhenStackIsEmpty: " + reason + ", go home"); + return mRootWindowContainer.resumeHomeActivity(prev, reason, getDisplayArea()); + } + + void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, + boolean newTask, boolean keepCurTransition, ActivityOptions options) { + Task rTask = r.getTask(); + final boolean allowMoveToFront = options == null || !options.getAvoidMoveToFront(); + final boolean isOrhasTask = rTask == this || hasChild(rTask); + // mLaunchTaskBehind tasks get placed at the back of the task stack. + if (!r.mLaunchTaskBehind && allowMoveToFront && (!isOrhasTask || newTask)) { + // Last activity in task had been removed or ActivityManagerService is reusing task. + // Insert or replace. + // Might not even be in. + positionChildAtTop(rTask); + } + Task task = null; + if (!newTask && isOrhasTask) { + // Starting activity cannot be occluding activity, otherwise starting window could be + // remove immediately without transferring to starting activity. + final ActivityRecord occludingActivity = getOccludingActivityAbove(r); + if (occludingActivity != null) { + // Here it is! Now, if this is not yet visible (occluded by another task) to the + // user, then just add it without starting; it will get started when the user + // navigates back to it. + if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " + task, + new RuntimeException("here").fillInStackTrace()); + rTask.positionChildAtTop(r); + ActivityOptions.abort(options); + return; + } + } + + // Place a new activity at top of stack, so it is next to interact with the user. + + // If we are not placing the new activity frontmost, we do not want to deliver the + // onUserLeaving callback to the actual frontmost activity + final Task activityTask = r.getTask(); + if (task == activityTask && mChildren.indexOf(task) != (getChildCount() - 1)) { + mStackSupervisor.mUserLeaving = false; + if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, + "startActivity() behind front, mUserLeaving=false"); + } + + task = activityTask; + + // Slot the activity into the history stack and proceed + if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to stack to task " + task, + new RuntimeException("here").fillInStackTrace()); + task.positionChildAtTop(r); + + // The transition animation and starting window are not needed if {@code allowMoveToFront} + // is false, because the activity won't be visible. + if ((!isHomeOrRecentsStack() || hasActivity()) && allowMoveToFront) { + final DisplayContent dc = getDisplay().mDisplayContent; + if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, + "Prepare open transition: starting " + r); + if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { + dc.prepareAppTransition(TRANSIT_NONE, keepCurTransition); + mStackSupervisor.mNoAnimActivities.add(r); + } else { + int transit = TRANSIT_ACTIVITY_OPEN; + if (newTask) { + if (r.mLaunchTaskBehind) { + transit = TRANSIT_TASK_OPEN_BEHIND; + } else if (getDisplay().isSingleTaskInstance()) { + // If a new task is being launched in a single task display, we don't need + // to play normal animation, but need to trigger a callback when an app + // transition is actually handled. So ignore already prepared activity, and + // override it. + transit = TRANSIT_SHOW_SINGLE_TASK_DISPLAY; + keepCurTransition = false; + } else { + // If a new task is being launched, then mark the existing top activity as + // supporting picture-in-picture while pausing only if the starting activity + // would not be considered an overlay on top of the current activity + // (eg. not fullscreen, or the assistant) + if (canEnterPipOnTaskSwitch(focusedTopActivity, + null /* toFrontTask */, r, options)) { + focusedTopActivity.supportsEnterPipOnTaskSwitch = true; + } + transit = TRANSIT_TASK_OPEN; + } + } + dc.prepareAppTransition(transit, keepCurTransition); + mStackSupervisor.mNoAnimActivities.remove(r); + } + boolean doShow = true; + if (newTask) { + // Even though this activity is starting fresh, we still need + // to reset it to make sure we apply affinities to move any + // existing activities from other tasks in to it. + // If the caller has requested that the target task be + // reset, then do so. + if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { + resetTaskIfNeeded(r, r); + doShow = topRunningNonDelayedActivityLocked(null) == r; + } + } else if (options != null && options.getAnimationType() + == ActivityOptions.ANIM_SCENE_TRANSITION) { + doShow = false; + } + if (r.mLaunchTaskBehind) { + // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we + // tell WindowManager that r is visible even though it is at the back of the stack. + r.setVisibility(true); + ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); + // Go ahead to execute app transition for this activity since the app transition + // will not be triggered through the resume channel. + getDisplay().mDisplayContent.executeAppTransition(); + } else if (SHOW_APP_STARTING_PREVIEW && doShow) { + // Figure out if we are transitioning from another activity that is + // "has the same starting icon" as the next one. This allows the + // window manager to keep the previous window it had previously + // created, if it still had one. + Task prevTask = r.getTask(); + ActivityRecord prev = prevTask.topActivityWithStartingWindow(); + if (prev != null) { + // We don't want to reuse the previous starting preview if: + // (1) The current activity is in a different task. + if (prev.getTask() != prevTask) { + prev = null; + } + // (2) The current activity is already displayed. + else if (prev.nowVisible) { + prev = null; + } + } + r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity)); + } + } else { + // If this is the first activity, don't do any fancy animations, + // because there is nothing for it to animate on top of. + ActivityOptions.abort(options); + } + } + + /** + * @return Whether the switch to another task can trigger the currently running activity to + * enter PiP while it is pausing (if supported). Only one of {@param toFrontTask} or + * {@param toFrontActivity} should be set. + */ + private boolean canEnterPipOnTaskSwitch(ActivityRecord pipCandidate, + Task toFrontTask, ActivityRecord toFrontActivity, ActivityOptions opts) { + if (opts != null && opts.disallowEnterPictureInPictureWhileLaunching()) { + // Ensure the caller has requested not to trigger auto-enter PiP + return false; + } + if (pipCandidate == null || pipCandidate.inPinnedWindowingMode()) { + // Ensure that we do not trigger entering PiP an activity on the pinned stack + return false; + } + final Task targetStack = toFrontTask != null + ? toFrontTask.getRootTask() : toFrontActivity.getRootTask(); + if (targetStack != null && targetStack.isActivityTypeAssistant()) { + // Ensure the task/activity being brought forward is not the assistant + return false; + } + return true; + } + + private boolean isTaskSwitch(ActivityRecord r, ActivityRecord topFocusedActivity) { + return topFocusedActivity != null && r.getTask() != topFocusedActivity.getTask(); + } + + /** + * Reset the task by reparenting the activities that have same affinity to the task or + * reparenting the activities that have different affinityies out of the task, while these + * activities allow task reparenting. + * + * @param taskTop Top activity of the task might be reset. + * @param newActivity The activity that going to be started. + * @return The non-finishing top activity of the task after reset or the original task top + * activity if all activities within the task are finishing. + */ + ActivityRecord resetTaskIfNeeded(ActivityRecord taskTop, ActivityRecord newActivity) { + final boolean forceReset = + (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; + final Task task = taskTop.getTask(); + + // If ActivityOptions are moved out and need to be aborted or moved to taskTop. + final ActivityOptions topOptions = sResetTargetTaskHelper.process(task, forceReset); + + if (mChildren.contains(task)) { + final ActivityRecord newTop = task.getTopNonFinishingActivity(); + if (newTop != null) { + taskTop = newTop; + } + } + + if (topOptions != null) { + // If we got some ActivityOptions from an activity on top that + // was removed from the task, propagate them to the new real top. + taskTop.updateOptionsLocked(topOptions); + } + + return taskTop; + } + + /** + * Finish the topmost activity that belongs to the crashed app. We may also finish the activity + * that requested launch of the crashed one to prevent launch-crash loop. + * @param app The app that crashed. + * @param reason Reason to perform this action. + * @return The task that was finished in this stack, {@code null} if top running activity does + * not belong to the crashed app. + */ + final Task finishTopCrashedActivityLocked(WindowProcessController app, String reason) { + final ActivityRecord r = topRunningActivity(); + if (r == null || r.app != app) { + return null; + } + if (r.isActivityTypeHome() && mAtmService.mHomeProcess == app) { + // Home activities should not be force-finished as we have nothing else to go + // back to. AppErrors will get to it after two crashes in MIN_CRASH_INTERVAL. + Slog.w(TAG, " Not force finishing home activity " + + r.intent.getComponent().flattenToShortString()); + return null; + } + Slog.w(TAG, " Force finishing activity " + + r.intent.getComponent().flattenToShortString()); + Task finishedTask = r.getTask(); + getDisplay().mDisplayContent.prepareAppTransition( + TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); + r.finishIfPossible(reason, false /* oomAdj */); + + // Also terminate any activities below it that aren't yet stopped, to avoid a situation + // where one will get re-start our crashing activity once it gets resumed again. + final ActivityRecord activityBelow = getActivityBelow(r); + if (activityBelow != null) { + if (activityBelow.isState(STARTED, RESUMED, PAUSING, PAUSED)) { + if (!activityBelow.isActivityTypeHome() + || mAtmService.mHomeProcess != activityBelow.app) { + Slog.w(TAG, " Force finishing activity " + + activityBelow.intent.getComponent().flattenToShortString()); + activityBelow.finishIfPossible(reason, false /* oomAdj */); + } + } + } + + return finishedTask; + } + + void finishVoiceTask(IVoiceInteractionSession session) { + final PooledConsumer c = PooledLambda.obtainConsumer(Task::finishIfVoiceTask, + PooledLambda.__(Task.class), session.asBinder()); + forAllLeafTasks(c, true /* traverseTopToBottom */); + c.recycle(); + } + + private static void finishIfVoiceTask(Task tr, IBinder binder) { + if (tr.voiceSession != null && tr.voiceSession.asBinder() == binder) { + tr.forAllActivities((r) -> { + if (r.finishing) return; + r.finishIfPossible("finish-voice", false /* oomAdj */); + tr.mAtmService.updateOomAdj(); + }); + } else { + // Check if any of the activities are using voice + final PooledFunction f = PooledLambda.obtainFunction( + Task::finishIfVoiceActivity, PooledLambda.__(ActivityRecord.class), + binder); + tr.forAllActivities(f); + f.recycle(); + } + } + + private static boolean finishIfVoiceActivity(ActivityRecord r, IBinder binder) { + if (r.voiceSession == null || r.voiceSession.asBinder() != binder) return false; + // Inform of cancellation + r.clearVoiceSessionLocked(); + try { + r.app.getThread().scheduleLocalVoiceInteractionStarted(r.appToken, null); + } catch (RemoteException re) { + // Ok Boomer... + } + r.mAtmService.finishRunningVoiceLocked(); + return true; + } + + /** Finish all activities in the stack without waiting. */ + void finishAllActivitiesImmediately() { + if (!hasChild()) { + removeIfPossible(); + return; + } + forAllActivities((r) -> { + Slog.d(TAG, "finishAllActivitiesImmediatelyLocked: finishing " + r); + r.destroyIfPossible("finishAllActivitiesImmediately"); + }); + } + + /** @return true if the stack behind this one is a standard activity type. */ + private boolean inFrontOfStandardStack() { + final TaskDisplayArea taskDisplayArea = getDisplayArea(); + if (taskDisplayArea == null) { + return false; + } + final int index = taskDisplayArea.getIndexOf(this); + if (index == 0) { + return false; + } + final Task stackBehind = taskDisplayArea.getChildAt(index - 1); + return stackBehind.isActivityTypeStandard(); + } + + boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { + // Basic case: for simple app-centric recents, we need to recreate + // the task if the affinity has changed. + + final String affinity = ActivityRecord.getTaskAffinityWithUid(destAffinity, srec.getUid()); + if (srec == null || srec.getTask().affinity == null + || !srec.getTask().affinity.equals(affinity)) { + return true; + } + // Document-centric case: an app may be split in to multiple documents; + // they need to re-create their task if this current activity is the root + // of a document, unless simply finishing it will return them to the + // correct app behind. + final Task task = srec.getTask(); + if (srec.isRootOfTask() && task.getBaseIntent() != null + && task.getBaseIntent().isDocument()) { + // Okay, this activity is at the root of its task. What to do, what to do... + if (!inFrontOfStandardStack()) { + // Finishing won't return to an application, so we need to recreate. + return true; + } + // We now need to get the task below it to determine what to do. + final Task prevTask = getTaskBelow(task); + if (prevTask == null) { + Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); + return false; + } + if (!task.affinity.equals(prevTask.affinity)) { + // These are different apps, so need to recreate. + return true; + } + } + return false; + } + + boolean navigateUpTo(ActivityRecord srec, Intent destIntent, NeededUriGrants destGrants, + int resultCode, Intent resultData, NeededUriGrants resultGrants) { + if (!srec.attachedToProcess()) { + // Nothing to do if the caller is not attached, because this method should be called + // from an alive activity. + return false; + } + final Task task = srec.getTask(); + if (!srec.isDescendantOf(this)) { + return false; + } + + ActivityRecord parent = task.getActivityBelow(srec); + boolean foundParentInTask = false; + final ComponentName dest = destIntent.getComponent(); + if (task.getBottomMostActivity() != srec && dest != null) { + final ActivityRecord candidate = task.getActivity( + (ar) -> ar.info.packageName.equals(dest.getPackageName()) + && ar.info.name.equals(dest.getClassName()), srec, + false /*includeBoundary*/, true /*traverseTopToBottom*/); + if (candidate != null) { + parent = candidate; + foundParentInTask = true; + } + } + + // TODO: There is a dup. of this block of code in ActivityTaskManagerService.finishActivity + // We should consolidate. + IActivityController controller = mAtmService.mController; + if (controller != null) { + ActivityRecord next = topRunningActivity(srec.appToken, INVALID_TASK_ID); + if (next != null) { + // ask watcher if this is allowed + boolean resumeOK = true; + try { + resumeOK = controller.activityResuming(next.packageName); + } catch (RemoteException e) { + mAtmService.mController = null; + Watchdog.getInstance().setActivityController(null); + } + + if (!resumeOK) { + return false; + } + } + } + final long origId = Binder.clearCallingIdentity(); + + final int[] resultCodeHolder = new int[1]; + resultCodeHolder[0] = resultCode; + final Intent[] resultDataHolder = new Intent[1]; + resultDataHolder[0] = resultData; + final NeededUriGrants[] resultGrantsHolder = new NeededUriGrants[1]; + resultGrantsHolder[0] = resultGrants; + final ActivityRecord finalParent = parent; + task.forAllActivities((ar) -> { + if (ar == finalParent) return true; + + ar.finishIfPossible(resultCodeHolder[0], resultDataHolder[0], resultGrantsHolder[0], + "navigate-up", true /* oomAdj */); + // Only return the supplied result for the first activity finished + resultCodeHolder[0] = Activity.RESULT_CANCELED; + resultDataHolder[0] = null; + return false; + }, srec, true, true); + resultCode = resultCodeHolder[0]; + resultData = resultDataHolder[0]; + + if (parent != null && foundParentInTask) { + final int callingUid = srec.info.applicationInfo.uid; + final int parentLaunchMode = parent.info.launchMode; + final int destIntentFlags = destIntent.getFlags(); + if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || + parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || + parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || + (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { + parent.deliverNewIntentLocked(callingUid, destIntent, destGrants, srec.packageName); + } else { + try { + ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( + destIntent.getComponent(), ActivityManagerService.STOCK_PM_FLAGS, + srec.mUserId); + // TODO(b/64750076): Check if calling pid should really be -1. + final int res = mAtmService.getActivityStartController() + .obtainStarter(destIntent, "navigateUpTo") + .setCaller(srec.app.getThread()) + .setActivityInfo(aInfo) + .setResultTo(parent.appToken) + .setCallingPid(-1) + .setCallingUid(callingUid) + .setCallingPackage(srec.packageName) + .setCallingFeatureId(parent.launchedFromFeatureId) + .setRealCallingPid(-1) + .setRealCallingUid(callingUid) + .setComponentSpecified(true) + .execute(); + foundParentInTask = res == ActivityManager.START_SUCCESS; + } catch (RemoteException e) { + foundParentInTask = false; + } + parent.finishIfPossible(resultCode, resultData, resultGrants, + "navigate-top", true /* oomAdj */); + } + } + Binder.restoreCallingIdentity(origId); + return foundParentInTask; + } + + void removeLaunchTickMessages() { + forAllActivities(ActivityRecord::removeLaunchTickRunnable); + } + + private void updateTransitLocked(int transit, ActivityOptions options, boolean forceOverride) { + if (options != null) { + ActivityRecord r = topRunningActivity(); + if (r != null && !r.isState(RESUMED)) { + r.updateOptionsLocked(options); + } else { + ActivityOptions.abort(options); + } + } + getDisplay().mDisplayContent.prepareAppTransition(transit, false, + 0 /* flags */, forceOverride); + } + + final void moveTaskToFront(Task tr, boolean noAnimation, ActivityOptions options, + AppTimeTracker timeTracker, String reason) { + moveTaskToFront(tr, noAnimation, options, timeTracker, !DEFER_RESUME, reason); + } + + final void moveTaskToFront(Task tr, boolean noAnimation, ActivityOptions options, + AppTimeTracker timeTracker, boolean deferResume, String reason) { + if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); + + final Task topStack = getDisplayArea().getTopStack(); + final ActivityRecord topActivity = topStack != null + ? topStack.getTopNonFinishingActivity() : null; + + if (tr != this && !tr.isDescendantOf(this)) { + // nothing to do! + if (noAnimation) { + ActivityOptions.abort(options); + } else if (isSingleTaskInstance()) { + // When a task is moved front on the display which can only contain one task, start + // a special transition. + // {@link AppTransitionController#handleAppTransitionReady} later picks up the + // transition, and schedules + // {@link ITaskStackListener#onSingleTaskDisplayDrawn} callback which is triggered + // after contents are drawn on the display. + updateTransitLocked(TRANSIT_SHOW_SINGLE_TASK_DISPLAY, options, + true /* forceOverride */); + } else { + updateTransitLocked(TRANSIT_TASK_TO_FRONT, options, false /* forceOverride */); + } + return; + } + + if (timeTracker != null) { + // The caller wants a time tracker associated with this task. + final PooledConsumer c = PooledLambda.obtainConsumer(ActivityRecord::setAppTimeTracker, + PooledLambda.__(ActivityRecord.class), timeTracker); + tr.forAllActivities(c); + c.recycle(); + } + + try { + // Defer updating the IME target since the new IME target will try to get computed + // before updating all closing and opening apps, which can cause the ime target to + // get calculated incorrectly. + getDisplay().deferUpdateImeTarget(); + + // Shift all activities with this task up to the top + // of the stack, keeping them in the same internal order. + positionChildAtTop(tr); + + // Don't refocus if invisible to current user + final ActivityRecord top = tr.getTopNonFinishingActivity(); + if (top == null || !top.okToShowLocked()) { + if (top != null) { + mStackSupervisor.mRecentTasks.add(top.getTask()); + } + ActivityOptions.abort(options); + return; + } + + // Set focus to the top running activity of this stack. + final ActivityRecord r = topRunningActivity(); + if (r != null) { + r.moveFocusableActivityToTop(reason); + } + + if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); + if (noAnimation) { + getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_NONE, false); + if (r != null) { + mStackSupervisor.mNoAnimActivities.add(r); + } + ActivityOptions.abort(options); + } else if (isSingleTaskInstance()) { + updateTransitLocked(TRANSIT_SHOW_SINGLE_TASK_DISPLAY, options, + true /* forceOverride */); + } else { + updateTransitLocked(TRANSIT_TASK_TO_FRONT, options, false /* forceOverride */); + } + + // If a new task is moved to the front, then mark the existing top activity as + // supporting + + // picture-in-picture while paused only if the task would not be considered an oerlay + // on top + // of the current activity (eg. not fullscreen, or the assistant) + if (canEnterPipOnTaskSwitch(topActivity, tr, null /* toFrontActivity */, + options)) { + topActivity.supportsEnterPipOnTaskSwitch = true; + } + + if (!deferResume) { + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + EventLogTags.writeWmTaskToFront(tr.mUserId, tr.mTaskId); + mAtmService.getTaskChangeNotificationController() + .notifyTaskMovedToFront(tr.getTaskInfo()); + } finally { + getDisplay().continueUpdateImeTarget(); + } + } + + /** + * Worker method for rearranging history stack. Implements the function of moving all + * activities for a specific task (gathering them if disjoint) into a single group at the + * bottom of the stack. + * + * If a watcher is installed, the action is preflighted and the watcher has an opportunity + * to premeptively cancel the move. + * + * @param tr The task to collect and move to the bottom. + * @return Returns true if the move completed, false if not. + */ + boolean moveTaskToBack(Task tr) { + Slog.i(TAG, "moveTaskToBack: " + tr); + + // In LockTask mode, moving a locked task to the back of the stack may expose unlocked + // ones. Therefore we need to check if this operation is allowed. + if (!mAtmService.getLockTaskController().canMoveTaskToBack(tr)) { + return false; + } + + // If we have a watcher, preflight the move before committing to it. First check + // for *other* available tasks, but if none are available, then try again allowing the + // current task to be selected. + if (isTopStackInDisplayArea() && mAtmService.mController != null) { + ActivityRecord next = topRunningActivity(null, tr.mTaskId); + if (next == null) { + next = topRunningActivity(null, INVALID_TASK_ID); + } + if (next != null) { + // ask watcher if this is allowed + boolean moveOK = true; + try { + moveOK = mAtmService.mController.activityResuming(next.packageName); + } catch (RemoteException e) { + mAtmService.mController = null; + Watchdog.getInstance().setActivityController(null); + } + if (!moveOK) { + return false; + } + } + } + + if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to back transition: task=" + + tr.mTaskId); + + getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); + moveToBack("moveTaskToBackLocked", tr); + + if (inPinnedWindowingMode()) { + mStackSupervisor.removeStack(this); + return true; + } + + mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */, + getDisplay().mDisplayId, false /* markFrozenIfConfigChanged */, + false /* deferResume */); + + ActivityRecord topActivity = getDisplayArea().topRunningActivity(); + Task topStack = topActivity.getRootTask(); + if (topStack != null && topStack != this && topActivity.isState(RESUMED)) { + // Usually resuming a top activity triggers the next app transition, but nothing's got + // resumed in this case, so we need to execute it explicitly. + getDisplay().mDisplayContent.executeAppTransition(); + } else { + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + return true; + } + + /** + * Ensures all visible activities at or below the input activity have the right configuration. + */ + void ensureVisibleActivitiesConfiguration(ActivityRecord start, boolean preserveWindow) { + mEnsureVisibleActivitiesConfigHelper.process(start, preserveWindow); + } + + // TODO: Can only be called from special methods in ActivityStackSupervisor. + // Need to consolidate those calls points into this resize method so anyone can call directly. + void resize(Rect displayedBounds, boolean preserveWindows, boolean deferResume) { + Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "stack.resize_" + getRootTaskId()); + mAtmService.deferWindowLayout(); + try { + // TODO: Why not just set this on the stack directly vs. on each tasks? + // Update override configurations of all tasks in the stack. + final PooledConsumer c = PooledLambda.obtainConsumer( + Task::processTaskResizeBounds, PooledLambda.__(Task.class), + displayedBounds); + forAllTasks(c, true /* traverseTopToBottom */); + c.recycle(); + + if (mBoundsAnimating) { + // Force to update task surface bounds and relayout windows, since configBounds + // remains unchanged during bounds animation. + updateSurfaceBounds(); + getDisplay().setLayoutNeeded(); + mWmService.requestTraversal(); + } + + if (!deferResume) { + ensureVisibleActivitiesConfiguration(topRunningActivity(), preserveWindows); + } + } finally { + mAtmService.continueWindowLayout(); + Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); + } + } + + private static void processTaskResizeBounds(Task task, Rect displayedBounds) { + if (!task.isResizeable()) return; + + task.setBounds(displayedBounds); + } + + /** + * Until we can break this "set task bounds to same as stack bounds" behavior, this + * basically resizes both stack and task bounds to the same bounds. + */ + private void setTaskBounds(Rect bounds) { + final PooledConsumer c = PooledLambda.obtainConsumer(Task::setTaskBoundsInner, + PooledLambda.__(Task.class), bounds); + forAllLeafTasks(c, true /* traverseTopToBottom */); + c.recycle(); + } + + private static void setTaskBoundsInner(Task task, Rect bounds) { + task.setBounds(task.isResizeable() ? bounds : null); + } + + boolean willActivityBeVisible(IBinder token) { + final ActivityRecord r = ActivityRecord.forTokenLocked(token); + if (r == null) { + return false; + } + + // See if there is an occluding activity on-top of this one. + final ActivityRecord occludingActivity = getOccludingActivityAbove(r); + if (occludingActivity != null) return false; + + if (r.finishing) Slog.e(TAG, "willActivityBeVisible: Returning false," + + " would have returned true for r=" + r); + return !r.finishing; + } + + void unhandledBackLocked() { + final ActivityRecord topActivity = getTopMostActivity(); + if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, + "Performing unhandledBack(): top activity: " + topActivity); + if (topActivity != null) { + topActivity.finishIfPossible("unhandled-back", true /* oomAdj */); + } + } + + /** + * Reset local parameters because an app's activity died. + * @param app The app of the activity that died. + * @return result from removeHistoryRecordsForAppLocked. + */ + boolean handleAppDied(WindowProcessController app) { + if (mPausingActivity != null && mPausingActivity.app == app) { + if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, + "App died while pausing: " + mPausingActivity); + mPausingActivity = null; + } + if (mLastPausedActivity != null && mLastPausedActivity.app == app) { + mLastPausedActivity = null; + mLastNoHistoryActivity = null; + } + + mStackSupervisor.removeHistoryRecords(app); + return mRemoveHistoryRecordsForApp.process(app); + } + + boolean dump(FileDescriptor fd, PrintWriter pw, boolean dumpAll, boolean dumpClient, + String dumpPackage, final boolean needSep) { + Runnable headerPrinter = () -> { + if (needSep) { + pw.println(); + } + pw.println(" Stack #" + getRootTaskId() + + ": type=" + activityTypeToString(getActivityType()) + + " mode=" + windowingModeToString(getWindowingMode())); + pw.println(" isSleeping=" + shouldSleepActivities()); + pw.println(" mBounds=" + getRequestedOverrideBounds()); + }; + + boolean printed = false; + + if (dumpPackage == null) { + // If we are not filtering by package, we want to print absolutely everything, + // so always print the header even if there are no tasks/activities inside. + headerPrinter.run(); + headerPrinter = null; + printed = true; + } + + printed |= printThisActivity(pw, mPausingActivity, dumpPackage, false, + " mPausingActivity: ", null); + printed |= printThisActivity(pw, getResumedActivity(), dumpPackage, false, + " mResumedActivity: ", null); + if (dumpAll) { + printed |= printThisActivity(pw, mLastPausedActivity, dumpPackage, false, + " mLastPausedActivity: ", null); + printed |= printThisActivity(pw, mLastNoHistoryActivity, dumpPackage, + false, " mLastNoHistoryActivity: ", null); + } + + printed |= dumpActivities(fd, pw, dumpAll, dumpClient, dumpPackage, false, headerPrinter); + + return printed; + } + + private boolean dumpActivities(FileDescriptor fd, PrintWriter pw, boolean dumpAll, + boolean dumpClient, String dumpPackage, boolean needSep, Runnable header) { + if (!hasChild()) { + return false; + } + final AtomicBoolean printedHeader = new AtomicBoolean(false); + final AtomicBoolean printed = new AtomicBoolean(false); + forAllLeafTasks((task) -> { + final String prefix = " "; + Runnable headerPrinter = () -> { + printed.set(true); + if (!printedHeader.get()) { + if (needSep) { + pw.println(""); + } + if (header != null) { + header.run(); + } + printedHeader.set(true); + } + pw.print(prefix); pw.print("* "); pw.println(task); + pw.print(prefix); pw.print(" mBounds="); + pw.println(task.getRequestedOverrideBounds()); + pw.print(prefix); pw.print(" mMinWidth="); pw.print(task.mMinWidth); + pw.print(" mMinHeight="); pw.println(task.mMinHeight); + if (mLastNonFullscreenBounds != null) { + pw.print(prefix); + pw.print(" mLastNonFullscreenBounds="); + pw.println(task.mLastNonFullscreenBounds); + } + task.dump(pw, prefix + " "); + }; + if (dumpPackage == null) { + // If we are not filtering by package, we want to print absolutely everything, + // so always print the header even if there are no activities inside. + headerPrinter.run(); + headerPrinter = null; + } + final ArrayList<ActivityRecord> activities = new ArrayList<>(); + // Add activities by traversing the hierarchy from bottom to top, since activities + // are dumped in reverse order in {@link ActivityStackSupervisor#dumpHistoryList()}. + task.forAllActivities((Consumer<ActivityRecord>) activities::add, + false /* traverseTopToBottom */); + dumpHistoryList(fd, pw, activities, prefix, "Hist", true, !dumpAll, dumpClient, + dumpPackage, false, headerPrinter, task); + }, true /* traverseTopToBottom */); + return printed.get(); + } + + ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { + ArrayList<ActivityRecord> activities = new ArrayList<>(); + + if ("all".equals(name)) { + forAllActivities((Consumer<ActivityRecord>) activities::add); + } else if ("top".equals(name)) { + final ActivityRecord topActivity = getTopMostActivity(); + if (topActivity != null) { + activities.add(topActivity); + } + } else { + ActivityManagerService.ItemMatcher matcher = new ActivityManagerService.ItemMatcher(); + matcher.build(name); + + forAllActivities((r) -> { + if (matcher.match(r, r.intent.getComponent())) { + activities.add(r); + } + }); + } + + return activities; + } + + ActivityRecord restartPackage(String packageName) { + ActivityRecord starting = topRunningActivity(); + + // All activities that came from the package must be + // restarted as if there was a config change. + PooledConsumer c = PooledLambda.obtainConsumer(Task::restartPackage, + PooledLambda.__(ActivityRecord.class), starting, packageName); + forAllActivities(c); + c.recycle(); + + return starting; + } + + private static void restartPackage( + ActivityRecord r, ActivityRecord starting, String packageName) { + if (r.info.packageName.equals(packageName)) { + r.forceNewConfig = true; + if (starting != null && r == starting && r.mVisibleRequested) { + r.startFreezingScreenLocked(CONFIG_SCREEN_LAYOUT); + } + } + } + + Task reuseOrCreateTask(ActivityInfo info, Intent intent, boolean toTop) { + return reuseOrCreateTask(info, intent, null /*voiceSession*/, null /*voiceInteractor*/, + toTop, null /*activity*/, null /*source*/, null /*options*/); + } + // TODO: Can be removed once we change callpoints creating stacks to be creating tasks. + /** Either returns this current task to be re-used or creates a new child task. */ + Task reuseOrCreateTask(ActivityInfo info, Intent intent, IVoiceInteractionSession voiceSession, + IVoiceInteractor voiceInteractor, boolean toTop, ActivityRecord activity, + ActivityRecord source, ActivityOptions options) { + + Task task; + if (DisplayContent.alwaysCreateStack(getWindowingMode(), getActivityType())) { + // This stack will only contain one task, so just return itself since all stacks ara now + // tasks and all tasks are now stacks. + task = reuseAsLeafTask(voiceSession, voiceInteractor, intent, info, activity); + } else { + // Create child task since this stack can contain multiple tasks. + final int taskId = activity != null + ? mStackSupervisor.getNextTaskIdForUser(activity.mUserId) + : mStackSupervisor.getNextTaskIdForUser(); + task = new Task(mAtmService, taskId, info, intent, voiceSession, + voiceInteractor, null /* taskDescription */, this); + + // add the task to stack first, mTaskPositioner might need the stack association + addChild(task, toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); + } + + int displayId = getDisplayId(); + if (displayId == INVALID_DISPLAY) displayId = DEFAULT_DISPLAY; + final boolean isLockscreenShown = mAtmService.mStackSupervisor.getKeyguardController() + .isKeyguardOrAodShowing(displayId); + if (!mStackSupervisor.getLaunchParamsController() + .layoutTask(task, info.windowLayout, activity, source, options) + && !getRequestedOverrideBounds().isEmpty() + && task.isResizeable() && !isLockscreenShown) { + task.setBounds(getRequestedOverrideBounds()); + } + + return task; + } + + void addChild(WindowContainer child, final boolean toTop, boolean showForAllUsers) { + if (isSingleTaskInstance() && hasChild()) { + throw new IllegalStateException("Can only have one child on stack=" + this); + } + + Task task = child.asTask(); + try { + + if (task != null) { + task.setForceShowForAllUsers(showForAllUsers); + } + // We only want to move the parents to the parents if we are creating this task at the + // top of its stack. + addChild(child, toTop ? MAX_VALUE : 0, toTop /*moveParents*/); + } finally { + if (task != null) { + task.setForceShowForAllUsers(false); + } + } + } + + void positionChildAt(Task task, int position) { + if (task.getRootTask() != this) { + throw new IllegalArgumentException("AS.positionChildAt: task=" + task + + " is not a child of stack=" + this + " current parent=" + task.getRootTask()); + } + + task.updateOverrideConfigurationForStack(this); + + final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); + final boolean wasResumed = topRunningActivity == task.getRootTask().mResumedActivity; + + boolean toTop = position >= getChildCount(); + boolean includingParents = toTop || getDisplayArea().getNextFocusableStack(this, + true /* ignoreCurrent */) == null; + if (WindowManagerDebugConfig.DEBUG_STACK) { + Slog.i(TAG_WM, "positionChildAt: positioning task=" + task + " at " + position); + } + positionChildAt(position, task, includingParents); + task.updateTaskMovement(toTop); + getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); + + + // TODO: Investigate if this random code is really needed. + if (task.voiceSession != null) { + try { + task.voiceSession.taskStarted(task.intent, task.mTaskId); + } catch (RemoteException e) { + } + } + + if (wasResumed) { + if (mResumedActivity != null) { + Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" + + " other stack to this stack mResumedActivity=" + mResumedActivity + + " other mResumedActivity=" + topRunningActivity); + } + topRunningActivity.setState(RESUMED, "positionChildAt"); + } + + // The task might have already been running and its visibility needs to be synchronized with + // the visibility of the stack / windows. + ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); + mRootWindowContainer.resumeFocusedStacksTopActivities(); + } + + public void setAlwaysOnTop(boolean alwaysOnTop) { + if (isAlwaysOnTop() == alwaysOnTop) { + return; + } + super.setAlwaysOnTop(alwaysOnTop); + final TaskDisplayArea taskDisplayArea = getDisplayArea(); + // positionChildAtTop() must be called even when always on top gets turned off because we + // need to make sure that the stack is moved from among always on top windows to below other + // always on top windows. Since the position the stack should be inserted into is calculated + // properly in {@link DisplayContent#getTopInsertPosition()} in both cases, we can just + // request that the stack is put at top here. + taskDisplayArea.positionStackAtTop(this, false /* includingParents */); + } + + /** NOTE: Should only be called from {@link Task#reparent}. */ + void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume, + boolean setPause, String reason) { + if (!moveToFront) { + return; + } + + final ActivityState origState = r.getState(); + // If the activity owns the last resumed activity, transfer that together, + // so that we don't resume the same activity again in the new stack. + // Apps may depend on onResume()/onPause() being called in pairs. + if (setResume) { + r.setState(RESUMED, "moveToFrontAndResumeStateIfNeeded"); + } + // If the activity was previously pausing, then ensure we transfer that as well + if (setPause) { + mPausingActivity = r; + r.schedulePauseTimeout(); + } + // Move the stack in which we are placing the activity to the front. + moveToFront(reason); + // If the original state is resumed, there is no state change to update focused app. + // So here makes sure the activity focus is set if it is the top. + if (origState == RESUMED && r == mRootWindowContainer.getTopResumedActivity()) { + mAtmService.setResumedActivityUncheckLocked(r, reason); + } + } + + void dismissPip() { + if (!isActivityTypeStandardOrUndefined()) { + throw new IllegalArgumentException( + "You can't move tasks from non-standard stacks."); + } + if (getWindowingMode() != WINDOWING_MODE_PINNED) { + throw new IllegalArgumentException( + "Can't exit pinned mode if it's not pinned already."); + } + + mWmService.inSurfaceTransaction(() -> { + final Task task = getBottomMostTask(); + setWindowingMode(WINDOWING_MODE_UNDEFINED); + + getDisplayArea().positionStackAtTop(this, false /* includingParents */); + + mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, this); + MetricsLoggerWrapper.logPictureInPictureFullScreen(mAtmService.mContext, + task.effectiveUid, task.realActivity.flattenToString()); + }); + } + + void prepareFreezingTaskBounds() { + forAllLeafTasks(Task::prepareFreezingBounds, true /* traverseTopToBottom */); + } + + private int setBounds(Rect existing, Rect bounds) { + if (equivalentBounds(existing, bounds)) { + return BOUNDS_CHANGE_NONE; + } + + final int result = super.setBounds(!inMultiWindowMode() ? null : bounds); + + updateSurfaceBounds(); + return result; + } + + @Override + public void getBounds(Rect bounds) { + bounds.set(getBounds()); + } + + /** + * @return the final bounds for the bounds animation. + */ + void getFinalAnimationBounds(Rect outBounds) { + outBounds.set(mBoundsAnimationTarget); + } + + /** + * @return the final source bounds for the bounds animation. + */ + void getFinalAnimationSourceHintBounds(Rect outBounds) { + outBounds.set(mBoundsAnimationSourceHintBounds); + } + + /** + * Put a Task in this stack. Used for adding only. + * When task is added to top of the stack, the entire branch of the hierarchy (including stack + * and display) will be brought to top. + * @param child The child to add. + * @param position Target position to add the task to. + */ + private void addChild(WindowContainer child, int position, boolean moveParents) { + // Add child task. + addChild(child, null); + + // Move child to a proper position, as some restriction for position might apply. + positionChildAt(position, child, moveParents /* includingParents */); + } + + void positionChildAtTop(Task child) { + if (child == null) { + // TODO: Fix the call-points that cause this to happen. + return; + } + + if (child == this) { + // TODO: Fix call-points + moveToFront("positionChildAtTop"); + return; + } + + positionChildAt(POSITION_TOP, child, true /* includingParents */); + child.updateTaskMovement(true); + + final DisplayContent displayContent = getDisplayContent(); + displayContent.layoutAndAssignWindowLayersIfNeeded(); + } + + void positionChildAtBottom(Task child) { + // If there are other focusable stacks on the display, the z-order of the display should not + // be changed just because a task was placed at the bottom. E.g. if it is moving the topmost + // task to bottom, the next focusable stack on the same display should be focused. + final Task nextFocusableStack = getDisplayArea().getNextFocusableStack( + child.getRootTask(), true /* ignoreCurrent */); + positionChildAtBottom(child, nextFocusableStack == null /* includingParents */); + child.updateTaskMovement(true); + } + + @VisibleForTesting + void positionChildAtBottom(Task child, boolean includingParents) { + if (child == null) { + // TODO: Fix the call-points that cause this to happen. + return; + } + + positionChildAt(POSITION_BOTTOM, child, includingParents); + getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); + } + + @Override + void onChildPositionChanged(WindowContainer child) { + if (isOrganized()) { + mAtmService.mTaskOrganizerController.dispatchTaskInfoChanged(this, false /* force */); + } + + if (!mChildren.contains(child)) { + return; + } + + final boolean isTop = getTopChild() == child; + + final Task task = child.asTask(); + if (task != null) { + task.updateTaskMovement(isTop); + } + + if (isTop) { + final DisplayContent displayContent = getDisplayContent(); + displayContent.layoutAndAssignWindowLayersIfNeeded(); + } + } + + void reparent(TaskDisplayArea newParent, boolean onTop) { + reparent(newParent, onTop ? POSITION_TOP : POSITION_BOTTOM); + } + + private void updateSurfaceBounds() { + updateSurfaceSize(getSyncTransaction()); + updateSurfacePosition(); + scheduleAnimation(); + } + + @Override + void getRelativePosition(Point outPos) { + super.getRelativePosition(outPos); + final int outset = getTaskOutset(); + outPos.x -= outset; + outPos.y -= outset; + } + + boolean shouldIgnoreInput() { + if (inSplitScreenPrimaryWindowingMode() && !isFocusable()) { + return true; + } + if (mAtmService.mHasLeanbackFeature && inPinnedWindowingMode() + && !isFocusedStackOnDisplay()) { + // Preventing Picture-in-Picture stack from receiving input on TVs. + return true; + } + return false; + } + + /** + * Sets the current picture-in-picture aspect ratio. + */ + void setPictureInPictureAspectRatio(float aspectRatio) { + if (!mWmService.mAtmService.mSupportsPictureInPicture) { + return; + } + + final DisplayContent displayContent = getDisplayContent(); + if (displayContent == null) { + return; + } + + if (!inPinnedWindowingMode()) { + return; + } + + final PinnedStackController pinnedStackController = + getDisplayContent().getPinnedStackController(); + + if (Float.compare(aspectRatio, pinnedStackController.getAspectRatio()) == 0) { + return; + } + + // Notify the pinned stack controller about aspect ratio change. + // This would result a callback delivered from SystemUI to WM to start animation, + // if the bounds are ought to be altered due to aspect ratio change. + pinnedStackController.setAspectRatio( + pinnedStackController.isValidPictureInPictureAspectRatio(aspectRatio) + ? aspectRatio : -1f); + } + + /** + * Sets the current picture-in-picture actions. + */ + void setPictureInPictureActions(List<RemoteAction> actions) { + if (!mWmService.mAtmService.mSupportsPictureInPicture) { + return; + } + + if (!inPinnedWindowingMode()) { + return; + } + + getDisplayContent().getPinnedStackController().setActions(actions); + } + + public boolean isForceScaled() { + return mBoundsAnimating; + } + + /** Returns true if a removal action is still being deferred. */ + boolean handleCompleteDeferredRemoval() { + if (isAnimating(TRANSITION | CHILDREN)) { + return true; + } + + return super.handleCompleteDeferredRemoval(); + } + + public DisplayInfo getDisplayInfo() { + return mDisplayContent.getDisplayInfo(); + } + + AnimatingActivityRegistry getAnimatingActivityRegistry() { + return mAnimatingActivityRegistry; + } + + void executeAppTransition(ActivityOptions options) { + getDisplay().mDisplayContent.executeAppTransition(); + ActivityOptions.abort(options); + } + + boolean shouldSleepActivities() { + final DisplayContent display = getDisplay(); + + // Do not sleep activities in this stack if we're marked as focused and the keyguard + // is in the process of going away. + if (isFocusedStackOnDisplay() + && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) { + return false; + } + + return display != null ? display.isSleeping() : mAtmService.isSleepingLocked(); + } + + boolean shouldSleepOrShutDownActivities() { + return shouldSleepActivities() || mAtmService.mShuttingDown; + } + + /** Bounds of the stack without adjusting for other factors in the system like visibility + * of docked stack. + * Most callers should be using {@link ConfigurationContainer#getRequestedOverrideBounds} a + * it takes into consideration other system factors. */ + void getRawBounds(Rect out) { + out.set(getRawBounds()); + } + + private Rect getRawBounds() { + return super.getBounds(); + } + + @Override + public void dumpDebug(ProtoOutputStream proto, long fieldId, + @WindowTraceLogLevel int logLevel) { + if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { + return; + } + + final long token = proto.start(fieldId); + super.dumpDebug(proto, WINDOW_CONTAINER, logLevel); + + proto.write(TaskProto.ID, mTaskId); + proto.write(DISPLAY_ID, getDisplayId()); + proto.write(ROOT_TASK_ID, getRootTaskId()); + + if (mResumedActivity != null) { + mResumedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); + } + if (realActivity != null) { + proto.write(REAL_ACTIVITY, realActivity.flattenToShortString()); + } + if (origActivity != null) { + proto.write(ORIG_ACTIVITY, origActivity.flattenToShortString()); + } + proto.write(ACTIVITY_TYPE, getActivityType()); + proto.write(RESIZE_MODE, mResizeMode); + proto.write(MIN_WIDTH, mMinWidth); + proto.write(MIN_HEIGHT, mMinHeight); + + proto.write(FILLS_PARENT, matchParentBounds()); + getRawBounds().dumpDebug(proto, BOUNDS); + + if (mLastNonFullscreenBounds != null) { + mLastNonFullscreenBounds.dumpDebug(proto, LAST_NON_FULLSCREEN_BOUNDS); + } + + proto.write(ANIMATING_BOUNDS, mBoundsAnimating); + + if (mSurfaceControl != null) { + proto.write(SURFACE_WIDTH, mSurfaceControl.getWidth()); + proto.write(SURFACE_HEIGHT, mSurfaceControl.getHeight()); + } + + proto.write(CREATED_BY_ORGANIZER, mCreatedByOrganizer); + + proto.end(token); + } } diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index aba5b99f7481..4473bd69681b 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -32,8 +32,6 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; import static com.android.server.wm.ActivityStackSupervisor.TAG_TASKS; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; @@ -42,6 +40,8 @@ import static com.android.server.wm.DisplayContent.alwaysCreateStack; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; import static com.android.server.wm.RootWindowContainer.TAG_STATES; +import static com.android.server.wm.Task.ActivityState.RESUMED; +import static com.android.server.wm.Task.STACK_VISIBILITY_VISIBLE; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; @@ -73,7 +73,7 @@ import java.util.function.Function; /** * {@link DisplayArea} that represents a section of a screen that contains app window containers. */ -final class TaskDisplayArea extends DisplayArea<ActivityStack> { +final class TaskDisplayArea extends DisplayArea<Task> { DisplayContent mDisplayContent; @@ -100,16 +100,16 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { // Cached reference to some special tasks we tend to get a lot so we don't need to loop // through the list to find them. - private ActivityStack mRootHomeTask; - private ActivityStack mRootPinnedTask; - private ActivityStack mRootSplitScreenPrimaryTask; + private Task mRootHomeTask; + private Task mRootPinnedTask; + private Task mRootSplitScreenPrimaryTask; // TODO(b/159029784): Remove when getStack() behavior is cleaned-up - private ActivityStack mRootRecentsTask; + private Task mRootRecentsTask; - private final ArrayList<ActivityStack> mTmpAlwaysOnTopStacks = new ArrayList<>(); - private final ArrayList<ActivityStack> mTmpNormalStacks = new ArrayList<>(); - private final ArrayList<ActivityStack> mTmpHomeStacks = new ArrayList<>(); + private final ArrayList<Task> mTmpAlwaysOnTopStacks = new ArrayList<>(); + private final ArrayList<Task> mTmpNormalStacks = new ArrayList<>(); + private final ArrayList<Task> mTmpHomeStacks = new ArrayList<>(); private final IntArray mTmpNeedsZBoostIndexes = new IntArray(); private int mTmpLayerForSplitScreenDividerAnchor; private int mTmpLayerForAnimationLayer; @@ -128,7 +128,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * have the topmost index, it is used as a preferred candidate to prevent being unable to resume * target stack properly when there are other focusable always-on-top stacks. */ - ActivityStack mPreferredTopFocusableStack; + Task mPreferredTopFocusableStack; private final RootWindowContainer.FindTaskResult mTmpFindTaskResult = new RootWindowContainer.FindTaskResult(); @@ -138,7 +138,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * stack has been resumed. If stacks are changing position this will hold the old stack until * the new stack becomes resumed after which it will be set to current focused stack. */ - ActivityStack mLastFocusedStack; + Task mLastFocusedStack; /** * All of the stacks on this display. Order matters, topmost stack is in front of all other * stacks, bottommost behind. Accessed directly by ActivityManager package classes. Any calls @@ -164,7 +164,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * Returns the topmost stack on the display that is compatible with the input windowing mode * and activity type. Null is no compatible stack on the display. */ - ActivityStack getStack(int windowingMode, int activityType) { + Task getStack(int windowingMode, int activityType) { if (activityType == ACTIVITY_TYPE_HOME) { return mRootHomeTask; } else if (activityType == ACTIVITY_TYPE_RECENTS) { @@ -176,7 +176,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return mRootSplitScreenPrimaryTask; } for (int i = getChildCount() - 1; i >= 0; --i) { - final ActivityStack stack = getChildAt(i); + final Task stack = getChildAt(i); if (activityType == ACTIVITY_TYPE_UNDEFINED && windowingMode == stack.getWindowingMode()) { // Passing in undefined type means we want to match the topmost stack with the @@ -191,33 +191,33 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } @VisibleForTesting - ActivityStack getTopStack() { + Task getTopStack() { final int count = getChildCount(); return count > 0 ? getChildAt(count - 1) : null; } // TODO: Figure-out a way to remove since it might be a source of confusion. - int getIndexOf(ActivityStack stack) { - return mChildren.indexOf(stack); + int getIndexOf(Task task) { + return mChildren.indexOf(task); } - @Nullable ActivityStack getRootHomeTask() { + @Nullable Task getRootHomeTask() { return mRootHomeTask; } - @Nullable ActivityStack getRootRecentsTask() { + @Nullable Task getRootRecentsTask() { return mRootRecentsTask; } - ActivityStack getRootPinnedTask() { + Task getRootPinnedTask() { return mRootPinnedTask; } - ActivityStack getRootSplitScreenPrimaryTask() { + Task getRootSplitScreenPrimaryTask() { return mRootSplitScreenPrimaryTask; } - ActivityStack getRootSplitScreenSecondaryTask() { + Task getRootSplitScreenSecondaryTask() { for (int i = mChildren.size() - 1; i >= 0; --i) { if (mChildren.get(i).inSplitScreenSecondaryWindowingMode()) { return mChildren.get(i); @@ -236,7 +236,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return visibleTasks; } - void onStackWindowingModeChanged(ActivityStack stack) { + void onStackWindowingModeChanged(Task stack) { removeStackReferenceIfNeeded(stack); addStackReferenceIfNeeded(stack); if (stack == mRootPinnedTask && getTopStack() != stack) { @@ -245,7 +245,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } } - void addStackReferenceIfNeeded(ActivityStack stack) { + void addStackReferenceIfNeeded(Task stack) { if (stack.isActivityTypeHome()) { if (mRootHomeTask != null) { if (!stack.isDescendantOf(mRootHomeTask)) { @@ -290,7 +290,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } } - void removeStackReferenceIfNeeded(ActivityStack stack) { + void removeStackReferenceIfNeeded(Task stack) { if (stack == mRootHomeTask) { mRootHomeTask = null; } else if (stack == mRootRecentsTask) { @@ -303,7 +303,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } @Override - void addChild(ActivityStack stack, int position) { + void addChild(Task stack, int position) { if (DEBUG_STACK) Slog.d(TAG_WM, "Set stack=" + stack + " on taskDisplayArea=" + this); addStackReferenceIfNeeded(stack); position = findPositionForStack(position, stack, true /* adding */); @@ -315,7 +315,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } @Override - protected void removeChild(ActivityStack stack) { + protected void removeChild(Task stack) { super.removeChild(stack); onStackRemoved(stack); mAtmService.updateSleepIfNeededLocked(); @@ -329,7 +329,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } @Override - void positionChildAt(int position, ActivityStack child, boolean includingParents) { + void positionChildAt(int position, Task child, boolean includingParents) { final boolean moveToTop = position >= getChildCount() - 1; final boolean moveToBottom = position <= 0; @@ -408,7 +408,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * * @return the priority of the stack */ - private int getPriority(ActivityStack stack) { + private int getPriority(Task stack) { if (mWmService.mAssistantOnTopOfDream && stack.isActivityTypeAssistant()) return 4; if (stack.isActivityTypeDream()) return 3; if (stack.inPinnedWindowingMode()) return 2; @@ -416,7 +416,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return 0; } - private int findMinPositionForStack(ActivityStack stack) { + private int findMinPositionForStack(Task stack) { int minPosition = POSITION_BOTTOM; for (int i = 0; i < mChildren.size(); ++i) { if (getPriority(getStackAt(i)) < getPriority(stack)) { @@ -438,9 +438,9 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return minPosition; } - private int findMaxPositionForStack(ActivityStack stack) { + private int findMaxPositionForStack(Task stack) { for (int i = mChildren.size() - 1; i >= 0; --i) { - final ActivityStack curr = getStackAt(i); + final Task curr = getStackAt(i); // Since a stack could be repositioned while still being one of the children, we check // if 'curr' is the same stack and skip it if so final boolean sameStack = curr == stack; @@ -470,7 +470,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * @param adding Flag indicates whether we're adding a new stack or positioning an existing. * @return The proper position for the stack. */ - private int findPositionForStack(int requestedPosition, ActivityStack stack, boolean adding) { + private int findPositionForStack(int requestedPosition, Task stack, boolean adding) { // The max possible position we can insert the stack at. int maxPosition = findMaxPositionForStack(stack); // The min possible position we can insert the stack at. @@ -632,7 +632,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { assignStackOrdering(t); for (int i = 0; i < mChildren.size(); i++) { - final ActivityStack s = mChildren.get(i); + final Task s = mChildren.get(i); s.assignChildLayers(t); } } @@ -645,7 +645,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { mTmpHomeStacks.clear(); mTmpNormalStacks.clear(); for (int i = 0; i < mChildren.size(); ++i) { - final ActivityStack s = mChildren.get(i); + final Task s = mChildren.get(i); if (s.isAlwaysOnTop()) { mTmpAlwaysOnTopStacks.add(s); } else if (s.isActivityTypeHome()) { @@ -675,7 +675,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer); } - private int adjustNormalStackLayer(ActivityStack s, int layer) { + private int adjustNormalStackLayer(Task s, int layer) { if (s.inSplitScreenWindowingMode()) { // The split screen divider anchor is located above the split screen window. mTmpLayerForSplitScreenDividerAnchor = layer++; @@ -696,12 +696,12 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * @param normalStacks Set {@code true} if this group is neither home nor always on top. * @return The adjusted layer value. */ - private int adjustRootTaskLayer(SurfaceControl.Transaction t, ArrayList<ActivityStack> stacks, + private int adjustRootTaskLayer(SurfaceControl.Transaction t, ArrayList<Task> stacks, int startLayer, boolean normalStacks) { mTmpNeedsZBoostIndexes.clear(); final int stackSize = stacks.size(); for (int i = 0; i < stackSize; i++) { - final ActivityStack stack = stacks.get(i); + final Task stack = stacks.get(i); if (!stack.needsZBoost()) { stack.assignLayer(t, startLayer++); if (normalStacks) { @@ -714,7 +714,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { final int zBoostSize = mTmpNeedsZBoostIndexes.size(); for (int i = 0; i < zBoostSize; i++) { - final ActivityStack stack = stacks.get(mTmpNeedsZBoostIndexes.get(i)); + final Task stack = stacks.get(mTmpNeedsZBoostIndexes.get(i)); stack.assignLayer(t, startLayer++); if (normalStacks) { startLayer = adjustNormalStackLayer(stack, startLayer); @@ -781,7 +781,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } } - void onStackRemoved(ActivityStack stack) { + void onStackRemoved(Task stack) { if (ActivityTaskManagerDebugConfig.DEBUG_STACK) { Slog.v(TAG_STACK, "removeStack: detaching " + stack + " from displayId=" + mDisplayContent.mDisplayId); @@ -800,40 +800,40 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } } - void positionStackAt(int position, ActivityStack child, boolean includingParents) { + void positionStackAt(int position, Task child, boolean includingParents) { positionChildAt(position, child, includingParents); mDisplayContent.layoutAndAssignWindowLayersIfNeeded(); } - void positionStackAtTop(ActivityStack stack, boolean includingParents) { + void positionStackAtTop(Task stack, boolean includingParents) { positionStackAtTop(stack, includingParents, null /* updateLastFocusedStackReason */); } - void positionStackAtTop(ActivityStack stack, boolean includingParents, + void positionStackAtTop(Task stack, boolean includingParents, String updateLastFocusedStackReason) { positionStackAt(stack, getStackCount(), includingParents, updateLastFocusedStackReason); } - void positionStackAtBottom(ActivityStack stack) { + void positionStackAtBottom(Task stack) { positionStackAtBottom(stack, null /* updateLastFocusedStackReason */); } - void positionStackAtBottom(ActivityStack stack, String updateLastFocusedStackReason) { + void positionStackAtBottom(Task stack, String updateLastFocusedStackReason) { positionStackAt(stack, 0, false /* includingParents */, updateLastFocusedStackReason); } - void positionStackAt(ActivityStack stack, int position) { + void positionStackAt(Task stack, int position) { positionStackAt(stack, position, false /* includingParents */, null /* updateLastFocusedStackReason */); } - void positionStackAt(ActivityStack stack, int position, boolean includingParents, + void positionStackAt(Task stack, int position, boolean includingParents, String updateLastFocusedStackReason) { // TODO: Keep in sync with WindowContainer.positionChildAt(), once we change that to adjust // the position internally, also update the logic here - final ActivityStack prevFocusedStack = updateLastFocusedStackReason != null + final Task prevFocusedStack = updateLastFocusedStackReason != null ? getFocusedStack() : null; final boolean wasContained = mChildren.contains(stack); if (mDisplayContent.mSingleTaskInstance && getStackCount() == 1 && !wasContained) { @@ -846,7 +846,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { positionStackAt(position, stack, includingParents); if (updateLastFocusedStackReason != null) { - final ActivityStack currentFocusedStack = getFocusedStack(); + final Task currentFocusedStack = getFocusedStack(); if (currentFocusedStack != prevFocusedStack) { mLastFocusedStack = prevFocusedStack; EventLogTags.writeWmFocusedStack(mRootWindowContainer.mCurrentUser, @@ -865,8 +865,8 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * when we just want to move a task to "the back" vs. a specific place. The primary use-case * is to make sure that moved-to-back apps go into secondary split when in split-screen mode. */ - void positionTaskBehindHome(ActivityStack task) { - final ActivityStack home = getOrCreateRootHomeTask(); + void positionTaskBehindHome(Task task) { + final Task home = getOrCreateRootHomeTask(); final WindowContainer homeParent = home.getParent(); final Task homeParentTask = homeParent != null ? homeParent.asTask() : null; if (homeParentTask == null) { @@ -878,17 +878,17 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } } else if (homeParentTask == task.getParent()) { // Apparently reparent early-outs if same stack, so we have to explicitly reorder. - ((ActivityStack) homeParentTask).positionChildAtBottom(task); + homeParentTask.positionChildAtBottom(task); } else { - task.reparent((ActivityStack) homeParentTask, false /* toTop */, + task.reparent(homeParentTask, false /* toTop */, Task.REPARENT_LEAVE_STACK_IN_PLACE, false /* animate */, false /* deferResume */, "positionTaskBehindHome"); } } - ActivityStack getStack(int rootTaskId) { + Task getStack(int rootTaskId) { for (int i = getStackCount() - 1; i >= 0; --i) { - final ActivityStack stack = getStackAt(i); + final Task stack = getStackAt(i); if (stack.getRootTaskId() == rootTaskId) { return stack; } @@ -901,7 +901,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * if a compatible stack doesn't exist. * @see #getOrCreateStack(int, int, boolean, Intent, Task) */ - ActivityStack getOrCreateStack(int windowingMode, int activityType, boolean onTop) { + Task getOrCreateStack(int windowingMode, int activityType, boolean onTop) { return getOrCreateStack(windowingMode, activityType, onTop, null /* intent */, null /* candidateTask */); } @@ -914,19 +914,19 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * @see #getStack(int, int) * @see #createStack(int, int, boolean) */ - ActivityStack getOrCreateStack(int windowingMode, int activityType, boolean onTop, + Task getOrCreateStack(int windowingMode, int activityType, boolean onTop, Intent intent, Task candidateTask) { // Need to pass in a determined windowing mode to see if a new stack should be created, // so use its parent's windowing mode if it is undefined. if (!alwaysCreateStack( windowingMode != WINDOWING_MODE_UNDEFINED ? windowingMode : getWindowingMode(), activityType)) { - ActivityStack stack = getStack(windowingMode, activityType); + Task stack = getStack(windowingMode, activityType); if (stack != null) { return stack; } } else if (candidateTask != null) { - final ActivityStack stack = (ActivityStack) candidateTask; + final Task stack = candidateTask; final int position = onTop ? POSITION_TOP : POSITION_BOTTOM; Task launchRootTask = updateLaunchRootTask(windowingMode); @@ -958,7 +958,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * if a compatible stack doesn't exist. * @see #getOrCreateStack(int, int, boolean) */ - ActivityStack getOrCreateStack(@Nullable ActivityRecord r, + Task getOrCreateStack(@Nullable ActivityRecord r, @Nullable ActivityOptions options, @Nullable Task candidateTask, int activityType, boolean onTop) { // First preference is the windowing mode in the activity options if set. @@ -977,7 +977,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return mAtmService.mStackSupervisor.getNextTaskIdForUser(); } - ActivityStack createStack(int windowingMode, int activityType, boolean onTop) { + Task createStack(int windowingMode, int activityType, boolean onTop) { return createStack(windowingMode, activityType, onTop, null /* info */, null /* intent */, false /* createdByOrganizer */); } @@ -997,7 +997,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * otherwise. * @return The newly created stack. */ - ActivityStack createStack(int windowingMode, int activityType, boolean onTop, ActivityInfo info, + Task createStack(int windowingMode, int activityType, boolean onTop, ActivityInfo info, Intent intent, boolean createdByOrganizer) { if (mDisplayContent.mSingleTaskInstance && getStackCount() > 0) { // Create stack on default display instead since this display can only contain 1 stack. @@ -1016,7 +1016,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { if (activityType != ACTIVITY_TYPE_STANDARD && activityType != ACTIVITY_TYPE_UNDEFINED) { // For now there can be only one stack of a particular non-standard activity type on a // display. So, get that ignoring whatever windowing mode it is currently in. - ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); + Task stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); if (stack != null) { throw new IllegalArgumentException("Stack=" + stack + " of activityType=" + activityType + " already on display=" + this + ". Can't have multiple."); @@ -1068,7 +1068,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } @VisibleForTesting - ActivityStack createStackUnchecked(int windowingMode, int activityType, int stackId, + Task createStackUnchecked(int windowingMode, int activityType, int stackId, boolean onTop, ActivityInfo info, Intent intent, boolean createdByOrganizer) { if (windowingMode == WINDOWING_MODE_PINNED && activityType != ACTIVITY_TYPE_STANDARD) { throw new IllegalArgumentException("Stack with windowing mode cannot with non standard " @@ -1086,12 +1086,12 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { windowingMode = WINDOWING_MODE_UNDEFINED; } - final ActivityStack stack = new ActivityStack(mAtmService, stackId, activityType, + final Task stack = new Task(mAtmService, stackId, activityType, info, intent, createdByOrganizer); if (launchRootTask != null) { launchRootTask.addChild(stack, onTop ? POSITION_TOP : POSITION_BOTTOM); if (onTop) { - positionStackAtTop((ActivityStack) launchRootTask, false /* includingParents */); + positionStackAtTop(launchRootTask, false /* includingParents */); } } else { addChild(stack, onTop ? POSITION_TOP : POSITION_BOTTOM); @@ -1104,13 +1104,13 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * Get the preferred focusable stack in priority. If the preferred stack does not exist, find a * focusable and visible stack from the top of stacks in this display. */ - ActivityStack getFocusedStack() { + Task getFocusedStack() { if (mPreferredTopFocusableStack != null) { return mPreferredTopFocusableStack; } for (int i = getStackCount() - 1; i >= 0; --i) { - final ActivityStack stack = getStackAt(i); + final Task stack = getStackAt(i); if (stack.isFocusableAndVisible()) { return stack; } @@ -1119,13 +1119,13 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return null; } - ActivityStack getNextFocusableStack(ActivityStack currentFocus, boolean ignoreCurrent) { + Task getNextFocusableStack(Task currentFocus, boolean ignoreCurrent) { final int currentWindowingMode = currentFocus != null ? currentFocus.getWindowingMode() : WINDOWING_MODE_UNDEFINED; - ActivityStack candidate = null; + Task candidate = null; for (int i = getStackCount() - 1; i >= 0; --i) { - final ActivityStack stack = getStackAt(i); + final Task stack = getStackAt(i); if (ignoreCurrent && stack == currentFocus) { continue; } @@ -1155,7 +1155,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { } ActivityRecord getFocusedActivity() { - final ActivityStack focusedStack = getFocusedStack(); + final Task focusedStack = getFocusedStack(); if (focusedStack == null) { return null; } @@ -1175,7 +1175,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return resumedActivity; } - ActivityStack getLastFocusedStack() { + Task getLastFocusedStack() { return mLastFocusedStack; } @@ -1186,7 +1186,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return false; } } - final ActivityStack currentFocusedStack = getFocusedStack(); + final Task currentFocusedStack = getFocusedStack(); if (ActivityTaskManagerDebugConfig.DEBUG_STACK) { Slog.d(TAG_STACK, "allResumedActivitiesComplete: mLastFocusedStack changing from=" + mLastFocusedStack + " to=" + currentFocusedStack); @@ -1208,7 +1208,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming) { boolean someActivityPaused = false; for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { - final ActivityStack stack = getStackAt(stackNdx); + final Task stack = getStackAt(stackNdx); final ActivityRecord resumedActivity = stack.getResumedActivity(); if (resumedActivity != null && (stack.getVisibility(resuming) != STACK_VISIBILITY_VISIBLE @@ -1231,7 +1231,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { RootWindowContainer.FindTaskResult result) { mTmpFindTaskResult.clear(); for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { - final ActivityStack stack = getStackAt(stackNdx); + final Task stack = getStackAt(stackNdx); if (!r.hasCompatibleActivityType(stack) && stack.isLeafTask()) { if (DEBUG_TASKS) { Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " + stack); @@ -1271,11 +1271,11 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { // Collect the stacks that are necessary to be removed instead of performing the removal // by looping mStacks, so that we don't miss any stacks after the stack size changed or // stacks reordered. - final ArrayList<ActivityStack> stacks = new ArrayList<>(); + final ArrayList<Task> stacks = new ArrayList<>(); for (int j = windowingModes.length - 1; j >= 0; --j) { final int windowingMode = windowingModes[j]; for (int i = getStackCount() - 1; i >= 0; --i) { - final ActivityStack stack = getStackAt(i); + final Task stack = getStackAt(i); if (!stack.isActivityTypeStandardOrUndefined()) { continue; } @@ -1299,15 +1299,15 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { // Collect the stacks that are necessary to be removed instead of performing the removal // by looping mStacks, so that we don't miss any stacks after the stack size changed or // stacks reordered. - final ArrayList<ActivityStack> stacks = new ArrayList<>(); + final ArrayList<Task> stacks = new ArrayList<>(); for (int j = activityTypes.length - 1; j >= 0; --j) { final int activityType = activityTypes[j]; for (int i = getStackCount() - 1; i >= 0; --i) { - final ActivityStack stack = getStackAt(i); + final Task stack = getStackAt(i); // Collect the root tasks that are currently being organized. if (stack.mCreatedByOrganizer) { for (int k = stack.getChildCount() - 1; k >= 0; --k) { - final ActivityStack childStack = (ActivityStack) stack.getChildAt(k); + final Task childStack = (Task) stack.getChildAt(k); if (childStack.getActivityType() == activityType) { stacks.add(childStack); } @@ -1327,15 +1327,15 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { onSplitScreenModeDismissed(null /* toTop */); } - void onSplitScreenModeDismissed(ActivityStack toTop) { + void onSplitScreenModeDismissed(Task toTop) { mAtmService.deferWindowLayout(); try { mLaunchRootTask = null; moveSplitScreenTasksToFullScreen(); } finally { - final ActivityStack topFullscreenStack = toTop != null + final Task topFullscreenStack = toTop != null ? toTop : getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); - final ActivityStack homeStack = getOrCreateRootHomeTask(); + final Task homeStack = getOrCreateRootHomeTask(); if (homeStack != null && ((topFullscreenStack != null && !isTopStack(homeStack)) || toTop != null)) { // Whenever split-screen is dismissed we want the home stack directly behind the @@ -1509,13 +1509,13 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return windowingMode; } - boolean isTopStack(ActivityStack stack) { + boolean isTopStack(Task stack) { return stack == getTopStack(); } - boolean isTopNotPinnedStack(ActivityStack stack) { + boolean isTopNotPinnedStack(Task stack) { for (int i = getStackCount() - 1; i >= 0; --i) { - final ActivityStack current = getStackAt(i); + final Task current = getStackAt(i); if (!current.inPinnedWindowingMode()) { return current == stack; } @@ -1538,7 +1538,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { */ ActivityRecord topRunningActivity(boolean considerKeyguardState) { ActivityRecord topRunning = null; - final ActivityStack focusedStack = getFocusedStack(); + final Task focusedStack = getFocusedStack(); if (focusedStack != null) { topRunning = focusedStack.topRunningActivity(); } @@ -1546,7 +1546,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { // Look in other focusable stacks. if (topRunning == null) { for (int i = getStackCount() - 1; i >= 0; --i) { - final ActivityStack stack = getStackAt(i); + final Task stack = getStackAt(i); // Only consider focusable stacks other than the current focused one. if (stack == focusedStack || !stack.isTopActivityFocusable()) { continue; @@ -1574,12 +1574,12 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { return mChildren.size(); } - protected ActivityStack getStackAt(int index) { + protected Task getStackAt(int index) { return mChildren.get(index); } @Nullable - ActivityStack getOrCreateRootHomeTask() { + Task getOrCreateRootHomeTask() { return getOrCreateRootHomeTask(false /* onTop */); } @@ -1590,8 +1590,8 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * be created at the top of the display, else at the bottom. */ @Nullable - ActivityStack getOrCreateRootHomeTask(boolean onTop) { - ActivityStack homeTask = getRootHomeTask(); + Task getOrCreateRootHomeTask(boolean onTop) { + Task homeTask = getRootHomeTask(); if (homeTask == null && mDisplayContent.supportsSystemDecorations()) { homeTask = createStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, onTop); } @@ -1607,12 +1607,12 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * Returns the topmost stack on the display that is compatible with the input windowing mode. * Null is no compatible stack on the display. */ - ActivityStack getTopStackInWindowingMode(int windowingMode) { + Task getTopStackInWindowingMode(int windowingMode) { return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED); } void moveHomeStackToFront(String reason) { - final ActivityStack homeStack = getOrCreateRootHomeTask(); + final Task homeStack = getOrCreateRootHomeTask(); if (homeStack != null) { homeStack.moveToFront(reason); } @@ -1638,7 +1638,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { @Nullable ActivityRecord getHomeActivityForUser(int userId) { - final ActivityStack homeStack = getRootHomeTask(); + final Task homeStack = getRootHomeTask(); if (homeStack == null) { return null; } @@ -1660,7 +1660,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * Generally used in conjunction with {@link #moveStackBehindStack}. */ // TODO(b/151575894): Remove special stack movement methods. - void moveStackBehindBottomMostVisibleStack(ActivityStack stack) { + void moveStackBehindBottomMostVisibleStack(Task stack) { if (stack.shouldBeVisible(null)) { // Skip if the stack is already visible return; @@ -1677,8 +1677,8 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { // Find the next position where the stack should be placed final int numStacks = isRootTask ? getStackCount() : stack.getParent().getChildCount(); for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { - final ActivityStack s = isRootTask ? getStackAt(stackNdx) - : (ActivityStack) stack.getParent().getChildAt(stackNdx); + final Task s = isRootTask ? getStackAt(stackNdx) + : (Task) stack.getParent().getChildAt(stackNdx); if (s == stack) { continue; } @@ -1703,7 +1703,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * {@param behindStack} is not currently in the display, then then the stack is moved to the * back. Generally used in conjunction with {@link #moveStackBehindBottomMostVisibleStack}. */ - void moveStackBehindStack(ActivityStack stack, ActivityStack behindStack) { + void moveStackBehindStack(Task stack, Task behindStack) { if (behindStack == null || behindStack == stack) { return; } @@ -1737,19 +1737,19 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * @return the stack currently above the {@param stack}. Can be null if the {@param stack} is * already top-most. */ - static ActivityStack getStackAbove(ActivityStack stack) { + static Task getStackAbove(Task stack) { final WindowContainer wc = stack.getParent(); final int index = wc.mChildren.indexOf(stack) + 1; - return (index < wc.mChildren.size()) ? (ActivityStack) wc.mChildren.get(index) : null; + return (index < wc.mChildren.size()) ? (Task) wc.mChildren.get(index) : null; } /** Returns true if the stack in the windowing mode is visible. */ boolean isStackVisible(int windowingMode) { - final ActivityStack stack = getTopStackInWindowingMode(windowingMode); + final Task stack = getTopStackInWindowingMode(windowingMode); return stack != null && stack.isVisible(); } - void removeStack(ActivityStack stack) { + void removeStack(Task stack) { removeChild(stack); } @@ -1783,7 +1783,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * Notifies of a stack order change * @param stack The stack which triggered the order change */ - void onStackOrderChanged(ActivityStack stack) { + void onStackOrderChanged(Task stack) { for (int i = mStackOrderChangedCallbacks.size() - 1; i >= 0; i--) { mStackOrderChangedCallbacks.get(i).onStackOrderChanged(stack); } @@ -1798,7 +1798,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * Callback for when the order of the stacks in the display changes. */ interface OnStackOrderChangedListener { - void onStackOrderChanged(ActivityStack stack); + void onStackOrderChanged(Task stack); } void ensureActivitiesVisible(ActivityRecord starting, int configChanges, @@ -1806,7 +1806,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { mAtmService.mStackSupervisor.beginActivityVisibilityUpdate(); try { for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { - final ActivityStack stack = getStackAt(stackNdx); + final Task stack = getStackAt(stackNdx); stack.ensureActivitiesVisible(starting, configChanges, preserveWindows, notifyClients); } @@ -1817,7 +1817,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { void prepareFreezingTaskBounds() { for (int stackNdx = getChildCount() - 1; stackNdx >= 0; --stackNdx) { - final ActivityStack stack = getChildAt(stackNdx); + final Task stack = getChildAt(stackNdx); stack.prepareFreezingTaskBounds(); } } @@ -1826,12 +1826,12 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { * Removes the stacks in the node applying the content removal node from the display. * @return last reparented stack, or {@code null} if the stacks had to be destroyed. */ - ActivityStack remove() { + Task remove() { mPreferredTopFocusableStack = null; // TODO(b/153090332): Allow setting content removal mode per task display area final boolean destroyContentOnRemoval = mDisplayContent.shouldDestroyContentOnRemove(); final TaskDisplayArea toDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack lastReparentedStack = null; + Task lastReparentedStack = null; // Stacks could be reparented from the removed display area to other display area. After // reparenting the last stack of the removed display area, the display area becomes ready to @@ -1842,10 +1842,10 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { int numStacks = getStackCount(); final boolean splitScreenActivated = toDisplayArea.isSplitScreenModeActivated(); - final ActivityStack rootStack = splitScreenActivated ? toDisplayArea + final Task rootStack = splitScreenActivated ? toDisplayArea .getTopStackInWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) : null; for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { - final ActivityStack stack = getStackAt(stackNdx); + final Task stack = getStackAt(stackNdx); // Always finish non-standard type stacks. if (destroyContentOnRemoval || !stack.isActivityTypeStandardOrUndefined()) { stack.finishAllActivitiesImmediately(); @@ -1895,7 +1895,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> { final String triplePrefix = doublePrefix + " "; pw.println(doublePrefix + "Application tokens in top down Z order:"); for (int stackNdx = getChildCount() - 1; stackNdx >= 0; --stackNdx) { - final ActivityStack stack = getChildAt(stackNdx); + final Task stack = getChildAt(stackNdx); pw.println(doublePrefix + "* " + stack); stack.dump(pw, triplePrefix, dumpAll); } diff --git a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java index 00ddf82d2ba3..9a818ce80872 100644 --- a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java +++ b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java @@ -341,8 +341,8 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier { } } - ActivityStack stack = (taskDisplayArea == null && task != null) - ? task.getStack() : null; + Task stack = (taskDisplayArea == null && task != null) + ? task.getRootTask() : null; if (stack != null) { if (DEBUG) appendLog("display-from-task=" + stack.getDisplayId()); taskDisplayArea = stack.getDisplayArea(); @@ -744,13 +744,13 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier { display.forAllTaskDisplayAreas(taskDisplayArea -> { int numStacks = taskDisplayArea.getStackCount(); for (int sNdx = 0; sNdx < numStacks; ++sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); - if (!stack.inFreeformWindowingMode()) { + final Task task = taskDisplayArea.getStackAt(sNdx); + if (!task.inFreeformWindowingMode()) { continue; } - for (int j = 0; j < stack.getChildCount(); ++j) { - taskBoundsToCheck.add(stack.getChildAt(j).getBounds()); + for (int j = 0; j < task.getChildCount(); ++j) { + taskBoundsToCheck.add(task.getChildAt(j).getBounds()); } } }, false /* traverseTopToBottom */); diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index f1e965ba7a14..d0785ff9a9ac 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -112,16 +112,16 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowContainer" : TAG_WM; - /** Animation layer that happens above all animating {@link ActivityStack}s. */ + /** Animation layer that happens above all animating {@link Task}s. */ static final int ANIMATION_LAYER_STANDARD = 0; - /** Animation layer that happens above all {@link ActivityStack}s. */ + /** Animation layer that happens above all {@link Task}s. */ static final int ANIMATION_LAYER_BOOSTED = 1; /** * Animation layer that is reserved for {@link WindowConfiguration#ACTIVITY_TYPE_HOME} * activities and all activities that are being controlled by the recents animation. This - * layer is generally below all {@link ActivityStack}s. + * layer is generally below all {@link Task}s. */ static final int ANIMATION_LAYER_HOME = 2; @@ -190,7 +190,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< /** * Sources which triggered a surface animation on this container. An animation target can be * promoted to higher level, for example, from a set of {@link ActivityRecord}s to - * {@link ActivityStack}. In this case, {@link ActivityRecord}s are set on this variable while + * {@link Task}. In this case, {@link ActivityRecord}s are set on this variable while * the animation is running, and reset after finishing it. */ private final ArraySet<WindowContainer> mSurfaceAnimationSources = new ArraySet<>(); diff --git a/services/core/java/com/android/server/wm/WindowFrames.java b/services/core/java/com/android/server/wm/WindowFrames.java index 97186b4e9cda..d96b6457f9db 100644 --- a/services/core/java/com/android/server/wm/WindowFrames.java +++ b/services/core/java/com/android/server/wm/WindowFrames.java @@ -57,7 +57,7 @@ public class WindowFrames { public final Rect mParentFrame = new Rect(); /** - * The entire screen area of the {@link ActivityStack} this window is in. Usually equal to the + * The entire screen area of the {@link Task} this window is in. Usually equal to the * screen area of the device. * * TODO(b/111611553): The name is unclear and most likely should be swapped with diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index aa691fc1ae6b..7d15587919e1 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1945,7 +1945,7 @@ public class WindowManagerService extends IWindowManager.Stub // re-factor. activity.firstWindowDrawn = false; activity.clearAllDrawn(); - final ActivityStack stack = activity.getStack(); + final Task stack = activity.getStack(); if (stack != null) { stack.mExitingActivities.remove(activity); } @@ -2863,7 +2863,7 @@ public class WindowManagerService extends IWindowManager.Stub } void getStackBounds(int windowingMode, int activityType, Rect bounds) { - final ActivityStack stack = mRoot.getStack(windowingMode, activityType); + final Task stack = mRoot.getStack(windowingMode, activityType); if (stack != null) { stack.getBounds(bounds); return; @@ -4587,7 +4587,7 @@ public class WindowManagerService extends IWindowManager.Stub return mRoot.getTopFocusedDisplayContent().mCurrentFocus; } - ActivityStack getImeFocusStackLocked() { + Task getImeFocusStackLocked() { // Don't use mCurrentFocus.getStack() because it returns home stack for system windows. // Also don't use mInputMethodTarget's stack, because some window with FLAG_NOT_FOCUSABLE // and FLAG_ALT_FOCUSABLE_IM flags both set might be set to IME target so they're moved @@ -4596,7 +4596,7 @@ public class WindowManagerService extends IWindowManager.Stub final DisplayContent topFocusedDisplay = mRoot.getTopFocusedDisplayContent(); final ActivityRecord focusedApp = topFocusedDisplay.mFocusedApp; return (focusedApp != null && focusedApp.getTask() != null) - ? focusedApp.getTask().getStack() : null; + ? focusedApp.getTask().getRootTask() : null; } public boolean detectSafeMode() { diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java index 24ad85356477..8912d584213e 100644 --- a/services/core/java/com/android/server/wm/WindowOrganizerController.java +++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java @@ -317,7 +317,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub Slog.w(TAG, "Container is no longer attached: " + task); return 0; } - final ActivityStack as = (ActivityStack) task; + final Task as = task; if (hop.isReparent()) { final boolean isNonOrganizedRootableTask = @@ -337,12 +337,12 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub + " multi-window mode... newParent=" + newParent + " task=" + task); return 0; } else { - task.reparent((ActivityStack) newParent, + task.reparent((Task) newParent, hop.getToTop() ? POSITION_TOP : POSITION_BOTTOM, false /*moveParents*/, "sanitizeAndApplyHierarchyOp"); } } else { - final ActivityStack rootTask = (ActivityStack) ( + final Task rootTask = (Task) ( (newParent != null && !(newParent instanceof TaskDisplayArea)) ? newParent : task.getRootTask()); if (hop.getToTop()) { @@ -395,10 +395,10 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub private void resizePinnedStackIfNeeded(ConfigurationContainer container, int configMask, int windowMask, Configuration config) { - if ((container instanceof ActivityStack) + if ((container instanceof Task) && ((configMask & ActivityInfo.CONFIG_WINDOW_CONFIGURATION) != 0) && ((windowMask & WindowConfiguration.WINDOW_CONFIG_BOUNDS) != 0)) { - final ActivityStack stack = (ActivityStack) container; + final Task stack = (Task) container; if (stack.inPinnedWindowingMode()) { stack.resize(config.windowConfiguration.getBounds(), PRESERVE_WINDOWS, true /* deferResume */); diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java index 29cf1776df9c..9a48154c7770 100644 --- a/services/core/java/com/android/server/wm/WindowProcessController.java +++ b/services/core/java/com/android/server/wm/WindowProcessController.java @@ -22,13 +22,6 @@ import static android.os.Build.VERSION_CODES.Q; import static android.view.Display.INVALID_DISPLAY; import static com.android.server.am.ActivityManagerService.MY_PID; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.ActivityState.STARTED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ACTIVITY_STARTS; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RELEASE; @@ -40,6 +33,13 @@ import static com.android.server.wm.ActivityTaskManagerService.ACTIVITY_BG_START import static com.android.server.wm.ActivityTaskManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS; import static com.android.server.wm.ActivityTaskManagerService.KEY_DISPATCHING_TIMEOUT_MS; import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE; +import static com.android.server.wm.Task.ActivityState.DESTROYED; +import static com.android.server.wm.Task.ActivityState.DESTROYING; +import static com.android.server.wm.Task.ActivityState.PAUSED; +import static com.android.server.wm.Task.ActivityState.PAUSING; +import static com.android.server.wm.Task.ActivityState.RESUMED; +import static com.android.server.wm.Task.ActivityState.STARTED; +import static com.android.server.wm.Task.ActivityState.STOPPING; import android.Manifest; import android.annotation.NonNull; @@ -690,7 +690,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio if (canUpdate) { // Make sure the previous top activity in the process no longer be resumed. if (mPreQTopResumedActivity != null && mPreQTopResumedActivity.isState(RESUMED)) { - final ActivityStack stack = mPreQTopResumedActivity.getRootTask(); + final Task stack = mPreQTopResumedActivity.getRootTask(); if (stack != null) { stack.startPausingLocked(false /* userLeaving */, false /* uiSleeping */, activity); @@ -924,7 +924,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio // Since there could be more than one activities in a process record, we don't need to // compute the OomAdj with each of them, just need to find out the activity with the // "best" state, the order would be visible, pausing, stopping... - ActivityStack.ActivityState best = DESTROYED; + Task.ActivityState best = DESTROYED; boolean finishing = true; boolean visible = false; synchronized (mAtm.mGlobalLockWithoutBoost) { diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index fd4fdfccdea8..1cbc95090bfd 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -1566,10 +1566,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP return mActivityRecord != null ? mActivityRecord.getTask() : null; } - @Nullable ActivityStack getRootTask() { + @Nullable Task getRootTask() { final Task task = getTask(); if (task != null) { - return (ActivityStack) task.getRootTask(); + return task.getRootTask(); } // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still // associate them with some stack to enable dimming. @@ -1611,7 +1611,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP bounds.setEmpty(); mTmpRect.setEmpty(); if (intersectWithStackBounds) { - final ActivityStack stack = task.getStack(); + final Task stack = task.getRootTask(); if (stack != null) { stack.getDimBounds(mTmpRect); } else { @@ -1622,7 +1622,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP // the secondary split, it means this is "minimized" and thus must prevent // overlapping with home. // TODO(b/158242495): get rid of this when drag/drop can use surface bounds. - final ActivityStack rootSecondary = + final Task rootSecondary = task.getDisplayArea().getRootSplitScreenSecondaryTask(); if (rootSecondary.isActivityTypeHome() || rootSecondary.isActivityTypeRecents()) { final WindowContainer topTask = rootSecondary.getTopChild(); @@ -2107,7 +2107,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP boolean isObscuringDisplay() { Task task = getTask(); - if (task != null && task.getStack() != null && !task.getStack().fillsParent()) { + if (task != null && task.getRootTask() != null && !task.getRootTask().fillsParent()) { return false; } return isOpaqueDrawn() && fillsDisplay(); @@ -2418,7 +2418,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP return false; } - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack != null && !stack.isFocusable()) { // Ignore when the stack shouldn't receive input event. // (i.e. the minimized stack in split screen mode.) @@ -2919,7 +2919,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP return false; } - return mActivityRecord.getTask().getStack().shouldIgnoreInput() + return mActivityRecord.getTask().getRootTask().shouldIgnoreInput() || !mActivityRecord.mVisibleRequested || isRecentsAnimationConsumingAppInput(); } @@ -3489,7 +3489,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP return; } - final ActivityStack stack = task.getStack(); + final Task stack = task.getRootTask(); if (stack == null || inFreeformWindowingMode()) { handle.setTouchableRegionCrop(null); return; @@ -3504,7 +3504,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP return; } - final ActivityStack stack = task.getStack(); + final Task stack = task.getRootTask(); if (stack == null || stack.mCreatedByOrganizer) { return; } @@ -3748,7 +3748,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP } private int getRootTaskId() { - final ActivityStack stack = getRootTask(); + final Task stack = getRootTask(); if (stack == null) { return INVALID_TASK_ID; } @@ -5451,7 +5451,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP outPoint.offset(-parentBounds.left, -parentBounds.top); } - ActivityStack stack = getRootTask(); + Task stack = getRootTask(); // If we have stack outsets, that means the top-left // will be outset, and we need to inset ourselves diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index da45300ed318..77fee851889e 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -924,15 +924,15 @@ class WindowStateAnimator { int posX = 0; int posY = 0; - task.getStack().getDimBounds(mTmpStackBounds); + task.getRootTask().getDimBounds(mTmpStackBounds); boolean allowStretching = false; - task.getStack().getFinalAnimationSourceHintBounds(mTmpSourceBounds); + task.getRootTask().getFinalAnimationSourceHintBounds(mTmpSourceBounds); // If we don't have source bounds, we can attempt to use the content insets // if we have content insets. if (mTmpSourceBounds.isEmpty() && (mWin.mLastRelayoutContentInsets.width() > 0 || mWin.mLastRelayoutContentInsets.height() > 0)) { - mTmpSourceBounds.set(task.getStack().mPreAnimationBounds); + mTmpSourceBounds.set(task.getRootTask().mPreAnimationBounds); mTmpSourceBounds.inset(mWin.mLastRelayoutContentInsets); allowStretching = true; } @@ -946,7 +946,7 @@ class WindowStateAnimator { if (!mTmpSourceBounds.isEmpty()) { // Get the final target stack bounds, if we are not animating, this is just the // current stack bounds - task.getStack().getFinalAnimationBounds(mTmpAnimatingBounds); + task.getRootTask().getFinalAnimationBounds(mTmpAnimatingBounds); // Calculate the current progress and interpolate the difference between the target // and source bounds @@ -1042,7 +1042,7 @@ class WindowStateAnimator { mSurfaceController.deferTransactionUntil(mWin.getClientViewRootSurface(), mWin.getFrameNumber()); } else { - final ActivityStack stack = mWin.getRootTask(); + final Task stack = mWin.getRootTask(); mTmpPos.x = 0; mTmpPos.y = 0; if (stack != null) { @@ -1576,7 +1576,7 @@ class WindowStateAnimator { */ boolean isForceScaled() { final Task task = mWin.getTask(); - if (task != null && task.getStack().isForceScaled()) { + if (task != null && task.getRootTask().isForceScaled()) { return true; } return mForceScaleUntilResize; diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java index e3bb1b6ca9f3..c60abe8d51d1 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityDisplayTests.java @@ -65,9 +65,9 @@ public class ActivityDisplayTests extends ActivityTestsBase { // Create a stack at bottom. final TaskDisplayArea taskDisplayAreas = mRootWindowContainer.getDefaultDisplay().getDefaultTaskDisplayArea(); - final ActivityStack stack = + final Task stack = new StackBuilder(mRootWindowContainer).setOnTop(!ON_TOP).build(); - final ActivityStack prevFocusedStack = taskDisplayAreas.getFocusedStack(); + final Task prevFocusedStack = taskDisplayAreas.getFocusedStack(); stack.moveToFront("moveStackToFront"); // After moving the stack to front, the previous focused should be the last focused. @@ -86,7 +86,7 @@ public class ActivityDisplayTests extends ActivityTestsBase { @Test public void testFullscreenStackCanBeFocusedWhenFocusablePinnedStackExists() { // Create a pinned stack and move to front. - final ActivityStack pinnedStack = mRootWindowContainer.getDefaultTaskDisplayArea() + final Task pinnedStack = mRootWindowContainer.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, ON_TOP); final Task pinnedTask = new TaskBuilder(mService.mStackSupervisor) .setStack(pinnedStack).build(); @@ -98,7 +98,7 @@ public class ActivityDisplayTests extends ActivityTestsBase { assertTrue(pinnedStack.isFocusedStackOnDisplay()); // Create a fullscreen stack and move to front. - final ActivityStack fullscreenStack = createFullscreenStackWithSimpleActivityAt( + final Task fullscreenStack = createFullscreenStackWithSimpleActivityAt( mRootWindowContainer.getDefaultDisplay()); fullscreenStack.moveToFront("moveFullscreenStackToFront"); @@ -114,8 +114,8 @@ public class ActivityDisplayTests extends ActivityTestsBase { public void testStackShouldNotBeFocusedAfterMovingToBackOrRemoving() { // Create a display which only contains 2 stacks. final DisplayContent display = addNewDisplayContentAt(DisplayContent.POSITION_TOP); - final ActivityStack stack1 = createFullscreenStackWithSimpleActivityAt(display); - final ActivityStack stack2 = createFullscreenStackWithSimpleActivityAt(display); + final Task stack1 = createFullscreenStackWithSimpleActivityAt(display); + final Task stack2 = createFullscreenStackWithSimpleActivityAt(display); // Put stack1 and stack2 on top. stack1.moveToFront("moveStack1ToFront"); @@ -143,11 +143,11 @@ public class ActivityDisplayTests extends ActivityTestsBase { doReturn(false).when(display).shouldDestroyContentOnRemove(); // Put home stack on the display. - final ActivityStack homeStack = new StackBuilder(mRootWindowContainer) + final Task homeStack = new StackBuilder(mRootWindowContainer) .setDisplay(display).setActivityType(ACTIVITY_TYPE_HOME).build(); // Put a finishing standard activity which will be reparented. - final ActivityStack stack = createFullscreenStackWithSimpleActivityAt(display); + final Task stack = createFullscreenStackWithSimpleActivityAt(display); stack.topRunningActivity().makeFinishingLocked(); clearInvocations(homeStack); @@ -158,8 +158,8 @@ public class ActivityDisplayTests extends ActivityTestsBase { verify(homeStack, never()).resumeTopActivityUncheckedLocked(any(), any()); } - private ActivityStack createFullscreenStackWithSimpleActivityAt(DisplayContent display) { - final ActivityStack fullscreenStack = display.getDefaultTaskDisplayArea().createStack( + private Task createFullscreenStackWithSimpleActivityAt(DisplayContent display) { + final Task fullscreenStack = display.getDefaultTaskDisplayArea().createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, ON_TOP); final Task fullscreenTask = new TaskBuilder(mService.mStackSupervisor) .setStack(fullscreenStack).build(); @@ -174,11 +174,11 @@ public class ActivityDisplayTests extends ActivityTestsBase { public void testTopRunningActivity() { final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); final KeyguardController keyguard = mSupervisor.getKeyguardController(); - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); final ActivityRecord activity = stack.getTopNonFinishingActivity(); // Create empty stack on top. - final ActivityStack emptyStack = + final Task emptyStack = new StackBuilder(mRootWindowContainer).setCreateActivity(false).build(); // Make sure the top running activity is not affected when keyguard is not locked. @@ -223,7 +223,7 @@ public class ActivityDisplayTests extends ActivityTestsBase { @Test public void testAlwaysOnTopStackLocation() { final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack alwaysOnTopStack = taskDisplayArea.createStack(WINDOWING_MODE_FREEFORM, + final Task alwaysOnTopStack = taskDisplayArea.createStack(WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, true /* onTop */); final ActivityRecord activity = new ActivityBuilder(mService).setCreateTask(true) .setStack(alwaysOnTopStack).build(); @@ -234,12 +234,12 @@ public class ActivityDisplayTests extends ActivityTestsBase { assertTrue(alwaysOnTopStack.getTopNonFinishingActivity().isAlwaysOnTop()); assertEquals(alwaysOnTopStack, taskDisplayArea.getTopStack()); - final ActivityStack pinnedStack = taskDisplayArea.createStack( + final Task pinnedStack = taskDisplayArea.createStack( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); assertEquals(pinnedStack, taskDisplayArea.getRootPinnedTask()); assertEquals(pinnedStack, taskDisplayArea.getTopStack()); - final ActivityStack anotherAlwaysOnTopStack = taskDisplayArea.createStack( + final Task anotherAlwaysOnTopStack = taskDisplayArea.createStack( WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, true /* onTop */); anotherAlwaysOnTopStack.setAlwaysOnTop(true); taskDisplayArea.positionStackAtTop(anotherAlwaysOnTopStack, false /* includingParents */); @@ -249,7 +249,7 @@ public class ActivityDisplayTests extends ActivityTestsBase { // existing alwaysOnTop stack. assertEquals(anotherAlwaysOnTopStack, taskDisplayArea.getStackAt(topPosition - 1)); - final ActivityStack nonAlwaysOnTopStack = taskDisplayArea.createStack( + final Task nonAlwaysOnTopStack = taskDisplayArea.createStack( WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, true /* onTop */); assertEquals(taskDisplayArea, nonAlwaysOnTopStack.getDisplayArea()); topPosition = taskDisplayArea.getStackCount() - 1; @@ -273,7 +273,7 @@ public class ActivityDisplayTests extends ActivityTestsBase { assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop()); assertEquals(anotherAlwaysOnTopStack, taskDisplayArea.getStackAt(topPosition - 1)); - final ActivityStack dreamStack = taskDisplayArea.createStack( + final Task dreamStack = taskDisplayArea.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_DREAM, true /* onTop */); assertEquals(taskDisplayArea, dreamStack.getDisplayArea()); assertTrue(dreamStack.isAlwaysOnTop()); @@ -282,7 +282,7 @@ public class ActivityDisplayTests extends ActivityTestsBase { assertEquals(dreamStack, taskDisplayArea.getTopStack()); assertEquals(pinnedStack, taskDisplayArea.getStackAt(topPosition - 1)); - final ActivityStack assistStack = taskDisplayArea.createStack( + final Task assistStack = taskDisplayArea.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); assertEquals(taskDisplayArea, assistStack.getDisplayArea()); assertFalse(assistStack.isAlwaysOnTop()); @@ -310,13 +310,13 @@ public class ActivityDisplayTests extends ActivityTestsBase { private void removeStackTests(Runnable runnable) { final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack stack1 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task stack1 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, ON_TOP); - final ActivityStack stack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task stack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, ON_TOP); - final ActivityStack stack3 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task stack3 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, ON_TOP); - final ActivityStack stack4 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task stack4 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, ON_TOP); final Task task1 = new TaskBuilder(mService.mStackSupervisor).setStack(stack1).build(); final Task task2 = new TaskBuilder(mService.mStackSupervisor).setStack(stack2).build(); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java index e1ce431fc97c..feac6dbe1051 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java @@ -341,7 +341,7 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { public void testConsecutiveLaunchOnDifferentDisplay() { onActivityLaunched(mTopActivity); - final ActivityStack stack = new StackBuilder(mRootWindowContainer) + final Task stack = new StackBuilder(mRootWindowContainer) .setDisplay(addNewDisplayContentAt(DisplayContent.POSITION_BOTTOM)) .setCreateActivity(false) .build(); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 76b1a4d69f05..e45ced64c5b6 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -45,19 +45,19 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static com.android.server.wm.ActivityRecord.FINISH_RESULT_CANCELLED; import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REMOVED; import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REQUESTED; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; -import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; -import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.ActivityState.STARTED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_INVISIBLE; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; +import static com.android.server.wm.Task.ActivityState.DESTROYED; +import static com.android.server.wm.Task.ActivityState.DESTROYING; +import static com.android.server.wm.Task.ActivityState.FINISHING; +import static com.android.server.wm.Task.ActivityState.INITIALIZING; +import static com.android.server.wm.Task.ActivityState.PAUSED; +import static com.android.server.wm.Task.ActivityState.PAUSING; +import static com.android.server.wm.Task.ActivityState.RESUMED; +import static com.android.server.wm.Task.ActivityState.STARTED; +import static com.android.server.wm.Task.ActivityState.STOPPED; +import static com.android.server.wm.Task.ActivityState.STOPPING; +import static com.android.server.wm.Task.STACK_VISIBILITY_INVISIBLE; +import static com.android.server.wm.Task.STACK_VISIBILITY_VISIBLE; +import static com.android.server.wm.Task.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; import static com.google.common.truth.Truth.assertThat; @@ -106,7 +106,7 @@ import android.view.WindowManagerGlobal; import androidx.test.filters.MediumTest; import com.android.internal.R; -import com.android.server.wm.ActivityStack.ActivityState; +import com.android.server.wm.Task.ActivityState; import org.junit.Before; import org.junit.Test; @@ -123,7 +123,7 @@ import org.mockito.invocation.InvocationOnMock; @Presubmit @RunWith(WindowTestRunner.class) public class ActivityRecordTests extends ActivityTestsBase { - private ActivityStack mStack; + private Task mStack; private Task mTask; private ActivityRecord mActivity; @@ -292,7 +292,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testSetsRelaunchReason_NotDragResizing() { - mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); + mActivity.setState(Task.ActivityState.RESUMED, "Testing"); mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), @@ -315,7 +315,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testSetsRelaunchReason_DragResizing() { - mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); + mActivity.setState(Task.ActivityState.RESUMED, "Testing"); mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), @@ -340,7 +340,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testSetsRelaunchReason_NonResizeConfigChanges() { - mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); + mActivity.setState(Task.ActivityState.RESUMED, "Testing"); mTask.onRequestedOverrideConfigurationChanged(mTask.getConfiguration()); mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), @@ -366,7 +366,7 @@ public class ActivityRecordTests extends ActivityTestsBase { .setTask(mTask) .setConfigChanges(CONFIG_ORIENTATION | CONFIG_SCREEN_LAYOUT) .build(); - mActivity.setState(ActivityStack.ActivityState.RESUMED, "Testing"); + mActivity.setState(Task.ActivityState.RESUMED, "Testing"); mActivity.setLastReportedConfiguration(new MergedConfiguration(new Configuration(), mActivity.getConfiguration())); @@ -489,7 +489,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testShouldMakeActive_deferredResume() { - mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); + mActivity.setState(Task.ActivityState.STOPPED, "Testing"); mSupervisor.beginDeferResume(); assertEquals(false, mActivity.shouldMakeActive(null /* activeActivity */)); @@ -503,14 +503,14 @@ public class ActivityRecordTests extends ActivityTestsBase { ActivityRecord finishingActivity = new ActivityBuilder(mService).setTask(mTask).build(); finishingActivity.finishing = true; ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); - mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); + mActivity.setState(Task.ActivityState.STOPPED, "Testing"); assertEquals(false, mActivity.shouldMakeActive(null /* activeActivity */)); } @Test public void testShouldResume_stackVisibility() { - mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); + mActivity.setState(Task.ActivityState.STOPPED, "Testing"); spyOn(mStack); doReturn(STACK_VISIBILITY_VISIBLE).when(mStack).getVisibility(null); @@ -525,7 +525,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testShouldResumeOrPauseWithResults() { - mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); + mActivity.setState(Task.ActivityState.STOPPED, "Testing"); spyOn(mStack); ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); @@ -544,9 +544,9 @@ public class ActivityRecordTests extends ActivityTestsBase { .setLaunchTaskBehind(true) .setConfigChanges(CONFIG_ORIENTATION) .build(); - mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); + mActivity.setState(Task.ActivityState.STOPPED, "Testing"); - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); try { doReturn(false).when(stack).isTranslucent(any()); assertFalse(mStack.shouldBeVisible(null /* starting */)); @@ -585,7 +585,7 @@ public class ActivityRecordTests extends ActivityTestsBase { public void testShouldStartWhenMakeClientActive() { ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); topActivity.setOccludesParent(false); - mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); + mActivity.setState(Task.ActivityState.STOPPED, "Testing"); mActivity.setVisibility(true); mActivity.makeActiveIfNeeded(null /* activeActivity */); assertEquals(STARTED, mActivity.getState()); @@ -754,14 +754,14 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testFinishActivityIfPossible_adjustStackOrder() { // Prepare the stacks with order (top to bottom): mStack, stack1, stack2. - final ActivityStack stack1 = new StackBuilder(mRootWindowContainer).build(); + final Task stack1 = new StackBuilder(mRootWindowContainer).build(); mStack.moveToFront("test"); // The stack2 is needed here for moving back to simulate the // {@link DisplayContent#mPreferredTopFocusableStack} is cleared, so // {@link DisplayContent#getFocusedStack} will rely on the order of focusable-and-visible // stacks. Then when mActivity is finishing, its stack will be invisible (no running // activities in the stack) that is the key condition to verify. - final ActivityStack stack2 = new StackBuilder(mRootWindowContainer).build(); + final Task stack2 = new StackBuilder(mRootWindowContainer).build(); stack2.moveToBack("test", stack2.getBottomMostTask()); assertTrue(mStack.isTopStackInDisplayArea()); @@ -787,7 +787,7 @@ public class ActivityRecordTests extends ActivityTestsBase { .setCreateTask(true) .setStack(mStack) .build(); - ActivityStack topRootableTask = (ActivityStack) topActivity.getTask(); + Task topRootableTask = topActivity.getTask(); topRootableTask.moveToFront("test"); assertTrue(mStack.isTopStackInDisplayArea()); @@ -807,7 +807,7 @@ public class ActivityRecordTests extends ActivityTestsBase { public void testFinishActivityIfPossible_PreferredTopStackChanged() { final ActivityRecord topActivityOnNonTopDisplay = createActivityOnDisplay(true /* defaultDisplay */, null /* process */); - ActivityStack topRootableTask = topActivityOnNonTopDisplay.getRootTask(); + Task topRootableTask = topActivityOnNonTopDisplay.getRootTask(); topRootableTask.moveToFront("test"); assertTrue(topRootableTask.isTopStackInDisplayArea()); assertEquals(topRootableTask, topActivityOnNonTopDisplay.getDisplayArea() @@ -971,7 +971,7 @@ public class ActivityRecordTests extends ActivityTestsBase { // Simulates that {@code currentTop} starts an existing activity from background (so its // state is stopped) and the starting flow just goes to place it at top. - final ActivityStack nextStack = new StackBuilder(mRootWindowContainer).build(); + final Task nextStack = new StackBuilder(mRootWindowContainer).build(); final ActivityRecord nextTop = nextStack.getTopNonFinishingActivity(); nextTop.setState(STOPPED, "test"); @@ -1093,7 +1093,7 @@ public class ActivityRecordTests extends ActivityTestsBase { // Add another stack to become focused and make the activity there visible. This way it // simulates finishing in non-focused stack in split-screen. - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); final ActivityRecord focusedActivity = stack.getTopMostActivity(); focusedActivity.nowVisible = true; focusedActivity.mVisibleRequested = true; @@ -1199,7 +1199,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testDestroyIfPossible_lastActivityAboveEmptyHomeStack() { // Empty the home stack. - final ActivityStack homeStack = mActivity.getDisplayArea().getRootHomeTask(); + final Task homeStack = mActivity.getDisplayArea().getRootHomeTask(); homeStack.forAllLeafTasks((t) -> { homeStack.removeChild(t, "test"); }, true /* traverseTopToBottom */); @@ -1225,7 +1225,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testCompleteFinishing_lastActivityAboveEmptyHomeStack() { // Empty the home stack. - final ActivityStack homeStack = mActivity.getDisplayArea().getRootHomeTask(); + final Task homeStack = mActivity.getDisplayArea().getRootHomeTask(); homeStack.forAllLeafTasks((t) -> { homeStack.removeChild(t, "test"); }, true /* traverseTopToBottom */); @@ -1325,7 +1325,7 @@ public class ActivityRecordTests extends ActivityTestsBase { @Test public void testRemoveFromHistory() { - final ActivityStack stack = mActivity.getRootTask(); + final Task stack = mActivity.getRootTask(); final Task task = mActivity.getTask(); mActivity.removeFromHistory("test"); @@ -1334,7 +1334,7 @@ public class ActivityRecordTests extends ActivityTestsBase { assertNull(mActivity.app); assertNull(mActivity.getTask()); assertEquals(0, task.getChildCount()); - assertEquals(task.getStack(), task); + assertEquals(task.getRootTask(), task); assertEquals(0, stack.getChildCount()); } @@ -1576,7 +1576,7 @@ public class ActivityRecordTests extends ActivityTestsBase { // Create a new task with custom config to reparent the activity to. final Task newTask = - new TaskBuilder(mSupervisor).setStack(initialTask.getStack()).build(); + new TaskBuilder(mSupervisor).setStack(initialTask.getRootTask()).build(); final Configuration newConfig = newTask.getConfiguration(); newConfig.densityDpi += 100; newTask.onRequestedOverrideConfigurationChanged(newConfig); @@ -1608,7 +1608,7 @@ public class ActivityRecordTests extends ActivityTestsBase { // Create a new task with custom config to reparent the second activity to. final Task newTask = - new TaskBuilder(mSupervisor).setStack(initialTask.getStack()).build(); + new TaskBuilder(mSupervisor).setStack(initialTask.getRootTask()).build(); final Configuration newConfig = newTask.getConfiguration(); newConfig.densityDpi += 100; newTask.onRequestedOverrideConfigurationChanged(newConfig); @@ -1696,7 +1696,7 @@ public class ActivityRecordTests extends ActivityTestsBase { display = new TestDisplayContent.Builder(mService, 2000, 1000).setDensityDpi(300) .setPosition(DisplayContent.POSITION_TOP).build(); } - final ActivityStack stack = display.getDefaultTaskDisplayArea() + final Task stack = display.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, true /* onTop */); final Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); return new ActivityBuilder(mService).setTask(task).setUseProcess(process).build(); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java index 5c6906cfa942..197c89a2d479 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java @@ -56,7 +56,7 @@ import org.junit.runner.RunWith; @Presubmit @RunWith(WindowTestRunner.class) public class ActivityStackSupervisorTests extends ActivityTestsBase { - private ActivityStack mFullscreenStack; + private Task mFullscreenStack; @Before public void setUp() throws Exception { @@ -113,7 +113,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { public void testHandleNonResizableTaskOnSecondaryDisplay() { // Create an unresizable task on secondary display. final DisplayContent newDisplay = addNewDisplayContentAt(DisplayContent.POSITION_TOP); - final ActivityStack stack = new StackBuilder(mRootWindowContainer) + final Task stack = new StackBuilder(mRootWindowContainer) .setDisplay(newDisplay).build(); final ActivityRecord unresizableActivity = stack.getTopNonFinishingActivity(); final Task task = unresizableActivity.getTask(); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java index 373eed921580..c2afa5f856ed 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java @@ -34,19 +34,19 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; -import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; -import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_INVISIBLE; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; -import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; +import static com.android.server.wm.Task.ActivityState.DESTROYING; +import static com.android.server.wm.Task.ActivityState.FINISHING; +import static com.android.server.wm.Task.ActivityState.PAUSING; +import static com.android.server.wm.Task.ActivityState.RESUMED; +import static com.android.server.wm.Task.ActivityState.STOPPED; +import static com.android.server.wm.Task.ActivityState.STOPPING; import static com.android.server.wm.Task.FLAG_FORCE_HIDDEN_FOR_TASK_ORG; import static com.android.server.wm.Task.REPARENT_MOVE_STACK_TO_FRONT; +import static com.android.server.wm.Task.STACK_VISIBILITY_INVISIBLE; +import static com.android.server.wm.Task.STACK_VISIBILITY_VISIBLE; +import static com.android.server.wm.Task.STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; import static com.android.server.wm.TaskDisplayArea.getStackAbove; import static com.android.server.wm.WindowContainer.POSITION_TOP; @@ -90,7 +90,7 @@ import java.util.function.Consumer; @RunWith(WindowTestRunner.class) public class ActivityStackTests extends ActivityTestsBase { private TaskDisplayArea mDefaultTaskDisplayArea; - private ActivityStack mStack; + private Task mStack; private Task mTask; @Before @@ -119,7 +119,7 @@ public class ActivityStackTests extends ActivityTestsBase { r.setState(RESUMED, "testResumedActivityFromTaskReparenting"); assertEquals(r, mStack.getResumedActivity()); - final ActivityStack destStack = mDefaultTaskDisplayArea.createStack( + final Task destStack = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); mTask.reparent(destStack, true /* toTop */, Task.REPARENT_KEEP_STACK_AT_FRONT, @@ -137,7 +137,7 @@ public class ActivityStackTests extends ActivityTestsBase { r.setState(RESUMED, "testResumedActivityFromActivityReparenting"); assertEquals(r, mStack.getResumedActivity()); - final ActivityStack destStack = mDefaultTaskDisplayArea.createStack( + final Task destStack = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); mTask.reparent(destStack, true /*toTop*/, REPARENT_MOVE_STACK_TO_FRONT, false, false, "testResumedActivityFromActivityReparenting"); @@ -153,7 +153,7 @@ public class ActivityStackTests extends ActivityTestsBase { organizer.setMoveToSecondaryOnEnter(false); // Create primary splitscreen stack. - final ActivityStack primarySplitScreen = mDefaultTaskDisplayArea.createStack( + final Task primarySplitScreen = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Assert windowing mode. @@ -178,10 +178,10 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveToPrimarySplitScreenThenMoveToBack() { TestSplitOrganizer organizer = new TestSplitOrganizer(mService); // This time, start with a fullscreen activitystack - final ActivityStack primarySplitScreen = mDefaultTaskDisplayArea.createStack( + final Task primarySplitScreen = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, true /* onTop */); - primarySplitScreen.reparent((ActivityStack) organizer.mPrimary, POSITION_TOP, + primarySplitScreen.reparent(organizer.mPrimary, POSITION_TOP, false /*moveParents*/, "test"); // Assert windowing mode. @@ -204,13 +204,13 @@ public class ActivityStackTests extends ActivityTestsBase { TestSplitOrganizer organizer = new TestSplitOrganizer(mService); // Set up split-screen with primary on top and secondary containing the home task below // another stack. - final ActivityStack primaryTask = mDefaultTaskDisplayArea.createStack( + final Task primaryTask = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack homeRoot = mDefaultTaskDisplayArea.getStack( + final Task homeRoot = mDefaultTaskDisplayArea.getStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); - final ActivityStack secondaryTask = mDefaultTaskDisplayArea.createStack( + final Task secondaryTask = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); - mDefaultTaskDisplayArea.positionStackAtTop((ActivityStack) organizer.mPrimary, + mDefaultTaskDisplayArea.positionStackAtTop(organizer.mPrimary, false /* includingParents */); // Move primary to back. @@ -228,7 +228,7 @@ public class ActivityStackTests extends ActivityTestsBase { assertEquals(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, primaryTask.getWindowingMode()); // Move secondary to back via parent (should be equivalent) - ((ActivityStack) organizer.mSecondary).moveToBack("test", secondaryTask); + organizer.mSecondary.moveToBack("test", secondaryTask); // Assert that it is now in back but still in secondary split assertEquals(1, homeRoot.compareTo(primaryTask)); @@ -239,12 +239,12 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testRemoveOrganizedTask_UpdateStackReference() { - final ActivityStack rootHomeTask = mDefaultTaskDisplayArea.getRootHomeTask(); + final Task rootHomeTask = mDefaultTaskDisplayArea.getRootHomeTask(); final ActivityRecord homeActivity = new ActivityBuilder(mService) .setStack(rootHomeTask) .setCreateTask(true) .build(); - final ActivityStack secondaryStack = (ActivityStack) WindowContainer.fromBinder( + final Task secondaryStack = (Task) WindowContainer.fromBinder( mService.mTaskOrganizerController.createRootTask(rootHomeTask.getDisplayId(), WINDOWING_MODE_SPLIT_SCREEN_SECONDARY).token.asBinder()); @@ -258,7 +258,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testStackInheritsDisplayWindowingMode() { - final ActivityStack primarySplitScreen = mDefaultTaskDisplayArea.createStack( + final Task primarySplitScreen = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, true /* onTop */); assertEquals(WINDOWING_MODE_FULLSCREEN, primarySplitScreen.getWindowingMode()); @@ -273,7 +273,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testStackOverridesDisplayWindowingMode() { - final ActivityStack primarySplitScreen = mDefaultTaskDisplayArea.createStack( + final Task primarySplitScreen = mDefaultTaskDisplayArea.createStack( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, true /* onTop */); assertEquals(WINDOWING_MODE_FULLSCREEN, primarySplitScreen.getWindowingMode()); @@ -354,9 +354,9 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveStackToBackIncludingParent() { final TaskDisplayArea taskDisplayArea = addNewDisplayContentAt(DisplayContent.POSITION_TOP) .getDefaultTaskDisplayArea(); - final ActivityStack stack1 = createStackForShouldBeVisibleTest(taskDisplayArea, + final Task stack1 = createStackForShouldBeVisibleTest(taskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack stack2 = createStackForShouldBeVisibleTest(taskDisplayArea, + final Task stack2 = createStackForShouldBeVisibleTest(taskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Do not move display to back because there is still another stack. @@ -371,9 +371,9 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testShouldBeVisible_Fullscreen() { - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); - final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Add an activity to the pinned stack so it isn't considered empty for visibility check. final ActivityRecord pinnedActivity = new ActivityBuilder(mService) @@ -384,7 +384,7 @@ public class ActivityStackTests extends ActivityTestsBase { assertTrue(homeStack.shouldBeVisible(null /* starting */)); assertTrue(pinnedStack.shouldBeVisible(null /* starting */)); - final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest( + final Task fullscreenStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Home stack shouldn't be visible behind an opaque fullscreen stack, but pinned stack @@ -402,14 +402,14 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testShouldBeVisible_SplitScreen() { - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); // Home stack should always be fullscreen for this test. doReturn(false).when(homeStack).supportsSplitScreenWindowingMode(); - final ActivityStack splitScreenPrimary = + final Task splitScreenPrimary = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack splitScreenSecondary = + final Task splitScreenSecondary = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); @@ -437,7 +437,7 @@ public class ActivityStackTests extends ActivityTestsBase { assertEquals(STACK_VISIBILITY_VISIBLE, splitScreenSecondary.getVisibility(null /* starting */)); - final ActivityStack splitScreenSecondary2 = + final Task splitScreenSecondary2 = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); // First split-screen secondary shouldn't be visible behind another opaque split-split @@ -460,7 +460,7 @@ public class ActivityStackTests extends ActivityTestsBase { assertEquals(STACK_VISIBILITY_VISIBLE, splitScreenSecondary2.getVisibility(null /* starting */)); - final ActivityStack assistantStack = createStackForShouldBeVisibleTest( + final Task assistantStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); @@ -531,13 +531,13 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testGetVisibility_MultiLevel() { - final ActivityStack homeStack = createStackForShouldBeVisibleTest( + final Task homeStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, true /* onTop */); - final ActivityStack splitPrimary = createStackForShouldBeVisibleTest( + final Task splitPrimary = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_UNDEFINED, true /* onTop */); - final ActivityStack splitSecondary = createStackForShouldBeVisibleTest( + final Task splitSecondary = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_UNDEFINED, true /* onTop */); @@ -556,7 +556,7 @@ public class ActivityStackTests extends ActivityTestsBase { // Add fullscreen translucent task that partially occludes split tasks - final ActivityStack translucentStack = createStandardStackForVisibilityTest( + final Task translucentStack = createStandardStackForVisibilityTest( WINDOWING_MODE_FULLSCREEN, true /* translucent */); // Fullscreen translucent task should be visible assertEquals(STACK_VISIBILITY_VISIBLE, translucentStack.getVisibility(null /* starting */)); @@ -580,10 +580,10 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testGetVisibility_FullscreenBehindTranslucent() { - final ActivityStack bottomStack = + final Task bottomStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, false /* translucent */); - final ActivityStack translucentStack = + final Task translucentStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, true /* translucent */); @@ -595,13 +595,13 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testGetVisibility_FullscreenBehindTranslucentAndOpaque() { - final ActivityStack bottomStack = + final Task bottomStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, false /* translucent */); - final ActivityStack translucentStack = + final Task translucentStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, true /* translucent */); - final ActivityStack opaqueStack = + final Task opaqueStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, false /* translucent */); @@ -613,13 +613,13 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testGetVisibility_FullscreenBehindOpaqueAndTranslucent() { - final ActivityStack bottomStack = + final Task bottomStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, false /* translucent */); - final ActivityStack opaqueStack = + final Task opaqueStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, false /* translucent */); - final ActivityStack translucentStack = + final Task translucentStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, true /* translucent */); @@ -632,10 +632,10 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testGetVisibility_FullscreenTranslucentBehindTranslucent() { - final ActivityStack bottomTranslucentStack = + final Task bottomTranslucentStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, true /* translucent */); - final ActivityStack translucentStack = + final Task translucentStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, true /* translucent */); @@ -647,10 +647,10 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testGetVisibility_FullscreenTranslucentBehindOpaque() { - final ActivityStack bottomTranslucentStack = + final Task bottomTranslucentStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, true /* translucent */); - final ActivityStack opaqueStack = + final Task opaqueStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, false /* translucent */); @@ -661,13 +661,13 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testGetVisibility_FullscreenBehindTranslucentAndPip() { - final ActivityStack bottomStack = + final Task bottomStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, false /* translucent */); - final ActivityStack translucentStack = + final Task translucentStack = createStandardStackForVisibilityTest(WINDOWING_MODE_FULLSCREEN, true /* translucent */); - final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); assertEquals(STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, @@ -684,7 +684,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testShouldBeVisible_Finishing() { - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); ActivityRecord topRunningHomeActivity = homeStack.topRunningActivity(); if (topRunningHomeActivity == null) { @@ -694,7 +694,7 @@ public class ActivityStackTests extends ActivityTestsBase { .build(); } - final ActivityStack translucentStack = createStackForShouldBeVisibleTest( + final Task translucentStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); doReturn(true).when(translucentStack).isTranslucent(any()); @@ -717,7 +717,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testShouldBeVisible_FullscreenBehindTranslucentInHomeStack() { - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); final ActivityRecord firstActivity = new ActivityBuilder(mService) @@ -740,9 +740,9 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindFullscreen() { mDefaultTaskDisplayArea.removeStack(mStack); - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); - final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest( + final Task fullscreenStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); @@ -760,9 +760,9 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeBehindTranslucent() { mDefaultTaskDisplayArea.removeStack(mStack); - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); - final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest( + final Task fullscreenStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); @@ -780,10 +780,10 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveHomeStackBehindBottomMostVisibleStack_NoMoveHomeOnTop() { mDefaultTaskDisplayArea.removeStack(mStack); - final ActivityStack fullscreenStack = createStackForShouldBeVisibleTest( + final Task fullscreenStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); doReturn(false).when(homeStack).isTranslucent(any()); @@ -800,15 +800,15 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreen() { mDefaultTaskDisplayArea.removeStack(mStack); - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); - final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( + final Task fullscreenStack1 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( + final Task fullscreenStack2 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); doReturn(false).when(homeStack).isTranslucent(any()); @@ -827,12 +827,12 @@ public class ActivityStackTests extends ActivityTestsBase { testMoveHomeStackBehindBottomMostVisibleStack_MoveHomeBehindFullscreenAndTranslucent() { mDefaultTaskDisplayArea.removeStack(mStack); - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); - final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( + final Task fullscreenStack1 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( + final Task fullscreenStack2 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); @@ -851,13 +851,13 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveHomeStackBehindStack_BehindHomeStack() { mDefaultTaskDisplayArea.removeStack(mStack); - final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( + final Task fullscreenStack1 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( + final Task fullscreenStack2 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); doReturn(false).when(homeStack).isTranslucent(any()); @@ -874,19 +874,19 @@ public class ActivityStackTests extends ActivityTestsBase { public void testMoveHomeStackBehindStack() { mDefaultTaskDisplayArea.removeStack(mStack); - final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( + final Task fullscreenStack1 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack fullscreenStack2 = createStackForShouldBeVisibleTest( + final Task fullscreenStack2 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack fullscreenStack3 = createStackForShouldBeVisibleTest( + final Task fullscreenStack3 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack fullscreenStack4 = createStackForShouldBeVisibleTest( + final Task fullscreenStack4 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); mDefaultTaskDisplayArea.moveStackBehindStack(homeStack, fullscreenStack1); @@ -901,13 +901,13 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testSetAlwaysOnTop() { - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); - final ActivityStack pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task pinnedStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); assertEquals(pinnedStack, getStackAbove(homeStack)); - final ActivityStack alwaysOnTopStack = createStackForShouldBeVisibleTest( + final Task alwaysOnTopStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, true /* onTop */); alwaysOnTopStack.setAlwaysOnTop(true); @@ -915,13 +915,13 @@ public class ActivityStackTests extends ActivityTestsBase { // Ensure (non-pinned) always on top stack is put below pinned stack. assertEquals(pinnedStack, getStackAbove(alwaysOnTopStack)); - final ActivityStack nonAlwaysOnTopStack = createStackForShouldBeVisibleTest( + final Task nonAlwaysOnTopStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Ensure non always on top stack is put below always on top stacks. assertEquals(alwaysOnTopStack, getStackAbove(nonAlwaysOnTopStack)); - final ActivityStack alwaysOnTopStack2 = createStackForShouldBeVisibleTest( + final Task alwaysOnTopStack2 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, true /* onTop */); alwaysOnTopStack2.setAlwaysOnTop(true); @@ -946,13 +946,13 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testSplitScreenMoveToFront() { - final ActivityStack splitScreenPrimary = createStackForShouldBeVisibleTest( + final Task splitScreenPrimary = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack splitScreenSecondary = createStackForShouldBeVisibleTest( + final Task splitScreenSecondary = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack assistantStack = createStackForShouldBeVisibleTest( + final Task assistantStack = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */); @@ -977,18 +977,18 @@ public class ActivityStackTests extends ActivityTestsBase { } } - private ActivityStack createStandardStackForVisibilityTest(int windowingMode, + private Task createStandardStackForVisibilityTest(int windowingMode, boolean translucent) { - final ActivityStack stack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task stack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, windowingMode, ACTIVITY_TYPE_STANDARD, true /* onTop */); doReturn(translucent).when(stack).isTranslucent(any()); return stack; } @SuppressWarnings("TypeParameterUnusedInFormals") - private ActivityStack createStackForShouldBeVisibleTest( + private Task createStackForShouldBeVisibleTest( TaskDisplayArea taskDisplayArea, int windowingMode, int activityType, boolean onTop) { - final ActivityStack stack; + final Task stack; if (activityType == ACTIVITY_TYPE_HOME) { // Home stack and activity are created in ActivityTestsBase#setupActivityManagerService stack = mDefaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); @@ -1152,7 +1152,7 @@ public class ActivityStackTests extends ActivityTestsBase { @Test public void testWontFinishHomeStackImmediately() { - final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, + final Task homeStack = createStackForShouldBeVisibleTest(mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */); ActivityRecord activity = homeStack.topRunningActivity(); @@ -1172,10 +1172,10 @@ public class ActivityStackTests extends ActivityTestsBase { public void testFinishCurrentActivity() { // Create 2 activities on a new display. final DisplayContent display = addNewDisplayContentAt(DisplayContent.POSITION_TOP); - final ActivityStack stack1 = createStackForShouldBeVisibleTest( + final Task stack1 = createStackForShouldBeVisibleTest( display.getDefaultTaskDisplayArea(), WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack stack2 = createStackForShouldBeVisibleTest( + final Task stack2 = createStackForShouldBeVisibleTest( display.getDefaultTaskDisplayArea(), WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); @@ -1194,7 +1194,7 @@ public class ActivityStackTests extends ActivityTestsBase { eq(display.mDisplayId), anyBoolean(), anyBoolean()); } - private ActivityRecord finishTopActivity(ActivityStack stack) { + private ActivityRecord finishTopActivity(Task stack) { final ActivityRecord activity = stack.topRunningActivity(); assertNotNull(activity); activity.setState(STOPPED, "finishTopActivity"); @@ -1252,7 +1252,7 @@ public class ActivityStackTests extends ActivityTestsBase { public void testStackOrderChangedOnPositionStack() { StackOrderChangedListener listener = new StackOrderChangedListener(); try { - final ActivityStack fullscreenStack1 = createStackForShouldBeVisibleTest( + final Task fullscreenStack1 = createStackForShouldBeVisibleTest( mDefaultTaskDisplayArea, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); mDefaultTaskDisplayArea.registerStackOrderChangedListener(listener); @@ -1382,7 +1382,7 @@ public class ActivityStackTests extends ActivityTestsBase { activities[i] = r; doReturn(null).when(mService).getProcessController( eq(r.processName), eq(r.info.applicationInfo.uid)); - r.setState(ActivityStack.ActivityState.INITIALIZING, "test"); + r.setState(Task.ActivityState.INITIALIZING, "test"); // Ensure precondition that the activity is opaque. assertTrue(r.occludesParent()); mSupervisor.startSpecificActivity(r, false /* andResume */, @@ -1443,7 +1443,7 @@ public class ActivityStackTests extends ActivityTestsBase { public boolean mChanged = false; @Override - public void onStackOrderChanged(ActivityStack stack) { + public void onStackOrderChanged(Task stack) { mChanged = true; } } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java index ca4456b7b926..c9a927901a37 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStartControllerTests.java @@ -77,7 +77,7 @@ public class ActivityStartControllerTests extends ActivityTestsBase { .setCreateTask(true) .build(); final int startFlags = random.nextInt(); - final ActivityStack stack = mService.mRootWindowContainer.getDefaultTaskDisplayArea() + final Task stack = mService.mRootWindowContainer.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); final WindowProcessController wpc = new WindowProcessController(mService, mService.mContext.getApplicationInfo(), "name", 12345, diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java index e3b1d6306a81..f2f8a12b6ea9 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java @@ -321,7 +321,7 @@ public class ActivityStarterTests extends ActivityTestsBase { if (mockGetLaunchStack) { // Instrument the stack and task used. - final ActivityStack stack = mRootWindowContainer.getDefaultTaskDisplayArea() + final Task stack = mRootWindowContainer.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); @@ -492,7 +492,7 @@ public class ActivityStarterTests extends ActivityTestsBase { private void assertNoTasks(DisplayContent display) { display.forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); assertFalse(stack.hasChild()); } }); @@ -741,7 +741,7 @@ public class ActivityStarterTests extends ActivityTestsBase { new TestDisplayContent.Builder(mService, 1000, 1500) .setPosition(POSITION_BOTTOM).build(); final TaskDisplayArea secondaryTaskContainer = secondaryDisplay.getDefaultTaskDisplayArea(); - final ActivityStack stack = secondaryTaskContainer.createStack( + final Task stack = secondaryTaskContainer.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Create an activity record on the top of secondary display. @@ -787,7 +787,7 @@ public class ActivityStarterTests extends ActivityTestsBase { ACTIVITY_TYPE_STANDARD, false /* onTop */)); // Create another activity on top of the secondary display. - final ActivityStack topStack = secondaryTaskContainer.createStack(WINDOWING_MODE_FULLSCREEN, + final Task topStack = secondaryTaskContainer.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); final Task topTask = new TaskBuilder(mSupervisor).setStack(topStack).build(); new ActivityBuilder(mService).setTask(topTask).build(); @@ -826,7 +826,7 @@ public class ActivityStarterTests extends ActivityTestsBase { Task task = topActivity.getTask(); starter.postStartActivityProcessing( - task.getTopNonFinishingActivity(), START_DELIVERED_TO_TOP, task.getStack()); + task.getTopNonFinishingActivity(), START_DELIVERED_TO_TOP, task.getRootTask()); verify(taskChangeNotifier).notifyActivityRestartAttempt( any(), anyBoolean(), anyBoolean(), anyBoolean()); @@ -835,14 +835,14 @@ public class ActivityStarterTests extends ActivityTestsBase { Task task2 = reusableActivity.getTask(); starter.postStartActivityProcessing( - task2.getTopNonFinishingActivity(), START_TASK_TO_FRONT, task.getStack()); + task2.getTopNonFinishingActivity(), START_TASK_TO_FRONT, task.getRootTask()); verify(taskChangeNotifier, times(2)).notifyActivityRestartAttempt( any(), anyBoolean(), anyBoolean(), anyBoolean()); verify(taskChangeNotifier).notifyActivityRestartAttempt( any(), anyBoolean(), anyBoolean(), eq(false)); } - private ActivityRecord createSingleTaskActivityOn(ActivityStack stack) { + private ActivityRecord createSingleTaskActivityOn(Task stack) { final ComponentName componentName = ComponentName.createRelative( DEFAULT_COMPONENT_PACKAGE_NAME, DEFAULT_COMPONENT_PACKAGE_NAME + ".SingleTaskActivity"); @@ -1046,7 +1046,7 @@ public class ActivityStarterTests extends ActivityTestsBase { targetRecord.setVisibility(false); final ActivityRecord sourceRecord = new ActivityBuilder(mService).build(); - final ActivityStack stack = spy( + final Task stack = spy( mRootWindowContainer.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, /* onTop */true)); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java index f65d6e0c82af..f8faae66c704 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java @@ -73,7 +73,7 @@ public class ActivityTaskManagerServiceTests extends ActivityTestsBase { /** Verify that activity is finished correctly upon request. */ @Test public void testActivityFinish() { - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity(); assertTrue("Activity must be finished", mService.finishActivity(activity.appToken, 0 /* resultCode */, null /* resultData */, @@ -87,7 +87,7 @@ public class ActivityTaskManagerServiceTests extends ActivityTestsBase { @Test public void testOnPictureInPictureRequested() throws RemoteException { - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity(); final ClientLifecycleManager mockLifecycleManager = mock(ClientLifecycleManager.class); doReturn(mockLifecycleManager).when(mService).getLifecycleManager(); @@ -106,7 +106,7 @@ public class ActivityTaskManagerServiceTests extends ActivityTestsBase { @Test(expected = IllegalStateException.class) public void testOnPictureInPictureRequested_cannotEnterPip() throws RemoteException { - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity(); ClientLifecycleManager lifecycleManager = mService.getLifecycleManager(); doReturn(false).when(activity).inPinnedWindowingMode(); @@ -120,7 +120,7 @@ public class ActivityTaskManagerServiceTests extends ActivityTestsBase { @Test(expected = IllegalStateException.class) public void testOnPictureInPictureRequested_alreadyInPIPMode() throws RemoteException { - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); final ActivityRecord activity = stack.getBottomMostTask().getTopNonFinishingActivity(); ClientLifecycleManager lifecycleManager = mService.getLifecycleManager(); doReturn(true).when(activity).inPinnedWindowingMode(); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java index 9d0cd26bc040..f97c3c90ffe7 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java @@ -112,7 +112,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { private String mAffinity; private int mUid = 12345; private boolean mCreateTask; - private ActivityStack mStack; + private Task mStack; private int mActivityFlags; private int mLaunchMode; private int mResizeMode = RESIZE_MODE_RESIZEABLE; @@ -164,7 +164,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { return this; } - ActivityBuilder setStack(ActivityStack stack) { + ActivityBuilder setStack(Task stack) { mStack = stack; return this; } @@ -338,7 +338,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { private IVoiceInteractionSession mVoiceSession; private boolean mCreateStack = true; - private ActivityStack mStack; + private Task mStack; private TaskDisplayArea mTaskDisplayArea; TaskBuilder(ActivityStackSupervisor supervisor) { @@ -384,7 +384,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { return this; } - TaskBuilder setStack(ActivityStack stack) { + TaskBuilder setStack(Task stack) { mStack = stack; return this; } @@ -418,7 +418,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { intent.setComponent(mComponent); intent.setFlags(mFlags); - final Task task = new ActivityStack(mSupervisor.mService, mTaskId, aInfo, + final Task task = new Task(mSupervisor.mService, mTaskId, aInfo, intent /*intent*/, mVoiceSession, null /*_voiceInteractor*/, null /*taskDescription*/, mStack); spyOn(task); @@ -503,11 +503,11 @@ class ActivityTestsBase extends SystemServiceTestsBase { return this; } - ActivityStack build() { + Task build() { SystemServicesTestRule.checkHoldsLock(mRootWindowContainer.mWmService.mGlobalLock); final int stackId = mStackId >= 0 ? mStackId : mTaskDisplayArea.getNextStackId(); - final ActivityStack stack = mTaskDisplayArea.createStackUnchecked( + final Task stack = mTaskDisplayArea.createStackUnchecked( mWindowingMode, mActivityType, stackId, mOnTop, mInfo, mIntent, false /* createdByOrganizer */); final ActivityStackSupervisor supervisor = mRootWindowContainer.mStackSupervisor; @@ -593,7 +593,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { DisplayContent dc = mService.mRootWindowContainer.getDisplayContent(mDisplayId); dc.forAllTaskDisplayAreas(taskDisplayArea -> { for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { - final ActivityStack stack = taskDisplayArea.getStackAt(sNdx); + final Task stack = taskDisplayArea.getStackAt(sNdx); if (!WindowConfiguration.isSplitScreenWindowingMode(stack.getWindowingMode())) { stack.reparent(mSecondary, POSITION_BOTTOM); } diff --git a/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java index e8fab2b0243b..673feb260dd4 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java @@ -53,14 +53,14 @@ import org.junit.runner.RunWith; @RunWith(WindowTestRunner.class) public class AppChangeTransitionTests extends WindowTestsBase { - private ActivityStack mStack; + private Task mStack; private Task mTask; private ActivityRecord mActivity; public void setUpOnDisplay(DisplayContent dc) { mActivity = createTestActivityRecord(dc, WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD); mTask = mActivity.getTask(); - mStack = mTask.getStack(); + mStack = mTask.getRootTask(); // Set a remote animator with snapshot disabled. Snapshots don't work in wmtests. RemoteAnimationDefinition definition = new RemoteAnimationDefinition(); diff --git a/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java index f2a553906095..d7baf8d05bd6 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java @@ -134,12 +134,12 @@ public class AppTransitionControllerTest extends WindowTestsBase { // [DisplayContent] -+- [TaskStack1] - [Task1] - [ActivityRecord1] (opening, invisible) // +- [TaskStack2] - [Task2] - [ActivityRecord2] (closing, visible) - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(stack1); activity1.setVisible(false); activity1.mVisibleRequested = true; - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity2 = WindowTestUtils.createTestActivityRecord(stack2); final ArraySet<ActivityRecord> opening = new ArraySet<>(); @@ -162,10 +162,10 @@ public class AppTransitionControllerTest extends WindowTestsBase { public void testGetAnimationTargets_visibilityAlreadyUpdated() { // [DisplayContent] -+- [TaskStack1] - [Task1] - [ActivityRecord1] (opening, visible) // +- [TaskStack2] - [Task2] - [ActivityRecord2] (closing, invisible) - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(stack1); - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity2 = WindowTestUtils.createTestActivityRecord(stack2); activity2.setVisible(false); activity2.mVisibleRequested = false; @@ -202,13 +202,13 @@ public class AppTransitionControllerTest extends WindowTestsBase { public void testGetAnimationTargets_visibilityAlreadyUpdated_butForcedTransitionRequested() { // [DisplayContent] -+- [TaskStack1] - [Task1] - [ActivityRecord1] (closing, invisible) // +- [TaskStack2] - [Task2] - [ActivityRecord2] (opening, visible) - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(stack1); activity1.setVisible(true); activity1.mVisibleRequested = true; activity1.mRequestForceTransition = true; - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity2 = WindowTestUtils.createTestActivityRecord(stack2); activity2.setVisible(false); activity2.mVisibleRequested = false; @@ -237,7 +237,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { // Create another non-empty task so the animation target won't promote to task display area. WindowTestUtils.createTestActivityRecord( mDisplayContent.getDefaultTaskDisplayArea().getOrCreateRootHomeTask()); - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity = WindowTestUtils.createTestActivityRecord(stack); activity.setVisible(false); activity.mIsExiting = true; @@ -266,7 +266,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { // +- [AppWindow1] (being-replaced) // +- [TaskStack2] - [Task2] - [ActivityRecord2] (closing, invisible) // +- [AppWindow2] (being-replaced) - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(stack1); final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( TYPE_BASE_APPLICATION); @@ -275,7 +275,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { appWindow1.mWillReplaceWindow = true; activity1.addWindow(appWindow1); - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity2 = WindowTestUtils.createTestActivityRecord(stack2); activity2.setVisible(false); activity2.mVisibleRequested = false; @@ -322,7 +322,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { // | // +- [TaskStack2] - [Task2] -+- [ActivityRecord3] (closing, visible) // +- [ActivityRecord4] (invisible) - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack1, 0 /* userId */); final ActivityRecord activity1 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task1); @@ -333,7 +333,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { activity2.setVisible(false); activity2.mVisibleRequested = false; - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final Task task2 = createTaskInStack(stack2, 0 /* userId */); final ActivityRecord activity3 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task2); @@ -365,7 +365,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { // [DisplayContent] - [TaskStack] - [Task] -+- [ActivityRecord1] (opening, invisible) // +- [ActivityRecord2] (closing, visible) - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); final ActivityRecord activity1 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task); @@ -401,7 +401,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { // +- [TaskStack2] - [Task2] -+- [ActivityRecord3] (closing, visible) // +- [ActivityRecord4] (visible) - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack1, 0 /* userId */); final ActivityRecord activity1 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task1); @@ -412,7 +412,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { final ActivityRecord activity2 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task1); - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final Task task2 = createTaskInStack(stack2, 0 /* userId */); final ActivityRecord activity3 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task2); @@ -447,7 +447,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { // +- [TaskStack2] - [Task2] -+- [ActivityRecord3] (closing, visible) // +- [ActivityRecord4] (closing, visible) - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack1, 0 /* userId */); final ActivityRecord activity1 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task1); @@ -460,7 +460,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { activity2.setVisible(false); activity2.mVisibleRequested = true; - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final Task task2 = createTaskInStack(stack2, 0 /* userId */); final ActivityRecord activity3 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task2); @@ -493,7 +493,7 @@ public class AppTransitionControllerTest extends WindowTestsBase { // [DisplayContent] - [TaskStack] -+- [Task1] - [ActivityRecord1] (opening, invisible) // +- [Task2] - [ActivityRecord2] (closing, visible) - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); final ActivityRecord activity1 = WindowTestUtils.createActivityRecordInTask( mDisplayContent, task1); diff --git a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java index 8c8fd0516623..17914e7fb68c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java @@ -47,7 +47,6 @@ import android.view.RemoteAnimationAdapter; import android.view.RemoteAnimationTarget; import android.view.WindowManager; -import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; import org.junit.Before; @@ -150,7 +149,7 @@ public class AppTransitionTests extends WindowTestsBase { final DisplayContent dc1 = createNewDisplay(Display.STATE_ON); final DisplayContent dc2 = createNewDisplay(Display.STATE_ON); - final ActivityStack stack1 = createTaskStackOnDisplay(dc1); + final Task stack1 = createTaskStackOnDisplay(dc1); final Task task1 = createTaskInStack(stack1, 0 /* userId */); final ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(dc1); diff --git a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java index c8b668bac455..97a2ebe98abb 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java @@ -82,7 +82,7 @@ import java.util.ArrayList; @RunWith(WindowTestRunner.class) public class AppWindowTokenTests extends WindowTestsBase { - ActivityStack mStack; + Task mStack; Task mTask; ActivityRecord mActivity; @@ -484,7 +484,7 @@ public class AppWindowTokenTests extends WindowTestsBase { } private ActivityRecord createIsolatedTestActivityRecord() { - final ActivityStack taskStack = createTaskStackOnDisplay(mDisplayContent); + final Task taskStack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(taskStack, 0 /* userId */); return createTestActivityRecordForGivenTask(task); } diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java b/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java index ce0aa79f2d89..4abb6059cc59 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java @@ -531,7 +531,7 @@ public class DisplayAreaPolicyBuilderTest { private Map<DisplayArea<?>, Set<Integer>> calculateZSets( DisplayAreaPolicyBuilder.Result policy, DisplayArea<WindowContainer> ime, - DisplayArea<ActivityStack> tasks) { + DisplayArea<Task> tasks) { Map<DisplayArea<?>, Set<Integer>> zSets = new HashMap<>(); int[] types = {TYPE_STATUS_BAR, TYPE_NAVIGATION_BAR, TYPE_PRESENTATION, TYPE_APPLICATION_OVERLAY}; diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyTests.java index d75b35a3db79..39bf8eb857b0 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyTests.java @@ -94,9 +94,9 @@ public class DisplayAreaPolicyTests { @Test public void testTaskDisplayArea_taskPositionChanged_updatesTaskDisplayAreaPosition() { - final ActivityStack stack1 = mTaskDisplayArea1.createStack( + final Task stack1 = mTaskDisplayArea1.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack stack2 = mTaskDisplayArea2.createStack( + final Task stack2 = mTaskDisplayArea2.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Initial order @@ -155,11 +155,11 @@ public class DisplayAreaPolicyTests { .addDisplayAreaGroupHierarchy(new DisplayAreaPolicyBuilder.HierarchyBuilder(group2) .setTaskDisplayAreas(Lists.newArrayList(taskDisplayArea5))) .build(wms); - final ActivityStack stack1 = taskDisplayArea1.createStack( + final Task stack1 = taskDisplayArea1.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack stack3 = taskDisplayArea3.createStack( + final Task stack3 = taskDisplayArea3.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack stack4 = taskDisplayArea4.createStack( + final Task stack4 = taskDisplayArea4.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Initial order diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java index f7b7b584fae5..a7e0dd4e674e 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -144,7 +144,7 @@ public class DisplayContentTests extends WindowTestsBase { waitUntilHandlersIdle(); exitingApp.mIsExiting = true; - exitingApp.getTask().getStack().mExitingActivities.add(exitingApp); + exitingApp.getTask().getRootTask().mExitingActivities.add(exitingApp); assertForAllWindowsOrder(Arrays.asList( mWallpaperWindow, @@ -321,7 +321,7 @@ public class DisplayContentTests extends WindowTestsBase { final DisplayContent dc = createNewDisplay(); // Add stack with activity. - final ActivityStack stack = createTaskStackOnDisplay(dc); + final Task stack = createTaskStackOnDisplay(dc); assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId()); assertEquals(dc, stack.getDisplayContent()); @@ -395,7 +395,7 @@ public class DisplayContentTests extends WindowTestsBase { final DisplayContent dc1 = createNewDisplay(); // Add stack with activity. - final ActivityStack stack0 = createTaskStackOnDisplay(dc0); + final Task stack0 = createTaskStackOnDisplay(dc0); final Task task0 = createTaskInStack(stack0, 0 /* userId */); final ActivityRecord activity = WindowTestUtils.createTestActivityRecord(dc0); @@ -403,7 +403,7 @@ public class DisplayContentTests extends WindowTestsBase { dc0.configureDisplayPolicy(); assertNotNull(dc0.mTapDetector); - final ActivityStack stack1 = createTaskStackOnDisplay(dc1); + final Task stack1 = createTaskStackOnDisplay(dc1); final Task task1 = createTaskInStack(stack1, 0 /* userId */); final ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(dc0); @@ -849,13 +849,13 @@ public class DisplayContentTests extends WindowTestsBase { dc.getDisplayRotation().setFixedToUserRotation( IWindowManager.FIXED_TO_USER_ROTATION_DISABLED); - final ActivityStack stack = + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mAtmService.mRootWindowContainer) .setDisplay(dc) .build(); doReturn(true).when(stack).isVisible(); - final ActivityStack freeformStack = + final Task freeformStack = new ActivityTestsBase.StackBuilder(mWm.mAtmService.mRootWindowContainer) .setDisplay(dc) .setWindowingMode(WINDOWING_MODE_FREEFORM) @@ -881,7 +881,7 @@ public class DisplayContentTests extends WindowTestsBase { IWindowManager.FIXED_TO_USER_ROTATION_DISABLED); final int newOrientation = getRotatedOrientation(dc); - final ActivityStack stack = + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mAtmService.mRootWindowContainer) .setDisplay(dc).build(); final ActivityRecord activity = stack.getTopMostTask().getTopNonFinishingActivity(); @@ -901,7 +901,7 @@ public class DisplayContentTests extends WindowTestsBase { IWindowManager.FIXED_TO_USER_ROTATION_ENABLED); final int newOrientation = getRotatedOrientation(dc); - final ActivityStack stack = + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mAtmService.mRootWindowContainer) .setDisplay(dc).build(); final ActivityRecord activity = stack.getTopMostTask().getTopNonFinishingActivity(); @@ -1337,7 +1337,7 @@ public class DisplayContentTests extends WindowTestsBase { // Leave PiP to fullscreen. The orientation can be updated from // ActivityRecord#reportDescendantOrientationChangeIfNeeded. pinnedTask.setWindowingMode(WINDOWING_MODE_FULLSCREEN); - homeActivity.setState(ActivityStack.ActivityState.STOPPED, "test"); + homeActivity.setState(Task.ActivityState.STOPPED, "test"); assertFalse(displayContent.hasTopFixedRotationLaunchingApp()); verify(mWm, atLeastOnce()).startFreezingDisplay(anyInt(), anyInt(), any(), anyInt()); @@ -1445,7 +1445,7 @@ public class DisplayContentTests extends WindowTestsBase { TaskDisplayArea defaultTaskDisplayArea = mWm.mRoot.getDefaultTaskDisplayArea(); // Remove the current home stack if it exists so a new one can be created below. - ActivityStack homeTask = defaultTaskDisplayArea.getRootHomeTask(); + Task homeTask = defaultTaskDisplayArea.getRootHomeTask(); if (homeTask != null) { defaultTaskDisplayArea.removeChild(homeTask); } @@ -1461,7 +1461,7 @@ public class DisplayContentTests extends WindowTestsBase { // Remove the current home stack if it exists so a new one can be created below. TaskDisplayArea taskDisplayArea = display.getDefaultTaskDisplayArea(); - ActivityStack homeTask = taskDisplayArea.getRootHomeTask(); + Task homeTask = taskDisplayArea.getRootHomeTask(); if (homeTask != null) { taskDisplayArea.removeChild(homeTask); } @@ -1493,7 +1493,7 @@ public class DisplayContentTests extends WindowTestsBase { @Test public void testFindScrollCaptureTargetWindow_behindWindow() { DisplayContent display = createNewDisplay(); - ActivityStack stack = createTaskStackOnDisplay(display); + Task stack = createTaskStackOnDisplay(display); Task task = createTaskInStack(stack, 0 /* userId */); WindowState activityWindow = createAppWindow(task, TYPE_APPLICATION, "App Window"); WindowState behindWindow = createWindow(null, TYPE_SCREENSHOT, display, "Screenshot"); @@ -1506,7 +1506,7 @@ public class DisplayContentTests extends WindowTestsBase { @Test public void testFindScrollCaptureTargetWindow_taskId() { DisplayContent display = createNewDisplay(); - ActivityStack stack = createTaskStackOnDisplay(display); + Task stack = createTaskStackOnDisplay(display); Task task = createTaskInStack(stack, 0 /* userId */); WindowState window = createAppWindow(task, TYPE_APPLICATION, "App Window"); WindowState behindWindow = createWindow(null, TYPE_SCREENSHOT, display, "Screenshot"); @@ -1533,7 +1533,7 @@ public class DisplayContentTests extends WindowTestsBase { @Test public void testSetWindowingModeAtomicallyUpdatesWindoingModeAndDisplayWindowingMode() { final DisplayContent dc = createNewDisplay(); - final ActivityStack stack = + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mAtmService.mRootWindowContainer) .setDisplay(dc) .build(); diff --git a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java index 0eee3ca53c7d..e18d93d82686 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java @@ -40,7 +40,6 @@ import android.view.SurfaceControl; import android.view.SurfaceSession; import android.view.View; -import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; import com.android.server.LocalServices; @@ -98,7 +97,7 @@ public class DragDropControllerTests extends WindowTestsBase { private WindowState createDropTargetWindow(String name, int ownerId) { final ActivityRecord activity = WindowTestUtils.createTestActivityRecord( mDisplayContent); - final ActivityStack stack = createTaskStackOnDisplay( + final Task stack = createTaskStackOnDisplay( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, mDisplayContent); final Task task = createTaskInStack(stack, ownerId); task.addChild(activity, 0); diff --git a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsControllerTests.java index 61de7d83fa1a..a7a8505e336d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsControllerTests.java @@ -309,12 +309,12 @@ public class LaunchParamsControllerTests extends ActivityTestsBase { mController.registerModifier(positioner); - final int beforeWindowMode = task.getStack().getWindowingMode(); + final int beforeWindowMode = task.getRootTask().getWindowingMode(); assertNotEquals(windowingMode, beforeWindowMode); mController.layoutTask(task, null /* windowLayout */); - final int afterWindowMode = task.getStack().getWindowingMode(); + final int afterWindowMode = task.getRootTask().getWindowingMode(); assertEquals(windowingMode, afterWindowMode); } diff --git a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java index 9bf86d2c4704..e389a538f25d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java @@ -114,7 +114,7 @@ public class LaunchParamsPersisterTests extends ActivityTestsBase { when(mRootWindowContainer.getDisplayContent(eq(mDisplayUniqueId))) .thenReturn(mTestDisplay); - ActivityStack stack = mTestDisplay.getDefaultTaskDisplayArea() + Task stack = mTestDisplay.getDefaultTaskDisplayArea() .createStack(TEST_WINDOWING_MODE, ACTIVITY_TYPE_STANDARD, /* onTop */ true); mTestTask = new TaskBuilder(mSupervisor).setComponent(TEST_COMPONENT).setStack(stack) .build(); @@ -337,7 +337,7 @@ public class LaunchParamsPersisterTests extends ActivityTestsBase { public void testClearsRecordsOfTheUserOnUserCleanUp() { mTarget.saveTask(mTestTask); - ActivityStack stack = mTestDisplay.getDefaultTaskDisplayArea().createStack( + Task stack = mTestDisplay.getDefaultTaskDisplayArea().createStack( TEST_WINDOWING_MODE, ACTIVITY_TYPE_STANDARD, /* onTop */ true); final Task anotherTaskOfTheSameUser = new TaskBuilder(mSupervisor) .setComponent(ALTERNATIVE_COMPONENT) diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java index fd169018782b..1724303633d9 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java @@ -105,7 +105,7 @@ public class RecentTasksTest extends ActivityTestsBase { private static final int INVALID_STACK_ID = 999; private TaskDisplayArea mTaskContainer; - private ActivityStack mStack; + private Task mStack; private TestTaskPersister mTaskPersister; private TestRecentTasks mRecentTasks; private TestRunningTasks mRunningTasks; @@ -829,7 +829,7 @@ public class RecentTasksTest extends ActivityTestsBase { mRecentTasks.add(mTasks.get(2)); mRecentTasks.add(mTasks.get(1)); - ActivityStack stack = mTasks.get(2).getStack(); + Task stack = mTasks.get(2).getRootTask(); stack.moveToFront("", mTasks.get(2)); doReturn(stack).when(mService.mRootWindowContainer).getTopDisplayFocusedStack(); @@ -850,8 +850,8 @@ public class RecentTasksTest extends ActivityTestsBase { public void testBackStackTasks_expectNoTrim() { mRecentTasks.setParameters(-1 /* min */, 1 /* max */, -1 /* ms */); - final ActivityStack homeStack = mTaskContainer.getRootHomeTask(); - final ActivityStack aboveHomeStack = mTaskContainer.createStack( + final Task homeStack = mTaskContainer.getRootHomeTask(); + final Task aboveHomeStack = mTaskContainer.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Add a number of tasks (beyond the max) but ensure that nothing is trimmed because all @@ -868,10 +868,10 @@ public class RecentTasksTest extends ActivityTestsBase { public void testBehindHomeStackTasks_expectTaskTrimmed() { mRecentTasks.setParameters(-1 /* min */, 1 /* max */, -1 /* ms */); - final ActivityStack behindHomeStack = mTaskContainer.createStack( + final Task behindHomeStack = mTaskContainer.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); - final ActivityStack homeStack = mTaskContainer.getRootHomeTask(); - final ActivityStack aboveHomeStack = mTaskContainer.createStack( + final Task homeStack = mTaskContainer.getRootHomeTask(); + final Task aboveHomeStack = mTaskContainer.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Add a number of tasks (beyond the max) but ensure that only the task in the stack behind @@ -890,9 +890,9 @@ public class RecentTasksTest extends ActivityTestsBase { public void testOtherDisplayTasks_expectNoTrim() { mRecentTasks.setParameters(-1 /* min */, 1 /* max */, -1 /* ms */); - final ActivityStack homeStack = mTaskContainer.getRootHomeTask(); + final Task homeStack = mTaskContainer.getRootHomeTask(); final DisplayContent otherDisplay = addNewDisplayContentAt(DisplayContent.POSITION_TOP); - final ActivityStack otherDisplayStack = otherDisplay.getDefaultTaskDisplayArea() + final Task otherDisplayStack = otherDisplay.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); // Add a number of tasks (beyond the max) on each display, ensure that the tasks are not diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java index 4fbdd616dc93..695a0e3881ea 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java @@ -92,7 +92,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { @Mock RecentsAnimationController.RecentsAnimationCallbacks mAnimationCallbacks; @Mock TaskSnapshot mMockTaskSnapshot; private RecentsAnimationController mController; - private ActivityStack mRootHomeTask; + private Task mRootHomeTask; @Before public void setUp() throws Exception { diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationTest.java index 44ca2cdcb142..e3cfe11df99f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationTest.java @@ -31,8 +31,8 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; +import static com.android.server.wm.Task.ActivityState.PAUSED; import static com.google.common.truth.Truth.assertThat; @@ -88,7 +88,7 @@ public class RecentsAnimationTest extends ActivityTestsBase { @Test public void testRecentsActivityVisiblility() { TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); ActivityRecord recentActivity = new ActivityBuilder(mService) .setComponent(mRecentsComponent) @@ -116,7 +116,7 @@ public class RecentsAnimationTest extends ActivityTestsBase { @Test public void testPreloadRecentsActivity() { TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack homeStack = + final Task homeStack = defaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); defaultTaskDisplayArea.positionStackAtTop(homeStack, false /* includingParents */); ActivityRecord topRunningHomeActivity = homeStack.topRunningActivity(); @@ -148,7 +148,7 @@ public class RecentsAnimationTest extends ActivityTestsBase { mService.startRecentsActivity(recentsIntent, null /* assistDataReceiver */, null /* recentsAnimationRunner */); - ActivityStack recentsStack = defaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN, + Task recentsStack = defaultTaskDisplayArea.getStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS); assertThat(recentsStack).isNotNull(); @@ -177,7 +177,7 @@ public class RecentsAnimationTest extends ActivityTestsBase { public void testRestartRecentsActivity() throws Exception { // Have a recents activity that is not attached to its process (ActivityRecord.app = null). TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack recentsStack = defaultTaskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task recentsStack = defaultTaskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); ActivityRecord recentActivity = new ActivityBuilder(mService).setComponent( mRecentsComponent).setCreateTask(true).setStack(recentsStack).build(); @@ -206,7 +206,7 @@ public class RecentsAnimationTest extends ActivityTestsBase { @Test public void testSetLaunchTaskBehindOfTargetActivity() { TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack homeStack = taskDisplayArea.getRootHomeTask(); + Task homeStack = taskDisplayArea.getRootHomeTask(); // Assume the home activity support recents. ActivityRecord targetActivity = homeStack.getTopNonFinishingActivity(); if (targetActivity == null) { @@ -248,21 +248,21 @@ public class RecentsAnimationTest extends ActivityTestsBase { @Test public void testCancelAnimationOnVisibleStackOrderChange() { TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); new ActivityBuilder(mService) .setComponent(new ComponentName(mContext.getPackageName(), "App1")) .setCreateTask(true) .setStack(fullscreenStack) .build(); - ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); new ActivityBuilder(mService) .setComponent(mRecentsComponent) .setCreateTask(true) .setStack(recentsStack) .build(); - ActivityStack fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); new ActivityBuilder(mService) .setComponent(new ComponentName(mContext.getPackageName(), "App2")) @@ -289,21 +289,21 @@ public class RecentsAnimationTest extends ActivityTestsBase { @Test public void testKeepAnimationOnHiddenStackOrderChange() { TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); new ActivityBuilder(mService) .setComponent(new ComponentName(mContext.getPackageName(), "App1")) .setCreateTask(true) .setStack(fullscreenStack) .build(); - ActivityStack recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task recentsStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); new ActivityBuilder(mService) .setComponent(mRecentsComponent) .setCreateTask(true) .setStack(recentsStack) .build(); - ActivityStack fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task fullscreenStack2 = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); new ActivityBuilder(mService) .setComponent(new ComponentName(mContext.getPackageName(), "App2")) @@ -326,7 +326,7 @@ public class RecentsAnimationTest extends ActivityTestsBase { public void testMultipleUserHomeActivity_findUserHomeTask() { TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultDisplay() .getDefaultTaskDisplayArea(); - ActivityStack homeStack = taskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED, + Task homeStack = taskDisplayArea.getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME); ActivityRecord otherUserHomeActivity = new ActivityBuilder(mService) .setStack(homeStack) @@ -335,7 +335,7 @@ public class RecentsAnimationTest extends ActivityTestsBase { .build(); otherUserHomeActivity.getTask().mUserId = TEST_USER_ID; - ActivityStack fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task fullscreenStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); new ActivityBuilder(mService) .setComponent(new ComponentName(mContext.getPackageName(), "App1")) diff --git a/services/tests/wmtests/src/com/android/server/wm/RootActivityContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootActivityContainerTests.java index d53c89628d93..3a5d33396c3a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RootActivityContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/RootActivityContainerTests.java @@ -37,9 +37,9 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; +import static com.android.server.wm.Task.ActivityState.STOPPED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -68,7 +68,7 @@ import android.util.Pair; import androidx.test.filters.MediumTest; import com.android.internal.app.ResolverActivity; -import com.android.server.wm.ActivityStack.ActivityState; +import com.android.server.wm.Task.ActivityState; import org.junit.Before; import org.junit.Test; @@ -89,7 +89,7 @@ import java.util.function.Consumer; @Presubmit @RunWith(WindowTestRunner.class) public class RootActivityContainerTests extends ActivityTestsBase { - private ActivityStack mFullscreenStack; + private Task mFullscreenStack; @Before public void setUp() throws Exception { @@ -132,7 +132,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { mRootWindowContainer.moveActivityToPinnedStack(firstActivity, "initialMove"); final TaskDisplayArea taskDisplayArea = mFullscreenStack.getDisplayArea(); - ActivityStack pinnedStack = taskDisplayArea.getRootPinnedTask(); + Task pinnedStack = taskDisplayArea.getRootPinnedTask(); // Ensure a task has moved over. ensureStackPlacement(pinnedStack, firstActivity); ensureStackPlacement(mFullscreenStack, secondActivity); @@ -172,7 +172,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { assertTrue(firstActivity.mRequestForceTransition); } - private static void ensureStackPlacement(ActivityStack stack, ActivityRecord... activities) { + private static void ensureStackPlacement(Task stack, ActivityRecord... activities) { final Task task = stack.getBottomMostTask(); final ArrayList<ActivityRecord> stackActivities = new ArrayList<>(); @@ -194,7 +194,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { public void testApplySleepTokens() { final DisplayContent display = mRootWindowContainer.getDefaultDisplay(); final KeyguardController keyguard = mSupervisor.getKeyguardController(); - final ActivityStack stack = new StackBuilder(mRootWindowContainer) + final Task stack = new StackBuilder(mRootWindowContainer) .setCreateActivity(false) .setDisplay(display) .setOnTop(false) @@ -229,7 +229,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { } private void verifySleepTokenBehavior(DisplayContent display, KeyguardController keyguard, - ActivityStack stack, boolean displaySleeping, boolean displayShouldSleep, + Task stack, boolean displaySleeping, boolean displayShouldSleep, boolean isFocusedStack, boolean keyguardShowing, boolean expectWakeFromSleep, boolean expectResumeTopActivity) { reset(stack); @@ -285,7 +285,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { final TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer .getDefaultTaskDisplayArea(); final int originalStackCount = defaultTaskDisplayArea.getStackCount(); - final ActivityStack stack = defaultTaskDisplayArea.createStack( + final Task stack = defaultTaskDisplayArea.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */); final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(stack).build(); @@ -309,7 +309,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { final TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer .getDefaultTaskDisplayArea(); final int originalStackCount = defaultTaskDisplayArea.getStackCount(); - final ActivityStack stack = defaultTaskDisplayArea.createStack( + final Task stack = defaultTaskDisplayArea.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */); final ActivityRecord firstActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(stack).build(); @@ -318,7 +318,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { final DisplayContent dc = defaultTaskDisplayArea.getDisplayContent(); final TaskDisplayArea secondTaskDisplayArea = WindowTestsBase.createTaskDisplayArea(dc, mRootWindowContainer.mWmService, "TestTaskDisplayArea", FEATURE_VENDOR_FIRST); - final ActivityStack secondStack = secondTaskDisplayArea.createStack( + final Task secondStack = secondTaskDisplayArea.createStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */); new ActivityBuilder(mService).setCreateTask(true).setStack(secondStack) .setUseProcess(firstActivity.app).build(); @@ -337,7 +337,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { public void testFocusability() { final TaskDisplayArea defaultTaskDisplayArea = mRootWindowContainer .getDefaultTaskDisplayArea(); - final ActivityStack stack = defaultTaskDisplayArea.createStack( + final Task stack = defaultTaskDisplayArea.createStack( WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); final ActivityRecord activity = new ActivityBuilder(mService).setCreateTask(true) .setStack(stack).build(); @@ -351,7 +351,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { assertFalse(stack.isTopActivityFocusable()); assertFalse(activity.isFocusable()); - final ActivityStack pinnedStack = defaultTaskDisplayArea.createStack( + final Task pinnedStack = defaultTaskDisplayArea.createStack( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */); final ActivityRecord pinnedActivity = new ActivityBuilder(mService).setCreateTask(true) .setStack(pinnedStack).build(); @@ -380,7 +380,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { @Test public void testSplitScreenPrimaryChosenWhenTopActivityLaunchedToSecondary() { // Create primary split-screen stack with a task and an activity. - final ActivityStack primaryStack = mRootWindowContainer.getDefaultTaskDisplayArea() + final Task primaryStack = mRootWindowContainer.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, true /* onTop */); final Task task = new TaskBuilder(mSupervisor).setStack(primaryStack).build(); @@ -390,7 +390,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { // split-screen secondary. final ActivityOptions options = ActivityOptions.makeBasic(); options.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY); - final ActivityStack result = + final Task result = mRootWindowContainer.getLaunchStack(r, options, task, true /* onTop */); // Assert that the primary stack is returned. @@ -403,13 +403,13 @@ public class RootActivityContainerTests extends ActivityTestsBase { @Test public void testFindTaskToMoveToFrontWhenRecentsOnTop() { // Create stack/task on default display. - final ActivityStack targetStack = new StackBuilder(mRootWindowContainer) + final Task targetStack = new StackBuilder(mRootWindowContainer) .setOnTop(false) .build(); final Task targetTask = targetStack.getBottomMostTask(); // Create Recents on top of the display. - final ActivityStack stack = new StackBuilder(mRootWindowContainer).setActivityType( + final Task stack = new StackBuilder(mRootWindowContainer).setActivityType( ACTIVITY_TYPE_RECENTS).build(); final String reason = "findTaskToMoveToFront"; @@ -428,14 +428,14 @@ public class RootActivityContainerTests extends ActivityTestsBase { public void testFindTaskToMoveToFrontWhenRecentsOnOtherDisplay() { // Create stack/task on default display. final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack targetStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task targetStack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */); final Task targetTask = new TaskBuilder(mSupervisor).setStack(targetStack).build(); // Create Recents on secondary display. final TestDisplayContent secondDisplay = addNewDisplayContentAt( DisplayContent.POSITION_TOP); - final ActivityStack stack = secondDisplay.getDefaultTaskDisplayArea() + final Task stack = secondDisplay.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); final Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); new ActivityBuilder(mService).setTask(task).build(); @@ -455,7 +455,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { public void testResumeActivityWhenNonTopmostStackIsTopFocused() { // Create a stack at bottom. final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack targetStack = spy(taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task targetStack = spy(taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */)); final Task task = new TaskBuilder(mSupervisor).setStack(targetStack).build(); final ActivityRecord activity = new ActivityBuilder(mService).setTask(task).build(); @@ -511,7 +511,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { // Create an activity on secondary display. final TestDisplayContent secondDisplay = addNewDisplayContentAt( DisplayContent.POSITION_TOP); - final ActivityStack stack = secondDisplay.getDefaultTaskDisplayArea() + final Task stack = secondDisplay.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); final Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); new ActivityBuilder(mService).setTask(task).build(); @@ -535,7 +535,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { public void testResumeActivityLingeringTransition() { // Create a stack at top. final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack targetStack = spy(taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task targetStack = spy(taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */)); final Task task = new TaskBuilder(mSupervisor).setStack(targetStack).build(); final ActivityRecord activity = new ActivityBuilder(mService).setTask(task).build(); @@ -555,7 +555,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { public void testResumeActivityLingeringTransition_notExecuted() { // Create a stack at bottom. final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack targetStack = spy(taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + final Task targetStack = spy(taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, false /* onTop */)); final Task task = new TaskBuilder(mSupervisor).setStack(targetStack).build(); final ActivityRecord activity = new ActivityBuilder(mService).setTask(task).build(); @@ -868,7 +868,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { options.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); doReturn(true).when(mSupervisor).canPlaceEntityOnDisplay(secondaryDisplay.mDisplayId, 300 /* test realCallerPid */, 300 /* test realCallerUid */, r.info); - final ActivityStack result = mRootWindowContainer.getLaunchStack(r, options, + final Task result = mRootWindowContainer.getLaunchStack(r, options, null /* task */, true /* onTop */, null, 300 /* test realCallerPid */, 300 /* test realCallerUid */); @@ -889,7 +889,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { .setTask(task).build(); // Make sure the root task is valid and can be reused on default display. - final ActivityStack stack = mRootWindowContainer.getValidLaunchStackInTaskDisplayArea( + final Task stack = mRootWindowContainer.getValidLaunchStackInTaskDisplayArea( mRootWindowContainer.getDefaultTaskDisplayArea(), activity, task, null, null); assertEquals(task, stack); @@ -900,7 +900,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { doReturn(mFullscreenStack).when(mRootWindowContainer).getTopDisplayFocusedStack(); final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack homeStack = taskDisplayArea.getRootHomeTask(); + Task homeStack = taskDisplayArea.getRootHomeTask(); if (homeStack != null) { homeStack.removeImmediately(); } @@ -920,7 +920,7 @@ public class RootActivityContainerTests extends ActivityTestsBase { // Create an activity on secondary display. final TestDisplayContent secondDisplay = addNewDisplayContentAt( DisplayContent.POSITION_TOP); - final ActivityStack stack = secondDisplay.getDefaultTaskDisplayArea() + final Task stack = secondDisplay.getDefaultTaskDisplayArea() .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); final ActivityRecord activity = new ActivityBuilder(mService).setStack(stack).build(); spyOn(activity); diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java index 181de8e2a1a3..0b8db17e058b 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java @@ -25,11 +25,11 @@ import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE; import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; import static android.view.WindowManager.LayoutParams.TYPE_TOAST; -import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; -import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; +import static com.android.server.wm.Task.ActivityState.FINISHING; +import static com.android.server.wm.Task.ActivityState.PAUSED; +import static com.android.server.wm.Task.ActivityState.PAUSING; +import static com.android.server.wm.Task.ActivityState.STOPPED; +import static com.android.server.wm.Task.ActivityState.STOPPING; import static com.google.common.truth.Truth.assertThat; @@ -149,7 +149,7 @@ public class RootWindowContainerTests extends WindowTestsBase { public void testAllPausedActivitiesComplete() { DisplayContent displayContent = mWm.mRoot.getDisplayContent(DEFAULT_DISPLAY); TaskDisplayArea taskDisplayArea = displayContent.getDefaultTaskDisplayArea(); - ActivityStack stack = taskDisplayArea.getStackAt(0); + Task stack = taskDisplayArea.getStackAt(0); ActivityRecord activity = createActivityRecord(displayContent, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); stack.mPausingActivity = activity; diff --git a/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java b/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java index 3d3a0f148db5..e51a133d5cce 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/RunningTasksTest.java @@ -62,7 +62,7 @@ public class RunningTasksTest extends ActivityTestsBase { final int numStacks = 2; for (int stackIndex = 0; stackIndex < numStacks; stackIndex++) { - final ActivityStack stack = new StackBuilder(mRootWindowContainer) + final Task stack = new StackBuilder(mRootWindowContainer) .setCreateActivity(false) .setDisplay(display) .setOnTop(false) @@ -104,7 +104,7 @@ public class RunningTasksTest extends ActivityTestsBase { final DisplayContent display = new TestDisplayContent.Builder(mService, 1000, 2500).build(); final int numTasks = 10; for (int i = 0; i < numTasks; i++) { - final ActivityStack stack = new StackBuilder(mRootWindowContainer) + final Task stack = new StackBuilder(mRootWindowContainer) .setCreateActivity(false) .setDisplay(display) .setOnTop(true) @@ -130,7 +130,7 @@ public class RunningTasksTest extends ActivityTestsBase { /** * Create a task with a single activity in it, with the given last active time. */ - private Task createTask(ActivityStack stack, String className, int taskId, + private Task createTask(Task stack, String className, int taskId, int lastActiveTime, Bundle extras) { final Task task = new TaskBuilder(mService.mStackSupervisor) .setComponent(new ComponentName(mContext.getPackageName(), className)) diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index a979c862a8e4..250cf09e8547 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -29,7 +29,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; -import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; +import static com.android.server.wm.Task.ActivityState.STOPPED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -65,7 +65,7 @@ import java.util.ArrayList; @Presubmit @RunWith(WindowTestRunner.class) public class SizeCompatTests extends ActivityTestsBase { - private ActivityStack mStack; + private Task mStack; private Task mTask; private ActivityRecord mActivity; @@ -86,7 +86,7 @@ public class SizeCompatTests extends ActivityTestsBase { doNothing().when(mSupervisor).scheduleRestartTimeout(mActivity); mActivity.mVisibleRequested = true; mActivity.setSavedState(null /* savedState */); - mActivity.setState(ActivityStack.ActivityState.RESUMED, "testRestart"); + mActivity.setState(Task.ActivityState.RESUMED, "testRestart"); prepareUnresizable(1.5f /* maxAspect */, SCREEN_ORIENTATION_UNSPECIFIED); final Rect originalOverrideBounds = new Rect(mActivity.getBounds()); @@ -94,7 +94,7 @@ public class SizeCompatTests extends ActivityTestsBase { // The visible activity should recompute configuration according to the last parent bounds. mService.restartActivityProcessIfVisible(mActivity.appToken); - assertEquals(ActivityStack.ActivityState.RESTARTING_PROCESS, mActivity.getState()); + assertEquals(Task.ActivityState.RESTARTING_PROCESS, mActivity.getState()); assertNotEquals(originalOverrideBounds, mActivity.getBounds()); } @@ -449,7 +449,7 @@ public class SizeCompatTests extends ActivityTestsBase { public void testHandleActivitySizeCompatMode() { setUpDisplaySizeWithApp(1000, 2000); ActivityRecord activity = mActivity; - activity.setState(ActivityStack.ActivityState.RESUMED, "testHandleActivitySizeCompatMode"); + activity.setState(Task.ActivityState.RESUMED, "testHandleActivitySizeCompatMode"); prepareUnresizable(-1.f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT); assertFitted(); @@ -476,7 +476,7 @@ public class SizeCompatTests extends ActivityTestsBase { activity.mVisibleRequested = true; activity.restartProcessIfVisible(); // The full lifecycle isn't hooked up so manually set state to resumed - activity.setState(ActivityStack.ActivityState.RESUMED, "testHandleActivitySizeCompatMode"); + activity.setState(Task.ActivityState.RESUMED, "testHandleActivitySizeCompatMode"); mStack.getDisplay().handleActivitySizeCompatModeIfNeeded(activity); // Expect null token when switching to non-size-compat mode activity. diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java index 50675b03ae1f..eb7d9c2d3c32 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java +++ b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java @@ -319,7 +319,7 @@ public class SystemServicesTestRule implements TestRule { spyOn(display); final TaskDisplayArea taskDisplayArea = display.getDefaultTaskDisplayArea(); spyOn(taskDisplayArea); - final ActivityStack homeStack = taskDisplayArea.getStack( + final Task homeStack = taskDisplayArea.getStack( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME); spyOn(homeStack); } diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java index 8c3661b409f4..27a8fc3c5943 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java @@ -32,7 +32,7 @@ import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; -import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; +import static com.android.server.wm.Task.ActivityState.RESUMED; import static com.google.common.truth.Truth.assertThat; @@ -67,7 +67,7 @@ import org.junit.runner.RunWith; @RunWith(WindowTestRunner.class) public class TaskDisplayAreaTests extends WindowTestsBase { - private ActivityStack mPinnedStack; + private Task mPinnedStack; @Before public void setUp() throws Exception { @@ -89,7 +89,7 @@ public class TaskDisplayAreaTests extends WindowTestsBase { @Test public void testActivityWithZBoost_taskDisplayAreaDoesNotMoveUp() { - final ActivityStack stack = createTaskStackOnDisplay( + final Task stack = createTaskStackOnDisplay( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); final ActivityRecord activity = WindowTestUtils.createTestActivityRecord(mDisplayContent); @@ -109,8 +109,8 @@ public class TaskDisplayAreaTests extends WindowTestsBase { @Test public void testStackPositionChildAt() { // Test that always-on-top stack can't be moved to position other than top. - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); - final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack2 = createTaskStackOnDisplay(mDisplayContent); final WindowContainer taskStackContainer = stack1.getParent(); @@ -134,7 +134,7 @@ public class TaskDisplayAreaTests extends WindowTestsBase { @Test public void testStackPositionBelowPinnedStack() { // Test that no stack can be above pinned stack. - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final WindowContainer taskStackContainer = stack1.getParent(); @@ -158,7 +158,7 @@ public class TaskDisplayAreaTests extends WindowTestsBase { doReturn(true).when(mDisplayContent).isTrusted(); // The display contains pinned stack that was added in {@link #setUp}. - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); // Add another display at top. @@ -216,10 +216,10 @@ public class TaskDisplayAreaTests extends WindowTestsBase { final TaskDisplayArea defaultTaskDisplayArea = rootWindowContainer.getDefaultTaskDisplayArea(); - final ActivityStack rootHomeTask = defaultTaskDisplayArea.getRootHomeTask(); + final Task rootHomeTask = defaultTaskDisplayArea.getRootHomeTask(); rootHomeTask.mResizeMode = RESIZE_MODE_UNRESIZEABLE; - final ActivityStack primarySplitTask = + final Task primarySplitTask = new ActivityTestsBase.StackBuilder(rootWindowContainer) .setTaskDisplayArea(defaultTaskDisplayArea) .setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) @@ -247,7 +247,7 @@ public class TaskDisplayAreaTests extends WindowTestsBase { private void assertGetOrCreateStack(int windowingMode, int activityType, Task candidateTask, boolean reuseCandidate) { final TaskDisplayArea taskDisplayArea = candidateTask.getDisplayArea(); - final ActivityStack stack = taskDisplayArea.getOrCreateStack(windowingMode, activityType, + final Task stack = taskDisplayArea.getOrCreateStack(windowingMode, activityType, false /* onTop */, null /* intent */, candidateTask /* candidateTask */); assertEquals(reuseCandidate, stack == candidateTask); } diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java index a69231b9e03a..a048526bb068 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java @@ -30,7 +30,6 @@ import static android.util.DisplayMetrics.DENSITY_DEFAULT; import static android.view.Display.DEFAULT_DISPLAY; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; -import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_CONTINUE; import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_SKIP; @@ -1350,13 +1349,13 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase { } private ActivityRecord createSourceActivity(TestDisplayContent display) { - final ActivityStack stack = display.getDefaultTaskDisplayArea() + final Task stack = display.getDefaultTaskDisplayArea() .createStack(display.getWindowingMode(), ACTIVITY_TYPE_STANDARD, true); return new ActivityBuilder(mService).setStack(stack).setCreateTask(true).build(); } private void addFreeformTaskTo(TestDisplayContent display, Rect bounds) { - final ActivityStack stack = display.getDefaultTaskDisplayArea() + final Task stack = display.getDefaultTaskDisplayArea() .createStack(display.getWindowingMode(), ACTIVITY_TYPE_STANDARD, true); stack.setWindowingMode(WINDOWING_MODE_FREEFORM); final Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskPositionerTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskPositionerTests.java index 93dcc9103640..0db3f94d1fc3 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskPositionerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskPositionerTests.java @@ -37,7 +37,6 @@ import android.platform.test.annotations.Presubmit; import android.util.DisplayMetrics; import android.util.Log; -import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; import org.junit.After; @@ -77,7 +76,7 @@ public class TaskPositionerTests extends WindowTestsBase { mMinVisibleHeight = dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, dm); removeGlobalMinSizeRestriction(); - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity = new ActivityTestsBase.ActivityBuilder(stack.mAtmService) .setStack(stack) // In real case, there is no additional level for freeform mode. diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java index abdbd5131fd9..bf76c8ee5f0a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java @@ -173,7 +173,7 @@ public class TaskRecordTests extends ActivityTestsBase { public void testFitWithinBounds() { final Rect parentBounds = new Rect(10, 10, 200, 200); TaskDisplayArea taskDisplayArea = mService.mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack stack = taskDisplayArea.createStack(WINDOWING_MODE_FREEFORM, + Task stack = taskDisplayArea.createStack(WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, true /* onTop */); Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); final Configuration parentConfig = stack.getConfiguration(); @@ -211,7 +211,7 @@ public class TaskRecordTests extends ActivityTestsBase { @Test public void testBoundsOnModeChangeFreeformToFullscreen() { DisplayContent display = mService.mRootWindowContainer.getDefaultDisplay(); - ActivityStack stack = new StackBuilder(mRootWindowContainer).setDisplay(display) + Task stack = new StackBuilder(mRootWindowContainer).setDisplay(display) .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); Task task = stack.getBottomMostTask(); task.getRootActivity().setOrientation(SCREEN_ORIENTATION_UNSPECIFIED); @@ -252,7 +252,7 @@ public class TaskRecordTests extends ActivityTestsBase { dr.setFixedToUserRotation(FIXED_TO_USER_ROTATION_ENABLED); dr.setUserRotation(USER_ROTATION_FREE, ROTATION_0); - ActivityStack stack = new StackBuilder(mRootWindowContainer) + Task stack = new StackBuilder(mRootWindowContainer) .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build(); Task task = stack.getBottomMostTask(); ActivityRecord root = task.getTopNonFinishingActivity(); @@ -313,7 +313,7 @@ public class TaskRecordTests extends ActivityTestsBase { Configuration.ORIENTATION_LANDSCAPE; display.onRequestedOverrideConfigurationChanged( display.getRequestedOverrideConfiguration()); - ActivityStack stack = new StackBuilder(mRootWindowContainer) + Task stack = new StackBuilder(mRootWindowContainer) .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build(); Task task = stack.getBottomMostTask(); ActivityRecord root = task.getTopNonFinishingActivity(); @@ -324,7 +324,7 @@ public class TaskRecordTests extends ActivityTestsBase { parentWindowContainer.setBounds(fullScreenBounds); doReturn(parentWindowContainer).when(task).getParent(); doReturn(display.getDefaultTaskDisplayArea()).when(task).getDisplayArea(); - doReturn(stack).when(task).getStack(); + doReturn(stack).when(task).getRootTask(); doReturn(true).when(parentWindowContainer).handlesOrientationChangeFromDescendant(); // Setting app to fixed portrait fits within parent, but Task shouldn't adjust the @@ -409,15 +409,15 @@ public class TaskRecordTests extends ActivityTestsBase { assertTrue(task.getResolvedOverrideBounds().isEmpty()); int origScreenH = task.getConfiguration().screenHeightDp; Configuration stackConfig = new Configuration(); - stackConfig.setTo(task.getStack().getRequestedOverrideConfiguration()); + stackConfig.setTo(task.getRootTask().getRequestedOverrideConfiguration()); stackConfig.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM); // Set bounds on stack (not task) and verify that the task resource configuration changes // despite it's override bounds being empty. - Rect bounds = new Rect(task.getStack().getBounds()); + Rect bounds = new Rect(task.getRootTask().getBounds()); bounds.bottom = (int) (bounds.bottom * 0.6f); stackConfig.windowConfiguration.setBounds(bounds); - task.getStack().onRequestedOverrideConfigurationChanged(stackConfig); + task.getRootTask().onRequestedOverrideConfigurationChanged(stackConfig); assertNotEquals(origScreenH, task.getConfiguration().screenHeightDp); } @@ -439,7 +439,7 @@ public class TaskRecordTests extends ActivityTestsBase { @Test public void testInsetDisregardedWhenFreeformOverlapsNavBar() { TaskDisplayArea taskDisplayArea = mService.mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack stack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, + Task stack = taskDisplayArea.createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); DisplayInfo displayInfo = new DisplayInfo(); mService.mContext.getDisplay().getDisplayInfo(displayInfo); @@ -514,7 +514,7 @@ public class TaskRecordTests extends ActivityTestsBase { info.packageName = DEFAULT_COMPONENT_PACKAGE_NAME; info.targetActivity = targetClassName; - final Task task = new ActivityStack(mService, 1 /* taskId */, info, intent, + final Task task = new Task(mService, 1 /* taskId */, info, intent, null /* voiceSession */, null /* voiceInteractor */, null /* taskDescriptor */, null /*stack*/); assertEquals("The alias activity component should be saved in task intent.", aliasClassName, @@ -880,7 +880,7 @@ public class TaskRecordTests extends ActivityTestsBase { final Task task = getTestTask(); task.setHasBeenVisible(false); task.getDisplayContent().setDisplayWindowingMode(WINDOWING_MODE_FREEFORM); - task.getStack().setWindowingMode(WINDOWING_MODE_FULLSCREEN); + task.getRootTask().setWindowingMode(WINDOWING_MODE_FULLSCREEN); task.setHasBeenVisible(true); task.onConfigurationChanged(task.getParent().getConfiguration()); @@ -896,7 +896,7 @@ public class TaskRecordTests extends ActivityTestsBase { final Task task = getTestTask(); task.setHasBeenVisible(false); task.getDisplayContent().setWindowingMode(WindowConfiguration.WINDOWING_MODE_FREEFORM); - task.getStack().setWindowingMode(WINDOWING_MODE_FULLSCREEN); + task.getRootTask().setWindowingMode(WINDOWING_MODE_FULLSCREEN); final DisplayContent oldDisplay = task.getDisplayContent(); LaunchParamsController.LaunchParams params = new LaunchParamsController.LaunchParams(); @@ -920,7 +920,7 @@ public class TaskRecordTests extends ActivityTestsBase { final Task task = getTestTask(); task.setHasBeenVisible(false); - task.getStack().setWindowingMode(WINDOWING_MODE_FULLSCREEN); + task.getRootTask().setWindowingMode(WINDOWING_MODE_FULLSCREEN); task.setHasBeenVisible(true); task.onConfigurationChanged(task.getParent().getConfiguration()); @@ -936,7 +936,7 @@ public class TaskRecordTests extends ActivityTestsBase { final Task task = getTestTask(); task.setHasBeenVisible(false); task.getDisplayContent().setDisplayWindowingMode(WINDOWING_MODE_FREEFORM); - task.getStack().setWindowingMode(WINDOWING_MODE_PINNED); + task.getRootTask().setWindowingMode(WINDOWING_MODE_PINNED); task.setHasBeenVisible(true); task.onConfigurationChanged(task.getParent().getConfiguration()); @@ -976,7 +976,7 @@ public class TaskRecordTests extends ActivityTestsBase { } private Task getTestTask() { - final ActivityStack stack = new StackBuilder(mRootWindowContainer).build(); + final Task stack = new StackBuilder(mRootWindowContainer).build(); return stack.getBottomMostTask(); } @@ -984,7 +984,7 @@ public class TaskRecordTests extends ActivityTestsBase { Rect expectedConfigBounds) { TaskDisplayArea taskDisplayArea = mService.mRootWindowContainer.getDefaultTaskDisplayArea(); - ActivityStack stack = taskDisplayArea.createStack(windowingMode, ACTIVITY_TYPE_STANDARD, + Task stack = taskDisplayArea.createStack(windowingMode, ACTIVITY_TYPE_STANDARD, true /* onTop */); Task task = new TaskBuilder(mSupervisor).setStack(stack).build(); @@ -1024,7 +1024,7 @@ public class TaskRecordTests extends ActivityTestsBase { } private Task createTask(int taskId) { - return new ActivityStack(mService, taskId, new Intent(), null, null, null, + return new Task(mService, taskId, new Intent(), null, null, null, ActivityBuilder.getDefaultComponent(), null, false, false, false, 0, 10050, null, 0, false, null, 0, 0, 0, 0, null, null, 0, false, false, false, 0, 0, null /*ActivityInfo*/, null /*_voiceSession*/, null /*_voiceInteractor*/, diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java index f1dbde066125..205b842253b7 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskStackTests.java @@ -59,7 +59,7 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testStackPositionChildAt() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); final Task task2 = createTaskInStack(stack, 1 /* userId */); @@ -74,8 +74,8 @@ public class TaskStackTests extends WindowTestsBase { assertEquals(stack.mChildren.get(1), task1); // Non-leaf task should be moved to top regardless of the user id. - createTaskInStack((ActivityStack) task2, 0 /* userId */); - createTaskInStack((ActivityStack) task2, 1 /* userId */); + createTaskInStack(task2, 0 /* userId */); + createTaskInStack(task2, 1 /* userId */); stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */); assertEquals(stack.mChildren.get(0), task1); assertEquals(stack.mChildren.get(1), task2); @@ -83,7 +83,7 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testClosingAppDifferentStackOrientation() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(mDisplayContent); @@ -103,7 +103,7 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testMoveTaskToBackDifferentStackOrientation() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(mDisplayContent); @@ -120,9 +120,9 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testStackRemoveImmediately() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); - assertEquals(stack, task.getStack()); + assertEquals(stack, task.getRootTask()); // Remove stack and check if its child is also removed. stack.removeImmediately(); @@ -132,7 +132,7 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testRemoveContainer() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); assertNotNull(stack); @@ -148,7 +148,7 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testRemoveContainer_deferRemoval() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); // Stack removal is deferred if one of its child is animating. @@ -172,12 +172,12 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testReparent() { // Create first stack on primary display. - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack1, 0 /* userId */); // Create second display and put second stack on it. final DisplayContent dc = createNewDisplay(); - final ActivityStack stack2 = createTaskStackOnDisplay(dc); + final Task stack2 = createTaskStackOnDisplay(dc); // Reparent clearInvocations(task1); // reset the number of onDisplayChanged for task. @@ -191,7 +191,7 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testStackOutset() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final int stackOutset = 10; spyOn(stack); doReturn(stackOutset).when(stack).getTaskOutset(); @@ -219,7 +219,7 @@ public class TaskStackTests extends WindowTestsBase { @Test public void testActivityAndTaskGetsProperType() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task1 = createTaskInStack(stack, 0 /* userId */); ActivityRecord activity1 = WindowTestUtils.createTestActivityRecord(mDisplayContent); diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java index 9d88ada5a90c..039ffc464337 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java @@ -54,7 +54,7 @@ public class TaskTests extends WindowTestsBase { @Test public void testRemoveContainer() { - final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); + final Task stackController1 = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stackController1, 0 /* userId */); final ActivityRecord activity = WindowTestUtils.createActivityRecordInTask(mDisplayContent, task); @@ -68,7 +68,7 @@ public class TaskTests extends WindowTestsBase { @Test public void testRemoveContainer_deferRemoval() { - final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); + final Task stackController1 = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stackController1, 0 /* userId */); final ActivityRecord activity = WindowTestUtils.createActivityRecordInTask(mDisplayContent, task); @@ -90,9 +90,9 @@ public class TaskTests extends WindowTestsBase { @Test public void testReparent() { - final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); + final Task stackController1 = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stackController1, 0 /* userId */); - final ActivityStack stackController2 = createTaskStackOnDisplay(mDisplayContent); + final Task stackController2 = createTaskStackOnDisplay(mDisplayContent); final Task task2 = createTaskInStack(stackController2, 0 /* userId */); boolean gotException = false; @@ -120,13 +120,13 @@ public class TaskTests extends WindowTestsBase { @Test public void testReparent_BetweenDisplays() { // Create first stack on primary display. - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack1, 0 /* userId */); assertEquals(mDisplayContent, stack1.getDisplayContent()); // Create second display and put second stack on it. final DisplayContent dc = createNewDisplay(); - final ActivityStack stack2 = createTaskStackOnDisplay(dc); + final Task stack2 = createTaskStackOnDisplay(dc); final Task task2 = createTaskInStack(stack2, 0 /* userId */); // Reparent and check state clearInvocations(task); // reset the number of onDisplayChanged for task. @@ -139,7 +139,7 @@ public class TaskTests extends WindowTestsBase { @Test public void testBounds() { - final ActivityStack stack1 = createTaskStackOnDisplay(mDisplayContent); + final Task stack1 = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack1, 0 /* userId */); // Check that setting bounds also updates surface position diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java index efc03df877b7..3ebc28886377 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java @@ -808,7 +808,7 @@ public class WindowContainerTests extends WindowTestsBase { @Test public void testOnDisplayChanged() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); final ActivityRecord activity = WindowTestUtils.createActivityRecordInTask(mDisplayContent, task); @@ -852,7 +852,7 @@ public class WindowContainerTests extends WindowTestsBase { @Test public void testTaskCanApplyAnimation() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); final ActivityRecord activity2 = WindowTestUtils.createActivityRecordInTask(mDisplayContent, task); @@ -863,7 +863,7 @@ public class WindowContainerTests extends WindowTestsBase { @Test public void testStackCanApplyAnimation() { - final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task stack = createTaskStackOnDisplay(mDisplayContent); final ActivityRecord activity2 = WindowTestUtils.createActivityRecordInTask(mDisplayContent, createTaskInStack(stack, 0 /* userId */)); final ActivityRecord activity1 = WindowTestUtils.createActivityRecordInTask(mDisplayContent, @@ -879,7 +879,7 @@ public class WindowContainerTests extends WindowTestsBase { assertNull(windowContainer.getDisplayArea()); // ActivityStack > WindowContainer - final ActivityStack activityStack = createTaskStackOnDisplay(mDisplayContent); + final Task activityStack = createTaskStackOnDisplay(mDisplayContent); activityStack.addChild(windowContainer, 0); activityStack.setParent(null); diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java index 8fa3a12f027d..f97dff3162c4 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java @@ -105,13 +105,13 @@ public class WindowManagerServiceTests extends WindowTestsBase { public void testTaskFocusChange_stackNotHomeType_focusChanges() throws RemoteException { DisplayContent display = createNewDisplay(); // Current focused window - ActivityStack focusedStack = createTaskStackOnDisplay( + Task focusedStack = createTaskStackOnDisplay( WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, display); Task focusedTask = createTaskInStack(focusedStack, 0 /* userId */); WindowState focusedWindow = createAppWindow(focusedTask, TYPE_APPLICATION, "App Window"); mDisplayContent.mCurrentFocus = focusedWindow; // Tapped task - ActivityStack tappedStack = createTaskStackOnDisplay( + Task tappedStack = createTaskStackOnDisplay( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, display); Task tappedTask = createTaskInStack(tappedStack, 0 /* userId */); spyOn(mWm.mActivityTaskManager); @@ -126,13 +126,13 @@ public class WindowManagerServiceTests extends WindowTestsBase { throws RemoteException { DisplayContent display = createNewDisplay(); // Current focused window - ActivityStack focusedStack = createTaskStackOnDisplay( + Task focusedStack = createTaskStackOnDisplay( WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, display); Task focusedTask = createTaskInStack(focusedStack, 0 /* userId */); WindowState focusedWindow = createAppWindow(focusedTask, TYPE_APPLICATION, "App Window"); mDisplayContent.mCurrentFocus = focusedWindow; // Tapped home task - ActivityStack tappedStack = createTaskStackOnDisplay( + Task tappedStack = createTaskStackOnDisplay( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, display); Task tappedTask = createTaskInStack(tappedStack, 0 /* userId */); spyOn(mWm.mActivityTaskManager); @@ -149,13 +149,13 @@ public class WindowManagerServiceTests extends WindowTestsBase { final TaskDisplayArea secondTda = createTaskDisplayArea( display, mWm, "Tapped TDA", FEATURE_VENDOR_FIRST); // Current focused window - ActivityStack focusedStack = createTaskStackOnDisplay( + Task focusedStack = createTaskStackOnDisplay( WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, display); Task focusedTask = createTaskInStack(focusedStack, 0 /* userId */); WindowState focusedWindow = createAppWindow(focusedTask, TYPE_APPLICATION, "App Window"); mDisplayContent.mCurrentFocus = focusedWindow; // Tapped home task on another task display area - ActivityStack tappedStack = createTaskStackOnTaskDisplayArea( + Task tappedStack = createTaskStackOnTaskDisplayArea( WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, secondTda); Task tappedTask = createTaskInStack(tappedStack, 0 /* userId */); spyOn(mWm.mActivityTaskManager); diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java index 7cc19ad0ddd8..bd52e9a294fc 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java @@ -103,7 +103,7 @@ public class WindowOrganizerTests extends WindowTestsBase { return registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); } - Task createTask(ActivityStack stack, boolean fakeDraw) { + Task createTask(Task stack, boolean fakeDraw) { final Task task = createTaskInStack(stack, 0); if (fakeDraw) { @@ -112,12 +112,12 @@ public class WindowOrganizerTests extends WindowTestsBase { return task; } - Task createTask(ActivityStack stack) { + Task createTask(Task stack) { // Fake draw notifications for most of our tests. return createTask(stack, true); } - ActivityStack createStack() { + Task createStack() { return createTaskStackOnDisplay(mDisplayContent); } @@ -130,7 +130,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testAppearVanish() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -144,7 +144,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testAppearWaitsForVisibility() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack, false); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -163,7 +163,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testNoVanishedIfNoAppear() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack, false /* hasBeenVisible */); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -179,7 +179,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testSwapOrganizer() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_PINNED); @@ -193,7 +193,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testSwapWindowingModes() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_PINNED); @@ -207,7 +207,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testTaskNoDraw() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack, false /* fakeDraw */); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -223,7 +223,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testClearOrganizer() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -238,7 +238,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testUnregisterOrganizer() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -253,11 +253,11 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testUnregisterOrganizerReturnsRegistrationToPrevious() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); - final ActivityStack stack2 = createStack(); + final Task stack2 = createStack(); final Task task2 = createTask(stack2); - final ActivityStack stack3 = createStack(); + final Task stack3 = createStack(); final Task task3 = createTask(stack3); final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); @@ -297,7 +297,7 @@ public class WindowOrganizerTests extends WindowTestsBase { public void testRegisterTaskOrganizerStackWindowingModeChanges() throws RemoteException { final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_PINNED); - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final Task task2 = createTask(stack); stack.setWindowingMode(WINDOWING_MODE_PINNED); @@ -310,7 +310,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testRegisterTaskOrganizerWithExistingTasks() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); stack.setWindowingMode(WINDOWING_MODE_PINNED); @@ -322,7 +322,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testTaskTransaction() { removeGlobalMinSizeRestriction(); - final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); final Task task = stack.getTopMostTask(); testTransaction(task); @@ -331,7 +331,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testStackTransaction() { removeGlobalMinSizeRestriction(); - final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); StackInfo info = mWm.mAtmService.getStackInfo(WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD); @@ -356,7 +356,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testSetWindowingMode() { - final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); testSetWindowingMode(stack); @@ -375,7 +375,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testSetActivityWindowingMode() { final ActivityRecord record = makePipableActivity(); - final ActivityStack stack = record.getStack(); + final Task stack = record.getStack(); final WindowContainerTransaction t = new WindowContainerTransaction(); t.setWindowingMode(stack.mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_PINNED); @@ -390,7 +390,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testContainerFocusableChanges() { removeGlobalMinSizeRestriction(); - final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); final Task task = stack.getTopMostTask(); WindowContainerTransaction t = new WindowContainerTransaction(); @@ -406,7 +406,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testContainerHiddenChanges() { removeGlobalMinSizeRestriction(); - final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); WindowContainerTransaction t = new WindowContainerTransaction(); assertTrue(stack.shouldBeVisible(null)); @@ -421,7 +421,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testOverrideConfigSize() { removeGlobalMinSizeRestriction(); - final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) + final Task stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); final Task task = stack.getTopMostTask(); WindowContainerTransaction t = new WindowContainerTransaction(); @@ -489,7 +489,7 @@ public class WindowOrganizerTests extends WindowTestsBase { RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); - final ActivityStack stack = createTaskStackOnDisplay( + final Task stack = createTaskStackOnDisplay( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); assertEquals(mDisplayContent.getWindowingMode(), stack.getWindowingMode()); WindowContainerTransaction wct = new WindowContainerTransaction(); @@ -550,7 +550,7 @@ public class WindowOrganizerTests extends WindowTestsBase { lastReportedTiles.clear(); called[0] = false; - final ActivityStack stack = createTaskStackOnDisplay( + final Task stack = createTaskStackOnDisplay( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); Task task1 = WindowContainer.fromBinder(info1.token.asBinder()).asTask(); WindowContainerTransaction wct = new WindowContainerTransaction(); @@ -561,7 +561,7 @@ public class WindowOrganizerTests extends WindowTestsBase { lastReportedTiles.clear(); called[0] = false; - final ActivityStack stack2 = createTaskStackOnDisplay( + final Task stack2 = createTaskStackOnDisplay( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, mDisplayContent); wct = new WindowContainerTransaction(); wct.reparent(stack2.mRemoteToken.toWindowContainerToken(), info1.token, true /* onTop */); @@ -617,9 +617,9 @@ public class WindowOrganizerTests extends WindowTestsBase { final int initialRootTaskCount = mWm.mAtmService.mTaskOrganizerController.getRootTasks( mDisplayContent.mDisplayId, null /* activityTypes */).size(); - final ActivityStack stack = createTaskStackOnDisplay( + final Task stack = createTaskStackOnDisplay( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); - final ActivityStack stack2 = createTaskStackOnDisplay( + final Task stack2 = createTaskStackOnDisplay( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, mDisplayContent); // Check getRootTasks works @@ -694,7 +694,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testTrivialBLASTCallback() throws RemoteException { - final ActivityStack stackController1 = createStack(); + final Task stackController1 = createStack(); final Task task = createTask(stackController1); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -716,7 +716,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testOverlappingBLASTCallback() throws RemoteException { - final ActivityStack stackController1 = createStack(); + final Task stackController1 = createStack(); final Task task = createTask(stackController1); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -745,7 +745,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testBLASTCallbackWithWindow() { - final ActivityStack stackController1 = createStack(); + final Task stackController1 = createStack(); final Task task = createTask(stackController1); final ITaskOrganizer organizer = registerMockOrganizer(); final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); @@ -769,7 +769,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testBLASTCallbackNoDoubleAdd() { - final ActivityStack stackController1 = createStack(); + final Task stackController1 = createStack(); final Task task = createTask(stackController1); final ITaskOrganizer organizer = registerMockOrganizer(); final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); @@ -791,7 +791,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testBLASTCallbackWithInvisibleWindow() { - final ActivityStack stackController1 = createStack(); + final Task stackController1 = createStack(); final Task task = createTask(stackController1); final ITaskOrganizer organizer = registerMockOrganizer(); final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); @@ -813,7 +813,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testBLASTCallbackWithChildWindow() { - final ActivityStack stackController1 = createStack(); + final Task stackController1 = createStack(); final Task task = createTask(stackController1); final ITaskOrganizer organizer = registerMockOrganizer(); final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); @@ -930,7 +930,7 @@ public class WindowOrganizerTests extends WindowTestsBase { mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(o, WINDOWING_MODE_MULTI_WINDOW); - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ActivityRecord record = WindowTestUtils.createActivityRecordInTask( stack.mDisplayContent, task); @@ -943,7 +943,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testPreventDuplicateAppear() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ITaskOrganizer organizer = registerMockOrganizer(); @@ -965,7 +965,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testInterceptBackPressedOnTaskRoot() throws RemoteException { - final ActivityStack stack = createStack(); + final Task stack = createStack(); final Task task = createTask(stack); final ActivityRecord activity = WindowTestUtils.createActivityRecordInTask( stack.mDisplayContent, task); @@ -992,7 +992,7 @@ public class WindowOrganizerTests extends WindowTestsBase { @Test public void testBLASTCallbackWithMultipleWindows() throws Exception { - final ActivityStack stackController = createStack(); + final Task stackController = createStack(); final Task task = createTask(stackController); final ITaskOrganizer organizer = registerMockOrganizer(); final WindowState w1 = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window 1"); diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java index ce9dd685293a..3894a2eaa461 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java @@ -250,7 +250,7 @@ public class WindowStateTests extends WindowTestsBase { // minimized and home stack is resizable, so that we should ignore input for the stack. final DockedStackDividerController controller = mDisplayContent.getDockedDividerController(); - final ActivityStack stack = createTaskStackOnDisplay(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, + final Task stack = createTaskStackOnDisplay(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, mDisplayContent); spyOn(appWindow); spyOn(controller); diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java index 49993610bbed..2502932c5421 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java @@ -32,8 +32,8 @@ import com.android.server.wm.ActivityTestsBase.ActivityBuilder; */ class WindowTestUtils { - /** Creates a {@link Task} and adds it to the specified {@link ActivityStack}. */ - static Task createTaskInStack(WindowManagerService service, ActivityStack stack, int userId) { + /** Creates a {@link Task} and adds it to the specified {@link Task}. */ + static Task createTaskInStack(WindowManagerService service, Task stack, int userId) { final Task task = new ActivityTestsBase.TaskBuilder(stack.mStackSupervisor) .setUserId(userId) .setStack(stack) @@ -48,7 +48,7 @@ class WindowTestUtils { return activity; } - static ActivityRecord createTestActivityRecord(ActivityStack stack) { + static ActivityRecord createTestActivityRecord(Task stack) { final ActivityRecord activity = new ActivityTestsBase.ActivityBuilder(stack.mAtmService) .setStack(stack) .setCreateTask(true) diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java index 0bbe0a04f618..dc388833f338 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java @@ -211,7 +211,7 @@ class WindowTestsBase extends SystemServiceTestsBase { ActivityRecord createTestActivityRecord(DisplayContent dc, int windowingMode, int activityType) { - final ActivityStack stack = createTaskStackOnDisplay(windowingMode, activityType, dc); + final Task stack = createTaskStackOnDisplay(windowingMode, activityType, dc); return WindowTestUtils.createTestActivityRecord(stack); } @@ -322,12 +322,12 @@ class WindowTestsBase extends SystemServiceTestsBase { return newTaskDisplayArea; } - /** Creates a {@link ActivityStack} and adds it to the specified {@link DisplayContent}. */ - ActivityStack createTaskStackOnDisplay(DisplayContent dc) { + /** Creates a {@link Task} and adds it to the specified {@link DisplayContent}. */ + Task createTaskStackOnDisplay(DisplayContent dc) { return createTaskStackOnDisplay(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc); } - ActivityStack createTaskStackOnDisplay(int windowingMode, int activityType, DisplayContent dc) { + Task createTaskStackOnDisplay(int windowingMode, int activityType, DisplayContent dc) { return new ActivityTestsBase.StackBuilder(dc.mWmService.mRoot) .setDisplay(dc) .setWindowingMode(windowingMode) @@ -337,7 +337,7 @@ class WindowTestsBase extends SystemServiceTestsBase { .build(); } - ActivityStack createTaskStackOnTaskDisplayArea(int windowingMode, int activityType, + Task createTaskStackOnTaskDisplayArea(int windowingMode, int activityType, TaskDisplayArea tda) { return new ActivityTestsBase.StackBuilder(tda.mWmService.mRoot) .setTaskDisplayArea(tda) @@ -348,8 +348,8 @@ class WindowTestsBase extends SystemServiceTestsBase { .build(); } - /** Creates a {@link Task} and adds it to the specified {@link ActivityStack}. */ - Task createTaskInStack(ActivityStack stack, int userId) { + /** Creates a {@link Task} and adds it to the specified {@link Task}. */ + Task createTaskInStack(Task stack, int userId) { return WindowTestUtils.createTaskInStack(mWm, stack, userId); } |