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