Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
| 20 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
| 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 24 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 25 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 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; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 32 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
| 33 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 34 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
| 35 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 36 | import static android.view.Display.DEFAULT_DISPLAY; |
| 37 | import static android.view.Display.INVALID_DISPLAY; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame^] | 38 | import static android.view.WindowManager.TRANSIT_SHOW_SINGLE_TASK_DISPLAY; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 39 | |
| 40 | import static com.android.server.am.ActivityStackSupervisorProto.CONFIGURATION_CONTAINER; |
| 41 | import static com.android.server.am.ActivityStackSupervisorProto.DISPLAYS; |
| 42 | import static com.android.server.am.ActivityStackSupervisorProto.FOCUSED_STACK_ID; |
| 43 | import static com.android.server.am.ActivityStackSupervisorProto.IS_HOME_RECENTS_COMPONENT; |
| 44 | import static com.android.server.am.ActivityStackSupervisorProto.KEYGUARD_CONTROLLER; |
| 45 | import static com.android.server.am.ActivityStackSupervisorProto.PENDING_ACTIVITIES; |
| 46 | import static com.android.server.am.ActivityStackSupervisorProto.RESUMED_ACTIVITY; |
| 47 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 48 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 49 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 50 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
| 51 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
| 52 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 53 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 54 | import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList; |
| 55 | import static com.android.server.wm.ActivityStackSupervisor.printThisActivity; |
| 56 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS; |
| 57 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RELEASE; |
| 58 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 59 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 60 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 61 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RECENTS; |
| 62 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RELEASE; |
| 63 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; |
| 64 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; |
| 65 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 66 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 67 | import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; |
| 68 | import static com.android.server.wm.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
| 69 | import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
| 70 | |
| 71 | import static java.lang.Integer.MAX_VALUE; |
| 72 | |
| 73 | import android.annotation.IntDef; |
| 74 | import android.annotation.NonNull; |
| 75 | import android.annotation.Nullable; |
| 76 | import android.annotation.UserIdInt; |
| 77 | import android.app.ActivityManager; |
| 78 | import android.app.ActivityOptions; |
| 79 | import android.app.AppGlobals; |
| 80 | import android.app.WindowConfiguration; |
| 81 | import android.content.ComponentName; |
| 82 | import android.content.Intent; |
| 83 | import android.content.pm.ActivityInfo; |
| 84 | import android.content.pm.ApplicationInfo; |
| 85 | import android.content.pm.ResolveInfo; |
| 86 | import android.content.res.Configuration; |
| 87 | import android.content.res.Resources; |
| 88 | import android.graphics.Rect; |
| 89 | import android.hardware.display.DisplayManager; |
| 90 | import android.hardware.display.DisplayManagerInternal; |
| 91 | import android.hardware.power.V1_0.PowerHint; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 92 | import android.os.FactoryTest; |
| 93 | import android.os.IBinder; |
| 94 | import android.os.RemoteException; |
| 95 | import android.os.SystemClock; |
| 96 | import android.os.Trace; |
| 97 | import android.os.UserHandle; |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 98 | import android.os.storage.StorageManager; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 99 | import android.provider.Settings; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 100 | import android.service.voice.IVoiceInteractionSession; |
| 101 | import android.util.ArraySet; |
| 102 | import android.util.DisplayMetrics; |
| 103 | import android.util.IntArray; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 104 | import android.util.Pair; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 105 | import android.util.Slog; |
| 106 | import android.util.SparseArray; |
| 107 | import android.util.SparseIntArray; |
| 108 | import android.util.TimeUtils; |
| 109 | import android.util.proto.ProtoOutputStream; |
| 110 | import android.view.Display; |
| 111 | import android.view.DisplayInfo; |
| 112 | |
| 113 | import com.android.internal.annotations.VisibleForTesting; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 114 | import com.android.internal.app.ResolverActivity; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 115 | import com.android.server.LocalServices; |
| 116 | import com.android.server.am.ActivityManagerService; |
| 117 | import com.android.server.am.AppTimeTracker; |
| 118 | import com.android.server.am.UserState; |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 119 | import com.android.server.policy.WindowManagerPolicy; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 120 | |
| 121 | import java.io.FileDescriptor; |
| 122 | import java.io.PrintWriter; |
| 123 | import java.lang.annotation.Retention; |
| 124 | import java.lang.annotation.RetentionPolicy; |
| 125 | import java.util.ArrayList; |
| 126 | import java.util.Iterator; |
| 127 | import java.util.List; |
| 128 | import java.util.Set; |
| 129 | |
| 130 | /** |
| 131 | * Root node for activity containers. |
| 132 | * TODO: This class is mostly temporary to separate things out of ActivityStackSupervisor.java. The |
| 133 | * intention is to have this merged with RootWindowContainer.java as part of unifying the hierarchy. |
| 134 | */ |
Wale Ogunwale | 31acb3f | 2018-11-20 15:23:55 -0800 | [diff] [blame] | 135 | class RootActivityContainer extends ConfigurationContainer |
| 136 | implements DisplayManager.DisplayListener { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 137 | |
| 138 | private static final String TAG = TAG_WITH_CLASS_NAME ? "RootActivityContainer" : TAG_ATM; |
| 139 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 140 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
| 141 | static final String TAG_STATES = TAG + POSTFIX_STATES; |
| 142 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
| 143 | |
| 144 | /** |
| 145 | * The modes which affect which tasks are returned when calling |
| 146 | * {@link RootActivityContainer#anyTaskForId(int)}. |
| 147 | */ |
| 148 | @Retention(RetentionPolicy.SOURCE) |
| 149 | @IntDef({ |
| 150 | MATCH_TASK_IN_STACKS_ONLY, |
| 151 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 152 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 153 | }) |
| 154 | public @interface AnyTaskForIdMatchTaskMode {} |
| 155 | // Match only tasks in the current stacks |
| 156 | static final int MATCH_TASK_IN_STACKS_ONLY = 0; |
| 157 | // Match either tasks in the current stacks, or in the recent tasks if not found in the stacks |
| 158 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS = 1; |
| 159 | // Match either tasks in the current stacks, or in the recent tasks, restoring it to the |
| 160 | // provided stack id |
| 161 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE = 2; |
| 162 | |
| 163 | ActivityTaskManagerService mService; |
| 164 | ActivityStackSupervisor mStackSupervisor; |
| 165 | WindowManagerService mWindowManager; |
| 166 | DisplayManager mDisplayManager; |
| 167 | private DisplayManagerInternal mDisplayManagerInternal; |
Wale Ogunwale | 31acb3f | 2018-11-20 15:23:55 -0800 | [diff] [blame] | 168 | // TODO: Remove after object merge with RootWindowContainer. |
| 169 | private RootWindowContainer mRootWindowContainer; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * List of displays which contain activities, sorted by z-order. |
| 173 | * The last entry in the list is the topmost. |
| 174 | */ |
| 175 | private final ArrayList<ActivityDisplay> mActivityDisplays = new ArrayList<>(); |
| 176 | |
| 177 | /** Reference to default display so we can quickly look it up. */ |
| 178 | private ActivityDisplay mDefaultDisplay; |
| 179 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 180 | |
| 181 | /** The current user */ |
| 182 | int mCurrentUser; |
| 183 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 184 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
| 185 | |
| 186 | /** |
| 187 | * A list of tokens that cause the top activity to be put to sleep. |
| 188 | * They are used by components that may hide and block interaction with underlying |
| 189 | * activities. |
| 190 | */ |
| 191 | final ArrayList<ActivityTaskManagerInternal.SleepToken> mSleepTokens = new ArrayList<>(); |
| 192 | |
| 193 | /** Is dock currently minimized. */ |
| 194 | boolean mIsDockMinimized; |
| 195 | |
| 196 | /** Set when a power hint has started, but not ended. */ |
| 197 | private boolean mPowerHintSent; |
| 198 | |
| 199 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 200 | // It will be calculated when the default display gets added. |
| 201 | int mDefaultMinSizeOfResizeableTaskDp = -1; |
| 202 | |
| 203 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 204 | private boolean mTaskLayersChanged = true; |
| 205 | |
| 206 | private final ArrayList<ActivityRecord> mTmpActivityList = new ArrayList<>(); |
| 207 | |
| 208 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 209 | static class FindTaskResult { |
| 210 | ActivityRecord mRecord; |
| 211 | boolean mIdealMatch; |
| 212 | |
| 213 | void clear() { |
| 214 | mRecord = null; |
| 215 | mIdealMatch = false; |
| 216 | } |
| 217 | |
| 218 | void setTo(FindTaskResult result) { |
| 219 | mRecord = result.mRecord; |
| 220 | mIdealMatch = result.mIdealMatch; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | RootActivityContainer(ActivityTaskManagerService service) { |
| 225 | mService = service; |
| 226 | mStackSupervisor = service.mStackSupervisor; |
| 227 | mStackSupervisor.mRootActivityContainer = this; |
| 228 | } |
| 229 | |
| 230 | @VisibleForTesting |
Wale Ogunwale | 31acb3f | 2018-11-20 15:23:55 -0800 | [diff] [blame] | 231 | void setWindowContainer(RootWindowContainer container) { |
| 232 | mRootWindowContainer = container; |
| 233 | mRootWindowContainer.setRootActivityContainer(this); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void setWindowManager(WindowManagerService wm) { |
| 237 | mWindowManager = wm; |
Wale Ogunwale | 31acb3f | 2018-11-20 15:23:55 -0800 | [diff] [blame] | 238 | setWindowContainer(mWindowManager.mRoot); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 239 | mDisplayManager = mService.mContext.getSystemService(DisplayManager.class); |
Charles Chen | 699e360 | 2019-01-10 15:00:25 +0800 | [diff] [blame] | 240 | mDisplayManager.registerDisplayListener(this, mService.mUiHandler); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 241 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
| 242 | |
| 243 | final Display[] displays = mDisplayManager.getDisplays(); |
| 244 | for (int displayNdx = 0; displayNdx < displays.length; ++displayNdx) { |
| 245 | final Display display = displays[displayNdx]; |
| 246 | final ActivityDisplay activityDisplay = new ActivityDisplay(this, display); |
| 247 | if (activityDisplay.mDisplayId == DEFAULT_DISPLAY) { |
| 248 | mDefaultDisplay = activityDisplay; |
| 249 | } |
| 250 | addChild(activityDisplay, ActivityDisplay.POSITION_TOP); |
| 251 | } |
| 252 | calculateDefaultMinimalSizeOfResizeableTasks(); |
| 253 | |
| 254 | final ActivityDisplay defaultDisplay = getDefaultDisplay(); |
| 255 | |
| 256 | defaultDisplay.getOrCreateStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
| 257 | positionChildAt(defaultDisplay, ActivityDisplay.POSITION_TOP); |
| 258 | } |
| 259 | |
| 260 | // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display. |
| 261 | ActivityDisplay getDefaultDisplay() { |
| 262 | return mDefaultDisplay; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Get an existing instance of {@link ActivityDisplay} that has the given uniqueId. Unique ID is |
| 267 | * defined in {@link DisplayInfo#uniqueId}. |
| 268 | * |
| 269 | * @param uniqueId the unique ID of the display |
| 270 | * @return the {@link ActivityDisplay} or {@code null} if nothing is found. |
| 271 | */ |
| 272 | ActivityDisplay getActivityDisplay(String uniqueId) { |
| 273 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 274 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 275 | final boolean isValid = display.mDisplay.isValid(); |
| 276 | if (isValid && display.mDisplay.getUniqueId().equals(uniqueId)) { |
| 277 | return display; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | return null; |
| 282 | } |
| 283 | |
| 284 | // TODO: Look into consolidating with getActivityDisplayOrCreate() |
| 285 | ActivityDisplay getActivityDisplay(int displayId) { |
| 286 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 287 | final ActivityDisplay activityDisplay = mActivityDisplays.get(i); |
| 288 | if (activityDisplay.mDisplayId == displayId) { |
| 289 | return activityDisplay; |
| 290 | } |
| 291 | } |
| 292 | return null; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 297 | * corresponding record in display manager. |
| 298 | */ |
| 299 | // TODO: Look into consolidating with getActivityDisplay() |
Charles Chen | b409e6c | 2019-02-12 12:30:17 +0800 | [diff] [blame] | 300 | @Nullable ActivityDisplay getActivityDisplayOrCreate(int displayId) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 301 | ActivityDisplay activityDisplay = getActivityDisplay(displayId); |
| 302 | if (activityDisplay != null) { |
| 303 | return activityDisplay; |
| 304 | } |
| 305 | if (mDisplayManager == null) { |
| 306 | // The system isn't fully initialized yet. |
| 307 | return null; |
| 308 | } |
| 309 | final Display display = mDisplayManager.getDisplay(displayId); |
| 310 | if (display == null) { |
| 311 | // The display is not registered in DisplayManager. |
| 312 | return null; |
| 313 | } |
| 314 | // The display hasn't been added to ActivityManager yet, create a new record now. |
| 315 | activityDisplay = new ActivityDisplay(this, display); |
| 316 | addChild(activityDisplay, ActivityDisplay.POSITION_BOTTOM); |
| 317 | return activityDisplay; |
| 318 | } |
| 319 | |
| 320 | /** Check if display with specified id is added to the list. */ |
| 321 | boolean isDisplayAdded(int displayId) { |
| 322 | return getActivityDisplayOrCreate(displayId) != null; |
| 323 | } |
| 324 | |
| 325 | ActivityRecord getDefaultDisplayHomeActivity() { |
| 326 | return getDefaultDisplayHomeActivityForUser(mCurrentUser); |
| 327 | } |
| 328 | |
| 329 | ActivityRecord getDefaultDisplayHomeActivityForUser(int userId) { |
| 330 | return getActivityDisplay(DEFAULT_DISPLAY).getHomeActivityForUser(userId); |
| 331 | } |
| 332 | |
| 333 | boolean startHomeOnAllDisplays(int userId, String reason) { |
| 334 | boolean homeStarted = false; |
| 335 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
| 336 | final int displayId = mActivityDisplays.get(i).mDisplayId; |
| 337 | homeStarted |= startHomeOnDisplay(userId, reason, displayId); |
| 338 | } |
| 339 | return homeStarted; |
| 340 | } |
| 341 | |
Louis Chang | dcdde95 | 2018-12-04 15:38:44 +0800 | [diff] [blame] | 342 | void startHomeOnEmptyDisplays(String reason) { |
| 343 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
| 344 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 345 | if (display.topRunningActivity() == null) { |
| 346 | startHomeOnDisplay(mCurrentUser, reason, display.mDisplayId); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 351 | boolean startHomeOnDisplay(int userId, String reason, int displayId) { |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 352 | return startHomeOnDisplay(userId, reason, displayId, false /* allowInstrumenting */, |
| 353 | false /* fromHomeKey */); |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 354 | } |
| 355 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 356 | /** |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 357 | * This starts home activity on displays that can have system decorations based on displayId - |
| 358 | * Default display always use primary home component. |
| 359 | * For Secondary displays, the home activity must have category SECONDARY_HOME and then resolves |
| 360 | * according to the priorities listed below. |
| 361 | * - If default home is not set, always use the secondary home defined in the config. |
| 362 | * - Use currently selected primary home activity. |
| 363 | * - Use the activity in the same package as currently selected primary home activity. |
| 364 | * If there are multiple activities matched, use first one. |
| 365 | * - Use the secondary home defined in the config. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 366 | */ |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 367 | boolean startHomeOnDisplay(int userId, String reason, int displayId, boolean allowInstrumenting, |
| 368 | boolean fromHomeKey) { |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 369 | // Fallback to top focused display if the displayId is invalid. |
| 370 | if (displayId == INVALID_DISPLAY) { |
| 371 | displayId = getTopDisplayFocusedStack().mDisplayId; |
| 372 | } |
| 373 | |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 374 | Intent homeIntent = null; |
| 375 | ActivityInfo aInfo = null; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 376 | if (displayId == DEFAULT_DISPLAY) { |
| 377 | homeIntent = mService.getHomeIntent(); |
| 378 | aInfo = resolveHomeActivity(userId, homeIntent); |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 379 | } else if (shouldPlaceSecondaryHomeOnDisplay(displayId)) { |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 380 | Pair<ActivityInfo, Intent> info = resolveSecondaryHomeActivity(userId, displayId); |
| 381 | aInfo = info.first; |
| 382 | homeIntent = info.second; |
| 383 | } |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 384 | if (aInfo == null || homeIntent == null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 385 | return false; |
| 386 | } |
| 387 | |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 388 | if (!canStartHomeOnDisplay(aInfo, displayId, allowInstrumenting)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 389 | return false; |
| 390 | } |
| 391 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 392 | // Updates the home component of the intent. |
| 393 | homeIntent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name)); |
| 394 | homeIntent.setFlags(homeIntent.getFlags() | FLAG_ACTIVITY_NEW_TASK); |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 395 | // Updates the extra information of the intent. |
| 396 | if (fromHomeKey) { |
| 397 | homeIntent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, true); |
| 398 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 399 | // Update the reason for ANR debugging to verify if the user activity is the one that |
| 400 | // actually launched. |
| 401 | final String myReason = reason + ":" + userId + ":" + UserHandle.getUserId( |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 402 | aInfo.applicationInfo.uid) + ":" + displayId; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 403 | mService.getActivityStartController().startHomeActivity(homeIntent, aInfo, myReason, |
| 404 | displayId); |
| 405 | return true; |
| 406 | } |
| 407 | |
| 408 | /** |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 409 | * This resolves the home activity info. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 410 | * @return the home activity info if any. |
| 411 | */ |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 412 | @VisibleForTesting |
| 413 | ActivityInfo resolveHomeActivity(int userId, Intent homeIntent) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 414 | final int flags = ActivityManagerService.STOCK_PM_FLAGS; |
| 415 | final ComponentName comp = homeIntent.getComponent(); |
| 416 | ActivityInfo aInfo = null; |
| 417 | try { |
| 418 | if (comp != null) { |
| 419 | // Factory test. |
| 420 | aInfo = AppGlobals.getPackageManager().getActivityInfo(comp, flags, userId); |
| 421 | } else { |
| 422 | final String resolvedType = |
| 423 | homeIntent.resolveTypeIfNeeded(mService.mContext.getContentResolver()); |
| 424 | final ResolveInfo info = AppGlobals.getPackageManager() |
| 425 | .resolveIntent(homeIntent, resolvedType, flags, userId); |
| 426 | if (info != null) { |
| 427 | aInfo = info.activityInfo; |
| 428 | } |
| 429 | } |
| 430 | } catch (RemoteException e) { |
| 431 | // ignore |
| 432 | } |
| 433 | |
| 434 | if (aInfo == null) { |
| 435 | Slog.wtf(TAG, "No home screen found for " + homeIntent, new Throwable()); |
| 436 | return null; |
| 437 | } |
| 438 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 439 | aInfo = new ActivityInfo(aInfo); |
| 440 | aInfo.applicationInfo = mService.getAppInfoForUser(aInfo.applicationInfo, userId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 441 | return aInfo; |
| 442 | } |
| 443 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 444 | @VisibleForTesting |
| 445 | Pair<ActivityInfo, Intent> resolveSecondaryHomeActivity(int userId, int displayId) { |
| 446 | if (displayId == DEFAULT_DISPLAY) { |
| 447 | throw new IllegalArgumentException( |
| 448 | "resolveSecondaryHomeActivity: Should not be DEFAULT_DISPLAY"); |
| 449 | } |
| 450 | // Resolve activities in the same package as currently selected primary home activity. |
| 451 | Intent homeIntent = mService.getHomeIntent(); |
| 452 | ActivityInfo aInfo = resolveHomeActivity(userId, homeIntent); |
| 453 | if (aInfo != null) { |
| 454 | if (ResolverActivity.class.getName().equals(aInfo.name)) { |
| 455 | // Always fallback to secondary home component if default home is not set. |
| 456 | aInfo = null; |
| 457 | } else { |
| 458 | // Look for secondary home activities in the currently selected default home |
| 459 | // package. |
| 460 | homeIntent = mService.getSecondaryHomeIntent(aInfo.applicationInfo.packageName); |
| 461 | final List<ResolveInfo> resolutions = resolveActivities(userId, homeIntent); |
| 462 | final int size = resolutions.size(); |
| 463 | final String targetName = aInfo.name; |
| 464 | aInfo = null; |
| 465 | for (int i = 0; i < size; i++) { |
| 466 | ResolveInfo resolveInfo = resolutions.get(i); |
| 467 | // We need to traverse all resolutions to check if the currently selected |
| 468 | // default home activity is present. |
| 469 | if (resolveInfo.activityInfo.name.equals(targetName)) { |
| 470 | aInfo = resolveInfo.activityInfo; |
| 471 | break; |
| 472 | } |
| 473 | } |
| 474 | if (aInfo == null && size > 0) { |
| 475 | // First one is the best. |
| 476 | aInfo = resolutions.get(0).activityInfo; |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | if (aInfo != null) { |
| 482 | if (!canStartHomeOnDisplay(aInfo, displayId, false /* allowInstrumenting */)) { |
| 483 | aInfo = null; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | // Fallback to secondary home component. |
| 488 | if (aInfo == null) { |
| 489 | homeIntent = mService.getSecondaryHomeIntent(null); |
| 490 | aInfo = resolveHomeActivity(userId, homeIntent); |
| 491 | } |
| 492 | return Pair.create(aInfo, homeIntent); |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Retrieve all activities that match the given intent. |
| 497 | * The list should already ordered from best to worst matched. |
| 498 | * {@link android.content.pm.PackageManager#queryIntentActivities} |
| 499 | */ |
| 500 | @VisibleForTesting |
| 501 | List<ResolveInfo> resolveActivities(int userId, Intent homeIntent) { |
| 502 | List<ResolveInfo> resolutions; |
| 503 | try { |
| 504 | final String resolvedType = |
| 505 | homeIntent.resolveTypeIfNeeded(mService.mContext.getContentResolver()); |
| 506 | resolutions = AppGlobals.getPackageManager().queryIntentActivities(homeIntent, |
| 507 | resolvedType, ActivityManagerService.STOCK_PM_FLAGS, userId).getList(); |
| 508 | |
| 509 | } catch (RemoteException e) { |
| 510 | resolutions = new ArrayList<>(); |
| 511 | } |
| 512 | return resolutions; |
| 513 | } |
| 514 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 515 | boolean resumeHomeActivity(ActivityRecord prev, String reason, int displayId) { |
| 516 | if (!mService.isBooting() && !mService.isBooted()) { |
| 517 | // Not ready yet! |
| 518 | return false; |
| 519 | } |
| 520 | |
| 521 | if (displayId == INVALID_DISPLAY) { |
| 522 | displayId = DEFAULT_DISPLAY; |
| 523 | } |
| 524 | |
| 525 | final ActivityRecord r = getActivityDisplay(displayId).getHomeActivity(); |
| 526 | final String myReason = reason + " resumeHomeActivity"; |
| 527 | |
| 528 | // Only resume home activity if isn't finishing. |
| 529 | if (r != null && !r.finishing) { |
| 530 | r.moveFocusableActivityToTop(myReason); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 531 | return resumeFocusedStacksTopActivities(r.getActivityStack(), prev, null); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 532 | } |
| 533 | return startHomeOnDisplay(mCurrentUser, myReason, displayId); |
| 534 | } |
| 535 | |
| 536 | /** |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 537 | * Check if the display is valid for secondary home activity. |
| 538 | * @param displayId The id of the target display. |
| 539 | * @return {@code true} if allow to launch, {@code false} otherwise. |
| 540 | */ |
| 541 | boolean shouldPlaceSecondaryHomeOnDisplay(int displayId) { |
| 542 | if (displayId == DEFAULT_DISPLAY) { |
| 543 | throw new IllegalArgumentException( |
| 544 | "shouldPlaceSecondaryHomeOnDisplay: Should not be DEFAULT_DISPLAY"); |
| 545 | } else if (displayId == INVALID_DISPLAY) { |
| 546 | return false; |
| 547 | } |
| 548 | |
| 549 | if (!mService.mSupportsMultiDisplay) { |
| 550 | // Can't launch home on secondary display if device does not support multi-display. |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | final boolean deviceProvisioned = Settings.Global.getInt( |
| 555 | mService.mContext.getContentResolver(), |
| 556 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 557 | if (!deviceProvisioned) { |
| 558 | // Can't launch home on secondary display before device is provisioned. |
| 559 | return false; |
| 560 | } |
| 561 | |
| 562 | if (!StorageManager.isUserKeyUnlocked(mCurrentUser)) { |
| 563 | // Can't launch home on secondary displays if device is still locked. |
| 564 | return false; |
| 565 | } |
| 566 | |
| 567 | final ActivityDisplay display = getActivityDisplay(displayId); |
| 568 | if (display == null || display.isRemoved() || !display.supportsSystemDecorations()) { |
| 569 | // Can't launch home on display that doesn't support system decorations. |
| 570 | return false; |
| 571 | } |
| 572 | |
| 573 | return true; |
| 574 | } |
| 575 | |
| 576 | /** |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 577 | * Check if home activity start should be allowed on a display. |
| 578 | * @param homeInfo {@code ActivityInfo} of the home activity that is going to be launched. |
| 579 | * @param displayId The id of the target display. |
| 580 | * @param allowInstrumenting Whether launching home should be allowed if being instrumented. |
| 581 | * @return {@code true} if allow to launch, {@code false} otherwise. |
| 582 | */ |
| 583 | boolean canStartHomeOnDisplay(ActivityInfo homeInfo, int displayId, |
| 584 | boolean allowInstrumenting) { |
| 585 | if (mService.mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL |
| 586 | && mService.mTopAction == null) { |
| 587 | // We are running in factory test mode, but unable to find the factory test app, so |
| 588 | // just sit around displaying the error message and don't try to start anything. |
| 589 | return false; |
| 590 | } |
| 591 | |
| 592 | final WindowProcessController app = |
| 593 | mService.getProcessController(homeInfo.processName, homeInfo.applicationInfo.uid); |
| 594 | if (!allowInstrumenting && app != null && app.isInstrumenting()) { |
| 595 | // Don't do this if the home app is currently being instrumented. |
| 596 | return false; |
| 597 | } |
| 598 | |
| 599 | if (displayId == DEFAULT_DISPLAY || (displayId != INVALID_DISPLAY |
| 600 | && displayId == mService.mVr2dDisplayId)) { |
| 601 | // No restrictions to default display or vr 2d display. |
| 602 | return true; |
| 603 | } |
| 604 | |
Chilun | 85ebc0d | 2019-04-15 16:00:53 +0800 | [diff] [blame] | 605 | if (!shouldPlaceSecondaryHomeOnDisplay(displayId)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 606 | return false; |
| 607 | } |
| 608 | |
| 609 | final boolean supportMultipleInstance = homeInfo.launchMode != LAUNCH_SINGLE_TASK |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 610 | && homeInfo.launchMode != LAUNCH_SINGLE_INSTANCE; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 611 | if (!supportMultipleInstance) { |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 612 | // Can't launch home on secondary displays if it requested to be single instance. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 613 | return false; |
| 614 | } |
| 615 | |
| 616 | return true; |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Ensure all activities visibility, update orientation and configuration. |
| 621 | * |
| 622 | * @param starting The currently starting activity or {@code null} if there is none. |
| 623 | * @param displayId The id of the display where operation is executed. |
| 624 | * @param markFrozenIfConfigChanged Whether to set {@link ActivityRecord#frozenBeforeDestroy} to |
| 625 | * {@code true} if config changed. |
| 626 | * @param deferResume Whether to defer resume while updating config. |
| 627 | * @return 'true' if starting activity was kept or wasn't provided, 'false' if it was relaunched |
| 628 | * because of configuration update. |
| 629 | */ |
| 630 | boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId, |
| 631 | boolean markFrozenIfConfigChanged, boolean deferResume) { |
| 632 | // First ensure visibility without updating the config just yet. We need this to know what |
| 633 | // activities are affecting configuration now. |
| 634 | // Passing null here for 'starting' param value, so that visibility of actual starting |
| 635 | // activity will be properly updated. |
| 636 | ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, |
| 637 | false /* preserveWindows */, false /* notifyClients */); |
| 638 | |
| 639 | if (displayId == INVALID_DISPLAY) { |
| 640 | // The caller didn't provide a valid display id, skip updating config. |
| 641 | return true; |
| 642 | } |
| 643 | |
| 644 | // Force-update the orientation from the WindowManager, since we need the true configuration |
| 645 | // to send to the client now. |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 646 | final DisplayContent displayContent = mRootWindowContainer.getDisplayContent(displayId); |
| 647 | Configuration config = null; |
| 648 | if (displayContent != null) { |
| 649 | config = displayContent.updateOrientationFromAppTokens( |
| 650 | getDisplayOverrideConfiguration(displayId), |
| 651 | starting != null && starting.mayFreezeScreenLocked(starting.app) |
| 652 | ? starting.appToken : null, |
| 653 | true /* forceUpdate */); |
| 654 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 655 | if (starting != null && markFrozenIfConfigChanged && config != null) { |
| 656 | starting.frozenBeforeDestroy = true; |
| 657 | } |
| 658 | |
| 659 | // Update the configuration of the activities on the display. |
| 660 | return mService.updateDisplayOverrideConfigurationLocked(config, starting, deferResume, |
| 661 | displayId); |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * @return a list of activities which are the top ones in each visible stack. The first |
| 666 | * entry will be the focused activity. |
| 667 | */ |
| 668 | List<IBinder> getTopVisibleActivities() { |
| 669 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
| 670 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 671 | // Traverse all displays. |
| 672 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
| 673 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 674 | // Traverse all stacks on a display. |
| 675 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 676 | final ActivityStack stack = display.getChildAt(j); |
| 677 | // Get top activity from a visible stack and add it to the list. |
| 678 | if (stack.shouldBeVisible(null /* starting */)) { |
| 679 | final ActivityRecord top = stack.getTopActivity(); |
| 680 | if (top != null) { |
| 681 | if (stack == topFocusedStack) { |
| 682 | topActivityTokens.add(0, top.appToken); |
| 683 | } else { |
| 684 | topActivityTokens.add(top.appToken); |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | return topActivityTokens; |
| 691 | } |
| 692 | |
| 693 | ActivityStack getTopDisplayFocusedStack() { |
| 694 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 695 | final ActivityStack focusedStack = mActivityDisplays.get(i).getFocusedStack(); |
| 696 | if (focusedStack != null) { |
| 697 | return focusedStack; |
| 698 | } |
| 699 | } |
| 700 | return null; |
| 701 | } |
| 702 | |
| 703 | ActivityRecord getTopResumedActivity() { |
| 704 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
| 705 | if (focusedStack == null) { |
| 706 | return null; |
| 707 | } |
| 708 | final ActivityRecord resumedActivity = focusedStack.getResumedActivity(); |
| 709 | if (resumedActivity != null && resumedActivity.app != null) { |
| 710 | return resumedActivity; |
| 711 | } |
| 712 | // The top focused stack might not have a resumed activity yet - look on all displays in |
| 713 | // focus order. |
| 714 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 715 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 716 | final ActivityRecord resumedActivityOnDisplay = display.getResumedActivity(); |
| 717 | if (resumedActivityOnDisplay != null) { |
| 718 | return resumedActivityOnDisplay; |
| 719 | } |
| 720 | } |
| 721 | return null; |
| 722 | } |
| 723 | |
| 724 | boolean isFocusable(ConfigurationContainer container, boolean alwaysFocusable) { |
| 725 | if (container.inSplitScreenPrimaryWindowingMode() && mIsDockMinimized) { |
| 726 | return false; |
| 727 | } |
| 728 | |
| 729 | return container.getWindowConfiguration().canReceiveKeys() || alwaysFocusable; |
| 730 | } |
| 731 | |
| 732 | boolean isTopDisplayFocusedStack(ActivityStack stack) { |
| 733 | return stack != null && stack == getTopDisplayFocusedStack(); |
| 734 | } |
| 735 | |
| 736 | void updatePreviousProcess(ActivityRecord r) { |
| 737 | // Now that this process has stopped, we may want to consider it to be the previous app to |
| 738 | // try to keep around in case the user wants to return to it. |
| 739 | |
| 740 | // First, found out what is currently the foreground app, so that we don't blow away the |
| 741 | // previous app if this activity is being hosted by the process that is actually still the |
| 742 | // foreground. |
| 743 | WindowProcessController fgApp = null; |
| 744 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 745 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 746 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 747 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 748 | if (isTopDisplayFocusedStack(stack)) { |
| 749 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 750 | if (resumedActivity != null) { |
| 751 | fgApp = resumedActivity.app; |
| 752 | } else if (stack.mPausingActivity != null) { |
| 753 | fgApp = stack.mPausingActivity.app; |
| 754 | } |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | // Now set this one as the previous process, only if that really makes sense to. |
| 761 | if (r.hasProcess() && fgApp != null && r.app != fgApp |
| 762 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
| 763 | && r.app != mService.mHomeProcess) { |
| 764 | mService.mPreviousProcess = r.app; |
| 765 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | boolean attachApplication(WindowProcessController app) throws RemoteException { |
| 770 | final String processName = app.mName; |
| 771 | boolean didSomething = false; |
| 772 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 773 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 774 | final ActivityStack stack = display.getFocusedStack(); |
| 775 | if (stack != null) { |
| 776 | stack.getAllRunningVisibleActivitiesLocked(mTmpActivityList); |
| 777 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 778 | final int size = mTmpActivityList.size(); |
| 779 | for (int i = 0; i < size; i++) { |
| 780 | final ActivityRecord activity = mTmpActivityList.get(i); |
| 781 | if (activity.app == null && app.mUid == activity.info.applicationInfo.uid |
| 782 | && processName.equals(activity.processName)) { |
| 783 | try { |
| 784 | if (mStackSupervisor.realStartActivityLocked(activity, app, |
| 785 | top == activity /* andResume */, true /* checkConfig */)) { |
| 786 | didSomething = true; |
| 787 | } |
| 788 | } catch (RemoteException e) { |
| 789 | Slog.w(TAG, "Exception in new application when starting activity " |
| 790 | + top.intent.getComponent().flattenToShortString(), e); |
| 791 | throw e; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | if (!didSomething) { |
| 798 | ensureActivitiesVisible(null, 0, false /* preserve_windows */); |
| 799 | } |
| 800 | return didSomething; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Make sure that all activities that need to be visible in the system actually are and update |
| 805 | * their configuration. |
| 806 | */ |
| 807 | void ensureActivitiesVisible(ActivityRecord starting, int configChanges, |
| 808 | boolean preserveWindows) { |
| 809 | ensureActivitiesVisible(starting, configChanges, preserveWindows, true /* notifyClients */); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * @see #ensureActivitiesVisible(ActivityRecord, int, boolean) |
| 814 | */ |
| 815 | void ensureActivitiesVisible(ActivityRecord starting, int configChanges, |
| 816 | boolean preserveWindows, boolean notifyClients) { |
| 817 | mStackSupervisor.getKeyguardController().beginActivityVisibilityUpdate(); |
| 818 | try { |
| 819 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 820 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 821 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Louis Chang | 77ce34d | 2019-01-03 15:45:12 +0800 | [diff] [blame] | 822 | display.ensureActivitiesVisible(starting, configChanges, preserveWindows, |
| 823 | notifyClients); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 824 | } |
| 825 | } finally { |
| 826 | mStackSupervisor.getKeyguardController().endActivityVisibilityUpdate(); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | boolean switchUser(int userId, UserState uss) { |
| 831 | final int focusStackId = getTopDisplayFocusedStack().getStackId(); |
| 832 | // We dismiss the docked stack whenever we switch users. |
| 833 | final ActivityStack dockedStack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
| 834 | if (dockedStack != null) { |
| 835 | mStackSupervisor.moveTasksToFullscreenStackLocked( |
| 836 | dockedStack, dockedStack.isFocusedStackOnDisplay()); |
| 837 | } |
| 838 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 839 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 840 | // appropriate. |
| 841 | removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
| 842 | |
| 843 | mUserStackInFront.put(mCurrentUser, focusStackId); |
| 844 | final int restoreStackId = |
| 845 | mUserStackInFront.get(userId, getDefaultDisplay().getHomeStack().mStackId); |
| 846 | mCurrentUser = userId; |
| 847 | |
| 848 | mStackSupervisor.mStartingUsers.add(uss); |
| 849 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 850 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 851 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 852 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 853 | stack.switchUserLocked(userId); |
| 854 | TaskRecord task = stack.topTask(); |
| 855 | if (task != null) { |
| 856 | stack.positionChildWindowContainerAtTop(task); |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | ActivityStack stack = getStack(restoreStackId); |
| 862 | if (stack == null) { |
| 863 | stack = getDefaultDisplay().getHomeStack(); |
| 864 | } |
| 865 | final boolean homeInFront = stack.isActivityTypeHome(); |
| 866 | if (stack.isOnHomeDisplay()) { |
| 867 | stack.moveToFront("switchUserOnHomeDisplay"); |
| 868 | } else { |
| 869 | // Stack was moved to another display while user was swapped out. |
| 870 | resumeHomeActivity(null, "switchUserOnOtherDisplay", DEFAULT_DISPLAY); |
| 871 | } |
| 872 | return homeInFront; |
| 873 | } |
| 874 | |
| 875 | void removeUser(int userId) { |
| 876 | mUserStackInFront.delete(userId); |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Update the last used stack id for non-current user (current user's last |
| 881 | * used stack is the focused stack) |
| 882 | */ |
| 883 | void updateUserStack(int userId, ActivityStack stack) { |
| 884 | if (userId != mCurrentUser) { |
| 885 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() |
| 886 | : getDefaultDisplay().getHomeStack().mStackId); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | void resizeStack(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 891 | Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, |
| 892 | boolean deferResume) { |
| 893 | |
| 894 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
| 895 | mStackSupervisor.resizeDockedStackLocked(bounds, tempTaskBounds, |
| 896 | tempTaskInsetBounds, null, null, preserveWindows, deferResume); |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | final boolean splitScreenActive = getDefaultDisplay().hasSplitScreenPrimaryStack(); |
| 901 | if (!allowResizeInDockedMode |
| 902 | && !stack.getWindowConfiguration().tasksAreFloating() && splitScreenActive) { |
| 903 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 904 | // size computed from the docked stack size (otherwise they will be out of sync) |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stack.mStackId); |
| 909 | mWindowManager.deferSurfaceLayout(); |
| 910 | try { |
| 911 | if (stack.affectedBySplitScreenResize()) { |
| 912 | if (bounds == null && stack.inSplitScreenWindowingMode()) { |
| 913 | // null bounds = fullscreen windowing mode...at least for now. |
| 914 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 915 | } else if (splitScreenActive) { |
| 916 | // If we are in split-screen mode and this stack support split-screen, then |
| 917 | // it should be split-screen secondary mode. i.e. adjacent to the docked stack. |
| 918 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 919 | } |
| 920 | } |
| 921 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
| 922 | if (!deferResume) { |
| 923 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 924 | stack.topRunningActivityLocked(), preserveWindows); |
| 925 | } |
| 926 | } finally { |
| 927 | mWindowManager.continueSurfaceLayout(); |
| 928 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Move stack with all its existing content to specified display. |
| 934 | * @param stackId Id of stack to move. |
| 935 | * @param displayId Id of display to move stack to. |
| 936 | * @param onTop Indicates whether container should be place on top or on bottom. |
| 937 | */ |
| 938 | void moveStackToDisplay(int stackId, int displayId, boolean onTop) { |
| 939 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreate(displayId); |
| 940 | if (activityDisplay == null) { |
| 941 | throw new IllegalArgumentException("moveStackToDisplay: Unknown displayId=" |
| 942 | + displayId); |
| 943 | } |
| 944 | final ActivityStack stack = getStack(stackId); |
| 945 | if (stack == null) { |
| 946 | throw new IllegalArgumentException("moveStackToDisplay: Unknown stackId=" |
| 947 | + stackId); |
| 948 | } |
| 949 | |
| 950 | final ActivityDisplay currentDisplay = stack.getDisplay(); |
| 951 | if (currentDisplay == null) { |
| 952 | throw new IllegalStateException("moveStackToDisplay: Stack with stack=" + stack |
| 953 | + " is not attached to any display."); |
| 954 | } |
| 955 | |
| 956 | if (currentDisplay.mDisplayId == displayId) { |
| 957 | throw new IllegalArgumentException("Trying to move stack=" + stack |
| 958 | + " to its current displayId=" + displayId); |
| 959 | } |
| 960 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 961 | if (activityDisplay.isSingleTaskInstance() && activityDisplay.getChildCount() > 0) { |
| 962 | // We don't allow moving stacks to single instance display that already has a child. |
| 963 | Slog.e(TAG, "Can not move stack=" + stack |
| 964 | + " to single task instance display=" + activityDisplay); |
| 965 | return; |
| 966 | } |
| 967 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 968 | stack.reparent(activityDisplay, onTop, false /* displayRemoved */); |
| 969 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 970 | } |
| 971 | |
| 972 | boolean moveTopStackActivityToPinnedStack(int stackId) { |
| 973 | final ActivityStack stack = getStack(stackId); |
| 974 | if (stack == null) { |
| 975 | throw new IllegalArgumentException( |
| 976 | "moveTopStackActivityToPinnedStack: Unknown stackId=" + stackId); |
| 977 | } |
| 978 | |
| 979 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 980 | if (r == null) { |
| 981 | Slog.w(TAG, "moveTopStackActivityToPinnedStack: No top running activity" |
| 982 | + " in stack=" + stack); |
| 983 | return false; |
| 984 | } |
| 985 | |
| 986 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
| 987 | Slog.w(TAG, "moveTopStackActivityToPinnedStack: Picture-In-Picture not supported for " |
| 988 | + " r=" + r); |
| 989 | return false; |
| 990 | } |
| 991 | |
| 992 | moveActivityToPinnedStack(r, null /* sourceBounds */, 0f /* aspectRatio */, |
| 993 | "moveTopActivityToPinnedStack"); |
| 994 | return true; |
| 995 | } |
| 996 | |
| 997 | void moveActivityToPinnedStack(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
| 998 | String reason) { |
| 999 | |
| 1000 | mWindowManager.deferSurfaceLayout(); |
| 1001 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1002 | final ActivityDisplay display = r.getActivityStack().getDisplay(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1003 | ActivityStack stack = display.getPinnedStack(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1004 | |
| 1005 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 1006 | // ensuring only one task is present. |
| 1007 | if (stack != null) { |
| 1008 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
| 1009 | } |
| 1010 | |
| 1011 | // Need to make sure the pinned stack exist so we can resize it below... |
| 1012 | stack = display.getOrCreateStack(WINDOWING_MODE_PINNED, r.getActivityType(), ON_TOP); |
| 1013 | |
| 1014 | // Calculate the target bounds here before the task is reparented back into pinned windowing |
| 1015 | // mode (which will reset the saved bounds) |
| 1016 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 1017 | |
| 1018 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1019 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1020 | // Resize the pinned stack to match the current size of the task the activity we are |
| 1021 | // going to be moving is currently contained in. We do this to have the right starting |
| 1022 | // animation bounds for the pinned stack to the desired bounds the caller wants. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1023 | resizeStack(stack, task.getRequestedOverrideBounds(), null /* tempTaskBounds */, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1024 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 1025 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
| 1026 | |
| 1027 | if (task.mActivities.size() == 1) { |
| 1028 | // Defer resume until below, and do not schedule PiP changes until we animate below |
| 1029 | task.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, DEFER_RESUME, |
| 1030 | false /* schedulePictureInPictureModeChange */, reason); |
| 1031 | } else { |
| 1032 | // There are multiple activities in the task and moving the top activity should |
| 1033 | // reveal/leave the other activities in their original task. |
| 1034 | |
| 1035 | // Currently, we don't support reparenting activities across tasks in two different |
| 1036 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 1037 | // activity into that task, and then reparent the whole task to the new stack. This |
| 1038 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 1039 | // is also done. |
| 1040 | final TaskRecord newTask = task.getStack().createTaskRecord( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1041 | mStackSupervisor.getNextTaskIdForUserLocked(r.mUserId), r.info, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1042 | r.intent, null, null, true); |
| 1043 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 1044 | |
| 1045 | // Defer resume until below, and do not schedule PiP changes until we animate below |
| 1046 | newTask.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
| 1047 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
| 1048 | } |
| 1049 | |
| 1050 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 1051 | // to the pinned stack |
| 1052 | r.supportsEnterPipOnTaskSwitch = false; |
| 1053 | } finally { |
| 1054 | mWindowManager.continueSurfaceLayout(); |
| 1055 | } |
| 1056 | |
| 1057 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 1058 | true /* fromFullscreen */); |
| 1059 | |
| 1060 | // Update the visibility of all activities after the they have been reparented to the new |
| 1061 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 1062 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 1063 | // thread. |
| 1064 | ensureActivitiesVisible(null, 0, false /* preserveWindows */); |
| 1065 | resumeFocusedStacksTopActivities(); |
| 1066 | |
| 1067 | mService.getTaskChangeNotificationController().notifyActivityPinned(r); |
| 1068 | } |
| 1069 | |
| 1070 | void executeAppTransitionForAllDisplay() { |
| 1071 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1072 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1073 | display.mDisplayContent.executeAppTransition(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | void setDockedStackMinimized(boolean minimized) { |
| 1078 | // Get currently focused stack before setting mIsDockMinimized. We do this because if |
| 1079 | // split-screen is active, primary stack will not be focusable (see #isFocusable) while |
| 1080 | // still occluding other stacks. This will cause getTopDisplayFocusedStack() to return null. |
| 1081 | final ActivityStack current = getTopDisplayFocusedStack(); |
| 1082 | mIsDockMinimized = minimized; |
| 1083 | if (mIsDockMinimized) { |
| 1084 | if (current.inSplitScreenPrimaryWindowingMode()) { |
| 1085 | // The primary split-screen stack can't be focused while it is minimize, so move |
| 1086 | // focus to something else. |
| 1087 | current.adjustFocusToNextFocusableStack("setDockedStackMinimized"); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | ActivityRecord findTask(ActivityRecord r, int preferredDisplayId) { |
| 1093 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
| 1094 | mTmpFindTaskResult.clear(); |
| 1095 | |
| 1096 | // Looking up task on preferred display first |
| 1097 | final ActivityDisplay preferredDisplay = getActivityDisplay(preferredDisplayId); |
| 1098 | if (preferredDisplay != null) { |
| 1099 | preferredDisplay.findTaskLocked(r, true /* isPreferredDisplay */, mTmpFindTaskResult); |
| 1100 | if (mTmpFindTaskResult.mIdealMatch) { |
| 1101 | return mTmpFindTaskResult.mRecord; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1106 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1107 | if (display.mDisplayId == preferredDisplayId) { |
| 1108 | continue; |
| 1109 | } |
| 1110 | |
| 1111 | display.findTaskLocked(r, false /* isPreferredDisplay */, mTmpFindTaskResult); |
| 1112 | if (mTmpFindTaskResult.mIdealMatch) { |
| 1113 | return mTmpFindTaskResult.mRecord; |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | if (DEBUG_TASKS && mTmpFindTaskResult.mRecord == null) Slog.d(TAG_TASKS, "No task found"); |
| 1118 | return mTmpFindTaskResult.mRecord; |
| 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * Finish the topmost activities in all stacks that belong to the crashed app. |
| 1123 | * @param app The app that crashed. |
| 1124 | * @param reason Reason to perform this action. |
| 1125 | * @return The task id that was finished in this stack, or INVALID_TASK_ID if none was finished. |
| 1126 | */ |
| 1127 | int finishTopCrashedActivities(WindowProcessController app, String reason) { |
| 1128 | TaskRecord finishedTask = null; |
| 1129 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
| 1130 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1131 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1132 | // It is possible that request to finish activity might also remove its task and stack, |
| 1133 | // so we need to be careful with indexes in the loop and check child count every time. |
| 1134 | for (int stackNdx = 0; stackNdx < display.getChildCount(); ++stackNdx) { |
| 1135 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1136 | final TaskRecord t = stack.finishTopCrashedActivityLocked(app, reason); |
| 1137 | if (stack == focusedStack || finishedTask == null) { |
| 1138 | finishedTask = t; |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | return finishedTask != null ? finishedTask.taskId : INVALID_TASK_ID; |
| 1143 | } |
| 1144 | |
| 1145 | boolean resumeFocusedStacksTopActivities() { |
| 1146 | return resumeFocusedStacksTopActivities(null, null, null); |
| 1147 | } |
| 1148 | |
| 1149 | boolean resumeFocusedStacksTopActivities( |
| 1150 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
| 1151 | |
| 1152 | if (!mStackSupervisor.readyToResume()) { |
| 1153 | return false; |
| 1154 | } |
| 1155 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1156 | boolean result = false; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1157 | if (targetStack != null && (targetStack.isTopStackOnDisplay() |
| 1158 | || getTopDisplayFocusedStack() == targetStack)) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1159 | result = targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1160 | } |
| 1161 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1162 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1163 | boolean resumedOnDisplay = false; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1164 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1165 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1166 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1167 | final ActivityRecord topRunningActivity = stack.topRunningActivityLocked(); |
| 1168 | if (!stack.isFocusableAndVisible() || topRunningActivity == null) { |
| 1169 | continue; |
| 1170 | } |
Louis Chang | c50a936 | 2019-02-12 12:35:24 +0800 | [diff] [blame] | 1171 | if (stack == targetStack) { |
| 1172 | // Simply update the result for targetStack because the targetStack had |
| 1173 | // already resumed in above. We don't want to resume it again, especially in |
| 1174 | // some cases, it would cause a second launch failure if app process was dead. |
| 1175 | resumedOnDisplay |= result; |
| 1176 | continue; |
| 1177 | } |
Jorim Jaggi | a5cf680 | 2019-04-26 19:43:11 +0200 | [diff] [blame] | 1178 | if (display.isTopStack(stack) && topRunningActivity.isState(RESUMED)) { |
| 1179 | // Kick off any lingering app transitions form the MoveTaskToFront operation, |
| 1180 | // but only consider the top task and stack on that display. |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1181 | stack.executeAppTransition(targetOptions); |
| 1182 | } else { |
| 1183 | resumedOnDisplay |= topRunningActivity.makeActiveIfNeeded(target); |
| 1184 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1185 | } |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1186 | if (!resumedOnDisplay) { |
| 1187 | // In cases when there are no valid activities (e.g. device just booted or launcher |
| 1188 | // crashed) it's possible that nothing was resumed on a display. Requesting resume |
| 1189 | // of top activity in focused stack explicitly will make sure that at least home |
| 1190 | // activity is started and resumed, and no recursion occurs. |
| 1191 | final ActivityStack focusedStack = display.getFocusedStack(); |
| 1192 | if (focusedStack != null) { |
| 1193 | focusedStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
| 1194 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1198 | return result; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | void applySleepTokens(boolean applyToStacks) { |
| 1202 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1203 | // Set the sleeping state of the display. |
| 1204 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1205 | final boolean displayShouldSleep = display.shouldSleep(); |
| 1206 | if (displayShouldSleep == display.isSleeping()) { |
| 1207 | continue; |
| 1208 | } |
| 1209 | display.setIsSleeping(displayShouldSleep); |
| 1210 | |
| 1211 | if (!applyToStacks) { |
| 1212 | continue; |
| 1213 | } |
| 1214 | |
| 1215 | // Set the sleeping state of the stacks on the display. |
| 1216 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1217 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1218 | if (displayShouldSleep) { |
| 1219 | stack.goToSleepIfPossible(false /* shuttingDown */); |
| 1220 | } else { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame^] | 1221 | // When the display which can only contain one task turns on, start a special |
| 1222 | // transition. {@link AppTransitionController#handleAppTransitionReady} later |
| 1223 | // picks up the transition, and schedules |
| 1224 | // {@link ITaskStackListener#onSingleTaskDisplayDrawn} callback which is |
| 1225 | // triggered after contents are drawn on the display. |
| 1226 | if (display.isSingleTaskInstance()) { |
| 1227 | display.mDisplayContent.prepareAppTransition( |
| 1228 | TRANSIT_SHOW_SINGLE_TASK_DISPLAY, false); |
| 1229 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1230 | stack.awakeFromSleepingLocked(); |
| 1231 | if (stack.isFocusedStackOnDisplay() |
| 1232 | && !mStackSupervisor.getKeyguardController() |
| 1233 | .isKeyguardOrAodShowing(display.mDisplayId)) { |
| 1234 | // If the keyguard is unlocked - resume immediately. |
| 1235 | // It is possible that the display will not be awake at the time we |
| 1236 | // process the keyguard going away, which can happen before the sleep token |
| 1237 | // is released. As a result, it is important we resume the activity here. |
| 1238 | resumeFocusedStacksTopActivities(); |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | if (displayShouldSleep || mStackSupervisor.mGoingToSleepActivities.isEmpty()) { |
| 1244 | continue; |
| 1245 | } |
| 1246 | // The display is awake now, so clean up the going to sleep list. |
| 1247 | for (Iterator<ActivityRecord> it = |
| 1248 | mStackSupervisor.mGoingToSleepActivities.iterator(); it.hasNext(); ) { |
| 1249 | final ActivityRecord r = it.next(); |
| 1250 | if (r.getDisplayId() == display.mDisplayId) { |
| 1251 | it.remove(); |
| 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | protected <T extends ActivityStack> T getStack(int stackId) { |
| 1258 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 1259 | final T stack = mActivityDisplays.get(i).getStack(stackId); |
| 1260 | if (stack != null) { |
| 1261 | return stack; |
| 1262 | } |
| 1263 | } |
| 1264 | return null; |
| 1265 | } |
| 1266 | |
| 1267 | /** @see ActivityDisplay#getStack(int, int) */ |
| 1268 | private <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
| 1269 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 1270 | final T stack = mActivityDisplays.get(i).getStack(windowingMode, activityType); |
| 1271 | if (stack != null) { |
| 1272 | return stack; |
| 1273 | } |
| 1274 | } |
| 1275 | return null; |
| 1276 | } |
| 1277 | |
| 1278 | private ActivityManager.StackInfo getStackInfo(ActivityStack stack) { |
| 1279 | final int displayId = stack.mDisplayId; |
| 1280 | final ActivityDisplay display = getActivityDisplay(displayId); |
| 1281 | ActivityManager.StackInfo info = new ActivityManager.StackInfo(); |
| 1282 | stack.getWindowContainerBounds(info.bounds); |
| 1283 | info.displayId = displayId; |
| 1284 | info.stackId = stack.mStackId; |
| 1285 | info.userId = stack.mCurrentUser; |
| 1286 | info.visible = stack.shouldBeVisible(null); |
| 1287 | // A stack might be not attached to a display. |
| 1288 | info.position = display != null ? display.getIndexOf(stack) : 0; |
| 1289 | info.configuration.setTo(stack.getConfiguration()); |
| 1290 | |
| 1291 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1292 | final int numTasks = tasks.size(); |
| 1293 | int[] taskIds = new int[numTasks]; |
| 1294 | String[] taskNames = new String[numTasks]; |
| 1295 | Rect[] taskBounds = new Rect[numTasks]; |
| 1296 | int[] taskUserIds = new int[numTasks]; |
| 1297 | for (int i = 0; i < numTasks; ++i) { |
| 1298 | final TaskRecord task = tasks.get(i); |
| 1299 | taskIds[i] = task.taskId; |
| 1300 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 1301 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 1302 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 1303 | : "unknown"; |
| 1304 | taskBounds[i] = new Rect(); |
| 1305 | task.getWindowContainerBounds(taskBounds[i]); |
| 1306 | taskUserIds[i] = task.userId; |
| 1307 | } |
| 1308 | info.taskIds = taskIds; |
| 1309 | info.taskNames = taskNames; |
| 1310 | info.taskBounds = taskBounds; |
| 1311 | info.taskUserIds = taskUserIds; |
| 1312 | |
| 1313 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 1314 | info.topActivity = top != null ? top.intent.getComponent() : null; |
| 1315 | return info; |
| 1316 | } |
| 1317 | |
| 1318 | ActivityManager.StackInfo getStackInfo(int stackId) { |
| 1319 | ActivityStack stack = getStack(stackId); |
| 1320 | if (stack != null) { |
| 1321 | return getStackInfo(stack); |
| 1322 | } |
| 1323 | return null; |
| 1324 | } |
| 1325 | |
| 1326 | ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
| 1327 | final ActivityStack stack = getStack(windowingMode, activityType); |
| 1328 | return (stack != null) ? getStackInfo(stack) : null; |
| 1329 | } |
| 1330 | |
| 1331 | ArrayList<ActivityManager.StackInfo> getAllStackInfos() { |
| 1332 | ArrayList<ActivityManager.StackInfo> list = new ArrayList<>(); |
| 1333 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 1334 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1335 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1336 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1337 | list.add(getStackInfo(stack)); |
| 1338 | } |
| 1339 | } |
| 1340 | return list; |
| 1341 | } |
| 1342 | |
| 1343 | void deferUpdateBounds(int activityType) { |
| 1344 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
| 1345 | if (stack != null) { |
| 1346 | stack.deferUpdateBounds(); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | void continueUpdateBounds(int activityType) { |
| 1351 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
| 1352 | if (stack != null) { |
| 1353 | stack.continueUpdateBounds(); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | @Override |
| 1358 | public void onDisplayAdded(int displayId) { |
| 1359 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
| 1360 | synchronized (mService.mGlobalLock) { |
Charles Chen | 3dedec3 | 2019-01-24 22:19:37 +0800 | [diff] [blame] | 1361 | final ActivityDisplay display = getActivityDisplayOrCreate(displayId); |
Charles Chen | b409e6c | 2019-02-12 12:30:17 +0800 | [diff] [blame] | 1362 | if (display == null) { |
| 1363 | return; |
| 1364 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1365 | // Do not start home before booting, or it may accidentally finish booting before it |
| 1366 | // starts. Instead, we expect home activities to be launched when the system is ready |
| 1367 | // (ActivityManagerService#systemReady). |
| 1368 | if (mService.isBooted() || mService.isBooting()) { |
Charles Chen | 3dedec3 | 2019-01-24 22:19:37 +0800 | [diff] [blame] | 1369 | startSystemDecorations(display.mDisplayContent); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
Charles Chen | 3dedec3 | 2019-01-24 22:19:37 +0800 | [diff] [blame] | 1374 | private void startSystemDecorations(final DisplayContent displayContent) { |
| 1375 | startHomeOnDisplay(mCurrentUser, "displayAdded", displayContent.getDisplayId()); |
| 1376 | displayContent.getDisplayPolicy().notifyDisplayReady(); |
| 1377 | } |
| 1378 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1379 | @Override |
| 1380 | public void onDisplayRemoved(int displayId) { |
| 1381 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
| 1382 | if (displayId == DEFAULT_DISPLAY) { |
| 1383 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 1384 | } |
| 1385 | |
| 1386 | synchronized (mService.mGlobalLock) { |
| 1387 | final ActivityDisplay activityDisplay = getActivityDisplay(displayId); |
| 1388 | if (activityDisplay == null) { |
| 1389 | return; |
| 1390 | } |
| 1391 | |
| 1392 | activityDisplay.remove(); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | @Override |
| 1397 | public void onDisplayChanged(int displayId) { |
| 1398 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
| 1399 | synchronized (mService.mGlobalLock) { |
| 1400 | final ActivityDisplay activityDisplay = getActivityDisplay(displayId); |
| 1401 | if (activityDisplay != null) { |
| 1402 | activityDisplay.onDisplayChanged(); |
| 1403 | } |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1408 | void updateUIDsPresentOnDisplay() { |
| 1409 | mDisplayAccessUIDs.clear(); |
| 1410 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1411 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
| 1412 | // Only bother calculating the whitelist for private displays |
| 1413 | if (activityDisplay.isPrivate()) { |
| 1414 | mDisplayAccessUIDs.append( |
| 1415 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1416 | } |
| 1417 | } |
| 1418 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1419 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1420 | } |
| 1421 | |
| 1422 | ActivityStack findStackBehind(ActivityStack stack) { |
| 1423 | final ActivityDisplay display = getActivityDisplay(stack.mDisplayId); |
| 1424 | if (display != null) { |
| 1425 | for (int i = display.getChildCount() - 1; i >= 0; i--) { |
| 1426 | if (display.getChildAt(i) == stack && i > 0) { |
| 1427 | return display.getChildAt(i - 1); |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
| 1432 | + " in=" + display); |
| 1433 | } |
| 1434 | |
| 1435 | @Override |
| 1436 | protected int getChildCount() { |
| 1437 | return mActivityDisplays.size(); |
| 1438 | } |
| 1439 | |
| 1440 | @Override |
| 1441 | protected ActivityDisplay getChildAt(int index) { |
| 1442 | return mActivityDisplays.get(index); |
| 1443 | } |
| 1444 | |
| 1445 | @Override |
| 1446 | protected ConfigurationContainer getParent() { |
| 1447 | return null; |
| 1448 | } |
| 1449 | |
Wale Ogunwale | 31acb3f | 2018-11-20 15:23:55 -0800 | [diff] [blame] | 1450 | // TODO: remove after object merge with RootWindowContainer |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1451 | void onChildPositionChanged(ActivityDisplay display, int position) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1452 | // Assume AM lock is held from positionChildAt of controller in each hierarchy. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1453 | if (display != null) { |
| 1454 | positionChildAt(display, position); |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | /** Change the z-order of the given display. */ |
| 1459 | private void positionChildAt(ActivityDisplay display, int position) { |
| 1460 | if (position >= mActivityDisplays.size()) { |
| 1461 | position = mActivityDisplays.size() - 1; |
| 1462 | } else if (position < 0) { |
| 1463 | position = 0; |
| 1464 | } |
| 1465 | |
| 1466 | if (mActivityDisplays.isEmpty()) { |
| 1467 | mActivityDisplays.add(display); |
| 1468 | } else if (mActivityDisplays.get(position) != display) { |
| 1469 | mActivityDisplays.remove(display); |
| 1470 | mActivityDisplays.add(position, display); |
| 1471 | } |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1472 | mStackSupervisor.updateTopResumedActivityIfNeeded(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | @VisibleForTesting |
| 1476 | void addChild(ActivityDisplay activityDisplay, int position) { |
| 1477 | positionChildAt(activityDisplay, position); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1478 | mRootWindowContainer.positionChildAt(position, activityDisplay.mDisplayContent); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | void removeChild(ActivityDisplay activityDisplay) { |
| 1482 | // The caller must tell the controller of {@link ActivityDisplay} to release its container |
| 1483 | // {@link DisplayContent}. That is done in {@link ActivityDisplay#releaseSelfIfNeeded}). |
| 1484 | mActivityDisplays.remove(activityDisplay); |
| 1485 | } |
| 1486 | |
| 1487 | Configuration getDisplayOverrideConfiguration(int displayId) { |
| 1488 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreate(displayId); |
| 1489 | if (activityDisplay == null) { |
| 1490 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 1491 | } |
| 1492 | |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1493 | return activityDisplay.getRequestedOverrideConfiguration(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | void setDisplayOverrideConfiguration(Configuration overrideConfiguration, int displayId) { |
| 1497 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreate(displayId); |
| 1498 | if (activityDisplay == null) { |
| 1499 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 1500 | } |
| 1501 | |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1502 | activityDisplay.onRequestedOverrideConfigurationChanged(overrideConfiguration); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | void prepareForShutdown() { |
| 1506 | for (int i = 0; i < mActivityDisplays.size(); i++) { |
| 1507 | createSleepToken("shutdown", mActivityDisplays.get(i).mDisplayId); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | ActivityTaskManagerInternal.SleepToken createSleepToken(String tag, int displayId) { |
| 1512 | final ActivityDisplay display = getActivityDisplay(displayId); |
| 1513 | if (display == null) { |
| 1514 | throw new IllegalArgumentException("Invalid display: " + displayId); |
| 1515 | } |
| 1516 | |
| 1517 | final SleepTokenImpl token = new SleepTokenImpl(tag, displayId); |
| 1518 | mSleepTokens.add(token); |
| 1519 | display.mAllSleepTokens.add(token); |
| 1520 | return token; |
| 1521 | } |
| 1522 | |
| 1523 | private void removeSleepToken(SleepTokenImpl token) { |
| 1524 | mSleepTokens.remove(token); |
| 1525 | |
| 1526 | final ActivityDisplay display = getActivityDisplay(token.mDisplayId); |
| 1527 | if (display != null) { |
| 1528 | display.mAllSleepTokens.remove(token); |
| 1529 | if (display.mAllSleepTokens.isEmpty()) { |
| 1530 | mService.updateSleepIfNeededLocked(); |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 1536 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1537 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1538 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1539 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1540 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | void invalidateTaskLayers() { |
| 1546 | mTaskLayersChanged = true; |
| 1547 | } |
| 1548 | |
| 1549 | void rankTaskLayersIfNeeded() { |
| 1550 | if (!mTaskLayersChanged) { |
| 1551 | return; |
| 1552 | } |
| 1553 | mTaskLayersChanged = false; |
| 1554 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
| 1555 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1556 | int baseLayer = 0; |
| 1557 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1558 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1559 | baseLayer += stack.rankTaskLayers(baseLayer); |
| 1560 | } |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1565 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1566 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1567 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1568 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1569 | stack.clearOtherAppTimeTrackers(except); |
| 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | void scheduleDestroyAllActivities(WindowProcessController app, String reason) { |
| 1575 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1576 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1577 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1578 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1579 | stack.scheduleDestroyActivities(app, reason); |
| 1580 | } |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | void releaseSomeActivitiesLocked(WindowProcessController app, String reason) { |
| 1585 | // Tasks is non-null only if two or more tasks are found. |
| 1586 | ArraySet<TaskRecord> tasks = app.getReleaseSomeActivitiesTasks(); |
| 1587 | if (tasks == null) { |
| 1588 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Didn't find two or more tasks to release"); |
| 1589 | return; |
| 1590 | } |
| 1591 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 1592 | // let's iterate through the tasks and release the oldest one. |
| 1593 | final int numDisplays = mActivityDisplays.size(); |
| 1594 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 1595 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1596 | final int stackCount = display.getChildCount(); |
| 1597 | // Step through all stacks starting from behind, to hit the oldest things first. |
| 1598 | for (int stackNdx = 0; stackNdx < stackCount; stackNdx++) { |
| 1599 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1600 | // Try to release activities in this stack; if we manage to, we are done. |
| 1601 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 1602 | return; |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | // Tries to put all activity stacks to sleep. Returns true if all stacks were |
| 1609 | // successfully put to sleep. |
| 1610 | boolean putStacksToSleep(boolean allowDelay, boolean shuttingDown) { |
| 1611 | boolean allSleep = true; |
| 1612 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1613 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1614 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | c219bc3 | 2018-12-06 15:38:41 +0800 | [diff] [blame] | 1615 | // Stacks and activities could be removed while putting activities to sleep if |
| 1616 | // the app process was gone. This prevents us getting exception by accessing an |
| 1617 | // invalid stack index. |
| 1618 | if (stackNdx >= display.getChildCount()) { |
| 1619 | continue; |
| 1620 | } |
| 1621 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1622 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1623 | if (allowDelay) { |
| 1624 | allSleep &= stack.goToSleepIfPossible(shuttingDown); |
| 1625 | } else { |
| 1626 | stack.goToSleep(); |
| 1627 | } |
| 1628 | } |
| 1629 | } |
| 1630 | return allSleep; |
| 1631 | } |
| 1632 | |
| 1633 | void handleAppCrash(WindowProcessController app) { |
| 1634 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1635 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1636 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1637 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1638 | stack.handleAppCrash(app); |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | ActivityRecord findActivity(Intent intent, ActivityInfo info, boolean compareIntentFilters) { |
| 1644 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1645 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1646 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1647 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1648 | final ActivityRecord ar = stack.findActivityLocked( |
| 1649 | intent, info, compareIntentFilters); |
| 1650 | if (ar != null) { |
| 1651 | return ar; |
| 1652 | } |
| 1653 | } |
| 1654 | } |
| 1655 | return null; |
| 1656 | } |
| 1657 | |
| 1658 | boolean hasAwakeDisplay() { |
| 1659 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1660 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1661 | if (!display.shouldSleep()) { |
| 1662 | return true; |
| 1663 | } |
| 1664 | } |
| 1665 | return false; |
| 1666 | } |
| 1667 | |
| 1668 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 1669 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop) { |
| 1670 | return getLaunchStack(r, options, candidateTask, onTop, null /* launchParams */); |
| 1671 | } |
| 1672 | |
| 1673 | /** |
| 1674 | * Returns the right stack to use for launching factoring in all the input parameters. |
| 1675 | * |
| 1676 | * @param r The activity we are trying to launch. Can be null. |
| 1677 | * @param options The activity options used to the launch. Can be null. |
| 1678 | * @param candidateTask The possible task the activity might be launched in. Can be null. |
| 1679 | * @params launchParams The resolved launch params to use. |
| 1680 | * |
| 1681 | * @return The stack to use for the launch or INVALID_STACK_ID. |
| 1682 | */ |
| 1683 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 1684 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop, |
| 1685 | @Nullable LaunchParamsController.LaunchParams launchParams) { |
| 1686 | int taskId = INVALID_TASK_ID; |
| 1687 | int displayId = INVALID_DISPLAY; |
| 1688 | //Rect bounds = null; |
| 1689 | |
| 1690 | // We give preference to the launch preference in activity options. |
| 1691 | if (options != null) { |
| 1692 | taskId = options.getLaunchTaskId(); |
| 1693 | displayId = options.getLaunchDisplayId(); |
| 1694 | } |
| 1695 | |
| 1696 | // First preference for stack goes to the task Id set in the activity options. Use the stack |
| 1697 | // associated with that if possible. |
| 1698 | if (taskId != INVALID_TASK_ID) { |
| 1699 | // Temporarily set the task id to invalid in case in re-entry. |
| 1700 | options.setLaunchTaskId(INVALID_TASK_ID); |
| 1701 | final TaskRecord task = anyTaskForId(taskId, |
| 1702 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); |
| 1703 | options.setLaunchTaskId(taskId); |
| 1704 | if (task != null) { |
| 1705 | return task.getStack(); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | final int activityType = resolveActivityType(r, options, candidateTask); |
| 1710 | T stack; |
| 1711 | |
| 1712 | // Next preference for stack goes to the display Id set the candidate display. |
| 1713 | if (launchParams != null && launchParams.mPreferredDisplayId != INVALID_DISPLAY) { |
| 1714 | displayId = launchParams.mPreferredDisplayId; |
| 1715 | } |
| 1716 | if (displayId != INVALID_DISPLAY && canLaunchOnDisplay(r, displayId)) { |
| 1717 | if (r != null) { |
| 1718 | stack = (T) getValidLaunchStackOnDisplay(displayId, r, candidateTask, options, |
| 1719 | launchParams); |
| 1720 | if (stack != null) { |
| 1721 | return stack; |
| 1722 | } |
| 1723 | } |
| 1724 | final ActivityDisplay display = getActivityDisplayOrCreate(displayId); |
| 1725 | if (display != null) { |
| 1726 | stack = display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
| 1727 | if (stack != null) { |
| 1728 | return stack; |
| 1729 | } |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | // Give preference to the stack and display of the input task and activity if they match the |
| 1734 | // mode we want to launch into. |
| 1735 | stack = null; |
| 1736 | ActivityDisplay display = null; |
| 1737 | if (candidateTask != null) { |
| 1738 | stack = candidateTask.getStack(); |
| 1739 | } |
| 1740 | if (stack == null && r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1741 | stack = r.getActivityStack(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1742 | } |
| 1743 | if (stack != null) { |
| 1744 | display = stack.getDisplay(); |
| 1745 | if (display != null && canLaunchOnDisplay(r, display.mDisplayId)) { |
| 1746 | int windowingMode = launchParams != null ? launchParams.mWindowingMode |
| 1747 | : WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
| 1748 | if (windowingMode == WindowConfiguration.WINDOWING_MODE_UNDEFINED) { |
| 1749 | windowingMode = display.resolveWindowingMode(r, options, candidateTask, |
| 1750 | activityType); |
| 1751 | } |
| 1752 | if (stack.isCompatible(windowingMode, activityType)) { |
| 1753 | return stack; |
| 1754 | } |
| 1755 | if (windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY |
| 1756 | && display.getSplitScreenPrimaryStack() == stack |
| 1757 | && candidateTask == stack.topTask()) { |
| 1758 | // This is a special case when we try to launch an activity that is currently on |
| 1759 | // top of split-screen primary stack, but is targeting split-screen secondary. |
| 1760 | // In this case we don't want to move it to another stack. |
| 1761 | // TODO(b/78788972): Remove after differentiating between preferred and required |
| 1762 | // launch options. |
| 1763 | return stack; |
| 1764 | } |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | if (display == null || !canLaunchOnDisplay(r, display.mDisplayId)) { |
| 1769 | display = getDefaultDisplay(); |
| 1770 | } |
| 1771 | |
| 1772 | return display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
| 1773 | } |
| 1774 | |
| 1775 | /** @return true if activity record is null or can be launched on provided display. */ |
| 1776 | private boolean canLaunchOnDisplay(ActivityRecord r, int displayId) { |
| 1777 | if (r == null) { |
| 1778 | return true; |
| 1779 | } |
| 1780 | return r.canBeLaunchedOnDisplay(displayId); |
| 1781 | } |
| 1782 | |
| 1783 | /** |
| 1784 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 1785 | * If there is no such stack, new dynamic stack can be created. |
| 1786 | * @param displayId Target display. |
| 1787 | * @param r Activity that should be launched there. |
| 1788 | * @param candidateTask The possible task the activity might be put in. |
| 1789 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 1790 | */ |
| 1791 | private ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r, |
| 1792 | @Nullable TaskRecord candidateTask, @Nullable ActivityOptions options, |
| 1793 | @Nullable LaunchParamsController.LaunchParams launchParams) { |
| 1794 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreate(displayId); |
| 1795 | if (activityDisplay == null) { |
| 1796 | throw new IllegalArgumentException( |
| 1797 | "Display with displayId=" + displayId + " not found."); |
| 1798 | } |
| 1799 | |
| 1800 | if (!r.canBeLaunchedOnDisplay(displayId)) { |
| 1801 | return null; |
| 1802 | } |
| 1803 | |
| 1804 | // If {@code r} is already in target display and its task is the same as the candidate task, |
| 1805 | // the intention should be getting a launch stack for the reusable activity, so we can use |
| 1806 | // the existing stack. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1807 | if (r.getDisplayId() == displayId && r.getTaskRecord() == candidateTask) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1808 | return candidateTask.getStack(); |
| 1809 | } |
| 1810 | |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1811 | int windowingMode; |
| 1812 | if (launchParams != null) { |
| 1813 | // When launch params is not null, we always defer to its windowing mode. Sometimes |
| 1814 | // it could be unspecified, which indicates it should inherit windowing mode from |
| 1815 | // display. |
| 1816 | windowingMode = launchParams.mWindowingMode; |
| 1817 | } else { |
| 1818 | windowingMode = options != null ? options.getLaunchWindowingMode() |
| 1819 | : r.getWindowingMode(); |
| 1820 | } |
| 1821 | windowingMode = activityDisplay.validateWindowingMode(windowingMode, r, candidateTask, |
| 1822 | r.getActivityType()); |
| 1823 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1824 | // Return the topmost valid stack on the display. |
| 1825 | for (int i = activityDisplay.getChildCount() - 1; i >= 0; --i) { |
| 1826 | final ActivityStack stack = activityDisplay.getChildAt(i); |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1827 | if (isValidLaunchStack(stack, r, windowingMode)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1828 | return stack; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | // If there is no valid stack on the external display - check if new dynamic stack will do. |
| 1833 | if (displayId != DEFAULT_DISPLAY) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1834 | final int activityType = |
| 1835 | options != null && options.getLaunchActivityType() != ACTIVITY_TYPE_UNDEFINED |
| 1836 | ? options.getLaunchActivityType() : r.getActivityType(); |
| 1837 | return activityDisplay.createStack(windowingMode, activityType, true /*onTop*/); |
| 1838 | } |
| 1839 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1840 | return null; |
| 1841 | } |
| 1842 | |
| 1843 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r, |
| 1844 | @Nullable ActivityOptions options, |
| 1845 | @Nullable LaunchParamsController.LaunchParams launchParams) { |
| 1846 | return getValidLaunchStackOnDisplay(displayId, r, null /* candidateTask */, options, |
| 1847 | launchParams); |
| 1848 | } |
| 1849 | |
| 1850 | // TODO: Can probably be consolidated into getLaunchStack()... |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1851 | private boolean isValidLaunchStack(ActivityStack stack, ActivityRecord r, int windowingMode) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1852 | switch (stack.getActivityType()) { |
| 1853 | case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); |
| 1854 | case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); |
| 1855 | case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant(); |
| 1856 | } |
| 1857 | // There is a 1-to-1 relationship between stack and task when not in |
| 1858 | // primary split-windowing mode. |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1859 | if (stack.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 1860 | && r.supportsSplitScreenWindowingMode() |
| 1861 | && (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 1862 | || windowingMode == WINDOWING_MODE_UNDEFINED)) { |
| 1863 | return true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1864 | } |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1865 | return false; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
| 1869 | @Nullable TaskRecord task) { |
| 1870 | // Preference is given to the activity type for the activity then the task since the type |
| 1871 | // once set shouldn't change. |
| 1872 | int activityType = r != null ? r.getActivityType() : ACTIVITY_TYPE_UNDEFINED; |
| 1873 | if (activityType == ACTIVITY_TYPE_UNDEFINED && task != null) { |
| 1874 | activityType = task.getActivityType(); |
| 1875 | } |
| 1876 | if (activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 1877 | return activityType; |
| 1878 | } |
| 1879 | if (options != null) { |
| 1880 | activityType = options.getLaunchActivityType(); |
| 1881 | } |
| 1882 | return activityType != ACTIVITY_TYPE_UNDEFINED ? activityType : ACTIVITY_TYPE_STANDARD; |
| 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * Get next focusable stack in the system. This will search through the stack on the same |
| 1887 | * display as the current focused stack, looking for a focusable and visible stack, different |
| 1888 | * from the target stack. If no valid candidates will be found, it will then go through all |
| 1889 | * displays and stacks in last-focused order. |
| 1890 | * |
| 1891 | * @param currentFocus The stack that previously had focus. |
| 1892 | * @param ignoreCurrent If we should ignore {@param currentFocus} when searching for next |
| 1893 | * candidate. |
| 1894 | * @return Next focusable {@link ActivityStack}, {@code null} if not found. |
| 1895 | */ |
| 1896 | ActivityStack getNextFocusableStack(@NonNull ActivityStack currentFocus, |
| 1897 | boolean ignoreCurrent) { |
| 1898 | // First look for next focusable stack on the same display |
| 1899 | final ActivityDisplay preferredDisplay = currentFocus.getDisplay(); |
| 1900 | final ActivityStack preferredFocusableStack = preferredDisplay.getNextFocusableStack( |
| 1901 | currentFocus, ignoreCurrent); |
| 1902 | if (preferredFocusableStack != null) { |
| 1903 | return preferredFocusableStack; |
| 1904 | } |
| 1905 | if (preferredDisplay.supportsSystemDecorations()) { |
| 1906 | // Stop looking for focusable stack on other displays because the preferred display |
| 1907 | // supports system decorations. Home activity would be launched on the same display if |
| 1908 | // no focusable stack found. |
| 1909 | return null; |
| 1910 | } |
| 1911 | |
| 1912 | // Now look through all displays |
| 1913 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 1914 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 1915 | if (display == preferredDisplay) { |
| 1916 | // We've already checked this one |
| 1917 | continue; |
| 1918 | } |
| 1919 | final ActivityStack nextFocusableStack = display.getNextFocusableStack(currentFocus, |
| 1920 | ignoreCurrent); |
| 1921 | if (nextFocusableStack != null) { |
| 1922 | return nextFocusableStack; |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | return null; |
| 1927 | } |
| 1928 | |
| 1929 | /** |
| 1930 | * Get next valid stack for launching provided activity in the system. This will search across |
| 1931 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 1932 | * that are on a currently focused display. |
| 1933 | * |
| 1934 | * @param r The activity that is being launched. |
| 1935 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 1936 | * searching for the next candidate. |
| 1937 | * @return Next valid {@link ActivityStack}, null if not found. |
| 1938 | */ |
| 1939 | ActivityStack getNextValidLaunchStack(@NonNull ActivityRecord r, int currentFocus) { |
| 1940 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 1941 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 1942 | if (display.mDisplayId == currentFocus) { |
| 1943 | continue; |
| 1944 | } |
| 1945 | final ActivityStack stack = getValidLaunchStackOnDisplay(display.mDisplayId, r, |
| 1946 | null /* options */, null /* launchParams */); |
| 1947 | if (stack != null) { |
| 1948 | return stack; |
| 1949 | } |
| 1950 | } |
| 1951 | return null; |
| 1952 | } |
| 1953 | |
| 1954 | boolean handleAppDied(WindowProcessController app) { |
| 1955 | boolean hasVisibleActivities = false; |
| 1956 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1957 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1958 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1959 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1960 | hasVisibleActivities |= stack.handleAppDiedLocked(app); |
| 1961 | } |
| 1962 | } |
| 1963 | return hasVisibleActivities; |
| 1964 | } |
| 1965 | |
| 1966 | void closeSystemDialogs() { |
| 1967 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1968 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1969 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1970 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1971 | stack.closeSystemDialogsLocked(); |
| 1972 | } |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | /** @return true if some activity was finished (or would have finished if doit were true). */ |
| 1977 | boolean finishDisabledPackageActivities(String packageName, Set<String> filterByClasses, |
| 1978 | boolean doit, boolean evenPersistent, int userId) { |
| 1979 | boolean didSomething = false; |
| 1980 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1981 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1982 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1983 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1984 | if (stack.finishDisabledPackageActivitiesLocked( |
| 1985 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
| 1986 | didSomething = true; |
| 1987 | } |
| 1988 | } |
| 1989 | } |
| 1990 | return didSomething; |
| 1991 | } |
| 1992 | |
| 1993 | void updateActivityApplicationInfo(ApplicationInfo aInfo) { |
| 1994 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1995 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1996 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1997 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1998 | stack.updateActivityApplicationInfoLocked(aInfo); |
| 1999 | } |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2004 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2005 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2006 | final int numStacks = display.getChildCount(); |
| 2007 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 2008 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2009 | stack.finishVoiceTask(session); |
| 2010 | } |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | /** |
| 2015 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2016 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2017 | */ |
| 2018 | void removeStacksInWindowingModes(int... windowingModes) { |
| 2019 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2020 | mActivityDisplays.get(i).removeStacksInWindowingModes(windowingModes); |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 2025 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2026 | mActivityDisplays.get(i).removeStacksWithActivityTypes(activityTypes); |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | ActivityRecord topRunningActivity() { |
| 2031 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2032 | final ActivityRecord topActivity = mActivityDisplays.get(i).topRunningActivity(); |
| 2033 | if (topActivity != null) { |
| 2034 | return topActivity; |
| 2035 | } |
| 2036 | } |
| 2037 | return null; |
| 2038 | } |
| 2039 | |
| 2040 | boolean allResumedActivitiesIdle() { |
| 2041 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2042 | // TODO(b/117135575): Check resumed activities on all visible stacks. |
| 2043 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2044 | if (display.isSleeping()) { |
| 2045 | // No resumed activities while display is sleeping. |
| 2046 | continue; |
| 2047 | } |
| 2048 | |
| 2049 | // If the focused stack is not null or not empty, there should have some activities |
| 2050 | // resuming or resumed. Make sure these activities are idle. |
| 2051 | final ActivityStack stack = display.getFocusedStack(); |
| 2052 | if (stack == null || stack.numActivities() == 0) { |
| 2053 | continue; |
| 2054 | } |
| 2055 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 2056 | if (resumedActivity == null || !resumedActivity.idle) { |
| 2057 | if (DEBUG_STATES) { |
| 2058 | Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
| 2059 | + stack.mStackId + " " + resumedActivity + " not idle"); |
| 2060 | } |
| 2061 | return false; |
| 2062 | } |
| 2063 | } |
| 2064 | // Send launch end powerhint when idle |
| 2065 | sendPowerHintForLaunchEndIfNeeded(); |
| 2066 | return true; |
| 2067 | } |
| 2068 | |
| 2069 | boolean allResumedActivitiesVisible() { |
| 2070 | boolean foundResumed = false; |
| 2071 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2072 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2073 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2074 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2075 | final ActivityRecord r = stack.getResumedActivity(); |
| 2076 | if (r != null) { |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2077 | if (!r.nowVisible) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2078 | return false; |
| 2079 | } |
| 2080 | foundResumed = true; |
| 2081 | } |
| 2082 | } |
| 2083 | } |
| 2084 | return foundResumed; |
| 2085 | } |
| 2086 | |
| 2087 | boolean allPausedActivitiesComplete() { |
| 2088 | boolean pausing = true; |
| 2089 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2090 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2091 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2092 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2093 | final ActivityRecord r = stack.mPausingActivity; |
| 2094 | if (r != null && !r.isState(PAUSED, STOPPED, STOPPING)) { |
| 2095 | if (DEBUG_STATES) { |
| 2096 | Slog.d(TAG_STATES, |
| 2097 | "allPausedActivitiesComplete: r=" + r + " state=" + r.getState()); |
| 2098 | pausing = false; |
| 2099 | } else { |
| 2100 | return false; |
| 2101 | } |
| 2102 | } |
| 2103 | } |
| 2104 | } |
| 2105 | return pausing; |
| 2106 | } |
| 2107 | |
| 2108 | /** |
| 2109 | * Find all visible task stacks containing {@param userId} and intercept them with an activity |
| 2110 | * to block out the contents and possibly start a credential-confirming intent. |
| 2111 | * |
| 2112 | * @param userId user handle for the locked managed profile. |
| 2113 | */ |
| 2114 | void lockAllProfileTasks(@UserIdInt int userId) { |
| 2115 | mWindowManager.deferSurfaceLayout(); |
| 2116 | try { |
| 2117 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2118 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2119 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2120 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2121 | final List<TaskRecord> tasks = stack.getAllTasks(); |
| 2122 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 2123 | final TaskRecord task = tasks.get(taskNdx); |
| 2124 | |
| 2125 | // Check the task for a top activity belonging to userId, or returning a |
| 2126 | // result to an activity belonging to userId. Example case: a document |
| 2127 | // picker for personal files, opened by a work app, should still get locked. |
| 2128 | if (taskTopActivityIsUser(task, userId)) { |
| 2129 | mService.getTaskChangeNotificationController().notifyTaskProfileLocked( |
| 2130 | task.taskId, userId); |
| 2131 | } |
| 2132 | } |
| 2133 | } |
| 2134 | } |
| 2135 | } finally { |
| 2136 | mWindowManager.continueSurfaceLayout(); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * Detects whether we should show a lock screen in front of this task for a locked user. |
| 2142 | * <p> |
| 2143 | * We'll do this if either of the following holds: |
| 2144 | * <ul> |
| 2145 | * <li>The top activity explicitly belongs to {@param userId}.</li> |
| 2146 | * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> |
| 2147 | * </ul> |
| 2148 | * |
| 2149 | * @return {@code true} if the top activity looks like it belongs to {@param userId}. |
| 2150 | */ |
| 2151 | private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { |
| 2152 | // To handle the case that work app is in the task but just is not the top one. |
| 2153 | final ActivityRecord activityRecord = task.getTopActivity(); |
| 2154 | final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); |
| 2155 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2156 | return (activityRecord != null && activityRecord.mUserId == userId) |
| 2157 | || (resultTo != null && resultTo.mUserId == userId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | void cancelInitializingActivities() { |
| 2161 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2162 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2163 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2164 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2165 | stack.cancelInitializingActivities(); |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | TaskRecord anyTaskForId(int id) { |
| 2171 | return anyTaskForId(id, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE); |
| 2172 | } |
| 2173 | |
| 2174 | TaskRecord anyTaskForId(int id, @AnyTaskForIdMatchTaskMode int matchMode) { |
| 2175 | return anyTaskForId(id, matchMode, null, !ON_TOP); |
| 2176 | } |
| 2177 | |
| 2178 | /** |
| 2179 | * Returns a {@link TaskRecord} for the input id if available. {@code null} otherwise. |
| 2180 | * @param id Id of the task we would like returned. |
| 2181 | * @param matchMode The mode to match the given task id in. |
| 2182 | * @param aOptions The activity options to use for restoration. Can be null. |
| 2183 | * @param onTop If the stack for the task should be the topmost on the display. |
| 2184 | */ |
| 2185 | TaskRecord anyTaskForId(int id, @AnyTaskForIdMatchTaskMode int matchMode, |
| 2186 | @Nullable ActivityOptions aOptions, boolean onTop) { |
| 2187 | // If options are set, ensure that we are attempting to actually restore a task |
| 2188 | if (matchMode != MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE && aOptions != null) { |
| 2189 | throw new IllegalArgumentException("Should not specify activity options for non-restore" |
| 2190 | + " lookup"); |
| 2191 | } |
| 2192 | |
| 2193 | int numDisplays = mActivityDisplays.size(); |
| 2194 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 2195 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2196 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2197 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2198 | final TaskRecord task = stack.taskForIdLocked(id); |
| 2199 | if (task == null) { |
| 2200 | continue; |
| 2201 | } |
| 2202 | if (aOptions != null) { |
| 2203 | // Resolve the stack the task should be placed in now based on options |
| 2204 | // and reparent if needed. |
| 2205 | final ActivityStack launchStack = |
| 2206 | getLaunchStack(null, aOptions, task, onTop); |
| 2207 | if (launchStack != null && stack != launchStack) { |
| 2208 | final int reparentMode = onTop |
| 2209 | ? REPARENT_MOVE_STACK_TO_FRONT : REPARENT_LEAVE_STACK_IN_PLACE; |
| 2210 | task.reparent(launchStack, onTop, reparentMode, ANIMATE, DEFER_RESUME, |
| 2211 | "anyTaskForId"); |
| 2212 | } |
| 2213 | } |
| 2214 | return task; |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | // If we are matching stack tasks only, return now |
| 2219 | if (matchMode == MATCH_TASK_IN_STACKS_ONLY) { |
| 2220 | return null; |
| 2221 | } |
| 2222 | |
| 2223 | // Otherwise, check the recent tasks and return if we find it there and we are not restoring |
| 2224 | // the task from recents |
| 2225 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, "Looking for task id=" + id + " in recents"); |
| 2226 | final TaskRecord task = mStackSupervisor.mRecentTasks.getTask(id); |
| 2227 | |
| 2228 | if (task == null) { |
| 2229 | if (DEBUG_RECENTS) { |
| 2230 | Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
| 2231 | } |
| 2232 | |
| 2233 | return null; |
| 2234 | } |
| 2235 | |
| 2236 | if (matchMode == MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) { |
| 2237 | return task; |
| 2238 | } |
| 2239 | |
| 2240 | // Implicitly, this case is MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 2241 | if (!mStackSupervisor.restoreRecentTaskLocked(task, aOptions, onTop)) { |
| 2242 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 2243 | "Couldn't restore task id=" + id + " found in recents"); |
| 2244 | return null; |
| 2245 | } |
| 2246 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, "Restored task id=" + id + " from in recents"); |
| 2247 | return task; |
| 2248 | } |
| 2249 | |
| 2250 | ActivityRecord isInAnyStack(IBinder token) { |
| 2251 | int numDisplays = mActivityDisplays.size(); |
| 2252 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 2253 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2254 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2255 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2256 | final ActivityRecord r = stack.isInStackLocked(token); |
| 2257 | if (r != null) { |
| 2258 | return r; |
| 2259 | } |
| 2260 | } |
| 2261 | } |
| 2262 | return null; |
| 2263 | } |
| 2264 | |
| 2265 | @VisibleForTesting |
| 2266 | void getRunningTasks(int maxNum, List<ActivityManager.RunningTaskInfo> list, |
| 2267 | @WindowConfiguration.ActivityType int ignoreActivityType, |
| 2268 | @WindowConfiguration.WindowingMode int ignoreWindowingMode, int callingUid, |
| 2269 | boolean allowed) { |
| 2270 | mStackSupervisor.mRunningTasks.getTasks(maxNum, list, ignoreActivityType, |
| 2271 | ignoreWindowingMode, mActivityDisplays, callingUid, allowed); |
| 2272 | } |
| 2273 | |
| 2274 | void sendPowerHintForLaunchStartIfNeeded(boolean forceSend, ActivityRecord targetActivity) { |
| 2275 | boolean sendHint = forceSend; |
| 2276 | |
| 2277 | if (!sendHint) { |
| 2278 | // Send power hint if we don't know what we're launching yet |
| 2279 | sendHint = targetActivity == null || targetActivity.app == null; |
| 2280 | } |
| 2281 | |
| 2282 | if (!sendHint) { // targetActivity != null |
| 2283 | // Send power hint when the activity's process is different than the current resumed |
| 2284 | // activity on all displays, or if there are no resumed activities in the system. |
| 2285 | boolean noResumedActivities = true; |
| 2286 | boolean allFocusedProcessesDiffer = true; |
| 2287 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 2288 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
| 2289 | final ActivityRecord resumedActivity = activityDisplay.getResumedActivity(); |
| 2290 | final WindowProcessController resumedActivityProcess = |
| 2291 | resumedActivity == null ? null : resumedActivity.app; |
| 2292 | |
| 2293 | noResumedActivities &= resumedActivityProcess == null; |
| 2294 | if (resumedActivityProcess != null) { |
| 2295 | allFocusedProcessesDiffer &= !resumedActivityProcess.equals(targetActivity.app); |
| 2296 | } |
| 2297 | } |
| 2298 | sendHint = noResumedActivities || allFocusedProcessesDiffer; |
| 2299 | } |
| 2300 | |
| 2301 | if (sendHint && mService.mPowerManagerInternal != null) { |
| 2302 | mService.mPowerManagerInternal.powerHint(PowerHint.LAUNCH, 1); |
| 2303 | mPowerHintSent = true; |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | void sendPowerHintForLaunchEndIfNeeded() { |
| 2308 | // Trigger launch power hint if activity is launched |
| 2309 | if (mPowerHintSent && mService.mPowerManagerInternal != null) { |
| 2310 | mService.mPowerManagerInternal.powerHint(PowerHint.LAUNCH, 0); |
| 2311 | mPowerHintSent = false; |
| 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | private void calculateDefaultMinimalSizeOfResizeableTasks() { |
| 2316 | final Resources res = mService.mContext.getResources(); |
| 2317 | final float minimalSize = res.getDimension( |
| 2318 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
| 2319 | final DisplayMetrics dm = res.getDisplayMetrics(); |
| 2320 | |
| 2321 | mDefaultMinSizeOfResizeableTaskDp = (int) (minimalSize / dm.density); |
| 2322 | } |
| 2323 | |
| 2324 | /** |
| 2325 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 2326 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 2327 | */ |
| 2328 | ArrayList<ActivityRecord> getDumpActivities(String name, boolean dumpVisibleStacksOnly, |
| 2329 | boolean dumpFocusedStackOnly) { |
| 2330 | if (dumpFocusedStackOnly) { |
| 2331 | return getTopDisplayFocusedStack().getDumpActivitiesLocked(name); |
| 2332 | } else { |
| 2333 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 2334 | int numDisplays = mActivityDisplays.size(); |
| 2335 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 2336 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2337 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2338 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2339 | if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { |
| 2340 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 2341 | } |
| 2342 | } |
| 2343 | } |
| 2344 | return activities; |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | public void dump(PrintWriter pw, String prefix) { |
| 2349 | pw.print(prefix); |
| 2350 | pw.println("topDisplayFocusedStack=" + getTopDisplayFocusedStack()); |
| 2351 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2352 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 2353 | display.dump(pw, prefix); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * Dump all connected displays' configurations. |
| 2359 | * @param prefix Prefix to apply to each line of the dump. |
| 2360 | */ |
| 2361 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 2362 | pw.print(prefix); pw.println("Display override configurations:"); |
| 2363 | final int displayCount = mActivityDisplays.size(); |
| 2364 | for (int i = 0; i < displayCount; i++) { |
| 2365 | final ActivityDisplay activityDisplay = mActivityDisplays.get(i); |
| 2366 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 2367 | pw.println(activityDisplay.getRequestedOverrideConfiguration()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | public void dumpDisplays(PrintWriter pw) { |
| 2372 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2373 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 2374 | pw.print("[id:" + display.mDisplayId + " stacks:"); |
| 2375 | display.dumpStacks(pw); |
| 2376 | pw.print("]"); |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | boolean dumpActivities(FileDescriptor fd, PrintWriter pw, boolean dumpAll, boolean dumpClient, |
| 2381 | String dumpPackage) { |
| 2382 | boolean printed = false; |
| 2383 | boolean needSep = false; |
| 2384 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2385 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
| 2386 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
| 2387 | pw.println(" (activities from top to bottom):"); |
| 2388 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 2389 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2390 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2391 | pw.println(); |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 2392 | printed = stack.dump(fd, pw, dumpAll, dumpClient, dumpPackage, needSep); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2393 | needSep = printed; |
| 2394 | } |
| 2395 | printThisActivity(pw, activityDisplay.getResumedActivity(), dumpPackage, needSep, |
| 2396 | " ResumedActivity:"); |
| 2397 | } |
| 2398 | |
| 2399 | printed |= dumpHistoryList(fd, pw, mStackSupervisor.mFinishingActivities, " ", |
| 2400 | "Fin", false, !dumpAll, |
| 2401 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 2402 | printed |= dumpHistoryList(fd, pw, mStackSupervisor.mStoppingActivities, " ", |
| 2403 | "Stop", false, !dumpAll, |
| 2404 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2405 | printed |= dumpHistoryList(fd, pw, mStackSupervisor.mGoingToSleepActivities, |
| 2406 | " ", "Sleep", false, !dumpAll, |
| 2407 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
| 2408 | |
| 2409 | return printed; |
| 2410 | } |
| 2411 | |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2412 | protected void writeToProto(ProtoOutputStream proto, long fieldId, |
| 2413 | @WindowTraceLogLevel int logLevel) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2414 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2415 | super.writeToProto(proto, CONFIGURATION_CONTAINER, logLevel); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2416 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 2417 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2418 | activityDisplay.writeToProto(proto, DISPLAYS, logLevel); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2419 | } |
| 2420 | mStackSupervisor.getKeyguardController().writeToProto(proto, KEYGUARD_CONTROLLER); |
| 2421 | // TODO(b/111541062): Update tests to look for resumed activities on all displays |
| 2422 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
| 2423 | if (focusedStack != null) { |
| 2424 | proto.write(FOCUSED_STACK_ID, focusedStack.mStackId); |
| 2425 | final ActivityRecord focusedActivity = focusedStack.getDisplay().getResumedActivity(); |
| 2426 | if (focusedActivity != null) { |
| 2427 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 2428 | } |
| 2429 | } else { |
| 2430 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 2431 | } |
| 2432 | proto.write(IS_HOME_RECENTS_COMPONENT, |
| 2433 | mStackSupervisor.mRecentTasks.isRecentsComponentHomeActivity(mCurrentUser)); |
| 2434 | mService.getActivityStartController().writeToProto(proto, PENDING_ACTIVITIES); |
| 2435 | proto.end(token); |
| 2436 | } |
| 2437 | |
| 2438 | private final class SleepTokenImpl extends ActivityTaskManagerInternal.SleepToken { |
| 2439 | private final String mTag; |
| 2440 | private final long mAcquireTime; |
| 2441 | private final int mDisplayId; |
| 2442 | |
| 2443 | public SleepTokenImpl(String tag, int displayId) { |
| 2444 | mTag = tag; |
| 2445 | mDisplayId = displayId; |
| 2446 | mAcquireTime = SystemClock.uptimeMillis(); |
| 2447 | } |
| 2448 | |
| 2449 | @Override |
| 2450 | public void release() { |
| 2451 | synchronized (mService.mGlobalLock) { |
| 2452 | removeSleepToken(this); |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | @Override |
| 2457 | public String toString() { |
| 2458 | return "{\"" + mTag + "\", display " + mDisplayId |
| 2459 | + ", acquire at " + TimeUtils.formatUptime(mAcquireTime) + "}"; |
| 2460 | } |
| 2461 | } |
| 2462 | } |