Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 29 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
| 30 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 31 | import static android.view.Display.FLAG_PRIVATE; |
| 32 | import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT; |
| 33 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 34 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 35 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 36 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 37 | import static com.android.server.am.ActivityDisplayProto.CONFIGURATION_CONTAINER; |
| 38 | import static com.android.server.am.ActivityDisplayProto.STACKS; |
| 39 | import static com.android.server.am.ActivityDisplayProto.ID; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 40 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 41 | import android.annotation.Nullable; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 42 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 43 | import android.app.ActivityOptions; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 44 | import android.app.WindowConfiguration; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 45 | import android.graphics.Point; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 46 | import android.util.IntArray; |
| 47 | import android.util.Slog; |
| 48 | import android.util.proto.ProtoOutputStream; |
| 49 | import android.view.Display; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 50 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 51 | import com.android.server.wm.ConfigurationContainer; |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 52 | import com.android.server.wm.DisplayWindowController; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 53 | |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 54 | import com.android.server.wm.WindowContainerListener; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 55 | import java.io.PrintWriter; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 56 | import java.util.ArrayList; |
| 57 | |
| 58 | /** |
| 59 | * Exactly one of these classes per Display in the system. Capable of holding zero or more |
| 60 | * attached {@link ActivityStack}s. |
| 61 | */ |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 62 | class ActivityDisplay extends ConfigurationContainer<ActivityStack> |
| 63 | implements WindowContainerListener { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 64 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityDisplay" : TAG_AM; |
| 65 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
| 66 | |
| 67 | static final int POSITION_TOP = Integer.MAX_VALUE; |
| 68 | static final int POSITION_BOTTOM = Integer.MIN_VALUE; |
| 69 | |
Bryce Lee | d9cce2c | 2017-12-04 16:16:27 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Counter for next free stack ID to use for dynamic activity stacks. Unique across displays. |
| 73 | */ |
| 74 | private static int sNextFreeStackId = 0; |
| 75 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 76 | private ActivityStackSupervisor mSupervisor; |
| 77 | /** Actual Display this object tracks. */ |
| 78 | int mDisplayId; |
| 79 | Display mDisplay; |
| 80 | |
| 81 | /** All of the stacks on this display. Order matters, topmost stack is in front of all other |
| 82 | * stacks, bottommost behind. Accessed directly by ActivityManager package classes */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 83 | private final ArrayList<ActivityStack> mStacks = new ArrayList<>(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 84 | |
| 85 | /** Array of all UIDs that are present on the display. */ |
| 86 | private IntArray mDisplayAccessUIDs = new IntArray(); |
| 87 | |
| 88 | /** All tokens used to put activities on this stack to sleep (including mOffToken) */ |
| 89 | final ArrayList<ActivityManagerInternal.SleepToken> mAllSleepTokens = new ArrayList<>(); |
| 90 | /** The token acquired by ActivityStackSupervisor to put stacks on the display to sleep */ |
| 91 | ActivityManagerInternal.SleepToken mOffToken; |
| 92 | |
| 93 | private boolean mSleeping; |
| 94 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 95 | // Cached reference to some special stacks we tend to get a lot so we don't need to loop |
| 96 | // through the list to find them. |
| 97 | private ActivityStack mHomeStack = null; |
| 98 | private ActivityStack mRecentsStack = null; |
| 99 | private ActivityStack mPinnedStack = null; |
| 100 | private ActivityStack mSplitScreenPrimaryStack = null; |
| 101 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 102 | // Used in updating the display size |
| 103 | private Point mTmpDisplaySize = new Point(); |
| 104 | |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 105 | private DisplayWindowController mWindowContainerController; |
| 106 | |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 107 | @VisibleForTesting |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 108 | ActivityDisplay(ActivityStackSupervisor supervisor, int displayId) { |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 109 | this(supervisor, supervisor.mDisplayManager.getDisplay(displayId)); |
| 110 | } |
| 111 | |
| 112 | ActivityDisplay(ActivityStackSupervisor supervisor, Display display) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 113 | mSupervisor = supervisor; |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 114 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 115 | mDisplay = display; |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 116 | mWindowContainerController = createWindowContainerController(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 117 | updateBounds(); |
| 118 | } |
| 119 | |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 120 | protected DisplayWindowController createWindowContainerController() { |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 121 | return new DisplayWindowController(mDisplay, this); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 124 | void updateBounds() { |
| 125 | mDisplay.getSize(mTmpDisplaySize); |
| 126 | setBounds(0, 0, mTmpDisplaySize.x, mTmpDisplaySize.y); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | void addChild(ActivityStack stack, int position) { |
| 130 | if (position == POSITION_BOTTOM) { |
| 131 | position = 0; |
| 132 | } else if (position == POSITION_TOP) { |
| 133 | position = mStacks.size(); |
| 134 | } |
| 135 | if (DEBUG_STACK) Slog.v(TAG_STACK, "addChild: attaching " + stack |
| 136 | + " to displayId=" + mDisplayId + " position=" + position); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 137 | addStackReferenceIfNeeded(stack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 138 | positionChildAt(stack, position); |
| 139 | mSupervisor.mService.updateSleepIfNeededLocked(); |
| 140 | } |
| 141 | |
| 142 | void removeChild(ActivityStack stack) { |
| 143 | if (DEBUG_STACK) Slog.v(TAG_STACK, "removeChild: detaching " + stack |
| 144 | + " from displayId=" + mDisplayId); |
| 145 | mStacks.remove(stack); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 146 | removeStackReferenceIfNeeded(stack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 147 | mSupervisor.mService.updateSleepIfNeededLocked(); |
| 148 | } |
| 149 | |
| 150 | void positionChildAtTop(ActivityStack stack) { |
| 151 | positionChildAt(stack, mStacks.size()); |
| 152 | } |
| 153 | |
| 154 | void positionChildAtBottom(ActivityStack stack) { |
| 155 | positionChildAt(stack, 0); |
| 156 | } |
| 157 | |
| 158 | private void positionChildAt(ActivityStack stack, int position) { |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 159 | // TODO: Keep in sync with WindowContainer.positionChildAt(), once we change that to adjust |
| 160 | // the position internally, also update the logic here |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 161 | mStacks.remove(stack); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 162 | final int insertPosition = getTopInsertPosition(stack, position); |
| 163 | mStacks.add(insertPosition, stack); |
| 164 | mWindowContainerController.positionChildAt(stack.getWindowContainerController(), |
| 165 | insertPosition); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | private int getTopInsertPosition(ActivityStack stack, int candidatePosition) { |
| 169 | int position = mStacks.size(); |
| 170 | if (position > 0) { |
| 171 | final ActivityStack topStack = mStacks.get(position - 1); |
| 172 | if (topStack.getWindowConfiguration().isAlwaysOnTop() && topStack != stack) { |
| 173 | // If the top stack is always on top, we move this stack just below it. |
| 174 | position--; |
| 175 | } |
| 176 | } |
| 177 | return Math.min(position, candidatePosition); |
| 178 | } |
| 179 | |
| 180 | <T extends ActivityStack> T getStack(int stackId) { |
| 181 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 182 | final ActivityStack stack = mStacks.get(i); |
| 183 | if (stack.mStackId == stackId) { |
| 184 | return (T) stack; |
| 185 | } |
| 186 | } |
| 187 | return null; |
| 188 | } |
| 189 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 190 | /** |
| 191 | * @return the topmost stack on the display that is compatible with the input windowing mode and |
| 192 | * activity type. {@code null} means no compatible stack on the display. |
| 193 | * @see ConfigurationContainer#isCompatible(int, int) |
| 194 | */ |
| 195 | <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 196 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 197 | return (T) mHomeStack; |
| 198 | } else if (activityType == ACTIVITY_TYPE_RECENTS) { |
| 199 | return (T) mRecentsStack; |
| 200 | } |
| 201 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 202 | return (T) mPinnedStack; |
| 203 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 204 | return (T) mSplitScreenPrimaryStack; |
| 205 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 206 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 207 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 208 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 209 | if (stack.isCompatible(windowingMode, activityType)) { |
| 210 | return (T) stack; |
| 211 | } |
| 212 | } |
| 213 | return null; |
| 214 | } |
| 215 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 216 | private boolean alwaysCreateStack(int windowingMode, int activityType) { |
| 217 | // Always create a stack for fullscreen, freeform, and split-screen-secondary windowing |
| 218 | // modes so that we can manage visual ordering and return types correctly. |
| 219 | return activityType == ACTIVITY_TYPE_STANDARD |
| 220 | && (windowingMode == WINDOWING_MODE_FULLSCREEN |
| 221 | || windowingMode == WINDOWING_MODE_FREEFORM |
| 222 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 223 | } |
| 224 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 225 | /** |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 226 | * Returns an existing stack compatible with the windowing mode and activity type or creates one |
| 227 | * if a compatible stack doesn't exist. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 228 | * @see #getStack(int, int) |
| 229 | * @see #createStack(int, int, boolean) |
| 230 | */ |
| 231 | <T extends ActivityStack> T getOrCreateStack(int windowingMode, int activityType, |
| 232 | boolean onTop) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 233 | if (!alwaysCreateStack(windowingMode, activityType)) { |
| 234 | T stack = getStack(windowingMode, activityType); |
| 235 | if (stack != null) { |
| 236 | return stack; |
| 237 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 238 | } |
| 239 | return createStack(windowingMode, activityType, onTop); |
| 240 | } |
| 241 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 242 | /** |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 243 | * Returns an existing stack compatible with the input params or creates one |
| 244 | * if a compatible stack doesn't exist. |
| 245 | * @see #getOrCreateStack(int, int, boolean) |
| 246 | */ |
| 247 | <T extends ActivityStack> T getOrCreateStack(@Nullable ActivityRecord r, |
| 248 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, int activityType, |
| 249 | boolean onTop) { |
| 250 | final int windowingMode = resolveWindowingMode(r, options, candidateTask, activityType); |
| 251 | return getOrCreateStack(windowingMode, activityType, onTop); |
| 252 | } |
| 253 | |
Bryce Lee | d9cce2c | 2017-12-04 16:16:27 -0800 | [diff] [blame] | 254 | private int getNextStackId() { |
| 255 | return sNextFreeStackId++; |
| 256 | } |
| 257 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 258 | /** |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 259 | * Creates a stack matching the input windowing mode and activity type on this display. |
| 260 | * @param windowingMode The windowing mode the stack should be created in. If |
| 261 | * {@link WindowConfiguration#WINDOWING_MODE_UNDEFINED} then the stack will |
| 262 | * be created in {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}. |
| 263 | * @param activityType The activityType the stack should be created in. If |
| 264 | * {@link WindowConfiguration#ACTIVITY_TYPE_UNDEFINED} then the stack will |
| 265 | * be created in {@link WindowConfiguration#ACTIVITY_TYPE_STANDARD}. |
| 266 | * @param onTop If true the stack will be created at the top of the display, else at the bottom. |
| 267 | * @return The newly created stack. |
| 268 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 269 | <T extends ActivityStack> T createStack(int windowingMode, int activityType, boolean onTop) { |
| 270 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 271 | if (activityType == ACTIVITY_TYPE_UNDEFINED) { |
| 272 | // Can't have an undefined stack type yet...so re-map to standard. Anyone that wants |
| 273 | // anything else should be passing it in anyways... |
| 274 | activityType = ACTIVITY_TYPE_STANDARD; |
| 275 | } |
| 276 | |
| 277 | if (activityType != ACTIVITY_TYPE_STANDARD) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 278 | // For now there can be only one stack of a particular non-standard activity type on a |
| 279 | // display. So, get that ignoring whatever windowing mode it is currently in. |
| 280 | T stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
| 281 | if (stack != null) { |
| 282 | throw new IllegalArgumentException("Stack=" + stack + " of activityType=" |
| 283 | + activityType + " already on display=" + this + ". Can't have multiple."); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | final ActivityManagerService service = mSupervisor.mService; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 288 | if (!isWindowingModeSupported(windowingMode, service.mSupportsMultiWindow, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 289 | service.mSupportsSplitScreenMultiWindow, service.mSupportsFreeformWindowManagement, |
| 290 | service.mSupportsPictureInPicture, activityType)) { |
| 291 | throw new IllegalArgumentException("Can't create stack for unsupported windowingMode=" |
| 292 | + windowingMode); |
| 293 | } |
| 294 | |
| 295 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 296 | // TODO: Should be okay to have stacks with with undefined windowing mode long term, but |
| 297 | // have to set them to something for now due to logic that depending on them. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 298 | windowingMode = getWindowingMode(); // Put in current display's windowing mode |
| 299 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 300 | // Else fullscreen for now... |
| 301 | windowingMode = WINDOWING_MODE_FULLSCREEN; |
| 302 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Bryce Lee | d9cce2c | 2017-12-04 16:16:27 -0800 | [diff] [blame] | 305 | final int stackId = getNextStackId(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 306 | return createStackUnchecked(windowingMode, activityType, stackId, onTop); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | @VisibleForTesting |
| 310 | <T extends ActivityStack> T createStackUnchecked(int windowingMode, int activityType, |
| 311 | int stackId, boolean onTop) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 312 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 313 | return (T) new PinnedActivityStack(this, stackId, mSupervisor, onTop); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 314 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 315 | return (T) new ActivityStack( |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 316 | this, stackId, mSupervisor, windowingMode, activityType, onTop); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 319 | /** |
| 320 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 321 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 322 | */ |
| 323 | void removeStacksInWindowingModes(int... windowingModes) { |
| 324 | if (windowingModes == null || windowingModes.length == 0) { |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | for (int j = windowingModes.length - 1 ; j >= 0; --j) { |
| 329 | final int windowingMode = windowingModes[j]; |
| 330 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 331 | final ActivityStack stack = mStacks.get(i); |
| 332 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 333 | continue; |
| 334 | } |
| 335 | if (stack.getWindowingMode() != windowingMode) { |
| 336 | continue; |
| 337 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 338 | mSupervisor.removeStack(stack); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 343 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 344 | if (activityTypes == null || activityTypes.length == 0) { |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | for (int j = activityTypes.length - 1 ; j >= 0; --j) { |
| 349 | final int activityType = activityTypes[j]; |
| 350 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 351 | final ActivityStack stack = mStacks.get(i); |
| 352 | if (stack.getActivityType() == activityType) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 353 | mSupervisor.removeStack(stack); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 359 | void onStackWindowingModeChanged(ActivityStack stack) { |
| 360 | removeStackReferenceIfNeeded(stack); |
| 361 | addStackReferenceIfNeeded(stack); |
| 362 | } |
| 363 | |
| 364 | private void addStackReferenceIfNeeded(ActivityStack stack) { |
| 365 | final int activityType = stack.getActivityType(); |
| 366 | final int windowingMode = stack.getWindowingMode(); |
| 367 | |
| 368 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 369 | if (mHomeStack != null && mHomeStack != stack) { |
| 370 | throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack=" |
| 371 | + mHomeStack + " already exist on display=" + this + " stack=" + stack); |
| 372 | } |
| 373 | mHomeStack = stack; |
| 374 | } else if (activityType == ACTIVITY_TYPE_RECENTS) { |
| 375 | if (mRecentsStack != null && mRecentsStack != stack) { |
| 376 | throw new IllegalArgumentException("addStackReferenceIfNeeded: recents stack=" |
| 377 | + mRecentsStack + " already exist on display=" + this + " stack=" + stack); |
| 378 | } |
| 379 | mRecentsStack = stack; |
| 380 | } |
| 381 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 382 | if (mPinnedStack != null && mPinnedStack != stack) { |
| 383 | throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack=" |
| 384 | + mPinnedStack + " already exist on display=" + this |
| 385 | + " stack=" + stack); |
| 386 | } |
| 387 | mPinnedStack = stack; |
| 388 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 389 | if (mSplitScreenPrimaryStack != null && mSplitScreenPrimaryStack != stack) { |
| 390 | throw new IllegalArgumentException("addStackReferenceIfNeeded:" |
| 391 | + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack |
| 392 | + " already exist on display=" + this + " stack=" + stack); |
| 393 | } |
| 394 | mSplitScreenPrimaryStack = stack; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 395 | onSplitScreenModeActivated(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | private void removeStackReferenceIfNeeded(ActivityStack stack) { |
| 400 | if (stack == mHomeStack) { |
| 401 | mHomeStack = null; |
| 402 | } else if (stack == mRecentsStack) { |
| 403 | mRecentsStack = null; |
| 404 | } else if (stack == mPinnedStack) { |
| 405 | mPinnedStack = null; |
| 406 | } else if (stack == mSplitScreenPrimaryStack) { |
| 407 | mSplitScreenPrimaryStack = null; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 408 | // Inform the reset of the system that split-screen mode was dismissed so things like |
| 409 | // resizing all the other stacks can take place. |
| 410 | onSplitScreenModeDismissed(); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | private void onSplitScreenModeDismissed() { |
| 415 | mSupervisor.mWindowManager.deferSurfaceLayout(); |
| 416 | try { |
| 417 | // Adjust the windowing mode of any stack in secondary split-screen to fullscreen. |
| 418 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 419 | final ActivityStack otherStack = mStacks.get(i); |
| 420 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 421 | continue; |
| 422 | } |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 423 | otherStack.setWindowingMode(WINDOWING_MODE_FULLSCREEN, false /* animate */, |
| 424 | false /* showRecents */, false /* enteringSplitScreenMode */, |
| 425 | true /* deferEnsuringVisibility */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 426 | } |
| 427 | } finally { |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 428 | final ActivityStack topFullscreenStack = |
Wale Ogunwale | f325785 | 2018-01-24 08:52:28 -0800 | [diff] [blame] | 429 | getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 430 | if (topFullscreenStack != null && mHomeStack != null && !isTopStack(mHomeStack)) { |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 431 | // Whenever split-screen is dismissed we want the home stack directly behind the |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 432 | // current top fullscreen stack so it shows up when the top stack is finished. |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 433 | // TODO: Would be better to use ActivityDisplay.positionChildAt() for this, however |
| 434 | // ActivityDisplay doesn't have a direct controller to WM side yet. We can switch |
| 435 | // once we have that. |
| 436 | mHomeStack.moveToFront("onSplitScreenModeDismissed"); |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 437 | topFullscreenStack.moveToFront("onSplitScreenModeDismissed"); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 438 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 439 | mSupervisor.mWindowManager.continueSurfaceLayout(); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | private void onSplitScreenModeActivated() { |
| 444 | mSupervisor.mWindowManager.deferSurfaceLayout(); |
| 445 | try { |
| 446 | // Adjust the windowing mode of any affected by split-screen to split-screen secondary. |
| 447 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 448 | final ActivityStack otherStack = mStacks.get(i); |
| 449 | if (otherStack == mSplitScreenPrimaryStack |
| 450 | || !otherStack.affectedBySplitScreenResize()) { |
| 451 | continue; |
| 452 | } |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 453 | otherStack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, |
| 454 | false /* animate */, false /* showRecents */, |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 455 | true /* enteringSplitScreenMode */, true /* deferEnsuringVisibility */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 456 | } |
| 457 | } finally { |
| 458 | mSupervisor.mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 462 | /** |
| 463 | * Returns true if the {@param windowingMode} is supported based on other parameters passed in. |
| 464 | * @param windowingMode The windowing mode we are checking support for. |
| 465 | * @param supportsMultiWindow If we should consider support for multi-window mode in general. |
| 466 | * @param supportsSplitScreen If we should consider support for split-screen multi-window. |
| 467 | * @param supportsFreeform If we should consider support for freeform multi-window. |
| 468 | * @param supportsPip If we should consider support for picture-in-picture mutli-window. |
| 469 | * @param activityType The activity type under consideration. |
| 470 | * @return true if the windowing mode is supported. |
| 471 | */ |
| 472 | private boolean isWindowingModeSupported(int windowingMode, boolean supportsMultiWindow, |
| 473 | boolean supportsSplitScreen, boolean supportsFreeform, boolean supportsPip, |
| 474 | int activityType) { |
| 475 | |
| 476 | if (windowingMode == WINDOWING_MODE_UNDEFINED |
| 477 | || windowingMode == WINDOWING_MODE_FULLSCREEN) { |
| 478 | return true; |
| 479 | } |
| 480 | if (!supportsMultiWindow) { |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 485 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 486 | return supportsSplitScreen |
| 487 | && WindowConfiguration.supportSplitScreenWindowingMode(activityType); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | if (!supportsFreeform && windowingMode == WINDOWING_MODE_FREEFORM) { |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | if (!supportsPip && windowingMode == WINDOWING_MODE_PINNED) { |
| 495 | return false; |
| 496 | } |
| 497 | return true; |
| 498 | } |
| 499 | |
| 500 | int resolveWindowingMode(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
| 501 | @Nullable TaskRecord task, int activityType) { |
| 502 | |
| 503 | // First preference if the windowing mode in the activity options if set. |
| 504 | int windowingMode = (options != null) |
| 505 | ? options.getLaunchWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 506 | |
| 507 | // If windowing mode is unset, then next preference is the candidate task, then the |
| 508 | // activity record. |
| 509 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 510 | if (task != null) { |
| 511 | windowingMode = task.getWindowingMode(); |
| 512 | } |
| 513 | if (windowingMode == WINDOWING_MODE_UNDEFINED && r != null) { |
| 514 | windowingMode = r.getWindowingMode(); |
| 515 | } |
| 516 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 517 | // Use the display's windowing mode. |
| 518 | windowingMode = getWindowingMode(); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | // Make sure the windowing mode we are trying to use makes sense for what is supported. |
| 523 | final ActivityManagerService service = mSupervisor.mService; |
| 524 | boolean supportsMultiWindow = service.mSupportsMultiWindow; |
| 525 | boolean supportsSplitScreen = service.mSupportsSplitScreenMultiWindow; |
| 526 | boolean supportsFreeform = service.mSupportsFreeformWindowManagement; |
| 527 | boolean supportsPip = service.mSupportsPictureInPicture; |
| 528 | if (supportsMultiWindow) { |
| 529 | if (task != null) { |
| 530 | supportsMultiWindow = task.isResizeable(); |
| 531 | supportsSplitScreen = task.supportsSplitScreenWindowingMode(); |
| 532 | // TODO: Do we need to check for freeform and Pip support here? |
| 533 | } else if (r != null) { |
| 534 | supportsMultiWindow = r.isResizeable(); |
| 535 | supportsSplitScreen = r.supportsSplitScreenWindowingMode(); |
| 536 | supportsFreeform = r.supportsFreeform(); |
| 537 | supportsPip = r.supportsPictureInPicture(); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | final boolean inSplitScreenMode = hasSplitScreenPrimaryStack(); |
| 542 | if (!inSplitScreenMode |
| 543 | && windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY) { |
| 544 | // Switch to fullscreen windowing mode if we are not in split-screen mode and we are |
| 545 | // trying to launch in split-screen secondary. |
| 546 | windowingMode = WINDOWING_MODE_FULLSCREEN; |
| 547 | } else if (inSplitScreenMode && windowingMode == WINDOWING_MODE_FULLSCREEN |
| 548 | && supportsSplitScreen) { |
| 549 | windowingMode = WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 550 | } |
| 551 | |
| 552 | if (windowingMode != WINDOWING_MODE_UNDEFINED |
| 553 | && isWindowingModeSupported(windowingMode, supportsMultiWindow, supportsSplitScreen, |
| 554 | supportsFreeform, supportsPip, activityType)) { |
| 555 | return windowingMode; |
| 556 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 557 | // Try to use the display's windowing mode otherwise fallback to fullscreen. |
| 558 | windowingMode = getWindowingMode(); |
| 559 | return windowingMode != WINDOWING_MODE_UNDEFINED |
| 560 | ? windowingMode : WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 563 | /** |
| 564 | * Get the topmost stack on the display. It may be different from focused stack, because |
| 565 | * focus may be on another display. |
| 566 | */ |
| 567 | ActivityStack getTopStack() { |
| 568 | return mStacks.isEmpty() ? null : mStacks.get(mStacks.size() - 1); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 571 | boolean isTopStack(ActivityStack stack) { |
| 572 | return stack == getTopStack(); |
| 573 | } |
| 574 | |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 575 | boolean isTopNotPinnedStack(ActivityStack stack) { |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 576 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 577 | final ActivityStack current = mStacks.get(i); |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 578 | if (!current.inPinnedWindowingMode()) { |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 579 | return current == stack; |
| 580 | } |
| 581 | } |
| 582 | return false; |
| 583 | } |
| 584 | |
Wale Ogunwale | f325785 | 2018-01-24 08:52:28 -0800 | [diff] [blame] | 585 | ActivityStack getTopStackInWindowingMode(int windowingMode) { |
| 586 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 587 | final ActivityStack current = mStacks.get(i); |
| 588 | if (windowingMode == current.getWindowingMode()) { |
| 589 | return current; |
| 590 | } |
| 591 | } |
| 592 | return null; |
| 593 | } |
| 594 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 595 | int getIndexOf(ActivityStack stack) { |
| 596 | return mStacks.indexOf(stack); |
| 597 | } |
| 598 | |
| 599 | void onLockTaskPackagesUpdated() { |
| 600 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 601 | mStacks.get(i).onLockTaskPackagesUpdated(); |
| 602 | } |
| 603 | } |
| 604 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 605 | /** We are in the process of exiting split-screen mode. */ |
| 606 | void onExitingSplitScreenMode() { |
| 607 | // Remove reference to the primary-split-screen stack so it no longer has any effect on the |
| 608 | // display. For example, we want to be able to create fullscreen stack for standard activity |
| 609 | // types when exiting split-screen mode. |
| 610 | mSplitScreenPrimaryStack = null; |
| 611 | } |
| 612 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 613 | ActivityStack getSplitScreenPrimaryStack() { |
| 614 | return mSplitScreenPrimaryStack; |
| 615 | } |
| 616 | |
| 617 | boolean hasSplitScreenPrimaryStack() { |
| 618 | return mSplitScreenPrimaryStack != null; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | PinnedActivityStack getPinnedStack() { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 622 | return (PinnedActivityStack) mPinnedStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | boolean hasPinnedStack() { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 626 | return mPinnedStack != null; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 629 | @Override |
| 630 | public String toString() { |
| 631 | return "ActivityDisplay={" + mDisplayId + " numStacks=" + mStacks.size() + "}"; |
| 632 | } |
| 633 | |
| 634 | @Override |
| 635 | protected int getChildCount() { |
| 636 | return mStacks.size(); |
| 637 | } |
| 638 | |
| 639 | @Override |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 640 | protected ActivityStack getChildAt(int index) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 641 | return mStacks.get(index); |
| 642 | } |
| 643 | |
| 644 | @Override |
| 645 | protected ConfigurationContainer getParent() { |
| 646 | return mSupervisor; |
| 647 | } |
| 648 | |
| 649 | boolean isPrivate() { |
| 650 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
| 651 | } |
| 652 | |
| 653 | boolean isUidPresent(int uid) { |
| 654 | for (ActivityStack stack : mStacks) { |
| 655 | if (stack.isUidPresent(uid)) { |
| 656 | return true; |
| 657 | } |
| 658 | } |
| 659 | return false; |
| 660 | } |
| 661 | |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 662 | void remove() { |
| 663 | final boolean destroyContentOnRemoval = shouldDestroyContentOnRemove(); |
| 664 | while (getChildCount() > 0) { |
| 665 | final ActivityStack stack = getChildAt(0); |
| 666 | if (destroyContentOnRemoval) { |
Andrii Kulian | 823af6e | 2018-02-28 18:51:36 -0800 | [diff] [blame] | 667 | // Override the stack configuration to make it equal to the current applied one, so |
| 668 | // that we don't accidentally report configuration change to activities that are |
| 669 | // going to be finished. |
| 670 | stack.onOverrideConfigurationChanged(stack.getConfiguration()); |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 671 | mSupervisor.moveStackToDisplayLocked(stack.mStackId, DEFAULT_DISPLAY, |
| 672 | false /* onTop */); |
| 673 | stack.finishAllActivitiesLocked(true /* immediately */); |
| 674 | } else { |
| 675 | // Moving all tasks to fullscreen stack, because it's guaranteed to be |
| 676 | // a valid launch stack for all activities. This way the task history from |
| 677 | // external display will be preserved on primary after move. |
| 678 | mSupervisor.moveTasksToFullscreenStackLocked(stack, true /* onTop */); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | mWindowContainerController.removeContainer(); |
| 683 | mWindowContainerController = null; |
| 684 | } |
| 685 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 686 | /** Update and get all UIDs that are present on the display and have access to it. */ |
| 687 | IntArray getPresentUIDs() { |
| 688 | mDisplayAccessUIDs.clear(); |
| 689 | for (ActivityStack stack : mStacks) { |
| 690 | stack.getPresentUIDs(mDisplayAccessUIDs); |
| 691 | } |
| 692 | return mDisplayAccessUIDs; |
| 693 | } |
| 694 | |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 695 | private boolean shouldDestroyContentOnRemove() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 696 | return mDisplay.getRemoveMode() == REMOVE_MODE_DESTROY_CONTENT; |
| 697 | } |
| 698 | |
| 699 | boolean shouldSleep() { |
| 700 | return (mStacks.isEmpty() || !mAllSleepTokens.isEmpty()) |
| 701 | && (mSupervisor.mService.mRunningVoice == null); |
| 702 | } |
| 703 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 704 | /** |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 705 | * @return the stack currently above the {@param stack}. Can be null if the {@param stack} is |
| 706 | * already top-most. |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 707 | */ |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 708 | ActivityStack getStackAbove(ActivityStack stack) { |
| 709 | final int stackIndex = mStacks.indexOf(stack) + 1; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 710 | return (stackIndex < mStacks.size()) ? mStacks.get(stackIndex) : null; |
| 711 | } |
| 712 | |
| 713 | /** |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 714 | * Adjusts the {@param stack} behind the last visible stack in the display if necessary. |
| 715 | * Generally used in conjunction with {@link #moveStackBehindStack}. |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 716 | */ |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 717 | void moveStackBehindBottomMostVisibleStack(ActivityStack stack) { |
| 718 | if (stack.shouldBeVisible(null)) { |
| 719 | // Skip if the stack is already visible |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 720 | return; |
| 721 | } |
| 722 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 723 | // Move the stack to the bottom to not affect the following visibility checks |
| 724 | positionChildAtBottom(stack); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 725 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 726 | // Find the next position where the stack should be placed |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 727 | final int numStacks = mStacks.size(); |
| 728 | for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 729 | final ActivityStack s = mStacks.get(stackNdx); |
| 730 | if (s == stack) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 731 | continue; |
| 732 | } |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 733 | final int winMode = s.getWindowingMode(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 734 | final boolean isValidWindowingMode = winMode == WINDOWING_MODE_FULLSCREEN || |
| 735 | winMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 736 | if (s.shouldBeVisible(null) && isValidWindowingMode) { |
| 737 | // Move the provided stack to behind this stack |
| 738 | positionChildAt(stack, Math.max(0, stackNdx - 1)); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 739 | break; |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /** |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 745 | * Moves the {@param stack} behind the given {@param behindStack} if possible. If |
| 746 | * {@param behindStack} is not currently in the display, then then the stack is moved to the |
| 747 | * back. Generally used in conjunction with {@link #moveStackBehindBottomMostVisibleStack}. |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 748 | */ |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 749 | void moveStackBehindStack(ActivityStack stack, ActivityStack behindStack) { |
| 750 | if (behindStack == null || behindStack == stack) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 751 | return; |
| 752 | } |
| 753 | |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 754 | // Note that positionChildAt will first remove the given stack before inserting into the |
| 755 | // list, so we need to adjust the insertion index to account for the removed index |
| 756 | // TODO: Remove this logic when WindowContainer.positionChildAt() is updated to adjust the |
| 757 | // position internally |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 758 | final int stackIndex = mStacks.indexOf(stack); |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 759 | final int behindStackIndex = mStacks.indexOf(behindStack); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 760 | final int insertIndex = stackIndex <= behindStackIndex |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 761 | ? behindStackIndex - 1 : behindStackIndex; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 762 | positionChildAt(stack, Math.max(0, insertIndex)); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 765 | boolean isSleeping() { |
| 766 | return mSleeping; |
| 767 | } |
| 768 | |
| 769 | void setIsSleeping(boolean asleep) { |
| 770 | mSleeping = asleep; |
| 771 | } |
| 772 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 773 | public void dump(PrintWriter pw, String prefix) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 774 | pw.println(prefix + "displayId=" + mDisplayId + " stacks=" + mStacks.size()); |
| 775 | final String myPrefix = prefix + " "; |
| 776 | if (mHomeStack != null) { |
| 777 | pw.println(myPrefix + "mHomeStack=" + mHomeStack); |
| 778 | } |
| 779 | if (mRecentsStack != null) { |
| 780 | pw.println(myPrefix + "mRecentsStack=" + mRecentsStack); |
| 781 | } |
| 782 | if (mPinnedStack != null) { |
| 783 | pw.println(myPrefix + "mPinnedStack=" + mPinnedStack); |
| 784 | } |
| 785 | if (mSplitScreenPrimaryStack != null) { |
| 786 | pw.println(myPrefix + "mSplitScreenPrimaryStack=" + mSplitScreenPrimaryStack); |
| 787 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 790 | public void dumpStacks(PrintWriter pw) { |
| 791 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 792 | pw.print(mStacks.get(i).mStackId); |
| 793 | if (i > 0) { |
| 794 | pw.print(","); |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 799 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 800 | final long token = proto.start(fieldId); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 801 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 802 | proto.write(ID, mDisplayId); |
| 803 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 804 | final ActivityStack stack = mStacks.get(stackNdx); |
| 805 | stack.writeToProto(proto, STACKS); |
| 806 | } |
| 807 | proto.end(token); |
| 808 | } |
| 809 | } |