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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 18 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.ROTATION_UNDEFINED; |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
| 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 29 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 30 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 31 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 32 | import static android.os.Build.VERSION_CODES.N; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 33 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 34 | import static android.view.Display.FLAG_PRIVATE; |
| 35 | import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 36 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 37 | import static com.android.server.am.ActivityDisplayProto.CONFIGURATION_CONTAINER; |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 38 | import static com.android.server.am.ActivityDisplayProto.FOCUSED_STACK_ID; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 39 | import static com.android.server.am.ActivityDisplayProto.ID; |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 40 | import static com.android.server.am.ActivityDisplayProto.RESUMED_ACTIVITY; |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 41 | import static com.android.server.am.ActivityDisplayProto.SINGLE_TASK_INSTANCE; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 42 | import static com.android.server.am.ActivityDisplayProto.STACKS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 43 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 44 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 45 | import static com.android.server.wm.ActivityStackSupervisor.TAG_TASKS; |
| 46 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 47 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 48 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 49 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 50 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 51 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 52 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 53 | import static com.android.server.wm.RootActivityContainer.FindTaskResult; |
| 54 | import static com.android.server.wm.RootActivityContainer.TAG_STATES; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 55 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 56 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 57 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 58 | import android.annotation.Nullable; |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 59 | import android.app.ActivityManager; |
| 60 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 61 | import android.app.ActivityOptions; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 62 | import android.app.WindowConfiguration; |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 63 | import android.content.pm.ActivityInfo; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 64 | import android.content.res.Configuration; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 65 | import android.graphics.Point; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 66 | import android.os.IBinder; |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 67 | import android.os.Message; |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 68 | import android.os.UserHandle; |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 69 | import android.provider.Settings; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 70 | import android.util.IntArray; |
| 71 | import android.util.Slog; |
| 72 | import android.util.proto.ProtoOutputStream; |
| 73 | import android.view.Display; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 74 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 75 | import com.android.internal.annotations.VisibleForTesting; |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 76 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 77 | import com.android.server.am.EventLogTags; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 78 | import com.android.server.protolog.common.ProtoLog; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 79 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 80 | import java.io.PrintWriter; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 81 | import java.util.ArrayList; |
| 82 | |
| 83 | /** |
| 84 | * Exactly one of these classes per Display in the system. Capable of holding zero or more |
| 85 | * attached {@link ActivityStack}s. |
| 86 | */ |
Riddle Hsu | 5947c36 | 2019-09-23 18:52:36 +0800 | [diff] [blame] | 87 | class ActivityDisplay extends ConfigurationContainer<ActivityStack> { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 88 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityDisplay" : TAG_ATM; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 89 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
| 90 | |
| 91 | static final int POSITION_TOP = Integer.MAX_VALUE; |
| 92 | static final int POSITION_BOTTOM = Integer.MIN_VALUE; |
| 93 | |
Bryce Lee | d9cce2c | 2017-12-04 16:16:27 -0800 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * Counter for next free stack ID to use for dynamic activity stacks. Unique across displays. |
| 97 | */ |
| 98 | private static int sNextFreeStackId = 0; |
| 99 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 100 | private ActivityTaskManagerService mService; |
| 101 | private RootActivityContainer mRootActivityContainer; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 102 | // TODO: Remove once unification is complete. |
| 103 | DisplayContent mDisplayContent; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 104 | /** Actual Display this object tracks. */ |
| 105 | int mDisplayId; |
| 106 | Display mDisplay; |
| 107 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 108 | /** |
| 109 | * All of the stacks on this display. Order matters, topmost stack is in front of all other |
| 110 | * stacks, bottommost behind. Accessed directly by ActivityManager package classes. Any calls |
| 111 | * changing the list should also call {@link #onStackOrderChanged()}. |
| 112 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 113 | private final ArrayList<ActivityStack> mStacks = new ArrayList<>(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 114 | private ArrayList<OnStackOrderChangedListener> mStackOrderChangedCallbacks = new ArrayList<>(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 115 | |
| 116 | /** Array of all UIDs that are present on the display. */ |
| 117 | private IntArray mDisplayAccessUIDs = new IntArray(); |
| 118 | |
| 119 | /** All tokens used to put activities on this stack to sleep (including mOffToken) */ |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 120 | final ArrayList<ActivityTaskManagerInternal.SleepToken> mAllSleepTokens = new ArrayList<>(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 121 | /** The token acquired by ActivityStackSupervisor to put stacks on the display to sleep */ |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 122 | ActivityTaskManagerInternal.SleepToken mOffToken; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 123 | |
| 124 | private boolean mSleeping; |
| 125 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 126 | /** We started the process of removing the display from the system. */ |
| 127 | private boolean mRemoving; |
| 128 | |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 129 | /** |
| 130 | * The display is removed from the system and we are just waiting for all activities on it to be |
| 131 | * finished before removing this object. |
| 132 | */ |
| 133 | private boolean mRemoved; |
| 134 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 135 | /** The display can only contain one task. */ |
| 136 | private boolean mSingleTaskInstance; |
| 137 | |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 138 | /** |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 139 | * Non-null if the last size compatibility mode activity is using non-native screen |
| 140 | * configuration. The activity is not able to put in multi-window mode, so it exists only one |
| 141 | * per display. |
| 142 | */ |
| 143 | private ActivityRecord mLastCompatModeActivity; |
| 144 | |
| 145 | /** |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 146 | * A focusable stack that is purposely to be positioned at the top. Although the stack may not |
| 147 | * have the topmost index, it is used as a preferred candidate to prevent being unable to resume |
| 148 | * target stack properly when there are other focusable always-on-top stacks. |
| 149 | */ |
| 150 | private ActivityStack mPreferredTopFocusableStack; |
| 151 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 152 | /** |
| 153 | * If this is the same as {@link #getFocusedStack} then the activity on the top of the focused |
| 154 | * stack has been resumed. If stacks are changing position this will hold the old stack until |
| 155 | * the new stack becomes resumed after which it will be set to current focused stack. |
| 156 | */ |
| 157 | private ActivityStack mLastFocusedStack; |
| 158 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 159 | // Cached reference to some special stacks we tend to get a lot so we don't need to loop |
| 160 | // through the list to find them. |
| 161 | private ActivityStack mHomeStack = null; |
| 162 | private ActivityStack mRecentsStack = null; |
| 163 | private ActivityStack mPinnedStack = null; |
| 164 | private ActivityStack mSplitScreenPrimaryStack = null; |
| 165 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 166 | // Used in updating the display size |
| 167 | private Point mTmpDisplaySize = new Point(); |
| 168 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 169 | // Used in updating override configurations |
| 170 | private final Configuration mTempConfig = new Configuration(); |
| 171 | |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 172 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 173 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 174 | ActivityDisplay(RootActivityContainer root, Display display) { |
| 175 | mRootActivityContainer = root; |
| 176 | mService = root.mService; |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 177 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 178 | mDisplay = display; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 179 | mDisplayContent = mService.mWindowManager.mRoot.createDisplayContent(mDisplay, this); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 180 | mDisplayContent.reconfigureDisplayLocked(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 181 | onRequestedOverrideConfigurationChanged( |
| 182 | mDisplayContent.getRequestedOverrideConfiguration()); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 185 | void onDisplayChanged() { |
| 186 | // The window policy is responsible for stopping activities on the default display. |
| 187 | final int displayId = mDisplay.getDisplayId(); |
| 188 | if (displayId != DEFAULT_DISPLAY) { |
| 189 | final int displayState = mDisplay.getState(); |
| 190 | if (displayState == Display.STATE_OFF && mOffToken == null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 191 | mOffToken = mService.acquireSleepToken("Display-off", displayId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 192 | } else if (displayState == Display.STATE_ON && mOffToken != null) { |
| 193 | mOffToken.release(); |
| 194 | mOffToken = null; |
| 195 | } |
| 196 | } |
| 197 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 198 | mDisplay.getRealSize(mTmpDisplaySize); |
| 199 | setBounds(0, 0, mTmpDisplaySize.x, mTmpDisplaySize.y); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 200 | if (mDisplayContent != null) { |
| 201 | mDisplayContent.updateDisplayInfo(); |
| 202 | mService.mWindowManager.requestTraversal(); |
| 203 | } |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 204 | } |
| 205 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 206 | // TODO(display-unify): Merge with addChild below. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 207 | void addChild(ActivityStack stack, int position) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 208 | addChild(stack, position, false /*fromDc*/); |
| 209 | } |
| 210 | |
| 211 | void addChild(ActivityStack stack, int position, boolean fromDc) { |
| 212 | boolean toTop = position == POSITION_TOP; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 213 | if (position == POSITION_BOTTOM) { |
| 214 | position = 0; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 215 | } else if (toTop) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 216 | position = mStacks.size(); |
| 217 | } |
| 218 | if (DEBUG_STACK) Slog.v(TAG_STACK, "addChild: attaching " + stack |
| 219 | + " to displayId=" + mDisplayId + " position=" + position); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 220 | addStackReferenceIfNeeded(stack); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 221 | if (!fromDc) { |
| 222 | mDisplayContent.setStackOnDisplay(stack, position); |
| 223 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 224 | positionChildAt(stack, position); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 225 | mService.updateSleepIfNeededLocked(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 228 | // TODO(display-unify): Merge with removeChild below. |
| 229 | void onChildRemoved(ActivityStack stack) { |
| 230 | if (!mStacks.remove(stack)) { |
| 231 | // Stack no longer here! |
| 232 | return; |
| 233 | } |
| 234 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 235 | if (DEBUG_STACK) Slog.v(TAG_STACK, "removeChild: detaching " + stack |
| 236 | + " from displayId=" + mDisplayId); |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 237 | if (mPreferredTopFocusableStack == stack) { |
| 238 | mPreferredTopFocusableStack = null; |
| 239 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 240 | removeStackReferenceIfNeeded(stack); |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 241 | releaseSelfIfNeeded(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 242 | mService.updateSleepIfNeededLocked(); |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 243 | onStackOrderChanged(stack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 246 | void removeChild(ActivityStack stack) { |
| 247 | mDisplayContent.removeStackFromDisplay(stack); |
| 248 | } |
| 249 | |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 250 | void positionChildAtTop(ActivityStack stack, boolean includingParents) { |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 251 | positionChildAtTop(stack, includingParents, null /* updateLastFocusedStackReason */); |
| 252 | } |
| 253 | |
| 254 | void positionChildAtTop(ActivityStack stack, boolean includingParents, |
| 255 | String updateLastFocusedStackReason) { |
| 256 | positionChildAt(stack, mStacks.size(), includingParents, updateLastFocusedStackReason); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void positionChildAtBottom(ActivityStack stack) { |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 260 | positionChildAtBottom(stack, null /* updateLastFocusedStackReason */); |
| 261 | } |
| 262 | |
| 263 | void positionChildAtBottom(ActivityStack stack, String updateLastFocusedStackReason) { |
| 264 | positionChildAt(stack, 0, false /* includingParents */, updateLastFocusedStackReason); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | private void positionChildAt(ActivityStack stack, int position) { |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 268 | positionChildAt(stack, position, false /* includingParents */, |
| 269 | null /* updateLastFocusedStackReason */); |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 270 | } |
| 271 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 272 | private void positionChildAt(ActivityStack stack, int position, boolean includingParents, |
| 273 | String updateLastFocusedStackReason) { |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 274 | // TODO: Keep in sync with WindowContainer.positionChildAt(), once we change that to adjust |
| 275 | // the position internally, also update the logic here |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 276 | final ActivityStack prevFocusedStack = updateLastFocusedStackReason != null |
| 277 | ? getFocusedStack() : null; |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 278 | final boolean wasContained = mStacks.remove(stack); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 279 | if (mSingleTaskInstance && getChildCount() > 0) { |
| 280 | throw new IllegalStateException( |
| 281 | "positionChildAt: Can only have one child on display=" + this); |
| 282 | } |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 283 | final int insertPosition = getTopInsertPosition(stack, position); |
| 284 | mStacks.add(insertPosition, stack); |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 285 | |
| 286 | // The insert position may be adjusted to non-top when there is always-on-top stack. Since |
| 287 | // the original position is preferred to be top, the stack should have higher priority when |
| 288 | // we are looking for top focusable stack. The condition {@code wasContained} restricts the |
| 289 | // preferred stack is set only when moving an existing stack to top instead of adding a new |
| 290 | // stack that may be too early (e.g. in the middle of launching or reparenting). |
| 291 | if (wasContained && position >= mStacks.size() - 1 && stack.isFocusableAndVisible()) { |
| 292 | mPreferredTopFocusableStack = stack; |
| 293 | } else if (mPreferredTopFocusableStack == stack) { |
| 294 | mPreferredTopFocusableStack = null; |
| 295 | } |
| 296 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 297 | if (updateLastFocusedStackReason != null) { |
| 298 | final ActivityStack currentFocusedStack = getFocusedStack(); |
| 299 | if (currentFocusedStack != prevFocusedStack) { |
| 300 | mLastFocusedStack = prevFocusedStack; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 301 | EventLogTags.writeAmFocusedStack(mRootActivityContainer.mCurrentUser, mDisplayId, |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 302 | currentFocusedStack == null ? -1 : currentFocusedStack.getStackId(), |
| 303 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), |
| 304 | updateLastFocusedStackReason); |
| 305 | } |
| 306 | } |
| 307 | |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 308 | // Since positionChildAt() is called during the creation process of pinned stacks, |
Riddle Hsu | 5947c36 | 2019-09-23 18:52:36 +0800 | [diff] [blame] | 309 | // ActivityStack#getStack() can be null. |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 310 | if (mDisplayContent != null) { |
| 311 | mDisplayContent.positionStackAt(insertPosition, stack, includingParents); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 312 | } |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 313 | onStackOrderChanged(stack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | private int getTopInsertPosition(ActivityStack stack, int candidatePosition) { |
| 317 | int position = mStacks.size(); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 318 | if (stack.inPinnedWindowingMode()) { |
| 319 | // Stack in pinned windowing mode is z-ordered on-top of all other stacks so okay to |
| 320 | // just return the candidate position. |
| 321 | return Math.min(position, candidatePosition); |
| 322 | } |
| 323 | while (position > 0) { |
| 324 | final ActivityStack targetStack = mStacks.get(position - 1); |
| 325 | if (!targetStack.isAlwaysOnTop()) { |
| 326 | // We reached a stack that isn't always-on-top. |
| 327 | break; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 328 | } |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 329 | if (stack.isAlwaysOnTop() && !targetStack.inPinnedWindowingMode()) { |
| 330 | // Always on-top non-pinned windowing mode stacks can go anywhere below pinned stack. |
| 331 | break; |
| 332 | } |
| 333 | position--; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 334 | } |
| 335 | return Math.min(position, candidatePosition); |
| 336 | } |
| 337 | |
| 338 | <T extends ActivityStack> T getStack(int stackId) { |
| 339 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 340 | final ActivityStack stack = mStacks.get(i); |
| 341 | if (stack.mStackId == stackId) { |
| 342 | return (T) stack; |
| 343 | } |
| 344 | } |
| 345 | return null; |
| 346 | } |
| 347 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 348 | /** |
| 349 | * @return the topmost stack on the display that is compatible with the input windowing mode and |
| 350 | * activity type. {@code null} means no compatible stack on the display. |
| 351 | * @see ConfigurationContainer#isCompatible(int, int) |
| 352 | */ |
| 353 | <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 354 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 355 | return (T) mHomeStack; |
| 356 | } else if (activityType == ACTIVITY_TYPE_RECENTS) { |
| 357 | return (T) mRecentsStack; |
| 358 | } |
| 359 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 360 | return (T) mPinnedStack; |
| 361 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 362 | return (T) mSplitScreenPrimaryStack; |
| 363 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 364 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 365 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 366 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 367 | if (stack.isCompatible(windowingMode, activityType)) { |
| 368 | return (T) stack; |
| 369 | } |
| 370 | } |
| 371 | return null; |
| 372 | } |
| 373 | |
Louis Chang | 9d6ba28 | 2019-02-20 17:22:10 +0800 | [diff] [blame] | 374 | boolean alwaysCreateStack(int windowingMode, int activityType) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 375 | // Always create a stack for fullscreen, freeform, and split-screen-secondary windowing |
| 376 | // modes so that we can manage visual ordering and return types correctly. |
| 377 | return activityType == ACTIVITY_TYPE_STANDARD |
| 378 | && (windowingMode == WINDOWING_MODE_FULLSCREEN |
| 379 | || windowingMode == WINDOWING_MODE_FREEFORM |
| 380 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 381 | } |
| 382 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 383 | /** |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 384 | * Returns an existing stack compatible with the windowing mode and activity type or creates one |
| 385 | * if a compatible stack doesn't exist. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 386 | * @see #getStack(int, int) |
| 387 | * @see #createStack(int, int, boolean) |
| 388 | */ |
| 389 | <T extends ActivityStack> T getOrCreateStack(int windowingMode, int activityType, |
| 390 | boolean onTop) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 391 | if (!alwaysCreateStack(windowingMode, activityType)) { |
| 392 | T stack = getStack(windowingMode, activityType); |
| 393 | if (stack != null) { |
| 394 | return stack; |
| 395 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 396 | } |
| 397 | return createStack(windowingMode, activityType, onTop); |
| 398 | } |
| 399 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 400 | /** |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 401 | * Returns an existing stack compatible with the input params or creates one |
| 402 | * if a compatible stack doesn't exist. |
| 403 | * @see #getOrCreateStack(int, int, boolean) |
| 404 | */ |
| 405 | <T extends ActivityStack> T getOrCreateStack(@Nullable ActivityRecord r, |
| 406 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, int activityType, |
| 407 | boolean onTop) { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 408 | // First preference is the windowing mode in the activity options if set. |
| 409 | int windowingMode = (options != null) |
| 410 | ? options.getLaunchWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 411 | // Validate that our desired windowingMode will work under the current conditions. |
| 412 | // UNDEFINED windowing mode is a valid result and means that the new stack will inherit |
| 413 | // it's display's windowing mode. |
| 414 | windowingMode = validateWindowingMode(windowingMode, r, candidateTask, activityType); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 415 | return getOrCreateStack(windowingMode, activityType, onTop); |
| 416 | } |
| 417 | |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 418 | @VisibleForTesting |
| 419 | int getNextStackId() { |
Bryce Lee | d9cce2c | 2017-12-04 16:16:27 -0800 | [diff] [blame] | 420 | return sNextFreeStackId++; |
| 421 | } |
| 422 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 423 | /** |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 424 | * Creates a stack matching the input windowing mode and activity type on this display. |
| 425 | * @param windowingMode The windowing mode the stack should be created in. If |
| 426 | * {@link WindowConfiguration#WINDOWING_MODE_UNDEFINED} then the stack will |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 427 | * inherit it's parent's windowing mode. |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 428 | * @param activityType The activityType the stack should be created in. If |
| 429 | * {@link WindowConfiguration#ACTIVITY_TYPE_UNDEFINED} then the stack will |
| 430 | * be created in {@link WindowConfiguration#ACTIVITY_TYPE_STANDARD}. |
| 431 | * @param onTop If true the stack will be created at the top of the display, else at the bottom. |
| 432 | * @return The newly created stack. |
| 433 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 434 | <T extends ActivityStack> T createStack(int windowingMode, int activityType, boolean onTop) { |
| 435 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 436 | if (mSingleTaskInstance && getChildCount() > 0) { |
| 437 | // Create stack on default display instead since this display can only contain 1 stack. |
| 438 | // TODO: Kinda a hack, but better that having the decision at each call point. Hoping |
| 439 | // this goes away once ActivityView is no longer using virtual displays. |
| 440 | return mRootActivityContainer.getDefaultDisplay().createStack( |
| 441 | windowingMode, activityType, onTop); |
| 442 | } |
| 443 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 444 | if (activityType == ACTIVITY_TYPE_UNDEFINED) { |
| 445 | // Can't have an undefined stack type yet...so re-map to standard. Anyone that wants |
| 446 | // anything else should be passing it in anyways... |
| 447 | activityType = ACTIVITY_TYPE_STANDARD; |
| 448 | } |
| 449 | |
| 450 | if (activityType != ACTIVITY_TYPE_STANDARD) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 451 | // For now there can be only one stack of a particular non-standard activity type on a |
| 452 | // display. So, get that ignoring whatever windowing mode it is currently in. |
| 453 | T stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
| 454 | if (stack != null) { |
| 455 | throw new IllegalArgumentException("Stack=" + stack + " of activityType=" |
| 456 | + activityType + " already on display=" + this + ". Can't have multiple."); |
| 457 | } |
| 458 | } |
| 459 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 460 | if (!isWindowingModeSupported(windowingMode, mService.mSupportsMultiWindow, |
| 461 | mService.mSupportsSplitScreenMultiWindow, |
| 462 | mService.mSupportsFreeformWindowManagement, mService.mSupportsPictureInPicture, |
| 463 | activityType)) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 464 | throw new IllegalArgumentException("Can't create stack for unsupported windowingMode=" |
| 465 | + windowingMode); |
| 466 | } |
| 467 | |
Bryce Lee | d9cce2c | 2017-12-04 16:16:27 -0800 | [diff] [blame] | 468 | final int stackId = getNextStackId(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 469 | return createStackUnchecked(windowingMode, activityType, stackId, onTop); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | @VisibleForTesting |
| 473 | <T extends ActivityStack> T createStackUnchecked(int windowingMode, int activityType, |
| 474 | int stackId, boolean onTop) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 475 | if (windowingMode == WINDOWING_MODE_PINNED && activityType != ACTIVITY_TYPE_STANDARD) { |
| 476 | throw new IllegalArgumentException("Stack with windowing mode cannot with non standard " |
| 477 | + "activity type."); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 478 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 479 | return (T) new ActivityStack(this, stackId, |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 480 | mRootActivityContainer.mStackSupervisor, windowingMode, activityType, onTop); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 483 | /** |
| 484 | * Get the preferred focusable stack in priority. If the preferred stack does not exist, find a |
| 485 | * focusable and visible stack from the top of stacks in this display. |
| 486 | */ |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 487 | ActivityStack getFocusedStack() { |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 488 | if (mPreferredTopFocusableStack != null) { |
| 489 | return mPreferredTopFocusableStack; |
| 490 | } |
| 491 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 492 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 493 | final ActivityStack stack = mStacks.get(i); |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 494 | if (stack.isFocusableAndVisible()) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 495 | return stack; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return null; |
| 500 | } |
| 501 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 502 | ActivityStack getNextFocusableStack(ActivityStack currentFocus, boolean ignoreCurrent) { |
| 503 | final int currentWindowingMode = currentFocus != null |
| 504 | ? currentFocus.getWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 505 | |
| 506 | ActivityStack candidate = null; |
| 507 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 508 | final ActivityStack stack = mStacks.get(i); |
| 509 | if (ignoreCurrent && stack == currentFocus) { |
| 510 | continue; |
| 511 | } |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 512 | if (!stack.isFocusableAndVisible()) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 513 | continue; |
| 514 | } |
| 515 | |
| 516 | if (currentWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 517 | && candidate == null && stack.inSplitScreenPrimaryWindowingMode()) { |
| 518 | // If the currently focused stack is in split-screen secondary we save off the |
| 519 | // top primary split-screen stack as a candidate for focus because we might |
| 520 | // prefer focus to move to an other stack to avoid primary split-screen stack |
| 521 | // overlapping with a fullscreen stack when a fullscreen stack is higher in z |
| 522 | // than the next split-screen stack. Assistant stack, I am looking at you... |
| 523 | // We only move the focus to the primary-split screen stack if there isn't a |
| 524 | // better alternative. |
| 525 | candidate = stack; |
| 526 | continue; |
| 527 | } |
| 528 | if (candidate != null && stack.inSplitScreenSecondaryWindowingMode()) { |
| 529 | // Use the candidate stack since we are now at the secondary split-screen. |
| 530 | return candidate; |
| 531 | } |
| 532 | return stack; |
| 533 | } |
| 534 | return candidate; |
| 535 | } |
| 536 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 537 | ActivityRecord getResumedActivity() { |
| 538 | final ActivityStack focusedStack = getFocusedStack(); |
| 539 | if (focusedStack == null) { |
| 540 | return null; |
| 541 | } |
| 542 | // TODO(b/111541062): Move this into ActivityStack#getResumedActivity() |
| 543 | // Check if the focused stack has the resumed activity |
| 544 | ActivityRecord resumedActivity = focusedStack.getResumedActivity(); |
| 545 | if (resumedActivity == null || resumedActivity.app == null) { |
| 546 | // If there is no registered resumed activity in the stack or it is not running - |
| 547 | // try to use previously resumed one. |
| 548 | resumedActivity = focusedStack.mPausingActivity; |
| 549 | if (resumedActivity == null || resumedActivity.app == null) { |
| 550 | // If previously resumed activity doesn't work either - find the topmost running |
| 551 | // activity that can be focused. |
| 552 | resumedActivity = focusedStack.topRunningActivityLocked(true /* focusableOnly */); |
| 553 | } |
| 554 | } |
| 555 | return resumedActivity; |
| 556 | } |
| 557 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 558 | ActivityStack getLastFocusedStack() { |
| 559 | return mLastFocusedStack; |
| 560 | } |
| 561 | |
| 562 | boolean allResumedActivitiesComplete() { |
| 563 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 564 | final ActivityRecord r = mStacks.get(stackNdx).getResumedActivity(); |
| 565 | if (r != null && !r.isState(RESUMED)) { |
| 566 | return false; |
| 567 | } |
| 568 | } |
| 569 | final ActivityStack currentFocusedStack = getFocusedStack(); |
| 570 | if (DEBUG_STACK) { |
| 571 | Slog.d(TAG_STACK, "allResumedActivitiesComplete: mLastFocusedStack changing from=" |
| 572 | + mLastFocusedStack + " to=" + currentFocusedStack); |
| 573 | } |
| 574 | mLastFocusedStack = currentFocusedStack; |
| 575 | return true; |
| 576 | } |
| 577 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 578 | /** |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 579 | * Pause all activities in either all of the stacks or just the back stacks. This is done before |
| 580 | * resuming a new activity and to make sure that previously active activities are |
| 581 | * paused in stacks that are no longer visible or in pinned windowing mode. This does not |
| 582 | * pause activities in visible stacks, so if an activity is launched within the same stack/task, |
| 583 | * then we should explicitly pause that stack's top activity. |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 584 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
| 585 | * @param resuming The resuming activity. |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 586 | * @return {@code true} if any activity was paused as a result of this call. |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 587 | */ |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 588 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 589 | boolean someActivityPaused = false; |
| 590 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 591 | final ActivityStack stack = mStacks.get(stackNdx); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 592 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 593 | if (resumedActivity != null |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 594 | && (stack.getVisibility(resuming) != STACK_VISIBILITY_VISIBLE |
| 595 | || !stack.isFocusable())) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 596 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 597 | " mResumedActivity=" + resumedActivity); |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 598 | someActivityPaused |= stack.startPausingLocked(userLeaving, false /* uiSleeping*/, |
| 599 | resuming); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | return someActivityPaused; |
| 603 | } |
| 604 | |
| 605 | /** |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 606 | * Find task for putting the Activity in. |
| 607 | */ |
| 608 | void findTaskLocked(final ActivityRecord r, final boolean isPreferredDisplay, |
| 609 | FindTaskResult result) { |
| 610 | mTmpFindTaskResult.clear(); |
| 611 | for (int stackNdx = getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 612 | final ActivityStack stack = getChildAt(stackNdx); |
| 613 | if (!r.hasCompatibleActivityType(stack)) { |
| 614 | if (DEBUG_TASKS) { |
| 615 | Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " + stack); |
| 616 | } |
| 617 | continue; |
| 618 | } |
| 619 | |
| 620 | stack.findTaskLocked(r, mTmpFindTaskResult); |
| 621 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 622 | // we should keep looking after finding an affinity match to see if there is a |
| 623 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 624 | // to target a display which isn't the source of the intent, so skip any affinity |
| 625 | // matches not on the specified display. |
| 626 | if (mTmpFindTaskResult.mRecord != null) { |
| 627 | if (mTmpFindTaskResult.mIdealMatch) { |
| 628 | result.setTo(mTmpFindTaskResult); |
| 629 | return; |
| 630 | } else if (isPreferredDisplay) { |
| 631 | // Note: since the traversing through the stacks is top down, the floating |
| 632 | // tasks should always have lower priority than any affinity-matching tasks |
| 633 | // in the fullscreen stacks |
| 634 | result.setTo(mTmpFindTaskResult); |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /** |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 641 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 642 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 643 | */ |
| 644 | void removeStacksInWindowingModes(int... windowingModes) { |
| 645 | if (windowingModes == null || windowingModes.length == 0) { |
| 646 | return; |
| 647 | } |
| 648 | |
Louis Chang | f787e53 | 2019-01-15 12:46:49 +0800 | [diff] [blame] | 649 | // Collect the stacks that are necessary to be removed instead of performing the removal |
| 650 | // by looping mStacks, so that we don't miss any stacks after the stack size changed or |
| 651 | // stacks reordered. |
| 652 | final ArrayList<ActivityStack> stacks = new ArrayList<>(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 653 | for (int j = windowingModes.length - 1 ; j >= 0; --j) { |
| 654 | final int windowingMode = windowingModes[j]; |
| 655 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 656 | final ActivityStack stack = mStacks.get(i); |
| 657 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 658 | continue; |
| 659 | } |
| 660 | if (stack.getWindowingMode() != windowingMode) { |
| 661 | continue; |
| 662 | } |
Louis Chang | f787e53 | 2019-01-15 12:46:49 +0800 | [diff] [blame] | 663 | stacks.add(stack); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
Louis Chang | f787e53 | 2019-01-15 12:46:49 +0800 | [diff] [blame] | 666 | |
| 667 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 668 | mRootActivityContainer.mStackSupervisor.removeStack(stacks.get(i)); |
| 669 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 672 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 673 | if (activityTypes == null || activityTypes.length == 0) { |
| 674 | return; |
| 675 | } |
| 676 | |
Louis Chang | f787e53 | 2019-01-15 12:46:49 +0800 | [diff] [blame] | 677 | // Collect the stacks that are necessary to be removed instead of performing the removal |
| 678 | // by looping mStacks, so that we don't miss any stacks after the stack size changed or |
| 679 | // stacks reordered. |
| 680 | final ArrayList<ActivityStack> stacks = new ArrayList<>(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 681 | for (int j = activityTypes.length - 1 ; j >= 0; --j) { |
| 682 | final int activityType = activityTypes[j]; |
| 683 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 684 | final ActivityStack stack = mStacks.get(i); |
| 685 | if (stack.getActivityType() == activityType) { |
Louis Chang | f787e53 | 2019-01-15 12:46:49 +0800 | [diff] [blame] | 686 | stacks.add(stack); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | } |
Louis Chang | f787e53 | 2019-01-15 12:46:49 +0800 | [diff] [blame] | 690 | |
| 691 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 692 | mRootActivityContainer.mStackSupervisor.removeStack(stacks.get(i)); |
| 693 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 696 | void onStackWindowingModeChanged(ActivityStack stack) { |
| 697 | removeStackReferenceIfNeeded(stack); |
| 698 | addStackReferenceIfNeeded(stack); |
| 699 | } |
| 700 | |
| 701 | private void addStackReferenceIfNeeded(ActivityStack stack) { |
| 702 | final int activityType = stack.getActivityType(); |
| 703 | final int windowingMode = stack.getWindowingMode(); |
| 704 | |
| 705 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 706 | if (mHomeStack != null && mHomeStack != stack) { |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 707 | throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack=" |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 708 | + mHomeStack + " already exist on display=" + this + " stack=" + stack); |
| 709 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 710 | mHomeStack = stack; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 711 | } else if (activityType == ACTIVITY_TYPE_RECENTS) { |
| 712 | if (mRecentsStack != null && mRecentsStack != stack) { |
| 713 | throw new IllegalArgumentException("addStackReferenceIfNeeded: recents stack=" |
| 714 | + mRecentsStack + " already exist on display=" + this + " stack=" + stack); |
| 715 | } |
| 716 | mRecentsStack = stack; |
| 717 | } |
| 718 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 719 | if (mPinnedStack != null && mPinnedStack != stack) { |
| 720 | throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack=" |
| 721 | + mPinnedStack + " already exist on display=" + this |
| 722 | + " stack=" + stack); |
| 723 | } |
| 724 | mPinnedStack = stack; |
| 725 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 726 | if (mSplitScreenPrimaryStack != null && mSplitScreenPrimaryStack != stack) { |
| 727 | throw new IllegalArgumentException("addStackReferenceIfNeeded:" |
| 728 | + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack |
| 729 | + " already exist on display=" + this + " stack=" + stack); |
| 730 | } |
| 731 | mSplitScreenPrimaryStack = stack; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 732 | onSplitScreenModeActivated(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
| 736 | private void removeStackReferenceIfNeeded(ActivityStack stack) { |
| 737 | if (stack == mHomeStack) { |
| 738 | mHomeStack = null; |
| 739 | } else if (stack == mRecentsStack) { |
| 740 | mRecentsStack = null; |
| 741 | } else if (stack == mPinnedStack) { |
| 742 | mPinnedStack = null; |
| 743 | } else if (stack == mSplitScreenPrimaryStack) { |
| 744 | mSplitScreenPrimaryStack = null; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 745 | // Inform the reset of the system that split-screen mode was dismissed so things like |
| 746 | // resizing all the other stacks can take place. |
| 747 | onSplitScreenModeDismissed(); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | private void onSplitScreenModeDismissed() { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 752 | mService.deferWindowLayout(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 753 | try { |
| 754 | // Adjust the windowing mode of any stack in secondary split-screen to fullscreen. |
| 755 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 756 | final ActivityStack otherStack = mStacks.get(i); |
| 757 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 758 | continue; |
| 759 | } |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 760 | otherStack.setWindowingMode(WINDOWING_MODE_UNDEFINED, false /* animate */, |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 761 | false /* showRecents */, false /* enteringSplitScreenMode */, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 762 | true /* deferEnsuringVisibility */, false /* creating */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 763 | } |
| 764 | } finally { |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 765 | final ActivityStack topFullscreenStack = |
Wale Ogunwale | f325785 | 2018-01-24 08:52:28 -0800 | [diff] [blame] | 766 | getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 767 | if (topFullscreenStack != null && mHomeStack != null && !isTopStack(mHomeStack)) { |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 768 | // 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] | 769 | // 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] | 770 | // TODO: Would be better to use ActivityDisplay.positionChildAt() for this, however |
| 771 | // ActivityDisplay doesn't have a direct controller to WM side yet. We can switch |
| 772 | // once we have that. |
| 773 | mHomeStack.moveToFront("onSplitScreenModeDismissed"); |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 774 | topFullscreenStack.moveToFront("onSplitScreenModeDismissed"); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 775 | } |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 776 | mService.continueWindowLayout(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
| 780 | private void onSplitScreenModeActivated() { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 781 | mService.deferWindowLayout(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 782 | try { |
| 783 | // Adjust the windowing mode of any affected by split-screen to split-screen secondary. |
| 784 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 785 | final ActivityStack otherStack = mStacks.get(i); |
| 786 | if (otherStack == mSplitScreenPrimaryStack |
| 787 | || !otherStack.affectedBySplitScreenResize()) { |
| 788 | continue; |
| 789 | } |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 790 | otherStack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, |
| 791 | false /* animate */, false /* showRecents */, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 792 | true /* enteringSplitScreenMode */, true /* deferEnsuringVisibility */, |
| 793 | false /* creating */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 794 | } |
| 795 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 796 | mService.continueWindowLayout(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 800 | /** |
| 801 | * Returns true if the {@param windowingMode} is supported based on other parameters passed in. |
| 802 | * @param windowingMode The windowing mode we are checking support for. |
| 803 | * @param supportsMultiWindow If we should consider support for multi-window mode in general. |
| 804 | * @param supportsSplitScreen If we should consider support for split-screen multi-window. |
| 805 | * @param supportsFreeform If we should consider support for freeform multi-window. |
| 806 | * @param supportsPip If we should consider support for picture-in-picture mutli-window. |
| 807 | * @param activityType The activity type under consideration. |
| 808 | * @return true if the windowing mode is supported. |
| 809 | */ |
| 810 | private boolean isWindowingModeSupported(int windowingMode, boolean supportsMultiWindow, |
| 811 | boolean supportsSplitScreen, boolean supportsFreeform, boolean supportsPip, |
| 812 | int activityType) { |
| 813 | |
| 814 | if (windowingMode == WINDOWING_MODE_UNDEFINED |
| 815 | || windowingMode == WINDOWING_MODE_FULLSCREEN) { |
| 816 | return true; |
| 817 | } |
| 818 | if (!supportsMultiWindow) { |
| 819 | return false; |
| 820 | } |
| 821 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 822 | final int displayWindowingMode = getWindowingMode(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 823 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 824 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 825 | return supportsSplitScreen |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 826 | && WindowConfiguration.supportSplitScreenWindowingMode(activityType) |
| 827 | // Freeform windows and split-screen windows don't mix well, so prevent |
| 828 | // split windowing modes on freeform displays. |
| 829 | && displayWindowingMode != WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | if (!supportsFreeform && windowingMode == WINDOWING_MODE_FREEFORM) { |
| 833 | return false; |
| 834 | } |
| 835 | |
| 836 | if (!supportsPip && windowingMode == WINDOWING_MODE_PINNED) { |
| 837 | return false; |
| 838 | } |
| 839 | return true; |
| 840 | } |
| 841 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 842 | /** |
| 843 | * Resolves the windowing mode that an {@link ActivityRecord} would be in if started on this |
| 844 | * display with the provided parameters. |
| 845 | * |
| 846 | * @param r The ActivityRecord in question. |
| 847 | * @param options Options to start with. |
| 848 | * @param task The task within-which the activity would start. |
| 849 | * @param activityType The type of activity to start. |
| 850 | * @return The resolved (not UNDEFINED) windowing-mode that the activity would be in. |
| 851 | */ |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 852 | int resolveWindowingMode(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
| 853 | @Nullable TaskRecord task, int activityType) { |
| 854 | |
| 855 | // First preference if the windowing mode in the activity options if set. |
| 856 | int windowingMode = (options != null) |
| 857 | ? options.getLaunchWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 858 | |
| 859 | // If windowing mode is unset, then next preference is the candidate task, then the |
| 860 | // activity record. |
| 861 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 862 | if (task != null) { |
| 863 | windowingMode = task.getWindowingMode(); |
| 864 | } |
| 865 | if (windowingMode == WINDOWING_MODE_UNDEFINED && r != null) { |
| 866 | windowingMode = r.getWindowingMode(); |
| 867 | } |
| 868 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 869 | // Use the display's windowing mode. |
| 870 | windowingMode = getWindowingMode(); |
| 871 | } |
| 872 | } |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 873 | windowingMode = validateWindowingMode(windowingMode, r, task, activityType); |
| 874 | return windowingMode != WINDOWING_MODE_UNDEFINED |
| 875 | ? windowingMode : WINDOWING_MODE_FULLSCREEN; |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 876 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 877 | |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 878 | /** |
| 879 | * Check that the requested windowing-mode is appropriate for the specified task and/or activity |
| 880 | * on this display. |
| 881 | * |
| 882 | * @param windowingMode The windowing-mode to validate. |
| 883 | * @param r The {@link ActivityRecord} to check against. |
| 884 | * @param task The {@link TaskRecord} to check against. |
| 885 | * @param activityType An activity type. |
| 886 | * @return The provided windowingMode or the closest valid mode which is appropriate. |
| 887 | */ |
| 888 | int validateWindowingMode(int windowingMode, @Nullable ActivityRecord r, |
| 889 | @Nullable TaskRecord task, int activityType) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 890 | // Make sure the windowing mode we are trying to use makes sense for what is supported. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 891 | boolean supportsMultiWindow = mService.mSupportsMultiWindow; |
| 892 | boolean supportsSplitScreen = mService.mSupportsSplitScreenMultiWindow; |
| 893 | boolean supportsFreeform = mService.mSupportsFreeformWindowManagement; |
| 894 | boolean supportsPip = mService.mSupportsPictureInPicture; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 895 | if (supportsMultiWindow) { |
| 896 | if (task != null) { |
| 897 | supportsMultiWindow = task.isResizeable(); |
| 898 | supportsSplitScreen = task.supportsSplitScreenWindowingMode(); |
| 899 | // TODO: Do we need to check for freeform and Pip support here? |
| 900 | } else if (r != null) { |
| 901 | supportsMultiWindow = r.isResizeable(); |
| 902 | supportsSplitScreen = r.supportsSplitScreenWindowingMode(); |
| 903 | supportsFreeform = r.supportsFreeform(); |
| 904 | supportsPip = r.supportsPictureInPicture(); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | final boolean inSplitScreenMode = hasSplitScreenPrimaryStack(); |
| 909 | if (!inSplitScreenMode |
| 910 | && windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY) { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 911 | // Switch to the display's windowing mode if we are not in split-screen mode and we are |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 912 | // trying to launch in split-screen secondary. |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 913 | windowingMode = WINDOWING_MODE_UNDEFINED; |
| 914 | } else if (inSplitScreenMode && (windowingMode == WINDOWING_MODE_FULLSCREEN |
| 915 | || windowingMode == WINDOWING_MODE_UNDEFINED) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 916 | && supportsSplitScreen) { |
| 917 | windowingMode = WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 918 | } |
| 919 | |
| 920 | if (windowingMode != WINDOWING_MODE_UNDEFINED |
| 921 | && isWindowingModeSupported(windowingMode, supportsMultiWindow, supportsSplitScreen, |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 922 | supportsFreeform, supportsPip, activityType)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 923 | return windowingMode; |
| 924 | } |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 925 | return WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 928 | /** |
| 929 | * Get the topmost stack on the display. It may be different from focused stack, because |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 930 | * some stacks are not focusable (e.g. PiP). |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 931 | */ |
| 932 | ActivityStack getTopStack() { |
| 933 | return mStacks.isEmpty() ? null : mStacks.get(mStacks.size() - 1); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 936 | boolean isTopStack(ActivityStack stack) { |
| 937 | return stack == getTopStack(); |
| 938 | } |
| 939 | |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 940 | boolean isTopNotPinnedStack(ActivityStack stack) { |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 941 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 942 | final ActivityStack current = mStacks.get(i); |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 943 | if (!current.inPinnedWindowingMode()) { |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 944 | return current == stack; |
| 945 | } |
| 946 | } |
| 947 | return false; |
| 948 | } |
| 949 | |
Wale Ogunwale | f325785 | 2018-01-24 08:52:28 -0800 | [diff] [blame] | 950 | ActivityStack getTopStackInWindowingMode(int windowingMode) { |
| 951 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 952 | final ActivityStack current = mStacks.get(i); |
| 953 | if (windowingMode == current.getWindowingMode()) { |
| 954 | return current; |
| 955 | } |
| 956 | } |
| 957 | return null; |
| 958 | } |
| 959 | |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 960 | ActivityRecord topRunningActivity() { |
| 961 | return topRunningActivity(false /* considerKeyguardState */); |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * Returns the top running activity in the focused stack. In the case the focused stack has no |
| 966 | * such activity, the next focusable stack on this display is returned. |
| 967 | * |
| 968 | * @param considerKeyguardState Indicates whether the locked state should be considered. if |
| 969 | * {@code true} and the keyguard is locked, only activities that |
| 970 | * can be shown on top of the keyguard will be considered. |
| 971 | * @return The top running activity. {@code null} if none is available. |
| 972 | */ |
| 973 | ActivityRecord topRunningActivity(boolean considerKeyguardState) { |
| 974 | ActivityRecord topRunning = null; |
| 975 | final ActivityStack focusedStack = getFocusedStack(); |
| 976 | if (focusedStack != null) { |
| 977 | topRunning = focusedStack.topRunningActivityLocked(); |
| 978 | } |
| 979 | |
| 980 | // Look in other focusable stacks. |
| 981 | if (topRunning == null) { |
| 982 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 983 | final ActivityStack stack = mStacks.get(i); |
| 984 | // Only consider focusable stacks other than the current focused one. |
| 985 | if (stack == focusedStack || !stack.isFocusable()) { |
| 986 | continue; |
| 987 | } |
| 988 | topRunning = stack.topRunningActivityLocked(); |
| 989 | if (topRunning != null) { |
| 990 | break; |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | // This activity can be considered the top running activity if we are not considering |
| 996 | // the locked state, the keyguard isn't locked, or we can show when locked. |
| 997 | if (topRunning != null && considerKeyguardState |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 998 | && mRootActivityContainer.mStackSupervisor.getKeyguardController().isKeyguardLocked() |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 999 | && !topRunning.canShowWhenLocked()) { |
| 1000 | return null; |
| 1001 | } |
| 1002 | |
| 1003 | return topRunning; |
| 1004 | } |
| 1005 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1006 | int getIndexOf(ActivityStack stack) { |
| 1007 | return mStacks.indexOf(stack); |
| 1008 | } |
| 1009 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1010 | boolean updateDisplayOverrideConfigurationLocked() { |
| 1011 | Configuration values = new Configuration(); |
| 1012 | mDisplayContent.computeScreenConfiguration(values); |
| 1013 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1014 | mService.mH.sendMessage(PooledLambda.obtainMessage( |
| 1015 | ActivityManagerInternal::updateOomLevelsForDisplay, mService.mAmInternal, |
| 1016 | mDisplayId)); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1017 | |
| 1018 | Settings.System.clearConfiguration(values); |
| 1019 | updateDisplayOverrideConfigurationLocked(values, null /* starting */, |
| 1020 | false /* deferResume */, mService.mTmpUpdateConfigurationResult); |
| 1021 | return mService.mTmpUpdateConfigurationResult.changes != 0; |
| 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * Updates override configuration specific for the selected display. If no config is provided, |
| 1026 | * new one will be computed in WM based on current display info. |
| 1027 | */ |
| 1028 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, |
| 1029 | ActivityRecord starting, boolean deferResume, |
| 1030 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 1031 | |
| 1032 | int changes = 0; |
| 1033 | boolean kept = true; |
| 1034 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1035 | mService.deferWindowLayout(); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1036 | try { |
| 1037 | if (values != null) { |
| 1038 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 1039 | // Override configuration of the default display duplicates global config, so |
| 1040 | // we're calling global config update instead for default display. It will also |
| 1041 | // apply the correct override config. |
| 1042 | changes = mService.updateGlobalConfigurationLocked(values, |
| 1043 | false /* initLocale */, false /* persistent */, |
| 1044 | UserHandle.USER_NULL /* userId */, deferResume); |
| 1045 | } else { |
| 1046 | changes = performDisplayOverrideConfigUpdate(values, deferResume); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | kept = mService.ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 1051 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1052 | mService.continueWindowLayout(); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | if (result != null) { |
| 1056 | result.changes = changes; |
| 1057 | result.activityRelaunched = !kept; |
| 1058 | } |
| 1059 | return kept; |
| 1060 | } |
| 1061 | |
| 1062 | int performDisplayOverrideConfigUpdate(Configuration values, boolean deferResume) { |
| 1063 | mTempConfig.setTo(getRequestedOverrideConfiguration()); |
| 1064 | final int changes = mTempConfig.updateFrom(values); |
| 1065 | if (changes != 0) { |
| 1066 | Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " |
| 1067 | + mTempConfig + " for displayId=" + mDisplayId); |
| 1068 | onRequestedOverrideConfigurationChanged(mTempConfig); |
| 1069 | |
| 1070 | final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; |
| 1071 | if (isDensityChange && mDisplayId == DEFAULT_DISPLAY) { |
| 1072 | mService.mAppWarnings.onDensityChanged(); |
| 1073 | |
| 1074 | // Post message to start process to avoid possible deadlock of calling into AMS with |
| 1075 | // the ATMS lock held. |
| 1076 | final Message msg = PooledLambda.obtainMessage( |
| 1077 | ActivityManagerInternal::killAllBackgroundProcessesExcept, |
| 1078 | mService.mAmInternal, N, |
| 1079 | ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); |
| 1080 | mService.mH.sendMessage(msg); |
| 1081 | } |
| 1082 | } |
| 1083 | return changes; |
| 1084 | } |
| 1085 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1086 | @Override |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1087 | public void onRequestedOverrideConfigurationChanged(Configuration overrideConfiguration) { |
| 1088 | final int currRotation = |
| 1089 | getRequestedOverrideConfiguration().windowConfiguration.getRotation(); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1090 | if (currRotation != ROTATION_UNDEFINED |
| 1091 | && currRotation != overrideConfiguration.windowConfiguration.getRotation() |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1092 | && mDisplayContent != null) { |
| 1093 | mDisplayContent.applyRotationLocked(currRotation, |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1094 | overrideConfiguration.windowConfiguration.getRotation()); |
| 1095 | } |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1096 | super.onRequestedOverrideConfigurationChanged(overrideConfiguration); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1097 | if (mDisplayContent != null) { |
| 1098 | mService.mWindowManager.setNewDisplayOverrideConfiguration( |
| 1099 | overrideConfiguration, mDisplayContent); |
| 1100 | } |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1101 | mService.addWindowLayoutReasons( |
| 1102 | ActivityTaskManagerService.LAYOUT_REASON_CONFIG_CHANGED); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | @Override |
| 1106 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 1107 | // update resources before cascade so that docked/pinned stacks use the correct info |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1108 | if (mDisplayContent != null) { |
| 1109 | mDisplayContent.preOnConfigurationChanged(); |
| 1110 | } |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1111 | super.onConfigurationChanged(newParentConfig); |
| 1112 | } |
| 1113 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1114 | void onLockTaskPackagesUpdated() { |
| 1115 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 1116 | mStacks.get(i).onLockTaskPackagesUpdated(); |
| 1117 | } |
| 1118 | } |
| 1119 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1120 | /** We are in the process of exiting split-screen mode. */ |
| 1121 | void onExitingSplitScreenMode() { |
| 1122 | // Remove reference to the primary-split-screen stack so it no longer has any effect on the |
| 1123 | // display. For example, we want to be able to create fullscreen stack for standard activity |
| 1124 | // types when exiting split-screen mode. |
| 1125 | mSplitScreenPrimaryStack = null; |
| 1126 | } |
| 1127 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1128 | /** Checks whether the given activity is in size compatibility mode and notifies the change. */ |
| 1129 | void handleActivitySizeCompatModeIfNeeded(ActivityRecord r) { |
| 1130 | if (!r.isState(RESUMED) || r.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 1131 | // The callback is only interested in the foreground changes of fullscreen activity. |
| 1132 | return; |
| 1133 | } |
| 1134 | if (!r.inSizeCompatMode()) { |
| 1135 | if (mLastCompatModeActivity != null) { |
| 1136 | mService.getTaskChangeNotificationController() |
| 1137 | .notifySizeCompatModeActivityChanged(mDisplayId, null /* activityToken */); |
| 1138 | } |
| 1139 | mLastCompatModeActivity = null; |
| 1140 | return; |
| 1141 | } |
| 1142 | if (mLastCompatModeActivity == r) { |
| 1143 | return; |
| 1144 | } |
| 1145 | mLastCompatModeActivity = r; |
| 1146 | mService.getTaskChangeNotificationController() |
| 1147 | .notifySizeCompatModeActivityChanged(mDisplayId, r.appToken); |
| 1148 | } |
| 1149 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1150 | ActivityStack getSplitScreenPrimaryStack() { |
| 1151 | return mSplitScreenPrimaryStack; |
| 1152 | } |
| 1153 | |
| 1154 | boolean hasSplitScreenPrimaryStack() { |
| 1155 | return mSplitScreenPrimaryStack != null; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1158 | ActivityStack getPinnedStack() { |
| 1159 | return mPinnedStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | boolean hasPinnedStack() { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1163 | return mPinnedStack != null; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1166 | @Override |
| 1167 | public String toString() { |
| 1168 | return "ActivityDisplay={" + mDisplayId + " numStacks=" + mStacks.size() + "}"; |
| 1169 | } |
| 1170 | |
| 1171 | @Override |
| 1172 | protected int getChildCount() { |
| 1173 | return mStacks.size(); |
| 1174 | } |
| 1175 | |
| 1176 | @Override |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1177 | protected ActivityStack getChildAt(int index) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1178 | return mStacks.get(index); |
| 1179 | } |
| 1180 | |
| 1181 | @Override |
| 1182 | protected ConfigurationContainer getParent() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1183 | return mRootActivityContainer; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | boolean isPrivate() { |
| 1187 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
| 1188 | } |
| 1189 | |
| 1190 | boolean isUidPresent(int uid) { |
| 1191 | for (ActivityStack stack : mStacks) { |
| 1192 | if (stack.isUidPresent(uid)) { |
| 1193 | return true; |
| 1194 | } |
| 1195 | } |
| 1196 | return false; |
| 1197 | } |
| 1198 | |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1199 | /** |
| 1200 | * @see #mRemoved |
| 1201 | */ |
| 1202 | boolean isRemoved() { |
| 1203 | return mRemoved; |
| 1204 | } |
| 1205 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 1206 | /** |
| 1207 | * @see #mRemoving |
| 1208 | */ |
| 1209 | boolean isRemoving() { |
| 1210 | return mRemoving; |
| 1211 | } |
| 1212 | |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 1213 | void remove() { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 1214 | mRemoving = true; |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 1215 | final boolean destroyContentOnRemoval = shouldDestroyContentOnRemove(); |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1216 | ActivityStack lastReparentedStack = null; |
| 1217 | mPreferredTopFocusableStack = null; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1218 | |
| 1219 | // Stacks could be reparented from the removed display to other display. While |
| 1220 | // reparenting the last stack of the removed display, the remove display is ready to be |
| 1221 | // released (no more ActivityStack). But, we cannot release it at that moment or the |
Riddle Hsu | 5947c36 | 2019-09-23 18:52:36 +0800 | [diff] [blame] | 1222 | // related WindowContainer will also be removed. So, we set display as removed after |
| 1223 | // reparenting stack finished. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1224 | final ActivityDisplay toDisplay = mRootActivityContainer.getDefaultDisplay(); |
| 1225 | mRootActivityContainer.mStackSupervisor.beginDeferResume(); |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1226 | try { |
| 1227 | int numStacks = mStacks.size(); |
| 1228 | // Keep the order from bottom to top. |
| 1229 | for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { |
| 1230 | final ActivityStack stack = mStacks.get(stackNdx); |
| 1231 | // Always finish non-standard type stacks. |
| 1232 | if (destroyContentOnRemoval || !stack.isActivityTypeStandardOrUndefined()) { |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 1233 | stack.finishAllActivitiesImmediately(); |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1234 | } else { |
| 1235 | // If default display is in split-window mode, set windowing mode of the stack |
| 1236 | // to split-screen secondary. Otherwise, set the windowing mode to undefined by |
| 1237 | // default to let stack inherited the windowing mode from the new display. |
| 1238 | final int windowingMode = toDisplay.hasSplitScreenPrimaryStack() |
| 1239 | ? WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 1240 | : WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 1241 | stack.reparent(toDisplay.mDisplayContent, true /* onTop */); |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1242 | stack.setWindowingMode(windowingMode); |
| 1243 | lastReparentedStack = stack; |
| 1244 | } |
| 1245 | // Stacks may be removed from this display. Ensure each stack will be processed and |
| 1246 | // the loop will end. |
| 1247 | stackNdx -= numStacks - mStacks.size(); |
| 1248 | numStacks = mStacks.size(); |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 1249 | } |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1250 | } finally { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1251 | mRootActivityContainer.mStackSupervisor.endDeferResume(); |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 1252 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1253 | mRemoved = true; |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 1254 | |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1255 | // Only update focus/visibility for the last one because there may be many stacks are |
| 1256 | // reparented and the intermediate states are unnecessary. |
| 1257 | if (lastReparentedStack != null) { |
| 1258 | lastReparentedStack.postReparent(); |
| 1259 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1260 | releaseSelfIfNeeded(); |
wilsonshih | 0299c8a | 2018-08-24 15:52:57 +0800 | [diff] [blame] | 1261 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 1262 | if (!mAllSleepTokens.isEmpty()) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1263 | mRootActivityContainer.mSleepTokens.removeAll(mAllSleepTokens); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 1264 | mAllSleepTokens.clear(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1265 | mService.updateSleepIfNeededLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 1266 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | private void releaseSelfIfNeeded() { |
Louis Chang | cc56871 | 2019-03-08 14:54:41 +0800 | [diff] [blame] | 1270 | if (!mRemoved || mDisplayContent == null) { |
| 1271 | return; |
| 1272 | } |
| 1273 | |
| 1274 | final ActivityStack stack = mStacks.size() == 1 ? mStacks.get(0) : null; |
| 1275 | if (stack != null && stack.isActivityTypeHome() && stack.getAllTasks().isEmpty()) { |
| 1276 | // Release this display if an empty home stack is the only thing left. |
| 1277 | // Since it is the last stack, this display will be released along with the stack |
| 1278 | // removal. |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame^] | 1279 | stack.removeIfPossible(); |
Louis Chang | cc56871 | 2019-03-08 14:54:41 +0800 | [diff] [blame] | 1280 | } else if (mStacks.isEmpty()) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1281 | mDisplayContent.removeIfPossible(); |
| 1282 | mDisplayContent = null; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1283 | mRootActivityContainer.removeChild(this); |
| 1284 | mRootActivityContainer.mStackSupervisor |
| 1285 | .getKeyguardController().onDisplayRemoved(mDisplayId); |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1286 | } |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1289 | /** Update and get all UIDs that are present on the display and have access to it. */ |
| 1290 | IntArray getPresentUIDs() { |
| 1291 | mDisplayAccessUIDs.clear(); |
| 1292 | for (ActivityStack stack : mStacks) { |
| 1293 | stack.getPresentUIDs(mDisplayAccessUIDs); |
| 1294 | } |
| 1295 | return mDisplayAccessUIDs; |
| 1296 | } |
| 1297 | |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1298 | /** |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 1299 | * Checks if system decorations should be shown on this display. |
| 1300 | * |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1301 | * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS |
| 1302 | */ |
| 1303 | boolean supportsSystemDecorations() { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1304 | return mDisplayContent.supportsSystemDecorations(); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1305 | } |
| 1306 | |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1307 | @VisibleForTesting |
| 1308 | boolean shouldDestroyContentOnRemove() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1309 | return mDisplay.getRemoveMode() == REMOVE_MODE_DESTROY_CONTENT; |
| 1310 | } |
| 1311 | |
| 1312 | boolean shouldSleep() { |
| 1313 | return (mStacks.isEmpty() || !mAllSleepTokens.isEmpty()) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1314 | && (mService.mRunningVoice == null); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 1317 | void setFocusedApp(ActivityRecord r, boolean moveFocusNow) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1318 | if (mDisplayContent == null) { |
| 1319 | return; |
| 1320 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1321 | final ActivityRecord newFocus; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1322 | final IBinder token = r.appToken; |
| 1323 | if (token == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1324 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "Clearing focused app, displayId=%d", |
| 1325 | mDisplayId); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1326 | newFocus = null; |
| 1327 | } else { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1328 | newFocus = mService.mWindowManager.mRoot.getActivityRecord(token); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1329 | if (newFocus == null) { |
| 1330 | Slog.w(TAG_WM, "Attempted to set focus to non-existing app token: " + token |
| 1331 | + ", displayId=" + mDisplayId); |
| 1332 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1333 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 1334 | "Set focused app to: %s moveFocusNow=%b displayId=%d", newFocus, |
| 1335 | moveFocusNow, mDisplayId); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | final boolean changed = mDisplayContent.setFocusedApp(newFocus); |
| 1339 | if (moveFocusNow && changed) { |
| 1340 | mService.mWindowManager.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 1341 | true /*updateInputWindows*/); |
| 1342 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 1343 | } |
| 1344 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1345 | /** |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1346 | * @return the stack currently above the {@param stack}. Can be null if the {@param stack} is |
| 1347 | * already top-most. |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1348 | */ |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1349 | ActivityStack getStackAbove(ActivityStack stack) { |
| 1350 | final int stackIndex = mStacks.indexOf(stack) + 1; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1351 | return (stackIndex < mStacks.size()) ? mStacks.get(stackIndex) : null; |
| 1352 | } |
| 1353 | |
| 1354 | /** |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1355 | * Adjusts the {@param stack} behind the last visible stack in the display if necessary. |
| 1356 | * Generally used in conjunction with {@link #moveStackBehindStack}. |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1357 | */ |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1358 | void moveStackBehindBottomMostVisibleStack(ActivityStack stack) { |
| 1359 | if (stack.shouldBeVisible(null)) { |
| 1360 | // Skip if the stack is already visible |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1361 | return; |
| 1362 | } |
| 1363 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1364 | // Move the stack to the bottom to not affect the following visibility checks |
| 1365 | positionChildAtBottom(stack); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1366 | |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1367 | // Find the next position where the stack should be placed |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1368 | final int numStacks = mStacks.size(); |
| 1369 | for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1370 | final ActivityStack s = mStacks.get(stackNdx); |
| 1371 | if (s == stack) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1372 | continue; |
| 1373 | } |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1374 | final int winMode = s.getWindowingMode(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1375 | final boolean isValidWindowingMode = winMode == WINDOWING_MODE_FULLSCREEN || |
| 1376 | winMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1377 | if (s.shouldBeVisible(null) && isValidWindowingMode) { |
| 1378 | // Move the provided stack to behind this stack |
| 1379 | positionChildAt(stack, Math.max(0, stackNdx - 1)); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1380 | break; |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | /** |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1386 | * Moves the {@param stack} behind the given {@param behindStack} if possible. If |
| 1387 | * {@param behindStack} is not currently in the display, then then the stack is moved to the |
| 1388 | * back. Generally used in conjunction with {@link #moveStackBehindBottomMostVisibleStack}. |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1389 | */ |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1390 | void moveStackBehindStack(ActivityStack stack, ActivityStack behindStack) { |
| 1391 | if (behindStack == null || behindStack == stack) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1392 | return; |
| 1393 | } |
| 1394 | |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 1395 | // Note that positionChildAt will first remove the given stack before inserting into the |
| 1396 | // list, so we need to adjust the insertion index to account for the removed index |
| 1397 | // TODO: Remove this logic when WindowContainer.positionChildAt() is updated to adjust the |
| 1398 | // position internally |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1399 | final int stackIndex = mStacks.indexOf(stack); |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 1400 | final int behindStackIndex = mStacks.indexOf(behindStack); |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1401 | final int insertIndex = stackIndex <= behindStackIndex |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 1402 | ? behindStackIndex - 1 : behindStackIndex; |
Winson Chung | 3e2980e | 2018-03-29 17:28:57 -0700 | [diff] [blame] | 1403 | positionChildAt(stack, Math.max(0, insertIndex)); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
Louis Chang | 77ce34d | 2019-01-03 15:45:12 +0800 | [diff] [blame] | 1406 | void ensureActivitiesVisible(ActivityRecord starting, int configChanges, |
| 1407 | boolean preserveWindows, boolean notifyClients) { |
| 1408 | for (int stackNdx = getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1409 | final ActivityStack stack = getChildAt(stackNdx); |
| 1410 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
| 1411 | notifyClients); |
| 1412 | } |
| 1413 | } |
| 1414 | |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1415 | void moveHomeStackToFront(String reason) { |
| 1416 | if (mHomeStack != null) { |
| 1417 | mHomeStack.moveToFront(reason); |
| 1418 | } |
| 1419 | } |
| 1420 | |
Riddle Hsu | 2b9a6d7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 1421 | /** |
| 1422 | * Moves the focusable home activity to top. If there is no such activity, the home stack will |
| 1423 | * still move to top. |
| 1424 | */ |
| 1425 | void moveHomeActivityToTop(String reason) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1426 | final ActivityRecord top = getHomeActivity(); |
| 1427 | if (top == null) { |
Riddle Hsu | 2b9a6d7 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 1428 | moveHomeStackToFront(reason); |
| 1429 | return; |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1430 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1431 | top.moveFocusableActivityToTop(reason); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | @Nullable |
| 1435 | ActivityStack getHomeStack() { |
| 1436 | return mHomeStack; |
| 1437 | } |
| 1438 | |
| 1439 | @Nullable |
| 1440 | ActivityRecord getHomeActivity() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1441 | return getHomeActivityForUser(mRootActivityContainer.mCurrentUser); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | @Nullable |
| 1445 | ActivityRecord getHomeActivityForUser(int userId) { |
| 1446 | if (mHomeStack == null) { |
| 1447 | return null; |
| 1448 | } |
| 1449 | |
| 1450 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 1451 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1452 | final TaskRecord task = tasks.get(taskNdx); |
| 1453 | if (!task.isActivityTypeHome()) { |
| 1454 | continue; |
| 1455 | } |
| 1456 | |
Wale Ogunwale | 1a06f15 | 2019-10-11 11:26:30 +0200 | [diff] [blame] | 1457 | for (int activityNdx = task.getChildCount() - 1; activityNdx >= 0; --activityNdx) { |
| 1458 | final ActivityRecord r = task.getChildAt(activityNdx); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1459 | if (r.isActivityTypeHome() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1460 | && ((userId == UserHandle.USER_ALL) || (r.mUserId == userId))) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1461 | return r; |
| 1462 | } |
| 1463 | } |
| 1464 | } |
| 1465 | return null; |
| 1466 | } |
| 1467 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1468 | boolean isSleeping() { |
| 1469 | return mSleeping; |
| 1470 | } |
| 1471 | |
| 1472 | void setIsSleeping(boolean asleep) { |
| 1473 | mSleeping = asleep; |
| 1474 | } |
| 1475 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1476 | /** |
| 1477 | * Adds a listener to be notified whenever the stack order in the display changes. Currently |
| 1478 | * only used by the {@link RecentsAnimation} to determine whether to interrupt and cancel the |
| 1479 | * current animation when the system state changes. |
| 1480 | */ |
| 1481 | void registerStackOrderChangedListener(OnStackOrderChangedListener listener) { |
| 1482 | if (!mStackOrderChangedCallbacks.contains(listener)) { |
| 1483 | mStackOrderChangedCallbacks.add(listener); |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | /** |
| 1488 | * Removes a previously registered stack order change listener. |
| 1489 | */ |
| 1490 | void unregisterStackOrderChangedListener(OnStackOrderChangedListener listener) { |
| 1491 | mStackOrderChangedCallbacks.remove(listener); |
| 1492 | } |
| 1493 | |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 1494 | /** |
| 1495 | * Notifies of a stack order change |
| 1496 | * @param stack The stack which triggered the order change |
| 1497 | */ |
| 1498 | private void onStackOrderChanged(ActivityStack stack) { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1499 | for (int i = mStackOrderChangedCallbacks.size() - 1; i >= 0; i--) { |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 1500 | mStackOrderChangedCallbacks.get(i).onStackOrderChanged(stack); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 1504 | /** |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1505 | * See {@link DisplayContent#deferUpdateImeTarget()} |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 1506 | */ |
| 1507 | public void deferUpdateImeTarget() { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1508 | if (mDisplayContent != null) { |
| 1509 | mDisplayContent.deferUpdateImeTarget(); |
| 1510 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | /** |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1514 | * See {@link DisplayContent#deferUpdateImeTarget()} |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 1515 | */ |
| 1516 | public void continueUpdateImeTarget() { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1517 | if (mDisplayContent != null) { |
| 1518 | mDisplayContent.continueUpdateImeTarget(); |
| 1519 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 1522 | void setDisplayToSingleTaskInstance() { |
| 1523 | final int childCount = getChildCount(); |
| 1524 | if (childCount > 1) { |
| 1525 | throw new IllegalArgumentException("Display already has multiple stacks. display=" |
| 1526 | + this); |
| 1527 | } |
| 1528 | if (childCount > 0) { |
| 1529 | final ActivityStack stack = getChildAt(0); |
| 1530 | if (stack.getChildCount() > 1) { |
| 1531 | throw new IllegalArgumentException("Display stack already has multiple tasks." |
| 1532 | + " display=" + this + " stack=" + stack); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | mSingleTaskInstance = true; |
| 1537 | } |
| 1538 | |
| 1539 | /** Returns true if the display can only contain one task */ |
| 1540 | boolean isSingleTaskInstance() { |
| 1541 | return mSingleTaskInstance; |
| 1542 | } |
| 1543 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1544 | @VisibleForTesting |
| 1545 | void removeAllTasks() { |
| 1546 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 1547 | final ActivityStack stack = getChildAt(i); |
| 1548 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1549 | for (int j = tasks.size() - 1; j >= 0; --j) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1550 | stack.removeChild(tasks.get(j), "removeAllTasks"); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1555 | public void dump(PrintWriter pw, String prefix) { |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 1556 | pw.println(prefix + "displayId=" + mDisplayId + " stacks=" + mStacks.size() |
| 1557 | + (mSingleTaskInstance ? " mSingleTaskInstance" : "")); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1558 | final String myPrefix = prefix + " "; |
| 1559 | if (mHomeStack != null) { |
| 1560 | pw.println(myPrefix + "mHomeStack=" + mHomeStack); |
| 1561 | } |
| 1562 | if (mRecentsStack != null) { |
| 1563 | pw.println(myPrefix + "mRecentsStack=" + mRecentsStack); |
| 1564 | } |
| 1565 | if (mPinnedStack != null) { |
| 1566 | pw.println(myPrefix + "mPinnedStack=" + mPinnedStack); |
| 1567 | } |
| 1568 | if (mSplitScreenPrimaryStack != null) { |
| 1569 | pw.println(myPrefix + "mSplitScreenPrimaryStack=" + mSplitScreenPrimaryStack); |
| 1570 | } |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 1571 | if (mPreferredTopFocusableStack != null) { |
| 1572 | pw.println(myPrefix + "mPreferredTopFocusableStack=" + mPreferredTopFocusableStack); |
| 1573 | } |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 1574 | if (mLastFocusedStack != null) { |
| 1575 | pw.println(myPrefix + "mLastFocusedStack=" + mLastFocusedStack); |
| 1576 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 1579 | public void dumpStacks(PrintWriter pw) { |
| 1580 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 1581 | pw.print(mStacks.get(i).mStackId); |
| 1582 | if (i > 0) { |
| 1583 | pw.print(","); |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1588 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 1589 | @WindowTraceLogLevel int logLevel) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1590 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1591 | super.writeToProto(proto, CONFIGURATION_CONTAINER, logLevel); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1592 | proto.write(ID, mDisplayId); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 1593 | proto.write(SINGLE_TASK_INSTANCE, mSingleTaskInstance); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 1594 | final ActivityStack focusedStack = getFocusedStack(); |
| 1595 | if (focusedStack != null) { |
| 1596 | proto.write(FOCUSED_STACK_ID, focusedStack.mStackId); |
| 1597 | final ActivityRecord focusedActivity = focusedStack.getDisplay().getResumedActivity(); |
| 1598 | if (focusedActivity != null) { |
| 1599 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 1600 | } |
| 1601 | } else { |
| 1602 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 1603 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1604 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1605 | final ActivityStack stack = mStacks.get(stackNdx); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1606 | stack.writeToProto(proto, STACKS, logLevel); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1607 | } |
| 1608 | proto.end(token); |
| 1609 | } |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1610 | |
| 1611 | /** |
| 1612 | * Callback for when the order of the stacks in the display changes. |
| 1613 | */ |
| 1614 | interface OnStackOrderChangedListener { |
Winson Chung | 65d66d3 | 2018-12-13 17:48:39 -0800 | [diff] [blame] | 1615 | void onStackOrderChanged(ActivityStack stack); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1616 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1617 | } |