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