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