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