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