Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 23 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 25 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 26 | import static com.android.server.am.ActivityManagerDebugConfig.*; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 27 | import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 28 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
| 29 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 30 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 31 | import static com.android.server.am.ActivityStackSupervisor.MOVING; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 32 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 33 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 34 | import android.graphics.Point; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 35 | import android.graphics.Rect; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 36 | import android.util.ArraySet; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 37 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 38 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 39 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 40 | import com.android.internal.os.BatteryStatsImpl; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 41 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 42 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 43 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 44 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 45 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 46 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 47 | |
| 48 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 49 | import android.app.ActivityManager; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 50 | import android.app.ActivityManager.StackId; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 51 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 52 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 53 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 54 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 55 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 56 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 57 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 58 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 59 | import android.content.pm.PackageManager; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 60 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 61 | import android.graphics.Bitmap; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 62 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 63 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 64 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 65 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 66 | import android.os.Handler; |
| 67 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 68 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 69 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 70 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 71 | import android.os.RemoteException; |
| 72 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 73 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 74 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 75 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 76 | import android.util.EventLog; |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 77 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 78 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 79 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 80 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 81 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 82 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 83 | import java.lang.ref.WeakReference; |
| 84 | import java.util.ArrayList; |
| 85 | import java.util.Iterator; |
| 86 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 87 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 88 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * State and management of a single stack of activities. |
| 92 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 93 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 94 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 95 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 96 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 97 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 98 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 99 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 100 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 101 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 102 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 103 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 104 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 105 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 106 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 107 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 108 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 109 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 110 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 111 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 112 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 113 | |
| 114 | private static final boolean VALIDATE_TOKENS = false; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 115 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 116 | // Ticks during which we check progress while waiting for an app to launch. |
| 117 | static final int LAUNCH_TICK = 500; |
| 118 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 119 | // How long we wait until giving up on the last activity to pause. This |
| 120 | // is short because it directly impacts the responsiveness of starting the |
| 121 | // next activity. |
| 122 | static final int PAUSE_TIMEOUT = 500; |
| 123 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 124 | // How long we wait for the activity to tell us it has stopped before |
| 125 | // giving up. This is a good amount of time because we really need this |
| 126 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 127 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 128 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 129 | // How long we wait until giving up on an activity telling us it has |
| 130 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 131 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 132 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 133 | // How long until we reset a task when the user returns to it. Currently |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 134 | // disabled. |
| 135 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 136 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 137 | // How long between activity launches that we consider safe to not warn |
| 138 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 139 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 140 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 141 | // Set to false to disable the preview that is shown while a new activity |
| 142 | // is being started. |
| 143 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 144 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 145 | // How long to wait for all background Activities to redraw following a call to |
| 146 | // convertToTranslucent(). |
| 147 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 148 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 149 | // How many activities have to be scheduled to stop to force a stop pass. |
| 150 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 151 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 152 | enum ActivityState { |
| 153 | INITIALIZING, |
| 154 | RESUMED, |
| 155 | PAUSING, |
| 156 | PAUSED, |
| 157 | STOPPING, |
| 158 | STOPPED, |
| 159 | FINISHING, |
| 160 | DESTROYING, |
| 161 | DESTROYED |
| 162 | } |
| 163 | |
| 164 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 165 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 166 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 167 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 168 | /** |
| 169 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 170 | * running) activities. It contains #TaskRecord objects. |
| 171 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 172 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 173 | |
| 174 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 175 | * Used for validating app tokens with window manager. |
| 176 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 177 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 178 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 179 | /** |
| 180 | * List of running activities, sorted by recent usage. |
| 181 | * The first entry in the list is the least recently used. |
| 182 | * It contains HistoryRecord objects. |
| 183 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 184 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 185 | |
| 186 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 187 | * Animations that for the current transition have requested not to |
| 188 | * be considered for the transition animation. |
| 189 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 190 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 193 | * When we are in the process of pausing an activity, before starting the |
| 194 | * next one, this variable holds the activity that is currently being paused. |
| 195 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 196 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * This is the last activity that we put into the paused state. This is |
| 200 | * used to determine if we need to do an activity transition while sleeping, |
| 201 | * when we normally hold the top activity paused. |
| 202 | */ |
| 203 | ActivityRecord mLastPausedActivity = null; |
| 204 | |
| 205 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 206 | * Activities that specify No History must be removed once the user navigates away from them. |
| 207 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 208 | * and finish it later if another activity replaces it on wakeup. |
| 209 | */ |
| 210 | ActivityRecord mLastNoHistoryActivity = null; |
| 211 | |
| 212 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 213 | * Current activity that is resumed, or null if there is none. |
| 214 | */ |
| 215 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 216 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 217 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 218 | * This is the last activity that has been started. It is only used to |
| 219 | * identify when multiple activities are started at once so that the user |
| 220 | * can be warned they may not be in the activity they think they are. |
| 221 | */ |
| 222 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 223 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 224 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 225 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 226 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 227 | // Activity in mTranslucentActivityWaiting is notified via |
| 228 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 229 | // background activity being drawn then the same call will be made with a true value. |
| 230 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 231 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 232 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 233 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 234 | * Set when we know we are going to be calling updateConfiguration() |
| 235 | * soon, so want to skip intermediate config checks. |
| 236 | */ |
| 237 | boolean mConfigWillChange; |
| 238 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 239 | // Whether or not this stack covers the entire screen; by default stacks are fullscreen |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 240 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 241 | // Current bounds of the stack or null if fullscreen. |
| 242 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 243 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 244 | long mLaunchStartTime = 0; |
| 245 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 246 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 247 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 248 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 249 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 250 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 251 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 252 | ArrayList<ActivityStack> mStacks; |
| 253 | /** The attached Display's unique identifier, or -1 if detached */ |
| 254 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 255 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 256 | /** Run all ActivityStacks through this */ |
| 257 | final ActivityStackSupervisor mStackSupervisor; |
| 258 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 259 | private final LaunchingTaskPositioner mTaskPositioner; |
| 260 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 261 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 262 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 263 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 264 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 265 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 266 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 267 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 268 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 269 | |
| 270 | static class ScheduleDestroyArgs { |
| 271 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 272 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 273 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 274 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 275 | mReason = reason; |
| 276 | } |
| 277 | } |
| 278 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 279 | final Handler mHandler; |
| 280 | |
| 281 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 282 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 283 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 284 | super(looper); |
| 285 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 286 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 287 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 288 | public void handleMessage(Message msg) { |
| 289 | switch (msg.what) { |
| 290 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 291 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 292 | // We don't at this point know if the activity is fullscreen, |
| 293 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 294 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 295 | synchronized (mService) { |
| 296 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 297 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 298 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 299 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 300 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 301 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 302 | case LAUNCH_TICK_MSG: { |
| 303 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 304 | synchronized (mService) { |
| 305 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 306 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 310 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 311 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 312 | // We don't at this point know if the activity is fullscreen, |
| 313 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 314 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 315 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 316 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 317 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 318 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 319 | case STOP_TIMEOUT_MSG: { |
| 320 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 321 | // We don't at this point know if the activity is fullscreen, |
| 322 | // so we need to be conservative and assume it isn't. |
| 323 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 324 | synchronized (mService) { |
| 325 | if (r.isInHistory()) { |
| 326 | activityStoppedLocked(r, null, null, null); |
| 327 | } |
| 328 | } |
| 329 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 330 | case DESTROY_ACTIVITIES_MSG: { |
| 331 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 332 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 333 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 334 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 335 | } break; |
| 336 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 337 | synchronized (mService) { |
| 338 | notifyActivityDrawnLocked(null); |
| 339 | } |
| 340 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 341 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 342 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 343 | final ActivityRecord r = getVisibleBehindActivity(); |
| 344 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 345 | if (r != null) { |
| 346 | mService.killAppAtUsersRequest(r.app, null); |
| 347 | } |
| 348 | } |
| 349 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 354 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 355 | int count = 0; |
| 356 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 357 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 358 | } |
| 359 | return count; |
| 360 | } |
| 361 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 362 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 363 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 364 | mActivityContainer = activityContainer; |
| 365 | mStackSupervisor = activityContainer.getOuter(); |
| 366 | mService = mStackSupervisor.mService; |
| 367 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 368 | mWindowManager = mService.mWindowManager; |
| 369 | mStackId = activityContainer.mStackId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 370 | mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 371 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 372 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 373 | ? new LaunchingTaskPositioner() : null; |
| 374 | } |
| 375 | |
| 376 | void attachDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 377 | mDisplayId = activityDisplay.mDisplayId; |
| 378 | mStacks = activityDisplay.mStacks; |
| 379 | mBounds = mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId, onTop); |
| 380 | mFullscreen = mBounds == null; |
| 381 | if (mTaskPositioner != null) { |
| 382 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 383 | mTaskPositioner.configure(mBounds); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | void detachDisplay() { |
| 388 | mDisplayId = Display.INVALID_DISPLAY; |
| 389 | mStacks = null; |
| 390 | if (mTaskPositioner != null) { |
| 391 | mTaskPositioner.reset(); |
| 392 | } |
| 393 | mWindowManager.detachStack(mStackId); |
| 394 | } |
| 395 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 396 | public void getDisplaySize(Point out) { |
| 397 | mActivityContainer.mActivityDisplay.mDisplay.getSize(out); |
| 398 | } |
| 399 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 400 | void setBounds(Rect bounds) { |
| 401 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 402 | if (mTaskPositioner != null) { |
| 403 | mTaskPositioner.configure(bounds); |
| 404 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 405 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 406 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 407 | boolean okToShowLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 408 | return mStackSupervisor.okToShowLocked(r); |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 411 | final ActivityRecord topRunningActivityLocked() { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 412 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 413 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 414 | if (r != null) { |
| 415 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 416 | } |
| 417 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 418 | return null; |
| 419 | } |
| 420 | |
| 421 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 422 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 423 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 424 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 425 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 426 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 427 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 428 | return r; |
| 429 | } |
| 430 | } |
| 431 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 432 | return null; |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 437 | * optional skip-over modes. It is intended for use with the ActivityController hook only. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 438 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 439 | * @param token If non-null, any history records matching this token will be skipped. |
| 440 | * @param taskId If non-zero, we'll attempt to skip over records with the same task ID. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 441 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 442 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 443 | */ |
| 444 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 445 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 446 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 447 | if (task.taskId == taskId) { |
| 448 | continue; |
| 449 | } |
| 450 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 451 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 452 | final ActivityRecord r = activities.get(i); |
| 453 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 454 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 455 | return r; |
| 456 | } |
| 457 | } |
| 458 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 459 | return null; |
| 460 | } |
| 461 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 462 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 463 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 464 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 465 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 466 | final ActivityRecord r = activities.get(activityNdx); |
| 467 | if (!r.finishing) { |
| 468 | return r; |
| 469 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 472 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 475 | final TaskRecord topTask() { |
| 476 | final int size = mTaskHistory.size(); |
| 477 | if (size > 0) { |
| 478 | return mTaskHistory.get(size - 1); |
| 479 | } |
| 480 | return null; |
| 481 | } |
| 482 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 483 | TaskRecord taskForIdLocked(int id) { |
| 484 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 485 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 486 | if (task.taskId == id) { |
| 487 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 488 | } |
| 489 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 490 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 493 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 494 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 495 | return isInStackLocked(r); |
| 496 | } |
| 497 | |
| 498 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 499 | if (r == null) { |
| 500 | return null; |
| 501 | } |
| 502 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 503 | if (task != null && task.stack != null |
| 504 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 505 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 506 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 507 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 508 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 509 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 510 | } |
| 511 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 512 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 513 | final boolean hadit = mLRUActivities.remove(r); |
| 514 | mLRUActivities.add(r); |
| 515 | return hadit; |
| 516 | } |
| 517 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 518 | final boolean isHomeStack() { |
| 519 | return mStackId == HOME_STACK_ID; |
| 520 | } |
| 521 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 522 | final boolean isOnHomeDisplay() { |
| 523 | return isAttached() && |
| 524 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 525 | } |
| 526 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 527 | void moveToFront(String reason) { |
| 528 | moveToFront(reason, null); |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * @param reason The reason for moving the stack to the front. |
| 533 | * @param task If non-null, the task will be moved to the top of the stack. |
| 534 | * */ |
| 535 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 536 | if (!isAttached()) { |
| 537 | return; |
| 538 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 539 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 540 | mStacks.remove(this); |
| 541 | int addIndex = mStacks.size(); |
| 542 | |
| 543 | if (addIndex > 0) { |
| 544 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 545 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 546 | // If the top stack is always on top, we move this stack just below it. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 547 | addIndex--; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 548 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | mStacks.add(addIndex, this); |
| 552 | |
| 553 | // TODO(multi-display): Needs to also work if focus is moving to the non-home display. |
| 554 | if (isOnHomeDisplay()) { |
| 555 | mStackSupervisor.setFocusStack(reason, this); |
| 556 | } |
| 557 | if (task != null) { |
| 558 | insertTaskAtTop(task, null); |
| 559 | } else { |
| 560 | task = topTask(); |
| 561 | } |
| 562 | if (task != null) { |
| 563 | mWindowManager.moveTaskToTop(task.taskId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 564 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | final boolean isAttached() { |
| 568 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 571 | /** |
| 572 | * Returns the top activity in any existing task matching the given |
| 573 | * Intent. Returns null if no such task is found. |
| 574 | */ |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 575 | ActivityRecord findTaskLocked(ActivityRecord target) { |
| 576 | Intent intent = target.intent; |
| 577 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 578 | ComponentName cls = intent.getComponent(); |
| 579 | if (info.targetActivity != null) { |
| 580 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 581 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 582 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 583 | boolean isDocument = intent != null & intent.isDocument(); |
| 584 | // If documentData is non-null then it must match the existing task data. |
| 585 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 586 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 587 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + target + " in " + this); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 588 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 589 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 590 | if (task.voiceSession != null) { |
| 591 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 592 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 593 | continue; |
| 594 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 595 | if (task.userId != userId) { |
| 596 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 597 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 598 | continue; |
| 599 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 600 | final ActivityRecord r = task.getTopActivity(); |
| 601 | if (r == null || r.finishing || r.userId != userId || |
| 602 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 603 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 604 | continue; |
| 605 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 606 | if (r.mActivityType != target.mActivityType) { |
| 607 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 608 | continue; |
| 609 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 610 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 611 | final Intent taskIntent = task.intent; |
| 612 | final Intent affinityIntent = task.affinityIntent; |
| 613 | final boolean taskIsDocument; |
| 614 | final Uri taskDocumentData; |
| 615 | if (taskIntent != null && taskIntent.isDocument()) { |
| 616 | taskIsDocument = true; |
| 617 | taskDocumentData = taskIntent.getData(); |
| 618 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 619 | taskIsDocument = true; |
| 620 | taskDocumentData = affinityIntent.getData(); |
| 621 | } else { |
| 622 | taskIsDocument = false; |
| 623 | taskDocumentData = null; |
| 624 | } |
| 625 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 626 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 627 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 628 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 629 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 630 | if (!isDocument && !taskIsDocument && task.rootAffinity != null) { |
| 631 | if (task.rootAffinity.equals(target.taskAffinity)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 632 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 633 | return r; |
| 634 | } |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 635 | } else if (taskIntent != null && taskIntent.getComponent() != null && |
| 636 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 637 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 638 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 639 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 640 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 641 | "For Intent " + intent + " bringing to top: " + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 642 | return r; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 643 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 644 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 645 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 646 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 647 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 648 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 649 | "For Intent " + intent + " bringing to top: " + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 650 | return r; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 651 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | return null; |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * Returns the first activity (starting from the top of the stack) that |
| 659 | * is the same as the given activity. Returns null if no such activity |
| 660 | * is found. |
| 661 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 662 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 663 | ComponentName cls = intent.getComponent(); |
| 664 | if (info.targetActivity != null) { |
| 665 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 666 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 667 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 668 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 669 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 670 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 671 | final boolean notCurrentUserTask = |
| 672 | !mStackSupervisor.isCurrentProfileLocked(task.userId); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 673 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 674 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 675 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 676 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 677 | if (notCurrentUserTask && (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 678 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 679 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 680 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 681 | return r; |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | return null; |
| 687 | } |
| 688 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 689 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 690 | * Move the activities around in the stack to bring a user to the foreground. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 691 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 692 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 693 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 694 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 695 | } |
| 696 | mCurrentUser = userId; |
| 697 | |
| 698 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 699 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 700 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 701 | final TaskRecord task = mTaskHistory.get(i); |
| 702 | |
| 703 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 704 | // okay to show the activity when locked. |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 705 | if (mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 706 | || task.topRunningActivityLocked() != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 707 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 708 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 709 | mTaskHistory.remove(i); |
| 710 | mTaskHistory.add(task); |
| 711 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 712 | // Use same value for i. |
| 713 | } else { |
| 714 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 715 | } |
| 716 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 717 | if (VALIDATE_TOKENS) { |
| 718 | validateAppTokensLocked(); |
| 719 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 722 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 723 | r.state = ActivityState.RESUMED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 724 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 725 | "Moving to RESUMED: " + r + " (starting new instance)"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 726 | r.stopped = false; |
| 727 | mResumedActivity = r; |
| 728 | r.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 729 | mRecentTasks.addLocked(r.task); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 730 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 731 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 732 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 733 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 734 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 737 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 738 | if (r != null) { |
| 739 | mRecentTasks.addLocked(r.task); |
| 740 | r.task.touchActiveTime(); |
| 741 | } |
| 742 | } |
| 743 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 744 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 745 | if (mFullyDrawnStartTime != 0) { |
| 746 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 747 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 748 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 749 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 750 | } |
| 751 | |
| 752 | private void stopFullyDrawnTraceIfNeeded() { |
| 753 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 754 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 755 | mFullyDrawnStartTime = 0; |
| 756 | } |
| 757 | } |
| 758 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 759 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 760 | if (r.displayStartTime == 0) { |
| 761 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 762 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 763 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 764 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 765 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 766 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 767 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 768 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 769 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 770 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 771 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 772 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 773 | // Make sure that there is no activity waiting for this to launch. |
| 774 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 775 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 776 | } else { |
| 777 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 778 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 779 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 782 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 783 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 784 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 785 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 786 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 787 | activities.get(activityNdx).setSleeping(false); |
| 788 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 789 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 790 | if (mPausingActivity != null) { |
| 791 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 792 | activityPausedLocked(mPausingActivity.appToken, true); |
| 793 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 796 | /** |
| 797 | * @return true if something must be done before going to sleep. |
| 798 | */ |
| 799 | boolean checkReadyForSleepLocked() { |
| 800 | if (mResumedActivity != null) { |
| 801 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 802 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 803 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 804 | "Sleep => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 805 | startPausingLocked(false, true, false, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 806 | return true; |
| 807 | } |
| 808 | if (mPausingActivity != null) { |
| 809 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 810 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still waiting to pause " + mPausingActivity); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 811 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 812 | } |
| 813 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 814 | if (hasVisibleBehindActivity()) { |
| 815 | // Stop visible behind activity before going to sleep. |
| 816 | final ActivityRecord r = mActivityContainer.mActivityDisplay.mVisibleBehindActivity; |
| 817 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 818 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 819 | "Sleep still waiting to stop visible behind " + r); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 820 | return true; |
| 821 | } |
| 822 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 823 | return false; |
| 824 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 825 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 826 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 827 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 828 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 829 | // Make sure any stopped but visible activities are now sleeping. |
| 830 | // This ensures that the activity's onStop() is called. |
| 831 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 832 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 833 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 834 | final ActivityRecord r = activities.get(activityNdx); |
| 835 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 836 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 837 | } |
| 838 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 839 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 840 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 841 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 842 | public final Bitmap screenshotActivitiesLocked(ActivityRecord who) { |
| 843 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 844 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 845 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 846 | return null; |
| 847 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 848 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 849 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 850 | // This is an optimization -- since we never show Home or Recents within Recents itself, |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 851 | // we can just go ahead and skip taking the screenshot if this is the home stack. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 852 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 853 | return null; |
| 854 | } |
| 855 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 856 | int w = mService.mThumbnailWidth; |
| 857 | int h = mService.mThumbnailHeight; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 858 | float scale = 1f; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 859 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 860 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 861 | |
| 862 | // When this flag is set, we currently take the fullscreen screenshot of the activity |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 863 | // but scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to |
| 864 | // use within SystemUI while keeping memory usage low. |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 865 | if (mService.mTakeFullscreenScreenshots) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 866 | w = h = -1; |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 867 | scale = 0.5f; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 868 | } |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 869 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 870 | w, h, scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 871 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 872 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 873 | return null; |
| 874 | } |
| 875 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 876 | /** |
| 877 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 878 | * is already an activity being paused or there is no resumed activity. |
| 879 | * |
| 880 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 881 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 882 | * screen turning off). |
| 883 | * @param resuming True if this is being called as part of resuming the top activity, so |
| 884 | * we shouldn't try to instigate a resume here. |
| 885 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 886 | * set to true, we will immediately complete the pause here before returning. |
| 887 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 888 | * it to tell us when it is done. |
| 889 | */ |
| 890 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming, |
| 891 | boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 892 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 893 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 894 | + " state=" + mPausingActivity.state); |
| 895 | if (!mService.isSleeping()) { |
| 896 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 897 | // Because activity will be paused immediately after resume, just let pause |
| 898 | // be completed by the order of activity paused from clients. |
| 899 | completePauseLocked(false); |
| 900 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 901 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 902 | ActivityRecord prev = mResumedActivity; |
| 903 | if (prev == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 904 | if (!resuming) { |
| 905 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
| 906 | mStackSupervisor.resumeTopActivitiesLocked(); |
| 907 | } |
| 908 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 909 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 910 | |
| 911 | if (mActivityContainer.mParentActivity == null) { |
| 912 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 913 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 916 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 917 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 918 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 919 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 920 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 921 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 922 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 923 | prev.state = ActivityState.PAUSING; |
| 924 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 925 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 926 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | 979f5ed | 2015-10-12 11:22:50 -0700 | [diff] [blame] | 927 | if (mService.mHasRecents |
| 928 | && (next == null || next.noDisplay || next.task != prev.task || uiSleeping)) { |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 929 | prev.mUpdateTaskThumbnailWhenHidden = true; |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 930 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 931 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 932 | |
| 933 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 934 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 935 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 936 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 937 | try { |
| 938 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 939 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 940 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 941 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 942 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 943 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 944 | } catch (Exception e) { |
| 945 | // Ignore exception, if process died other code will cleanup. |
| 946 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 947 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 948 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 949 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 950 | } |
| 951 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 952 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 953 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 954 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | // If we are not going to sleep, we want to ensure the device is |
| 958 | // awake until the next activity is started. |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 959 | if (!uiSleeping && !mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 960 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 963 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 964 | // Have the window manager pause its key dispatching until the new |
| 965 | // activity has started. If we're pausing the activity just because |
| 966 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 967 | // key dispatch; the same activity will pick it up again on wakeup. |
| 968 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 969 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 970 | } else if (DEBUG_PAUSE) { |
| 971 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 974 | if (dontWait) { |
| 975 | // If the caller said they don't want to wait for the pause, then complete |
| 976 | // the pause now. |
| 977 | completePauseLocked(false); |
| 978 | return false; |
| 979 | |
| 980 | } else { |
| 981 | // Schedule a pause timeout in case the app doesn't respond. |
| 982 | // We don't give it much time because this directly impacts the |
| 983 | // responsiveness seen by the user. |
| 984 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 985 | msg.obj = prev; |
| 986 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 987 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 988 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 989 | return true; |
| 990 | } |
| 991 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 992 | } else { |
| 993 | // This activity failed to schedule the |
| 994 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 995 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 996 | if (!resuming) { |
| 997 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
| 998 | } |
| 999 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1000 | } |
| 1001 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1002 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1003 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1004 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1005 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1006 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1007 | final ActivityRecord r = isInStackLocked(token); |
| 1008 | if (r != null) { |
| 1009 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1010 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1011 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1012 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1013 | completePauseLocked(true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1014 | } else { |
| 1015 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1016 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1017 | mPausingActivity != null |
| 1018 | ? mPausingActivity.shortComponentName : "(none)"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1019 | if (r.state == ActivityState.PAUSING) { |
| 1020 | r.state = ActivityState.PAUSED; |
| 1021 | if (r.finishing) { |
| 1022 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1023 | "Executing finish of failed to pause activity: " + r); |
| 1024 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1025 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1026 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1031 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 1032 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 1033 | if (r.state != ActivityState.STOPPING) { |
| 1034 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 1035 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1036 | return; |
| 1037 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1038 | if (persistentState != null) { |
| 1039 | r.persistentState = persistentState; |
| 1040 | mService.notifyTaskPersisterLocked(r.task, false); |
| 1041 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1042 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + r + ": " + icicle); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1043 | if (icicle != null) { |
| 1044 | // If icicle is null, this is happening due to a timeout, so we |
| 1045 | // haven't really saved the state. |
| 1046 | r.icicle = icicle; |
| 1047 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 1048 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1049 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1050 | } |
| 1051 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1052 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + r + " (stop complete)"); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1053 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1054 | r.stopped = true; |
| 1055 | r.state = ActivityState.STOPPED; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1056 | if (mActivityContainer.mActivityDisplay.mVisibleBehindActivity == r) { |
| 1057 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1058 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1059 | if (r.finishing) { |
| 1060 | r.clearOptionsLocked(); |
| 1061 | } else { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1062 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1063 | destroyActivityLocked(r, true, "stop-config"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1064 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1065 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1066 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1067 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1072 | private void completePauseLocked(boolean resumeNext) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1073 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1074 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1075 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1076 | if (prev != null) { |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1077 | final boolean wasStopping = prev.state == ActivityState.STOPPING; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1078 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1079 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1080 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1081 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1082 | } else if (prev.app != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1083 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending stop: " + prev); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1084 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1085 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1086 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1087 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1088 | if (prev.configDestroy) { |
| 1089 | // The previous is being paused because the configuration |
| 1090 | // is changing, which means it is actually stopping... |
| 1091 | // To juggle the fact that we are also starting a new |
| 1092 | // instance right now, we need to first completely stop |
| 1093 | // the current instance before starting the new one. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1094 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Destroying after pause: " + prev); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1095 | destroyActivityLocked(prev, true, "pause-config"); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1096 | } else if (wasStopping) { |
| 1097 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1098 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1099 | // We don't need to schedule another stop, we only need to let it happen. |
| 1100 | prev.state = ActivityState.STOPPING; |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 1101 | } else if (!hasVisibleBehindActivity() || mService.isSleepingOrShuttingDown()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1102 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1103 | // stopping. |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1104 | addToStopping(prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1107 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "App died during pause, not stopping: " + prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1108 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1109 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1110 | // It is possible the activity was freezing the screen before it was paused. |
| 1111 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1112 | // since it is no longer visible. |
| 1113 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1114 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1115 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1116 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1117 | if (resumeNext) { |
| 1118 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
| 1119 | if (!mService.isSleepingOrShuttingDown()) { |
| 1120 | mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null); |
| 1121 | } else { |
| 1122 | mStackSupervisor.checkReadyForSleepLocked(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1123 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1124 | if (top == null || (prev != null && top != prev)) { |
| 1125 | // If there are no more activities available to run, |
| 1126 | // do resume anyway to start something. Also if the top |
| 1127 | // activity on the stack is not the just paused activity, |
| 1128 | // we need to go ahead and resume it to ensure we complete |
| 1129 | // an in-flight app switch. |
| 1130 | mStackSupervisor.resumeTopActivitiesLocked(topStack, null, null); |
| 1131 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1132 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1133 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1134 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1135 | if (prev != null) { |
| 1136 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1137 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1138 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1139 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1140 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1141 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1142 | if (diff > 0) { |
| 1143 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1144 | synchronized (bsi) { |
| 1145 | BatteryStatsImpl.Uid.Proc ps = |
| 1146 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1147 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1148 | if (ps != null) { |
| 1149 | ps.addForegroundTimeLocked(diff); |
| 1150 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1154 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1155 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1156 | |
| 1157 | // Notfiy when the task stack has changed |
| 1158 | mService.notifyTaskStackChangedLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1161 | private void addToStopping(ActivityRecord r) { |
| 1162 | mStackSupervisor.mStoppingActivities.add(r); |
| 1163 | if (mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE || |
| 1164 | r.frontOfTask && mTaskHistory.size() <= 1) { |
| 1165 | // If we already have a few activities waiting to stop, |
| 1166 | // then give up on things going idle and start clearing |
| 1167 | // them out. Or if r is the last of activity of the last task the stack |
| 1168 | // will be empty and must be cleared immediately. |
| 1169 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "To many pending stops, forcing idle"); |
| 1170 | mStackSupervisor.scheduleIdleLocked(); |
| 1171 | } else { |
| 1172 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1173 | } |
| 1174 | } |
| 1175 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1176 | /** |
| 1177 | * Once we know that we have asked an application to put an activity in |
| 1178 | * the resumed state (either by launching it or explicitly telling it), |
| 1179 | * this function updates the rest of our state to match that fact. |
| 1180 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1181 | private void completeResumeLocked(ActivityRecord next) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1182 | next.idle = false; |
| 1183 | next.results = null; |
| 1184 | next.newIntents = null; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1185 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1186 | if (next.isHomeActivity()) { |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1187 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1188 | if (app != null && app != mService.mHomeProcess) { |
| 1189 | mService.mHomeProcess = app; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1193 | if (next.nowVisible) { |
| 1194 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1195 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1196 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1197 | |
| 1198 | // schedule an idle timeout in case the app doesn't do it for us. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1199 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1200 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1201 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1202 | |
| 1203 | next.resumeKeyDispatchingLocked(); |
| 1204 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1205 | |
| 1206 | // Mark the point when the activity is resuming |
| 1207 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1208 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1209 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1210 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1211 | } else { |
| 1212 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1213 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1214 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1215 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1216 | |
| 1217 | if (mActivityContainer.mActivityDisplay.mVisibleBehindActivity == next) { |
| 1218 | // When resuming an activity, require it to call requestVisibleBehind() again. |
| 1219 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(null); |
| 1220 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1223 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1224 | r.visible = visible; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1225 | if (!visible && r.mUpdateTaskThumbnailWhenHidden) { |
| 1226 | r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null); |
| 1227 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1228 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1229 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1230 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1231 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1232 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1233 | container.setVisible(visible); |
| 1234 | } |
| 1235 | } |
| 1236 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1237 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1238 | // otherwise return null; |
| 1239 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1240 | TaskRecord task = r.task; |
| 1241 | if (task == null) { |
| 1242 | return null; |
| 1243 | } |
| 1244 | |
| 1245 | ActivityStack stack = task.stack; |
| 1246 | if (stack == null) { |
| 1247 | return null; |
| 1248 | } |
| 1249 | |
| 1250 | int stackNdx = mStacks.indexOf(stack); |
| 1251 | |
| 1252 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1253 | int taskNdx = tasks.indexOf(task); |
| 1254 | |
| 1255 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1256 | int activityNdx = activities.indexOf(r) + 1; |
| 1257 | |
| 1258 | final int numStacks = mStacks.size(); |
| 1259 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1260 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1261 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1262 | final int numTasks = tasks.size(); |
| 1263 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1264 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1265 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1266 | final int numActivities = activities.size(); |
| 1267 | while (activityNdx < numActivities) { |
| 1268 | final ActivityRecord activity = activities.get(activityNdx); |
| 1269 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1270 | return historyStack.mFullscreen |
| 1271 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1272 | } |
| 1273 | ++activityNdx; |
| 1274 | } |
| 1275 | activityNdx = 0; |
| 1276 | ++taskNdx; |
| 1277 | } |
| 1278 | taskNdx = 0; |
| 1279 | ++stackNdx; |
| 1280 | } |
| 1281 | |
| 1282 | return null; |
| 1283 | } |
| 1284 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1285 | private ActivityStack getNextVisibleStackLocked() { |
| 1286 | ArrayList<ActivityStack> stacks = mStacks; |
| 1287 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1288 | if (parent != null) { |
| 1289 | stacks = parent.task.stack.mStacks; |
| 1290 | } |
| 1291 | if (stacks != null) { |
| 1292 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1293 | ActivityStack stack = stacks.get(i); |
| 1294 | if (stack != this && stack.isStackVisibleLocked()) { |
| 1295 | return stack; |
| 1296 | } |
| 1297 | } |
| 1298 | } |
| 1299 | return null; |
| 1300 | } |
| 1301 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1302 | /** Returns true if the stack contains a fullscreen task. */ |
| 1303 | private boolean hasFullscreenTask() { |
| 1304 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1305 | final TaskRecord task = mTaskHistory.get(i); |
| 1306 | if (task.mFullscreen) { |
| 1307 | return true; |
| 1308 | } |
| 1309 | } |
| 1310 | return false; |
| 1311 | } |
| 1312 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1313 | private boolean hasTranslucentActivity(ActivityStack stack) { |
| 1314 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1315 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1316 | final TaskRecord task = tasks.get(taskNdx); |
| 1317 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1318 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1319 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1320 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1321 | // Conditions for an activity to obscure the stack we're |
| 1322 | // examining: |
| 1323 | // 1. Not Finishing AND Visible AND: |
| 1324 | // 2. Either: |
| 1325 | // - Full Screen Activity OR |
| 1326 | // - On top of Home and our stack is NOT home |
| 1327 | if (!r.finishing && r.visible && (r.fullscreen || |
| 1328 | (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()))) { |
| 1329 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1333 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /** Returns true if the stack is considered visible. */ |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1337 | private boolean isStackVisibleLocked() { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1338 | if (!isAttached()) { |
| 1339 | return false; |
| 1340 | } |
| 1341 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1342 | if (mStackSupervisor.isFrontStack(this) || mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1343 | return true; |
| 1344 | } |
| 1345 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1346 | final int stackIndex = mStacks.indexOf(this); |
| 1347 | |
| 1348 | if (stackIndex == mStacks.size() - 1) { |
| 1349 | Slog.wtf(TAG, |
| 1350 | "Stack=" + this + " isn't front stack but is at the top of the stack list"); |
| 1351 | return false; |
| 1352 | } |
| 1353 | |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1354 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 1355 | if (isLockscreenShown && !StackId.isAllowedOverLockscreen(mStackId)) { |
| 1356 | return false; |
| 1357 | } |
| 1358 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1359 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1360 | final int focusedStackId = focusedStack.mStackId; |
| 1361 | |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1362 | if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 1363 | && hasVisibleBehindActivity() && focusedStackId == HOME_STACK_ID) { |
| 1364 | // The fullscreen stack should be visible if it has a visible behind activity behind |
| 1365 | // the home stack that will be translucent. |
| 1366 | return true; |
| 1367 | } |
| 1368 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1369 | if (mStackId == DOCKED_STACK_ID) { |
| 1370 | // Docked stack is always visible, except in the case where the home activity |
| 1371 | // is the top running activity in the focused home stack. |
| 1372 | if (focusedStackId != HOME_STACK_ID) { |
| 1373 | return true; |
| 1374 | } |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1375 | ActivityRecord topHomeActivity = focusedStack.topRunningActivityLocked(); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1376 | return topHomeActivity == null || !topHomeActivity.isHomeActivity(); |
| 1377 | } |
| 1378 | |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1379 | // Find the first stack below focused stack that actually got something visible. |
| 1380 | int belowFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1381 | while (belowFocusedIndex >= 0 && |
| 1382 | mStacks.get(belowFocusedIndex).topRunningActivityLocked() == null) { |
| 1383 | belowFocusedIndex--; |
| 1384 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1385 | if ((focusedStackId == DOCKED_STACK_ID || focusedStackId == PINNED_STACK_ID) |
| 1386 | && stackIndex == belowFocusedIndex) { |
| 1387 | // Stacks directly behind the docked or pinned stack are always visible. |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1388 | return true; |
| 1389 | } |
| 1390 | |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1391 | if (focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 1392 | && hasTranslucentActivity(focusedStack)) { |
| 1393 | // Stacks behind the fullscreen stack with a translucent activity are always |
| 1394 | // visible so they can act as a backdrop to the translucent activity. |
| 1395 | // For example, dialog activities |
| 1396 | if (stackIndex == belowFocusedIndex) { |
| 1397 | return true; |
| 1398 | } |
| 1399 | if (belowFocusedIndex >= 0) { |
| 1400 | final ActivityStack stack = mStacks.get(belowFocusedIndex); |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1401 | if ((stack.mStackId == DOCKED_STACK_ID || stack.mStackId == PINNED_STACK_ID) |
| 1402 | && stackIndex == (belowFocusedIndex - 1)) { |
| 1403 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1404 | // complete backdrop to the translucent activity when the docked stack is up. |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1405 | return true; |
| 1406 | } |
| 1407 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1410 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1411 | // Visibility of any static stack should have been determined by the conditions above. |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1412 | return false; |
| 1413 | } |
| 1414 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1415 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1416 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1417 | |
| 1418 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1419 | continue; |
| 1420 | } |
| 1421 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1422 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1423 | // These stacks can't have any dynamic stacks visible behind them. |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1424 | return false; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1425 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1426 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1427 | if (!hasTranslucentActivity(stack)) { |
| 1428 | return false; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | return true; |
| 1433 | } |
| 1434 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1435 | final int rankTaskLayers(int baseLayer) { |
| 1436 | int layer = 0; |
| 1437 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1438 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1439 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1440 | if (r == null || r.finishing || !r.visible) { |
| 1441 | task.mLayerRank = -1; |
| 1442 | } else { |
| 1443 | task.mLayerRank = baseLayer + layer++; |
| 1444 | } |
| 1445 | } |
| 1446 | return layer; |
| 1447 | } |
| 1448 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1449 | /** |
| 1450 | * Make sure that all activities that need to be visible (that is, they |
| 1451 | * currently can be seen by the user) actually are. |
| 1452 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1453 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1454 | boolean preserveWindows) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1455 | ActivityRecord top = topRunningActivityLocked(); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1456 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1457 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1458 | if (top != null) { |
| 1459 | checkTranslucentActivityWaiting(top); |
| 1460 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1461 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1462 | // If the top activity is not fullscreen, then we need to |
| 1463 | // make sure any activities under it are now visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1464 | boolean aboveTop = top != null; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1465 | final boolean stackInvisible = !isStackVisibleLocked(); |
| 1466 | boolean behindFullscreenActivity = stackInvisible; |
Wale Ogunwale | addd00e | 2015-04-04 17:10:50 -0700 | [diff] [blame] | 1467 | boolean noStackActivityResumed = (isInStackLocked(starting) == null); |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1468 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1469 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1470 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1471 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1472 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1473 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1474 | final ActivityRecord r = activities.get(activityNdx); |
| 1475 | if (r.finishing) { |
| 1476 | continue; |
| 1477 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1478 | final boolean isTop = r == top; |
| 1479 | if (aboveTop && !isTop) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1480 | continue; |
| 1481 | } |
| 1482 | aboveTop = false; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1483 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1484 | // but must be drawn initially for the animation as though they were visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1485 | if ((!behindFullscreenActivity || r.mLaunchTaskBehind) |
| 1486 | && okToShowLocked(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1487 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1488 | "Make visible? " + r + " finishing=" + r.finishing |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1489 | + " state=" + r.state); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1490 | // First: if this is not the current activity being started, make |
| 1491 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1492 | if (r != starting) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1493 | ensureActivityConfigurationLocked(r, 0, preserveWindows); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1494 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1495 | |
| 1496 | if (r.app == null || r.app.thread == null) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1497 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1498 | noStackActivityResumed, r)) { |
| 1499 | if (activityNdx >= activities.size()) { |
| 1500 | // Record may be removed if its process needs to restart. |
| 1501 | activityNdx = activities.size() - 1; |
| 1502 | } else { |
| 1503 | noStackActivityResumed = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1504 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1505 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1506 | } else if (r.visible) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1507 | // If this activity is already visible, then there is nothing to do here. |
| 1508 | if (handleAlreadyVisible(r)) { |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1509 | noStackActivityResumed = false; |
| 1510 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1511 | } else { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1512 | makeVisible(starting, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1513 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1514 | // Aggregate current change flags. |
| 1515 | configChanges |= r.configChangeFlags; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1516 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1517 | behindFullscreenActivity, task, r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1518 | } else { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1519 | makeInvisible(stackInvisible, behindFullscreenActivity, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1520 | } |
| 1521 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1522 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1523 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1524 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1525 | // status of an activity in a previous task affects other. |
| 1526 | behindFullscreenActivity = stackInvisible; |
| 1527 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1528 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1529 | |
| 1530 | if (mTranslucentActivityWaiting != null && |
| 1531 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1532 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1533 | notifyActivityDrawnLocked(null); |
| 1534 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1535 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1536 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1537 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 1538 | if (mTranslucentActivityWaiting != top) { |
| 1539 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1540 | if (mTranslucentActivityWaiting != null) { |
| 1541 | // Call the callback with a timeout indication. |
| 1542 | notifyActivityDrawnLocked(null); |
| 1543 | mTranslucentActivityWaiting = null; |
| 1544 | } |
| 1545 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1550 | boolean isTop, boolean noStackActivityResumed, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1551 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 1552 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 1553 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 1554 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1555 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1556 | // This activity needs to be visible, but isn't even running... |
| 1557 | // get it started and resume if no other stack in this stack is resumed. |
| 1558 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 1559 | if (r != starting) { |
| 1560 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1561 | } |
| 1562 | if (!r.visible || r.mLaunchTaskBehind) { |
| 1563 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
| 1564 | setVisible(r, true); |
| 1565 | } |
| 1566 | if (r != starting) { |
| 1567 | mStackSupervisor.startSpecificActivityLocked(r, noStackActivityResumed, false); |
| 1568 | return true; |
| 1569 | } |
| 1570 | } |
| 1571 | return false; |
| 1572 | } |
| 1573 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1574 | private void makeInvisible(boolean stackInvisible, boolean behindFullscreenActivity, |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1575 | ActivityRecord r) { |
| 1576 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r + " finishing=" |
| 1577 | + r.finishing + " state=" + r.state + " stackInvisible=" + stackInvisible |
| 1578 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1579 | if (!r.visible) { |
| 1580 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 1581 | return; |
| 1582 | } |
| 1583 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 1584 | // keeping the screen frozen. |
| 1585 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r); |
| 1586 | try { |
| 1587 | setVisible(r, false); |
| 1588 | switch (r.state) { |
| 1589 | case STOPPING: |
| 1590 | case STOPPED: |
| 1591 | if (r.app != null && r.app.thread != null) { |
| 1592 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1593 | "Scheduling invisibility: " + r); |
| 1594 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1595 | } |
| 1596 | break; |
| 1597 | |
| 1598 | case INITIALIZING: |
| 1599 | case RESUMED: |
| 1600 | case PAUSING: |
| 1601 | case PAUSED: |
| 1602 | // This case created for transitioning activities from |
| 1603 | // translucent to opaque {@link Activity#convertToOpaque}. |
| 1604 | if (getVisibleBehindActivity() == r) { |
| 1605 | releaseBackgroundResources(r); |
| 1606 | } else { |
| 1607 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1608 | mStackSupervisor.mStoppingActivities.add(r); |
| 1609 | } |
| 1610 | mStackSupervisor.scheduleIdleLocked(); |
| 1611 | } |
| 1612 | break; |
| 1613 | |
| 1614 | default: |
| 1615 | break; |
| 1616 | } |
| 1617 | } catch (Exception e) { |
| 1618 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1619 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 1624 | TaskRecord task, ActivityRecord r) { |
| 1625 | if (r.fullscreen) { |
| 1626 | // At this point, nothing else needs to be shown in this task. |
| 1627 | behindFullscreenActivity = true; |
| 1628 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
| 1629 | + " stackInvisible=" + stackInvisible |
| 1630 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1631 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
| 1632 | behindFullscreenActivity = true; |
| 1633 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 1634 | + " stackInvisible=" + stackInvisible |
| 1635 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1636 | } |
| 1637 | return behindFullscreenActivity; |
| 1638 | } |
| 1639 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1640 | private void makeVisible(ActivityRecord starting, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1641 | // This activity is not currently visible, but is running. Tell it to become visible. |
| 1642 | r.visible = true; |
| 1643 | if (r.state != ActivityState.RESUMED && r != starting) { |
| 1644 | // If this activity is paused, tell it to now show its window. |
| 1645 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1646 | "Making visible and scheduling visibility: " + r); |
| 1647 | try { |
| 1648 | if (mTranslucentActivityWaiting != null) { |
| 1649 | r.updateOptionsLocked(r.returningOptions); |
| 1650 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
| 1651 | } |
| 1652 | setVisible(r, true); |
| 1653 | r.sleeping = false; |
| 1654 | r.app.pendingUiClean = true; |
| 1655 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1656 | r.stopFreezingScreenLocked(false); |
| 1657 | } catch (Exception e) { |
| 1658 | // Just skip on any failure; we'll make it |
| 1659 | // visible when it next restarts. |
| 1660 | Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e); |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1665 | private boolean handleAlreadyVisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1666 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Skipping: already visible at " + r); |
| 1667 | r.stopFreezingScreenLocked(false); |
| 1668 | try { |
| 1669 | if (r.returningOptions != null) { |
| 1670 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions); |
| 1671 | } |
| 1672 | } catch(RemoteException e) { |
| 1673 | } |
| 1674 | return r.state == ActivityState.RESUMED; |
| 1675 | } |
| 1676 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1677 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1678 | mTranslucentActivityWaiting = r; |
| 1679 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1680 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1681 | } |
| 1682 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1683 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1684 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1685 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1686 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1687 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1688 | final ActivityRecord r = activities.get(activityNdx); |
| 1689 | if ( r.appTimeTracker != except) { |
| 1690 | r.appTimeTracker = null; |
| 1691 | } |
| 1692 | } |
| 1693 | } |
| 1694 | } |
| 1695 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1696 | /** |
| 1697 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1698 | * redrawn notify the top activity by calling |
| 1699 | * {@link Activity#onTranslucentConversionComplete}. |
| 1700 | * |
| 1701 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1702 | * occurred and the activity will be notified immediately. |
| 1703 | */ |
| 1704 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1705 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1706 | if ((r == null) |
| 1707 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1708 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1709 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1710 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1711 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1712 | mTranslucentActivityWaiting = null; |
| 1713 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1714 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1715 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1716 | if (waitingActivity != null) { |
| 1717 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 1718 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 1719 | try { |
| 1720 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1721 | waitingActivity.appToken, r != null); |
| 1722 | } catch (RemoteException e) { |
| 1723 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1729 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 1730 | * starting window displayed then remove that starting window. It is possible that the activity |
| 1731 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 1732 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1733 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1734 | boolean aboveTop = true; |
| 1735 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1736 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1737 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1738 | final ActivityRecord r = activities.get(activityNdx); |
| 1739 | if (aboveTop) { |
| 1740 | if (r == topActivity) { |
| 1741 | aboveTop = false; |
| 1742 | } |
| 1743 | continue; |
| 1744 | } |
| 1745 | |
| 1746 | if (r.state == ActivityState.INITIALIZING && r.mStartingWindowShown) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1747 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 1748 | "Found orphaned starting window " + r); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1749 | r.mStartingWindowShown = false; |
| 1750 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 1751 | } |
| 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1756 | /** |
| 1757 | * Ensure that the top activity in the stack is resumed. |
| 1758 | * |
| 1759 | * @param prev The previously resumed activity, for when in the process |
| 1760 | * of pausing; can be null to call from elsewhere. |
| 1761 | * |
| 1762 | * @return Returns true if something is being resumed, or false if |
| 1763 | * nothing happened. |
| 1764 | */ |
| 1765 | final boolean resumeTopActivityLocked(ActivityRecord prev) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1766 | return resumeTopActivityLocked(prev, null); |
| 1767 | } |
| 1768 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1769 | final boolean resumeTopActivityLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1770 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1771 | // Don't even start recursing. |
| 1772 | return false; |
| 1773 | } |
| 1774 | |
| 1775 | boolean result = false; |
| 1776 | try { |
| 1777 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1778 | mStackSupervisor.inResumeTopActivity = true; |
| 1779 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 1780 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 1781 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1782 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1783 | result = resumeTopActivityInnerLocked(prev, options); |
| 1784 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1785 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1786 | } |
| 1787 | return result; |
| 1788 | } |
| 1789 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1790 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1791 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1792 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1793 | if (!mService.mBooting && !mService.mBooted) { |
| 1794 | // Not ready yet! |
| 1795 | return false; |
| 1796 | } |
| 1797 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1798 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1799 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 1800 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1801 | // Do not resume this stack if its parent is not resumed. |
| 1802 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 1803 | return false; |
| 1804 | } |
| 1805 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1806 | cancelInitializingActivities(); |
| 1807 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1808 | // Find the first activity that is not finishing. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1809 | final ActivityRecord next = topRunningActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1810 | |
| 1811 | // Remember how we'll process this pause/resume situation, and ensure |
| 1812 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1813 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1814 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1815 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1816 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1817 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1818 | // There are no more activities! |
| 1819 | final String reason = "noMoreActivities"; |
| 1820 | if (!mFullscreen) { |
| 1821 | // Try to move focus to the next visible stack with a running activity if this |
| 1822 | // stack is not covering the entire screen. |
| 1823 | final ActivityStack stack = getNextVisibleStackLocked(); |
| 1824 | if (adjustFocusToNextVisibleStackLocked(stack, reason)) { |
| 1825 | return mStackSupervisor.resumeTopActivitiesLocked(stack, prev, null); |
| 1826 | } |
| 1827 | } |
| 1828 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1829 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1830 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1831 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1832 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1833 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1834 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1835 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1836 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1837 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1841 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1842 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1843 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1844 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1845 | // Make sure we have executed any pending transitions, since there |
| 1846 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1847 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1848 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1849 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1850 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1851 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1852 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1853 | return false; |
| 1854 | } |
| 1855 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1856 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 1857 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1858 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1859 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1860 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1861 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1862 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1863 | // This task is going away but it was supposed to return to the home stack. |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1864 | // Now the task above it has to return to the home task instead. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1865 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1866 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 1867 | } else if (!isOnHomeDisplay()) { |
| 1868 | return false; |
| 1869 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1870 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1871 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1872 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1873 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1874 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 1875 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1876 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1879 | // If we are sleeping, and there is no resumed activity, and the top |
| 1880 | // activity is paused, well that is the state we want. |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1881 | if (mService.isSleepingOrShuttingDown() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1882 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1883 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1884 | // Make sure we have executed any pending transitions, since there |
| 1885 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1886 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1887 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1888 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1889 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1890 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1891 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1892 | return false; |
| 1893 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1894 | |
| 1895 | // Make sure that the user who owns this activity is started. If not, |
| 1896 | // we will just leave it as is because someone should be bringing |
| 1897 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1898 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1899 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 1900 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1901 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1902 | return false; |
| 1903 | } |
| 1904 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1905 | // The activity may be waiting for stop, but that is no longer |
| 1906 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1907 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1908 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1909 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1910 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1911 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1912 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1913 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1914 | // If we are currently pausing an activity, then don't do anything |
| 1915 | // until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 1916 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1917 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1918 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1919 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1920 | return false; |
| 1921 | } |
| 1922 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1923 | // Okay we are now going to start a switch, to 'next'. We may first |
| 1924 | // have to pause the current activity, but this is an important point |
| 1925 | // where we have decided to go to 'next' so keep track of that. |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1926 | // XXX "App Redirected" dialog is getting too many false positives |
| 1927 | // at this point, so turn off for now. |
| 1928 | if (false) { |
| 1929 | if (mLastStartedActivity != null && !mLastStartedActivity.finishing) { |
| 1930 | long now = SystemClock.uptimeMillis(); |
| 1931 | final boolean inTime = mLastStartedActivity.startTime != 0 |
| 1932 | && (mLastStartedActivity.startTime + START_WARN_TIME) >= now; |
| 1933 | final int lastUid = mLastStartedActivity.info.applicationInfo.uid; |
| 1934 | final int nextUid = next.info.applicationInfo.uid; |
| 1935 | if (inTime && lastUid != nextUid |
| 1936 | && lastUid != next.launchedFromUid |
| 1937 | && mService.checkPermission( |
| 1938 | android.Manifest.permission.STOP_APP_SWITCHES, |
| 1939 | -1, next.launchedFromUid) |
| 1940 | != PackageManager.PERMISSION_GRANTED) { |
| 1941 | mService.showLaunchWarningLocked(mLastStartedActivity, next); |
| 1942 | } else { |
| 1943 | next.startTime = now; |
| 1944 | mLastStartedActivity = next; |
| 1945 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1946 | } else { |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1947 | next.startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1948 | mLastStartedActivity = next; |
| 1949 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1950 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1951 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1952 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 1953 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1954 | // We need to start pausing the current activity so the top one |
| 1955 | // can be resumed... |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1956 | boolean dontWaitForPause = (next.info.flags&ActivityInfo.FLAG_RESUME_WHILE_PAUSING) != 0; |
| 1957 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1958 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1959 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1960 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | e042bf2 | 2014-11-11 11:28:43 -0800 | [diff] [blame] | 1961 | pausing |= startPausingLocked(userLeaving, false, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1962 | } |
| 1963 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1964 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1965 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1966 | // At this point we want to put the upcoming activity's process |
| 1967 | // at the top of the LRU list, since we know we will be needing it |
| 1968 | // very soon and it would be a waste to let it get killed if it |
| 1969 | // happens to be sitting towards the end. |
| 1970 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1971 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1972 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1973 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1974 | return true; |
| 1975 | } |
| 1976 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1977 | // If the most recent activity was noHistory but was only stopped rather |
| 1978 | // than stopped+finished because the device went to sleep, we need to make |
| 1979 | // sure to finish it as we're making a new activity topmost. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1980 | if (mService.isSleeping() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1981 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1982 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1983 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1984 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 1985 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1986 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1989 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1990 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 1991 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1992 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1993 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1994 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1995 | } else { |
| 1996 | // The next activity is already visible, so hide the previous |
| 1997 | // activity's windows right now so we can show the new one ASAP. |
| 1998 | // We only do this if the previous is finishing, which should mean |
| 1999 | // it is on top of the one being resumed so hiding it quickly |
| 2000 | // is good. Otherwise, we want to do the normal route of allowing |
| 2001 | // the resumed activity to be shown so we can decide if the |
| 2002 | // previous should actually be hidden depending on whether the |
| 2003 | // new one is found to be full-screen or not. |
| 2004 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2005 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2006 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2007 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2008 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2009 | + ", nowVisible=" + next.nowVisible); |
| 2010 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2011 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2012 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2013 | + ", waitingVisible=" |
| 2014 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2015 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2016 | } |
| 2017 | } |
| 2018 | } |
| 2019 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2020 | // Launching this app's activity, make sure the app is no longer |
| 2021 | // considered stopped. |
| 2022 | try { |
| 2023 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2024 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2025 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2026 | } catch (IllegalArgumentException e) { |
| 2027 | Slog.w(TAG, "Failed trying to unstop package " |
| 2028 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2029 | } |
| 2030 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2031 | // We are starting up the next activity, so tell the window manager |
| 2032 | // that the previous one will be hidden soon. This way it can know |
| 2033 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2034 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2035 | if (prev != null) { |
| 2036 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2037 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2038 | "Prepare close transition: prev=" + prev); |
| 2039 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2040 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2041 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2042 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2043 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2044 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 2045 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2046 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2047 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2048 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2049 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2050 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2051 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2052 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2053 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2054 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2055 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2056 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2057 | : next.mLaunchTaskBehind |
| 2058 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2059 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2060 | } |
| 2061 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2062 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2063 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2064 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2065 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2066 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2067 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2068 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2069 | } |
| 2070 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2071 | |
| 2072 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2073 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2074 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2075 | if (opts != null) { |
| 2076 | resumeAnimOptions = opts.toBundle(); |
| 2077 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2078 | next.applyOptionsLocked(); |
| 2079 | } else { |
| 2080 | next.clearOptionsLocked(); |
| 2081 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2082 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2083 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2084 | if (next.app != null && next.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2085 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2086 | |
| 2087 | // This activity is now becoming visible. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2088 | mWindowManager.setAppVisibility(next.appToken, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2089 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2090 | // schedule launch ticks to collect information about slow apps. |
| 2091 | next.startLaunchTickingLocked(); |
| 2092 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2093 | ActivityRecord lastResumedActivity = |
| 2094 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2095 | ActivityState lastState = next.state; |
| 2096 | |
| 2097 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2098 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2099 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next + " (in existing)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2100 | next.state = ActivityState.RESUMED; |
| 2101 | mResumedActivity = next; |
| 2102 | next.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 2103 | mRecentTasks.addLocked(next.task); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2104 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2105 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2106 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2107 | |
| 2108 | // Have the window manager re-evaluate the orientation of |
| 2109 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2110 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2111 | if (mStackSupervisor.isFocusedStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2112 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2113 | mService.mConfiguration, |
| 2114 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2115 | if (config != null) { |
| 2116 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2117 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2118 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2119 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2120 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2121 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2122 | // The configuration update wasn't able to keep the existing |
| 2123 | // instance of the activity, and instead started a new one. |
| 2124 | // We should be all done, but let's just make sure our activity |
| 2125 | // is still at the top and schedule another run if something |
| 2126 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2127 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2128 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2129 | "Activity config changed during resume: " + next |
| 2130 | + ", new next: " + nextNext); |
| 2131 | if (nextNext != next) { |
| 2132 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2133 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2134 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2135 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2136 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2137 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2138 | return true; |
| 2139 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2140 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2141 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2142 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2143 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2144 | try { |
| 2145 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2146 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2147 | if (a != null) { |
| 2148 | final int N = a.size(); |
| 2149 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2150 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2151 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2152 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2157 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2160 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2161 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2162 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2163 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2164 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2165 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2166 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2167 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2168 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2169 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2170 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2171 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2172 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2173 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2174 | } catch (Exception e) { |
| 2175 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2176 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2177 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2178 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2179 | if (lastStack != null) { |
| 2180 | lastStack.mResumedActivity = lastResumedActivity; |
| 2181 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2182 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2183 | if (!next.hasBeenLaunched) { |
| 2184 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2185 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2186 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2187 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2188 | next.appToken, next.packageName, next.theme, |
| 2189 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2190 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 2191 | next.windowFlags, null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2192 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2193 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2194 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2195 | return true; |
| 2196 | } |
| 2197 | |
| 2198 | // From this point on, if something goes wrong there is no way |
| 2199 | // to recover the activity. |
| 2200 | try { |
| 2201 | next.visible = true; |
| 2202 | completeResumeLocked(next); |
| 2203 | } catch (Exception e) { |
| 2204 | // If any exception gets thrown, toss away this |
| 2205 | // activity and try the next one. |
| 2206 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2207 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2208 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2209 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2210 | return true; |
| 2211 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2212 | next.stopped = false; |
| 2213 | |
| 2214 | } else { |
| 2215 | // Whoops, need to restart this activity! |
| 2216 | if (!next.hasBeenLaunched) { |
| 2217 | next.hasBeenLaunched = true; |
| 2218 | } else { |
| 2219 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2220 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2221 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2222 | mService.compatibilityInfoForPackageLocked( |
| 2223 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2224 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2225 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2226 | null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2227 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2228 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2229 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2230 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2231 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2232 | } |
| 2233 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2234 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2235 | return true; |
| 2236 | } |
| 2237 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2238 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2239 | final int index = mTaskHistory.indexOf(targetTask); |
| 2240 | if (index >= 0) { |
| 2241 | final int numTasks = mTaskHistory.size(); |
| 2242 | for (int i = index + 1; i < numTasks; ++i) { |
| 2243 | TaskRecord task = mTaskHistory.get(i); |
| 2244 | if (task.userId == targetTask.userId) { |
| 2245 | return task; |
| 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | return null; |
| 2250 | } |
| 2251 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2252 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2253 | if (position >= mTaskHistory.size()) { |
| 2254 | insertTaskAtTop(task, null); |
| 2255 | return; |
| 2256 | } |
| 2257 | // Calculate maximum possible position for this task. |
| 2258 | int maxPosition = mTaskHistory.size(); |
| 2259 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2260 | && task.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2261 | // Put non-current user tasks below current user tasks. |
| 2262 | while (maxPosition > 0) { |
| 2263 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2264 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2265 | || tmpTask.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2266 | break; |
| 2267 | } |
| 2268 | maxPosition--; |
| 2269 | } |
| 2270 | } |
| 2271 | position = Math.min(position, maxPosition); |
| 2272 | mTaskHistory.remove(task); |
| 2273 | mTaskHistory.add(position, task); |
| 2274 | updateTaskMovement(task, true); |
| 2275 | } |
| 2276 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2277 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2278 | // If the moving task is over home stack, transfer its return type to next task |
| 2279 | if (task.isOverHomeStack()) { |
| 2280 | final TaskRecord nextTask = getNextTask(task); |
| 2281 | if (nextTask != null) { |
| 2282 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
| 2283 | } |
| 2284 | } |
| 2285 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2286 | // If this is being moved to the top by another activity or being launched from the home |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2287 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2288 | if (isOnHomeDisplay()) { |
| 2289 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2290 | final boolean fromHome = lastStack.isHomeStack(); |
| 2291 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Craig Mautner | 3b1dac8 | 2014-07-15 09:51:33 -0700 | [diff] [blame] | 2292 | task.setTaskToReturnTo(fromHome |
| 2293 | ? lastStack.topTask() == null |
| 2294 | ? HOME_ACTIVITY_TYPE |
| 2295 | : lastStack.topTask().taskType |
| 2296 | : APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2297 | } |
| 2298 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2299 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2300 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2301 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2302 | mTaskHistory.remove(task); |
| 2303 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2304 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2305 | final boolean notShownWhenLocked = |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2306 | (newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2307 | || (newActivity == null && task.topRunningActivityLocked() == null); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2308 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2309 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2310 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2311 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2312 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2313 | || tmpTask.topRunningActivityLocked() == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2314 | break; |
| 2315 | } |
| 2316 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2317 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2318 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2319 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2320 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2321 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2322 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 2323 | final void startActivityLocked(ActivityRecord r, boolean newTask, boolean keepCurTransition, |
| 2324 | ActivityOptions options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2325 | TaskRecord rTask = r.task; |
| 2326 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2327 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2328 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2329 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2330 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2331 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2332 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2333 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2334 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2335 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2336 | if (!newTask) { |
| 2337 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2338 | boolean startIt = true; |
| 2339 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2340 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2341 | if (task.getTopActivity() == null) { |
| 2342 | // All activities in task are finishing. |
| 2343 | continue; |
| 2344 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2345 | if (task == r.task) { |
| 2346 | // Here it is! Now, if this is not yet visible to the |
| 2347 | // user, then just add it without starting; it will |
| 2348 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2349 | if (!startIt) { |
| 2350 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2351 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2352 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2353 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2354 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2355 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2356 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2357 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2358 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2359 | return; |
| 2360 | } |
| 2361 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2362 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2363 | startIt = false; |
| 2364 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | // Place a new activity at top of stack, so it is next to interact |
| 2369 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2370 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2371 | // If we are not placing the new activity frontmost, we do not want |
| 2372 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2373 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2374 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2375 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2376 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2377 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2378 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2379 | |
| 2380 | task = r.task; |
| 2381 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2382 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2383 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to stack to task " + task, |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 2384 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2385 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2386 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2387 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2388 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2389 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2390 | // We want to show the starting preview window if we are |
| 2391 | // switching to a new task, or the next activity's process is |
| 2392 | // not currently running. |
| 2393 | boolean showStartingIcon = newTask; |
| 2394 | ProcessRecord proc = r.app; |
| 2395 | if (proc == null) { |
| 2396 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2397 | } |
| 2398 | if (proc == null || proc.thread == null) { |
| 2399 | showStartingIcon = true; |
| 2400 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2401 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2402 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2403 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2404 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2405 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2406 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2407 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2408 | ? r.mLaunchTaskBehind |
| 2409 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2410 | : AppTransition.TRANSIT_TASK_OPEN |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2411 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2412 | mNoAnimActivities.remove(r); |
| 2413 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2414 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2415 | boolean doShow = true; |
| 2416 | if (newTask) { |
| 2417 | // Even though this activity is starting fresh, we still need |
| 2418 | // to reset it to make sure we apply affinities to move any |
| 2419 | // existing activities from other tasks in to it. |
| 2420 | // If the caller has requested that the target task be |
| 2421 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2422 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2423 | resetTaskIfNeededLocked(r, r); |
| 2424 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2425 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2426 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2427 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2428 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2429 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2430 | if (r.mLaunchTaskBehind) { |
| 2431 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2432 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2433 | mWindowManager.setAppVisibility(r.appToken, true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2434 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2435 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2436 | // Figure out if we are transitioning from another activity that is |
| 2437 | // "has the same starting icon" as the next one. This allows the |
| 2438 | // window manager to keep the previous window it had previously |
| 2439 | // created, if it still had one. |
| 2440 | ActivityRecord prev = mResumedActivity; |
| 2441 | if (prev != null) { |
| 2442 | // We don't want to reuse the previous starting preview if: |
| 2443 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2444 | if (prev.task != r.task) { |
| 2445 | prev = null; |
| 2446 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2447 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2448 | else if (prev.nowVisible) { |
| 2449 | prev = null; |
| 2450 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2451 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2452 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2453 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2454 | mService.compatibilityInfoForPackageLocked( |
| 2455 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2456 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2457 | prev != null ? prev.appToken : null, showStartingIcon); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2458 | r.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2459 | } |
| 2460 | } else { |
| 2461 | // If this is the first activity, don't do any fancy animations, |
| 2462 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2463 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2464 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2465 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2466 | } |
| 2467 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2468 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2469 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2472 | final void validateAppTokensLocked() { |
| 2473 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2474 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2475 | final int numTasks = mTaskHistory.size(); |
| 2476 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2477 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2478 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2479 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2480 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2481 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2482 | TaskGroup group = new TaskGroup(); |
| 2483 | group.taskId = task.taskId; |
| 2484 | mValidateAppTokens.add(group); |
| 2485 | final int numActivities = activities.size(); |
| 2486 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2487 | final ActivityRecord r = activities.get(activityNdx); |
| 2488 | group.tokens.add(r.appToken); |
| 2489 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2490 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2491 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2492 | } |
| 2493 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2494 | /** |
| 2495 | * Perform a reset of the given task, if needed as part of launching it. |
| 2496 | * Returns the new HistoryRecord at the top of the task. |
| 2497 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2498 | /** |
| 2499 | * Helper method for #resetTaskIfNeededLocked. |
| 2500 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2501 | * for another task, or leave it as-is. |
| 2502 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2503 | * @param forceReset |
| 2504 | * @return An ActivityOptions that needs to be processed. |
| 2505 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2506 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2507 | ActivityOptions topOptions = null; |
| 2508 | |
| 2509 | int replyChainEnd = -1; |
| 2510 | boolean canMoveOptions = true; |
| 2511 | |
| 2512 | // We only do this for activities that are not the root of the task (since if we finish |
| 2513 | // the root, we may no longer have the task!). |
| 2514 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2515 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2516 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2517 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2518 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2519 | if (target.frontOfTask) |
| 2520 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2521 | |
| 2522 | final int flags = target.info.flags; |
| 2523 | final boolean finishOnTaskLaunch = |
| 2524 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2525 | final boolean allowTaskReparenting = |
| 2526 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2527 | final boolean clearWhenTaskReset = |
| 2528 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2529 | |
| 2530 | if (!finishOnTaskLaunch |
| 2531 | && !clearWhenTaskReset |
| 2532 | && target.resultTo != null) { |
| 2533 | // If this activity is sending a reply to a previous |
| 2534 | // activity, we can't do anything with it now until |
| 2535 | // we reach the start of the reply chain. |
| 2536 | // XXX note that we are assuming the result is always |
| 2537 | // to the previous activity, which is almost always |
| 2538 | // the case but we really shouldn't count on. |
| 2539 | if (replyChainEnd < 0) { |
| 2540 | replyChainEnd = i; |
| 2541 | } |
| 2542 | } else if (!finishOnTaskLaunch |
| 2543 | && !clearWhenTaskReset |
| 2544 | && allowTaskReparenting |
| 2545 | && target.taskAffinity != null |
| 2546 | && !target.taskAffinity.equals(task.affinity)) { |
| 2547 | // If this activity has an affinity for another |
| 2548 | // task, then we need to move it out of here. We will |
| 2549 | // move it as far out of the way as possible, to the |
| 2550 | // bottom of the activity stack. This also keeps it |
| 2551 | // correctly ordered with any activities we previously |
| 2552 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2553 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2554 | final ActivityRecord bottom = |
| 2555 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2556 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2557 | if (bottom != null && target.taskAffinity != null |
| 2558 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2559 | // If the activity currently at the bottom has the |
| 2560 | // same task affinity as the one we are moving, |
| 2561 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2562 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2563 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2564 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2565 | } else { |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2566 | targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2567 | null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2568 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2569 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2570 | + " out to new task " + target.task); |
| 2571 | } |
| 2572 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2573 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2574 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2575 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2576 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2577 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2578 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2579 | if (p.finishing) { |
| 2580 | continue; |
| 2581 | } |
| 2582 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2583 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2584 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2585 | topOptions = p.takeOptionsLocked(); |
| 2586 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2587 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2588 | } |
| 2589 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2590 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2591 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2592 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2593 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2594 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2595 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2596 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2597 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2598 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2599 | } |
| 2600 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2601 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2602 | if (VALIDATE_TOKENS) { |
| 2603 | validateAppTokensLocked(); |
| 2604 | } |
| 2605 | |
| 2606 | replyChainEnd = -1; |
| 2607 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2608 | // If the activity should just be removed -- either |
| 2609 | // because it asks for it, or the task should be |
| 2610 | // cleared -- then finish it and anything that is |
| 2611 | // part of its reply chain. |
| 2612 | int end; |
| 2613 | if (clearWhenTaskReset) { |
| 2614 | // In this case, we want to finish this activity |
| 2615 | // and everything above it, so be sneaky and pretend |
| 2616 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2617 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2618 | } else if (replyChainEnd < 0) { |
| 2619 | end = i; |
| 2620 | } else { |
| 2621 | end = replyChainEnd; |
| 2622 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2623 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2624 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2625 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2626 | if (p.finishing) { |
| 2627 | continue; |
| 2628 | } |
| 2629 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2630 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2631 | topOptions = p.takeOptionsLocked(); |
| 2632 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2633 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2634 | } |
| 2635 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2636 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2637 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2638 | if (finishActivityLocked( |
| 2639 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2640 | end--; |
| 2641 | srcPos--; |
| 2642 | } |
| 2643 | } |
| 2644 | replyChainEnd = -1; |
| 2645 | } else { |
| 2646 | // If we were in the middle of a chain, well the |
| 2647 | // activity that started it all doesn't want anything |
| 2648 | // special, so leave it all as-is. |
| 2649 | replyChainEnd = -1; |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | return topOptions; |
| 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2658 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2659 | * @param affinityTask The task we are looking for an affinity to. |
| 2660 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2661 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2662 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2663 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2664 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2665 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2666 | int replyChainEnd = -1; |
| 2667 | final int taskId = task.taskId; |
| 2668 | final String taskAffinity = task.affinity; |
| 2669 | |
| 2670 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2671 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2672 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 2673 | |
| 2674 | // Do not operate on or below the effective root Activity. |
| 2675 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2676 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2677 | if (target.frontOfTask) |
| 2678 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2679 | |
| 2680 | final int flags = target.info.flags; |
| 2681 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2682 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2683 | |
| 2684 | if (target.resultTo != null) { |
| 2685 | // If this activity is sending a reply to a previous |
| 2686 | // activity, we can't do anything with it now until |
| 2687 | // we reach the start of the reply chain. |
| 2688 | // XXX note that we are assuming the result is always |
| 2689 | // to the previous activity, which is almost always |
| 2690 | // the case but we really shouldn't count on. |
| 2691 | if (replyChainEnd < 0) { |
| 2692 | replyChainEnd = i; |
| 2693 | } |
| 2694 | } else if (topTaskIsHigher |
| 2695 | && allowTaskReparenting |
| 2696 | && taskAffinity != null |
| 2697 | && taskAffinity.equals(target.taskAffinity)) { |
| 2698 | // This activity has an affinity for our task. Either remove it if we are |
| 2699 | // clearing or move it over to our task. Note that |
| 2700 | // we currently punt on the case where we are resetting a |
| 2701 | // task that is not at the top but who has activities above |
| 2702 | // with an affinity to it... this is really not a normal |
| 2703 | // case, and we will need to later pull that task to the front |
| 2704 | // and usually at that point we will do the reset and pick |
| 2705 | // up those remaining activities. (This only happens if |
| 2706 | // someone starts an activity in a new task from an activity |
| 2707 | // in a task that is not currently on top.) |
| 2708 | if (forceReset || finishOnTaskLaunch) { |
| 2709 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2710 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2711 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2712 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2713 | final ActivityRecord p = activities.get(srcPos); |
| 2714 | if (p.finishing) { |
| 2715 | continue; |
| 2716 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2717 | finishActivityLocked( |
| 2718 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2719 | } |
| 2720 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2721 | if (taskInsertionPoint < 0) { |
| 2722 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2723 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2724 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2725 | |
| 2726 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2727 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2728 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 2729 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2730 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2731 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2732 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2733 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2734 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2735 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2736 | "Removing and adding activity " + p + " to stack at " + task |
| 2737 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2738 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 2739 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2740 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2741 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2742 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2743 | if (VALIDATE_TOKENS) { |
| 2744 | validateAppTokensLocked(); |
| 2745 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2746 | |
| 2747 | // Now we've moved it in to place... but what if this is |
| 2748 | // a singleTop activity and we have put it on top of another |
| 2749 | // instance of the same activity? Then we drop the instance |
| 2750 | // below so it remains singleTop. |
| 2751 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2752 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2753 | int targetNdx = taskActivities.indexOf(target); |
| 2754 | if (targetNdx > 0) { |
| 2755 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2756 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2757 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2758 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2759 | } |
| 2760 | } |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | replyChainEnd = -1; |
| 2765 | } |
| 2766 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2767 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2768 | } |
| 2769 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2770 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2771 | ActivityRecord newActivity) { |
| 2772 | boolean forceReset = |
| 2773 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2774 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2775 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2776 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2777 | forceReset = true; |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | final TaskRecord task = taskTop.task; |
| 2782 | |
| 2783 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2784 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2785 | boolean taskFound = false; |
| 2786 | |
| 2787 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2788 | ActivityOptions topOptions = null; |
| 2789 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2790 | // Preserve the location for reparenting in the new task. |
| 2791 | int reparentInsertionPoint = -1; |
| 2792 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2793 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2794 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2795 | |
| 2796 | if (targetTask == task) { |
| 2797 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2798 | taskFound = true; |
| 2799 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2800 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2801 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2802 | } |
| 2803 | } |
| 2804 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2805 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 2806 | if (taskNdx >= 0) { |
| 2807 | do { |
| 2808 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2809 | } while (taskTop == null && taskNdx >= 0); |
| 2810 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2811 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2812 | if (topOptions != null) { |
| 2813 | // If we got some ActivityOptions from an activity on top that |
| 2814 | // was removed from the task, propagate them to the new real top. |
| 2815 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2816 | taskTop.updateOptionsLocked(topOptions); |
| 2817 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2818 | topOptions.abort(); |
| 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | return taskTop; |
| 2823 | } |
| 2824 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2825 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2826 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2827 | |
| 2828 | if (callingUid > 0) { |
| 2829 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2830 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2834 | + " : who=" + resultWho + " req=" + requestCode |
| 2835 | + " res=" + resultCode + " data=" + data); |
| 2836 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2837 | try { |
| 2838 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2839 | list.add(new ResultInfo(resultWho, requestCode, |
| 2840 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2841 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2842 | return; |
| 2843 | } catch (Exception e) { |
| 2844 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2849 | } |
| 2850 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2851 | private void adjustFocusedActivityLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2852 | if (!mStackSupervisor.isFocusedStack(this) || mService.mFocusedActivity != r) { |
| 2853 | return; |
| 2854 | } |
| 2855 | |
| 2856 | final ActivityRecord next = topRunningActivityLocked(); |
| 2857 | final String myReason = reason + " adjustFocus"; |
| 2858 | if (next != r) { |
| 2859 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId)) { |
| 2860 | // For freeform, docked, and pinned stacks we always keep the focus within the |
| 2861 | // stack as long as there is a running activity in the stack that we can adjust |
| 2862 | // focus to. |
| 2863 | mService.setFocusedActivityLocked(next, myReason); |
| 2864 | return; |
| 2865 | } else { |
| 2866 | final TaskRecord task = r.task; |
| 2867 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
| 2868 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 2869 | // stack to prevent the home screen from moving to the top and obscuring |
| 2870 | // other visible stacks. |
| 2871 | if (!mFullscreen |
| 2872 | && adjustFocusToNextVisibleStackLocked(null, myReason)) { |
| 2873 | return; |
| 2874 | } |
| 2875 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 2876 | // other visible stack. |
| 2877 | if (mStackSupervisor.moveHomeStackTaskToTop( |
| 2878 | task.getTaskToReturnTo(), myReason)) { |
| 2879 | // Activity focus was already adjusted. Nothing else to do... |
| 2880 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 2881 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2882 | } |
| 2883 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2884 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2885 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2886 | final ActivityRecord top = mStackSupervisor.topRunningActivityLocked(); |
| 2887 | if (top != null) { |
| 2888 | mService.setFocusedActivityLocked(top, myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2889 | } |
| 2890 | } |
| 2891 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2892 | private boolean adjustFocusToNextVisibleStackLocked(ActivityStack inStack, String reason) { |
| 2893 | final ActivityStack stack = (inStack != null) ? inStack : getNextVisibleStackLocked(); |
| 2894 | final String myReason = reason + " adjustFocusToNextVisibleStack"; |
| 2895 | if (stack == null) { |
| 2896 | return false; |
| 2897 | } |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2898 | final ActivityRecord top = stack.topRunningActivityLocked(); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2899 | if (top == null) { |
| 2900 | return false; |
| 2901 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2902 | mService.setFocusedActivityLocked(top, myReason); |
| 2903 | return true; |
| 2904 | } |
| 2905 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2906 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2907 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2908 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2909 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2910 | if (!r.finishing) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2911 | if (!mService.isSleeping()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2912 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 2913 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 2914 | "stop-no-history", false)) { |
| 2915 | // Activity was finished, no need to continue trying to schedule stop. |
| 2916 | adjustFocusedActivityLocked(r, "stopActivityFinished"); |
| 2917 | r.resumeKeyDispatchingLocked(); |
| 2918 | return; |
| 2919 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2920 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2921 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2922 | + " on stop because we're just sleeping"); |
| 2923 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2924 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2928 | adjustFocusedActivityLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2929 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2930 | try { |
| 2931 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2932 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 2933 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2934 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2935 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2936 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2937 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2938 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2939 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2940 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 2941 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2942 | r.setSleeping(true); |
| 2943 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2944 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2945 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2946 | } catch (Exception e) { |
| 2947 | // Maybe just ignore exceptions here... if the process |
| 2948 | // has crashed, our death notification will clean things |
| 2949 | // up. |
| 2950 | Slog.w(TAG, "Exception thrown during pause", e); |
| 2951 | // Just in case, assume it to be stopped. |
| 2952 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2953 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Stop failed; moving to STOPPED: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2954 | r.state = ActivityState.STOPPED; |
| 2955 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2956 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | } |
| 2960 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 2961 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2962 | /** |
| 2963 | * @return Returns true if the activity is being finished, false if for |
| 2964 | * some reason it is being left as-is. |
| 2965 | */ |
| 2966 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2967 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2968 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2969 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 2970 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2971 | + ", result=" + resultCode + ", data=" + resultData |
| 2972 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2973 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2974 | return false; |
| 2975 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2976 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2977 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2978 | return true; |
| 2979 | } |
| 2980 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2981 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2982 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2983 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2984 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2985 | ActivityRecord r = activities.get(activityNdx); |
| 2986 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 2987 | if ((r.resultWho == null && resultWho == null) || |
| 2988 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 2989 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 2990 | false); |
| 2991 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2992 | } |
| 2993 | } |
| 2994 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2995 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2998 | final void finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2999 | ActivityRecord r = topRunningActivityLocked(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3000 | if (r != null && r.app == app) { |
| 3001 | // If the top running activity is from this crashing |
| 3002 | // process, then terminate it to avoid getting in a loop. |
| 3003 | Slog.w(TAG, " Force finishing activity " |
| 3004 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3005 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 3006 | int activityNdx = r.task.mActivities.indexOf(r); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3007 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3008 | // Also terminate any activities below it that aren't yet |
| 3009 | // stopped, to avoid a situation where one will get |
| 3010 | // re-start our crashing activity once it gets resumed again. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3011 | --activityNdx; |
| 3012 | if (activityNdx < 0) { |
| 3013 | do { |
| 3014 | --taskNdx; |
| 3015 | if (taskNdx < 0) { |
| 3016 | break; |
| 3017 | } |
| 3018 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3019 | } while (activityNdx < 0); |
| 3020 | } |
| 3021 | if (activityNdx >= 0) { |
| 3022 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3023 | if (r.state == ActivityState.RESUMED |
| 3024 | || r.state == ActivityState.PAUSING |
| 3025 | || r.state == ActivityState.PAUSED) { |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 3026 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3027 | Slog.w(TAG, " Force finishing activity " |
| 3028 | + r.intent.getComponent().flattenToShortString()); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3029 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | } |
| 3033 | } |
| 3034 | } |
| 3035 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3036 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3037 | IBinder sessionBinder = session.asBinder(); |
| 3038 | boolean didOne = false; |
| 3039 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3040 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3041 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3042 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3043 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3044 | if (!r.finishing) { |
| 3045 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3046 | false); |
| 3047 | didOne = true; |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | } |
| 3052 | if (didOne) { |
| 3053 | mService.updateOomAdjLocked(); |
| 3054 | } |
| 3055 | } |
| 3056 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3057 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3058 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 3059 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3060 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3061 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3062 | break; |
| 3063 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3064 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3065 | } |
| 3066 | return true; |
| 3067 | } |
| 3068 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3069 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 3070 | // send the result |
| 3071 | ActivityRecord resultTo = r.resultTo; |
| 3072 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3073 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3074 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3075 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3076 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3077 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3078 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3079 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3080 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3081 | if (r.info.applicationInfo.uid > 0) { |
| 3082 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3083 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3084 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3085 | } |
| 3086 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3087 | resultData); |
| 3088 | r.resultTo = null; |
| 3089 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3090 | else if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "No result destination from " + r); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3091 | |
| 3092 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3093 | // because clients have remote IPC references to this object so we |
| 3094 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3095 | r.results = null; |
| 3096 | r.pendingResults = null; |
| 3097 | r.newIntents = null; |
| 3098 | r.icicle = null; |
| 3099 | } |
| 3100 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3101 | /** |
| 3102 | * @return Returns true if this activity has been removed from the history |
| 3103 | * list, or false if it is still in the list and will be removed later. |
| 3104 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3105 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3106 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3107 | if (r.finishing) { |
| 3108 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3109 | return false; |
| 3110 | } |
| 3111 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3112 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3113 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3114 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3115 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3116 | task.taskId, r.shortComponentName, reason); |
| 3117 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3118 | final int index = activities.indexOf(r); |
| 3119 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3120 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3121 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3122 | // If the caller asked that this activity (and all above it) |
| 3123 | // be cleared when the task is reset, don't lose that information, |
| 3124 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3125 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3126 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3131 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3132 | adjustFocusedActivityLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3133 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3134 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3135 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3136 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3137 | boolean endTask = index <= 0; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3138 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3139 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3140 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3141 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 3142 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3143 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3144 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3145 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3146 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3147 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3148 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3149 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3150 | "finish() => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3151 | startPausingLocked(false, false, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3154 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3155 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3156 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3157 | } else if (r.state != ActivityState.PAUSING) { |
| 3158 | // If the activity is PAUSING, we will complete the finish once |
| 3159 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3160 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3161 | if (r.visible) { |
| 3162 | mWindowManager.setAppVisibility(r.appToken, false); |
| 3163 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3164 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3165 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3166 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | return false; |
| 3170 | } |
| 3171 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3172 | static final int FINISH_IMMEDIATELY = 0; |
| 3173 | static final int FINISH_AFTER_PAUSE = 1; |
| 3174 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3175 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3176 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3177 | // First things first: if this activity is currently visible, |
| 3178 | // and the resumed activity is not yet visible, then hold off on |
| 3179 | // finishing until the resumed one becomes visible. |
| 3180 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3181 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 3182 | addToStopping(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3183 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3184 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3185 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3186 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3187 | if (oomAdj) { |
| 3188 | mService.updateOomAdjLocked(); |
| 3189 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3190 | return r; |
| 3191 | } |
| 3192 | |
| 3193 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3194 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3195 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3196 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3197 | if (mResumedActivity == r) { |
| 3198 | mResumedActivity = null; |
| 3199 | } |
| 3200 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3201 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3202 | r.state = ActivityState.FINISHING; |
| 3203 | |
| 3204 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3205 | || (mode == FINISH_AFTER_PAUSE && prevState == ActivityState.PAUSED) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3206 | || prevState == ActivityState.STOPPED |
| 3207 | || prevState == ActivityState.INITIALIZING) { |
| 3208 | // If this activity is already stopped, we can just finish |
| 3209 | // it right now. |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3210 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3211 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3212 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3213 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3214 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3215 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3216 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3217 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3218 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3219 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3220 | |
| 3221 | // Need to go through the full pause cycle to get this |
| 3222 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3223 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3224 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3225 | r.resumeKeyDispatchingLocked(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3226 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3227 | return r; |
| 3228 | } |
| 3229 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3230 | void finishAllActivitiesLocked(boolean immediately) { |
| 3231 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3232 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3233 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3234 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3235 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3236 | noActivitiesInStack = false; |
| 3237 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3238 | continue; |
| 3239 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3240 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3241 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3242 | } |
| 3243 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3244 | if (noActivitiesInStack) { |
| 3245 | mActivityContainer.onTaskListEmptyLocked(); |
| 3246 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3249 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3250 | // Basic case: for simple app-centric recents, we need to recreate |
| 3251 | // the task if the affinity has changed. |
| 3252 | if (srec == null || srec.task.affinity == null || |
| 3253 | !srec.task.affinity.equals(destAffinity)) { |
| 3254 | return true; |
| 3255 | } |
| 3256 | // Document-centric case: an app may be split in to multiple documents; |
| 3257 | // they need to re-create their task if this current activity is the root |
| 3258 | // of a document, unless simply finishing it will return them to the the |
| 3259 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3260 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3261 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3262 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3263 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3264 | // Finishing won't return to an application, so we need to recreate. |
| 3265 | return true; |
| 3266 | } |
| 3267 | // We now need to get the task below it to determine what to do. |
| 3268 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3269 | if (taskIdx <= 0) { |
| 3270 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3271 | return false; |
| 3272 | } |
| 3273 | if (taskIdx == 0) { |
| 3274 | // At the bottom of the stack, nothing to go back to. |
| 3275 | return true; |
| 3276 | } |
| 3277 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3278 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3279 | // These are different apps, so need to recreate. |
| 3280 | return true; |
| 3281 | } |
| 3282 | } |
| 3283 | return false; |
| 3284 | } |
| 3285 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3286 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3287 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3288 | final TaskRecord task = srec.task; |
| 3289 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3290 | final int start = activities.indexOf(srec); |
| 3291 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3292 | return false; |
| 3293 | } |
| 3294 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3295 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3296 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3297 | final ComponentName dest = destIntent.getComponent(); |
| 3298 | if (start > 0 && dest != null) { |
| 3299 | for (int i = finishTo; i >= 0; i--) { |
| 3300 | ActivityRecord r = activities.get(i); |
| 3301 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3302 | r.info.name.equals(dest.getClassName())) { |
| 3303 | finishTo = i; |
| 3304 | parent = r; |
| 3305 | foundParentInTask = true; |
| 3306 | break; |
| 3307 | } |
| 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | IActivityController controller = mService.mController; |
| 3312 | if (controller != null) { |
| 3313 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3314 | if (next != null) { |
| 3315 | // ask watcher if this is allowed |
| 3316 | boolean resumeOK = true; |
| 3317 | try { |
| 3318 | resumeOK = controller.activityResuming(next.packageName); |
| 3319 | } catch (RemoteException e) { |
| 3320 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3321 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | if (!resumeOK) { |
| 3325 | return false; |
| 3326 | } |
| 3327 | } |
| 3328 | } |
| 3329 | final long origId = Binder.clearCallingIdentity(); |
| 3330 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3331 | ActivityRecord r = activities.get(i); |
| 3332 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3333 | // Only return the supplied result for the first activity finished |
| 3334 | resultCode = Activity.RESULT_CANCELED; |
| 3335 | resultData = null; |
| 3336 | } |
| 3337 | |
| 3338 | if (parent != null && foundParentInTask) { |
| 3339 | final int parentLaunchMode = parent.info.launchMode; |
| 3340 | final int destIntentFlags = destIntent.getFlags(); |
| 3341 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3342 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3343 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3344 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3345 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3346 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3347 | } else { |
| 3348 | try { |
| 3349 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3350 | destIntent.getComponent(), 0, srec.userId); |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 3351 | int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3352 | null, aInfo, null, null, parent.appToken, null, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3353 | 0, -1, parent.launchedFromUid, parent.launchedFromPackage, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 3354 | -1, parent.launchedFromUid, 0, null, false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3355 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3356 | } catch (RemoteException e) { |
| 3357 | foundParentInTask = false; |
| 3358 | } |
| 3359 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3360 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | Binder.restoreCallingIdentity(origId); |
| 3364 | return foundParentInTask; |
| 3365 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3366 | /** |
| 3367 | * Perform the common clean-up of an activity record. This is called both |
| 3368 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3369 | * representation) and cleaning things up as a result of its hosting |
| 3370 | * processing going away, in which case there is no remaining client-side |
| 3371 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3372 | * |
| 3373 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3374 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3375 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3376 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3377 | if (mResumedActivity == r) { |
| 3378 | mResumedActivity = null; |
| 3379 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3380 | if (mPausingActivity == r) { |
| 3381 | mPausingActivity = null; |
| 3382 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3383 | mService.clearFocusedActivity(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3384 | |
| 3385 | r.configDestroy = false; |
| 3386 | r.frozenBeforeDestroy = false; |
| 3387 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3388 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3389 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (cleaning up)"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3390 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3391 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during cleanUp for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3392 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3395 | // Make sure this record is no longer in the pending finishes list. |
| 3396 | // This could happen, for example, if we are trimming activities |
| 3397 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3398 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3399 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3400 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3401 | // Remove any pending results. |
| 3402 | if (r.finishing && r.pendingResults != null) { |
| 3403 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3404 | PendingIntentRecord rec = apr.get(); |
| 3405 | if (rec != null) { |
| 3406 | mService.cancelIntentSenderLocked(rec, false); |
| 3407 | } |
| 3408 | } |
| 3409 | r.pendingResults = null; |
| 3410 | } |
| 3411 | |
| 3412 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3413 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3416 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3417 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3418 | if (getVisibleBehindActivity() == r) { |
| 3419 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3420 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3424 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3425 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3426 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3427 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3428 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3431 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3432 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3433 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3434 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3435 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3436 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3437 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3438 | r.takeFromHistory(); |
| 3439 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3440 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3441 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3442 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3443 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during remove for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3444 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3445 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3446 | if (VALIDATE_TOKENS) { |
| 3447 | validateAppTokensLocked(); |
| 3448 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3449 | final TaskRecord task = r.task; |
| 3450 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3451 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3452 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3453 | if (mStackSupervisor.isFocusedStack(this) && task == topTask() && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3454 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3455 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3456 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3457 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3458 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3459 | cleanUpActivityServicesLocked(r); |
| 3460 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3461 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3462 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3463 | /** |
| 3464 | * Perform clean-up of service connections in an activity record. |
| 3465 | */ |
| 3466 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3467 | // Throw away any services that have been bound by this activity. |
| 3468 | if (r.connections != null) { |
| 3469 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3470 | while (it.hasNext()) { |
| 3471 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3472 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3473 | } |
| 3474 | r.connections = null; |
| 3475 | } |
| 3476 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3477 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3478 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3479 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3480 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3481 | mHandler.sendMessage(msg); |
| 3482 | } |
| 3483 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3484 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3485 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3486 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3487 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3488 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3489 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3490 | final ActivityRecord r = activities.get(activityNdx); |
| 3491 | if (r.finishing) { |
| 3492 | continue; |
| 3493 | } |
| 3494 | if (r.fullscreen) { |
| 3495 | lastIsOpaque = true; |
| 3496 | } |
| 3497 | if (owner != null && r.app != owner) { |
| 3498 | continue; |
| 3499 | } |
| 3500 | if (!lastIsOpaque) { |
| 3501 | continue; |
| 3502 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3503 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3504 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Destroying " + r + " in state " + r.state |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3505 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3506 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3507 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3508 | activityRemoved = true; |
| 3509 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3510 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3511 | } |
| 3512 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3513 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3514 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3515 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3518 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3519 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3520 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3521 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3522 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3523 | return destroyActivityLocked(r, true, reason); |
| 3524 | } |
| 3525 | return false; |
| 3526 | } |
| 3527 | |
| 3528 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3529 | String reason) { |
| 3530 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3531 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3532 | int maxTasks = tasks.size() / 4; |
| 3533 | if (maxTasks < 1) { |
| 3534 | maxTasks = 1; |
| 3535 | } |
| 3536 | int numReleased = 0; |
| 3537 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3538 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3539 | if (!tasks.contains(task)) { |
| 3540 | continue; |
| 3541 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3542 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Looking for activities to release in " + task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3543 | int curNum = 0; |
| 3544 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3545 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3546 | final ActivityRecord activity = activities.get(actNdx); |
| 3547 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3548 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3549 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3550 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3551 | destroyActivityLocked(activity, true, reason); |
| 3552 | if (activities.get(actNdx) != activity) { |
| 3553 | // Was removed from list, back up so we don't miss the next one. |
| 3554 | actNdx--; |
| 3555 | } |
| 3556 | curNum++; |
| 3557 | } |
| 3558 | } |
| 3559 | if (curNum > 0) { |
| 3560 | numReleased += curNum; |
| 3561 | maxTasks--; |
| 3562 | if (mTaskHistory.get(taskNdx) != task) { |
| 3563 | // The entire task got removed, back up so we don't miss the next one. |
| 3564 | taskNdx--; |
| 3565 | } |
| 3566 | } |
| 3567 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3568 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3569 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3570 | return numReleased; |
| 3571 | } |
| 3572 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3573 | /** |
| 3574 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3575 | * called both when actually finishing an activity, or when performing |
| 3576 | * a configuration switch where we destroy the current client-side object |
| 3577 | * but then create a new client-side object for this same HistoryRecord. |
| 3578 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3579 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3580 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3581 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3582 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3583 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3584 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3585 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3586 | |
| 3587 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3588 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3589 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3590 | |
| 3591 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3592 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3593 | if (hadApp) { |
| 3594 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3595 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3596 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 3597 | mService.mHeavyWeightProcess = null; |
| 3598 | mService.mHandler.sendEmptyMessage( |
| 3599 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 3600 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3601 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 3602 | // Update any services we are bound to that might care about whether |
| 3603 | // their client may have activities. |
| 3604 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 3605 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 3606 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3607 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3612 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3613 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3614 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3615 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3616 | r.configChangeFlags); |
| 3617 | } catch (Exception e) { |
| 3618 | // We can just ignore exceptions here... if the process |
| 3619 | // has crashed, our death notification will clean things |
| 3620 | // up. |
| 3621 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 3622 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3623 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3624 | removedFromHistory = true; |
| 3625 | skipDestroy = true; |
| 3626 | } |
| 3627 | } |
| 3628 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3629 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3630 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3631 | // If the activity is finishing, we need to wait on removing it |
| 3632 | // from the list to give it a chance to do its cleanup. During |
| 3633 | // that time it may make calls back with its token so we need to |
| 3634 | // be able to find it on the list and so we don't want to remove |
| 3635 | // it from the list yet. Otherwise, we can just immediately put |
| 3636 | // it in the destroyed state since we are not removing it from the |
| 3637 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3638 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3639 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3640 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3641 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3642 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3643 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 3644 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3645 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3646 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3647 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3648 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3649 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3650 | } |
| 3651 | } else { |
| 3652 | // remove this record from the history. |
| 3653 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3654 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3655 | removedFromHistory = true; |
| 3656 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3657 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (no app)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3658 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3659 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3660 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3665 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3666 | if (!mLRUActivities.remove(r) && hadApp) { |
| 3667 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 3668 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3669 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3670 | return removedFromHistory; |
| 3671 | } |
| 3672 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3673 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3674 | final long origId = Binder.clearCallingIdentity(); |
| 3675 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3676 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3677 | if (r != null) { |
| 3678 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3679 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3680 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3681 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3682 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3683 | if (r.state == ActivityState.DESTROYING) { |
| 3684 | cleanUpActivityLocked(r, true, false); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3685 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3686 | } |
| 3687 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3688 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3691 | } |
| 3692 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3693 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 3694 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3695 | if (hasVisibleBehindActivity() && |
| 3696 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3697 | if (r == topRunningActivityLocked()) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3698 | // Don't release the top activity if it has requested to run behind the next |
| 3699 | // activity. |
| 3700 | return; |
| 3701 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3702 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3703 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3704 | " thread=" + r.app.thread); |
| 3705 | if (r != null && r.app != null && r.app.thread != null) { |
| 3706 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3707 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3708 | } catch (RemoteException e) { |
| 3709 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3710 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3711 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3712 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3713 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3714 | } |
| 3715 | } |
| 3716 | } |
| 3717 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3718 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3719 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 3720 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3721 | if (r != null) { |
| 3722 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3723 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3724 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3725 | } |
| 3726 | mStackSupervisor.resumeTopActivitiesLocked(); |
| 3727 | } |
| 3728 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3729 | boolean hasVisibleBehindActivity() { |
| 3730 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3733 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3734 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3735 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3736 | } |
| 3737 | } |
| 3738 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3739 | ActivityRecord getVisibleBehindActivity() { |
| 3740 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3741 | } |
| 3742 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3743 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 3744 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3745 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3746 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3747 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3748 | while (i > 0) { |
| 3749 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3750 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3751 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3752 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3753 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3754 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3755 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3756 | } |
| 3757 | } |
| 3758 | } |
| 3759 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3760 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 3761 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3762 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 3763 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3764 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 3765 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3766 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3767 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3768 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 3769 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3770 | |
| 3771 | boolean hasVisibleActivities = false; |
| 3772 | |
| 3773 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3774 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3775 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3776 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3777 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3778 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3779 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3780 | final ActivityRecord r = activities.get(activityNdx); |
| 3781 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3782 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3783 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3784 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 3785 | if (r.visible) { |
| 3786 | hasVisibleActivities = true; |
| 3787 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3788 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3789 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 3790 | // Don't currently have state for the activity, or |
| 3791 | // it is finishing -- always remove it. |
| 3792 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3793 | } else if (!r.visible && r.launchCount > 2 && |
| 3794 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3795 | // We have launched this activity too many times since it was |
| 3796 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3797 | // (Note if the activity is visible, we don't remove the record. |
| 3798 | // We leave the dead window on the screen but the process will |
| 3799 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3800 | remove = true; |
| 3801 | } else { |
| 3802 | // The process may be gone, but the activity lives on! |
| 3803 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3804 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3805 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3806 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 3807 | "Removing activity " + r + " from stack at " + i |
| 3808 | + ": haveState=" + r.haveState |
| 3809 | + " stateNotNeeded=" + r.stateNotNeeded |
| 3810 | + " finishing=" + r.finishing |
| 3811 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3812 | if (!r.finishing) { |
| 3813 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 3814 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3815 | r.userId, System.identityHashCode(r), |
| 3816 | r.task.taskId, r.shortComponentName, |
| 3817 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3818 | if (r.state == ActivityState.RESUMED) { |
| 3819 | mService.updateUsageStats(r, false); |
| 3820 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3821 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3822 | } else { |
| 3823 | // We have the current state for this activity, so |
| 3824 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3825 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 3826 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 3827 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3828 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3829 | // Set nowVisible to previous visible state. If the app was visible while |
| 3830 | // it died, we leave the dead window on screen so it's basically visible. |
| 3831 | // This is needed when user later tap on the dead window, we need to stop |
| 3832 | // other apps when user transfers focus to the restarted activity. |
| 3833 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3834 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3835 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3836 | "App died, clearing saved state of " + r); |
| 3837 | r.icicle = null; |
| 3838 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3839 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3840 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3841 | if (remove) { |
| 3842 | removeActivityFromHistoryLocked(r, "appDied"); |
| 3843 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3844 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3849 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3850 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3851 | final void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3852 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3853 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3854 | if (r != null && r.state != ActivityState.RESUMED) { |
| 3855 | r.updateOptionsLocked(options); |
| 3856 | } else { |
| 3857 | ActivityOptions.abort(options); |
| 3858 | } |
| 3859 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3860 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3861 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 3862 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3863 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 3864 | if (task.isPersistable) { |
| 3865 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 3866 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 3867 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 3868 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 3869 | if (!toFront) { |
| 3870 | task.mLastTimeMoved *= -1; |
| 3871 | } |
| 3872 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3873 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3876 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3877 | final int top = mTaskHistory.size() - 1; |
| 3878 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 3879 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3880 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3881 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 3882 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3883 | mTaskHistory.remove(taskNdx); |
| 3884 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3885 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3886 | return; |
| 3887 | } |
| 3888 | } |
| 3889 | } |
| 3890 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3891 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3892 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3893 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3894 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3895 | final int numTasks = mTaskHistory.size(); |
| 3896 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3897 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3898 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3899 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3900 | ActivityOptions.abort(options); |
| 3901 | } else { |
| 3902 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 3903 | } |
| 3904 | return; |
| 3905 | } |
| 3906 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3907 | if (timeTracker != null) { |
| 3908 | // The caller wants a time tracker associated with this task. |
| 3909 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 3910 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 3911 | } |
| 3912 | } |
| 3913 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3914 | // Shift all activities with this task up to the top |
| 3915 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 3916 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3917 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 3918 | // Don't refocus if invisible to current user |
| 3919 | ActivityRecord top = tr.getTopActivity(); |
| 3920 | if (!okToShowLocked(top)) { |
| 3921 | addRecentActivityLocked(top); |
| 3922 | ActivityOptions.abort(options); |
| 3923 | return; |
| 3924 | } |
| 3925 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3926 | // Set focus to the top running activity of this stack. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3927 | ActivityRecord r = topRunningActivityLocked(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3928 | mService.setFocusedActivityLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3929 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3930 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3931 | if (noAnimation) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3932 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3933 | if (r != null) { |
| 3934 | mNoAnimActivities.add(r); |
| 3935 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3936 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3937 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3938 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3939 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 3940 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3941 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3942 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3943 | |
| 3944 | if (VALIDATE_TOKENS) { |
| 3945 | validateAppTokensLocked(); |
| 3946 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3950 | * Worker method for rearranging history stack. Implements the function of moving all |
| 3951 | * activities for a specific task (gathering them if disjoint) into a single group at the |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3952 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3953 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3954 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 3955 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3956 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3957 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3958 | * @return Returns true if the move completed, false if not. |
| 3959 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3960 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3961 | final TaskRecord tr = taskForIdLocked(taskId); |
| 3962 | if (tr == null) { |
| 3963 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 3964 | return false; |
| 3965 | } |
| 3966 | |
| 3967 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3968 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3969 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3970 | // If we have a watcher, preflight the move before committing to it. First check |
| 3971 | // for *other* available tasks, but if none are available, then try again allowing the |
| 3972 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3973 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3974 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3975 | if (next == null) { |
| 3976 | next = topRunningActivityLocked(null, 0); |
| 3977 | } |
| 3978 | if (next != null) { |
| 3979 | // ask watcher if this is allowed |
| 3980 | boolean moveOK = true; |
| 3981 | try { |
| 3982 | moveOK = mService.mController.activityResuming(next.packageName); |
| 3983 | } catch (RemoteException e) { |
| 3984 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3985 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3986 | } |
| 3987 | if (!moveOK) { |
| 3988 | return false; |
| 3989 | } |
| 3990 | } |
| 3991 | } |
| 3992 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3993 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to back transition: task=" + taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3994 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame^] | 3995 | if (mStackId == HOME_STACK_ID && topTask().isHomeTask()) { |
| 3996 | // For the case where we are moving the home task back and there is an activity visible |
| 3997 | // behind it on the fullscreen stack, we want to move the focus to the visible behind |
| 3998 | // activity to maintain order with what the user is seeing. |
| 3999 | final ActivityStack fullscreenStack = |
| 4000 | mStackSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
| 4001 | if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) { |
| 4002 | final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity(); |
| 4003 | mService.setFocusedActivityLocked(visibleBehind, "moveTaskToBack"); |
| 4004 | mStackSupervisor.resumeTopActivitiesLocked(fullscreenStack, null, null); |
| 4005 | return true; |
| 4006 | } |
| 4007 | } |
| 4008 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4009 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4010 | |
| 4011 | // If true, we should resume the home activity next if the task we are moving to the |
| 4012 | // back is over the home stack. We force to false if the task we are moving to back |
| 4013 | // is the home task and we don't want it resumed after moving to the back. |
| 4014 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4015 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4016 | final TaskRecord nextTask = getNextTask(tr); |
| 4017 | if (nextTask != null) { |
| 4018 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4019 | } else { |
| 4020 | prevIsHome = true; |
| 4021 | } |
| 4022 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4023 | mTaskHistory.remove(tr); |
| 4024 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4025 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4026 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4027 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 4028 | // We make sure here that some activity in the stack will launch home. |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4029 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4030 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4031 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4032 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4033 | break; |
| 4034 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4035 | if (taskNdx == 1) { |
| 4036 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4037 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4038 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4039 | } |
| 4040 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4041 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4042 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4043 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4044 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4045 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4048 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4049 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4050 | if (!mService.mBooting && !mService.mBooted) { |
| 4051 | // Not ready yet! |
| 4052 | return false; |
| 4053 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4054 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 4055 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4056 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4059 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4060 | return true; |
| 4061 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4062 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 4063 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4064 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4065 | final Uri data = r.intent.getData(); |
| 4066 | final String strData = data != null ? data.toSafeString() : null; |
| 4067 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4068 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4069 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4070 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4071 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
| 4074 | /** |
| 4075 | * Make sure the given activity matches the current configuration. Returns |
| 4076 | * false if the activity had to be destroyed. Returns true if the |
| 4077 | * configuration is the same, or the activity will remain running as-is |
| 4078 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 4079 | * correct configuration and all other bookkeeping is handled. |
| 4080 | */ |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4081 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, int globalChanges, |
| 4082 | boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4083 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4084 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4085 | "Skipping config check (will change): " + r); |
| 4086 | return true; |
| 4087 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4088 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4089 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4090 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4091 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4092 | // Short circuit: if the two configurations are the exact same |
| 4093 | // object (the common case), then there is nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4094 | final Configuration newConfig = mService.mConfiguration; |
| 4095 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4096 | if (r.configuration == newConfig |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4097 | && r.taskConfigOverride == taskConfig |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4098 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4099 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4100 | "Configuration unchanged in " + r); |
| 4101 | return true; |
| 4102 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4103 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4104 | // We don't worry about activities that are finishing. |
| 4105 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4106 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4107 | "Configuration doesn't matter in finishing " + r); |
| 4108 | r.stopFreezingScreenLocked(false); |
| 4109 | return true; |
| 4110 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4111 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4112 | // Okay we now are going to make this activity have the new config. |
| 4113 | // But then we need to figure out how it needs to deal with that. |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4114 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4115 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4116 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4117 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4118 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4119 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4120 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4121 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4122 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4123 | "Configuration no differences in " + r); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4124 | // There are no significant differences, so we won't relaunch but should still deliver |
| 4125 | // the new configuration to the client process. |
| 4126 | r.scheduleConfigurationChanged(taskConfig, false); |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4127 | return true; |
| 4128 | } |
| 4129 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 4130 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4131 | "Configuration changes for " + r + " ; taskChanges=" |
| 4132 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 4133 | + Configuration.configurationDiffToString(changes)); |
| 4134 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4135 | // If the activity isn't currently running, just leave the new |
| 4136 | // configuration and it will pick that up next time it starts. |
| 4137 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4138 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4139 | "Configuration doesn't matter not running " + r); |
| 4140 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4141 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4142 | return true; |
| 4143 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4144 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4145 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4146 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4147 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4148 | + Integer.toHexString(changes) + ", handles=0x" |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4149 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig |
| 4150 | + ", taskConfig=" + taskConfig); |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4151 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4152 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4153 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4154 | r.configChangeFlags |= changes; |
| 4155 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4156 | r.forceNewConfig = false; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4157 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4158 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4159 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4160 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4161 | } else if (r.state == ActivityState.PAUSING) { |
| 4162 | // A little annoying: we are waiting for this activity to |
| 4163 | // finish pausing. Let's not do anything now, but just |
| 4164 | // flag that it needs to be restarted when done pausing. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4165 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4166 | "Config is skipping already pausing " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4167 | r.configDestroy = true; |
| 4168 | return true; |
| 4169 | } else if (r.state == ActivityState.RESUMED) { |
| 4170 | // Try to optimize this case: the configuration is changing |
| 4171 | // and we need to restart the top, resumed activity. |
| 4172 | // Instead of doing the normal handshaking, just say |
| 4173 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4174 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4175 | "Config is relaunching resumed " + r); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4176 | relaunchActivityLocked(r, r.configChangeFlags, true, |
| 4177 | preserveWindow && isResizeOnlyChange(changes)); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4178 | r.configChangeFlags = 0; |
| 4179 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4180 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4181 | "Config is relaunching non-resumed " + r); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4182 | relaunchActivityLocked(r, r.configChangeFlags, false, |
| 4183 | preserveWindow && isResizeOnlyChange(changes)); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4184 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4185 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4186 | |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4187 | // All done... tell the caller we weren't able to keep this |
| 4188 | // activity around. |
| 4189 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4190 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4191 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4192 | // Default case: the activity can handle this new configuration, so hand it over. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4193 | // NOTE: We only forward the task override configuration as the system level configuration |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4194 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4195 | // system level configuration it last got. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4196 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4197 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4198 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4199 | return true; |
| 4200 | } |
| 4201 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4202 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4203 | Configuration oldTaskOverride) { |
| 4204 | // Determine what has changed. May be nothing, if this is a config |
| 4205 | // that has come back from the app after going idle. In that case |
| 4206 | // we just want to leave the official config object now in the |
| 4207 | // activity and do nothing else. |
| 4208 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4209 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4210 | // the app. |
| 4211 | if ((taskChanges & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) { |
| 4212 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4213 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4214 | || record.crossesVerticalSizeThreshold( |
| 4215 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4216 | if (!crosses) { |
| 4217 | taskChanges &= ~ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4218 | } |
| 4219 | } |
| 4220 | if ((taskChanges & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
| 4221 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4222 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 4223 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4224 | taskChanges &= ~ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 4225 | } |
| 4226 | } |
| 4227 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4228 | } |
| 4229 | |
| 4230 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4231 | Configuration oldTaskOverride, int taskChanges) { |
| 4232 | if (taskChanges == 0) { |
| 4233 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4234 | // Check for changes we care about. |
| 4235 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
| 4236 | taskChanges |= ActivityInfo.CONFIG_ORIENTATION; |
| 4237 | } |
| 4238 | // We want to explicitly track situations where the size configuration goes from |
| 4239 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4240 | // because there is no threshold. |
| 4241 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4242 | final int newHeight = taskConfig.screenHeightDp; |
| 4243 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4244 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4245 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
| 4246 | taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4247 | } |
| 4248 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4249 | final int newWidth = taskConfig.screenWidthDp; |
| 4250 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4251 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4252 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
| 4253 | taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4254 | } |
| 4255 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4256 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4257 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4258 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4259 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
| 4260 | taskChanges |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 4261 | } |
| 4262 | } |
| 4263 | return taskChanges; |
| 4264 | } |
| 4265 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4266 | private static boolean isResizeOnlyChange(int change) { |
| 4267 | return (change & ~(ActivityInfo.CONFIG_SCREEN_SIZE |
| 4268 | | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) == 0; |
| 4269 | } |
| 4270 | |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4271 | private void relaunchActivityLocked( |
| 4272 | ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) { |
| 4273 | if (mService.mSuppressResizeConfigChanges && preserveWindow) { |
| 4274 | return; |
| 4275 | } |
| 4276 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4277 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4278 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4279 | if (andResume) { |
| 4280 | results = r.results; |
| 4281 | newIntents = r.newIntents; |
| 4282 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4283 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4284 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4285 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4286 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4287 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4288 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4289 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4290 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4291 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4292 | mStackSupervisor.removeChildActivityContainers(r); |
| 4293 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4294 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4295 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 4296 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4297 | r.forceNewConfig = false; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4298 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4299 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4300 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4301 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4302 | // the caller will only pass in 'andResume' if this activity is |
| 4303 | // currently resumed, which implies we aren't sleeping. |
| 4304 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4305 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | if (andResume) { |
| 4309 | r.results = null; |
| 4310 | r.newIntents = null; |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4311 | r.state = ActivityState.RESUMED; |
| 4312 | } else { |
| 4313 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4314 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4315 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4316 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4317 | |
| 4318 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4319 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4320 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4321 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4322 | final ActivityRecord r = activities.get(activityNdx); |
| 4323 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4324 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4325 | } |
| 4326 | if (r.fullscreen && !r.finishing) { |
| 4327 | return false; |
| 4328 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4329 | } |
| 4330 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4331 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4332 | if (r == null) { |
| 4333 | return false; |
| 4334 | } |
| 4335 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4336 | + " would have returned true for r=" + r); |
| 4337 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4341 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4342 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4343 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4344 | final ActivityRecord r = activities.get(activityNdx); |
| 4345 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4346 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4347 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | } |
| 4351 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4352 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4353 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4354 | boolean didSomething = false; |
| 4355 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4356 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4357 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4358 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4359 | int numActivities = activities.size(); |
| 4360 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4361 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4362 | final boolean sameComponent = |
| 4363 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4364 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4365 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4366 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4367 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4368 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4369 | if (!doit) { |
| 4370 | if (r.finishing) { |
| 4371 | // If this activity is just finishing, then it is not |
| 4372 | // interesting as far as something to stop. |
| 4373 | continue; |
| 4374 | } |
| 4375 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4376 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4377 | if (r.isHomeActivity()) { |
| 4378 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4379 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4380 | continue; |
| 4381 | } else { |
| 4382 | homeActivity = r.realActivity; |
| 4383 | } |
| 4384 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4385 | didSomething = true; |
| 4386 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4387 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4388 | if (r.app != null) { |
| 4389 | r.app.removed = true; |
| 4390 | } |
| 4391 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4392 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4393 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4394 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4395 | true)) { |
| 4396 | // r has been deleted from mActivities, accommodate. |
| 4397 | --numActivities; |
| 4398 | --activityNdx; |
| 4399 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4400 | } |
| 4401 | } |
| 4402 | } |
| 4403 | return didSomething; |
| 4404 | } |
| 4405 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4406 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4407 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4408 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4409 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4410 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4411 | if (task.getTopActivity() == null) { |
| 4412 | continue; |
| 4413 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4414 | ActivityRecord r = null; |
| 4415 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4416 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4417 | int numActivities = 0; |
| 4418 | int numRunning = 0; |
| 4419 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4420 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4421 | continue; |
| 4422 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4423 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4424 | tmp = activities.get(activityNdx); |
| 4425 | if (tmp.finishing) { |
| 4426 | continue; |
| 4427 | } |
| 4428 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4429 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4430 | // Initialize state for next task if needed. |
| 4431 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4432 | top = r; |
| 4433 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4434 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4435 | |
| 4436 | // Add 'r' into the current task. |
| 4437 | numActivities++; |
| 4438 | if (r.app != null && r.app.thread != null) { |
| 4439 | numRunning++; |
| 4440 | } |
| 4441 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4442 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4443 | TAG, r.intent.getComponent().flattenToShortString() |
| 4444 | + ": task=" + r.task); |
| 4445 | } |
| 4446 | |
| 4447 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4448 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4449 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4450 | ci.baseActivity = r.intent.getComponent(); |
| 4451 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4452 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4453 | if (focusedStack && topTask) { |
| 4454 | // Give the latest time to ensure foreground task can be sorted |
| 4455 | // at the first, because lastActiveTime of creating task is 0. |
| 4456 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4457 | topTask = false; |
| 4458 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4459 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4460 | if (top.task != null) { |
| 4461 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4462 | } |
| 4463 | ci.numActivities = numActivities; |
| 4464 | ci.numRunning = numRunning; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4465 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4466 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4470 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4471 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Performing unhandledBack(): top activity at " + top); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4472 | if (top >= 0) { |
| 4473 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4474 | int activityTop = activities.size() - 1; |
| 4475 | if (activityTop > 0) { |
| 4476 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4477 | "unhandled-back", true); |
| 4478 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4479 | } |
| 4480 | } |
| 4481 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4482 | /** |
| 4483 | * Reset local parameters because an app's activity died. |
| 4484 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4485 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4486 | */ |
| 4487 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4488 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4489 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4490 | "App died while pausing: " + mPausingActivity); |
| 4491 | mPausingActivity = null; |
| 4492 | } |
| 4493 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4494 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4495 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4498 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4499 | } |
| 4500 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4501 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4502 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4503 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4504 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4505 | final ActivityRecord r = activities.get(activityNdx); |
| 4506 | if (r.app == app) { |
| 4507 | Slog.w(TAG, " Force finishing activity " |
| 4508 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 4509 | // Force the destroy to skip right to removal. |
| 4510 | r.app = null; |
| 4511 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4512 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4513 | } |
| 4514 | } |
| 4515 | } |
| 4516 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4517 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4518 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4519 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4520 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4521 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4522 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 4523 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4524 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 4525 | " Task id #" + task.taskId + "\n" + |
| 4526 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 4527 | " mBounds=" + task.mBounds + "\n" + |
| 4528 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4529 | if (printed) { |
| 4530 | header = null; |
| 4531 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4532 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4533 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 4537 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 4538 | |
| 4539 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4540 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4541 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4542 | } |
| 4543 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4544 | final int top = mTaskHistory.size() - 1; |
| 4545 | if (top >= 0) { |
| 4546 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 4547 | int listTop = list.size() - 1; |
| 4548 | if (listTop >= 0) { |
| 4549 | activities.add(list.get(listTop)); |
| 4550 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4551 | } |
| 4552 | } else { |
| 4553 | ItemMatcher matcher = new ItemMatcher(); |
| 4554 | matcher.build(name); |
| 4555 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4556 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4557 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 4558 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 4559 | activities.add(r1); |
| 4560 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4561 | } |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | return activities; |
| 4566 | } |
| 4567 | |
| 4568 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4569 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4570 | |
| 4571 | // All activities that came from the package must be |
| 4572 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4573 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4574 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4575 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4576 | final ActivityRecord a = activities.get(activityNdx); |
| 4577 | if (a.info.packageName.equals(packageName)) { |
| 4578 | a.forceNewConfig = true; |
| 4579 | if (starting != null && a == starting && a.visible) { |
| 4580 | a.startFreezingScreenLocked(starting.app, |
| 4581 | ActivityInfo.CONFIG_SCREEN_LAYOUT); |
| 4582 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4583 | } |
| 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | return starting; |
| 4588 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4589 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4590 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4591 | removeTask(task, reason, !MOVING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4592 | } |
| 4593 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4594 | /** |
| 4595 | * Removes the input task from this stack. |
| 4596 | * @param task to remove. |
| 4597 | * @param reason for removal. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4598 | * @param moving task to another stack. In the case we are moving we don't want to perform |
| 4599 | * some operations on the task like removing it from window manager or recents. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4600 | */ |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4601 | void removeTask(TaskRecord task, String reason, boolean moving) { |
| 4602 | if (!moving) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4603 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4604 | mWindowManager.removeTask(task.taskId); |
Wale Ogunwale | b317b22 | 2015-11-09 11:14:10 -0800 | [diff] [blame] | 4605 | if (!StackId.persistTaskBounds(mStackId)) { |
| 4606 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 4607 | // default configuration the next time it launches. |
| 4608 | task.updateOverrideConfiguration(null); |
| 4609 | } |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4610 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4611 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4612 | final ActivityRecord r = mResumedActivity; |
| 4613 | if (r != null && r.task == task) { |
| 4614 | mResumedActivity = null; |
| 4615 | } |
| 4616 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4617 | final int taskNdx = mTaskHistory.indexOf(task); |
| 4618 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4619 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 4620 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 4621 | if (!nextTask.isOverHomeStack()) { |
| 4622 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 4623 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4624 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4625 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4626 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4627 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4628 | if (!moving && task.mActivities.isEmpty()) { |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4629 | final boolean isVoiceSession = task.voiceSession != null; |
| 4630 | if (isVoiceSession) { |
| 4631 | try { |
| 4632 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 4633 | } catch (RemoteException e) { |
| 4634 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4635 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4636 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 4637 | // Task creator asked to remove this when done, or this task was a voice |
| 4638 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 4639 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 4640 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4641 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4642 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4643 | |
| 4644 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4645 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Chong Zhang | a8be5e5 | 2015-10-05 17:06:28 -0700 | [diff] [blame] | 4646 | // We only need to adjust focused stack if this stack is in focus. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 4647 | if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4648 | String myReason = reason + " leftTaskHistoryEmpty"; |
| 4649 | if (mFullscreen || !adjustFocusToNextVisibleStackLocked(null, myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4650 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4651 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4652 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 4653 | if (mStacks != null) { |
| 4654 | mStacks.remove(this); |
| 4655 | mStacks.add(0, this); |
| 4656 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4657 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 4658 | mActivityContainer.onTaskListEmptyLocked(); |
| 4659 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4660 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 4661 | |
| 4662 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4663 | } |
| 4664 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4665 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 4666 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 4667 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4668 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 4669 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4670 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4671 | addTask(task, toTop, "createTaskRecord"); |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 4672 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 4673 | if (!layoutTaskInStack(task, info.layout) && mBounds != null && task.mResizeable |
| 4674 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 4675 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4676 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4677 | return task; |
| 4678 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4679 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 4680 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.Layout layout) { |
| 4681 | if (mTaskPositioner == null) { |
| 4682 | return false; |
| 4683 | } |
| 4684 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, layout); |
| 4685 | return true; |
| 4686 | } |
| 4687 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4688 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4689 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4690 | } |
| 4691 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4692 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
| 4693 | final ActivityStack prevStack = preAddTask(task, reason); |
| 4694 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4695 | task.stack = this; |
| 4696 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4697 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4698 | } else { |
| 4699 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4700 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4701 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4702 | postAddTask(task, prevStack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4703 | } |
| 4704 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4705 | void positionTask(final TaskRecord task, int position) { |
| 4706 | final ActivityStack prevStack = preAddTask(task, "positionTask"); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4707 | task.stack = this; |
| 4708 | insertTaskAtPosition(task, position); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4709 | postAddTask(task, prevStack); |
| 4710 | } |
| 4711 | |
| 4712 | private ActivityStack preAddTask(TaskRecord task, String reason) { |
| 4713 | final ActivityStack prevStack = task.stack; |
| 4714 | if (prevStack != null && prevStack != this) { |
| 4715 | prevStack.removeTask(task, reason, MOVING); |
| 4716 | } |
| 4717 | return prevStack; |
| 4718 | } |
| 4719 | |
| 4720 | private void postAddTask(TaskRecord task, ActivityStack prevStack) { |
| 4721 | if (prevStack != null) { |
| 4722 | if (prevStack != this |
| 4723 | && (prevStack.mStackId == PINNED_STACK_ID || mStackId == PINNED_STACK_ID)) { |
| 4724 | task.reportPictureInPictureModeChange(); |
| 4725 | } |
| 4726 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4727 | try { |
| 4728 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4729 | } catch (RemoteException e) { |
| 4730 | } |
| 4731 | } |
| 4732 | } |
| 4733 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4734 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4735 | final Rect bounds = task.getLaunchBounds(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4736 | task.updateOverrideConfiguration(bounds); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 4737 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 4738 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
| 4739 | (r.info.flags & ActivityInfo.FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, |
| 4740 | r.info.configChanges, task.voiceSession != null, r.mLaunchTaskBehind, |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 4741 | bounds, task.mOverrideConfig, !r.isHomeActivity()); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4742 | mWindowManager.setTaskResizeable(task.taskId, task.mResizeable); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4743 | r.taskConfigOverride = task.mOverrideConfig; |
| 4744 | } |
| 4745 | |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4746 | void setFocusAndResumeStateIfNeeded( |
| 4747 | ActivityRecord r, boolean setFocus, boolean setResume, String reason) { |
| 4748 | // If the activity had focus before move focus to this stack. |
| 4749 | if (setFocus) { |
| 4750 | // If the activity owns the last resumed activity, transfer that together, |
| 4751 | // so that we don't resume the same activity again in the new stack. |
| 4752 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 4753 | if (setResume) { |
| 4754 | mResumedActivity = r; |
| 4755 | // Move the stack in which we are placing the activity to the front. We don't use |
| 4756 | // ActivityManagerService.setFocusedActivityLocked, because if the activity is |
| 4757 | // already focused, the call will short-circuit and do nothing. |
| 4758 | moveToFront(reason); |
| 4759 | } else { |
| 4760 | // We need to not only move the stack to the front, but also have the activity |
| 4761 | // focused. This will achieve both goals. |
| 4762 | mService.setFocusedActivityLocked(r, reason); |
| 4763 | } |
| 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | /** |
| 4768 | * Moves the input activity from its current stack to this one. |
| 4769 | * NOTE: The current task of the activity isn't moved to this stack. Instead a new task is |
| 4770 | * created on this stack which the activity is added to. |
| 4771 | * */ |
| 4772 | void moveActivityToStack(ActivityRecord r) { |
| 4773 | final ActivityStack prevStack = r.task.stack; |
| 4774 | if (prevStack.mStackId == mStackId) { |
| 4775 | // You are already in the right stack silly... |
| 4776 | return; |
| 4777 | } |
| 4778 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 4779 | final boolean wasFocused = mStackSupervisor.isFocusedStack(prevStack) |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4780 | && (mStackSupervisor.topRunningActivityLocked() == r); |
| 4781 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 4782 | |
| 4783 | final TaskRecord task = createTaskRecord( |
| 4784 | mStackSupervisor.getNextTaskId(), r.info, r.intent, null, null, true); |
| 4785 | r.setTask(task, null); |
| 4786 | task.addActivityToTop(r); |
| 4787 | setAppTask(r, task); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4788 | task.reportPictureInPictureModeChange(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4789 | setFocusAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack"); |
| 4790 | } |
| 4791 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4792 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
| 4793 | final Rect bounds = task.getLaunchBounds(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4794 | task.updateOverrideConfiguration(bounds); |
| 4795 | mWindowManager.setAppTask( |
Wale Ogunwale | 2998eef | 2015-12-02 19:46:29 -0800 | [diff] [blame] | 4796 | r.appToken, task.taskId, mStackId, task.getLaunchBounds(), task.mOverrideConfig); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4797 | mWindowManager.setTaskResizeable(task.taskId, task.mResizeable); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4798 | r.taskConfigOverride = task.mOverrideConfig; |
| 4799 | } |
| 4800 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4801 | public int getStackId() { |
| 4802 | return mStackId; |
| 4803 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4804 | |
| 4805 | @Override |
| 4806 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 4807 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 4808 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4809 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4810 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4811 | void onLockTaskPackagesUpdatedLocked() { |
| 4812 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4813 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 4814 | } |
| 4815 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4816 | } |