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