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