Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 18 | |
Michal Karpinski | 7b97a02 | 2018-12-14 15:17:29 +0000 | [diff] [blame] | 19 | import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 20 | import static android.app.Activity.RESULT_CANCELED; |
Bryce Lee | f9d4954 | 2017-06-26 16:27:32 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.START_ABORTED; |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 22 | import static android.app.ActivityManager.START_CANCELED; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 23 | import static android.app.ActivityManager.START_CLASS_NOT_FOUND; |
| 24 | import static android.app.ActivityManager.START_DELIVERED_TO_TOP; |
| 25 | import static android.app.ActivityManager.START_FLAG_ONLY_IF_NEEDED; |
| 26 | import static android.app.ActivityManager.START_RETURN_INTENT_TO_CALLER; |
| 27 | import static android.app.ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION; |
| 28 | import static android.app.ActivityManager.START_SUCCESS; |
| 29 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
Louis Chang | 0513a94 | 2019-03-06 12:38:13 +0800 | [diff] [blame] | 30 | import static android.app.WaitResult.LAUNCH_STATE_COLD; |
| 31 | import static android.app.WaitResult.LAUNCH_STATE_HOT; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 32 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 33 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 7d7973a | 2018-04-05 10:25:59 -0700 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 38 | import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; |
| 39 | import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; |
Wale Ogunwale | 2a25a62 | 2016-01-30 11:27:21 -0800 | [diff] [blame] | 40 | import static android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 41 | import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 42 | import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 43 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 44 | import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION; |
| 45 | import static android.content.Intent.FLAG_ACTIVITY_NO_USER_ACTION; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 46 | import static android.content.Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP; |
| 47 | import static android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT; |
| 48 | import static android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED; |
| 49 | import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS; |
| 50 | import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; |
Louis Chang | b45ee7e | 2019-01-17 10:36:56 +0800 | [diff] [blame] | 51 | import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 52 | import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS; |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 53 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 54 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 55 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
| 56 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP; |
Michal Karpinski | 7b97a02 | 2018-12-14 15:17:29 +0000 | [diff] [blame] | 57 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 58 | import static android.os.Process.INVALID_UID; |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 59 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 60 | import static android.view.Display.INVALID_DISPLAY; |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 61 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 62 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 63 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
| 64 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 65 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 66 | import static com.android.server.wm.ActivityStackSupervisor.TAG_TASKS; |
| 67 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 68 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 69 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PERMISSIONS_REVIEW; |
| 70 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS; |
| 71 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 72 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 73 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_USER_LEAVING; |
| 74 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 75 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 76 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RESULTS; |
| 77 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_LEAVING; |
| 78 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 79 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 80 | import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 81 | import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_BOUNDS; |
| 82 | import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_DISPLAY; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 83 | import static com.android.server.wm.Task.REPARENT_MOVE_STACK_TO_FRONT; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 84 | |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 85 | import android.annotation.NonNull; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 86 | import android.annotation.Nullable; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 87 | import android.app.ActivityManager; |
| 88 | import android.app.ActivityOptions; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 89 | import android.app.IApplicationThread; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 90 | import android.app.PendingIntent; |
| 91 | import android.app.ProfilerInfo; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 92 | import android.app.WaitResult; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 93 | import android.content.IIntentSender; |
| 94 | import android.content.Intent; |
| 95 | import android.content.IntentSender; |
| 96 | import android.content.pm.ActivityInfo; |
| 97 | import android.content.pm.ApplicationInfo; |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 98 | import android.content.pm.AuxiliaryResolveInfo; |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 99 | import android.content.pm.PackageManager; |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 100 | import android.content.pm.PackageManagerInternal; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 101 | import android.content.pm.ResolveInfo; |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 102 | import android.content.pm.UserInfo; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 103 | import android.content.res.Configuration; |
| 104 | import android.graphics.Rect; |
| 105 | import android.os.Binder; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 106 | import android.os.Bundle; |
| 107 | import android.os.IBinder; |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 108 | import android.os.Process; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 109 | import android.os.RemoteException; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 110 | import android.os.Trace; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 111 | import android.os.UserHandle; |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 112 | import android.os.UserManager; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 113 | import android.service.voice.IVoiceInteractionSession; |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 114 | import android.text.TextUtils; |
Michal Karpinski | b7daac2 | 2019-03-25 10:12:41 +0000 | [diff] [blame] | 115 | import android.util.ArraySet; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 116 | import android.util.Pools.SynchronizedPool; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 117 | import android.util.Slog; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 118 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 119 | import com.android.internal.annotations.VisibleForTesting; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 120 | import com.android.internal.app.HeavyWeightSwitcherActivity; |
| 121 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 122 | import com.android.server.am.PendingIntentRecord; |
Louis Chang | dd3592a | 2018-11-05 11:04:14 +0800 | [diff] [blame] | 123 | import com.android.server.pm.InstantAppResolver; |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 124 | import com.android.server.wm.ActivityMetricsLogger.LaunchingState; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 125 | import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch; |
| 126 | import com.android.server.wm.LaunchParamsController.LaunchParams; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 127 | |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 128 | import java.io.PrintWriter; |
| 129 | import java.text.DateFormat; |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 130 | import java.util.Date; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 131 | |
| 132 | /** |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 133 | * Controller for interpreting how and then launching an activity. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 134 | * |
| 135 | * This class collects all the logic for determining how an intent and flags should be turned into |
| 136 | * an activity and associated task and stack. |
| 137 | */ |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 138 | class ActivityStarter { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 139 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStarter" : TAG_ATM; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 140 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
| 141 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 142 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
| 143 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 144 | private static final int INVALID_LAUNCH_MODE = -1; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 145 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 146 | private final ActivityTaskManagerService mService; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 147 | private final RootWindowContainer mRootWindowContainer; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 148 | private final ActivityStackSupervisor mSupervisor; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 149 | private final ActivityStartInterceptor mInterceptor; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 150 | private final ActivityStartController mController; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 151 | |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 152 | // Share state variable among methods when starting an activity. |
Louis Chang | 07b1300 | 2019-11-27 22:08:37 +0800 | [diff] [blame] | 153 | @VisibleForTesting |
| 154 | ActivityRecord mStartActivity; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 155 | private Intent mIntent; |
| 156 | private int mCallingUid; |
| 157 | private ActivityOptions mOptions; |
| 158 | |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 159 | // If it is true, background activity can only be started in an existing task that contains |
Alan Stokes | 07389b6 | 2019-05-20 15:22:54 +0100 | [diff] [blame] | 160 | // an activity with same uid, or if activity starts are enabled in developer options. |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 161 | private boolean mRestrictedBgActivity; |
| 162 | |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 163 | private int mLaunchMode; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 164 | private boolean mLaunchTaskBehind; |
| 165 | private int mLaunchFlags; |
| 166 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 167 | private LaunchParams mLaunchParams = new LaunchParams(); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 168 | |
| 169 | private ActivityRecord mNotTop; |
| 170 | private boolean mDoResume; |
| 171 | private int mStartFlags; |
| 172 | private ActivityRecord mSourceRecord; |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 173 | |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 174 | // The display to launch the activity onto, barring any strong reason to do otherwise. |
| 175 | private int mPreferredDisplayId; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 176 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 177 | private Task mInTask; |
Louis Chang | 07b1300 | 2019-11-27 22:08:37 +0800 | [diff] [blame] | 178 | @VisibleForTesting |
| 179 | boolean mAddingToTask; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 180 | private Task mReuseTask; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 181 | |
| 182 | private ActivityInfo mNewTaskInfo; |
| 183 | private Intent mNewTaskIntent; |
| 184 | private ActivityStack mSourceStack; |
| 185 | private ActivityStack mTargetStack; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 186 | private boolean mMovedToFront; |
| 187 | private boolean mNoAnimation; |
| 188 | private boolean mKeepCurTransition; |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 189 | private boolean mAvoidMoveToFront; |
Winson Chung | e219ae1 | 2019-07-18 13:43:23 -0700 | [diff] [blame] | 190 | private boolean mFrozeTaskList; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 191 | |
Bryce Lee | 325e0968 | 2017-10-05 17:20:25 -0700 | [diff] [blame] | 192 | // We must track when we deliver the new intent since multiple code paths invoke |
| 193 | // {@link #deliverNewIntent}. This is due to early returns in the code path. This flag is used |
| 194 | // inside {@link #deliverNewIntent} to suppress duplicate requests and ensure the intent is |
| 195 | // delivered at most once. |
| 196 | private boolean mIntentDelivered; |
| 197 | |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 198 | private IVoiceInteractionSession mVoiceSession; |
| 199 | private IVoiceInteractor mVoiceInteractor; |
| 200 | |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 201 | // Last activity record we attempted to start |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 202 | private ActivityRecord mLastStartActivityRecord; |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 203 | // The result of the last activity we attempted to start. |
| 204 | private int mLastStartActivityResult; |
| 205 | // Time in milli seconds we attempted to start the last activity. |
| 206 | private long mLastStartActivityTimeMs; |
| 207 | // The reason we were trying to start the last activity |
| 208 | private String mLastStartReason; |
Wale Ogunwale | 59bcba6 | 2017-06-16 12:42:51 -0700 | [diff] [blame] | 209 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 210 | /* |
| 211 | * Request details provided through setter methods. Should be reset after {@link #execute()} |
| 212 | * to avoid unnecessarily retaining parameters. Note that the request is ignored when |
| 213 | * {@link #startResolvedActivity} is invoked directly. |
| 214 | */ |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 215 | @VisibleForTesting |
| 216 | Request mRequest = new Request(); |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 217 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 218 | /** |
| 219 | * An interface that to provide {@link ActivityStarter} instances to the controller. This is |
| 220 | * used by tests to inject their own starter implementations for verification purposes. |
| 221 | */ |
| 222 | @VisibleForTesting |
| 223 | interface Factory { |
| 224 | /** |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 225 | * Sets the {@link ActivityStartController} to be passed to {@link ActivityStarter}. |
| 226 | */ |
| 227 | void setController(ActivityStartController controller); |
| 228 | |
| 229 | /** |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 230 | * Generates an {@link ActivityStarter} that is ready to handle a new start request. |
| 231 | * @param controller The {@link ActivityStartController} which the starter who will own |
| 232 | * this instance. |
| 233 | * @return an {@link ActivityStarter} |
| 234 | */ |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 235 | ActivityStarter obtain(); |
| 236 | |
| 237 | /** |
| 238 | * Recycles a starter for reuse. |
| 239 | */ |
| 240 | void recycle(ActivityStarter starter); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 243 | /** |
| 244 | * Default implementation of {@link StarterFactory}. |
| 245 | */ |
| 246 | static class DefaultFactory implements Factory { |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 247 | /** |
| 248 | * The maximum count of starters that should be active at one time: |
| 249 | * 1. last ran starter (for logging and post activity processing) |
| 250 | * 2. current running starter |
| 251 | * 3. starter from re-entry in (2) |
| 252 | */ |
| 253 | private final int MAX_STARTER_COUNT = 3; |
| 254 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 255 | private ActivityStartController mController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 256 | private ActivityTaskManagerService mService; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 257 | private ActivityStackSupervisor mSupervisor; |
| 258 | private ActivityStartInterceptor mInterceptor; |
| 259 | |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 260 | private SynchronizedPool<ActivityStarter> mStarterPool = |
| 261 | new SynchronizedPool<>(MAX_STARTER_COUNT); |
| 262 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 263 | DefaultFactory(ActivityTaskManagerService service, |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 264 | ActivityStackSupervisor supervisor, ActivityStartInterceptor interceptor) { |
| 265 | mService = service; |
| 266 | mSupervisor = supervisor; |
| 267 | mInterceptor = interceptor; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 268 | } |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 269 | |
| 270 | @Override |
| 271 | public void setController(ActivityStartController controller) { |
| 272 | mController = controller; |
| 273 | } |
| 274 | |
| 275 | @Override |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 276 | public ActivityStarter obtain() { |
| 277 | ActivityStarter starter = mStarterPool.acquire(); |
| 278 | |
| 279 | if (starter == null) { |
| 280 | starter = new ActivityStarter(mController, mService, mSupervisor, mInterceptor); |
| 281 | } |
| 282 | |
| 283 | return starter; |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void recycle(ActivityStarter starter) { |
| 288 | starter.reset(true /* clearRequest*/); |
| 289 | mStarterPool.release(starter); |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Container for capturing initial start request details. This information is NOT reset until |
| 295 | * the {@link ActivityStarter} is recycled, allowing for multiple invocations with the same |
| 296 | * parameters. |
| 297 | * |
| 298 | * TODO(b/64750076): Investigate consolidating member variables of {@link ActivityStarter} with |
| 299 | * the request object. Note that some member variables are referenced in |
| 300 | * {@link #dump(PrintWriter, String)} and therefore cannot be cleared immediately after |
| 301 | * execution. |
| 302 | */ |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 303 | @VisibleForTesting |
| 304 | static class Request { |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 305 | private static final int DEFAULT_CALLING_UID = -1; |
| 306 | private static final int DEFAULT_CALLING_PID = 0; |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 307 | static final int DEFAULT_REAL_CALLING_UID = -1; |
| 308 | static final int DEFAULT_REAL_CALLING_PID = 0; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 309 | |
| 310 | IApplicationThread caller; |
| 311 | Intent intent; |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 312 | // A copy of the original requested intent, in case for ephemeral app launch. |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 313 | Intent ephemeralIntent; |
| 314 | String resolvedType; |
| 315 | ActivityInfo activityInfo; |
| 316 | ResolveInfo resolveInfo; |
| 317 | IVoiceInteractionSession voiceSession; |
| 318 | IVoiceInteractor voiceInteractor; |
| 319 | IBinder resultTo; |
| 320 | String resultWho; |
| 321 | int requestCode; |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 322 | int callingPid = DEFAULT_CALLING_PID; |
| 323 | int callingUid = DEFAULT_CALLING_UID; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 324 | String callingPackage; |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 325 | int realCallingPid = DEFAULT_REAL_CALLING_PID; |
| 326 | int realCallingUid = DEFAULT_REAL_CALLING_UID; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 327 | int startFlags; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 328 | SafeActivityOptions activityOptions; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 329 | boolean ignoreTargetSecurity; |
| 330 | boolean componentSpecified; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 331 | boolean avoidMoveToFront; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 332 | ActivityRecord[] outActivity; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 333 | Task inTask; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 334 | String reason; |
| 335 | ProfilerInfo profilerInfo; |
| 336 | Configuration globalConfig; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 337 | int userId; |
| 338 | WaitResult waitResult; |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 339 | int filterCallingUid; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 340 | PendingIntentRecord originatingPendingIntent; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 341 | boolean allowBackgroundActivityStart; |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 342 | |
| 343 | /** |
Jorim Jaggi | 6fa41c3 | 2018-04-23 18:35:00 +0200 | [diff] [blame] | 344 | * If set to {@code true}, allows this activity start to look into |
| 345 | * {@link PendingRemoteAnimationRegistry} |
| 346 | */ |
| 347 | boolean allowPendingRemoteAnimationRegistryLookup; |
| 348 | |
| 349 | /** |
Bryce Lee | a3cd8e0 | 2018-01-09 15:44:24 -0800 | [diff] [blame] | 350 | * Ensure constructed request matches reset instance. |
| 351 | */ |
| 352 | Request() { |
| 353 | reset(); |
| 354 | } |
| 355 | |
| 356 | /** |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 357 | * Sets values back to the initial state, clearing any held references. |
| 358 | */ |
| 359 | void reset() { |
| 360 | caller = null; |
| 361 | intent = null; |
| 362 | ephemeralIntent = null; |
| 363 | resolvedType = null; |
| 364 | activityInfo = null; |
| 365 | resolveInfo = null; |
| 366 | voiceSession = null; |
| 367 | voiceInteractor = null; |
| 368 | resultTo = null; |
| 369 | resultWho = null; |
| 370 | requestCode = 0; |
Bryce Lee | a3cd8e0 | 2018-01-09 15:44:24 -0800 | [diff] [blame] | 371 | callingPid = DEFAULT_CALLING_PID; |
| 372 | callingUid = DEFAULT_CALLING_UID; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 373 | callingPackage = null; |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 374 | realCallingPid = DEFAULT_REAL_CALLING_PID; |
| 375 | realCallingUid = DEFAULT_REAL_CALLING_UID; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 376 | startFlags = 0; |
| 377 | activityOptions = null; |
| 378 | ignoreTargetSecurity = false; |
| 379 | componentSpecified = false; |
| 380 | outActivity = null; |
| 381 | inTask = null; |
| 382 | reason = null; |
| 383 | profilerInfo = null; |
| 384 | globalConfig = null; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 385 | userId = 0; |
| 386 | waitResult = null; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 387 | avoidMoveToFront = false; |
Jorim Jaggi | 6fa41c3 | 2018-04-23 18:35:00 +0200 | [diff] [blame] | 388 | allowPendingRemoteAnimationRegistryLookup = true; |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 389 | filterCallingUid = UserHandle.USER_NULL; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 390 | originatingPendingIntent = null; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 391 | allowBackgroundActivityStart = false; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Adopts all values from passed in request. |
| 396 | */ |
| 397 | void set(Request request) { |
| 398 | caller = request.caller; |
| 399 | intent = request.intent; |
| 400 | ephemeralIntent = request.ephemeralIntent; |
| 401 | resolvedType = request.resolvedType; |
| 402 | activityInfo = request.activityInfo; |
| 403 | resolveInfo = request.resolveInfo; |
| 404 | voiceSession = request.voiceSession; |
| 405 | voiceInteractor = request.voiceInteractor; |
| 406 | resultTo = request.resultTo; |
| 407 | resultWho = request.resultWho; |
| 408 | requestCode = request.requestCode; |
| 409 | callingPid = request.callingPid; |
| 410 | callingUid = request.callingUid; |
| 411 | callingPackage = request.callingPackage; |
| 412 | realCallingPid = request.realCallingPid; |
| 413 | realCallingUid = request.realCallingUid; |
| 414 | startFlags = request.startFlags; |
| 415 | activityOptions = request.activityOptions; |
| 416 | ignoreTargetSecurity = request.ignoreTargetSecurity; |
| 417 | componentSpecified = request.componentSpecified; |
| 418 | outActivity = request.outActivity; |
| 419 | inTask = request.inTask; |
| 420 | reason = request.reason; |
| 421 | profilerInfo = request.profilerInfo; |
| 422 | globalConfig = request.globalConfig; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 423 | userId = request.userId; |
| 424 | waitResult = request.waitResult; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 425 | avoidMoveToFront = request.avoidMoveToFront; |
Jorim Jaggi | 6fa41c3 | 2018-04-23 18:35:00 +0200 | [diff] [blame] | 426 | allowPendingRemoteAnimationRegistryLookup |
| 427 | = request.allowPendingRemoteAnimationRegistryLookup; |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 428 | filterCallingUid = request.filterCallingUid; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 429 | originatingPendingIntent = request.originatingPendingIntent; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 430 | allowBackgroundActivityStart = request.allowBackgroundActivityStart; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 431 | } |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 432 | |
| 433 | /** |
| 434 | * Resolve activity from the given intent for this launch. |
| 435 | */ |
| 436 | void resolveActivity(ActivityStackSupervisor supervisor) { |
| 437 | if (realCallingPid == Request.DEFAULT_REAL_CALLING_PID) { |
| 438 | realCallingPid = Binder.getCallingPid(); |
| 439 | } |
| 440 | if (realCallingUid == Request.DEFAULT_REAL_CALLING_UID) { |
| 441 | realCallingUid = Binder.getCallingUid(); |
| 442 | } |
| 443 | |
| 444 | if (callingUid >= 0) { |
| 445 | callingPid = -1; |
| 446 | } else if (caller == null) { |
| 447 | callingPid = realCallingPid; |
| 448 | callingUid = realCallingUid; |
| 449 | } else { |
| 450 | callingPid = callingUid = -1; |
| 451 | } |
| 452 | |
| 453 | // Save a copy in case ephemeral needs it |
| 454 | ephemeralIntent = new Intent(intent); |
| 455 | // Don't modify the client's object! |
| 456 | intent = new Intent(intent); |
| 457 | if (intent.getComponent() != null |
| 458 | && !(Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() == null) |
| 459 | && !Intent.ACTION_INSTALL_INSTANT_APP_PACKAGE.equals(intent.getAction()) |
| 460 | && !Intent.ACTION_RESOLVE_INSTANT_APP_PACKAGE.equals(intent.getAction()) |
| 461 | && supervisor.mService.getPackageManagerInternalLocked() |
| 462 | .isInstantAppInstallerComponent(intent.getComponent())) { |
| 463 | // Intercept intents targeted directly to the ephemeral installer the ephemeral |
| 464 | // installer should never be started with a raw Intent; instead adjust the intent |
| 465 | // so it looks like a "normal" instant app launch. |
| 466 | intent.setComponent(null /* component */); |
| 467 | } |
| 468 | |
| 469 | resolveInfo = supervisor.resolveIntent(intent, resolvedType, userId, |
| 470 | 0 /* matchFlags */, |
| 471 | computeResolveFilterUid(callingUid, realCallingUid, filterCallingUid)); |
| 472 | if (resolveInfo == null) { |
| 473 | final UserInfo userInfo = supervisor.getUserInfo(userId); |
| 474 | if (userInfo != null && userInfo.isManagedProfile()) { |
| 475 | // Special case for managed profiles, if attempting to launch non-cryto aware |
| 476 | // app in a locked managed profile from an unlocked parent allow it to resolve |
| 477 | // as user will be sent via confirm credentials to unlock the profile. |
| 478 | final UserManager userManager = UserManager.get(supervisor.mService.mContext); |
| 479 | boolean profileLockedAndParentUnlockingOrUnlocked = false; |
| 480 | final long token = Binder.clearCallingIdentity(); |
| 481 | try { |
| 482 | final UserInfo parent = userManager.getProfileParent(userId); |
| 483 | profileLockedAndParentUnlockingOrUnlocked = (parent != null) |
| 484 | && userManager.isUserUnlockingOrUnlocked(parent.id) |
| 485 | && !userManager.isUserUnlockingOrUnlocked(userId); |
| 486 | } finally { |
| 487 | Binder.restoreCallingIdentity(token); |
| 488 | } |
| 489 | if (profileLockedAndParentUnlockingOrUnlocked) { |
| 490 | resolveInfo = supervisor.resolveIntent(intent, resolvedType, userId, |
| 491 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 492 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
| 493 | computeResolveFilterUid(callingUid, realCallingUid, |
| 494 | filterCallingUid)); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | // Collect information about the target of the Intent. |
| 500 | activityInfo = supervisor.resolveActivity(intent, resolveInfo, startFlags, |
| 501 | profilerInfo); |
| 502 | } |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 505 | ActivityStarter(ActivityStartController controller, ActivityTaskManagerService service, |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 506 | ActivityStackSupervisor supervisor, ActivityStartInterceptor interceptor) { |
| 507 | mController = controller; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 508 | mService = service; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 509 | mRootWindowContainer = service.mRootWindowContainer; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 510 | mSupervisor = supervisor; |
| 511 | mInterceptor = interceptor; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 512 | reset(true); |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Effectively duplicates the starter passed in. All state and request values will be |
| 517 | * mirrored. |
| 518 | * @param starter |
| 519 | */ |
| 520 | void set(ActivityStarter starter) { |
| 521 | mStartActivity = starter.mStartActivity; |
| 522 | mIntent = starter.mIntent; |
| 523 | mCallingUid = starter.mCallingUid; |
| 524 | mOptions = starter.mOptions; |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 525 | mRestrictedBgActivity = starter.mRestrictedBgActivity; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 526 | |
| 527 | mLaunchTaskBehind = starter.mLaunchTaskBehind; |
| 528 | mLaunchFlags = starter.mLaunchFlags; |
| 529 | mLaunchMode = starter.mLaunchMode; |
| 530 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 531 | mLaunchParams.set(starter.mLaunchParams); |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 532 | |
| 533 | mNotTop = starter.mNotTop; |
| 534 | mDoResume = starter.mDoResume; |
| 535 | mStartFlags = starter.mStartFlags; |
| 536 | mSourceRecord = starter.mSourceRecord; |
| 537 | mPreferredDisplayId = starter.mPreferredDisplayId; |
| 538 | |
| 539 | mInTask = starter.mInTask; |
| 540 | mAddingToTask = starter.mAddingToTask; |
| 541 | mReuseTask = starter.mReuseTask; |
| 542 | |
| 543 | mNewTaskInfo = starter.mNewTaskInfo; |
| 544 | mNewTaskIntent = starter.mNewTaskIntent; |
| 545 | mSourceStack = starter.mSourceStack; |
| 546 | |
| 547 | mTargetStack = starter.mTargetStack; |
| 548 | mMovedToFront = starter.mMovedToFront; |
| 549 | mNoAnimation = starter.mNoAnimation; |
| 550 | mKeepCurTransition = starter.mKeepCurTransition; |
| 551 | mAvoidMoveToFront = starter.mAvoidMoveToFront; |
Winson Chung | e219ae1 | 2019-07-18 13:43:23 -0700 | [diff] [blame] | 552 | mFrozeTaskList = starter.mFrozeTaskList; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 553 | |
| 554 | mVoiceSession = starter.mVoiceSession; |
| 555 | mVoiceInteractor = starter.mVoiceInteractor; |
| 556 | |
| 557 | mIntentDelivered = starter.mIntentDelivered; |
| 558 | |
| 559 | mRequest.set(starter.mRequest); |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 562 | boolean relatedToPackage(String packageName) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 563 | return (mLastStartActivityRecord != null |
| 564 | && packageName.equals(mLastStartActivityRecord.packageName)) |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 565 | || (mStartActivity != null && packageName.equals(mStartActivity.packageName)); |
| 566 | } |
| 567 | |
| 568 | /** |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 569 | * Starts an activity based on the provided {@link ActivityRecord} and environment parameters. |
| 570 | * Note that this method is called internally as well as part of {@link #executeRequest}. |
| 571 | */ |
| 572 | void startResolvedActivity(final ActivityRecord r, ActivityRecord sourceRecord, |
| 573 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 574 | int startFlags, boolean doResume, ActivityOptions options, Task inTask) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 575 | try { |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 576 | final LaunchingState launchingState = mSupervisor.getActivityMetricsLogger() |
| 577 | .notifyActivityLaunching(r.intent, r.resultTo); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 578 | mLastStartReason = "startResolvedActivity"; |
| 579 | mLastStartActivityTimeMs = System.currentTimeMillis(); |
| 580 | mLastStartActivityRecord = r; |
| 581 | mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession, |
| 582 | voiceInteractor, startFlags, doResume, options, inTask, |
| 583 | false /* restrictedBgActivity */); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 584 | mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(launchingState, |
| 585 | mLastStartActivityResult, mLastStartActivityRecord); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 586 | } finally { |
| 587 | onExecutionComplete(); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * Resolve necessary information according the request parameters provided earlier, and execute |
| 593 | * the request which begin the journey of starting an activity. |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 594 | * @return The starter result. |
| 595 | */ |
| 596 | int execute() { |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 597 | try { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 598 | // Refuse possible leaked file descriptors |
| 599 | if (mRequest.intent != null && mRequest.intent.hasFileDescriptors()) { |
| 600 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 601 | } |
| 602 | |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 603 | final LaunchingState launchingState; |
| 604 | synchronized (mService.mGlobalLock) { |
| 605 | final ActivityRecord caller = ActivityRecord.forTokenLocked(mRequest.resultTo); |
| 606 | launchingState = mSupervisor.getActivityMetricsLogger().notifyActivityLaunching( |
| 607 | mRequest.intent, caller); |
| 608 | } |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 609 | |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 610 | // Do not lock the resolving to avoid potential deadlock. |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 611 | if (mRequest.activityInfo == null) { |
| 612 | mRequest.resolveActivity(mSupervisor); |
| 613 | } |
| 614 | |
| 615 | int res; |
| 616 | synchronized (mService.mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 617 | final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 618 | stack.mConfigWillChange = mRequest.globalConfig != null |
| 619 | && mService.getGlobalConfiguration().diff(mRequest.globalConfig) != 0; |
| 620 | if (DEBUG_CONFIGURATION) { |
| 621 | Slog.v(TAG_CONFIGURATION, "Starting activity when config will change = " |
| 622 | + stack.mConfigWillChange); |
| 623 | } |
| 624 | |
| 625 | final long origId = Binder.clearCallingIdentity(); |
| 626 | |
| 627 | res = resolveToHeavyWeightSwitcherIfNeeded(); |
| 628 | if (res != START_SUCCESS) { |
| 629 | return res; |
| 630 | } |
| 631 | res = executeRequest(mRequest); |
| 632 | |
| 633 | Binder.restoreCallingIdentity(origId); |
| 634 | |
| 635 | if (stack.mConfigWillChange) { |
| 636 | // If the caller also wants to switch to a new configuration, do so now. |
| 637 | // This allows a clean switch, as we are waiting for the current activity |
| 638 | // to pause (so we will not destroy it), and have not yet started the |
| 639 | // next activity. |
| 640 | mService.mAmInternal.enforceCallingPermission( |
| 641 | android.Manifest.permission.CHANGE_CONFIGURATION, |
| 642 | "updateConfiguration()"); |
| 643 | stack.mConfigWillChange = false; |
| 644 | if (DEBUG_CONFIGURATION) { |
| 645 | Slog.v(TAG_CONFIGURATION, |
| 646 | "Updating to new configuration after starting activity."); |
| 647 | } |
| 648 | mService.updateConfigurationLocked(mRequest.globalConfig, null, false); |
| 649 | } |
| 650 | |
| 651 | // Notify ActivityMetricsLogger that the activity has launched. |
| 652 | // ActivityMetricsLogger will then wait for the windows to be drawn and populate |
| 653 | // WaitResult. |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 654 | mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(launchingState, res, |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 655 | mLastStartActivityRecord); |
| 656 | return getExternalResult(mRequest.waitResult == null ? res |
| 657 | : waitForResult(res, mLastStartActivityRecord)); |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 658 | } |
| 659 | } finally { |
| 660 | onExecutionComplete(); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /** |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 665 | * Updates the request to heavy-weight switch if this is a heavy-weight process while there |
| 666 | * already have another, different heavy-weight process running. |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 667 | */ |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 668 | private int resolveToHeavyWeightSwitcherIfNeeded() { |
| 669 | if (mRequest.activityInfo == null || !mService.mHasHeavyWeightFeature |
| 670 | || (mRequest.activityInfo.applicationInfo.privateFlags |
| 671 | & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) == 0) { |
| 672 | return START_SUCCESS; |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 673 | } |
Bryce Lee | f9d4954 | 2017-06-26 16:27:32 -0700 | [diff] [blame] | 674 | |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 675 | if (!mRequest.activityInfo.processName.equals( |
| 676 | mRequest.activityInfo.applicationInfo.packageName)) { |
| 677 | return START_SUCCESS; |
| 678 | } |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 679 | |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 680 | final WindowProcessController heavy = mService.mHeavyWeightProcess; |
| 681 | if (heavy == null || (heavy.mInfo.uid == mRequest.activityInfo.applicationInfo.uid |
| 682 | && heavy.mName.equals(mRequest.activityInfo.processName))) { |
| 683 | return START_SUCCESS; |
| 684 | } |
| 685 | |
| 686 | int appCallingUid = mRequest.callingUid; |
| 687 | if (mRequest.caller != null) { |
| 688 | WindowProcessController callerApp = mService.getProcessController(mRequest.caller); |
| 689 | if (callerApp != null) { |
| 690 | appCallingUid = callerApp.mInfo.uid; |
| 691 | } else { |
| 692 | Slog.w(TAG, "Unable to find app for caller " + mRequest.caller + " (pid=" |
| 693 | + mRequest.callingPid + ") when starting: " + mRequest.intent.toString()); |
| 694 | SafeActivityOptions.abort(mRequest.activityOptions); |
| 695 | return ActivityManager.START_PERMISSION_DENIED; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | final IIntentSender target = mService.getIntentSenderLocked( |
| 700 | ActivityManager.INTENT_SENDER_ACTIVITY, "android" /* packageName */, appCallingUid, |
| 701 | mRequest.userId, null /* token */, null /* resultWho*/, 0 /* requestCode*/, |
| 702 | new Intent[] { mRequest.intent }, new String[] { mRequest.resolvedType }, |
| 703 | PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT, |
| 704 | null /* bOptions */); |
| 705 | |
| 706 | final Intent newIntent = new Intent(); |
| 707 | if (mRequest.requestCode >= 0) { |
| 708 | // Caller is requesting a result. |
| 709 | newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_HAS_RESULT, true); |
| 710 | } |
| 711 | newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_INTENT, new IntentSender(target)); |
| 712 | heavy.updateIntentForHeavyWeightActivity(newIntent); |
| 713 | newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_NEW_APP, |
| 714 | mRequest.activityInfo.packageName); |
| 715 | newIntent.setFlags(mRequest.intent.getFlags()); |
| 716 | newIntent.setClassName("android" /* packageName */, |
| 717 | HeavyWeightSwitcherActivity.class.getName()); |
| 718 | mRequest.intent = newIntent; |
| 719 | mRequest.resolvedType = null; |
| 720 | mRequest.caller = null; |
| 721 | mRequest.callingUid = Binder.getCallingUid(); |
| 722 | mRequest.callingPid = Binder.getCallingPid(); |
| 723 | mRequest.componentSpecified = true; |
| 724 | mRequest.resolveInfo = mSupervisor.resolveIntent(mRequest.intent, null /* resolvedType */, |
| 725 | mRequest.userId, 0 /* matchFlags */, |
| 726 | computeResolveFilterUid(mRequest.callingUid, mRequest.realCallingUid, |
| 727 | mRequest.filterCallingUid)); |
| 728 | mRequest.activityInfo = |
| 729 | mRequest.resolveInfo != null ? mRequest.resolveInfo.activityInfo : null; |
| 730 | if (mRequest.activityInfo != null) { |
| 731 | mRequest.activityInfo = mService.mAmInternal.getActivityInfoForUser( |
| 732 | mRequest.activityInfo, mRequest.userId); |
| 733 | } |
| 734 | |
| 735 | return START_SUCCESS; |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 738 | /** |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 739 | * Wait for activity launch completes. |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 740 | */ |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 741 | private int waitForResult(int res, ActivityRecord r) { |
| 742 | mRequest.waitResult.result = res; |
| 743 | switch(res) { |
| 744 | case START_SUCCESS: { |
| 745 | mSupervisor.mWaitingActivityLaunched.add(mRequest.waitResult); |
| 746 | do { |
| 747 | try { |
| 748 | mService.mGlobalLock.wait(); |
| 749 | } catch (InterruptedException e) { |
| 750 | } |
| 751 | } while (mRequest.waitResult.result != START_TASK_TO_FRONT |
| 752 | && !mRequest.waitResult.timeout && mRequest.waitResult.who == null); |
| 753 | if (mRequest.waitResult.result == START_TASK_TO_FRONT) { |
| 754 | res = START_TASK_TO_FRONT; |
| 755 | } |
| 756 | break; |
| 757 | } |
| 758 | case START_DELIVERED_TO_TOP: { |
| 759 | mRequest.waitResult.timeout = false; |
| 760 | mRequest.waitResult.who = r.mActivityComponent; |
| 761 | mRequest.waitResult.totalTime = 0; |
| 762 | break; |
| 763 | } |
| 764 | case START_TASK_TO_FRONT: { |
| 765 | mRequest.waitResult.launchState = |
| 766 | r.attachedToProcess() ? LAUNCH_STATE_HOT : LAUNCH_STATE_COLD; |
| 767 | // ActivityRecord may represent a different activity, but it should not be |
| 768 | // in the resumed state. |
| 769 | if (r.nowVisible && r.isState(RESUMED)) { |
| 770 | mRequest.waitResult.timeout = false; |
| 771 | mRequest.waitResult.who = r.mActivityComponent; |
| 772 | mRequest.waitResult.totalTime = 0; |
| 773 | } else { |
Riddle Hsu | c48c891 | 2019-10-31 13:34:27 +0800 | [diff] [blame] | 774 | mSupervisor.waitActivityVisible(r.mActivityComponent, mRequest.waitResult); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 775 | // Note: the timeout variable is not currently not ever set. |
| 776 | do { |
| 777 | try { |
| 778 | mService.mGlobalLock.wait(); |
| 779 | } catch (InterruptedException e) { |
| 780 | } |
| 781 | } while (!mRequest.waitResult.timeout && mRequest.waitResult.who == null); |
| 782 | } |
| 783 | break; |
| 784 | } |
| 785 | } |
| 786 | return res; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 787 | } |
| 788 | |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 789 | /** |
| 790 | * Executing activity start request and starts the journey of starting an activity. Here |
| 791 | * begins with performing several preliminary checks. The normally activity launch flow will |
| 792 | * go through {@link #startActivityUnchecked} to {@link #startActivityInner}. |
| 793 | */ |
| 794 | private int executeRequest(Request request) { |
| 795 | if (TextUtils.isEmpty(request.reason)) { |
| 796 | throw new IllegalArgumentException("Need to specify a reason."); |
| 797 | } |
| 798 | mLastStartReason = request.reason; |
| 799 | mLastStartActivityTimeMs = System.currentTimeMillis(); |
| 800 | mLastStartActivityRecord = null; |
| 801 | |
| 802 | final IApplicationThread caller = request.caller; |
| 803 | Intent intent = request.intent; |
| 804 | String resolvedType = request.resolvedType; |
| 805 | ActivityInfo aInfo = request.activityInfo; |
| 806 | ResolveInfo rInfo = request.resolveInfo; |
| 807 | final IVoiceInteractionSession voiceSession = request.voiceSession; |
| 808 | final IBinder resultTo = request.resultTo; |
| 809 | String resultWho = request.resultWho; |
| 810 | int requestCode = request.requestCode; |
| 811 | int callingPid = request.callingPid; |
| 812 | int callingUid = request.callingUid; |
| 813 | String callingPackage = request.callingPackage; |
| 814 | final int realCallingPid = request.realCallingPid; |
| 815 | final int realCallingUid = request.realCallingUid; |
| 816 | final int startFlags = request.startFlags; |
| 817 | final SafeActivityOptions options = request.activityOptions; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 818 | Task inTask = request.inTask; |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 819 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 820 | int err = ActivityManager.START_SUCCESS; |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 821 | // Pull the optional Ephemeral Installer-only bundle out of the options early. |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 822 | final Bundle verificationBundle = |
| 823 | options != null ? options.popAppVerificationBundle() : null; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 824 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 825 | WindowProcessController callerApp = null; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 826 | if (caller != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 827 | callerApp = mService.getProcessController(caller); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 828 | if (callerApp != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 829 | callingPid = callerApp.getPid(); |
| 830 | callingUid = callerApp.mInfo.uid; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 831 | } else { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 832 | Slog.w(TAG, "Unable to find app for caller " + caller + " (pid=" + callingPid |
| 833 | + ") when starting: " + intent.toString()); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 834 | err = ActivityManager.START_PERMISSION_DENIED; |
| 835 | } |
| 836 | } |
| 837 | |
Bryce Lee | 93e7f79 | 2017-10-25 15:54:55 -0700 | [diff] [blame] | 838 | final int userId = aInfo != null && aInfo.applicationInfo != null |
| 839 | ? UserHandle.getUserId(aInfo.applicationInfo.uid) : 0; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 840 | if (err == ActivityManager.START_SUCCESS) { |
| 841 | Slog.i(TAG, "START u" + userId + " {" + intent.toShortString(true, true, true, false) |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 842 | + "} from uid " + callingUid); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | ActivityRecord sourceRecord = null; |
| 846 | ActivityRecord resultRecord = null; |
| 847 | if (resultTo != null) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 848 | sourceRecord = mRootWindowContainer.isInAnyStack(resultTo); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 849 | if (DEBUG_RESULTS) { |
| 850 | Slog.v(TAG_RESULTS, "Will send result to " + resultTo + " " + sourceRecord); |
| 851 | } |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 852 | if (sourceRecord != null) { |
| 853 | if (requestCode >= 0 && !sourceRecord.finishing) { |
| 854 | resultRecord = sourceRecord; |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | final int launchFlags = intent.getFlags(); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 860 | if ((launchFlags & Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0 && sourceRecord != null) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 861 | // Transfer the result target from the source activity to the new one being started, |
| 862 | // including any failures. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 863 | if (requestCode >= 0) { |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 864 | SafeActivityOptions.abort(options); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 865 | return ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT; |
| 866 | } |
| 867 | resultRecord = sourceRecord.resultTo; |
| 868 | if (resultRecord != null && !resultRecord.isInStackLocked()) { |
| 869 | resultRecord = null; |
| 870 | } |
| 871 | resultWho = sourceRecord.resultWho; |
| 872 | requestCode = sourceRecord.requestCode; |
| 873 | sourceRecord.resultTo = null; |
| 874 | if (resultRecord != null) { |
| 875 | resultRecord.removeResultsLocked(sourceRecord, resultWho, requestCode); |
| 876 | } |
| 877 | if (sourceRecord.launchedFromUid == callingUid) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 878 | // The new activity is being launched from the same uid as the previous activity |
| 879 | // in the flow, and asking to forward its result back to the previous. In this |
| 880 | // case the activity is serving as a trampoline between the two, so we also want |
| 881 | // to update its launchedFromPackage to be the same as the previous activity. |
| 882 | // Note that this is safe, since we know these two packages come from the same |
| 883 | // uid; the caller could just as well have supplied that same package name itself |
| 884 | // . This specifially deals with the case of an intent picker/chooser being |
| 885 | // launched in the app flow to redirect to an activity picked by the user, where |
| 886 | // we want the final activity to consider it to have been launched by the |
| 887 | // previous app activity. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 888 | callingPackage = sourceRecord.launchedFromPackage; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) { |
| 893 | // We couldn't find a class that can handle the given Intent. |
| 894 | // That's the end of that! |
| 895 | err = ActivityManager.START_INTENT_NOT_RESOLVED; |
| 896 | } |
| 897 | |
| 898 | if (err == ActivityManager.START_SUCCESS && aInfo == null) { |
| 899 | // We couldn't find the specific class specified in the Intent. |
| 900 | // Also the end of the line. |
| 901 | err = ActivityManager.START_CLASS_NOT_FOUND; |
| 902 | } |
| 903 | |
| 904 | if (err == ActivityManager.START_SUCCESS && sourceRecord != null |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 905 | && sourceRecord.getTask().voiceSession != null) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 906 | // If this activity is being launched as part of a voice session, we need to ensure |
| 907 | // that it is safe to do so. If the upcoming activity will also be part of the voice |
| 908 | // session, we can only launch it if it has explicitly said it supports the VOICE |
| 909 | // category, or it is a part of the calling app. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 910 | if ((launchFlags & FLAG_ACTIVITY_NEW_TASK) == 0 |
| 911 | && sourceRecord.info.applicationInfo.uid != aInfo.applicationInfo.uid) { |
| 912 | try { |
| 913 | intent.addCategory(Intent.CATEGORY_VOICE); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 914 | if (!mService.getPackageManager().activitySupportsIntent( |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 915 | intent.getComponent(), intent, resolvedType)) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 916 | Slog.w(TAG, "Activity being started in current voice task does not support " |
| 917 | + "voice: " + intent); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 918 | err = ActivityManager.START_NOT_VOICE_COMPATIBLE; |
| 919 | } |
| 920 | } catch (RemoteException e) { |
| 921 | Slog.w(TAG, "Failure checking voice capabilities", e); |
| 922 | err = ActivityManager.START_NOT_VOICE_COMPATIBLE; |
| 923 | } |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | if (err == ActivityManager.START_SUCCESS && voiceSession != null) { |
| 928 | // If the caller is starting a new voice session, just make sure the target |
| 929 | // is actually allowing it to run this way. |
| 930 | try { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 931 | if (!mService.getPackageManager().activitySupportsIntent(intent.getComponent(), |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 932 | intent, resolvedType)) { |
| 933 | Slog.w(TAG, |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 934 | "Activity being started in new voice task does not support: " + intent); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 935 | err = ActivityManager.START_NOT_VOICE_COMPATIBLE; |
| 936 | } |
| 937 | } catch (RemoteException e) { |
| 938 | Slog.w(TAG, "Failure checking voice capabilities", e); |
| 939 | err = ActivityManager.START_NOT_VOICE_COMPATIBLE; |
| 940 | } |
| 941 | } |
| 942 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 943 | final ActivityStack resultStack = resultRecord == null |
| 944 | ? null : resultRecord.getActivityStack(); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 945 | |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 946 | if (err != START_SUCCESS) { |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 947 | if (resultRecord != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 948 | resultRecord.sendResult(INVALID_UID, resultWho, requestCode, RESULT_CANCELED, |
| 949 | null /* data */); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 950 | } |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 951 | SafeActivityOptions.abort(options); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 952 | return err; |
| 953 | } |
| 954 | |
| 955 | boolean abort = !mSupervisor.checkStartAnyActivityPermission(intent, aInfo, resultWho, |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 956 | requestCode, callingPid, callingUid, callingPackage, request.ignoreTargetSecurity, |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 957 | inTask != null, callerApp, resultRecord, resultStack); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 958 | abort |= !mService.mIntentFirewall.checkStartActivity(intent, callingUid, |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 959 | callingPid, resolvedType, aInfo.applicationInfo); |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 960 | abort |= !mService.getPermissionPolicyInternal().checkStartActivity(intent, callingUid, |
| 961 | callingPackage); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 962 | |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 963 | boolean restrictedBgActivity = false; |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 964 | if (!abort) { |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 965 | try { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 966 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 967 | "shouldAbortBackgroundActivityStart"); |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 968 | restrictedBgActivity = shouldAbortBackgroundActivityStart(callingUid, |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 969 | callingPid, callingPackage, realCallingUid, realCallingPid, callerApp, |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 970 | request.originatingPendingIntent, request.allowBackgroundActivityStart, |
| 971 | intent); |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 972 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 973 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 974 | } |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 977 | // Merge the two options bundles, while realCallerOptions takes precedence. |
| 978 | ActivityOptions checkedOptions = options != null |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 979 | ? options.getOptions(intent, aInfo, callerApp, mSupervisor) : null; |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 980 | if (request.allowPendingRemoteAnimationRegistryLookup) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 981 | checkedOptions = mService.getActivityStartController() |
Jorim Jaggi | 6fa41c3 | 2018-04-23 18:35:00 +0200 | [diff] [blame] | 982 | .getPendingRemoteAnimationRegistry() |
| 983 | .overrideOptionsIfNeeded(callingPackage, checkedOptions); |
| 984 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 985 | if (mService.mController != null) { |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 986 | try { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 987 | // The Intent we give to the watcher has the extra data stripped off, since it |
| 988 | // can contain private information. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 989 | Intent watchIntent = intent.cloneFilter(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 990 | abort |= !mService.mController.activityStarting(watchIntent, |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 991 | aInfo.applicationInfo.packageName); |
| 992 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 993 | mService.mController = null; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 997 | mInterceptor.setStates(userId, realCallingPid, realCallingUid, startFlags, callingPackage); |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 998 | if (mInterceptor.intercept(intent, rInfo, aInfo, resolvedType, inTask, callingPid, |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 999 | callingUid, checkedOptions)) { |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 1000 | // activity start was intercepted, e.g. because the target user is currently in quiet |
| 1001 | // mode (turn off work) or the target application is suspended |
| 1002 | intent = mInterceptor.mIntent; |
| 1003 | rInfo = mInterceptor.mRInfo; |
| 1004 | aInfo = mInterceptor.mAInfo; |
| 1005 | resolvedType = mInterceptor.mResolvedType; |
| 1006 | inTask = mInterceptor.mInTask; |
| 1007 | callingPid = mInterceptor.mCallingPid; |
| 1008 | callingUid = mInterceptor.mCallingUid; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1009 | checkedOptions = mInterceptor.mActivityOptions; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1012 | if (abort) { |
| 1013 | if (resultRecord != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1014 | resultRecord.sendResult(INVALID_UID, resultWho, requestCode, RESULT_CANCELED, |
| 1015 | null /* data */); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1016 | } |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1017 | // We pretend to the caller that it was really started, but they will just get a |
| 1018 | // cancel result. |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1019 | ActivityOptions.abort(checkedOptions); |
Bryce Lee | f9d4954 | 2017-06-26 16:27:32 -0700 | [diff] [blame] | 1020 | return START_ABORTED; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | // If permissions need a review before any of the app components can run, we |
| 1024 | // launch the review activity and pass a pending intent to start the activity |
| 1025 | // we are to launching now after the review is completed. |
Philip P. Moltmann | 6c644e6 | 2018-07-18 15:41:24 -0700 | [diff] [blame] | 1026 | if (aInfo != null) { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1027 | if (mService.getPackageManagerInternalLocked().isPermissionsReviewRequired( |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1028 | aInfo.packageName, userId)) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1029 | final IIntentSender target = mService.getIntentSenderLocked( |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1030 | ActivityManager.INTENT_SENDER_ACTIVITY, callingPackage, |
| 1031 | callingUid, userId, null, null, 0, new Intent[]{intent}, |
| 1032 | new String[]{resolvedType}, PendingIntent.FLAG_CANCEL_CURRENT |
| 1033 | | PendingIntent.FLAG_ONE_SHOT, null); |
| 1034 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1035 | Intent newIntent = new Intent(Intent.ACTION_REVIEW_PERMISSIONS); |
Philip P. Moltmann | c3e66d0 | 2019-01-31 15:56:18 -0800 | [diff] [blame] | 1036 | |
| 1037 | int flags = intent.getFlags(); |
| 1038 | flags |= Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
| 1039 | |
| 1040 | /* |
| 1041 | * Prevent reuse of review activity: Each app needs their own review activity. By |
| 1042 | * default activities launched with NEW_TASK or NEW_DOCUMENT try to reuse activities |
| 1043 | * with the same launch parameters (extras are ignored). Hence to avoid possible |
| 1044 | * reuse force a new activity via the MULTIPLE_TASK flag. |
| 1045 | * |
| 1046 | * Activities that are not launched with NEW_TASK or NEW_DOCUMENT are not re-used, |
| 1047 | * hence no need to add the flag in this case. |
| 1048 | */ |
| 1049 | if ((flags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NEW_DOCUMENT)) != 0) { |
| 1050 | flags |= Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
| 1051 | } |
| 1052 | newIntent.setFlags(flags); |
| 1053 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1054 | newIntent.putExtra(Intent.EXTRA_PACKAGE_NAME, aInfo.packageName); |
| 1055 | newIntent.putExtra(Intent.EXTRA_INTENT, new IntentSender(target)); |
| 1056 | if (resultRecord != null) { |
| 1057 | newIntent.putExtra(Intent.EXTRA_RESULT_NEEDED, true); |
| 1058 | } |
| 1059 | intent = newIntent; |
| 1060 | |
| 1061 | resolvedType = null; |
| 1062 | callingUid = realCallingUid; |
| 1063 | callingPid = realCallingPid; |
| 1064 | |
Svet Ganov | cbcbf66 | 2018-05-10 17:25:29 -0700 | [diff] [blame] | 1065 | rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId, 0, |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 1066 | computeResolveFilterUid( |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1067 | callingUid, realCallingUid, request.filterCallingUid)); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1068 | aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, |
| 1069 | null /*profilerInfo*/); |
| 1070 | |
| 1071 | if (DEBUG_PERMISSIONS_REVIEW) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1072 | final ActivityStack focusedStack = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1073 | mRootWindowContainer.getTopDisplayFocusedStack(); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1074 | Slog.i(TAG, "START u" + userId + " {" + intent.toShortString(true, true, |
| 1075 | true, false) + "} from uid " + callingUid + " on display " |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 1076 | + (focusedStack == null ? DEFAULT_DISPLAY |
| 1077 | : focusedStack.getDisplayId())); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | // If we have an ephemeral app, abort the process of launching the resolved intent. |
| 1083 | // Instead, launch the ephemeral installer. Once the installer is finished, it |
| 1084 | // starts either the intent we resolved here [on install error] or the ephemeral |
| 1085 | // app [on install success]. |
Patrick Baumann | a89a172 | 2018-02-07 15:26:52 -0800 | [diff] [blame] | 1086 | if (rInfo != null && rInfo.auxiliaryInfo != null) { |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1087 | intent = createLaunchIntent(rInfo.auxiliaryInfo, request.ephemeralIntent, |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 1088 | callingPackage, verificationBundle, resolvedType, userId); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1089 | resolvedType = null; |
| 1090 | callingUid = realCallingUid; |
| 1091 | callingPid = realCallingPid; |
| 1092 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1093 | aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, null /*profilerInfo*/); |
| 1094 | } |
| 1095 | |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1096 | final ActivityRecord r = new ActivityRecord(mService, callerApp, callingPid, callingUid, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1097 | callingPackage, intent, resolvedType, aInfo, mService.getGlobalConfiguration(), |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1098 | resultRecord, resultWho, requestCode, request.componentSpecified, |
| 1099 | voiceSession != null, mSupervisor, checkedOptions, sourceRecord); |
| 1100 | mLastStartActivityRecord = r; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1101 | |
| 1102 | if (r.appTimeTracker == null && sourceRecord != null) { |
| 1103 | // If the caller didn't specify an explicit time tracker, we want to continue |
| 1104 | // tracking under any it has. |
| 1105 | r.appTimeTracker = sourceRecord.appTimeTracker; |
| 1106 | } |
| 1107 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1108 | final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1109 | |
| 1110 | // If we are starting an activity that is not from the same uid as the currently resumed |
| 1111 | // one, check whether app switches are allowed. |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1112 | if (voiceSession == null && (stack.getResumedActivity() == null |
| 1113 | || stack.getResumedActivity().info.applicationInfo.uid != realCallingUid)) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1114 | if (!mService.checkAppSwitchAllowedLocked(callingPid, callingUid, |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1115 | realCallingPid, realCallingUid, "Activity start")) { |
Alan Stokes | 07389b6 | 2019-05-20 15:22:54 +0100 | [diff] [blame] | 1116 | if (!(restrictedBgActivity && handleBackgroundActivityAbort(r))) { |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1117 | mController.addPendingActivityLaunch(new PendingActivityLaunch(r, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 1118 | sourceRecord, startFlags, stack, callerApp)); |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1119 | } |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1120 | ActivityOptions.abort(checkedOptions); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1121 | return ActivityManager.START_SWITCHES_CANCELED; |
| 1122 | } |
| 1123 | } |
| 1124 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1125 | mService.onStartActivitySetDidAppSwitch(); |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1126 | mController.doPendingActivityLaunches(false); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1127 | |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1128 | mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession, |
| 1129 | request.voiceInteractor, startFlags, true /* doResume */, checkedOptions, inTask, |
| 1130 | restrictedBgActivity); |
| 1131 | |
| 1132 | if (request.outActivity != null) { |
| 1133 | request.outActivity[0] = mLastStartActivityRecord; |
| 1134 | } |
| 1135 | |
Riddle Hsu | 7f8643a | 2019-12-05 14:37:30 +0800 | [diff] [blame] | 1136 | return mLastStartActivityResult; |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * Return true if background activity is really aborted. |
| 1141 | * |
| 1142 | * TODO(b/131748165): Refactor the logic so we don't need to call this method everywhere. |
| 1143 | */ |
| 1144 | private boolean handleBackgroundActivityAbort(ActivityRecord r) { |
| 1145 | // TODO(b/131747138): Remove toast and refactor related code in R release. |
| 1146 | final boolean abort = !mService.isBackgroundActivityStartsEnabled(); |
| 1147 | if (!abort) { |
| 1148 | return false; |
| 1149 | } |
| 1150 | final ActivityRecord resultRecord = r.resultTo; |
| 1151 | final String resultWho = r.resultWho; |
| 1152 | int requestCode = r.requestCode; |
| 1153 | if (resultRecord != null) { |
| 1154 | resultRecord.sendResult(INVALID_UID, resultWho, requestCode, RESULT_CANCELED, |
| 1155 | null /* data */); |
| 1156 | } |
| 1157 | // We pretend to the caller that it was really started to make it backward compatible, but |
| 1158 | // they will just get a cancel result. |
| 1159 | ActivityOptions.abort(r.pendingOptions); |
| 1160 | return true; |
| 1161 | } |
| 1162 | |
| 1163 | static int getExternalResult(int result) { |
| 1164 | // Aborted results are treated as successes externally, but we must track them internally. |
| 1165 | return result != START_ABORTED ? result : START_SUCCESS; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Called when execution is complete. Sets state indicating completion and proceeds with |
| 1170 | * recycling if appropriate. |
| 1171 | */ |
| 1172 | private void onExecutionComplete() { |
| 1173 | mController.onExecutionComplete(this); |
Wale Ogunwale | cc25a8a | 2016-01-23 14:31:37 -0800 | [diff] [blame] | 1174 | } |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1175 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 1176 | boolean shouldAbortBackgroundActivityStart(int callingUid, int callingPid, |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 1177 | final String callingPackage, int realCallingUid, int realCallingPid, |
| 1178 | WindowProcessController callerApp, PendingIntentRecord originatingPendingIntent, |
| 1179 | boolean allowBackgroundActivityStart, Intent intent) { |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 1180 | // don't abort for the most important UIDs |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1181 | final int callingAppId = UserHandle.getAppId(callingUid); |
| 1182 | if (callingUid == Process.ROOT_UID || callingAppId == Process.SYSTEM_UID |
| 1183 | || callingAppId == Process.NFC_UID) { |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 1184 | return false; |
| 1185 | } |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 1186 | // don't abort if the callingUid has a visible window or is a persistent system process |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 1187 | final int callingUidProcState = mService.getUidState(callingUid); |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 1188 | final boolean callingUidHasAnyVisibleWindow = |
| 1189 | mService.mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(callingUid); |
| 1190 | final boolean isCallingUidForeground = callingUidHasAnyVisibleWindow |
Amith Yamasani | f235d0b | 2019-03-20 22:49:43 -0700 | [diff] [blame] | 1191 | || callingUidProcState == ActivityManager.PROCESS_STATE_TOP |
| 1192 | || callingUidProcState == ActivityManager.PROCESS_STATE_BOUND_TOP; |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1193 | final boolean isCallingUidPersistentSystemProcess = |
| 1194 | callingUidProcState <= ActivityManager.PROCESS_STATE_PERSISTENT_UI; |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 1195 | if (callingUidHasAnyVisibleWindow || isCallingUidPersistentSystemProcess) { |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 1196 | return false; |
| 1197 | } |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1198 | // take realCallingUid into consideration |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 1199 | final int realCallingUidProcState = (callingUid == realCallingUid) |
| 1200 | ? callingUidProcState |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 1201 | : mService.getUidState(realCallingUid); |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 1202 | final boolean realCallingUidHasAnyVisibleWindow = (callingUid == realCallingUid) |
| 1203 | ? callingUidHasAnyVisibleWindow |
| 1204 | : mService.mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(realCallingUid); |
| 1205 | final boolean isRealCallingUidForeground = (callingUid == realCallingUid) |
| 1206 | ? isCallingUidForeground |
| 1207 | : realCallingUidHasAnyVisibleWindow |
| 1208 | || realCallingUidProcState == ActivityManager.PROCESS_STATE_TOP; |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1209 | final int realCallingAppId = UserHandle.getAppId(realCallingUid); |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 1210 | final boolean isRealCallingUidPersistentSystemProcess = (callingUid == realCallingUid) |
| 1211 | ? isCallingUidPersistentSystemProcess |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1212 | : (realCallingAppId == Process.SYSTEM_UID) |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 1213 | || realCallingUidProcState <= ActivityManager.PROCESS_STATE_PERSISTENT_UI; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1214 | if (realCallingUid != callingUid) { |
Alan Stokes | 6ac9efd | 2019-05-09 12:50:37 +0000 | [diff] [blame] | 1215 | // don't abort if the realCallingUid has a visible window |
| 1216 | if (realCallingUidHasAnyVisibleWindow) { |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1217 | return false; |
| 1218 | } |
| 1219 | // if the realCallingUid is a persistent system process, abort if the IntentSender |
| 1220 | // wasn't whitelisted to start an activity |
Michal Karpinski | d016285 | 2019-01-15 16:05:25 +0000 | [diff] [blame] | 1221 | if (isRealCallingUidPersistentSystemProcess && allowBackgroundActivityStart) { |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1222 | return false; |
| 1223 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 1224 | // don't abort if the realCallingUid is an associated companion app |
| 1225 | if (mService.isAssociatedCompanionApp(UserHandle.getUserId(realCallingUid), |
| 1226 | realCallingUid)) { |
| 1227 | return false; |
| 1228 | } |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 1229 | } |
Michal Karpinski | 7b97a02 | 2018-12-14 15:17:29 +0000 | [diff] [blame] | 1230 | // don't abort if the callingUid has START_ACTIVITIES_FROM_BACKGROUND permission |
| 1231 | if (mService.checkPermission(START_ACTIVITIES_FROM_BACKGROUND, callingPid, callingUid) |
| 1232 | == PERMISSION_GRANTED) { |
| 1233 | return false; |
| 1234 | } |
Michal Karpinski | 82bb590 | 2018-11-28 15:52:52 +0000 | [diff] [blame] | 1235 | // don't abort if the caller has the same uid as the recents component |
| 1236 | if (mSupervisor.mRecentTasks.isCallerRecents(callingUid)) { |
| 1237 | return false; |
| 1238 | } |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 1239 | // don't abort if the callingUid is the device owner |
| 1240 | if (mService.isDeviceOwner(callingUid)) { |
Michal Karpinski | 302dcec | 2019-02-01 11:48:25 +0000 | [diff] [blame] | 1241 | return false; |
| 1242 | } |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 1243 | // don't abort if the callingUid has companion device |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 1244 | final int callingUserId = UserHandle.getUserId(callingUid); |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 1245 | if (mService.isAssociatedCompanionApp(callingUserId, callingUid)) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 1246 | return false; |
| 1247 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 1248 | // If we don't have callerApp at this point, no caller was provided to startActivity(). |
| 1249 | // That's the case for PendingIntent-based starts, since the creator's process might not be |
| 1250 | // up and alive. If that's the case, we retrieve the WindowProcessController for the send() |
| 1251 | // caller, so that we can make the decision based on its foreground/whitelisted state. |
| 1252 | int callerAppUid = callingUid; |
| 1253 | if (callerApp == null) { |
| 1254 | callerApp = mService.getProcessController(realCallingPid, realCallingUid); |
| 1255 | callerAppUid = realCallingUid; |
| 1256 | } |
| 1257 | // don't abort if the callerApp or other processes of that uid are whitelisted in any way |
| 1258 | if (callerApp != null) { |
| 1259 | // first check the original calling process |
| 1260 | if (callerApp.areBackgroundActivityStartsAllowed()) { |
| 1261 | return false; |
| 1262 | } |
| 1263 | // only if that one wasn't whitelisted, check the other ones |
| 1264 | final ArraySet<WindowProcessController> uidProcesses = |
| 1265 | mService.mProcessMap.getProcesses(callerAppUid); |
| 1266 | if (uidProcesses != null) { |
| 1267 | for (int i = uidProcesses.size() - 1; i >= 0; i--) { |
| 1268 | final WindowProcessController proc = uidProcesses.valueAt(i); |
| 1269 | if (proc != callerApp && proc.areBackgroundActivityStartsAllowed()) { |
| 1270 | return false; |
| 1271 | } |
| 1272 | } |
| 1273 | } |
| 1274 | } |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 1275 | // don't abort if the callingUid has SYSTEM_ALERT_WINDOW permission |
| 1276 | if (mService.hasSystemAlertWindowPermission(callingUid, callingPid, callingPackage)) { |
| 1277 | Slog.w(TAG, "Background activity start for " + callingPackage |
| 1278 | + " allowed because SYSTEM_ALERT_WINDOW permission is granted."); |
| 1279 | return false; |
| 1280 | } |
Michal Karpinski | c02364c | 2019-01-22 13:00:04 +0000 | [diff] [blame] | 1281 | // anything that has fallen through would currently be aborted |
| 1282 | Slog.w(TAG, "Background activity start [callingPackage: " + callingPackage |
Michal Karpinski | d016285 | 2019-01-15 16:05:25 +0000 | [diff] [blame] | 1283 | + "; callingUid: " + callingUid |
| 1284 | + "; isCallingUidForeground: " + isCallingUidForeground |
| 1285 | + "; isCallingUidPersistentSystemProcess: " + isCallingUidPersistentSystemProcess |
| 1286 | + "; realCallingUid: " + realCallingUid |
| 1287 | + "; isRealCallingUidForeground: " + isRealCallingUidForeground |
| 1288 | + "; isRealCallingUidPersistentSystemProcess: " |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 1289 | + isRealCallingUidPersistentSystemProcess |
Michal Karpinski | d016285 | 2019-01-15 16:05:25 +0000 | [diff] [blame] | 1290 | + "; originatingPendingIntent: " + originatingPendingIntent |
| 1291 | + "; isBgStartWhitelisted: " + allowBackgroundActivityStart |
| 1292 | + "; intent: " + intent |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 1293 | + "; callerApp: " + callerApp |
Michal Karpinski | d016285 | 2019-01-15 16:05:25 +0000 | [diff] [blame] | 1294 | + "]"); |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 1295 | // log aborted activity start to TRON |
| 1296 | if (mService.isActivityStartsLoggingEnabled()) { |
| 1297 | mSupervisor.getActivityMetricsLogger().logAbortedBgActivityStart(intent, callerApp, |
| 1298 | callingUid, callingPackage, callingUidProcState, callingUidHasAnyVisibleWindow, |
| 1299 | realCallingUid, realCallingUidProcState, realCallingUidHasAnyVisibleWindow, |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 1300 | (originatingPendingIntent != null)); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 1301 | } |
Michal Karpinski | 4fd5b84 | 2019-01-28 15:13:32 +0000 | [diff] [blame] | 1302 | return true; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 1303 | } |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1304 | |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1305 | /** |
| 1306 | * Creates a launch intent for the given auxiliary resolution data. |
| 1307 | */ |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1308 | private @NonNull Intent createLaunchIntent(@Nullable AuxiliaryResolveInfo auxiliaryResponse, |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 1309 | Intent originalIntent, String callingPackage, Bundle verificationBundle, |
| 1310 | String resolvedType, int userId) { |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1311 | if (auxiliaryResponse != null && auxiliaryResponse.needsPhaseTwo) { |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 1312 | // request phase two resolution |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 1313 | PackageManagerInternal packageManager = mService.getPackageManagerInternalLocked(); |
| 1314 | boolean isRequesterInstantApp = packageManager.isInstantApp(callingPackage, userId); |
| 1315 | packageManager.requestInstantAppResolutionPhaseTwo( |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 1316 | auxiliaryResponse, originalIntent, resolvedType, callingPackage, |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 1317 | isRequesterInstantApp, verificationBundle, userId); |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 1318 | } |
Todd Kennedy | dfc27c6 | 2017-05-17 15:32:10 -0700 | [diff] [blame] | 1319 | return InstantAppResolver.buildEphemeralInstallerIntent( |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1320 | originalIntent, |
| 1321 | InstantAppResolver.sanitizeIntent(originalIntent), |
| 1322 | auxiliaryResponse == null ? null : auxiliaryResponse.failureIntent, |
| 1323 | callingPackage, |
| 1324 | verificationBundle, |
| 1325 | resolvedType, |
| 1326 | userId, |
| 1327 | auxiliaryResponse == null ? null : auxiliaryResponse.installFailureActivity, |
| 1328 | auxiliaryResponse == null ? null : auxiliaryResponse.token, |
| 1329 | auxiliaryResponse != null && auxiliaryResponse.needsPhaseTwo, |
| 1330 | auxiliaryResponse == null ? null : auxiliaryResponse.filters); |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1333 | void postStartActivityProcessing(ActivityRecord r, int result, |
| 1334 | ActivityStack startedActivityStack) { |
Winson Chung | e219ae1 | 2019-07-18 13:43:23 -0700 | [diff] [blame] | 1335 | if (!ActivityManager.isStartResultSuccessful(result)) { |
| 1336 | if (mFrozeTaskList) { |
| 1337 | // If we specifically froze the task list as part of starting an activity, then |
| 1338 | // reset the frozen list state if it failed to start. This is normally otherwise |
| 1339 | // called when the freeze-timeout has elapsed. |
| 1340 | mSupervisor.mRecentTasks.resetFreezeTaskListReorderingOnTimeout(); |
| 1341 | } |
| 1342 | } |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 1343 | if (ActivityManager.isStartResultFatalError(result)) { |
Wale Ogunwale | cc25a8a | 2016-01-23 14:31:37 -0800 | [diff] [blame] | 1344 | return; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1345 | } |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 1346 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1347 | // We're waiting for an activity launch to finish, but that activity simply |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1348 | // brought another activity to front. We must also handle the case where the task is already |
| 1349 | // in the front as a result of the trampoline activity being in the same task (it will be |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1350 | // considered focused as the trampoline will be finished). Let them know about this, so |
| 1351 | // it waits for the new activity to become visible instead, {@link #waitResultIfNeeded}. |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1352 | mSupervisor.reportWaitingActivityLaunchedIfNeeded(r, result); |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1353 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1354 | if (startedActivityStack == null) { |
| 1355 | return; |
| 1356 | } |
| 1357 | |
Wale Ogunwale | ac36e4d | 2017-11-29 13:30:26 -0800 | [diff] [blame] | 1358 | final int clearTaskFlags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK; |
| 1359 | boolean clearedTask = (mLaunchFlags & clearTaskFlags) == clearTaskFlags |
| 1360 | && mReuseTask != null; |
Wale Ogunwale | 7d7973a | 2018-04-05 10:25:59 -0700 | [diff] [blame] | 1361 | if (result == START_TASK_TO_FRONT || result == START_DELIVERED_TO_TOP || clearedTask) { |
| 1362 | // The activity was already running so it wasn't started, but either brought to the |
| 1363 | // front or the new intent was delivered to it since it was already in front. Notify |
| 1364 | // anyone interested in this piece of information. |
| 1365 | switch (startedActivityStack.getWindowingMode()) { |
| 1366 | case WINDOWING_MODE_PINNED: |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1367 | mService.getTaskChangeNotificationController().notifyPinnedActivityRestartAttempt( |
Wale Ogunwale | 7d7973a | 2018-04-05 10:25:59 -0700 | [diff] [blame] | 1368 | clearedTask); |
| 1369 | break; |
| 1370 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1371 | final ActivityStack homeStack = |
| 1372 | startedActivityStack.getDisplay().getHomeStack(); |
Wale Ogunwale | 7d7973a | 2018-04-05 10:25:59 -0700 | [diff] [blame] | 1373 | if (homeStack != null && homeStack.shouldBeVisible(null /* starting */)) { |
| 1374 | mService.mWindowManager.showRecentApps(); |
| 1375 | } |
| 1376 | break; |
| 1377 | } |
Wale Ogunwale | cc25a8a | 2016-01-23 14:31:37 -0800 | [diff] [blame] | 1378 | } |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Svet Ganov | cbcbf66 | 2018-05-10 17:25:29 -0700 | [diff] [blame] | 1381 | /** |
| 1382 | * Compute the logical UID based on which the package manager would filter |
| 1383 | * app components i.e. based on which the instant app policy would be applied |
| 1384 | * because it is the logical calling UID. |
| 1385 | * |
| 1386 | * @param customCallingUid The UID on whose behalf to make the call. |
| 1387 | * @param actualCallingUid The UID actually making the call. |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 1388 | * @param filterCallingUid The UID to be used to filter for instant apps. |
Svet Ganov | cbcbf66 | 2018-05-10 17:25:29 -0700 | [diff] [blame] | 1389 | * @return The logical UID making the call. |
| 1390 | */ |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 1391 | static int computeResolveFilterUid(int customCallingUid, int actualCallingUid, |
| 1392 | int filterCallingUid) { |
| 1393 | return filterCallingUid != UserHandle.USER_NULL |
| 1394 | ? filterCallingUid |
| 1395 | : (customCallingUid >= 0 ? customCallingUid : actualCallingUid); |
Svet Ganov | cbcbf66 | 2018-05-10 17:25:29 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1398 | /** |
| 1399 | * Start an activity while most of preliminary checks has been done and caller has been |
| 1400 | * confirmed that holds necessary permissions to do so. |
| 1401 | * Here also ensures that the starting activity is removed if the start wasn't successful. |
| 1402 | */ |
| 1403 | private int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord, |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 1404 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1405 | int startFlags, boolean doResume, ActivityOptions options, Task inTask, |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1406 | boolean restrictedBgActivity) { |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1407 | int result = START_CANCELED; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1408 | final ActivityStack startedActivityStack; |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1409 | try { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1410 | mService.deferWindowLayout(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1411 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "startActivityInner"); |
| 1412 | result = startActivityInner(r, sourceRecord, voiceSession, voiceInteractor, |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1413 | startFlags, doResume, options, inTask, restrictedBgActivity); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1414 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1415 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 1416 | startedActivityStack = handleStartResult(r, result); |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1417 | mService.continueWindowLayout(); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1418 | } |
| 1419 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1420 | postStartActivityProcessing(r, result, startedActivityStack); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1421 | |
| 1422 | return result; |
| 1423 | } |
| 1424 | |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1425 | /** |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1426 | * If the start result is success, ensure that the configuration of the started activity matches |
| 1427 | * the current display. Otherwise clean up unassociated containers to avoid leakage. |
| 1428 | * |
| 1429 | * @return the stack where the successful started activity resides. |
| 1430 | */ |
| 1431 | private @Nullable ActivityStack handleStartResult(@NonNull ActivityRecord started, int result) { |
| 1432 | final ActivityStack currentStack = started.getActivityStack(); |
| 1433 | ActivityStack startedActivityStack = currentStack != null ? currentStack : mTargetStack; |
| 1434 | |
| 1435 | if (ActivityManager.isStartResultSuccessful(result)) { |
| 1436 | if (startedActivityStack != null) { |
| 1437 | // If there is no state change (e.g. a resumed activity is reparented to top of |
| 1438 | // another display) to trigger a visibility/configuration checking, we have to |
| 1439 | // update the configuration for changing to different display. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1440 | final ActivityRecord currentTop = startedActivityStack.topRunningActivity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1441 | if (currentTop != null && currentTop.shouldUpdateConfigForDisplayChanged()) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1442 | mRootWindowContainer.ensureVisibilityAndConfig( |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1443 | currentTop, currentTop.getDisplayId(), |
| 1444 | true /* markFrozenIfConfigChanged */, false /* deferResume */); |
| 1445 | } |
| 1446 | } |
| 1447 | return startedActivityStack; |
| 1448 | } |
| 1449 | |
| 1450 | // If we are not able to proceed, disassociate the activity from the task. Leaving an |
| 1451 | // activity in an incomplete state can lead to issues, such as performing operations |
| 1452 | // without a window container. |
| 1453 | final ActivityStack stack = mStartActivity.getActivityStack(); |
| 1454 | if (stack != null) { |
| 1455 | mStartActivity.finishIfPossible("startActivity", true /* oomAdj */); |
| 1456 | } |
| 1457 | |
| 1458 | // Stack should also be detached from display and be removed if it's empty. |
| 1459 | if (startedActivityStack != null && startedActivityStack.isAttached() |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1460 | && !startedActivityStack.hasActivity() |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1461 | && !startedActivityStack.isActivityTypeHome()) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 1462 | startedActivityStack.removeIfPossible(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1463 | startedActivityStack = null; |
| 1464 | } |
| 1465 | return startedActivityStack; |
| 1466 | } |
| 1467 | |
| 1468 | /** |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1469 | * Start an activity and determine if the activity should be adding to the top of an existing |
| 1470 | * task or delivered new intent to an existing activity. Also manipulating the activity task |
| 1471 | * onto requested or valid stack/display. |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1472 | * |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1473 | * Note: This method should only be called from {@link #startActivityUnchecked}. |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1474 | */ |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1475 | private int startActivityInner(final ActivityRecord r, ActivityRecord sourceRecord, |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1476 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1477 | int startFlags, boolean doResume, ActivityOptions options, Task inTask, |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1478 | boolean restrictedBgActivity) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1479 | setInitialState(r, options, inTask, doResume, startFlags, sourceRecord, voiceSession, |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1480 | voiceInteractor, restrictedBgActivity); |
| 1481 | |
Louis Chang | 39ba54b | 2018-10-18 11:28:57 +0800 | [diff] [blame] | 1482 | final int preferredWindowingMode = mLaunchParams.mWindowingMode; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1483 | |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1484 | computeLaunchingTaskFlags(); |
| 1485 | |
| 1486 | computeSourceStack(); |
| 1487 | |
| 1488 | mIntent.setFlags(mLaunchFlags); |
| 1489 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1490 | final Task reusedTask = getReusableTask(); |
Louis Chang | f7dd7f2 | 2019-11-05 11:59:56 +0800 | [diff] [blame] | 1491 | mSupervisor.getLaunchParamsController().calculate(reusedTask != null ? reusedTask : mInTask, |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1492 | r.info.windowLayout, r, sourceRecord, options, PHASE_BOUNDS, mLaunchParams); |
| 1493 | mPreferredDisplayId = |
| 1494 | mLaunchParams.hasPreferredDisplay() ? mLaunchParams.mPreferredDisplayId |
| 1495 | : DEFAULT_DISPLAY; |
| 1496 | |
Winson Chung | e219ae1 | 2019-07-18 13:43:23 -0700 | [diff] [blame] | 1497 | // If requested, freeze the task list |
| 1498 | if (mOptions != null && mOptions.freezeRecentTasksReordering() |
| 1499 | && mSupervisor.mRecentTasks.isCallerRecents(r.launchedFromUid) |
| 1500 | && !mSupervisor.mRecentTasks.isFreezeTaskListReorderingSet()) { |
| 1501 | mFrozeTaskList = true; |
| 1502 | mSupervisor.mRecentTasks.setFreezeTaskListReordering(); |
| 1503 | } |
| 1504 | |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1505 | // Compute if there is an existing task that should be used for. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1506 | final Task targetTask = reusedTask != null ? reusedTask : computeTargetTask(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1507 | final boolean newTask = targetTask == null; |
| 1508 | |
| 1509 | // Check if starting activity on given task or on a new task is allowed. |
| 1510 | int startResult = isAllowedToStart(r, newTask, targetTask); |
| 1511 | if (startResult != START_SUCCESS) { |
| 1512 | return startResult; |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1513 | } |
| 1514 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 1515 | final ActivityRecord targetTaskTop = newTask |
| 1516 | ? null : targetTask.getTopNonFinishingActivity(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1517 | if (targetTaskTop != null) { |
| 1518 | // Recycle the target task for this launch. |
Louis Chang | f7dd7f2 | 2019-11-05 11:59:56 +0800 | [diff] [blame] | 1519 | startResult = recycleTask(targetTask, targetTaskTop, reusedTask); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1520 | if (startResult != START_SUCCESS) { |
| 1521 | return startResult; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1522 | } |
Louis Chang | f7dd7f2 | 2019-11-05 11:59:56 +0800 | [diff] [blame] | 1523 | } else { |
| 1524 | mAddingToTask = true; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | // If the activity being launched is the same as the one currently at the top, then |
| 1528 | // we need to check if it should only be launched once. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1529 | final ActivityStack topStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1530 | startResult = deliverToCurrentTopIfNeeded(topStack); |
| 1531 | if (startResult != START_SUCCESS) { |
| 1532 | return startResult; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1535 | if (mTargetStack == null) { |
| 1536 | mTargetStack = computeStackFocus(mStartActivity, true, mLaunchFlags, mOptions); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1537 | } |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1538 | if (newTask) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1539 | final Task taskToAffiliate = (mLaunchTaskBehind && mSourceRecord != null) |
| 1540 | ? mSourceRecord.getTask() : null; |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1541 | setNewTask(taskToAffiliate); |
Louis Chang | a3e6b89 | 2019-09-16 10:39:00 +0800 | [diff] [blame] | 1542 | if (mService.getLockTaskController().isLockTaskModeViolation( |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1543 | mStartActivity.getTask())) { |
Louis Chang | a3e6b89 | 2019-09-16 10:39:00 +0800 | [diff] [blame] | 1544 | Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); |
| 1545 | return START_RETURN_LOCK_TASK_MODE_VIOLATION; |
| 1546 | } |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1547 | } else if (mAddingToTask) { |
| 1548 | addOrReparentStartingActivity(targetTask, "adding to task"); |
| 1549 | } |
| 1550 | |
| 1551 | if (!mAvoidMoveToFront && mDoResume) { |
| 1552 | mTargetStack.moveToFront("reuseOrNewTask"); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 1553 | } |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1554 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 1555 | mService.mUgmInternal.grantUriPermissionFromIntent(mCallingUid, mStartActivity.packageName, |
| 1556 | mIntent, mStartActivity.getUriPermissionsLocked(), mStartActivity.mUserId); |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 1557 | mService.getPackageManagerInternalLocked().grantImplicitAccess( |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 1558 | mStartActivity.mUserId, mIntent, |
Patrick Baumann | b6e7297 | 2019-09-20 07:54:47 -0700 | [diff] [blame] | 1559 | mCallingUid, |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 1560 | UserHandle.getAppId(mStartActivity.info.applicationInfo.uid) |
| 1561 | ); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1562 | if (newTask) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 1563 | EventLogTags.writeWmCreateTask(mStartActivity.mUserId, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1564 | mStartActivity.getTask().mTaskId); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1565 | } |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1566 | mStartActivity.logStartActivity( |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 1567 | EventLogTags.WM_CREATE_ACTIVITY, mStartActivity.getTask()); |
| 1568 | |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1569 | mTargetStack.mLastPausedActivity = null; |
Wei Wang | 98f03f9 | 2016-05-18 11:32:52 -0700 | [diff] [blame] | 1570 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1571 | mRootWindowContainer.sendPowerHintForLaunchStartIfNeeded( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1572 | false /* forceSend */, mStartActivity); |
Wei Wang | 98f03f9 | 2016-05-18 11:32:52 -0700 | [diff] [blame] | 1573 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 1574 | mTargetStack.startActivityLocked(mStartActivity, topStack.getTopNonFinishingActivity(), |
| 1575 | newTask, mKeepCurTransition, mOptions); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1576 | if (mDoResume) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1577 | final ActivityRecord topTaskActivity = |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1578 | mStartActivity.getTask().topRunningActivityLocked(); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1579 | if (!mTargetStack.isFocusable() |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 1580 | || (topTaskActivity != null && topTaskActivity.isTaskOverlay() |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 1581 | && mStartActivity != topTaskActivity)) { |
Filip Gruszczynski | 3d7fdc1 | 2016-01-31 17:33:29 -0800 | [diff] [blame] | 1582 | // If the activity is not focusable, we can't resume it, but still would like to |
| 1583 | // make sure it becomes visible as it starts (this will also trigger entry |
| 1584 | // animation). An example of this are PIP activities. |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1585 | // Also, we don't want to resume activities in a task that currently has an overlay |
| 1586 | // as the starting activity just needs to be in the visible paused state until the |
| 1587 | // over is removed. |
Wale Ogunwale | 076c3b1 | 2019-11-20 12:17:22 -0800 | [diff] [blame] | 1588 | mTargetStack.ensureActivitiesVisible(mStartActivity, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | ae846f4 | 2016-02-22 14:00:56 -0800 | [diff] [blame] | 1589 | // Go ahead and tell window manager to execute app transition for this activity |
| 1590 | // since the app transition will not be triggered through the resume channel. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1591 | mTargetStack.getDisplay().mDisplayContent.executeAppTransition(); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1592 | } else { |
Winson Chung | 3206603 | 2016-11-04 11:55:21 -0700 | [diff] [blame] | 1593 | // If the target stack was not previously focusable (previous top running activity |
| 1594 | // on that stack was not visible) then any prior calls to move the stack to the |
| 1595 | // will not update the focused stack. If starting the new activity now allows the |
| 1596 | // task stack to be focusable, then ensure that we now update the focused stack |
| 1597 | // accordingly. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1598 | if (mTargetStack.isFocusable() |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1599 | && !mRootWindowContainer.isTopDisplayFocusedStack(mTargetStack)) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1600 | mTargetStack.moveToFront("startActivityInner"); |
Winson Chung | 3206603 | 2016-11-04 11:55:21 -0700 | [diff] [blame] | 1601 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1602 | mRootWindowContainer.resumeFocusedStacksTopActivities( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1603 | mTargetStack, mStartActivity, mOptions); |
Filip Gruszczynski | 3d7fdc1 | 2016-01-31 17:33:29 -0800 | [diff] [blame] | 1604 | } |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 1605 | } else if (mStartActivity != null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1606 | mSupervisor.mRecentTasks.add(mStartActivity.getTask()); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1607 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1608 | mRootWindowContainer.updateUserStack(mStartActivity.mUserId, mTargetStack); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1609 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1610 | mSupervisor.handleNonResizableTaskIfNeeded(mStartActivity.getTask(), |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1611 | preferredWindowingMode, mPreferredDisplayId, mTargetStack); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1612 | |
| 1613 | return START_SUCCESS; |
| 1614 | } |
| 1615 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1616 | private Task computeTargetTask() { |
Louis Chang | f7dd7f2 | 2019-11-05 11:59:56 +0800 | [diff] [blame] | 1617 | if (mStartActivity.resultTo == null && mInTask == null && !mAddingToTask |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1618 | && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) { |
| 1619 | // A new task should be created instead of using existing one. |
| 1620 | return null; |
| 1621 | } else if (mSourceRecord != null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1622 | return mSourceRecord.getTask(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1623 | } else if (mInTask != null) { |
| 1624 | return mInTask; |
| 1625 | } else { |
| 1626 | final ActivityRecord top = computeStackFocus(mStartActivity, false /* newTask */, |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 1627 | mLaunchFlags, mOptions).getTopNonFinishingActivity(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1628 | if (top != null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1629 | return top.getTask(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | return null; |
| 1633 | } |
| 1634 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1635 | private int isAllowedToStart(ActivityRecord r, boolean newTask, Task targetTask) { |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1636 | if (mStartActivity.packageName == null) { |
| 1637 | if (mStartActivity.resultTo != null) { |
| 1638 | mStartActivity.resultTo.sendResult(INVALID_UID, mStartActivity.resultWho, |
| 1639 | mStartActivity.requestCode, RESULT_CANCELED, null /* data */); |
| 1640 | } |
| 1641 | ActivityOptions.abort(mOptions); |
| 1642 | return START_CLASS_NOT_FOUND; |
| 1643 | } |
| 1644 | |
| 1645 | // Do not start home activity if it cannot be launched on preferred display. We are not |
| 1646 | // doing this in ActivityStackSupervisor#canPlaceEntityOnDisplay because it might |
| 1647 | // fallback to launch on other displays. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1648 | if (r.isActivityTypeHome() && !mRootWindowContainer.canStartHomeOnDisplay(r.info, |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1649 | mPreferredDisplayId, true /* allowInstrumenting */)) { |
| 1650 | Slog.w(TAG, "Cannot launch home on display " + mPreferredDisplayId); |
| 1651 | return START_CANCELED; |
| 1652 | } |
| 1653 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1654 | if (mRestrictedBgActivity && (newTask || !targetTask.isUidPresent(mCallingUid)) |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1655 | && handleBackgroundActivityAbort(mStartActivity)) { |
| 1656 | Slog.e(TAG, "Abort background activity starts from " + mCallingUid); |
| 1657 | return START_ABORTED; |
| 1658 | } |
| 1659 | |
| 1660 | // When the flags NEW_TASK and CLEAR_TASK are set, then the task gets reused but still |
| 1661 | // needs to be a lock task mode violation since the task gets cleared out and the device |
| 1662 | // would otherwise leave the locked task. |
| 1663 | final boolean isNewClearTask = |
| 1664 | (mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) |
| 1665 | == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); |
Louis Chang | a3e6b89 | 2019-09-16 10:39:00 +0800 | [diff] [blame] | 1666 | if (!newTask && mService.getLockTaskController().isLockTaskModeViolation(targetTask, |
| 1667 | isNewClearTask)) { |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1668 | Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); |
| 1669 | return START_RETURN_LOCK_TASK_MODE_VIOLATION; |
| 1670 | } |
| 1671 | |
| 1672 | return START_SUCCESS; |
| 1673 | } |
| 1674 | |
| 1675 | /** |
| 1676 | * Prepare the target task to be reused for this launch, which including: |
| 1677 | * - Position the target task on valid stack on preferred display. |
| 1678 | * - Comply to the specified activity launch flags |
| 1679 | * - Determine whether need to add a new activity on top or just brought the task to front. |
| 1680 | */ |
Louis Chang | 07b1300 | 2019-11-27 22:08:37 +0800 | [diff] [blame] | 1681 | @VisibleForTesting |
| 1682 | int recycleTask(Task targetTask, ActivityRecord targetTaskTop, Task reusedTask) { |
| 1683 | // Should not recycle task which is from a different user, just adding the starting |
| 1684 | // activity to the task. |
| 1685 | if (targetTask.mUserId != mStartActivity.mUserId) { |
| 1686 | mTargetStack = targetTask.getStack(); |
| 1687 | mAddingToTask = true; |
| 1688 | return START_SUCCESS; |
| 1689 | } |
| 1690 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1691 | boolean clearTaskForReuse = false; |
Louis Chang | f7dd7f2 | 2019-11-05 11:59:56 +0800 | [diff] [blame] | 1692 | if (reusedTask != null) { |
Louis Chang | 2787a9a | 2019-12-17 15:15:11 +0800 | [diff] [blame] | 1693 | if (mStartActivity.getTask() == null) { |
Louis Chang | f7dd7f2 | 2019-11-05 11:59:56 +0800 | [diff] [blame] | 1694 | mStartActivity.setTaskForReuse(reusedTask); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1695 | clearTaskForReuse = true; |
| 1696 | } |
| 1697 | |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1698 | if (targetTask.intent == null) { |
| 1699 | // This task was started because of movement of the activity based on |
| 1700 | // affinity... |
| 1701 | // Now that we are actually launching it, we can assign the base intent. |
| 1702 | targetTask.setIntent(mStartActivity); |
| 1703 | } else { |
| 1704 | final boolean taskOnHome = |
| 1705 | (mStartActivity.intent.getFlags() & FLAG_ACTIVITY_TASK_ON_HOME) != 0; |
| 1706 | if (taskOnHome) { |
| 1707 | targetTask.intent.addFlags(FLAG_ACTIVITY_TASK_ON_HOME); |
| 1708 | } else { |
| 1709 | targetTask.intent.removeFlags(FLAG_ACTIVITY_TASK_ON_HOME); |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1714 | mRootWindowContainer.sendPowerHintForLaunchStartIfNeeded(false /* forceSend */, |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1715 | targetTaskTop); |
| 1716 | |
| 1717 | setTargetStackIfNeeded(targetTaskTop); |
| 1718 | |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1719 | // When there is a reused activity and the current result is a trampoline activity, |
| 1720 | // set the reused activity as the result. |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1721 | if (mLastStartActivityRecord != null |
| 1722 | && (mLastStartActivityRecord.finishing || mLastStartActivityRecord.noDisplay)) { |
| 1723 | mLastStartActivityRecord = targetTaskTop; |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) { |
| 1727 | // We don't need to start a new activity, and the client said not to do anything |
| 1728 | // if that is the case, so this is it! And for paranoia, make sure we have |
| 1729 | // correctly resumed the top activity. |
| 1730 | if (!mMovedToFront && mDoResume) { |
| 1731 | if (DEBUG_TASKS) { |
| 1732 | Slog.d(TAG_TASKS, "Bring to front target: " + mTargetStack |
| 1733 | + " from " + targetTaskTop); |
| 1734 | } |
| 1735 | mTargetStack.moveToFront("intentActivityFound"); |
| 1736 | } |
| 1737 | resumeTargetStackIfNeeded(); |
| 1738 | return START_RETURN_INTENT_TO_CALLER; |
| 1739 | } |
| 1740 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 1741 | complyActivityFlags(targetTask, |
| 1742 | reusedTask != null ? reusedTask.getTopNonFinishingActivity() : null); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1743 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1744 | if (clearTaskForReuse) { |
| 1745 | // Clear task for re-use so later code to methods |
| 1746 | // {@link #setTaskFromReuseOrCreateNewTask}, {@link #setTaskFromSourceRecord}, or |
| 1747 | // {@link #setTaskFromInTask} can parent it to the task. |
| 1748 | mStartActivity.setTaskForReuse(null); |
| 1749 | } |
| 1750 | |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1751 | if (mAddingToTask) { |
| 1752 | return START_SUCCESS; |
| 1753 | } |
| 1754 | |
Louis Chang | 3ee5fc0 | 2019-09-23 11:32:10 +0800 | [diff] [blame] | 1755 | if (mMovedToFront) { |
| 1756 | // We moved the task to front, use starting window to hide initial drawn delay. |
| 1757 | targetTaskTop.showStartingWindow(null /* prev */, false /* newTask */, |
| 1758 | true /* taskSwitch */); |
| 1759 | } else if (mDoResume) { |
| 1760 | // Make sure the stack and its belonging display are moved to topmost. |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1761 | mTargetStack.moveToFront("intentActivityFound"); |
| 1762 | } |
| 1763 | // We didn't do anything... but it was needed (a.k.a., client don't use that intent!) |
| 1764 | // And for paranoia, make sure we have correctly resumed the top activity. |
| 1765 | resumeTargetStackIfNeeded(); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1766 | // The reusedActivity could be finishing, for example of starting an activity with |
| 1767 | // FLAG_ACTIVITY_CLEAR_TOP flag. In that case, return the top running activity in the |
| 1768 | // task instead. |
| 1769 | mLastStartActivityRecord = |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 1770 | targetTaskTop.finishing ? targetTask.getTopNonFinishingActivity() : targetTaskTop; |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1771 | return mMovedToFront ? START_TASK_TO_FRONT : START_DELIVERED_TO_TOP; |
| 1772 | } |
| 1773 | |
| 1774 | /** |
| 1775 | * Check if the activity being launched is the same as the one currently at the top and it |
| 1776 | * should only be launched once. |
| 1777 | */ |
| 1778 | private int deliverToCurrentTopIfNeeded(ActivityStack topStack) { |
| 1779 | final ActivityRecord top = topStack.topRunningNonDelayedActivityLocked(mNotTop); |
| 1780 | final boolean dontStart = top != null && mStartActivity.resultTo == null |
| 1781 | && top.mActivityComponent.equals(mStartActivity.mActivityComponent) |
| 1782 | && top.mUserId == mStartActivity.mUserId |
| 1783 | && top.attachedToProcess() |
| 1784 | && ((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0 |
| 1785 | || isLaunchModeOneOf(LAUNCH_SINGLE_TOP, LAUNCH_SINGLE_TASK)) |
| 1786 | // This allows home activity to automatically launch on secondary display when |
| 1787 | // display added, if home was the top activity on default display, instead of |
| 1788 | // sending new intent to the home activity on default display. |
| 1789 | && (!top.isActivityTypeHome() || top.getDisplayId() == mPreferredDisplayId); |
| 1790 | if (!dontStart) { |
| 1791 | return START_SUCCESS; |
| 1792 | } |
| 1793 | |
| 1794 | // For paranoia, make sure we have correctly resumed the top activity. |
| 1795 | topStack.mLastPausedActivity = null; |
| 1796 | if (mDoResume) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1797 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1798 | } |
| 1799 | ActivityOptions.abort(mOptions); |
| 1800 | if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) { |
| 1801 | // We don't need to start a new activity, and the client said not to do anything if |
| 1802 | // that is the case, so this is it! |
| 1803 | return START_RETURN_INTENT_TO_CALLER; |
| 1804 | } |
| 1805 | |
| 1806 | deliverNewIntent(top); |
| 1807 | |
| 1808 | // Don't use mStartActivity.task to show the toast. We're not starting a new activity but |
| 1809 | // reusing 'top'. Fields in mStartActivity may not be fully initialized. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1810 | mSupervisor.handleNonResizableTaskIfNeeded(top.getTask(), |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1811 | mLaunchParams.mWindowingMode, mPreferredDisplayId, topStack); |
| 1812 | |
| 1813 | return START_DELIVERED_TO_TOP; |
| 1814 | } |
| 1815 | |
| 1816 | /** |
| 1817 | * Applying the launching flags to the task, which might clear few or all the activities in the |
| 1818 | * task. |
| 1819 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1820 | private void complyActivityFlags(Task targetTask, ActivityRecord reusedActivity) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 1821 | ActivityRecord targetTaskTop = targetTask.getTopNonFinishingActivity(); |
Louis Chang | 2dcb127 | 2019-09-27 15:01:19 +0800 | [diff] [blame] | 1822 | final boolean resetTask = |
| 1823 | reusedActivity != null && (mLaunchFlags & FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0; |
| 1824 | if (resetTask) { |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1825 | targetTaskTop = mTargetStack.resetTaskIfNeeded(targetTaskTop, mStartActivity); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | if ((mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) |
| 1829 | == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) { |
| 1830 | // The caller has requested to completely replace any existing task with its new |
| 1831 | // activity. Well that should not be too hard... |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1832 | // Note: we must persist the {@link Task} first as intentActivity could be |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1833 | // removed from calling performClearTaskLocked (For example, if it is being brought out |
| 1834 | // of history or if it is finished immediately), thus disassociating the task. Also note |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1835 | // that mReuseTask is reset as a result of {@link Task#performClearTaskLocked} |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1836 | // launching another activity. |
| 1837 | // TODO(b/36119896): We shouldn't trigger activity launches in this path since we are |
| 1838 | // already launching one. |
| 1839 | targetTask.performClearTaskLocked(); |
| 1840 | targetTask.setIntent(mStartActivity); |
| 1841 | mAddingToTask = true; |
| 1842 | } else if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0 |
| 1843 | || isDocumentLaunchesIntoExisting(mLaunchFlags) |
| 1844 | || isLaunchModeOneOf(LAUNCH_SINGLE_INSTANCE, LAUNCH_SINGLE_TASK)) { |
| 1845 | // In this situation we want to remove all activities from the task up to the one |
| 1846 | // being started. In most cases this means we are resetting the task to its initial |
| 1847 | // state. |
| 1848 | final ActivityRecord top = targetTask.performClearTaskForReuseLocked(mStartActivity, |
| 1849 | mLaunchFlags); |
| 1850 | |
| 1851 | // The above code can remove {@code reusedActivity} from the task, leading to the |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1852 | // {@code ActivityRecord} removing its reference to the {@code Task}. The task |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1853 | // reference is needed in the call below to {@link setTargetStackAndMoveToFrontIfNeeded} |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1854 | if (targetTaskTop.getTask() == null) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1855 | targetTask.addChild(targetTaskTop); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | if (top != null) { |
| 1859 | if (top.isRootOfTask()) { |
| 1860 | // Activity aliases may mean we use different intents for the top activity, |
| 1861 | // so make sure the task now has the identity of the new intent. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1862 | top.getTask().setIntent(mStartActivity); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1863 | } |
| 1864 | deliverNewIntent(top); |
| 1865 | } else { |
| 1866 | // A special case: we need to start the activity because it is not currently |
| 1867 | // running, and the caller has asked to clear the current task to have this |
| 1868 | // activity at the top. |
| 1869 | mAddingToTask = true; |
| 1870 | if (targetTask.getStack() == null) { |
| 1871 | // Target stack got cleared when we all activities were removed above. |
| 1872 | // Go ahead and reset it. |
| 1873 | mTargetStack = computeStackFocus(mSourceRecord, false /* newTask */, |
| 1874 | mLaunchFlags, mOptions); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1875 | mTargetStack.addChild(targetTask, !mLaunchTaskBehind /* toTop */, |
| 1876 | (mStartActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | } else if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) == 0 && !mAddingToTask |
| 1880 | && (mLaunchFlags & FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) { |
| 1881 | // In this case, we are launching an activity in our own task that may |
| 1882 | // already be running somewhere in the history, and we want to shuffle it to |
| 1883 | // the front of the stack if so. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1884 | final ActivityRecord act = |
| 1885 | targetTask.findActivityInHistory(mStartActivity.mActivityComponent); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1886 | if (act != null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1887 | final Task task = act.getTask(); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1888 | task.moveActivityToFrontLocked(act); |
| 1889 | act.updateOptionsLocked(mOptions); |
| 1890 | deliverNewIntent(act); |
| 1891 | mTargetStack.mLastPausedActivity = null; |
| 1892 | } else { |
| 1893 | mAddingToTask = true; |
| 1894 | } |
| 1895 | } else if (mStartActivity.mActivityComponent.equals(targetTask.realActivity)) { |
Louis Chang | 382419b | 2019-10-03 21:43:38 +0800 | [diff] [blame] | 1896 | if (targetTask == mInTask) { |
| 1897 | // In this case we are bringing up an existing activity from a recent task. We |
| 1898 | // don't need to add a new activity instance on top. |
| 1899 | } else if (((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0 |
| 1900 | || LAUNCH_SINGLE_TOP == mLaunchMode) |
| 1901 | && targetTaskTop.mActivityComponent.equals(mStartActivity.mActivityComponent) |
| 1902 | && mStartActivity.resultTo == null) { |
| 1903 | // In this case the top activity on the task is the same as the one being launched, |
| 1904 | // so we take that as a request to bring the task to the foreground. If the top |
| 1905 | // activity in the task is the root activity, deliver this new intent to it if it |
| 1906 | // desires. |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1907 | if (targetTaskTop.isRootOfTask()) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1908 | targetTaskTop.getTask().setIntent(mStartActivity); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1909 | } |
| 1910 | deliverNewIntent(targetTaskTop); |
| 1911 | } else if (!targetTask.isSameIntentFilter(mStartActivity)) { |
| 1912 | // In this case we are launching the root activity of the task, but with a |
| 1913 | // different intent. We should start a new instance on top. |
| 1914 | mAddingToTask = true; |
| 1915 | } else if (reusedActivity == null) { |
| 1916 | mAddingToTask = true; |
| 1917 | } |
Louis Chang | 2dcb127 | 2019-09-27 15:01:19 +0800 | [diff] [blame] | 1918 | } else if (!resetTask) { |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 1919 | // In this case an activity is being launched in to an existing task, without |
| 1920 | // resetting that task. This is typically the situation of launching an activity |
| 1921 | // from a notification or shortcut. We want to place the new activity on top of the |
| 1922 | // current task. |
| 1923 | mAddingToTask = true; |
| 1924 | } else if (!targetTask.rootWasReset) { |
| 1925 | // In this case we are launching into an existing task that has not yet been started |
| 1926 | // from its front door. The current task has been brought to the front. Ideally, |
| 1927 | // we'd probably like to place this new task at the bottom of its stack, but that's |
| 1928 | // a little hard to do with the current organization of the code so for now we'll |
| 1929 | // just drop it. |
| 1930 | targetTask.setIntent(mStartActivity); |
| 1931 | } |
| 1932 | } |
| 1933 | |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 1934 | /** |
| 1935 | * Resets the {@link ActivityStarter} state. |
| 1936 | * @param clearRequest whether the request should be reset to default values. |
| 1937 | */ |
| 1938 | void reset(boolean clearRequest) { |
| 1939 | mStartActivity = null; |
| 1940 | mIntent = null; |
| 1941 | mCallingUid = -1; |
| 1942 | mOptions = null; |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1943 | mRestrictedBgActivity = false; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 1944 | |
| 1945 | mLaunchTaskBehind = false; |
| 1946 | mLaunchFlags = 0; |
| 1947 | mLaunchMode = INVALID_LAUNCH_MODE; |
| 1948 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 1949 | mLaunchParams.reset(); |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 1950 | |
| 1951 | mNotTop = null; |
| 1952 | mDoResume = false; |
| 1953 | mStartFlags = 0; |
| 1954 | mSourceRecord = null; |
| 1955 | mPreferredDisplayId = INVALID_DISPLAY; |
| 1956 | |
| 1957 | mInTask = null; |
| 1958 | mAddingToTask = false; |
| 1959 | mReuseTask = null; |
| 1960 | |
| 1961 | mNewTaskInfo = null; |
| 1962 | mNewTaskIntent = null; |
| 1963 | mSourceStack = null; |
| 1964 | |
| 1965 | mTargetStack = null; |
| 1966 | mMovedToFront = false; |
| 1967 | mNoAnimation = false; |
| 1968 | mKeepCurTransition = false; |
| 1969 | mAvoidMoveToFront = false; |
Winson Chung | e219ae1 | 2019-07-18 13:43:23 -0700 | [diff] [blame] | 1970 | mFrozeTaskList = false; |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 1971 | |
| 1972 | mVoiceSession = null; |
| 1973 | mVoiceInteractor = null; |
| 1974 | |
| 1975 | mIntentDelivered = false; |
| 1976 | |
| 1977 | if (clearRequest) { |
| 1978 | mRequest.reset(); |
| 1979 | } |
| 1980 | } |
| 1981 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1982 | private void setInitialState(ActivityRecord r, ActivityOptions options, Task inTask, |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1983 | boolean doResume, int startFlags, ActivityRecord sourceRecord, |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1984 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 1985 | boolean restrictedBgActivity) { |
Bryce Lee | daa91e4 | 2017-12-06 14:13:01 -0800 | [diff] [blame] | 1986 | reset(false /* clearRequest */); |
| 1987 | |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1988 | mStartActivity = r; |
| 1989 | mIntent = r.intent; |
| 1990 | mOptions = options; |
| 1991 | mCallingUid = r.launchedFromUid; |
| 1992 | mSourceRecord = sourceRecord; |
| 1993 | mVoiceSession = voiceSession; |
| 1994 | mVoiceInteractor = voiceInteractor; |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 1995 | mRestrictedBgActivity = restrictedBgActivity; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 1996 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 1997 | mLaunchParams.reset(); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 1998 | |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 1999 | // Preferred display id is the only state we need for now and it could be updated again |
| 2000 | // after we located a reusable task (which might be resided in another display). |
Garfield Tan | 706dbcb | 2018-10-15 11:33:02 -0700 | [diff] [blame] | 2001 | mSupervisor.getLaunchParamsController().calculate(inTask, r.info.windowLayout, r, |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 2002 | sourceRecord, options, PHASE_DISPLAY, mLaunchParams); |
| 2003 | mPreferredDisplayId = |
| 2004 | mLaunchParams.hasPreferredDisplay() ? mLaunchParams.mPreferredDisplayId |
| 2005 | : DEFAULT_DISPLAY; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 2006 | |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2007 | mLaunchMode = r.launchMode; |
| 2008 | |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2009 | mLaunchFlags = adjustLaunchFlagsToDocumentMode( |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2010 | r, LAUNCH_SINGLE_INSTANCE == mLaunchMode, |
| 2011 | LAUNCH_SINGLE_TASK == mLaunchMode, mIntent.getFlags()); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2012 | mLaunchTaskBehind = r.mLaunchTaskBehind |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2013 | && !isLaunchModeOneOf(LAUNCH_SINGLE_TASK, LAUNCH_SINGLE_INSTANCE) |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2014 | && (mLaunchFlags & FLAG_ACTIVITY_NEW_DOCUMENT) != 0; |
| 2015 | |
| 2016 | sendNewTaskResultRequestIfNeeded(); |
| 2017 | |
| 2018 | if ((mLaunchFlags & FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && r.resultTo == null) { |
| 2019 | mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK; |
| 2020 | } |
| 2021 | |
| 2022 | // If we are actually going to launch in to a new task, there are some cases where |
| 2023 | // we further want to do multiple task. |
| 2024 | if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) { |
| 2025 | if (mLaunchTaskBehind |
| 2026 | || r.info.documentLaunchMode == DOCUMENT_LAUNCH_ALWAYS) { |
| 2027 | mLaunchFlags |= FLAG_ACTIVITY_MULTIPLE_TASK; |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | // We'll invoke onUserLeaving before onPause only if the launching |
| 2032 | // activity did not explicitly state that this is an automated launch. |
| 2033 | mSupervisor.mUserLeaving = (mLaunchFlags & FLAG_ACTIVITY_NO_USER_ACTION) == 0; |
| 2034 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 2035 | "startActivity() => mUserLeaving=" + mSupervisor.mUserLeaving); |
| 2036 | |
| 2037 | // If the caller has asked not to resume at this point, we make note |
| 2038 | // of this in the record so that we can skip it when trying to find |
| 2039 | // the top running activity. |
| 2040 | mDoResume = doResume; |
Louis Chang | 3731715 | 2019-05-09 09:53:58 +0800 | [diff] [blame] | 2041 | if (!doResume || !r.okToShowLocked() || mLaunchTaskBehind) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2042 | r.delayedResume = true; |
| 2043 | mDoResume = false; |
| 2044 | } |
| 2045 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2046 | if (mOptions != null) { |
| 2047 | if (mOptions.getLaunchTaskId() != -1 && mOptions.getTaskOverlay()) { |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 2048 | r.setTaskOverlay(true); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2049 | if (!mOptions.canTaskOverlayResume()) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2050 | final Task task = mRootWindowContainer.anyTaskForId( |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2051 | mOptions.getLaunchTaskId()); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2052 | final ActivityRecord top = task != null |
| 2053 | ? task.getTopNonFinishingActivity() : null; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2054 | if (top != null && !top.isState(RESUMED)) { |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 2055 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2056 | // The caller specifies that we'd like to be avoided to be moved to the |
| 2057 | // front, so be it! |
| 2058 | mDoResume = false; |
| 2059 | mAvoidMoveToFront = true; |
| 2060 | } |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 2061 | } |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2062 | } else if (mOptions.getAvoidMoveToFront()) { |
Winson Chung | ba40d3a | 2018-05-16 09:40:16 -0700 | [diff] [blame] | 2063 | mDoResume = false; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2064 | mAvoidMoveToFront = true; |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 2065 | } |
| 2066 | } |
| 2067 | |
Louis Chang | 2f4e9b46 | 2019-03-05 16:43:15 +0800 | [diff] [blame] | 2068 | mNotTop = (mLaunchFlags & FLAG_ACTIVITY_PREVIOUS_IS_TOP) != 0 ? sourceRecord : null; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2069 | |
| 2070 | mInTask = inTask; |
| 2071 | // In some flows in to this function, we retrieve the task record and hold on to it |
| 2072 | // without a lock before calling back in to here... so the task at this point may |
| 2073 | // not actually be in recents. Check for that, and if it isn't in recents just |
| 2074 | // consider it invalid. |
| 2075 | if (inTask != null && !inTask.inRecents) { |
| 2076 | Slog.w(TAG, "Starting activity in task not in recents: " + inTask); |
| 2077 | mInTask = null; |
| 2078 | } |
| 2079 | |
| 2080 | mStartFlags = startFlags; |
| 2081 | // If the onlyIfNeeded flag is set, then we can do this if the activity being launched |
| 2082 | // is the same as the one making the call... or, as a special case, if we do not know |
| 2083 | // the caller then we count the current top activity as the caller. |
| 2084 | if ((startFlags & START_FLAG_ONLY_IF_NEEDED) != 0) { |
| 2085 | ActivityRecord checkedCaller = sourceRecord; |
| 2086 | if (checkedCaller == null) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2087 | checkedCaller = mRootWindowContainer.getTopDisplayFocusedStack() |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2088 | .topRunningNonDelayedActivityLocked(mNotTop); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2089 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2090 | if (!checkedCaller.mActivityComponent.equals(r.mActivityComponent)) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2091 | // Caller is not the same as launcher, so always needed. |
| 2092 | mStartFlags &= ~START_FLAG_ONLY_IF_NEEDED; |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | mNoAnimation = (mLaunchFlags & FLAG_ACTIVITY_NO_ANIMATION) != 0; |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 2097 | |
Alan Stokes | 07389b6 | 2019-05-20 15:22:54 +0100 | [diff] [blame] | 2098 | if (mRestrictedBgActivity && !mService.isBackgroundActivityStartsEnabled()) { |
Ricky Wai | b147fa1 | 2019-04-25 16:08:30 +0100 | [diff] [blame] | 2099 | mAvoidMoveToFront = true; |
| 2100 | mDoResume = false; |
| 2101 | } |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | private void sendNewTaskResultRequestIfNeeded() { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2105 | if (mStartActivity.resultTo != null && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2106 | // For whatever reason this activity is being launched into a new task... |
| 2107 | // yet the caller has requested a result back. Well, that is pretty messed up, |
| 2108 | // so instead immediately send back a cancel and let the new task continue launched |
| 2109 | // as normal without a dependency on its originator. |
| 2110 | Slog.w(TAG, "Activity is launching as a new task, so cancelling activity result."); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2111 | mStartActivity.resultTo.sendResult(INVALID_UID, mStartActivity.resultWho, |
| 2112 | mStartActivity.requestCode, RESULT_CANCELED, null /* data */); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2113 | mStartActivity.resultTo = null; |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | private void computeLaunchingTaskFlags() { |
| 2118 | // If the caller is not coming from another activity, but has given us an explicit task into |
| 2119 | // which they would like us to launch the new activity, then let's see about doing that. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2120 | if (mSourceRecord == null && mInTask != null && mInTask.getStack() != null) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2121 | final Intent baseIntent = mInTask.getBaseIntent(); |
| 2122 | final ActivityRecord root = mInTask.getRootActivity(); |
| 2123 | if (baseIntent == null) { |
| 2124 | ActivityOptions.abort(mOptions); |
| 2125 | throw new IllegalArgumentException("Launching into task without base intent: " |
| 2126 | + mInTask); |
| 2127 | } |
| 2128 | |
| 2129 | // If this task is empty, then we are adding the first activity -- it |
| 2130 | // determines the root, and must be launching as a NEW_TASK. |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2131 | if (isLaunchModeOneOf(LAUNCH_SINGLE_INSTANCE, LAUNCH_SINGLE_TASK)) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2132 | if (!baseIntent.getComponent().equals(mStartActivity.intent.getComponent())) { |
| 2133 | ActivityOptions.abort(mOptions); |
| 2134 | throw new IllegalArgumentException("Trying to launch singleInstance/Task " |
| 2135 | + mStartActivity + " into different task " + mInTask); |
| 2136 | } |
| 2137 | if (root != null) { |
| 2138 | ActivityOptions.abort(mOptions); |
| 2139 | throw new IllegalArgumentException("Caller with mInTask " + mInTask |
| 2140 | + " has root " + root + " but target is singleInstance/Task"); |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | // If task is empty, then adopt the interesting intent launch flags in to the |
| 2145 | // activity being started. |
| 2146 | if (root == null) { |
| 2147 | final int flagsOfInterest = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK |
| 2148 | | FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS; |
| 2149 | mLaunchFlags = (mLaunchFlags & ~flagsOfInterest) |
| 2150 | | (baseIntent.getFlags() & flagsOfInterest); |
| 2151 | mIntent.setFlags(mLaunchFlags); |
| 2152 | mInTask.setIntent(mStartActivity); |
| 2153 | mAddingToTask = true; |
| 2154 | |
| 2155 | // If the task is not empty and the caller is asking to start it as the root of |
| 2156 | // a new task, then we don't actually want to start this on the task. We will |
| 2157 | // bring the task to the front, and possibly give it a new intent. |
| 2158 | } else if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) { |
| 2159 | mAddingToTask = false; |
| 2160 | |
| 2161 | } else { |
| 2162 | mAddingToTask = true; |
| 2163 | } |
| 2164 | |
| 2165 | mReuseTask = mInTask; |
| 2166 | } else { |
| 2167 | mInTask = null; |
| 2168 | // Launch ResolverActivity in the source task, so that it stays in the task bounds |
| 2169 | // when in freeform workspace. |
| 2170 | // Also put noDisplay activities in the source task. These by itself can be placed |
| 2171 | // in any task/stack, however it could launch other activities like ResolverActivity, |
| 2172 | // and we want those to stay in the original task. |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 2173 | if ((mStartActivity.isResolverOrDelegateActivity() || mStartActivity.noDisplay) |
| 2174 | && mSourceRecord != null && mSourceRecord.inFreeformWindowingMode()) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2175 | mAddingToTask = true; |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | if (mInTask == null) { |
| 2180 | if (mSourceRecord == null) { |
| 2181 | // This activity is not being started from another... in this |
| 2182 | // case we -always- start a new task. |
| 2183 | if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) == 0 && mInTask == null) { |
| 2184 | Slog.w(TAG, "startActivity called from non-Activity context; forcing " + |
| 2185 | "Intent.FLAG_ACTIVITY_NEW_TASK for: " + mIntent); |
| 2186 | mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK; |
| 2187 | } |
| 2188 | } else if (mSourceRecord.launchMode == LAUNCH_SINGLE_INSTANCE) { |
| 2189 | // The original activity who is starting us is running as a single |
| 2190 | // instance... this new activity it is starting must go on its |
| 2191 | // own task. |
| 2192 | mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK; |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2193 | } else if (isLaunchModeOneOf(LAUNCH_SINGLE_INSTANCE, LAUNCH_SINGLE_TASK)) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2194 | // The activity being started is a single instance... it always |
| 2195 | // gets launched into its own task. |
| 2196 | mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK; |
| 2197 | } |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | private void computeSourceStack() { |
| 2202 | if (mSourceRecord == null) { |
| 2203 | mSourceStack = null; |
| 2204 | return; |
| 2205 | } |
| 2206 | if (!mSourceRecord.finishing) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2207 | mSourceStack = mSourceRecord.getActivityStack(); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2208 | return; |
| 2209 | } |
| 2210 | |
| 2211 | // If the source is finishing, we can't further count it as our source. This is because the |
| 2212 | // task it is associated with may now be empty and on its way out, so we don't want to |
| 2213 | // blindly throw it in to that task. Instead we will take the NEW_TASK flow and try to find |
| 2214 | // a task for it. But save the task information so it can be used when creating the new task. |
| 2215 | if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) == 0) { |
| 2216 | Slog.w(TAG, "startActivity called from finishing " + mSourceRecord |
| 2217 | + "; forcing " + "Intent.FLAG_ACTIVITY_NEW_TASK for: " + mIntent); |
| 2218 | mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK; |
| 2219 | mNewTaskInfo = mSourceRecord.info; |
Bryce Lee | d9ed45d | 2017-05-22 15:57:24 -0700 | [diff] [blame] | 2220 | |
| 2221 | // It is not guaranteed that the source record will have a task associated with it. For, |
| 2222 | // example, if this method is being called for processing a pending activity launch, it |
| 2223 | // is possible that the activity has been removed from the task after the launch was |
| 2224 | // enqueued. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2225 | final Task sourceTask = mSourceRecord.getTask(); |
Bryce Lee | d9ed45d | 2017-05-22 15:57:24 -0700 | [diff] [blame] | 2226 | mNewTaskIntent = sourceTask != null ? sourceTask.intent : null; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2227 | } |
| 2228 | mSourceRecord = null; |
| 2229 | mSourceStack = null; |
| 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * Decide whether the new activity should be inserted into an existing task. Returns null |
| 2234 | * if not or an ActivityRecord with the task into which the new activity should be added. |
| 2235 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2236 | private Task getReusableTask() { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2237 | // We may want to try to place the new activity in to an existing task. We always |
| 2238 | // do this if the target activity is singleTask or singleInstance; we will also do |
| 2239 | // this if NEW_TASK has been requested, and there is not an additional qualifier telling |
| 2240 | // us to still place it in a new task: multi task, always doc mode, or being asked to |
| 2241 | // launch this as a new task behind the current one. |
| 2242 | boolean putIntoExistingTask = ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0 && |
| 2243 | (mLaunchFlags & FLAG_ACTIVITY_MULTIPLE_TASK) == 0) |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2244 | || isLaunchModeOneOf(LAUNCH_SINGLE_INSTANCE, LAUNCH_SINGLE_TASK); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2245 | // If bring to front is requested, and no result is requested and we have not been given |
| 2246 | // an explicit task to launch in to, and we can find a task that was started with this |
| 2247 | // same component, then instead of launching bring that one to the front. |
| 2248 | putIntoExistingTask &= mInTask == null && mStartActivity.resultTo == null; |
| 2249 | ActivityRecord intentActivity = null; |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2250 | if (mOptions != null && mOptions.getLaunchTaskId() != -1) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2251 | Task launchTask = mRootWindowContainer.anyTaskForId(mOptions.getLaunchTaskId()); |
Louis Chang | f7dd7f2 | 2019-11-05 11:59:56 +0800 | [diff] [blame] | 2252 | if (launchTask != null) { |
| 2253 | return launchTask; |
| 2254 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2255 | } else if (putIntoExistingTask) { |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2256 | if (LAUNCH_SINGLE_INSTANCE == mLaunchMode) { |
Wale Ogunwale | 13dbfff | 2016-05-20 08:50:15 -0700 | [diff] [blame] | 2257 | // There can be one and only one instance of single instance activity in the |
| 2258 | // history, and it is always in its own unique task, so we do a special search. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2259 | intentActivity = mRootWindowContainer.findActivity(mIntent, mStartActivity.info, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2260 | mStartActivity.isActivityTypeHome()); |
Wale Ogunwale | 13dbfff | 2016-05-20 08:50:15 -0700 | [diff] [blame] | 2261 | } else if ((mLaunchFlags & FLAG_ACTIVITY_LAUNCH_ADJACENT) != 0) { |
| 2262 | // For the launch adjacent case we only want to put the activity in an existing |
| 2263 | // task if the activity already exists in the history. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2264 | intentActivity = mRootWindowContainer.findActivity(mIntent, mStartActivity.info, |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2265 | !(LAUNCH_SINGLE_TASK == mLaunchMode)); |
Wale Ogunwale | 13dbfff | 2016-05-20 08:50:15 -0700 | [diff] [blame] | 2266 | } else { |
| 2267 | // Otherwise find the best task to put the activity in. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2268 | intentActivity = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2269 | mRootWindowContainer.findTask(mStartActivity, mPreferredDisplayId); |
Wale Ogunwale | 13dbfff | 2016-05-20 08:50:15 -0700 | [diff] [blame] | 2270 | } |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2271 | } |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2272 | |
Louis Chang | 54506cb | 2018-11-23 11:03:41 +0800 | [diff] [blame] | 2273 | if (intentActivity != null |
| 2274 | && (mStartActivity.isActivityTypeHome() || intentActivity.isActivityTypeHome()) |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2275 | && intentActivity.getDisplayId() != mPreferredDisplayId) { |
| 2276 | // Do not reuse home activity on other displays. |
| 2277 | intentActivity = null; |
| 2278 | } |
| 2279 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2280 | return intentActivity != null ? intentActivity.getTask() : null; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2281 | } |
| 2282 | |
Andrii Kulian | fab9cd8 | 2017-03-21 19:37:09 -0700 | [diff] [blame] | 2283 | /** |
| 2284 | * Figure out which task and activity to bring to front when we have found an existing matching |
| 2285 | * activity record in history. May also clear the task if needed. |
| 2286 | * @param intentActivity Existing matching activity. |
| 2287 | * @return {@link ActivityRecord} brought to front. |
| 2288 | */ |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2289 | private void setTargetStackIfNeeded(ActivityRecord intentActivity) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2290 | mTargetStack = intentActivity.getActivityStack(); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2291 | mTargetStack.mLastPausedActivity = null; |
| 2292 | // If the target task is not in the front, then we need to bring it to the front... |
| 2293 | // except... well, with SINGLE_TASK_LAUNCH it's not entirely clear. We'd like to have |
| 2294 | // the same behavior as if a new instance was being started, which means not bringing it |
| 2295 | // to the front if the caller is not itself in the front. |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 2296 | final boolean differentTopTask; |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 2297 | if (mPreferredDisplayId == mTargetStack.getDisplayId()) { |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 2298 | final ActivityStack focusStack = mTargetStack.getDisplay().getFocusedStack(); |
| 2299 | final ActivityRecord curTop = (focusStack == null) |
| 2300 | ? null : focusStack.topRunningNonDelayedActivityLocked(mNotTop); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2301 | final Task topTask = curTop != null ? curTop.getTask() : null; |
| 2302 | differentTopTask = topTask != intentActivity.getTask() |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2303 | || (focusStack != null && topTask != focusStack.getTopMostTask()); |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 2304 | } else { |
| 2305 | // The existing task should always be different from those in other displays. |
| 2306 | differentTopTask = true; |
| 2307 | } |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2308 | |
Riddle Hsu | b70b36d | 2018-09-11 21:20:02 +0800 | [diff] [blame] | 2309 | if (differentTopTask && !mAvoidMoveToFront) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2310 | mStartActivity.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2311 | if (mSourceRecord == null || (mSourceStack.getTopNonFinishingActivity() != null && |
| 2312 | mSourceStack.getTopNonFinishingActivity().getTask() |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2313 | == mSourceRecord.getTask())) { |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2314 | // We really do want to push this one into the user's face, right now. |
| 2315 | if (mLaunchTaskBehind && mSourceRecord != null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2316 | intentActivity.setTaskToAffiliateWith(mSourceRecord.getTask()); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2317 | } |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2318 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2319 | final Task intentTask = intentActivity.getTask(); |
Louis Chang | f3070c5 | 2019-10-09 15:57:30 +0800 | [diff] [blame] | 2320 | final ActivityStack launchStack = |
| 2321 | getLaunchStack(mStartActivity, mLaunchFlags, intentTask, mOptions); |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2322 | if (launchStack == null || launchStack == mTargetStack) { |
| 2323 | // We only want to move to the front, if we aren't going to launch on a |
| 2324 | // different stack. If we launch on a different stack, we will put the |
| 2325 | // task on top there. |
| 2326 | mTargetStack.moveTaskToFrontLocked(intentTask, mNoAnimation, mOptions, |
| 2327 | mStartActivity.appTimeTracker, "bringingFoundTaskToFront"); |
| 2328 | mMovedToFront = true; |
| 2329 | } else if (launchStack.inSplitScreenWindowingMode()) { |
| 2330 | if ((mLaunchFlags & FLAG_ACTIVITY_LAUNCH_ADJACENT) != 0) { |
| 2331 | // If we want to launch adjacent and mTargetStack is not the computed |
| 2332 | // launch stack - move task to top of computed stack. |
| 2333 | intentTask.reparent(launchStack, ON_TOP, |
Andrii Kulian | fab9cd8 | 2017-03-21 19:37:09 -0700 | [diff] [blame] | 2334 | REPARENT_MOVE_STACK_TO_FRONT, ANIMATE, DEFER_RESUME, |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2335 | "launchToSide"); |
| 2336 | } else { |
| 2337 | // TODO: This should be reevaluated in MW v2. |
| 2338 | // We choose to move task to front instead of launching it adjacent |
| 2339 | // when specific stack was requested explicitly and it appeared to be |
| 2340 | // adjacent stack, but FLAG_ACTIVITY_LAUNCH_ADJACENT was not set. |
| 2341 | mTargetStack.moveTaskToFrontLocked(intentTask, |
| 2342 | mNoAnimation, mOptions, mStartActivity.appTimeTracker, |
| 2343 | "bringToFrontInsteadOfAdjacentLaunch"); |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2344 | } |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2345 | mMovedToFront = launchStack != launchStack.getDisplay() |
| 2346 | .getTopStackInWindowingMode(launchStack.getWindowingMode()); |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 2347 | } else if (launchStack.getDisplayId() != mTargetStack.getDisplayId()) { |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2348 | // Target and computed stacks are on different displays and we've |
| 2349 | // found a matching task - move the existing instance to that display and |
| 2350 | // move it to front. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2351 | intentActivity.getTask().reparent(launchStack, ON_TOP, |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2352 | REPARENT_MOVE_STACK_TO_FRONT, ANIMATE, DEFER_RESUME, |
| 2353 | "reparentToDisplay"); |
| 2354 | mMovedToFront = true; |
| 2355 | } else if (launchStack.isActivityTypeHome() |
| 2356 | && !mTargetStack.isActivityTypeHome()) { |
| 2357 | // It is possible for the home activity to be in another stack initially. |
| 2358 | // For example, the activity may have been initially started with an intent |
| 2359 | // which placed it in the fullscreen stack. To ensure the proper handling of |
| 2360 | // the activity based on home stack assumptions, we must move it over. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2361 | intentActivity.getTask().reparent(launchStack, ON_TOP, |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2362 | REPARENT_MOVE_STACK_TO_FRONT, ANIMATE, DEFER_RESUME, |
| 2363 | "reparentingHome"); |
| 2364 | mMovedToFront = true; |
Louis Chang | f3070c5 | 2019-10-09 15:57:30 +0800 | [diff] [blame] | 2365 | } |
| 2366 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2367 | if (launchStack != null && launchStack.getTopMostTask() == null) { |
Louis Chang | fe0dfcb | 2019-09-02 15:59:38 +0800 | [diff] [blame] | 2368 | // The task does not need to be reparented to the launch stack. Remove the |
| 2369 | // launch stack if there is no activity in it. |
Louis Chang | f3070c5 | 2019-10-09 15:57:30 +0800 | [diff] [blame] | 2370 | Slog.w(TAG, "Removing an empty stack: " + launchStack); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2371 | launchStack.removeIfPossible(); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2372 | } |
Louis Chang | fe0dfcb | 2019-09-02 15:59:38 +0800 | [diff] [blame] | 2373 | |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2374 | mOptions = null; |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2375 | } |
| 2376 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2377 | // Need to update mTargetStack because if task was moved out of it, the original stack may |
| 2378 | // be destroyed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2379 | mTargetStack = intentActivity.getActivityStack(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2380 | mSupervisor.handleNonResizableTaskIfNeeded(intentActivity.getTask(), |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2381 | WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, mTargetStack); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | private void resumeTargetStackIfNeeded() { |
| 2385 | if (mDoResume) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2386 | mRootWindowContainer.resumeFocusedStacksTopActivities(mTargetStack, null, mOptions); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2387 | } else { |
| 2388 | ActivityOptions.abort(mOptions); |
| 2389 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2390 | mRootWindowContainer.updateUserStack(mStartActivity.mUserId, mTargetStack); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2391 | } |
| 2392 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2393 | private void setNewTask(Task taskToAffiliate) { |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2394 | final boolean toTop = !mLaunchTaskBehind && !mAvoidMoveToFront; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2395 | final Task task = mTargetStack.createTask( |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 2396 | mSupervisor.getNextTaskIdForUser(mStartActivity.mUserId), |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2397 | mNewTaskInfo != null ? mNewTaskInfo : mStartActivity.info, |
| 2398 | mNewTaskIntent != null ? mNewTaskIntent : mIntent, mVoiceSession, |
| 2399 | mVoiceInteractor, toTop, mStartActivity, mSourceRecord, mOptions); |
| 2400 | addOrReparentStartingActivity(task, "setTaskFromReuseOrCreateNewTask - mReuseTask"); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2401 | updateBounds(mStartActivity.getTask(), mLaunchParams.mBounds); |
Louis Chang | e890245 | 2019-06-10 10:49:28 +0800 | [diff] [blame] | 2402 | |
Louis Chang | bde91e9 | 2019-08-16 17:19:47 +0800 | [diff] [blame] | 2403 | if (DEBUG_TASKS) { |
| 2404 | Slog.v(TAG_TASKS, "Starting new activity " + mStartActivity |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2405 | + " in new task " + mStartActivity.getTask()); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | if (taskToAffiliate != null) { |
| 2409 | mStartActivity.setTaskToAffiliateWith(taskToAffiliate); |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Bryce Lee | 325e0968 | 2017-10-05 17:20:25 -0700 | [diff] [blame] | 2413 | private void deliverNewIntent(ActivityRecord activity) { |
| 2414 | if (mIntentDelivered) { |
| 2415 | return; |
| 2416 | } |
| 2417 | |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 2418 | activity.logStartActivity(EventLogTags.WM_NEW_INTENT, activity.getTask()); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2419 | activity.deliverNewIntentLocked(mCallingUid, mStartActivity.intent, |
Bryce Lee | 325e0968 | 2017-10-05 17:20:25 -0700 | [diff] [blame] | 2420 | mStartActivity.launchedFromPackage); |
| 2421 | mIntentDelivered = true; |
| 2422 | } |
| 2423 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2424 | @VisibleForTesting |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2425 | void updateBounds(Task task, Rect bounds) { |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 2426 | if (bounds.isEmpty()) { |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 2427 | return; |
| 2428 | } |
| 2429 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2430 | final ActivityStack stack = task.getStack(); |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2431 | if (stack != null && stack.inPinnedWindowingMode()) { |
| 2432 | mService.animateResizePinnedStack(stack.mStackId, bounds, -1); |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 2433 | } else { |
Evan Rosky | a4cc3a9 | 2019-06-28 13:25:01 -0700 | [diff] [blame] | 2434 | task.setBounds(bounds); |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2438 | private void addOrReparentStartingActivity(Task parent, String reason) { |
| 2439 | if (mStartActivity.getTask() == null || mStartActivity.getTask() == parent) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 2440 | parent.addChild(mStartActivity); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 2441 | } else { |
Wale Ogunwale | 1a06f15 | 2019-10-11 11:26:30 +0200 | [diff] [blame] | 2442 | mStartActivity.reparent(parent, parent.getChildCount() /* top */, reason); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 2443 | } |
Wale Ogunwale | 01d6656 | 2015-12-29 08:19:19 -0800 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | private int adjustLaunchFlagsToDocumentMode(ActivityRecord r, boolean launchSingleInstance, |
| 2447 | boolean launchSingleTask, int launchFlags) { |
| 2448 | if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && |
| 2449 | (launchSingleInstance || launchSingleTask)) { |
| 2450 | // We have a conflict between the Intent and the Activity manifest, manifest wins. |
| 2451 | Slog.i(TAG, "Ignoring FLAG_ACTIVITY_NEW_DOCUMENT, launchMode is " + |
| 2452 | "\"singleInstance\" or \"singleTask\""); |
| 2453 | launchFlags &= |
| 2454 | ~(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_MULTIPLE_TASK); |
| 2455 | } else { |
| 2456 | switch (r.info.documentLaunchMode) { |
| 2457 | case ActivityInfo.DOCUMENT_LAUNCH_NONE: |
| 2458 | break; |
| 2459 | case ActivityInfo.DOCUMENT_LAUNCH_INTO_EXISTING: |
| 2460 | launchFlags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
| 2461 | break; |
| 2462 | case ActivityInfo.DOCUMENT_LAUNCH_ALWAYS: |
| 2463 | launchFlags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
| 2464 | break; |
| 2465 | case ActivityInfo.DOCUMENT_LAUNCH_NEVER: |
| 2466 | launchFlags &= ~FLAG_ACTIVITY_MULTIPLE_TASK; |
| 2467 | break; |
| 2468 | } |
| 2469 | } |
| 2470 | return launchFlags; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2471 | } |
| 2472 | |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 2473 | private ActivityStack computeStackFocus(ActivityRecord r, boolean newTask, int launchFlags, |
| 2474 | ActivityOptions aOptions) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2475 | final Task task = r.getTask(); |
Jorim Jaggi | 4ad9856 | 2016-04-19 20:30:47 -0700 | [diff] [blame] | 2476 | ActivityStack stack = getLaunchStack(r, launchFlags, task, aOptions); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2477 | if (stack != null) { |
| 2478 | return stack; |
| 2479 | } |
| 2480 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2481 | final ActivityStack currentStack = task != null ? task.getStack() : null; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2482 | final ActivityStack focusedStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2483 | if (currentStack != null) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 2484 | if (focusedStack != currentStack) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2485 | if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG_FOCUS, |
| 2486 | "computeStackFocus: Setting " + "focused stack to r=" + r |
| 2487 | + " task=" + task); |
| 2488 | } else { |
| 2489 | if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG_FOCUS, |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 2490 | "computeStackFocus: Focused stack already=" + focusedStack); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2491 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2492 | return currentStack; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2493 | } |
| 2494 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2495 | if (canLaunchIntoFocusedStack(r, newTask)) { |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2496 | if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG_FOCUS, |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 2497 | "computeStackFocus: Have a focused stack=" + focusedStack); |
| 2498 | return focusedStack; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2499 | } |
| 2500 | |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 2501 | if (mPreferredDisplayId != DEFAULT_DISPLAY) { |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2502 | // Try to put the activity in a stack on a secondary display. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2503 | stack = mRootWindowContainer.getValidLaunchStackOnDisplay( |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2504 | mPreferredDisplayId, r, aOptions, mLaunchParams); |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2505 | if (stack == null) { |
| 2506 | // If source display is not suitable - look for topmost valid stack in the system. |
| 2507 | if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG_FOCUS, |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 2508 | "computeStackFocus: Can't launch on mPreferredDisplayId=" |
| 2509 | + mPreferredDisplayId + ", looking on all displays."); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2510 | stack = mRootWindowContainer.getNextValidLaunchStack(r, mPreferredDisplayId); |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2511 | } |
| 2512 | } |
| 2513 | if (stack == null) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2514 | stack = mRootWindowContainer.getLaunchStack(r, aOptions, task, ON_TOP); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2515 | } |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2516 | if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG_FOCUS, "computeStackFocus: New stack r=" |
| 2517 | + r + " stackId=" + stack.mStackId); |
| 2518 | return stack; |
| 2519 | } |
| 2520 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2521 | /** Check if provided activity record can launch in currently focused stack. */ |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2522 | // TODO: This method can probably be consolidated into getLaunchStack() below. |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2523 | private boolean canLaunchIntoFocusedStack(ActivityRecord r, boolean newTask) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2524 | final ActivityStack focusedStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2525 | final boolean canUseFocusedStack; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2526 | if (focusedStack.isActivityTypeAssistant()) { |
| 2527 | canUseFocusedStack = r.isActivityTypeAssistant(); |
| 2528 | } else { |
| 2529 | switch (focusedStack.getWindowingMode()) { |
| 2530 | case WINDOWING_MODE_FULLSCREEN: |
| 2531 | // The fullscreen stack can contain any task regardless of if the task is |
| 2532 | // resizeable or not. So, we let the task go in the fullscreen task if it is the |
| 2533 | // focus stack. |
| 2534 | canUseFocusedStack = true; |
| 2535 | break; |
| 2536 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: |
| 2537 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: |
| 2538 | // Any activity which supports split screen can go in the docked stack. |
| 2539 | canUseFocusedStack = r.supportsSplitScreenWindowingMode(); |
| 2540 | break; |
| 2541 | case WINDOWING_MODE_FREEFORM: |
| 2542 | // Any activity which supports freeform can go in the freeform stack. |
| 2543 | canUseFocusedStack = r.supportsFreeform(); |
| 2544 | break; |
| 2545 | default: |
| 2546 | // Dynamic stacks behave similarly to the fullscreen stack and can contain any |
| 2547 | // resizeable task. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2548 | canUseFocusedStack = !focusedStack.isOnHomeDisplay() |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 2549 | && r.canBeLaunchedOnDisplay(focusedStack.getDisplayId()); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2550 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2551 | } |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2552 | return canUseFocusedStack && !newTask |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2553 | // Using the focus stack isn't important enough to override the preferred display. |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 2554 | && (mPreferredDisplayId == focusedStack.getDisplayId()); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 2555 | } |
| 2556 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2557 | private ActivityStack getLaunchStack(ActivityRecord r, int launchFlags, Task task, |
Jorim Jaggi | 4ad9856 | 2016-04-19 20:30:47 -0700 | [diff] [blame] | 2558 | ActivityOptions aOptions) { |
Bryce Lee | a19b5ad | 2017-06-07 16:54:11 -0700 | [diff] [blame] | 2559 | // We are reusing a task, keep the stack! |
| 2560 | if (mReuseTask != null) { |
| 2561 | return mReuseTask.getStack(); |
| 2562 | } |
Jorim Jaggi | b8c5876 | 2016-04-20 17:58:29 -0700 | [diff] [blame] | 2563 | |
Karthik Ravi Shankar | 99493db | 2017-03-08 18:30:19 -0800 | [diff] [blame] | 2564 | if (((launchFlags & FLAG_ACTIVITY_LAUNCH_ADJACENT) == 0) |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 2565 | || mPreferredDisplayId != DEFAULT_DISPLAY) { |
Louis Chang | 3731715 | 2019-05-09 09:53:58 +0800 | [diff] [blame] | 2566 | final boolean onTop = |
| 2567 | (aOptions == null || !aOptions.getAvoidMoveToFront()) && !mLaunchTaskBehind; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2568 | final ActivityStack stack = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2569 | mRootWindowContainer.getLaunchStack(r, aOptions, task, onTop, mLaunchParams, |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 2570 | mRequest.realCallingPid, mRequest.realCallingUid); |
Garfield Tan | 20d9e2f | 2018-11-16 15:42:29 -0800 | [diff] [blame] | 2571 | return stack; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2572 | } |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2573 | // Otherwise handle adjacent launch. |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2574 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2575 | final ActivityStack focusedStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2576 | // The parent activity doesn't want to launch the activity on top of itself, but |
| 2577 | // instead tries to put it onto other side in side-by-side mode. |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 2578 | final ActivityStack parentStack = task != null ? task.getStack(): focusedStack; |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2579 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 2580 | if (parentStack != focusedStack) { |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2581 | // If task's parent stack is not focused - use it during adjacent launch. |
| 2582 | return parentStack; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2583 | } else { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2584 | if (focusedStack != null && task == focusedStack.getTopMostTask()) { |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2585 | // If task is already on top of focused stack - use it. We don't want to move the |
| 2586 | // existing focused task to adjacent stack, just deliver new intent in this case. |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 2587 | return focusedStack; |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2590 | if (parentStack != null && parentStack.inSplitScreenPrimaryWindowingMode()) { |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2591 | // If parent was in docked stack, the natural place to launch another activity |
| 2592 | // will be fullscreen, so it can appear alongside the docked window. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2593 | final int activityType = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2594 | mRootWindowContainer.resolveActivityType(r, mOptions, task); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2595 | return parentStack.getDisplay().getOrCreateStack( |
| 2596 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, activityType, ON_TOP); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2597 | } else { |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2598 | // If the parent is not in the docked stack, we check if there is docked window |
| 2599 | // and if yes, we will launch into that stack. If not, we just put the new |
| 2600 | // activity into parent's stack, because we can't find a better place. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2601 | final ActivityStack dockedStack = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2602 | mRootWindowContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2603 | if (dockedStack != null && !dockedStack.shouldBeVisible(r)) { |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2604 | // There is a docked stack, but it isn't visible, so we can't launch into that. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2605 | return mRootWindowContainer.getLaunchStack(r, aOptions, task, ON_TOP); |
Andrii Kulian | 4ac2a58 | 2016-03-25 00:07:38 -0700 | [diff] [blame] | 2606 | } else { |
| 2607 | return dockedStack; |
| 2608 | } |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | } |
| 2612 | |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2613 | private boolean isLaunchModeOneOf(int mode1, int mode2) { |
| 2614 | return mode1 == mLaunchMode || mode2 == mLaunchMode; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2615 | } |
| 2616 | |
Daichi Hirono | 15a0299 | 2016-04-27 18:47:01 +0900 | [diff] [blame] | 2617 | static boolean isDocumentLaunchesIntoExisting(int flags) { |
| 2618 | return (flags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && |
| 2619 | (flags & Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0; |
| 2620 | } |
liulvping | cfa825f | 2016-09-26 20:00:15 +0800 | [diff] [blame] | 2621 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2622 | ActivityStarter setIntent(Intent intent) { |
| 2623 | mRequest.intent = intent; |
| 2624 | return this; |
| 2625 | } |
| 2626 | |
Bryce Lee | 32e09ef | 2018-03-19 15:29:49 -0700 | [diff] [blame] | 2627 | @VisibleForTesting |
| 2628 | Intent getIntent() { |
| 2629 | return mRequest.intent; |
| 2630 | } |
| 2631 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2632 | ActivityStarter setReason(String reason) { |
| 2633 | mRequest.reason = reason; |
| 2634 | return this; |
| 2635 | } |
| 2636 | |
| 2637 | ActivityStarter setCaller(IApplicationThread caller) { |
| 2638 | mRequest.caller = caller; |
| 2639 | return this; |
| 2640 | } |
| 2641 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2642 | ActivityStarter setResolvedType(String type) { |
| 2643 | mRequest.resolvedType = type; |
| 2644 | return this; |
| 2645 | } |
| 2646 | |
| 2647 | ActivityStarter setActivityInfo(ActivityInfo info) { |
| 2648 | mRequest.activityInfo = info; |
| 2649 | return this; |
| 2650 | } |
| 2651 | |
| 2652 | ActivityStarter setResolveInfo(ResolveInfo info) { |
| 2653 | mRequest.resolveInfo = info; |
| 2654 | return this; |
| 2655 | } |
| 2656 | |
| 2657 | ActivityStarter setVoiceSession(IVoiceInteractionSession voiceSession) { |
| 2658 | mRequest.voiceSession = voiceSession; |
| 2659 | return this; |
| 2660 | } |
| 2661 | |
| 2662 | ActivityStarter setVoiceInteractor(IVoiceInteractor voiceInteractor) { |
| 2663 | mRequest.voiceInteractor = voiceInteractor; |
| 2664 | return this; |
| 2665 | } |
| 2666 | |
| 2667 | ActivityStarter setResultTo(IBinder resultTo) { |
| 2668 | mRequest.resultTo = resultTo; |
| 2669 | return this; |
| 2670 | } |
| 2671 | |
| 2672 | ActivityStarter setResultWho(String resultWho) { |
| 2673 | mRequest.resultWho = resultWho; |
| 2674 | return this; |
| 2675 | } |
| 2676 | |
| 2677 | ActivityStarter setRequestCode(int requestCode) { |
| 2678 | mRequest.requestCode = requestCode; |
| 2679 | return this; |
| 2680 | } |
| 2681 | |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 2682 | /** |
| 2683 | * Sets the pid of the caller who originally started the activity. |
| 2684 | * |
| 2685 | * Normally, the pid/uid would be the calling pid from the binder call. |
| 2686 | * However, in case of a {@link PendingIntent}, the pid/uid pair of the caller is considered |
| 2687 | * the original entity that created the pending intent, in contrast to setRealCallingPid/Uid, |
| 2688 | * which represents the entity who invoked pending intent via {@link PendingIntent#send}. |
| 2689 | */ |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2690 | ActivityStarter setCallingPid(int pid) { |
| 2691 | mRequest.callingPid = pid; |
| 2692 | return this; |
| 2693 | } |
| 2694 | |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 2695 | /** |
| 2696 | * Sets the uid of the caller who originally started the activity. |
| 2697 | * |
| 2698 | * @see #setCallingPid |
| 2699 | */ |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2700 | ActivityStarter setCallingUid(int uid) { |
| 2701 | mRequest.callingUid = uid; |
| 2702 | return this; |
| 2703 | } |
| 2704 | |
| 2705 | ActivityStarter setCallingPackage(String callingPackage) { |
| 2706 | mRequest.callingPackage = callingPackage; |
| 2707 | return this; |
| 2708 | } |
| 2709 | |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 2710 | /** |
| 2711 | * Sets the pid of the caller who requested to launch the activity. |
| 2712 | * |
| 2713 | * The pid/uid represents the caller who launches the activity in this request. |
| 2714 | * It will almost same as setCallingPid/Uid except when processing {@link PendingIntent}: |
| 2715 | * the pid/uid will be the caller who called {@link PendingIntent#send()}. |
| 2716 | * |
| 2717 | * @see #setCallingPid |
| 2718 | */ |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2719 | ActivityStarter setRealCallingPid(int pid) { |
| 2720 | mRequest.realCallingPid = pid; |
| 2721 | return this; |
| 2722 | } |
| 2723 | |
lumark | f65e02d | 2019-09-14 19:25:21 +0800 | [diff] [blame] | 2724 | /** |
| 2725 | * Sets the uid of the caller who requested to launch the activity. |
| 2726 | * |
| 2727 | * @see #setRealCallingPid |
| 2728 | */ |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2729 | ActivityStarter setRealCallingUid(int uid) { |
| 2730 | mRequest.realCallingUid = uid; |
| 2731 | return this; |
| 2732 | } |
| 2733 | |
| 2734 | ActivityStarter setStartFlags(int startFlags) { |
| 2735 | mRequest.startFlags = startFlags; |
| 2736 | return this; |
| 2737 | } |
| 2738 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2739 | ActivityStarter setActivityOptions(SafeActivityOptions options) { |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2740 | mRequest.activityOptions = options; |
| 2741 | return this; |
| 2742 | } |
| 2743 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2744 | ActivityStarter setActivityOptions(Bundle bOptions) { |
| 2745 | return setActivityOptions(SafeActivityOptions.fromBundle(bOptions)); |
| 2746 | } |
| 2747 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2748 | ActivityStarter setIgnoreTargetSecurity(boolean ignoreTargetSecurity) { |
| 2749 | mRequest.ignoreTargetSecurity = ignoreTargetSecurity; |
| 2750 | return this; |
| 2751 | } |
| 2752 | |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 2753 | ActivityStarter setFilterCallingUid(int filterCallingUid) { |
| 2754 | mRequest.filterCallingUid = filterCallingUid; |
| 2755 | return this; |
| 2756 | } |
| 2757 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2758 | ActivityStarter setComponentSpecified(boolean componentSpecified) { |
| 2759 | mRequest.componentSpecified = componentSpecified; |
| 2760 | return this; |
| 2761 | } |
| 2762 | |
| 2763 | ActivityStarter setOutActivity(ActivityRecord[] outActivity) { |
| 2764 | mRequest.outActivity = outActivity; |
| 2765 | return this; |
| 2766 | } |
| 2767 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2768 | ActivityStarter setInTask(Task inTask) { |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2769 | mRequest.inTask = inTask; |
| 2770 | return this; |
| 2771 | } |
| 2772 | |
| 2773 | ActivityStarter setWaitResult(WaitResult result) { |
| 2774 | mRequest.waitResult = result; |
| 2775 | return this; |
| 2776 | } |
| 2777 | |
| 2778 | ActivityStarter setProfilerInfo(ProfilerInfo info) { |
| 2779 | mRequest.profilerInfo = info; |
| 2780 | return this; |
| 2781 | } |
| 2782 | |
| 2783 | ActivityStarter setGlobalConfiguration(Configuration config) { |
| 2784 | mRequest.globalConfig = config; |
| 2785 | return this; |
| 2786 | } |
| 2787 | |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 2788 | ActivityStarter setUserId(int userId) { |
| 2789 | mRequest.userId = userId; |
| 2790 | return this; |
| 2791 | } |
| 2792 | |
Jorim Jaggi | 6fa41c3 | 2018-04-23 18:35:00 +0200 | [diff] [blame] | 2793 | ActivityStarter setAllowPendingRemoteAnimationRegistryLookup(boolean allowLookup) { |
| 2794 | mRequest.allowPendingRemoteAnimationRegistryLookup = allowLookup; |
| 2795 | return this; |
| 2796 | } |
| 2797 | |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 2798 | ActivityStarter setOriginatingPendingIntent(PendingIntentRecord originatingPendingIntent) { |
| 2799 | mRequest.originatingPendingIntent = originatingPendingIntent; |
| 2800 | return this; |
| 2801 | } |
| 2802 | |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 2803 | ActivityStarter setAllowBackgroundActivityStart(boolean allowBackgroundActivityStart) { |
| 2804 | mRequest.allowBackgroundActivityStart = allowBackgroundActivityStart; |
| 2805 | return this; |
| 2806 | } |
| 2807 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2808 | void dump(PrintWriter pw, String prefix) { |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 2809 | prefix = prefix + " "; |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2810 | pw.print(prefix); |
| 2811 | pw.print("mCurrentUser="); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2812 | pw.println(mRootWindowContainer.mCurrentUser); |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2813 | pw.print(prefix); |
| 2814 | pw.print("mLastStartReason="); |
| 2815 | pw.println(mLastStartReason); |
| 2816 | pw.print(prefix); |
| 2817 | pw.print("mLastStartActivityTimeMs="); |
| 2818 | pw.println(DateFormat.getDateTimeInstance().format(new Date(mLastStartActivityTimeMs))); |
| 2819 | pw.print(prefix); |
| 2820 | pw.print("mLastStartActivityResult="); |
| 2821 | pw.println(mLastStartActivityResult); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 2822 | if (mLastStartActivityRecord != null) { |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2823 | pw.print(prefix); |
| 2824 | pw.println("mLastStartActivityRecord:"); |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 2825 | mLastStartActivityRecord.dump(pw, prefix + " ", true /* dumpAll */); |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 2826 | } |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 2827 | if (mStartActivity != null) { |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2828 | pw.print(prefix); |
| 2829 | pw.println("mStartActivity:"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2830 | mStartActivity.dump(pw, prefix + " ", true /* dumpAll */); |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 2831 | } |
| 2832 | if (mIntent != null) { |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2833 | pw.print(prefix); |
| 2834 | pw.print("mIntent="); |
| 2835 | pw.println(mIntent); |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 2836 | } |
| 2837 | if (mOptions != null) { |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2838 | pw.print(prefix); |
| 2839 | pw.print("mOptions="); |
| 2840 | pw.println(mOptions); |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 2841 | } |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2842 | pw.print(prefix); |
| 2843 | pw.print("mLaunchSingleTop="); |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2844 | pw.print(LAUNCH_SINGLE_TOP == mLaunchMode); |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2845 | pw.print(" mLaunchSingleInstance="); |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2846 | pw.print(LAUNCH_SINGLE_INSTANCE == mLaunchMode); |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2847 | pw.print(" mLaunchSingleTask="); |
Bryce Lee | 7daee39 | 2017-10-12 13:46:18 -0700 | [diff] [blame] | 2848 | pw.println(LAUNCH_SINGLE_TASK == mLaunchMode); |
Dianne Hackborn | e676ec7 | 2017-07-25 10:55:08 -0700 | [diff] [blame] | 2849 | pw.print(prefix); |
| 2850 | pw.print("mLaunchFlags=0x"); |
| 2851 | pw.print(Integer.toHexString(mLaunchFlags)); |
| 2852 | pw.print(" mDoResume="); |
| 2853 | pw.print(mDoResume); |
| 2854 | pw.print(" mAddingToTask="); |
| 2855 | pw.println(mAddingToTask); |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 2856 | } |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 2857 | } |