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