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 | 61803ee | 2015-08-07 19:59:47 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID; |
| 21 | import static android.app.ActivityManager.HOME_STACK_ID; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 23 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 24 | import static com.android.server.am.ActivityManagerDebugConfig.*; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 25 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 26 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
| 27 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 28 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 29 | import static com.android.server.am.ActivityStackSupervisor.MOVING; |
| 30 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 31 | import android.graphics.Rect; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 32 | import android.util.ArraySet; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 33 | import android.view.IApplicationToken; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 34 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 35 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 36 | import com.android.internal.os.BatteryStatsImpl; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 37 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 38 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 39 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 40 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 41 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 42 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 43 | |
| 44 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 45 | import android.app.ActivityManager; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 46 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 47 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 48 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 49 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 50 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 51 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 52 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 53 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 54 | import android.content.pm.PackageManager; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 55 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 56 | import android.graphics.Bitmap; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 57 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 58 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 59 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 60 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 61 | import android.os.Handler; |
| 62 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 63 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 64 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 65 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 66 | import android.os.RemoteException; |
| 67 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 68 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 69 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 70 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 71 | import android.util.EventLog; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 72 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 73 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 74 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 75 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 76 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 77 | import java.lang.ref.WeakReference; |
| 78 | import java.util.ArrayList; |
| 79 | import java.util.Iterator; |
| 80 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 81 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 82 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * State and management of a single stack of activities. |
| 86 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 87 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 88 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 89 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 90 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 91 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 92 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 93 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 94 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 95 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 96 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 97 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 98 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 99 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 100 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 101 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 102 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 103 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 104 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 105 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 106 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 107 | |
| 108 | private static final boolean VALIDATE_TOKENS = false; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 109 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 110 | // Ticks during which we check progress while waiting for an app to launch. |
| 111 | static final int LAUNCH_TICK = 500; |
| 112 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 113 | // How long we wait until giving up on the last activity to pause. This |
| 114 | // is short because it directly impacts the responsiveness of starting the |
| 115 | // next activity. |
| 116 | static final int PAUSE_TIMEOUT = 500; |
| 117 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 118 | // How long we wait for the activity to tell us it has stopped before |
| 119 | // giving up. This is a good amount of time because we really need this |
| 120 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 121 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 122 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 123 | // How long we wait until giving up on an activity telling us it has |
| 124 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 125 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 126 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 127 | // 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] | 128 | // disabled. |
| 129 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 130 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 131 | // How long between activity launches that we consider safe to not warn |
| 132 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 133 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 134 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 135 | // Set to false to disable the preview that is shown while a new activity |
| 136 | // is being started. |
| 137 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 138 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 139 | // How long to wait for all background Activities to redraw following a call to |
| 140 | // convertToTranslucent(). |
| 141 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 142 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 143 | enum ActivityState { |
| 144 | INITIALIZING, |
| 145 | RESUMED, |
| 146 | PAUSING, |
| 147 | PAUSED, |
| 148 | STOPPING, |
| 149 | STOPPED, |
| 150 | FINISHING, |
| 151 | DESTROYING, |
| 152 | DESTROYED |
| 153 | } |
| 154 | |
| 155 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 156 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 157 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 158 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 159 | /** |
| 160 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 161 | * running) activities. It contains #TaskRecord objects. |
| 162 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 163 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 164 | |
| 165 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 166 | * Used for validating app tokens with window manager. |
| 167 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 168 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 169 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 170 | /** |
| 171 | * List of running activities, sorted by recent usage. |
| 172 | * The first entry in the list is the least recently used. |
| 173 | * It contains HistoryRecord objects. |
| 174 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 175 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 176 | |
| 177 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 178 | * Animations that for the current transition have requested not to |
| 179 | * be considered for the transition animation. |
| 180 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 181 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 182 | |
| 183 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 184 | * When we are in the process of pausing an activity, before starting the |
| 185 | * next one, this variable holds the activity that is currently being paused. |
| 186 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 187 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * This is the last activity that we put into the paused state. This is |
| 191 | * used to determine if we need to do an activity transition while sleeping, |
| 192 | * when we normally hold the top activity paused. |
| 193 | */ |
| 194 | ActivityRecord mLastPausedActivity = null; |
| 195 | |
| 196 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 197 | * Activities that specify No History must be removed once the user navigates away from them. |
| 198 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 199 | * and finish it later if another activity replaces it on wakeup. |
| 200 | */ |
| 201 | ActivityRecord mLastNoHistoryActivity = null; |
| 202 | |
| 203 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 204 | * Current activity that is resumed, or null if there is none. |
| 205 | */ |
| 206 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 207 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 208 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 209 | * This is the last activity that has been started. It is only used to |
| 210 | * identify when multiple activities are started at once so that the user |
| 211 | * can be warned they may not be in the activity they think they are. |
| 212 | */ |
| 213 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 214 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 215 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 216 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 217 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 218 | // Activity in mTranslucentActivityWaiting is notified via |
| 219 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 220 | // background activity being drawn then the same call will be made with a true value. |
| 221 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 222 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 223 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 224 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 225 | * Set when we know we are going to be calling updateConfiguration() |
| 226 | * soon, so want to skip intermediate config checks. |
| 227 | */ |
| 228 | boolean mConfigWillChange; |
| 229 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 230 | // 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] | 231 | boolean mFullscreen = true; |
| 232 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 233 | long mLaunchStartTime = 0; |
| 234 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 235 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 236 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 237 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 238 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 239 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 240 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 241 | ArrayList<ActivityStack> mStacks; |
| 242 | /** The attached Display's unique identifier, or -1 if detached */ |
| 243 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 244 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 245 | /** Run all ActivityStacks through this */ |
| 246 | final ActivityStackSupervisor mStackSupervisor; |
| 247 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 248 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 249 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 250 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 251 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 252 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 253 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 254 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 255 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 256 | |
| 257 | static class ScheduleDestroyArgs { |
| 258 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 259 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 260 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 261 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 262 | mReason = reason; |
| 263 | } |
| 264 | } |
| 265 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 266 | final Handler mHandler; |
| 267 | |
| 268 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 269 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 270 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 271 | super(looper); |
| 272 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 273 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 274 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 275 | public void handleMessage(Message msg) { |
| 276 | switch (msg.what) { |
| 277 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 278 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 279 | // We don't at this point know if the activity is fullscreen, |
| 280 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 281 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 282 | synchronized (mService) { |
| 283 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 284 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 285 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 286 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 287 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 288 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 289 | case LAUNCH_TICK_MSG: { |
| 290 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 291 | synchronized (mService) { |
| 292 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 293 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 297 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 298 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 299 | // We don't at this point know if the activity is fullscreen, |
| 300 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 301 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 302 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 303 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 304 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 305 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 306 | case STOP_TIMEOUT_MSG: { |
| 307 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 308 | // We don't at this point know if the activity is fullscreen, |
| 309 | // so we need to be conservative and assume it isn't. |
| 310 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 311 | synchronized (mService) { |
| 312 | if (r.isInHistory()) { |
| 313 | activityStoppedLocked(r, null, null, null); |
| 314 | } |
| 315 | } |
| 316 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 317 | case DESTROY_ACTIVITIES_MSG: { |
| 318 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 319 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 320 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 321 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 322 | } break; |
| 323 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 324 | synchronized (mService) { |
| 325 | notifyActivityDrawnLocked(null); |
| 326 | } |
| 327 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 328 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 329 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 330 | final ActivityRecord r = getVisibleBehindActivity(); |
| 331 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 332 | if (r != null) { |
| 333 | mService.killAppAtUsersRequest(r.app, null); |
| 334 | } |
| 335 | } |
| 336 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 341 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 342 | int count = 0; |
| 343 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 344 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 345 | } |
| 346 | return count; |
| 347 | } |
| 348 | |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 349 | int numTasks() { |
| 350 | return mTaskHistory.size(); |
| 351 | } |
| 352 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 353 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 354 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 355 | mActivityContainer = activityContainer; |
| 356 | mStackSupervisor = activityContainer.getOuter(); |
| 357 | mService = mStackSupervisor.mService; |
| 358 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 359 | mWindowManager = mService.mWindowManager; |
| 360 | mStackId = activityContainer.mStackId; |
| 361 | mCurrentUser = mService.mCurrentUserId; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 362 | mRecentTasks = recentTasks; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 363 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 364 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 365 | boolean okToShowLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame^] | 366 | return mStackSupervisor.okToShowLocked(r); |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 369 | final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 370 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 371 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(notTop); |
| 372 | if (r != null) { |
| 373 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 374 | } |
| 375 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 376 | return null; |
| 377 | } |
| 378 | |
| 379 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 380 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 381 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 382 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 383 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 384 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 385 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 386 | return r; |
| 387 | } |
| 388 | } |
| 389 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 390 | return null; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 395 | * 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] | 396 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 397 | * @param token If non-null, any history records matching this token will be skipped. |
| 398 | * @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] | 399 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 400 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 401 | */ |
| 402 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 403 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 404 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 405 | if (task.taskId == taskId) { |
| 406 | continue; |
| 407 | } |
| 408 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 409 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 410 | final ActivityRecord r = activities.get(i); |
| 411 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 412 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 413 | return r; |
| 414 | } |
| 415 | } |
| 416 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 417 | return null; |
| 418 | } |
| 419 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 420 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 421 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 422 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 423 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 424 | final ActivityRecord r = activities.get(activityNdx); |
| 425 | if (!r.finishing) { |
| 426 | return r; |
| 427 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 430 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 433 | final TaskRecord topTask() { |
| 434 | final int size = mTaskHistory.size(); |
| 435 | if (size > 0) { |
| 436 | return mTaskHistory.get(size - 1); |
| 437 | } |
| 438 | return null; |
| 439 | } |
| 440 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 441 | TaskRecord taskForIdLocked(int id) { |
| 442 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 443 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 444 | if (task.taskId == id) { |
| 445 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 446 | } |
| 447 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 448 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 451 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 452 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 453 | return isInStackLocked(r); |
| 454 | } |
| 455 | |
| 456 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 457 | if (r == null) { |
| 458 | return null; |
| 459 | } |
| 460 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 461 | if (task != null && task.stack != null |
| 462 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 463 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 464 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 465 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 466 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 467 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 470 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 471 | final boolean hadit = mLRUActivities.remove(r); |
| 472 | mLRUActivities.add(r); |
| 473 | return hadit; |
| 474 | } |
| 475 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 476 | final boolean isHomeStack() { |
| 477 | return mStackId == HOME_STACK_ID; |
| 478 | } |
| 479 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 480 | final boolean isOnHomeDisplay() { |
| 481 | return isAttached() && |
| 482 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 483 | } |
| 484 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 485 | void moveToFront(String reason) { |
| 486 | moveToFront(reason, null); |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * @param reason The reason for moving the stack to the front. |
| 491 | * @param task If non-null, the task will be moved to the top of the stack. |
| 492 | * */ |
| 493 | void moveToFront(String reason, TaskRecord task) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 494 | if (isAttached()) { |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 495 | final boolean homeStack = isHomeStack() |
| 496 | || (mActivityContainer.mParentActivity != null |
| 497 | && mActivityContainer.mParentActivity.isHomeActivity()); |
| 498 | ActivityStack lastFocusStack = null; |
| 499 | if (!homeStack) { |
| 500 | // Need to move this stack to the front before calling |
| 501 | // {@link ActivityStackSupervisor#moveHomeStack} below. |
| 502 | lastFocusStack = mStacks.get(mStacks.size() - 1); |
| 503 | mStacks.remove(this); |
| 504 | mStacks.add(this); |
Wale Ogunwale | af0e448 | 2015-02-24 12:27:31 -0800 | [diff] [blame] | 505 | } |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 506 | // TODO(multi-display): Focus stack currently adjusted in call to move home stack. |
| 507 | // Needs to also work if focus is moving to the non-home display. |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 508 | if (isOnHomeDisplay()) { |
| 509 | mStackSupervisor.moveHomeStack(homeStack, reason, lastFocusStack); |
| 510 | } |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 511 | if (task != null) { |
| 512 | insertTaskAtTop(task, null); |
| 513 | } else { |
| 514 | task = topTask(); |
| 515 | } |
Craig Mautner | 6b904ef | 2014-12-17 15:45:03 -0800 | [diff] [blame] | 516 | if (task != null) { |
| 517 | mWindowManager.moveTaskToTop(task.taskId); |
| 518 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 519 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | final boolean isAttached() { |
| 523 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 526 | /** |
| 527 | * Returns the top activity in any existing task matching the given |
| 528 | * Intent. Returns null if no such task is found. |
| 529 | */ |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 530 | ActivityRecord findTaskLocked(ActivityRecord target) { |
| 531 | Intent intent = target.intent; |
| 532 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 533 | ComponentName cls = intent.getComponent(); |
| 534 | if (info.targetActivity != null) { |
| 535 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 536 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 537 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 538 | boolean isDocument = intent != null & intent.isDocument(); |
| 539 | // If documentData is non-null then it must match the existing task data. |
| 540 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 541 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 542 | 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] | 543 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 544 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 545 | if (task.voiceSession != null) { |
| 546 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 547 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 548 | continue; |
| 549 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 550 | if (task.userId != userId) { |
| 551 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 552 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 553 | continue; |
| 554 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 555 | final ActivityRecord r = task.getTopActivity(); |
| 556 | if (r == null || r.finishing || r.userId != userId || |
| 557 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 558 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 559 | continue; |
| 560 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 561 | if (r.mActivityType != target.mActivityType) { |
| 562 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 563 | continue; |
| 564 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 565 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 566 | final Intent taskIntent = task.intent; |
| 567 | final Intent affinityIntent = task.affinityIntent; |
| 568 | final boolean taskIsDocument; |
| 569 | final Uri taskDocumentData; |
| 570 | if (taskIntent != null && taskIntent.isDocument()) { |
| 571 | taskIsDocument = true; |
| 572 | taskDocumentData = taskIntent.getData(); |
| 573 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 574 | taskIsDocument = true; |
| 575 | taskDocumentData = affinityIntent.getData(); |
| 576 | } else { |
| 577 | taskIsDocument = false; |
| 578 | taskDocumentData = null; |
| 579 | } |
| 580 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 581 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 582 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 583 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 584 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 585 | if (!isDocument && !taskIsDocument && task.rootAffinity != null) { |
| 586 | if (task.rootAffinity.equals(target.taskAffinity)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 587 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 588 | return r; |
| 589 | } |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 590 | } else if (taskIntent != null && taskIntent.getComponent() != null && |
| 591 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 592 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 593 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 594 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 595 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 596 | "For Intent " + intent + " bringing to top: " + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 597 | return r; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 598 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 599 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 600 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 601 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 602 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 603 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 604 | "For Intent " + intent + " bringing to top: " + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 605 | return r; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 606 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | return null; |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Returns the first activity (starting from the top of the stack) that |
| 614 | * is the same as the given activity. Returns null if no such activity |
| 615 | * is found. |
| 616 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 617 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 618 | ComponentName cls = intent.getComponent(); |
| 619 | if (info.targetActivity != null) { |
| 620 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 621 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 622 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 623 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 624 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 625 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 626 | final boolean notCurrentUserTask = |
| 627 | !mStackSupervisor.isCurrentProfileLocked(task.userId); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 628 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 629 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 630 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 631 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 632 | if (notCurrentUserTask && (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 633 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 634 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 635 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 636 | return r; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | return null; |
| 642 | } |
| 643 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 644 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 645 | * 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] | 646 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 647 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 648 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 649 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 650 | } |
| 651 | mCurrentUser = userId; |
| 652 | |
| 653 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 654 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 655 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 656 | final TaskRecord task = mTaskHistory.get(i); |
| 657 | |
| 658 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 659 | // okay to show the activity when locked. |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 660 | if (mStackSupervisor.isCurrentProfileLocked(task.userId) |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 661 | || task.topRunningActivityLocked(null) != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 662 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 663 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 664 | mTaskHistory.remove(i); |
| 665 | mTaskHistory.add(task); |
| 666 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 667 | // Use same value for i. |
| 668 | } else { |
| 669 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 670 | } |
| 671 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 672 | if (VALIDATE_TOKENS) { |
| 673 | validateAppTokensLocked(); |
| 674 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 677 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 678 | r.state = ActivityState.RESUMED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 679 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 680 | "Moving to RESUMED: " + r + " (starting new instance)"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 681 | r.stopped = false; |
| 682 | mResumedActivity = r; |
| 683 | r.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 684 | mRecentTasks.addLocked(r.task); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 685 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 686 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 687 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 688 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 689 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame^] | 692 | private void addRecentActivityLocked(ActivityRecord r) { |
| 693 | if (r != null) { |
| 694 | mRecentTasks.addLocked(r.task); |
| 695 | r.task.touchActiveTime(); |
| 696 | } |
| 697 | } |
| 698 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 699 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 700 | if (mFullyDrawnStartTime != 0) { |
| 701 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 702 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 703 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 704 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 705 | } |
| 706 | |
| 707 | private void stopFullyDrawnTraceIfNeeded() { |
| 708 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 709 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 710 | mFullyDrawnStartTime = 0; |
| 711 | } |
| 712 | } |
| 713 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 714 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 715 | if (r.displayStartTime == 0) { |
| 716 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 717 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 718 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 719 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 720 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 721 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 722 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 723 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 724 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 725 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 726 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 727 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 728 | // Make sure that there is no activity waiting for this to launch. |
| 729 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 730 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 731 | } else { |
| 732 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 733 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 734 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 737 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 738 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 739 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 740 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 741 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 742 | activities.get(activityNdx).setSleeping(false); |
| 743 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 744 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 745 | if (mPausingActivity != null) { |
| 746 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 747 | activityPausedLocked(mPausingActivity.appToken, true); |
| 748 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 749 | } |
| 750 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 751 | /** |
| 752 | * @return true if something must be done before going to sleep. |
| 753 | */ |
| 754 | boolean checkReadyForSleepLocked() { |
| 755 | if (mResumedActivity != null) { |
| 756 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 757 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 758 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 759 | "Sleep => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 760 | startPausingLocked(false, true, false, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 761 | return true; |
| 762 | } |
| 763 | if (mPausingActivity != null) { |
| 764 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 765 | 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] | 766 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 767 | } |
| 768 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 769 | if (hasVisibleBehindActivity()) { |
| 770 | // Stop visible behind activity before going to sleep. |
| 771 | final ActivityRecord r = mActivityContainer.mActivityDisplay.mVisibleBehindActivity; |
| 772 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 773 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 774 | "Sleep still waiting to stop visible behind " + r); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 775 | return true; |
| 776 | } |
| 777 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 778 | return false; |
| 779 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 780 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 781 | void goToSleep() { |
| 782 | ensureActivitiesVisibleLocked(null, 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 783 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 784 | // Make sure any stopped but visible activities are now sleeping. |
| 785 | // This ensures that the activity's onStop() is called. |
| 786 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 787 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 788 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 789 | final ActivityRecord r = activities.get(activityNdx); |
| 790 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 791 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 792 | } |
| 793 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 794 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 795 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 796 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 797 | public final Bitmap screenshotActivities(ActivityRecord who) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 798 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivities: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 799 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 800 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 801 | return null; |
| 802 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 803 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 804 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 805 | // 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] | 806 | // 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] | 807 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 808 | return null; |
| 809 | } |
| 810 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 811 | int w = mService.mThumbnailWidth; |
| 812 | int h = mService.mThumbnailHeight; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 813 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 814 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 815 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Dianne Hackborn | 27eac1d | 2015-03-16 17:15:53 -0700 | [diff] [blame] | 816 | w, h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 817 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 818 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 819 | return null; |
| 820 | } |
| 821 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 822 | /** |
| 823 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 824 | * is already an activity being paused or there is no resumed activity. |
| 825 | * |
| 826 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 827 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 828 | * screen turning off). |
| 829 | * @param resuming True if this is being called as part of resuming the top activity, so |
| 830 | * we shouldn't try to instigate a resume here. |
| 831 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 832 | * set to true, we will immediately complete the pause here before returning. |
| 833 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 834 | * it to tell us when it is done. |
| 835 | */ |
| 836 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming, |
| 837 | boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 838 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 839 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 840 | + " state=" + mPausingActivity.state); |
| 841 | if (!mService.isSleeping()) { |
| 842 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 843 | // Because activity will be paused immediately after resume, just let pause |
| 844 | // be completed by the order of activity paused from clients. |
| 845 | completePauseLocked(false); |
| 846 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 847 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 848 | ActivityRecord prev = mResumedActivity; |
| 849 | if (prev == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 850 | if (!resuming) { |
| 851 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
| 852 | mStackSupervisor.resumeTopActivitiesLocked(); |
| 853 | } |
| 854 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 855 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 856 | |
| 857 | if (mActivityContainer.mParentActivity == null) { |
| 858 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 859 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 860 | } |
| 861 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 862 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 863 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 864 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 865 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 866 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 867 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 868 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 869 | prev.state = ActivityState.PAUSING; |
| 870 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 871 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 872 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | d3e2a08 | 2014-11-04 16:09:19 -0800 | [diff] [blame] | 873 | if (mService.mHasRecents && (next == null || next.noDisplay || next.task != prev.task || uiSleeping)) { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 874 | prev.updateThumbnailLocked(screenshotActivities(prev), null); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 875 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 876 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 877 | |
| 878 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 879 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 880 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 881 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 882 | try { |
| 883 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 884 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 885 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 886 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 887 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 888 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 889 | } catch (Exception e) { |
| 890 | // Ignore exception, if process died other code will cleanup. |
| 891 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 892 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 893 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 894 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 895 | } |
| 896 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 897 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 898 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 899 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | // If we are not going to sleep, we want to ensure the device is |
| 903 | // awake until the next activity is started. |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 904 | if (!uiSleeping && !mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 905 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 908 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 909 | // Have the window manager pause its key dispatching until the new |
| 910 | // activity has started. If we're pausing the activity just because |
| 911 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 912 | // key dispatch; the same activity will pick it up again on wakeup. |
| 913 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 914 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 915 | } else if (DEBUG_PAUSE) { |
| 916 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 919 | if (dontWait) { |
| 920 | // If the caller said they don't want to wait for the pause, then complete |
| 921 | // the pause now. |
| 922 | completePauseLocked(false); |
| 923 | return false; |
| 924 | |
| 925 | } else { |
| 926 | // Schedule a pause timeout in case the app doesn't respond. |
| 927 | // We don't give it much time because this directly impacts the |
| 928 | // responsiveness seen by the user. |
| 929 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 930 | msg.obj = prev; |
| 931 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 932 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 933 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 934 | return true; |
| 935 | } |
| 936 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 937 | } else { |
| 938 | // This activity failed to schedule the |
| 939 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 940 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 941 | if (!resuming) { |
| 942 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
| 943 | } |
| 944 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 947 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 948 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 949 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 950 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 951 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 952 | final ActivityRecord r = isInStackLocked(token); |
| 953 | if (r != null) { |
| 954 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 955 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 956 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 957 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 958 | completePauseLocked(true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 959 | } else { |
| 960 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 961 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 962 | mPausingActivity != null |
| 963 | ? mPausingActivity.shortComponentName : "(none)"); |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 964 | if (r.finishing && r.state == ActivityState.PAUSING) { |
| 965 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 966 | "Executing finish of failed to pause activity: " + r); |
| 967 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 968 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 973 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 974 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 975 | if (r.state != ActivityState.STOPPING) { |
| 976 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 977 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 978 | return; |
| 979 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 980 | if (persistentState != null) { |
| 981 | r.persistentState = persistentState; |
| 982 | mService.notifyTaskPersisterLocked(r.task, false); |
| 983 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 984 | 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] | 985 | if (icicle != null) { |
| 986 | // If icicle is null, this is happening due to a timeout, so we |
| 987 | // haven't really saved the state. |
| 988 | r.icicle = icicle; |
| 989 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 990 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 991 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 992 | } |
| 993 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 994 | 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] | 995 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 996 | r.stopped = true; |
| 997 | r.state = ActivityState.STOPPED; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 998 | if (mActivityContainer.mActivityDisplay.mVisibleBehindActivity == r) { |
| 999 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1000 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1001 | if (r.finishing) { |
| 1002 | r.clearOptionsLocked(); |
| 1003 | } else { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1004 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1005 | destroyActivityLocked(r, true, "stop-config"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1006 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1007 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1008 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1009 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1014 | private void completePauseLocked(boolean resumeNext) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1015 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1016 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1017 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1018 | if (prev != null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1019 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1020 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1021 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1022 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1023 | } else if (prev.app != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1024 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending stop: " + prev); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1025 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1026 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1027 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1028 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1029 | if (prev.configDestroy) { |
| 1030 | // The previous is being paused because the configuration |
| 1031 | // is changing, which means it is actually stopping... |
| 1032 | // To juggle the fact that we are also starting a new |
| 1033 | // instance right now, we need to first completely stop |
| 1034 | // the current instance before starting the new one. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1035 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Destroying after pause: " + prev); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1036 | destroyActivityLocked(prev, true, "pause-config"); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 1037 | } else if (!hasVisibleBehindActivity() || mService.isSleepingOrShuttingDown()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1038 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1039 | // stopping. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1040 | mStackSupervisor.mStoppingActivities.add(prev); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1041 | if (mStackSupervisor.mStoppingActivities.size() > 3 || |
| 1042 | prev.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1043 | // If we already have a few activities waiting to stop, |
| 1044 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1045 | // them out. Or if r is the last of activity of the last task the stack |
| 1046 | // will be empty and must be cleared immediately. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1047 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "To many pending stops, forcing idle"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1048 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1049 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1050 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1054 | 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] | 1055 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1056 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1057 | // It is possible the activity was freezing the screen before it was paused. |
| 1058 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1059 | // since it is no longer visible. |
| 1060 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1061 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1062 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1063 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1064 | if (resumeNext) { |
| 1065 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
| 1066 | if (!mService.isSleepingOrShuttingDown()) { |
| 1067 | mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null); |
| 1068 | } else { |
| 1069 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1070 | ActivityRecord top = topStack.topRunningActivityLocked(null); |
| 1071 | if (top == null || (prev != null && top != prev)) { |
| 1072 | // If there are no more activities available to run, |
| 1073 | // do resume anyway to start something. Also if the top |
| 1074 | // activity on the stack is not the just paused activity, |
| 1075 | // we need to go ahead and resume it to ensure we complete |
| 1076 | // an in-flight app switch. |
| 1077 | mStackSupervisor.resumeTopActivitiesLocked(topStack, null, null); |
| 1078 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1079 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1080 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1081 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1082 | if (prev != null) { |
| 1083 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1084 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1085 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1086 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1087 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1088 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1089 | if (diff > 0) { |
| 1090 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1091 | synchronized (bsi) { |
| 1092 | BatteryStatsImpl.Uid.Proc ps = |
| 1093 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1094 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1095 | if (ps != null) { |
| 1096 | ps.addForegroundTimeLocked(diff); |
| 1097 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1101 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1102 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1103 | |
| 1104 | // Notfiy when the task stack has changed |
| 1105 | mService.notifyTaskStackChangedLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | /** |
| 1109 | * Once we know that we have asked an application to put an activity in |
| 1110 | * the resumed state (either by launching it or explicitly telling it), |
| 1111 | * this function updates the rest of our state to match that fact. |
| 1112 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1113 | private void completeResumeLocked(ActivityRecord next) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1114 | next.idle = false; |
| 1115 | next.results = null; |
| 1116 | next.newIntents = null; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1117 | |
| 1118 | if (next.isHomeActivity() && next.isNotResolverActivity()) { |
| 1119 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1120 | if (app != null && app != mService.mHomeProcess) { |
| 1121 | mService.mHomeProcess = app; |
| 1122 | } |
| 1123 | } |
| 1124 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1125 | if (next.nowVisible) { |
| 1126 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1127 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1128 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1129 | |
| 1130 | // 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] | 1131 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1132 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1133 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1134 | |
| 1135 | next.resumeKeyDispatchingLocked(); |
| 1136 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1137 | |
| 1138 | // Mark the point when the activity is resuming |
| 1139 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1140 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1141 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1142 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1143 | } else { |
| 1144 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1145 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1146 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1147 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1148 | |
| 1149 | if (mActivityContainer.mActivityDisplay.mVisibleBehindActivity == next) { |
| 1150 | // When resuming an activity, require it to call requestVisibleBehind() again. |
| 1151 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(null); |
| 1152 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1155 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1156 | r.visible = visible; |
| 1157 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1158 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1159 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1160 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1161 | container.setVisible(visible); |
| 1162 | } |
| 1163 | } |
| 1164 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1165 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1166 | // otherwise return null; |
| 1167 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1168 | TaskRecord task = r.task; |
| 1169 | if (task == null) { |
| 1170 | return null; |
| 1171 | } |
| 1172 | |
| 1173 | ActivityStack stack = task.stack; |
| 1174 | if (stack == null) { |
| 1175 | return null; |
| 1176 | } |
| 1177 | |
| 1178 | int stackNdx = mStacks.indexOf(stack); |
| 1179 | |
| 1180 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1181 | int taskNdx = tasks.indexOf(task); |
| 1182 | |
| 1183 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1184 | int activityNdx = activities.indexOf(r) + 1; |
| 1185 | |
| 1186 | final int numStacks = mStacks.size(); |
| 1187 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1188 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1189 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1190 | final int numTasks = tasks.size(); |
| 1191 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1192 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1193 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1194 | final int numActivities = activities.size(); |
| 1195 | while (activityNdx < numActivities) { |
| 1196 | final ActivityRecord activity = activities.get(activityNdx); |
| 1197 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1198 | return historyStack.mFullscreen |
| 1199 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1200 | } |
| 1201 | ++activityNdx; |
| 1202 | } |
| 1203 | activityNdx = 0; |
| 1204 | ++taskNdx; |
| 1205 | } |
| 1206 | taskNdx = 0; |
| 1207 | ++stackNdx; |
| 1208 | } |
| 1209 | |
| 1210 | return null; |
| 1211 | } |
| 1212 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1213 | private ActivityStack getNextVisibleStackLocked() { |
| 1214 | ArrayList<ActivityStack> stacks = mStacks; |
| 1215 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1216 | if (parent != null) { |
| 1217 | stacks = parent.task.stack.mStacks; |
| 1218 | } |
| 1219 | if (stacks != null) { |
| 1220 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1221 | ActivityStack stack = stacks.get(i); |
| 1222 | if (stack != this && stack.isStackVisibleLocked()) { |
| 1223 | return stack; |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | return null; |
| 1228 | } |
| 1229 | |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1230 | // Checks if any of the stacks above this one has a fullscreen activity behind it. |
| 1231 | // If so, this stack is hidden, otherwise it is visible. |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1232 | private boolean isStackVisibleLocked() { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1233 | if (!isAttached()) { |
| 1234 | return false; |
| 1235 | } |
| 1236 | |
| 1237 | if (mStackSupervisor.isFrontStack(this)) { |
| 1238 | return true; |
| 1239 | } |
| 1240 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1241 | // Any stack that isn't the front stack is not visible, except for the case of the home |
| 1242 | // stack behind the main application stack since we can have dialog activities on the |
| 1243 | // main application stack that need the home stack to display behind them. |
| 1244 | // TODO(multi-window): Also need to add exception for side-by-side stacks. |
| 1245 | final boolean homeStack = mStackId == HOME_STACK_ID; |
| 1246 | if (!homeStack) { |
| 1247 | return false; |
| 1248 | } |
| 1249 | |
Jose Lima | 729cb23 | 2014-05-05 15:59:40 -0700 | [diff] [blame] | 1250 | /** |
| 1251 | * Start at the task above this one and go up, looking for a visible |
| 1252 | * fullscreen activity, or a translucent activity that requested the |
| 1253 | * wallpaper to be shown behind it. |
| 1254 | */ |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1255 | for (int i = mStacks.indexOf(this) + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1256 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1257 | if (stack.mStackId != FULLSCREEN_WORKSPACE_STACK_ID) { |
| 1258 | return false; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1259 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1260 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1261 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1262 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1263 | final TaskRecord task = tasks.get(taskNdx); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1264 | // task above isn't fullscreen, so, we assume we're still visible. |
| 1265 | if (!task.mFullscreen) { |
| 1266 | continue; |
| 1267 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1268 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1269 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1270 | final ActivityRecord r = activities.get(activityNdx); |
Jose Lima | 729cb23 | 2014-05-05 15:59:40 -0700 | [diff] [blame] | 1271 | |
| 1272 | // Conditions for an activity to obscure the stack we're |
| 1273 | // examining: |
| 1274 | // 1. Not Finishing AND Visible AND: |
| 1275 | // 2. Either: |
| 1276 | // - Full Screen Activity OR |
| 1277 | // - On top of Home and our stack is NOT home |
| 1278 | if (!r.finishing && r.visible && (r.fullscreen || |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1279 | (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()))) { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1280 | return false; |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | return true; |
| 1287 | } |
| 1288 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1289 | /** |
| 1290 | * Make sure that all activities that need to be visible (that is, they |
| 1291 | * currently can be seen by the user) actually are. |
| 1292 | */ |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1293 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) { |
| 1294 | ActivityRecord top = topRunningActivityLocked(null); |
| 1295 | if (top == null) { |
| 1296 | return; |
| 1297 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1298 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1299 | "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1300 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 1301 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1302 | if (mTranslucentActivityWaiting != top) { |
| 1303 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1304 | if (mTranslucentActivityWaiting != null) { |
| 1305 | // Call the callback with a timeout indication. |
| 1306 | notifyActivityDrawnLocked(null); |
| 1307 | mTranslucentActivityWaiting = null; |
| 1308 | } |
| 1309 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1310 | } |
| 1311 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1312 | // If the top activity is not fullscreen, then we need to |
| 1313 | // make sure any activities under it are now visible. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1314 | boolean aboveTop = true; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1315 | boolean behindFullscreen = !isStackVisibleLocked(); |
Wale Ogunwale | addd00e | 2015-04-04 17:10:50 -0700 | [diff] [blame] | 1316 | boolean noStackActivityResumed = (isInStackLocked(starting) == null); |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1317 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1318 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1319 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1320 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1321 | // Set to true if an activity in this task is fullscreen thereby hiding other |
| 1322 | // activities in the same task. Initialized to the same value as behindFullscreen |
| 1323 | // which represent if the entire task/stack is behind another fullscreen task/stack. |
| 1324 | boolean behindFullscreenActivity = behindFullscreen; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1325 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1326 | final ActivityRecord r = activities.get(activityNdx); |
| 1327 | if (r.finishing) { |
| 1328 | continue; |
| 1329 | } |
| 1330 | if (aboveTop && r != top) { |
| 1331 | continue; |
| 1332 | } |
| 1333 | aboveTop = false; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1334 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1335 | // but must be drawn initially for the animation as though they were visible. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1336 | if (!behindFullscreenActivity || r.mLaunchTaskBehind) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1337 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1338 | "Make visible? " + r + " finishing=" + r.finishing |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1339 | + " state=" + r.state); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1340 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1341 | // First: if this is not the current activity being started, make |
| 1342 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1343 | if (r != starting) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1344 | ensureActivityConfigurationLocked(r, 0); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1345 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1346 | |
| 1347 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | addd00e | 2015-04-04 17:10:50 -0700 | [diff] [blame] | 1348 | // This activity needs to be visible, but isn't even running... |
| 1349 | // get it started and resume if no other stack in this stack is resumed. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1350 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1351 | "Start and freeze screen for " + r); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1352 | if (r != starting) { |
| 1353 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1354 | } |
| 1355 | if (!r.visible || r.mLaunchTaskBehind) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1356 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1357 | "Starting and making visible: " + r); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1358 | setVisible(r, true); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1359 | } |
| 1360 | if (r != starting) { |
Wale Ogunwale | addd00e | 2015-04-04 17:10:50 -0700 | [diff] [blame] | 1361 | mStackSupervisor.startSpecificActivityLocked( |
| 1362 | r, noStackActivityResumed, false); |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1363 | if (activityNdx >= activities.size()) { |
| 1364 | // Record may be removed if its process needs to restart. |
| 1365 | activityNdx = activities.size() - 1; |
| 1366 | } else { |
| 1367 | noStackActivityResumed = false; |
| 1368 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | } else if (r.visible) { |
| 1372 | // If this activity is already visible, then there is nothing |
| 1373 | // else to do here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1374 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1375 | "Skipping: already visible at " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1376 | r.stopFreezingScreenLocked(false); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1377 | try { |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1378 | if (r.returningOptions != null) { |
| 1379 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, |
| 1380 | r.returningOptions); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1381 | } |
| 1382 | } catch(RemoteException e) { |
| 1383 | } |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1384 | if (r.state == ActivityState.RESUMED) { |
| 1385 | noStackActivityResumed = false; |
| 1386 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1387 | } else { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1388 | // This activity is not currently visible, but is running. |
| 1389 | // Tell it to become visible. |
| 1390 | r.visible = true; |
| 1391 | if (r.state != ActivityState.RESUMED && r != starting) { |
| 1392 | // If this activity is paused, tell it |
| 1393 | // to now show its window. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1394 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1395 | "Making visible and scheduling visibility: " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1396 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1397 | if (mTranslucentActivityWaiting != null) { |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1398 | r.updateOptionsLocked(r.returningOptions); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1399 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
| 1400 | } |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1401 | setVisible(r, true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1402 | r.sleeping = false; |
| 1403 | r.app.pendingUiClean = true; |
| 1404 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1405 | r.stopFreezingScreenLocked(false); |
| 1406 | } catch (Exception e) { |
| 1407 | // Just skip on any failure; we'll make it |
| 1408 | // visible when it next restarts. |
| 1409 | Slog.w(TAG, "Exception thrown making visibile: " |
| 1410 | + r.intent.getComponent(), e); |
| 1411 | } |
| 1412 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1413 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1414 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1415 | // Aggregate current change flags. |
| 1416 | configChanges |= r.configChangeFlags; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1417 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1418 | if (r.fullscreen) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1419 | // At this point, nothing else needs to be shown in this task. |
| 1420 | behindFullscreenActivity = true; |
| 1421 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
| 1422 | + " behindFullscreen=" + behindFullscreen |
| 1423 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1424 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1425 | behindFullscreenActivity = true; |
| 1426 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 1427 | + " behindFullscreen=" + behindFullscreen |
| 1428 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1429 | } |
| 1430 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1431 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1432 | "Make invisible? " + r + " finishing=" + r.finishing |
| 1433 | + " state=" + r.state + " behindFullscreen=" + behindFullscreen |
| 1434 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1435 | // Now for any activities that aren't visible to the user, make |
| 1436 | // sure they no longer are keeping the screen frozen. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1437 | if (r.visible) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1438 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1439 | try { |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1440 | setVisible(r, false); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1441 | switch (r.state) { |
| 1442 | case STOPPING: |
| 1443 | case STOPPED: |
| 1444 | if (r.app != null && r.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1445 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1446 | "Scheduling invisibility: " + r); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1447 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1448 | } |
| 1449 | break; |
| 1450 | |
| 1451 | case INITIALIZING: |
| 1452 | case RESUMED: |
| 1453 | case PAUSING: |
| 1454 | case PAUSED: |
Craig Mautner | 8817610 | 2013-07-22 12:57:51 -0700 | [diff] [blame] | 1455 | // This case created for transitioning activities from |
| 1456 | // translucent to opaque {@link Activity#convertToOpaque}. |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1457 | if (getVisibleBehindActivity() == r) { |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1458 | releaseBackgroundResources(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1459 | } else { |
| 1460 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1461 | mStackSupervisor.mStoppingActivities.add(r); |
| 1462 | } |
| 1463 | mStackSupervisor.scheduleIdleLocked(); |
Craig Mautner | e5273b4 | 2013-09-09 12:57:47 -0700 | [diff] [blame] | 1464 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1465 | break; |
| 1466 | |
| 1467 | default: |
| 1468 | break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1469 | } |
| 1470 | } catch (Exception e) { |
| 1471 | // Just skip on any failure; we'll make it |
| 1472 | // visible when it next restarts. |
| 1473 | Slog.w(TAG, "Exception thrown making hidden: " |
| 1474 | + r.intent.getComponent(), e); |
| 1475 | } |
| 1476 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1477 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1478 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1479 | } |
| 1480 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1481 | // Factoring if the previous task is fullscreen there by affecting the visibility of |
| 1482 | // task behind it. |
| 1483 | behindFullscreen |= task.mFullscreen; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1484 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1485 | |
| 1486 | if (mTranslucentActivityWaiting != null && |
| 1487 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1488 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1489 | notifyActivityDrawnLocked(null); |
| 1490 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1491 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1492 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1493 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1494 | mTranslucentActivityWaiting = r; |
| 1495 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1496 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1497 | } |
| 1498 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1499 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1500 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1501 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1502 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1503 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1504 | final ActivityRecord r = activities.get(activityNdx); |
| 1505 | if ( r.appTimeTracker != except) { |
| 1506 | r.appTimeTracker = null; |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1512 | /** |
| 1513 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1514 | * redrawn notify the top activity by calling |
| 1515 | * {@link Activity#onTranslucentConversionComplete}. |
| 1516 | * |
| 1517 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1518 | * occurred and the activity will be notified immediately. |
| 1519 | */ |
| 1520 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1521 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1522 | if ((r == null) |
| 1523 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1524 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1525 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1526 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1527 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1528 | mTranslucentActivityWaiting = null; |
| 1529 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1530 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1531 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1532 | if (waitingActivity != null) { |
| 1533 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 1534 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 1535 | try { |
| 1536 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1537 | waitingActivity.appToken, r != null); |
| 1538 | } catch (RemoteException e) { |
| 1539 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1540 | } |
| 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1545 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 1546 | * starting window displayed then remove that starting window. It is possible that the activity |
| 1547 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 1548 | void cancelInitializingActivities() { |
| 1549 | final ActivityRecord topActivity = topRunningActivityLocked(null); |
| 1550 | boolean aboveTop = true; |
| 1551 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1552 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1553 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1554 | final ActivityRecord r = activities.get(activityNdx); |
| 1555 | if (aboveTop) { |
| 1556 | if (r == topActivity) { |
| 1557 | aboveTop = false; |
| 1558 | } |
| 1559 | continue; |
| 1560 | } |
| 1561 | |
| 1562 | if (r.state == ActivityState.INITIALIZING && r.mStartingWindowShown) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1563 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 1564 | "Found orphaned starting window " + r); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1565 | r.mStartingWindowShown = false; |
| 1566 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 1567 | } |
| 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1572 | /** |
| 1573 | * Ensure that the top activity in the stack is resumed. |
| 1574 | * |
| 1575 | * @param prev The previously resumed activity, for when in the process |
| 1576 | * of pausing; can be null to call from elsewhere. |
| 1577 | * |
| 1578 | * @return Returns true if something is being resumed, or false if |
| 1579 | * nothing happened. |
| 1580 | */ |
| 1581 | final boolean resumeTopActivityLocked(ActivityRecord prev) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1582 | return resumeTopActivityLocked(prev, null); |
| 1583 | } |
| 1584 | |
| 1585 | final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1586 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1587 | // Don't even start recursing. |
| 1588 | return false; |
| 1589 | } |
| 1590 | |
| 1591 | boolean result = false; |
| 1592 | try { |
| 1593 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1594 | mStackSupervisor.inResumeTopActivity = true; |
| 1595 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 1596 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 1597 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1598 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1599 | result = resumeTopActivityInnerLocked(prev, options); |
| 1600 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1601 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1602 | } |
| 1603 | return result; |
| 1604 | } |
| 1605 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1606 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, Bundle options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1607 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1608 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1609 | if (!mService.mBooting && !mService.mBooted) { |
| 1610 | // Not ready yet! |
| 1611 | return false; |
| 1612 | } |
| 1613 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1614 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1615 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 1616 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1617 | // Do not resume this stack if its parent is not resumed. |
| 1618 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 1619 | return false; |
| 1620 | } |
| 1621 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1622 | cancelInitializingActivities(); |
| 1623 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1624 | // Find the first activity that is not finishing. |
Craig Mautner | 94ab466 | 2015-01-20 10:49:22 -0800 | [diff] [blame] | 1625 | final ActivityRecord next = topRunningActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1626 | |
| 1627 | // Remember how we'll process this pause/resume situation, and ensure |
| 1628 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1629 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1630 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1631 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1632 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1633 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1634 | // There are no more activities! |
| 1635 | final String reason = "noMoreActivities"; |
| 1636 | if (!mFullscreen) { |
| 1637 | // Try to move focus to the next visible stack with a running activity if this |
| 1638 | // stack is not covering the entire screen. |
| 1639 | final ActivityStack stack = getNextVisibleStackLocked(); |
| 1640 | if (adjustFocusToNextVisibleStackLocked(stack, reason)) { |
| 1641 | return mStackSupervisor.resumeTopActivitiesLocked(stack, prev, null); |
| 1642 | } |
| 1643 | } |
| 1644 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1645 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1646 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1647 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1648 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1649 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1650 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1651 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1652 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1653 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1657 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1658 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1659 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1660 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1661 | // Make sure we have executed any pending transitions, since there |
| 1662 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1663 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1664 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1665 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1666 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1667 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1668 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1669 | return false; |
| 1670 | } |
| 1671 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1672 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 1673 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1674 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1675 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1676 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1677 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1678 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1679 | // 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] | 1680 | // 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] | 1681 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1682 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 1683 | } else if (!isOnHomeDisplay()) { |
| 1684 | return false; |
| 1685 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1686 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1687 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1688 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1689 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1690 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 1691 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1692 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1695 | // If we are sleeping, and there is no resumed activity, and the top |
| 1696 | // activity is paused, well that is the state we want. |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1697 | if (mService.isSleepingOrShuttingDown() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1698 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1699 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1700 | // Make sure we have executed any pending transitions, since there |
| 1701 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1702 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1703 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1704 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1705 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1706 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1707 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1708 | return false; |
| 1709 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1710 | |
| 1711 | // Make sure that the user who owns this activity is started. If not, |
| 1712 | // we will just leave it as is because someone should be bringing |
| 1713 | // another user's activities to the top of the stack. |
| 1714 | if (mService.mStartedUsers.get(next.userId) == null) { |
| 1715 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 1716 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1717 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1718 | return false; |
| 1719 | } |
| 1720 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1721 | // The activity may be waiting for stop, but that is no longer |
| 1722 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1723 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1724 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1725 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1726 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1727 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1728 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1729 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1730 | // If we are currently pausing an activity, then don't do anything |
| 1731 | // until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 1732 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1733 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1734 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1735 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1736 | return false; |
| 1737 | } |
| 1738 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1739 | // Okay we are now going to start a switch, to 'next'. We may first |
| 1740 | // have to pause the current activity, but this is an important point |
| 1741 | // 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] | 1742 | // XXX "App Redirected" dialog is getting too many false positives |
| 1743 | // at this point, so turn off for now. |
| 1744 | if (false) { |
| 1745 | if (mLastStartedActivity != null && !mLastStartedActivity.finishing) { |
| 1746 | long now = SystemClock.uptimeMillis(); |
| 1747 | final boolean inTime = mLastStartedActivity.startTime != 0 |
| 1748 | && (mLastStartedActivity.startTime + START_WARN_TIME) >= now; |
| 1749 | final int lastUid = mLastStartedActivity.info.applicationInfo.uid; |
| 1750 | final int nextUid = next.info.applicationInfo.uid; |
| 1751 | if (inTime && lastUid != nextUid |
| 1752 | && lastUid != next.launchedFromUid |
| 1753 | && mService.checkPermission( |
| 1754 | android.Manifest.permission.STOP_APP_SWITCHES, |
| 1755 | -1, next.launchedFromUid) |
| 1756 | != PackageManager.PERMISSION_GRANTED) { |
| 1757 | mService.showLaunchWarningLocked(mLastStartedActivity, next); |
| 1758 | } else { |
| 1759 | next.startTime = now; |
| 1760 | mLastStartedActivity = next; |
| 1761 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1762 | } else { |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1763 | next.startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1764 | mLastStartedActivity = next; |
| 1765 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1766 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1767 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1768 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 1769 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1770 | // We need to start pausing the current activity so the top one |
| 1771 | // can be resumed... |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1772 | boolean dontWaitForPause = (next.info.flags&ActivityInfo.FLAG_RESUME_WHILE_PAUSING) != 0; |
| 1773 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1774 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1775 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1776 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | e042bf2 | 2014-11-11 11:28:43 -0800 | [diff] [blame] | 1777 | pausing |= startPausingLocked(userLeaving, false, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1778 | } |
| 1779 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1780 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1781 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1782 | // At this point we want to put the upcoming activity's process |
| 1783 | // at the top of the LRU list, since we know we will be needing it |
| 1784 | // very soon and it would be a waste to let it get killed if it |
| 1785 | // happens to be sitting towards the end. |
| 1786 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1787 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1788 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1789 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1790 | return true; |
| 1791 | } |
| 1792 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1793 | // If the most recent activity was noHistory but was only stopped rather |
| 1794 | // than stopped+finished because the device went to sleep, we need to make |
| 1795 | // sure to finish it as we're making a new activity topmost. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1796 | if (mService.isSleeping() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1797 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1798 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1799 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1800 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 1801 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1802 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1805 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1806 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 1807 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1808 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1809 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1810 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1811 | } else { |
| 1812 | // The next activity is already visible, so hide the previous |
| 1813 | // activity's windows right now so we can show the new one ASAP. |
| 1814 | // We only do this if the previous is finishing, which should mean |
| 1815 | // it is on top of the one being resumed so hiding it quickly |
| 1816 | // is good. Otherwise, we want to do the normal route of allowing |
| 1817 | // the resumed activity to be shown so we can decide if the |
| 1818 | // previous should actually be hidden depending on whether the |
| 1819 | // new one is found to be full-screen or not. |
| 1820 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1821 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1822 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1823 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1824 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1825 | + ", nowVisible=" + next.nowVisible); |
| 1826 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1827 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1828 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1829 | + ", waitingVisible=" |
| 1830 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 1831 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1836 | // Launching this app's activity, make sure the app is no longer |
| 1837 | // considered stopped. |
| 1838 | try { |
| 1839 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1840 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1841 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 1842 | } catch (IllegalArgumentException e) { |
| 1843 | Slog.w(TAG, "Failed trying to unstop package " |
| 1844 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1845 | } |
| 1846 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1847 | // We are starting up the next activity, so tell the window manager |
| 1848 | // that the previous one will be hidden soon. This way it can know |
| 1849 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1850 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1851 | if (prev != null) { |
| 1852 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1853 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1854 | "Prepare close transition: prev=" + prev); |
| 1855 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1856 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1857 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1858 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1859 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1860 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 1861 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1862 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1863 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1864 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1865 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1866 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 1867 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1868 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1869 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1870 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1871 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1872 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1873 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1874 | : next.mLaunchTaskBehind |
| 1875 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 1876 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | if (false) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1880 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1881 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1882 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1883 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1884 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1885 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1886 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1887 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1888 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1889 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1890 | } |
| 1891 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1892 | |
| 1893 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1894 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1895 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 1896 | if (opts != null) { |
| 1897 | resumeAnimOptions = opts.toBundle(); |
| 1898 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1899 | next.applyOptionsLocked(); |
| 1900 | } else { |
| 1901 | next.clearOptionsLocked(); |
| 1902 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1903 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1904 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1905 | if (next.app != null && next.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1906 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1907 | |
| 1908 | // This activity is now becoming visible. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1909 | mWindowManager.setAppVisibility(next.appToken, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1910 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1911 | // schedule launch ticks to collect information about slow apps. |
| 1912 | next.startLaunchTickingLocked(); |
| 1913 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1914 | ActivityRecord lastResumedActivity = |
| 1915 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1916 | ActivityState lastState = next.state; |
| 1917 | |
| 1918 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1919 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1920 | 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] | 1921 | next.state = ActivityState.RESUMED; |
| 1922 | mResumedActivity = next; |
| 1923 | next.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 1924 | mRecentTasks.addLocked(next.task); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1925 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1926 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1927 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1928 | |
| 1929 | // Have the window manager re-evaluate the orientation of |
| 1930 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1931 | boolean notUpdated = true; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1932 | if (mStackSupervisor.isFrontStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1933 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1934 | mService.mConfiguration, |
| 1935 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 1936 | if (config != null) { |
| 1937 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1938 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 1939 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1940 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1941 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1942 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1943 | // The configuration update wasn't able to keep the existing |
| 1944 | // instance of the activity, and instead started a new one. |
| 1945 | // We should be all done, but let's just make sure our activity |
| 1946 | // is still at the top and schedule another run if something |
| 1947 | // weird happened. |
| 1948 | ActivityRecord nextNext = topRunningActivityLocked(null); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1949 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1950 | "Activity config changed during resume: " + next |
| 1951 | + ", new next: " + nextNext); |
| 1952 | if (nextNext != next) { |
| 1953 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1954 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1955 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1956 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1957 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1958 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1959 | return true; |
| 1960 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1961 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1962 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1963 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1964 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1965 | try { |
| 1966 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 1967 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1968 | if (a != null) { |
| 1969 | final int N = a.size(); |
| 1970 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1971 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 1972 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1973 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1978 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 1981 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 1982 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1983 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1984 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1985 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 1986 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 1987 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1988 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1989 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1990 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1991 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1992 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1993 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1994 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1995 | } catch (Exception e) { |
| 1996 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1997 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1998 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1999 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2000 | if (lastStack != null) { |
| 2001 | lastStack.mResumedActivity = lastResumedActivity; |
| 2002 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2003 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2004 | if (!next.hasBeenLaunched) { |
| 2005 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2006 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2007 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2008 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2009 | next.appToken, next.packageName, next.theme, |
| 2010 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2011 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 2012 | next.windowFlags, null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2013 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2014 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2015 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2016 | return true; |
| 2017 | } |
| 2018 | |
| 2019 | // From this point on, if something goes wrong there is no way |
| 2020 | // to recover the activity. |
| 2021 | try { |
| 2022 | next.visible = true; |
| 2023 | completeResumeLocked(next); |
| 2024 | } catch (Exception e) { |
| 2025 | // If any exception gets thrown, toss away this |
| 2026 | // activity and try the next one. |
| 2027 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2028 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2029 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2030 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2031 | return true; |
| 2032 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2033 | next.stopped = false; |
| 2034 | |
| 2035 | } else { |
| 2036 | // Whoops, need to restart this activity! |
| 2037 | if (!next.hasBeenLaunched) { |
| 2038 | next.hasBeenLaunched = true; |
| 2039 | } else { |
| 2040 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2041 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2042 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2043 | mService.compatibilityInfoForPackageLocked( |
| 2044 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2045 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2046 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2047 | null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2048 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2049 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2050 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2051 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2052 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2055 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2056 | return true; |
| 2057 | } |
| 2058 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2059 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2060 | final int index = mTaskHistory.indexOf(targetTask); |
| 2061 | if (index >= 0) { |
| 2062 | final int numTasks = mTaskHistory.size(); |
| 2063 | for (int i = index + 1; i < numTasks; ++i) { |
| 2064 | TaskRecord task = mTaskHistory.get(i); |
| 2065 | if (task.userId == targetTask.userId) { |
| 2066 | return task; |
| 2067 | } |
| 2068 | } |
| 2069 | } |
| 2070 | return null; |
| 2071 | } |
| 2072 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2073 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2074 | if (position >= mTaskHistory.size()) { |
| 2075 | insertTaskAtTop(task, null); |
| 2076 | return; |
| 2077 | } |
| 2078 | // Calculate maximum possible position for this task. |
| 2079 | int maxPosition = mTaskHistory.size(); |
| 2080 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) |
| 2081 | && task.topRunningActivityLocked(null) == null) { |
| 2082 | // Put non-current user tasks below current user tasks. |
| 2083 | while (maxPosition > 0) { |
| 2084 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2085 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
| 2086 | || tmpTask.topRunningActivityLocked(null) == null) { |
| 2087 | break; |
| 2088 | } |
| 2089 | maxPosition--; |
| 2090 | } |
| 2091 | } |
| 2092 | position = Math.min(position, maxPosition); |
| 2093 | mTaskHistory.remove(task); |
| 2094 | mTaskHistory.add(position, task); |
| 2095 | updateTaskMovement(task, true); |
| 2096 | } |
| 2097 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2098 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2099 | // If the moving task is over home stack, transfer its return type to next task |
| 2100 | if (task.isOverHomeStack()) { |
| 2101 | final TaskRecord nextTask = getNextTask(task); |
| 2102 | if (nextTask != null) { |
| 2103 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
| 2104 | } |
| 2105 | } |
| 2106 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2107 | // 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] | 2108 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2109 | if (isOnHomeDisplay()) { |
| 2110 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2111 | final boolean fromHome = lastStack.isHomeStack(); |
| 2112 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Craig Mautner | 3b1dac8 | 2014-07-15 09:51:33 -0700 | [diff] [blame] | 2113 | task.setTaskToReturnTo(fromHome |
| 2114 | ? lastStack.topTask() == null |
| 2115 | ? HOME_ACTIVITY_TYPE |
| 2116 | : lastStack.topTask().taskType |
| 2117 | : APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2118 | } |
| 2119 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2120 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2121 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2122 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2123 | mTaskHistory.remove(task); |
| 2124 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2125 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2126 | final boolean notShownWhenLocked = |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2127 | (newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2128 | || (newActivity == null && task.topRunningActivityLocked(null) == null); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2129 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2130 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2131 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2132 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2133 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2134 | || tmpTask.topRunningActivityLocked(null) == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2135 | break; |
| 2136 | } |
| 2137 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2138 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2139 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2140 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2141 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2142 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2143 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2144 | final void startActivityLocked(ActivityRecord r, boolean newTask, |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2145 | boolean doResume, boolean keepCurTransition, Bundle options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2146 | TaskRecord rTask = r.task; |
| 2147 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2148 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2149 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2150 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2151 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2152 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2153 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2154 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2155 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2156 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2157 | if (!newTask) { |
| 2158 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2159 | boolean startIt = true; |
| 2160 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2161 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2162 | if (task.getTopActivity() == null) { |
| 2163 | // All activities in task are finishing. |
| 2164 | continue; |
| 2165 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2166 | if (task == r.task) { |
| 2167 | // Here it is! Now, if this is not yet visible to the |
| 2168 | // user, then just add it without starting; it will |
| 2169 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2170 | if (!startIt) { |
| 2171 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2172 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2173 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2174 | r.putInHistory(); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2175 | addAppToken(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2176 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2177 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2178 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2179 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2180 | return; |
| 2181 | } |
| 2182 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2183 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2184 | startIt = false; |
| 2185 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | // Place a new activity at top of stack, so it is next to interact |
| 2190 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2191 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2192 | // If we are not placing the new activity frontmost, we do not want |
| 2193 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2194 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2195 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2196 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2197 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2198 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2199 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2200 | |
| 2201 | task = r.task; |
| 2202 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2203 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2204 | 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] | 2205 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2206 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2207 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2208 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2209 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2210 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2211 | // We want to show the starting preview window if we are |
| 2212 | // switching to a new task, or the next activity's process is |
| 2213 | // not currently running. |
| 2214 | boolean showStartingIcon = newTask; |
| 2215 | ProcessRecord proc = r.app; |
| 2216 | if (proc == null) { |
| 2217 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2218 | } |
| 2219 | if (proc == null || proc.thread == null) { |
| 2220 | showStartingIcon = true; |
| 2221 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2222 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2223 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2224 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2225 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2226 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2227 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2228 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2229 | ? r.mLaunchTaskBehind |
| 2230 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2231 | : AppTransition.TRANSIT_TASK_OPEN |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2232 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2233 | mNoAnimActivities.remove(r); |
| 2234 | } |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2235 | addAppToken(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2236 | boolean doShow = true; |
| 2237 | if (newTask) { |
| 2238 | // Even though this activity is starting fresh, we still need |
| 2239 | // to reset it to make sure we apply affinities to move any |
| 2240 | // existing activities from other tasks in to it. |
| 2241 | // If the caller has requested that the target task be |
| 2242 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2243 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2244 | resetTaskIfNeededLocked(r, r); |
| 2245 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2246 | } |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2247 | } else if (options != null && new ActivityOptions(options).getAnimationType() |
| 2248 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2249 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2250 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2251 | if (r.mLaunchTaskBehind) { |
| 2252 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2253 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2254 | mWindowManager.setAppVisibility(r.appToken, true); |
| 2255 | ensureActivitiesVisibleLocked(null, 0); |
| 2256 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2257 | // Figure out if we are transitioning from another activity that is |
| 2258 | // "has the same starting icon" as the next one. This allows the |
| 2259 | // window manager to keep the previous window it had previously |
| 2260 | // created, if it still had one. |
| 2261 | ActivityRecord prev = mResumedActivity; |
| 2262 | if (prev != null) { |
| 2263 | // We don't want to reuse the previous starting preview if: |
| 2264 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2265 | if (prev.task != r.task) { |
| 2266 | prev = null; |
| 2267 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2268 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2269 | else if (prev.nowVisible) { |
| 2270 | prev = null; |
| 2271 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2272 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2273 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2274 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2275 | mService.compatibilityInfoForPackageLocked( |
| 2276 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2277 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2278 | prev != null ? prev.appToken : null, showStartingIcon); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2279 | r.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2280 | } |
| 2281 | } else { |
| 2282 | // If this is the first activity, don't do any fancy animations, |
| 2283 | // because there is nothing for it to animate on top of. |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2284 | addAppToken(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2285 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2286 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2287 | } |
| 2288 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2289 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | if (doResume) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2293 | mStackSupervisor.resumeTopActivitiesLocked(this, r, options); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame^] | 2294 | } else { |
| 2295 | addRecentActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2296 | } |
| 2297 | } |
| 2298 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2299 | final void validateAppTokensLocked() { |
| 2300 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2301 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2302 | final int numTasks = mTaskHistory.size(); |
| 2303 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2304 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2305 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2306 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2307 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2308 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2309 | TaskGroup group = new TaskGroup(); |
| 2310 | group.taskId = task.taskId; |
| 2311 | mValidateAppTokens.add(group); |
| 2312 | final int numActivities = activities.size(); |
| 2313 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2314 | final ActivityRecord r = activities.get(activityNdx); |
| 2315 | group.tokens.add(r.appToken); |
| 2316 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2317 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2318 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2319 | } |
| 2320 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2321 | /** |
| 2322 | * Perform a reset of the given task, if needed as part of launching it. |
| 2323 | * Returns the new HistoryRecord at the top of the task. |
| 2324 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2325 | /** |
| 2326 | * Helper method for #resetTaskIfNeededLocked. |
| 2327 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2328 | * for another task, or leave it as-is. |
| 2329 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2330 | * @param forceReset |
| 2331 | * @return An ActivityOptions that needs to be processed. |
| 2332 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2333 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2334 | ActivityOptions topOptions = null; |
| 2335 | |
| 2336 | int replyChainEnd = -1; |
| 2337 | boolean canMoveOptions = true; |
| 2338 | |
| 2339 | // We only do this for activities that are not the root of the task (since if we finish |
| 2340 | // the root, we may no longer have the task!). |
| 2341 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2342 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2343 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2344 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2345 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2346 | if (target.frontOfTask) |
| 2347 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2348 | |
| 2349 | final int flags = target.info.flags; |
| 2350 | final boolean finishOnTaskLaunch = |
| 2351 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2352 | final boolean allowTaskReparenting = |
| 2353 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2354 | final boolean clearWhenTaskReset = |
| 2355 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2356 | |
| 2357 | if (!finishOnTaskLaunch |
| 2358 | && !clearWhenTaskReset |
| 2359 | && target.resultTo != null) { |
| 2360 | // If this activity is sending a reply to a previous |
| 2361 | // activity, we can't do anything with it now until |
| 2362 | // we reach the start of the reply chain. |
| 2363 | // XXX note that we are assuming the result is always |
| 2364 | // to the previous activity, which is almost always |
| 2365 | // the case but we really shouldn't count on. |
| 2366 | if (replyChainEnd < 0) { |
| 2367 | replyChainEnd = i; |
| 2368 | } |
| 2369 | } else if (!finishOnTaskLaunch |
| 2370 | && !clearWhenTaskReset |
| 2371 | && allowTaskReparenting |
| 2372 | && target.taskAffinity != null |
| 2373 | && !target.taskAffinity.equals(task.affinity)) { |
| 2374 | // If this activity has an affinity for another |
| 2375 | // task, then we need to move it out of here. We will |
| 2376 | // move it as far out of the way as possible, to the |
| 2377 | // bottom of the activity stack. This also keeps it |
| 2378 | // correctly ordered with any activities we previously |
| 2379 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2380 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2381 | final ActivityRecord bottom = |
| 2382 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2383 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2384 | if (bottom != null && target.taskAffinity != null |
| 2385 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2386 | // If the activity currently at the bottom has the |
| 2387 | // same task affinity as the one we are moving, |
| 2388 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2389 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2390 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2391 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2392 | } else { |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2393 | targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2394 | null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2395 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2396 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2397 | + " out to new task " + target.task); |
| 2398 | } |
| 2399 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2400 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2401 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2402 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2403 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2404 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2405 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2406 | if (p.finishing) { |
| 2407 | continue; |
| 2408 | } |
| 2409 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2410 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2411 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2412 | topOptions = p.takeOptionsLocked(); |
| 2413 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2414 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2415 | } |
| 2416 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2417 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2418 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2419 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2420 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2421 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2422 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2423 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2424 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2425 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2426 | } |
| 2427 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2428 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2429 | if (VALIDATE_TOKENS) { |
| 2430 | validateAppTokensLocked(); |
| 2431 | } |
| 2432 | |
| 2433 | replyChainEnd = -1; |
| 2434 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2435 | // If the activity should just be removed -- either |
| 2436 | // because it asks for it, or the task should be |
| 2437 | // cleared -- then finish it and anything that is |
| 2438 | // part of its reply chain. |
| 2439 | int end; |
| 2440 | if (clearWhenTaskReset) { |
| 2441 | // In this case, we want to finish this activity |
| 2442 | // and everything above it, so be sneaky and pretend |
| 2443 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2444 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2445 | } else if (replyChainEnd < 0) { |
| 2446 | end = i; |
| 2447 | } else { |
| 2448 | end = replyChainEnd; |
| 2449 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2450 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2451 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2452 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2453 | if (p.finishing) { |
| 2454 | continue; |
| 2455 | } |
| 2456 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2457 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2458 | topOptions = p.takeOptionsLocked(); |
| 2459 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2460 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2461 | } |
| 2462 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2463 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2464 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2465 | if (finishActivityLocked( |
| 2466 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2467 | end--; |
| 2468 | srcPos--; |
| 2469 | } |
| 2470 | } |
| 2471 | replyChainEnd = -1; |
| 2472 | } else { |
| 2473 | // If we were in the middle of a chain, well the |
| 2474 | // activity that started it all doesn't want anything |
| 2475 | // special, so leave it all as-is. |
| 2476 | replyChainEnd = -1; |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | return topOptions; |
| 2481 | } |
| 2482 | |
| 2483 | /** |
| 2484 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2485 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2486 | * @param affinityTask The task we are looking for an affinity to. |
| 2487 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2488 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2489 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2490 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2491 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2492 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2493 | int replyChainEnd = -1; |
| 2494 | final int taskId = task.taskId; |
| 2495 | final String taskAffinity = task.affinity; |
| 2496 | |
| 2497 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2498 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2499 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 2500 | |
| 2501 | // Do not operate on or below the effective root Activity. |
| 2502 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2503 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2504 | if (target.frontOfTask) |
| 2505 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2506 | |
| 2507 | final int flags = target.info.flags; |
| 2508 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2509 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2510 | |
| 2511 | if (target.resultTo != null) { |
| 2512 | // If this activity is sending a reply to a previous |
| 2513 | // activity, we can't do anything with it now until |
| 2514 | // we reach the start of the reply chain. |
| 2515 | // XXX note that we are assuming the result is always |
| 2516 | // to the previous activity, which is almost always |
| 2517 | // the case but we really shouldn't count on. |
| 2518 | if (replyChainEnd < 0) { |
| 2519 | replyChainEnd = i; |
| 2520 | } |
| 2521 | } else if (topTaskIsHigher |
| 2522 | && allowTaskReparenting |
| 2523 | && taskAffinity != null |
| 2524 | && taskAffinity.equals(target.taskAffinity)) { |
| 2525 | // This activity has an affinity for our task. Either remove it if we are |
| 2526 | // clearing or move it over to our task. Note that |
| 2527 | // we currently punt on the case where we are resetting a |
| 2528 | // task that is not at the top but who has activities above |
| 2529 | // with an affinity to it... this is really not a normal |
| 2530 | // case, and we will need to later pull that task to the front |
| 2531 | // and usually at that point we will do the reset and pick |
| 2532 | // up those remaining activities. (This only happens if |
| 2533 | // someone starts an activity in a new task from an activity |
| 2534 | // in a task that is not currently on top.) |
| 2535 | if (forceReset || finishOnTaskLaunch) { |
| 2536 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2537 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2538 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2539 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2540 | final ActivityRecord p = activities.get(srcPos); |
| 2541 | if (p.finishing) { |
| 2542 | continue; |
| 2543 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2544 | finishActivityLocked( |
| 2545 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2546 | } |
| 2547 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2548 | if (taskInsertionPoint < 0) { |
| 2549 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2550 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2551 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2552 | |
| 2553 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2554 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2555 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 2556 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2557 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2558 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2559 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2560 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2561 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2562 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2563 | "Removing and adding activity " + p + " to stack at " + task |
| 2564 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2565 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 2566 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2567 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2568 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2569 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2570 | if (VALIDATE_TOKENS) { |
| 2571 | validateAppTokensLocked(); |
| 2572 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2573 | |
| 2574 | // Now we've moved it in to place... but what if this is |
| 2575 | // a singleTop activity and we have put it on top of another |
| 2576 | // instance of the same activity? Then we drop the instance |
| 2577 | // below so it remains singleTop. |
| 2578 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2579 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2580 | int targetNdx = taskActivities.indexOf(target); |
| 2581 | if (targetNdx > 0) { |
| 2582 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2583 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2584 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2585 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2586 | } |
| 2587 | } |
| 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | replyChainEnd = -1; |
| 2592 | } |
| 2593 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2594 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2595 | } |
| 2596 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2597 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2598 | ActivityRecord newActivity) { |
| 2599 | boolean forceReset = |
| 2600 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2601 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2602 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2603 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2604 | forceReset = true; |
| 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | final TaskRecord task = taskTop.task; |
| 2609 | |
| 2610 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2611 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2612 | boolean taskFound = false; |
| 2613 | |
| 2614 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2615 | ActivityOptions topOptions = null; |
| 2616 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2617 | // Preserve the location for reparenting in the new task. |
| 2618 | int reparentInsertionPoint = -1; |
| 2619 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2620 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2621 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2622 | |
| 2623 | if (targetTask == task) { |
| 2624 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2625 | taskFound = true; |
| 2626 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2627 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2628 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2632 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 2633 | if (taskNdx >= 0) { |
| 2634 | do { |
| 2635 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2636 | } while (taskTop == null && taskNdx >= 0); |
| 2637 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2638 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2639 | if (topOptions != null) { |
| 2640 | // If we got some ActivityOptions from an activity on top that |
| 2641 | // was removed from the task, propagate them to the new real top. |
| 2642 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2643 | taskTop.updateOptionsLocked(topOptions); |
| 2644 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2645 | topOptions.abort(); |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | return taskTop; |
| 2650 | } |
| 2651 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2652 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2653 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2654 | |
| 2655 | if (callingUid > 0) { |
| 2656 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2657 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2661 | + " : who=" + resultWho + " req=" + requestCode |
| 2662 | + " res=" + resultCode + " data=" + data); |
| 2663 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2664 | try { |
| 2665 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2666 | list.add(new ResultInfo(resultWho, requestCode, |
| 2667 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2668 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2669 | return; |
| 2670 | } catch (Exception e) { |
| 2671 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2676 | } |
| 2677 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2678 | private void adjustFocusedActivityLocked(ActivityRecord r, String reason) { |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2679 | if (mStackSupervisor.isFrontStack(this) && mService.mFocusedActivity == r) { |
| 2680 | ActivityRecord next = topRunningActivityLocked(null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2681 | final String myReason = reason + " adjustFocus"; |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2682 | if (next != r) { |
Wale Ogunwale | 61803ee | 2015-08-07 19:59:47 -0700 | [diff] [blame] | 2683 | if (next != null && mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 2684 | // For freeform stack we always keep the focus within the stack as long as |
| 2685 | // there is a running activity in the stack that we can adjust focus to. |
| 2686 | mService.setFocusedActivityLocked(next, myReason); |
| 2687 | return; |
| 2688 | } else { |
| 2689 | final TaskRecord task = r.task; |
| 2690 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
| 2691 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 2692 | // stack to prevent the home screen from moving to the top and obscuring |
| 2693 | // other visible stacks. |
| 2694 | if (!mFullscreen |
| 2695 | && adjustFocusToNextVisibleStackLocked(null, myReason)) { |
| 2696 | return; |
| 2697 | } |
| 2698 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 2699 | // other visible stack. |
| 2700 | if (mStackSupervisor.moveHomeStackTaskToTop( |
| 2701 | task.getTaskToReturnTo(), myReason)) { |
| 2702 | // Activity focus was already adjusted. Nothing else to do... |
| 2703 | return; |
| 2704 | } |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 2705 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2706 | } |
| 2707 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2708 | |
| 2709 | final ActivityRecord top = mStackSupervisor.topRunningActivityLocked(); |
Winson Chung | 648c83b | 2014-04-28 15:11:56 -0700 | [diff] [blame] | 2710 | if (top != null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2711 | mService.setFocusedActivityLocked(top, myReason); |
Winson Chung | 648c83b | 2014-04-28 15:11:56 -0700 | [diff] [blame] | 2712 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2716 | private boolean adjustFocusToNextVisibleStackLocked(ActivityStack inStack, String reason) { |
| 2717 | final ActivityStack stack = (inStack != null) ? inStack : getNextVisibleStackLocked(); |
| 2718 | final String myReason = reason + " adjustFocusToNextVisibleStack"; |
| 2719 | if (stack == null) { |
| 2720 | return false; |
| 2721 | } |
| 2722 | final ActivityRecord top = stack.topRunningActivityLocked(null); |
| 2723 | if (top == null) { |
| 2724 | return false; |
| 2725 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2726 | mService.setFocusedActivityLocked(top, myReason); |
| 2727 | return true; |
| 2728 | } |
| 2729 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2730 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2731 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2732 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2733 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2734 | if (!r.finishing) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2735 | if (!mService.isSleeping()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2736 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 2737 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 2738 | "stop-no-history", false)) { |
| 2739 | // Activity was finished, no need to continue trying to schedule stop. |
| 2740 | adjustFocusedActivityLocked(r, "stopActivityFinished"); |
| 2741 | r.resumeKeyDispatchingLocked(); |
| 2742 | return; |
| 2743 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2744 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2745 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2746 | + " on stop because we're just sleeping"); |
| 2747 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2748 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2752 | adjustFocusedActivityLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2753 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2754 | try { |
| 2755 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2756 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 2757 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2758 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2759 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2760 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2761 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2762 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2763 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2764 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 2765 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2766 | r.setSleeping(true); |
| 2767 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2768 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2769 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2770 | } catch (Exception e) { |
| 2771 | // Maybe just ignore exceptions here... if the process |
| 2772 | // has crashed, our death notification will clean things |
| 2773 | // up. |
| 2774 | Slog.w(TAG, "Exception thrown during pause", e); |
| 2775 | // Just in case, assume it to be stopped. |
| 2776 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2777 | 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] | 2778 | r.state = ActivityState.STOPPED; |
| 2779 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2780 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | } |
| 2784 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 2785 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2786 | /** |
| 2787 | * @return Returns true if the activity is being finished, false if for |
| 2788 | * some reason it is being left as-is. |
| 2789 | */ |
| 2790 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2791 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2792 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2793 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 2794 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2795 | + ", result=" + resultCode + ", data=" + resultData |
| 2796 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2797 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2798 | return false; |
| 2799 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2800 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2801 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2802 | return true; |
| 2803 | } |
| 2804 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2805 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2806 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2807 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2808 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2809 | ActivityRecord r = activities.get(activityNdx); |
| 2810 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 2811 | if ((r.resultWho == null && resultWho == null) || |
| 2812 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 2813 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 2814 | false); |
| 2815 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2816 | } |
| 2817 | } |
| 2818 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2819 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2822 | final void finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2823 | ActivityRecord r = topRunningActivityLocked(null); |
| 2824 | if (r != null && r.app == app) { |
| 2825 | // If the top running activity is from this crashing |
| 2826 | // process, then terminate it to avoid getting in a loop. |
| 2827 | Slog.w(TAG, " Force finishing activity " |
| 2828 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2829 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 2830 | int activityNdx = r.task.mActivities.indexOf(r); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2831 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2832 | // Also terminate any activities below it that aren't yet |
| 2833 | // stopped, to avoid a situation where one will get |
| 2834 | // re-start our crashing activity once it gets resumed again. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2835 | --activityNdx; |
| 2836 | if (activityNdx < 0) { |
| 2837 | do { |
| 2838 | --taskNdx; |
| 2839 | if (taskNdx < 0) { |
| 2840 | break; |
| 2841 | } |
| 2842 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 2843 | } while (activityNdx < 0); |
| 2844 | } |
| 2845 | if (activityNdx >= 0) { |
| 2846 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2847 | if (r.state == ActivityState.RESUMED |
| 2848 | || r.state == ActivityState.PAUSING |
| 2849 | || r.state == ActivityState.PAUSED) { |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2850 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2851 | Slog.w(TAG, " Force finishing activity " |
| 2852 | + r.intent.getComponent().flattenToShortString()); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2853 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2854 | } |
| 2855 | } |
| 2856 | } |
| 2857 | } |
| 2858 | } |
| 2859 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2860 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 2861 | IBinder sessionBinder = session.asBinder(); |
| 2862 | boolean didOne = false; |
| 2863 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2864 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 2865 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 2866 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2867 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 2868 | if (!r.finishing) { |
| 2869 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 2870 | false); |
| 2871 | didOne = true; |
| 2872 | } |
| 2873 | } |
| 2874 | } |
| 2875 | } |
| 2876 | if (didOne) { |
| 2877 | mService.updateOomAdjLocked(); |
| 2878 | } |
| 2879 | } |
| 2880 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2881 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2882 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 2883 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 2884 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 2885 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2886 | break; |
| 2887 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2888 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2889 | } |
| 2890 | return true; |
| 2891 | } |
| 2892 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2893 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 2894 | // send the result |
| 2895 | ActivityRecord resultTo = r.resultTo; |
| 2896 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2897 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2898 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 2899 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2900 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 2901 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 2902 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 2903 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2904 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2905 | if (r.info.applicationInfo.uid > 0) { |
| 2906 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 2907 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2908 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2909 | } |
| 2910 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 2911 | resultData); |
| 2912 | r.resultTo = null; |
| 2913 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2914 | 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] | 2915 | |
| 2916 | // Make sure this HistoryRecord is not holding on to other resources, |
| 2917 | // because clients have remote IPC references to this object so we |
| 2918 | // can't assume that will go away and want to avoid circular IPC refs. |
| 2919 | r.results = null; |
| 2920 | r.pendingResults = null; |
| 2921 | r.newIntents = null; |
| 2922 | r.icicle = null; |
| 2923 | } |
| 2924 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2925 | /** |
| 2926 | * @return Returns true if this activity has been removed from the history |
| 2927 | * list, or false if it is still in the list and will be removed later. |
| 2928 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2929 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 2930 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2931 | if (r.finishing) { |
| 2932 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 2933 | return false; |
| 2934 | } |
| 2935 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2936 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2937 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2938 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2939 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2940 | task.taskId, r.shortComponentName, reason); |
| 2941 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2942 | final int index = activities.indexOf(r); |
| 2943 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2944 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 2945 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2946 | // If the caller asked that this activity (and all above it) |
| 2947 | // be cleared when the task is reset, don't lose that information, |
| 2948 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2949 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2950 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2955 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2956 | adjustFocusedActivityLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2957 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2958 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2959 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2960 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2961 | boolean endTask = index <= 0; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2962 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2963 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2964 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2965 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 2966 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2967 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2968 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2969 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2970 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2971 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2972 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 2973 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 2974 | "finish() => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 2975 | startPausingLocked(false, false, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2978 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 2979 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2980 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2981 | } else if (r.state != ActivityState.PAUSING) { |
| 2982 | // If the activity is PAUSING, we will complete the finish once |
| 2983 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2984 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2985 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2986 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2987 | 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] | 2988 | } |
| 2989 | |
| 2990 | return false; |
| 2991 | } |
| 2992 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2993 | static final int FINISH_IMMEDIATELY = 0; |
| 2994 | static final int FINISH_AFTER_PAUSE = 1; |
| 2995 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2996 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2997 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2998 | // First things first: if this activity is currently visible, |
| 2999 | // and the resumed activity is not yet visible, then hold off on |
| 3000 | // finishing until the resumed one becomes visible. |
| 3001 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3002 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 3003 | mStackSupervisor.mStoppingActivities.add(r); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3004 | if (mStackSupervisor.mStoppingActivities.size() > 3 |
| 3005 | || r.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3006 | // If we already have a few activities waiting to stop, |
| 3007 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3008 | // them out. Or if r is the last of activity of the last task the stack |
| 3009 | // will be empty and must be cleared immediately. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3010 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3011 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3012 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3013 | } |
| 3014 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3015 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3016 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3017 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3018 | if (oomAdj) { |
| 3019 | mService.updateOomAdjLocked(); |
| 3020 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3021 | return r; |
| 3022 | } |
| 3023 | |
| 3024 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3025 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3026 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3027 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3028 | if (mResumedActivity == r) { |
| 3029 | mResumedActivity = null; |
| 3030 | } |
| 3031 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3032 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3033 | r.state = ActivityState.FINISHING; |
| 3034 | |
| 3035 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3036 | || (mode == FINISH_AFTER_PAUSE && prevState == ActivityState.PAUSED) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3037 | || prevState == ActivityState.STOPPED |
| 3038 | || prevState == ActivityState.INITIALIZING) { |
| 3039 | // If this activity is already stopped, we can just finish |
| 3040 | // it right now. |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3041 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3042 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3043 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3044 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3045 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3046 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3047 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3048 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3049 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3050 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3051 | |
| 3052 | // Need to go through the full pause cycle to get this |
| 3053 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3054 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3055 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3056 | r.resumeKeyDispatchingLocked(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3057 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3058 | return r; |
| 3059 | } |
| 3060 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3061 | void finishAllActivitiesLocked(boolean immediately) { |
| 3062 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3063 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3064 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3065 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3066 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3067 | noActivitiesInStack = false; |
| 3068 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3069 | continue; |
| 3070 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3071 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3072 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3073 | } |
| 3074 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3075 | if (noActivitiesInStack) { |
| 3076 | mActivityContainer.onTaskListEmptyLocked(); |
| 3077 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3078 | } |
| 3079 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3080 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3081 | // Basic case: for simple app-centric recents, we need to recreate |
| 3082 | // the task if the affinity has changed. |
| 3083 | if (srec == null || srec.task.affinity == null || |
| 3084 | !srec.task.affinity.equals(destAffinity)) { |
| 3085 | return true; |
| 3086 | } |
| 3087 | // Document-centric case: an app may be split in to multiple documents; |
| 3088 | // they need to re-create their task if this current activity is the root |
| 3089 | // of a document, unless simply finishing it will return them to the the |
| 3090 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3091 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3092 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3093 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3094 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3095 | // Finishing won't return to an application, so we need to recreate. |
| 3096 | return true; |
| 3097 | } |
| 3098 | // We now need to get the task below it to determine what to do. |
| 3099 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3100 | if (taskIdx <= 0) { |
| 3101 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3102 | return false; |
| 3103 | } |
| 3104 | if (taskIdx == 0) { |
| 3105 | // At the bottom of the stack, nothing to go back to. |
| 3106 | return true; |
| 3107 | } |
| 3108 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3109 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3110 | // These are different apps, so need to recreate. |
| 3111 | return true; |
| 3112 | } |
| 3113 | } |
| 3114 | return false; |
| 3115 | } |
| 3116 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3117 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3118 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3119 | final TaskRecord task = srec.task; |
| 3120 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3121 | final int start = activities.indexOf(srec); |
| 3122 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3123 | return false; |
| 3124 | } |
| 3125 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3126 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3127 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3128 | final ComponentName dest = destIntent.getComponent(); |
| 3129 | if (start > 0 && dest != null) { |
| 3130 | for (int i = finishTo; i >= 0; i--) { |
| 3131 | ActivityRecord r = activities.get(i); |
| 3132 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3133 | r.info.name.equals(dest.getClassName())) { |
| 3134 | finishTo = i; |
| 3135 | parent = r; |
| 3136 | foundParentInTask = true; |
| 3137 | break; |
| 3138 | } |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | IActivityController controller = mService.mController; |
| 3143 | if (controller != null) { |
| 3144 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3145 | if (next != null) { |
| 3146 | // ask watcher if this is allowed |
| 3147 | boolean resumeOK = true; |
| 3148 | try { |
| 3149 | resumeOK = controller.activityResuming(next.packageName); |
| 3150 | } catch (RemoteException e) { |
| 3151 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3152 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | if (!resumeOK) { |
| 3156 | return false; |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | final long origId = Binder.clearCallingIdentity(); |
| 3161 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3162 | ActivityRecord r = activities.get(i); |
| 3163 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3164 | // Only return the supplied result for the first activity finished |
| 3165 | resultCode = Activity.RESULT_CANCELED; |
| 3166 | resultData = null; |
| 3167 | } |
| 3168 | |
| 3169 | if (parent != null && foundParentInTask) { |
| 3170 | final int parentLaunchMode = parent.info.launchMode; |
| 3171 | final int destIntentFlags = destIntent.getFlags(); |
| 3172 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3173 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3174 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3175 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3176 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3177 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3178 | } else { |
| 3179 | try { |
| 3180 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3181 | destIntent.getComponent(), 0, srec.userId); |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 3182 | int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3183 | null, aInfo, null, null, parent.appToken, null, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3184 | 0, -1, parent.launchedFromUid, parent.launchedFromPackage, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 3185 | -1, parent.launchedFromUid, 0, null, false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3186 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3187 | } catch (RemoteException e) { |
| 3188 | foundParentInTask = false; |
| 3189 | } |
| 3190 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3191 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3192 | } |
| 3193 | } |
| 3194 | Binder.restoreCallingIdentity(origId); |
| 3195 | return foundParentInTask; |
| 3196 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3197 | /** |
| 3198 | * Perform the common clean-up of an activity record. This is called both |
| 3199 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3200 | * representation) and cleaning things up as a result of its hosting |
| 3201 | * processing going away, in which case there is no remaining client-side |
| 3202 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3203 | * |
| 3204 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3205 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3206 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3207 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3208 | if (mResumedActivity == r) { |
| 3209 | mResumedActivity = null; |
| 3210 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3211 | if (mPausingActivity == r) { |
| 3212 | mPausingActivity = null; |
| 3213 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3214 | mService.clearFocusedActivity(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3215 | |
| 3216 | r.configDestroy = false; |
| 3217 | r.frozenBeforeDestroy = false; |
| 3218 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3219 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3220 | 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] | 3221 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3222 | 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] | 3223 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3226 | // Make sure this record is no longer in the pending finishes list. |
| 3227 | // This could happen, for example, if we are trimming activities |
| 3228 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3229 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3230 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3231 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3232 | // Remove any pending results. |
| 3233 | if (r.finishing && r.pendingResults != null) { |
| 3234 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3235 | PendingIntentRecord rec = apr.get(); |
| 3236 | if (rec != null) { |
| 3237 | mService.cancelIntentSenderLocked(rec, false); |
| 3238 | } |
| 3239 | } |
| 3240 | r.pendingResults = null; |
| 3241 | } |
| 3242 | |
| 3243 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3244 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3247 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3248 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3249 | if (getVisibleBehindActivity() == r) { |
| 3250 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3251 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3255 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3256 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3257 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3258 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3259 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3262 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3263 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3264 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3265 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3266 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3267 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3268 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3269 | r.takeFromHistory(); |
| 3270 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3271 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3272 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3273 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3274 | 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] | 3275 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3276 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3277 | if (VALIDATE_TOKENS) { |
| 3278 | validateAppTokensLocked(); |
| 3279 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3280 | final TaskRecord task = r.task; |
| 3281 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3282 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3283 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3284 | if (mStackSupervisor.isFrontStack(this) && task == topTask() && |
| 3285 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3286 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3287 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3288 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3289 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3290 | cleanUpActivityServicesLocked(r); |
| 3291 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3292 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3293 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3294 | /** |
| 3295 | * Perform clean-up of service connections in an activity record. |
| 3296 | */ |
| 3297 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3298 | // Throw away any services that have been bound by this activity. |
| 3299 | if (r.connections != null) { |
| 3300 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3301 | while (it.hasNext()) { |
| 3302 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3303 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3304 | } |
| 3305 | r.connections = null; |
| 3306 | } |
| 3307 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3308 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3309 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3310 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3311 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3312 | mHandler.sendMessage(msg); |
| 3313 | } |
| 3314 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3315 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3316 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3317 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3318 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3319 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3320 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3321 | final ActivityRecord r = activities.get(activityNdx); |
| 3322 | if (r.finishing) { |
| 3323 | continue; |
| 3324 | } |
| 3325 | if (r.fullscreen) { |
| 3326 | lastIsOpaque = true; |
| 3327 | } |
| 3328 | if (owner != null && r.app != owner) { |
| 3329 | continue; |
| 3330 | } |
| 3331 | if (!lastIsOpaque) { |
| 3332 | continue; |
| 3333 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3334 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3335 | 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] | 3336 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3337 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3338 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3339 | activityRemoved = true; |
| 3340 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3341 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3342 | } |
| 3343 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3344 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3345 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3346 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3347 | } |
| 3348 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3349 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3350 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3351 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3352 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3353 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3354 | return destroyActivityLocked(r, true, reason); |
| 3355 | } |
| 3356 | return false; |
| 3357 | } |
| 3358 | |
| 3359 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3360 | String reason) { |
| 3361 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3362 | 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] | 3363 | int maxTasks = tasks.size() / 4; |
| 3364 | if (maxTasks < 1) { |
| 3365 | maxTasks = 1; |
| 3366 | } |
| 3367 | int numReleased = 0; |
| 3368 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3369 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3370 | if (!tasks.contains(task)) { |
| 3371 | continue; |
| 3372 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3373 | 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] | 3374 | int curNum = 0; |
| 3375 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3376 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3377 | final ActivityRecord activity = activities.get(actNdx); |
| 3378 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3379 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3380 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3381 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3382 | destroyActivityLocked(activity, true, reason); |
| 3383 | if (activities.get(actNdx) != activity) { |
| 3384 | // Was removed from list, back up so we don't miss the next one. |
| 3385 | actNdx--; |
| 3386 | } |
| 3387 | curNum++; |
| 3388 | } |
| 3389 | } |
| 3390 | if (curNum > 0) { |
| 3391 | numReleased += curNum; |
| 3392 | maxTasks--; |
| 3393 | if (mTaskHistory.get(taskNdx) != task) { |
| 3394 | // The entire task got removed, back up so we don't miss the next one. |
| 3395 | taskNdx--; |
| 3396 | } |
| 3397 | } |
| 3398 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3399 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3400 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3401 | return numReleased; |
| 3402 | } |
| 3403 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3404 | /** |
| 3405 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3406 | * called both when actually finishing an activity, or when performing |
| 3407 | * a configuration switch where we destroy the current client-side object |
| 3408 | * but then create a new client-side object for this same HistoryRecord. |
| 3409 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3410 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3411 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3412 | "Removing activity from " + reason + ": token=" + r |
| 3413 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3414 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3415 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3416 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3417 | |
| 3418 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3419 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3420 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3421 | |
| 3422 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3423 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3424 | if (hadApp) { |
| 3425 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3426 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3427 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 3428 | mService.mHeavyWeightProcess = null; |
| 3429 | mService.mHandler.sendEmptyMessage( |
| 3430 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 3431 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3432 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 3433 | // Update any services we are bound to that might care about whether |
| 3434 | // their client may have activities. |
| 3435 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 3436 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 3437 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3438 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3443 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3444 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3445 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3446 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3447 | r.configChangeFlags); |
| 3448 | } catch (Exception e) { |
| 3449 | // We can just ignore exceptions here... if the process |
| 3450 | // has crashed, our death notification will clean things |
| 3451 | // up. |
| 3452 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 3453 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3454 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3455 | removedFromHistory = true; |
| 3456 | skipDestroy = true; |
| 3457 | } |
| 3458 | } |
| 3459 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3460 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3461 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3462 | // If the activity is finishing, we need to wait on removing it |
| 3463 | // from the list to give it a chance to do its cleanup. During |
| 3464 | // that time it may make calls back with its token so we need to |
| 3465 | // be able to find it on the list and so we don't want to remove |
| 3466 | // it from the list yet. Otherwise, we can just immediately put |
| 3467 | // it in the destroyed state since we are not removing it from the |
| 3468 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3469 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3470 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3471 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3472 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3473 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3474 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 3475 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3476 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3477 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3478 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3479 | 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] | 3480 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3481 | } |
| 3482 | } else { |
| 3483 | // remove this record from the history. |
| 3484 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3485 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3486 | removedFromHistory = true; |
| 3487 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3488 | 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] | 3489 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3490 | 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] | 3491 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3496 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3497 | if (!mLRUActivities.remove(r) && hadApp) { |
| 3498 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 3499 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3500 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3501 | return removedFromHistory; |
| 3502 | } |
| 3503 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3504 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3505 | final long origId = Binder.clearCallingIdentity(); |
| 3506 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3507 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3508 | if (r != null) { |
| 3509 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3510 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3511 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3512 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3513 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3514 | if (r.state == ActivityState.DESTROYING) { |
| 3515 | cleanUpActivityLocked(r, true, false); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3516 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3517 | } |
| 3518 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3519 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3520 | } finally { |
| 3521 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3522 | } |
| 3523 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3524 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 3525 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3526 | if (hasVisibleBehindActivity() && |
| 3527 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3528 | if (r == topRunningActivityLocked(null)) { |
| 3529 | // Don't release the top activity if it has requested to run behind the next |
| 3530 | // activity. |
| 3531 | return; |
| 3532 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3533 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3534 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3535 | " thread=" + r.app.thread); |
| 3536 | if (r != null && r.app != null && r.app.thread != null) { |
| 3537 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3538 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3539 | } catch (RemoteException e) { |
| 3540 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3541 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3542 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3543 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3544 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3549 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3550 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 3551 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3552 | if (r != null) { |
| 3553 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3554 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3555 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3556 | } |
| 3557 | mStackSupervisor.resumeTopActivitiesLocked(); |
| 3558 | } |
| 3559 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3560 | boolean hasVisibleBehindActivity() { |
| 3561 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3564 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3565 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3566 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3567 | } |
| 3568 | } |
| 3569 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3570 | ActivityRecord getVisibleBehindActivity() { |
| 3571 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3574 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 3575 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3576 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3577 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3578 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3579 | while (i > 0) { |
| 3580 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3581 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3582 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3583 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3584 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3585 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3586 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | } |
| 3590 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3591 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 3592 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3593 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 3594 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3595 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 3596 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3597 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3598 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3599 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 3600 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3601 | |
| 3602 | boolean hasVisibleActivities = false; |
| 3603 | |
| 3604 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3605 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3606 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3607 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3608 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3609 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3610 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3611 | final ActivityRecord r = activities.get(activityNdx); |
| 3612 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3613 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3614 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3615 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 3616 | if (r.visible) { |
| 3617 | hasVisibleActivities = true; |
| 3618 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3619 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3620 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 3621 | // Don't currently have state for the activity, or |
| 3622 | // it is finishing -- always remove it. |
| 3623 | remove = true; |
| 3624 | } else if (r.launchCount > 2 && |
| 3625 | r.lastLaunchTime > (SystemClock.uptimeMillis()-60000)) { |
| 3626 | // We have launched this activity too many times since it was |
| 3627 | // able to run, so give up and remove it. |
| 3628 | remove = true; |
| 3629 | } else { |
| 3630 | // The process may be gone, but the activity lives on! |
| 3631 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3632 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3633 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3634 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 3635 | "Removing activity " + r + " from stack at " + i |
| 3636 | + ": haveState=" + r.haveState |
| 3637 | + " stateNotNeeded=" + r.stateNotNeeded |
| 3638 | + " finishing=" + r.finishing |
| 3639 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3640 | if (!r.finishing) { |
| 3641 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 3642 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3643 | r.userId, System.identityHashCode(r), |
| 3644 | r.task.taskId, r.shortComponentName, |
| 3645 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3646 | if (r.state == ActivityState.RESUMED) { |
| 3647 | mService.updateUsageStats(r, false); |
| 3648 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3649 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3650 | } else { |
| 3651 | // We have the current state for this activity, so |
| 3652 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3653 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 3654 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 3655 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3656 | r.app = null; |
| 3657 | r.nowVisible = false; |
| 3658 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3659 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3660 | "App died, clearing saved state of " + r); |
| 3661 | r.icicle = null; |
| 3662 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3663 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3664 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3665 | if (remove) { |
| 3666 | removeActivityFromHistoryLocked(r, "appDied"); |
| 3667 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3668 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | |
| 3672 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3673 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3674 | |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3675 | final void updateTransitLocked(int transit, Bundle options) { |
| 3676 | if (options != null) { |
| 3677 | ActivityRecord r = topRunningActivityLocked(null); |
| 3678 | if (r != null && r.state != ActivityState.RESUMED) { |
| 3679 | r.updateOptionsLocked(options); |
| 3680 | } else { |
| 3681 | ActivityOptions.abort(options); |
| 3682 | } |
| 3683 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3684 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3685 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 3686 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3687 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 3688 | if (task.isPersistable) { |
| 3689 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 3690 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 3691 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 3692 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 3693 | if (!toFront) { |
| 3694 | task.mLastTimeMoved *= -1; |
| 3695 | } |
| 3696 | } |
| 3697 | } |
| 3698 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3699 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3700 | final int top = mTaskHistory.size() - 1; |
| 3701 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 3702 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3703 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3704 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 3705 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3706 | mTaskHistory.remove(taskNdx); |
| 3707 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3708 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3709 | return; |
| 3710 | } |
| 3711 | } |
| 3712 | } |
| 3713 | |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3714 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, Bundle options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3715 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3716 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3717 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3718 | final int numTasks = mTaskHistory.size(); |
| 3719 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3720 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3721 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3722 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3723 | ActivityOptions.abort(options); |
| 3724 | } else { |
| 3725 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 3726 | } |
| 3727 | return; |
| 3728 | } |
| 3729 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3730 | if (timeTracker != null) { |
| 3731 | // The caller wants a time tracker associated with this task. |
| 3732 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 3733 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 3734 | } |
| 3735 | } |
| 3736 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3737 | // Shift all activities with this task up to the top |
| 3738 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 3739 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3740 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame^] | 3741 | // Don't refocus if invisible to current user |
| 3742 | ActivityRecord top = tr.getTopActivity(); |
| 3743 | if (!okToShowLocked(top)) { |
| 3744 | addRecentActivityLocked(top); |
| 3745 | ActivityOptions.abort(options); |
| 3746 | return; |
| 3747 | } |
| 3748 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3749 | // Set focus to the top running activity of this stack. |
| 3750 | ActivityRecord r = topRunningActivityLocked(null); |
| 3751 | mService.setFocusedActivityLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3752 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3753 | 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] | 3754 | if (noAnimation) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3755 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3756 | if (r != null) { |
| 3757 | mNoAnimActivities.add(r); |
| 3758 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3759 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3760 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3761 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3762 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 3763 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3764 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3765 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3766 | |
| 3767 | if (VALIDATE_TOKENS) { |
| 3768 | validateAppTokensLocked(); |
| 3769 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3773 | * Worker method for rearranging history stack. Implements the function of moving all |
| 3774 | * 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] | 3775 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3776 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3777 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 3778 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3779 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3780 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3781 | * @return Returns true if the move completed, false if not. |
| 3782 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3783 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3784 | final TaskRecord tr = taskForIdLocked(taskId); |
| 3785 | if (tr == null) { |
| 3786 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 3787 | return false; |
| 3788 | } |
| 3789 | |
| 3790 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3791 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3792 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3793 | // If we have a watcher, preflight the move before committing to it. First check |
| 3794 | // for *other* available tasks, but if none are available, then try again allowing the |
| 3795 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3796 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3797 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3798 | if (next == null) { |
| 3799 | next = topRunningActivityLocked(null, 0); |
| 3800 | } |
| 3801 | if (next != null) { |
| 3802 | // ask watcher if this is allowed |
| 3803 | boolean moveOK = true; |
| 3804 | try { |
| 3805 | moveOK = mService.mController.activityResuming(next.packageName); |
| 3806 | } catch (RemoteException e) { |
| 3807 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3808 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3809 | } |
| 3810 | if (!moveOK) { |
| 3811 | return false; |
| 3812 | } |
| 3813 | } |
| 3814 | } |
| 3815 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3816 | 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] | 3817 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 3818 | boolean prevIsHome = false; |
| 3819 | if (tr.isOverHomeStack()) { |
| 3820 | final TaskRecord nextTask = getNextTask(tr); |
| 3821 | if (nextTask != null) { |
| 3822 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 3823 | } else { |
| 3824 | prevIsHome = true; |
| 3825 | } |
| 3826 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3827 | mTaskHistory.remove(tr); |
| 3828 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3829 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3830 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3831 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 3832 | // 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] | 3833 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3834 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 3835 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3836 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3837 | break; |
| 3838 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3839 | if (taskNdx == 1) { |
| 3840 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3841 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3842 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3845 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3846 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3847 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3848 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3849 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3850 | } |
| 3851 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3852 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 3853 | if (prevIsHome || task == tr && tr.isOverHomeStack() |
| 3854 | || numTasks <= 1 && isOnHomeDisplay()) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 3855 | if (!mService.mBooting && !mService.mBooted) { |
| 3856 | // Not ready yet! |
| 3857 | return false; |
| 3858 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3859 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 3860 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3861 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3864 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3865 | return true; |
| 3866 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 3867 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3868 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3869 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3870 | final Uri data = r.intent.getData(); |
| 3871 | final String strData = data != null ? data.toSafeString() : null; |
| 3872 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3873 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3874 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3875 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3876 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | /** |
| 3880 | * Make sure the given activity matches the current configuration. Returns |
| 3881 | * false if the activity had to be destroyed. Returns true if the |
| 3882 | * configuration is the same, or the activity will remain running as-is |
| 3883 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 3884 | * correct configuration and all other bookkeeping is handled. |
| 3885 | */ |
| 3886 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, |
| 3887 | int globalChanges) { |
| 3888 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3889 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3890 | "Skipping config check (will change): " + r); |
| 3891 | return true; |
| 3892 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3893 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3894 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3895 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3896 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3897 | // Short circuit: if the two configurations are the exact same |
| 3898 | // object (the common case), then there is nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3899 | final Configuration newConfig = mService.mConfiguration; |
| 3900 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3901 | if (r.configuration == newConfig |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3902 | && r.taskConfigOverride == taskConfig |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3903 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3904 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3905 | "Configuration unchanged in " + r); |
| 3906 | return true; |
| 3907 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3908 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3909 | // We don't worry about activities that are finishing. |
| 3910 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3911 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3912 | "Configuration doesn't matter in finishing " + r); |
| 3913 | r.stopFreezingScreenLocked(false); |
| 3914 | return true; |
| 3915 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3916 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3917 | // Okay we now are going to make this activity have the new config. |
| 3918 | // 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] | 3919 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3920 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3921 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3922 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3923 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3924 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3925 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3926 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3927 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3928 | "Configuration no differences in " + r); |
| 3929 | return true; |
| 3930 | } |
| 3931 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3932 | // If the activity isn't currently running, just leave the new |
| 3933 | // configuration and it will pick that up next time it starts. |
| 3934 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3935 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3936 | "Configuration doesn't matter not running " + r); |
| 3937 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3938 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3939 | return true; |
| 3940 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3941 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3942 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3943 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3944 | "Checking to restart " + r.info.name + ": changed=0x" |
| 3945 | + Integer.toHexString(changes) + ", handles=0x" |
| 3946 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig); |
| 3947 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 3948 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3949 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 3950 | r.configChangeFlags |= changes; |
| 3951 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3952 | r.forceNewConfig = false; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3953 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3954 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3955 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3956 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3957 | } else if (r.state == ActivityState.PAUSING) { |
| 3958 | // A little annoying: we are waiting for this activity to |
| 3959 | // finish pausing. Let's not do anything now, but just |
| 3960 | // flag that it needs to be restarted when done pausing. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3961 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3962 | "Config is skipping already pausing " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3963 | r.configDestroy = true; |
| 3964 | return true; |
| 3965 | } else if (r.state == ActivityState.RESUMED) { |
| 3966 | // Try to optimize this case: the configuration is changing |
| 3967 | // and we need to restart the top, resumed activity. |
| 3968 | // Instead of doing the normal handshaking, just say |
| 3969 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3970 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3971 | "Config is relaunching resumed " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3972 | relaunchActivityLocked(r, r.configChangeFlags, true); |
| 3973 | r.configChangeFlags = 0; |
| 3974 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3975 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3976 | "Config is relaunching non-resumed " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3977 | relaunchActivityLocked(r, r.configChangeFlags, false); |
| 3978 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3979 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3980 | |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3981 | // All done... tell the caller we weren't able to keep this |
| 3982 | // activity around. |
| 3983 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3984 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3985 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3986 | // 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] | 3987 | // 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] | 3988 | // changes is always sent to all processes when they happen so it can just use whatever |
| 3989 | // system level configuration it last got. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3990 | if (r.app != null && r.app.thread != null) { |
| 3991 | try { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3992 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Sending new config to " + r); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3993 | r.app.thread.scheduleActivityConfigurationChanged( |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3994 | r.appToken, new Configuration(taskConfig)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3995 | } catch (RemoteException e) { |
| 3996 | // If process died, whatever. |
| 3997 | } |
| 3998 | } |
| 3999 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4000 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4001 | return true; |
| 4002 | } |
| 4003 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4004 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4005 | Configuration oldTaskOverride) { |
| 4006 | // Determine what has changed. May be nothing, if this is a config |
| 4007 | // that has come back from the app after going idle. In that case |
| 4008 | // we just want to leave the official config object now in the |
| 4009 | // activity and do nothing else. |
| 4010 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4011 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4012 | // the app. |
| 4013 | if ((taskChanges & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) { |
| 4014 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4015 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4016 | || record.crossesVerticalSizeThreshold( |
| 4017 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4018 | if (!crosses) { |
| 4019 | taskChanges &= ~ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4020 | } |
| 4021 | } |
| 4022 | if ((taskChanges & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
| 4023 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4024 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4025 | final boolean crosses = record.crossesHorizontalSizeThreshold(oldSmallest, newSmallest) |
| 4026 | || record.crossesVerticalSizeThreshold(oldSmallest, newSmallest); |
| 4027 | if (!crosses) { |
| 4028 | taskChanges &= ~ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 4029 | } |
| 4030 | } |
| 4031 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4032 | } |
| 4033 | |
| 4034 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4035 | Configuration oldTaskOverride, int taskChanges) { |
| 4036 | if (taskChanges == 0) { |
| 4037 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4038 | // Check for changes we care about. |
| 4039 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
| 4040 | taskChanges |= ActivityInfo.CONFIG_ORIENTATION; |
| 4041 | } |
| 4042 | // We want to explicitly track situations where the size configuration goes from |
| 4043 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4044 | // because there is no threshold. |
| 4045 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4046 | final int newHeight = taskConfig.screenHeightDp; |
| 4047 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4048 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4049 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
| 4050 | taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4051 | } |
| 4052 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4053 | final int newWidth = taskConfig.screenWidthDp; |
| 4054 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4055 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4056 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
| 4057 | taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4058 | } |
| 4059 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4060 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4061 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4062 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4063 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
| 4064 | taskChanges |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 4065 | } |
| 4066 | } |
| 4067 | return taskChanges; |
| 4068 | } |
| 4069 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 4070 | private boolean relaunchActivityLocked(ActivityRecord r, int changes, boolean andResume) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4071 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4072 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4073 | if (andResume) { |
| 4074 | results = r.results; |
| 4075 | newIntents = r.newIntents; |
| 4076 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4077 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4078 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4079 | + " andResume=" + andResume); |
| 4080 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4081 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4082 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4083 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4084 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4085 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4086 | mStackSupervisor.removeChildActivityContainers(r); |
| 4087 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4088 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4089 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 4090 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4091 | r.forceNewConfig = false; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4092 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4093 | !andResume, new Configuration(mService.mConfiguration), |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4094 | new Configuration(r.task.mOverrideConfig)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4095 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4096 | // the caller will only pass in 'andResume' if this activity is |
| 4097 | // currently resumed, which implies we aren't sleeping. |
| 4098 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4099 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | if (andResume) { |
| 4103 | r.results = null; |
| 4104 | r.newIntents = null; |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4105 | r.state = ActivityState.RESUMED; |
| 4106 | } else { |
| 4107 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4108 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | return true; |
| 4112 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4113 | |
| 4114 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4115 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4116 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4117 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4118 | final ActivityRecord r = activities.get(activityNdx); |
| 4119 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4120 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4121 | } |
| 4122 | if (r.fullscreen && !r.finishing) { |
| 4123 | return false; |
| 4124 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4125 | } |
| 4126 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4127 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4128 | if (r == null) { |
| 4129 | return false; |
| 4130 | } |
| 4131 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4132 | + " would have returned true for r=" + r); |
| 4133 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4137 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4138 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4139 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4140 | final ActivityRecord r = activities.get(activityNdx); |
| 4141 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4142 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4143 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4144 | } |
| 4145 | } |
| 4146 | } |
| 4147 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4148 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4149 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4150 | boolean didSomething = false; |
| 4151 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4152 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4153 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4154 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4155 | int numActivities = activities.size(); |
| 4156 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4157 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4158 | final boolean sameComponent = |
| 4159 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4160 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4161 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4162 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4163 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4164 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4165 | if (!doit) { |
| 4166 | if (r.finishing) { |
| 4167 | // If this activity is just finishing, then it is not |
| 4168 | // interesting as far as something to stop. |
| 4169 | continue; |
| 4170 | } |
| 4171 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4172 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4173 | if (r.isHomeActivity()) { |
| 4174 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4175 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4176 | continue; |
| 4177 | } else { |
| 4178 | homeActivity = r.realActivity; |
| 4179 | } |
| 4180 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4181 | didSomething = true; |
| 4182 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4183 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4184 | if (r.app != null) { |
| 4185 | r.app.removed = true; |
| 4186 | } |
| 4187 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4188 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4189 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4190 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4191 | true)) { |
| 4192 | // r has been deleted from mActivities, accommodate. |
| 4193 | --numActivities; |
| 4194 | --activityNdx; |
| 4195 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4196 | } |
| 4197 | } |
| 4198 | } |
| 4199 | return didSomething; |
| 4200 | } |
| 4201 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4202 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4203 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4204 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4205 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4206 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4207 | if (task.getTopActivity() == null) { |
| 4208 | continue; |
| 4209 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4210 | ActivityRecord r = null; |
| 4211 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4212 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4213 | int numActivities = 0; |
| 4214 | int numRunning = 0; |
| 4215 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4216 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4217 | continue; |
| 4218 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4219 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4220 | tmp = activities.get(activityNdx); |
| 4221 | if (tmp.finishing) { |
| 4222 | continue; |
| 4223 | } |
| 4224 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4225 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4226 | // Initialize state for next task if needed. |
| 4227 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4228 | top = r; |
| 4229 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4230 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4231 | |
| 4232 | // Add 'r' into the current task. |
| 4233 | numActivities++; |
| 4234 | if (r.app != null && r.app.thread != null) { |
| 4235 | numRunning++; |
| 4236 | } |
| 4237 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4238 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4239 | TAG, r.intent.getComponent().flattenToShortString() |
| 4240 | + ": task=" + r.task); |
| 4241 | } |
| 4242 | |
| 4243 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4244 | ci.id = task.taskId; |
| 4245 | ci.baseActivity = r.intent.getComponent(); |
| 4246 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4247 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4248 | if (focusedStack && topTask) { |
| 4249 | // Give the latest time to ensure foreground task can be sorted |
| 4250 | // at the first, because lastActiveTime of creating task is 0. |
| 4251 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4252 | topTask = false; |
| 4253 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4254 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4255 | if (top.task != null) { |
| 4256 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4257 | } |
| 4258 | ci.numActivities = numActivities; |
| 4259 | ci.numRunning = numRunning; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4260 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4261 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4265 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4266 | 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] | 4267 | if (top >= 0) { |
| 4268 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4269 | int activityTop = activities.size() - 1; |
| 4270 | if (activityTop > 0) { |
| 4271 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4272 | "unhandled-back", true); |
| 4273 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4274 | } |
| 4275 | } |
| 4276 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4277 | /** |
| 4278 | * Reset local parameters because an app's activity died. |
| 4279 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4280 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4281 | */ |
| 4282 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4283 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4284 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4285 | "App died while pausing: " + mPausingActivity); |
| 4286 | mPausingActivity = null; |
| 4287 | } |
| 4288 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4289 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4290 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4291 | } |
| 4292 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4293 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4294 | } |
| 4295 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4296 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4297 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4298 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4299 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4300 | final ActivityRecord r = activities.get(activityNdx); |
| 4301 | if (r.app == app) { |
| 4302 | Slog.w(TAG, " Force finishing activity " |
| 4303 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 4304 | // Force the destroy to skip right to removal. |
| 4305 | r.app = null; |
| 4306 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4307 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4308 | } |
| 4309 | } |
| 4310 | } |
| 4311 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4312 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4313 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4314 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4315 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4316 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4317 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 4318 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4319 | dumpClient, dumpPackage, needSep, header, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 4320 | " Task id #" + task.taskId); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4321 | if (printed) { |
| 4322 | header = null; |
| 4323 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4324 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4325 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 4329 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 4330 | |
| 4331 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4332 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4333 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4334 | } |
| 4335 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4336 | final int top = mTaskHistory.size() - 1; |
| 4337 | if (top >= 0) { |
| 4338 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 4339 | int listTop = list.size() - 1; |
| 4340 | if (listTop >= 0) { |
| 4341 | activities.add(list.get(listTop)); |
| 4342 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4343 | } |
| 4344 | } else { |
| 4345 | ItemMatcher matcher = new ItemMatcher(); |
| 4346 | matcher.build(name); |
| 4347 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4348 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4349 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 4350 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 4351 | activities.add(r1); |
| 4352 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | return activities; |
| 4358 | } |
| 4359 | |
| 4360 | ActivityRecord restartPackage(String packageName) { |
| 4361 | ActivityRecord starting = topRunningActivityLocked(null); |
| 4362 | |
| 4363 | // All activities that came from the package must be |
| 4364 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4365 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4366 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4367 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4368 | final ActivityRecord a = activities.get(activityNdx); |
| 4369 | if (a.info.packageName.equals(packageName)) { |
| 4370 | a.forceNewConfig = true; |
| 4371 | if (starting != null && a == starting && a.visible) { |
| 4372 | a.startFreezingScreenLocked(starting.app, |
| 4373 | ActivityInfo.CONFIG_SCREEN_LAYOUT); |
| 4374 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4375 | } |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | return starting; |
| 4380 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4381 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4382 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4383 | removeTask(task, reason, !MOVING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4384 | } |
| 4385 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4386 | /** |
| 4387 | * Removes the input task from this stack. |
| 4388 | * @param task to remove. |
| 4389 | * @param reason for removal. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4390 | * @param moving task to another stack. In the case we are moving we don't want to perform |
| 4391 | * 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] | 4392 | */ |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4393 | void removeTask(TaskRecord task, String reason, boolean moving) { |
| 4394 | if (!moving) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4395 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4396 | mWindowManager.removeTask(task.taskId); |
| 4397 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4398 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4399 | final ActivityRecord r = mResumedActivity; |
| 4400 | if (r != null && r.task == task) { |
| 4401 | mResumedActivity = null; |
| 4402 | } |
| 4403 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4404 | final int taskNdx = mTaskHistory.indexOf(task); |
| 4405 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4406 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 4407 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 4408 | if (!nextTask.isOverHomeStack()) { |
| 4409 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 4410 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4411 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4412 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4413 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4414 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4415 | if (!moving && task.mActivities.isEmpty()) { |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4416 | final boolean isVoiceSession = task.voiceSession != null; |
| 4417 | if (isVoiceSession) { |
| 4418 | try { |
| 4419 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 4420 | } catch (RemoteException e) { |
| 4421 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4422 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4423 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 4424 | // Task creator asked to remove this when done, or this task was a voice |
| 4425 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 4426 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 4427 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4428 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4429 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4430 | |
| 4431 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4432 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 4433 | final boolean notHomeStack = !isHomeStack(); |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4434 | if (isOnHomeDisplay()) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4435 | String myReason = reason + " leftTaskHistoryEmpty"; |
| 4436 | if (mFullscreen || !adjustFocusToNextVisibleStackLocked(null, myReason)) { |
| 4437 | mStackSupervisor.moveHomeStack(notHomeStack, myReason); |
| 4438 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4439 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 4440 | if (mStacks != null) { |
| 4441 | mStacks.remove(this); |
| 4442 | mStacks.add(0, this); |
| 4443 | } |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 4444 | if (notHomeStack) { |
| 4445 | mActivityContainer.onTaskListEmptyLocked(); |
| 4446 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4447 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 4448 | |
| 4449 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4450 | } |
| 4451 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4452 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 4453 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 4454 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4455 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 4456 | voiceInteractor); |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4457 | addTask(task, toTop, false); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4458 | return task; |
| 4459 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4460 | |
| 4461 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4462 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4463 | } |
| 4464 | |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4465 | void addTask(final TaskRecord task, final boolean toTop, boolean moving) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4466 | task.stack = this; |
| 4467 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4468 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4469 | } else { |
| 4470 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4471 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4472 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4473 | if (!moving && task.voiceSession != null) { |
| 4474 | try { |
| 4475 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4476 | } catch (RemoteException e) { |
| 4477 | } |
| 4478 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4479 | } |
| 4480 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4481 | void positionTask(final TaskRecord task, int position, boolean moving) { |
| 4482 | task.stack = this; |
| 4483 | insertTaskAtPosition(task, position); |
| 4484 | if (!moving && task.voiceSession != null) { |
| 4485 | try { |
| 4486 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4487 | } catch (RemoteException e) { |
| 4488 | } |
| 4489 | } |
| 4490 | } |
| 4491 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4492 | void addAppToken(ActivityRecord r, TaskRecord task) { |
| 4493 | final Rect bounds = task.getLaunchBounds(); |
| 4494 | final Configuration config = |
| 4495 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 4496 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
| 4497 | (r.info.flags & ActivityInfo.FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, |
| 4498 | r.info.configChanges, task.voiceSession != null, r.mLaunchTaskBehind, |
| 4499 | bounds); |
| 4500 | if (config != null) { |
| 4501 | task.updateOverrideConfiguration(config, bounds); |
| 4502 | } |
| 4503 | r.taskConfigOverride = task.mOverrideConfig; |
| 4504 | } |
| 4505 | |
| 4506 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
| 4507 | final Rect bounds = task.getLaunchBounds(); |
| 4508 | final Configuration config = |
| 4509 | mWindowManager.setAppTask(r.appToken, task.taskId, task.getLaunchBounds()); |
| 4510 | if (config != null) { |
| 4511 | task.updateOverrideConfiguration(config, bounds); |
| 4512 | } |
| 4513 | r.taskConfigOverride = task.mOverrideConfig; |
| 4514 | } |
| 4515 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4516 | public int getStackId() { |
| 4517 | return mStackId; |
| 4518 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4519 | |
| 4520 | @Override |
| 4521 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 4522 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 4523 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4524 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4525 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4526 | void onLockTaskPackagesUpdatedLocked() { |
| 4527 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4528 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 4529 | } |
| 4530 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4531 | } |