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 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 19 | import static com.android.server.am.ActivityManagerService.TAG; |
| 20 | import static com.android.server.am.ActivityManagerService.localLOGV; |
| 21 | import static com.android.server.am.ActivityManagerService.DEBUG_CLEANUP; |
| 22 | import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION; |
| 23 | import static com.android.server.am.ActivityManagerService.DEBUG_PAUSE; |
| 24 | import static com.android.server.am.ActivityManagerService.DEBUG_RESULTS; |
| 25 | import static com.android.server.am.ActivityManagerService.DEBUG_STACK; |
| 26 | import static com.android.server.am.ActivityManagerService.DEBUG_SWITCH; |
| 27 | import static com.android.server.am.ActivityManagerService.DEBUG_TASKS; |
| 28 | import static com.android.server.am.ActivityManagerService.DEBUG_TRANSITION; |
| 29 | import static com.android.server.am.ActivityManagerService.DEBUG_USER_LEAVING; |
| 30 | import static com.android.server.am.ActivityManagerService.DEBUG_VISBILITY; |
| 31 | import static com.android.server.am.ActivityManagerService.VALIDATE_TOKENS; |
| 32 | |
| 33 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE; |
| 34 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_APP; |
| 35 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_SAVED_STATE; |
| 36 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_STATES; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 37 | import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID; |
| 38 | |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 39 | import android.os.Trace; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 40 | import com.android.internal.os.BatteryStatsImpl; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 41 | import com.android.internal.util.Objects; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 42 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 43 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 44 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 45 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 46 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 47 | |
| 48 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 49 | import android.app.ActivityManager; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 50 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 51 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 52 | import android.app.IActivityController; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 53 | import android.app.IThumbnailReceiver; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 54 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 55 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 56 | import android.content.ComponentName; |
| 57 | import android.content.Context; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 58 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 59 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 60 | import android.content.pm.PackageManager; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 61 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 62 | import android.content.res.Resources; |
| 63 | import android.graphics.Bitmap; |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 64 | import android.graphics.Bitmap.Config; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 65 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 66 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 67 | import android.os.Bundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 68 | import android.os.Handler; |
| 69 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 70 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 71 | import android.os.Message; |
| 72 | import android.os.PowerManager; |
| 73 | import android.os.RemoteException; |
| 74 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 75 | import android.os.UserHandle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 76 | import android.util.EventLog; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 77 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 78 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 79 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 80 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 81 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 82 | import java.lang.ref.WeakReference; |
| 83 | import java.util.ArrayList; |
| 84 | import java.util.Iterator; |
| 85 | import java.util.List; |
| 86 | |
| 87 | /** |
| 88 | * State and management of a single stack of activities. |
| 89 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 90 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 91 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 92 | // Ticks during which we check progress while waiting for an app to launch. |
| 93 | static final int LAUNCH_TICK = 500; |
| 94 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 95 | // How long we wait until giving up on the last activity to pause. This |
| 96 | // is short because it directly impacts the responsiveness of starting the |
| 97 | // next activity. |
| 98 | static final int PAUSE_TIMEOUT = 500; |
| 99 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 100 | // How long we wait for the activity to tell us it has stopped before |
| 101 | // giving up. This is a good amount of time because we really need this |
| 102 | // from the application in order to get its saved state. |
| 103 | static final int STOP_TIMEOUT = 10*1000; |
| 104 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 105 | // How long we wait until giving up on an activity telling us it has |
| 106 | // finished destroying itself. |
| 107 | static final int DESTROY_TIMEOUT = 10*1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 108 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 109 | // 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] | 110 | // disabled. |
| 111 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 112 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 113 | // How long between activity launches that we consider safe to not warn |
| 114 | // the user about an unexpected activity being launched on top. |
| 115 | static final long START_WARN_TIME = 5*1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 116 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 117 | // Set to false to disable the preview that is shown while a new activity |
| 118 | // is being started. |
| 119 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 120 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 121 | // How long to wait for all background Activities to redraw following a call to |
| 122 | // convertToTranslucent(). |
| 123 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 124 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 125 | enum ActivityState { |
| 126 | INITIALIZING, |
| 127 | RESUMED, |
| 128 | PAUSING, |
| 129 | PAUSED, |
| 130 | STOPPING, |
| 131 | STOPPED, |
| 132 | FINISHING, |
| 133 | DESTROYING, |
| 134 | DESTROYED |
| 135 | } |
| 136 | |
| 137 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 138 | final WindowManagerService mWindowManager; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 139 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 140 | final Context mContext; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 141 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 142 | /** |
| 143 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 144 | * running) activities. It contains #TaskRecord objects. |
| 145 | */ |
| 146 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<TaskRecord>(); |
| 147 | |
| 148 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 149 | * Used for validating app tokens with window manager. |
| 150 | */ |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 151 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<TaskGroup>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 152 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 153 | /** |
| 154 | * List of running activities, sorted by recent usage. |
| 155 | * The first entry in the list is the least recently used. |
| 156 | * It contains HistoryRecord objects. |
| 157 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 158 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<ActivityRecord>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 161 | * Animations that for the current transition have requested not to |
| 162 | * be considered for the transition animation. |
| 163 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 164 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<ActivityRecord>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 165 | |
| 166 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 167 | * When we are in the process of pausing an activity, before starting the |
| 168 | * next one, this variable holds the activity that is currently being paused. |
| 169 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 170 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * This is the last activity that we put into the paused state. This is |
| 174 | * used to determine if we need to do an activity transition while sleeping, |
| 175 | * when we normally hold the top activity paused. |
| 176 | */ |
| 177 | ActivityRecord mLastPausedActivity = null; |
| 178 | |
| 179 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 180 | * Activities that specify No History must be removed once the user navigates away from them. |
| 181 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 182 | * and finish it later if another activity replaces it on wakeup. |
| 183 | */ |
| 184 | ActivityRecord mLastNoHistoryActivity = null; |
| 185 | |
| 186 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 187 | * Current activity that is resumed, or null if there is none. |
| 188 | */ |
| 189 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 190 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 191 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 192 | * This is the last activity that has been started. It is only used to |
| 193 | * identify when multiple activities are started at once so that the user |
| 194 | * can be warned they may not be in the activity they think they are. |
| 195 | */ |
| 196 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 197 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 198 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 199 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 200 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 201 | // Activity in mTranslucentActivityWaiting is notified via |
| 202 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 203 | // background activity being drawn then the same call will be made with a true value. |
| 204 | ActivityRecord mTranslucentActivityWaiting = null; |
| 205 | ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = |
| 206 | new ArrayList<ActivityRecord>(); |
| 207 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 208 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 209 | * Set when we know we are going to be calling updateConfiguration() |
| 210 | * soon, so want to skip intermediate config checks. |
| 211 | */ |
| 212 | boolean mConfigWillChange; |
| 213 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 214 | long mLaunchStartTime = 0; |
| 215 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 216 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 217 | /** |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 218 | * Save the most recent screenshot for reuse. This keeps Recents from taking two identical |
| 219 | * screenshots, one for the Recents thumbnail and one for the pauseActivity thumbnail. |
| 220 | */ |
| 221 | private ActivityRecord mLastScreenshotActivity = null; |
| 222 | private Bitmap mLastScreenshotBitmap = null; |
| 223 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 224 | int mThumbnailWidth = -1; |
| 225 | int mThumbnailHeight = -1; |
| 226 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 227 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 228 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 229 | final int mStackId; |
| 230 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 231 | /** Run all ActivityStacks through this */ |
| 232 | final ActivityStackSupervisor mStackSupervisor; |
| 233 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 234 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 235 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 236 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 237 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 238 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 239 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 240 | |
| 241 | static class ScheduleDestroyArgs { |
| 242 | final ProcessRecord mOwner; |
| 243 | final boolean mOomAdj; |
| 244 | final String mReason; |
| 245 | ScheduleDestroyArgs(ProcessRecord owner, boolean oomAdj, String reason) { |
| 246 | mOwner = owner; |
| 247 | mOomAdj = oomAdj; |
| 248 | mReason = reason; |
| 249 | } |
| 250 | } |
| 251 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 252 | final Handler mHandler; |
| 253 | |
| 254 | final class ActivityStackHandler extends Handler { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 255 | //public Handler() { |
| 256 | // if (localLOGV) Slog.v(TAG, "Handler started!"); |
| 257 | //} |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 258 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 259 | super(looper); |
| 260 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 261 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 262 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 263 | public void handleMessage(Message msg) { |
| 264 | switch (msg.what) { |
| 265 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 266 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 267 | // We don't at this point know if the activity is fullscreen, |
| 268 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 269 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 270 | synchronized (mService) { |
| 271 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 272 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 273 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 274 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 275 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 276 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 277 | case LAUNCH_TICK_MSG: { |
| 278 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 279 | synchronized (mService) { |
| 280 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 281 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 285 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 286 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 287 | // We don't at this point know if the activity is fullscreen, |
| 288 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 289 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 290 | synchronized (mService) { |
| 291 | activityDestroyedLocked(r != null ? r.appToken : null); |
| 292 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 293 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 294 | case STOP_TIMEOUT_MSG: { |
| 295 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 296 | // We don't at this point know if the activity is fullscreen, |
| 297 | // so we need to be conservative and assume it isn't. |
| 298 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 299 | synchronized (mService) { |
| 300 | if (r.isInHistory()) { |
| 301 | activityStoppedLocked(r, null, null, null); |
| 302 | } |
| 303 | } |
| 304 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 305 | case DESTROY_ACTIVITIES_MSG: { |
| 306 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 307 | synchronized (mService) { |
| 308 | destroyActivitiesLocked(args.mOwner, args.mOomAdj, args.mReason); |
| 309 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 310 | } break; |
| 311 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 312 | synchronized (mService) { |
| 313 | notifyActivityDrawnLocked(null); |
| 314 | } |
| 315 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 316 | } |
| 317 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 320 | private int numActivities() { |
| 321 | int count = 0; |
| 322 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 323 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 324 | } |
| 325 | return count; |
| 326 | } |
| 327 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 328 | ActivityStack(ActivityManagerService service, Context context, Looper looper, int stackId) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 329 | mHandler = new ActivityStackHandler(looper); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 330 | mService = service; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 331 | mWindowManager = service.mWindowManager; |
| 332 | mStackSupervisor = service.mStackSupervisor; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 333 | mContext = context; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 334 | mStackId = stackId; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 335 | mCurrentUser = service.mCurrentUserId; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 336 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 337 | |
| 338 | private boolean okToShow(ActivityRecord r) { |
| 339 | return r.userId == mCurrentUser |
| 340 | || (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0; |
| 341 | } |
| 342 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 343 | final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 344 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 345 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 346 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 347 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 348 | ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 349 | if (!r.finishing && r != notTop && okToShow(r)) { |
| 350 | return r; |
| 351 | } |
| 352 | } |
| 353 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 354 | return null; |
| 355 | } |
| 356 | |
| 357 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 358 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 359 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 360 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 361 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 362 | ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 363 | if (!r.finishing && !r.delayedResume && r != notTop && okToShow(r)) { |
| 364 | return r; |
| 365 | } |
| 366 | } |
| 367 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 368 | return null; |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 373 | * 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] | 374 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 375 | * @param token If non-null, any history records matching this token will be skipped. |
| 376 | * @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] | 377 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 378 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 379 | */ |
| 380 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 381 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 382 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 383 | if (task.taskId == taskId) { |
| 384 | continue; |
| 385 | } |
| 386 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 387 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 388 | final ActivityRecord r = activities.get(i); |
| 389 | // Note: the taskId check depends on real taskId fields being non-zero |
| 390 | if (!r.finishing && (token != r.appToken) && okToShow(r)) { |
| 391 | return r; |
| 392 | } |
| 393 | } |
| 394 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 395 | return null; |
| 396 | } |
| 397 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 398 | final ActivityRecord topActivity() { |
| 399 | // Iterate to find the first non-empty task stack. Note that this code can |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 400 | // be simplified once we stop storing tasks with empty mActivities lists. |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 401 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 402 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 403 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 404 | return activities.get(activityNdx); |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 405 | } |
| 406 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 407 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 410 | final TaskRecord topTask() { |
| 411 | final int size = mTaskHistory.size(); |
| 412 | if (size > 0) { |
| 413 | return mTaskHistory.get(size - 1); |
| 414 | } |
| 415 | return null; |
| 416 | } |
| 417 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 418 | TaskRecord taskForIdLocked(int id) { |
| 419 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 420 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 421 | if (task.taskId == id) { |
| 422 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 425 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 428 | ActivityRecord isInStackLocked(IBinder token) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 429 | final ActivityRecord r = ActivityRecord.forToken(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 430 | if (r != null) { |
| 431 | final TaskRecord task = r.task; |
| 432 | if (task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
| 433 | if (task.stack != this) Slog.w(TAG, |
| 434 | "Illegal state! task does not point to stack it is in."); |
| 435 | return r; |
| 436 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 437 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 438 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 441 | boolean containsApp(ProcessRecord app) { |
| 442 | if (app == null) { |
| 443 | return false; |
| 444 | } |
| 445 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 446 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 447 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 448 | final ActivityRecord r = activities.get(activityNdx); |
| 449 | if (r.finishing) { |
| 450 | continue; |
| 451 | } |
| 452 | if (r.app == app) { |
| 453 | return true; |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | return false; |
| 458 | } |
| 459 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 460 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 461 | final boolean hadit = mLRUActivities.remove(r); |
| 462 | mLRUActivities.add(r); |
| 463 | return hadit; |
| 464 | } |
| 465 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 466 | final boolean isHomeStack() { |
| 467 | return mStackId == HOME_STACK_ID; |
| 468 | } |
| 469 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 470 | /** |
| 471 | * Returns the top activity in any existing task matching the given |
| 472 | * Intent. Returns null if no such task is found. |
| 473 | */ |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 474 | ActivityRecord findTaskLocked(ActivityRecord target) { |
| 475 | Intent intent = target.intent; |
| 476 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 477 | ComponentName cls = intent.getComponent(); |
| 478 | if (info.targetActivity != null) { |
| 479 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 480 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 481 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 482 | |
| 483 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 484 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 485 | if (task.userId != userId) { |
| 486 | // Looking for a different task. |
| 487 | continue; |
| 488 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 489 | final ActivityRecord r = task.getTopActivity(); |
| 490 | if (r == null || r.finishing || r.userId != userId || |
| 491 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
| 492 | continue; |
| 493 | } |
| 494 | |
| 495 | //Slog.i(TAG, "Comparing existing cls=" + r.task.intent.getComponent().flattenToShortString() |
| 496 | // + "/aff=" + r.task.affinity + " to new cls=" |
| 497 | // + intent.getComponent().flattenToShortString() + "/aff=" + taskAffinity); |
| 498 | if (task.affinity != null) { |
| 499 | if (task.affinity.equals(info.taskAffinity)) { |
| 500 | //Slog.i(TAG, "Found matching affinity!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 501 | return r; |
| 502 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 503 | } else if (task.intent != null && task.intent.getComponent().equals(cls)) { |
| 504 | //Slog.i(TAG, "Found matching class!"); |
| 505 | //dump(); |
| 506 | //Slog.i(TAG, "For Intent " + intent + " bringing to top: " + r.intent); |
| 507 | return r; |
| 508 | } else if (task.affinityIntent != null |
| 509 | && task.affinityIntent.getComponent().equals(cls)) { |
| 510 | //Slog.i(TAG, "Found matching class!"); |
| 511 | //dump(); |
| 512 | //Slog.i(TAG, "For Intent " + intent + " bringing to top: " + r.intent); |
| 513 | return r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
| 517 | return null; |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Returns the first activity (starting from the top of the stack) that |
| 522 | * is the same as the given activity. Returns null if no such activity |
| 523 | * is found. |
| 524 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 525 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 526 | ComponentName cls = intent.getComponent(); |
| 527 | if (info.targetActivity != null) { |
| 528 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 529 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 530 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 531 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 532 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 533 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 534 | if (task.userId != mCurrentUser) { |
| 535 | return null; |
| 536 | } |
| 537 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 538 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 539 | ActivityRecord r = activities.get(activityNdx); |
| 540 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 541 | //Slog.i(TAG, "Found matching class!"); |
| 542 | //dump(); |
| 543 | //Slog.i(TAG, "For Intent " + intent + " bringing to top: " + r.intent); |
| 544 | return r; |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | return null; |
| 550 | } |
| 551 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 552 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 553 | * 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] | 554 | * @return whether there are any activities for the specified user. |
| 555 | */ |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 556 | final boolean switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 557 | if (VALIDATE_TOKENS) { |
| 558 | validateAppTokensLocked(); |
| 559 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 560 | if (mCurrentUser == userId) { |
| 561 | return true; |
| 562 | } |
| 563 | mCurrentUser = userId; |
| 564 | |
| 565 | // Move userId's tasks to the top. |
| 566 | boolean haveActivities = false; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 567 | int index = mTaskHistory.size(); |
| 568 | for (int i = 0; i < index; ++i) { |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 569 | TaskRecord task = mTaskHistory.get(i); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 570 | if (task.userId == userId) { |
| 571 | haveActivities = true; |
| 572 | mTaskHistory.remove(i); |
| 573 | mTaskHistory.add(task); |
| 574 | --index; |
| 575 | } |
| 576 | } |
| 577 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 578 | return haveActivities; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 581 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 582 | r.state = ActivityState.RESUMED; |
| 583 | if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + r |
| 584 | + " (starting new instance)"); |
| 585 | r.stopped = false; |
| 586 | mResumedActivity = r; |
| 587 | r.task.touchActiveTime(); |
| 588 | mService.addRecentTaskLocked(r.task); |
| 589 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 590 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 591 | 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] | 592 | } |
| 593 | |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 594 | private void startLaunchTraces() { |
| 595 | if (mFullyDrawnStartTime != 0) { |
| 596 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 597 | } |
| 598 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0); |
| 599 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 600 | } |
| 601 | |
| 602 | private void stopFullyDrawnTraceIfNeeded() { |
| 603 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 604 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 605 | mFullyDrawnStartTime = 0; |
| 606 | } |
| 607 | } |
| 608 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 609 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 610 | if (r.displayStartTime == 0) { |
| 611 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 612 | if (mLaunchStartTime == 0) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 613 | startLaunchTraces(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 614 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 615 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 616 | } else if (mLaunchStartTime == 0) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 617 | startLaunchTraces(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 618 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 619 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 620 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 621 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 622 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 623 | // Make sure that there is no activity waiting for this to launch. |
| 624 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 625 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 626 | } else { |
| 627 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 628 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 629 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 632 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 633 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 634 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 635 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 636 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 637 | activities.get(activityNdx).setSleeping(false); |
| 638 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 639 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 640 | } |
| 641 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 642 | /** |
| 643 | * @return true if something must be done before going to sleep. |
| 644 | */ |
| 645 | boolean checkReadyForSleepLocked() { |
| 646 | if (mResumedActivity != null) { |
| 647 | // Still have something resumed; can't sleep until it is paused. |
| 648 | if (DEBUG_PAUSE) Slog.v(TAG, "Sleep needs to pause " + mResumedActivity); |
| 649 | if (DEBUG_USER_LEAVING) Slog.v(TAG, "Sleep => pause with userLeaving=false"); |
| 650 | startPausingLocked(false, true); |
| 651 | return true; |
| 652 | } |
| 653 | if (mPausingActivity != null) { |
| 654 | // Still waiting for something to pause; can't sleep yet. |
| 655 | if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still waiting to pause " + mPausingActivity); |
| 656 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 659 | return false; |
| 660 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 661 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 662 | void goToSleep() { |
| 663 | ensureActivitiesVisibleLocked(null, 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 664 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 665 | // Make sure any stopped but visible activities are now sleeping. |
| 666 | // This ensures that the activity's onStop() is called. |
| 667 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 668 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 669 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 670 | final ActivityRecord r = activities.get(activityNdx); |
| 671 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 672 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 673 | } |
| 674 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 675 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 676 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 677 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 678 | public final Bitmap screenshotActivities(ActivityRecord who) { |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 679 | if (who.noDisplay) { |
| 680 | return null; |
| 681 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 682 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 683 | Resources res = mService.mContext.getResources(); |
| 684 | int w = mThumbnailWidth; |
| 685 | int h = mThumbnailHeight; |
| 686 | if (w < 0) { |
| 687 | mThumbnailWidth = w = |
| 688 | res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width); |
| 689 | mThumbnailHeight = h = |
| 690 | res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height); |
| 691 | } |
| 692 | |
| 693 | if (w > 0) { |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 694 | if (who != mLastScreenshotActivity || mLastScreenshotBitmap == null |
| 695 | || mLastScreenshotBitmap.getWidth() != w |
| 696 | || mLastScreenshotBitmap.getHeight() != h) { |
| 697 | mLastScreenshotActivity = who; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 698 | mLastScreenshotBitmap = mWindowManager.screenshotApplications( |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 699 | who.appToken, Display.DEFAULT_DISPLAY, w, h); |
| 700 | } |
| 701 | if (mLastScreenshotBitmap != null) { |
| 702 | return mLastScreenshotBitmap.copy(Config.ARGB_8888, true); |
| 703 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 704 | } |
| 705 | return null; |
| 706 | } |
| 707 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 708 | final void startPausingLocked(boolean userLeaving, boolean uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 709 | if (mPausingActivity != null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 710 | Slog.e(TAG, "Trying to pause when pause is already pending for " |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 711 | + mPausingActivity, new RuntimeException("here").fillInStackTrace()); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 712 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 713 | ActivityRecord prev = mResumedActivity; |
| 714 | if (prev == null) { |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 715 | Slog.e(TAG, "Trying to pause when nothing is resumed", |
| 716 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 717 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 718 | return; |
| 719 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 720 | if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSING: " + prev); |
| 721 | else if (DEBUG_PAUSE) Slog.v(TAG, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 722 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 723 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 724 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 725 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 726 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 727 | prev.state = ActivityState.PAUSING; |
| 728 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 729 | clearLaunchTime(prev); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 730 | prev.updateThumbnail(screenshotActivities(prev), null); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 731 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 732 | |
| 733 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 734 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 735 | if (prev.app != null && prev.app.thread != null) { |
| 736 | if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending pause: " + prev); |
| 737 | try { |
| 738 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 739 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 740 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 741 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 742 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
| 743 | userLeaving, prev.configChangeFlags); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 744 | } catch (Exception e) { |
| 745 | // Ignore exception, if process died other code will cleanup. |
| 746 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 747 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 748 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 749 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 750 | } |
| 751 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 752 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 753 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 754 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | // If we are not going to sleep, we want to ensure the device is |
| 758 | // awake until the next activity is started. |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 759 | if (!mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 760 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 763 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 764 | // Have the window manager pause its key dispatching until the new |
| 765 | // activity has started. If we're pausing the activity just because |
| 766 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 767 | // key dispatch; the same activity will pick it up again on wakeup. |
| 768 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 769 | prev.pauseKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 770 | } else { |
| 771 | if (DEBUG_PAUSE) Slog.v(TAG, "Key dispatch not paused for screen off"); |
| 772 | } |
| 773 | |
| 774 | // Schedule a pause timeout in case the app doesn't respond. |
| 775 | // We don't give it much time because this directly impacts the |
| 776 | // responsiveness seen by the user. |
| 777 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 778 | msg.obj = prev; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 779 | prev.pauseTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 780 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
| 781 | if (DEBUG_PAUSE) Slog.v(TAG, "Waiting for pause to complete..."); |
| 782 | } else { |
| 783 | // This activity failed to schedule the |
| 784 | // pause, so just treat it as being paused now. |
| 785 | if (DEBUG_PAUSE) Slog.v(TAG, "Activity not running, resuming next."); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 786 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 789 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 790 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 791 | if (DEBUG_PAUSE) Slog.v( |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 792 | TAG, "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 793 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 794 | final ActivityRecord r = isInStackLocked(token); |
| 795 | if (r != null) { |
| 796 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 797 | if (mPausingActivity == r) { |
| 798 | if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSED: " + r |
| 799 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
| 800 | r.state = ActivityState.PAUSED; |
| 801 | completePauseLocked(); |
| 802 | } else { |
| 803 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 804 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 805 | mPausingActivity != null |
| 806 | ? mPausingActivity.shortComponentName : "(none)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 811 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, Bitmap thumbnail, |
| 812 | CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 813 | if (r.state != ActivityState.STOPPING) { |
| 814 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 815 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 816 | return; |
| 817 | } |
Dianne Hackborn | 98cfebc | 2011-10-18 13:17:33 -0700 | [diff] [blame] | 818 | if (DEBUG_SAVED_STATE) Slog.i(TAG, "Saving icicle of " + r + ": " + icicle); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 819 | if (icicle != null) { |
| 820 | // If icicle is null, this is happening due to a timeout, so we |
| 821 | // haven't really saved the state. |
| 822 | r.icicle = icicle; |
| 823 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 824 | r.launchCount = 0; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 825 | r.updateThumbnail(thumbnail, description); |
| 826 | } |
| 827 | if (!r.stopped) { |
| 828 | if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r + " (stop complete)"); |
| 829 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 830 | r.stopped = true; |
| 831 | r.state = ActivityState.STOPPED; |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 832 | if (r.finishing) { |
| 833 | r.clearOptionsLocked(); |
| 834 | } else { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 835 | if (r.configDestroy) { |
| 836 | destroyActivityLocked(r, true, false, "stop-config"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 837 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 838 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 839 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 840 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 845 | private void completePauseLocked() { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 846 | ActivityRecord prev = mPausingActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 847 | if (DEBUG_PAUSE) Slog.v(TAG, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 848 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 849 | if (prev != null) { |
| 850 | if (prev.finishing) { |
| 851 | if (DEBUG_PAUSE) Slog.v(TAG, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 852 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 853 | } else if (prev.app != null) { |
| 854 | if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending stop: " + prev); |
| 855 | if (prev.waitingVisible) { |
| 856 | prev.waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 857 | mStackSupervisor.mWaitingVisibleActivities.remove(prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 858 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v( |
| 859 | TAG, "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 860 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 861 | if (prev.configDestroy) { |
| 862 | // The previous is being paused because the configuration |
| 863 | // is changing, which means it is actually stopping... |
| 864 | // To juggle the fact that we are also starting a new |
| 865 | // instance right now, we need to first completely stop |
| 866 | // the current instance before starting the new one. |
| 867 | if (DEBUG_PAUSE) Slog.v(TAG, "Destroying after pause: " + prev); |
| 868 | destroyActivityLocked(prev, true, false, "pause-config"); |
| 869 | } else { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 870 | mStackSupervisor.mStoppingActivities.add(prev); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 871 | if (mStackSupervisor.mStoppingActivities.size() > 3 || |
| 872 | prev.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 873 | // If we already have a few activities waiting to stop, |
| 874 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 875 | // them out. Or if r is the last of activity of the last task the stack |
| 876 | // will be empty and must be cleared immediately. |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 877 | if (DEBUG_PAUSE) Slog.v(TAG, "To many pending stops, forcing idle"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 878 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 879 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 880 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | } else { |
| 884 | if (DEBUG_PAUSE) Slog.v(TAG, "App died during pause, not stopping: " + prev); |
| 885 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 886 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 887 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 888 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 889 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 890 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 891 | if (!mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 892 | mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 893 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 894 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 895 | ActivityRecord top = topStack.topRunningActivityLocked(null); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 896 | if (top == null || (prev != null && top != prev)) { |
| 897 | // If there are no more activities available to run, |
| 898 | // do resume anyway to start something. Also if the top |
| 899 | // activity on the stack is not the just paused activity, |
| 900 | // we need to go ahead and resume it to ensure we complete |
| 901 | // an in-flight app switch. |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 902 | mStackSupervisor.resumeTopActivitiesLocked(topStack, null, null); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 903 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 904 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 905 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 906 | if (prev != null) { |
| 907 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 908 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 909 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 910 | && mService.mBatteryStatsService.isOnBattery()) { |
| 911 | long diff; |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 912 | synchronized (mService.mProcessCpuThread) { |
| 913 | diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 914 | - prev.cpuTimeAtResume; |
| 915 | } |
| 916 | if (diff > 0) { |
| 917 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 918 | synchronized (bsi) { |
| 919 | BatteryStatsImpl.Uid.Proc ps = |
| 920 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 921 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 922 | if (ps != null) { |
| 923 | ps.addForegroundTimeLocked(diff); |
| 924 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 928 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 929 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Once we know that we have asked an application to put an activity in |
| 934 | * the resumed state (either by launching it or explicitly telling it), |
| 935 | * this function updates the rest of our state to match that fact. |
| 936 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 937 | private void completeResumeLocked(ActivityRecord next) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 938 | next.idle = false; |
| 939 | next.results = null; |
| 940 | next.newIntents = null; |
| 941 | |
| 942 | // 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] | 943 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 944 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 945 | mStackSupervisor.reportResumedActivityLocked(next); |
| 946 | |
| 947 | next.resumeKeyDispatchingLocked(); |
| 948 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 949 | |
| 950 | // Mark the point when the activity is resuming |
| 951 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 952 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 953 | if (next.app != null) { |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 954 | synchronized (mService.mProcessCpuThread) { |
| 955 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 956 | } |
| 957 | } else { |
| 958 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 959 | } |
| 960 | } |
| 961 | |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 962 | /** |
| 963 | * Version of ensureActivitiesVisible that can easily be called anywhere. |
| 964 | */ |
| 965 | final boolean ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) { |
| 966 | return ensureActivitiesVisibleLocked(starting, configChanges, false); |
| 967 | } |
| 968 | |
| 969 | final boolean ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 970 | boolean forceHomeShown) { |
| 971 | ActivityRecord r = topRunningActivityLocked(null); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 972 | return r != null && |
| 973 | ensureActivitiesVisibleLocked(r, starting, null, configChanges, forceHomeShown); |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 976 | /** |
| 977 | * Make sure that all activities that need to be visible (that is, they |
| 978 | * currently can be seen by the user) actually are. |
| 979 | */ |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 980 | final boolean ensureActivitiesVisibleLocked(ActivityRecord top, ActivityRecord starting, |
| 981 | String onlyThisProcess, int configChanges, boolean forceHomeShown) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 982 | if (DEBUG_VISBILITY) Slog.v( |
| 983 | TAG, "ensureActivitiesVisible behind " + top |
| 984 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 985 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 986 | if (mTranslucentActivityWaiting != top) { |
| 987 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 988 | if (mTranslucentActivityWaiting != null) { |
| 989 | // Call the callback with a timeout indication. |
| 990 | notifyActivityDrawnLocked(null); |
| 991 | mTranslucentActivityWaiting = null; |
| 992 | } |
| 993 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 994 | } |
| 995 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 996 | // If the top activity is not fullscreen, then we need to |
| 997 | // make sure any activities under it are now visible. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 998 | boolean aboveTop = true; |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 999 | boolean showHomeBehindStack = false; |
| 1000 | boolean behindFullscreen = !mStackSupervisor.isFrontStack(this) && |
| 1001 | !(forceHomeShown && isHomeStack()); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1002 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1003 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1004 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1005 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1006 | final ActivityRecord r = activities.get(activityNdx); |
| 1007 | if (r.finishing) { |
| 1008 | continue; |
| 1009 | } |
| 1010 | if (aboveTop && r != top) { |
| 1011 | continue; |
| 1012 | } |
| 1013 | aboveTop = false; |
| 1014 | if (!behindFullscreen) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1015 | if (DEBUG_VISBILITY) Slog.v( |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1016 | TAG, "Make visible? " + r + " finishing=" + r.finishing |
| 1017 | + " state=" + r.state); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1018 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1019 | final boolean doThisProcess = onlyThisProcess == null |
| 1020 | || onlyThisProcess.equals(r.processName); |
| 1021 | |
| 1022 | // First: if this is not the current activity being started, make |
| 1023 | // sure it matches the current configuration. |
| 1024 | if (r != starting && doThisProcess) { |
| 1025 | ensureActivityConfigurationLocked(r, 0); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1026 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1027 | |
| 1028 | if (r.app == null || r.app.thread == null) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1029 | if (onlyThisProcess == null || onlyThisProcess.equals(r.processName)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1030 | // This activity needs to be visible, but isn't even |
| 1031 | // running... get it started, but don't resume it |
| 1032 | // at this point. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1033 | if (DEBUG_VISBILITY) Slog.v(TAG, "Start and freeze screen for " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1034 | if (r != starting) { |
| 1035 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1036 | } |
| 1037 | if (!r.visible) { |
| 1038 | if (DEBUG_VISBILITY) Slog.v( |
| 1039 | TAG, "Starting and making visible: " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1040 | mWindowManager.setAppVisibility(r.appToken, true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1041 | } |
| 1042 | if (r != starting) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1043 | mStackSupervisor.startSpecificActivityLocked(r, false, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | } else if (r.visible) { |
| 1048 | // If this activity is already visible, then there is nothing |
| 1049 | // else to do here. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1050 | if (DEBUG_VISBILITY) Slog.v(TAG, "Skipping: already visible at " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1051 | r.stopFreezingScreenLocked(false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1052 | |
| 1053 | } else if (onlyThisProcess == null) { |
| 1054 | // This activity is not currently visible, but is running. |
| 1055 | // Tell it to become visible. |
| 1056 | r.visible = true; |
| 1057 | if (r.state != ActivityState.RESUMED && r != starting) { |
| 1058 | // If this activity is paused, tell it |
| 1059 | // to now show its window. |
| 1060 | if (DEBUG_VISBILITY) Slog.v( |
| 1061 | TAG, "Making visible and scheduling visibility: " + r); |
| 1062 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1063 | if (mTranslucentActivityWaiting != null) { |
| 1064 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
| 1065 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1066 | mWindowManager.setAppVisibility(r.appToken, true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1067 | r.sleeping = false; |
| 1068 | r.app.pendingUiClean = true; |
| 1069 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1070 | r.stopFreezingScreenLocked(false); |
| 1071 | } catch (Exception e) { |
| 1072 | // Just skip on any failure; we'll make it |
| 1073 | // visible when it next restarts. |
| 1074 | Slog.w(TAG, "Exception thrown making visibile: " |
| 1075 | + r.intent.getComponent(), e); |
| 1076 | } |
| 1077 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1078 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1079 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1080 | // Aggregate current change flags. |
| 1081 | configChanges |= r.configChangeFlags; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1082 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1083 | if (r.fullscreen) { |
| 1084 | // At this point, nothing else needs to be shown |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 1085 | if (DEBUG_VISBILITY) Slog.v(TAG, "Fullscreen: at " + r); |
| 1086 | behindFullscreen = true; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1087 | } else if (task.mOnTopOfHome) { |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 1088 | if (DEBUG_VISBILITY) Slog.v(TAG, "Showing home: at " + r); |
| 1089 | showHomeBehindStack = true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1090 | behindFullscreen = true; |
| 1091 | } |
| 1092 | } else { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1093 | if (DEBUG_VISBILITY) Slog.v( |
| 1094 | TAG, "Make invisible? " + r + " finishing=" + r.finishing |
| 1095 | + " state=" + r.state |
| 1096 | + " behindFullscreen=" + behindFullscreen); |
| 1097 | // Now for any activities that aren't visible to the user, make |
| 1098 | // sure they no longer are keeping the screen frozen. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1099 | if (r.visible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1100 | if (DEBUG_VISBILITY) Slog.v(TAG, "Making invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1101 | r.visible = false; |
| 1102 | try { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1103 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1104 | switch (r.state) { |
| 1105 | case STOPPING: |
| 1106 | case STOPPED: |
| 1107 | if (r.app != null && r.app.thread != null) { |
| 1108 | if (DEBUG_VISBILITY) Slog.v( |
| 1109 | TAG, "Scheduling invisibility: " + r); |
| 1110 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1111 | } |
| 1112 | break; |
| 1113 | |
| 1114 | case INITIALIZING: |
| 1115 | case RESUMED: |
| 1116 | case PAUSING: |
| 1117 | case PAUSED: |
Craig Mautner | 8817610 | 2013-07-22 12:57:51 -0700 | [diff] [blame] | 1118 | // This case created for transitioning activities from |
| 1119 | // translucent to opaque {@link Activity#convertToOpaque}. |
Craig Mautner | e5273b4 | 2013-09-09 12:57:47 -0700 | [diff] [blame] | 1120 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1121 | mStackSupervisor.mStoppingActivities.add(r); |
| 1122 | } |
| 1123 | mStackSupervisor.scheduleIdleLocked(); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1124 | break; |
| 1125 | |
| 1126 | default: |
| 1127 | break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } catch (Exception e) { |
| 1130 | // Just skip on any failure; we'll make it |
| 1131 | // visible when it next restarts. |
| 1132 | Slog.w(TAG, "Exception thrown making hidden: " |
| 1133 | + r.intent.getComponent(), e); |
| 1134 | } |
| 1135 | } else { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1136 | if (DEBUG_VISBILITY) Slog.v(TAG, "Already invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1137 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1138 | } |
| 1139 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1140 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 1141 | return showHomeBehindStack; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1142 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1143 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1144 | void convertToTranslucent(ActivityRecord r) { |
| 1145 | mTranslucentActivityWaiting = r; |
| 1146 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1147 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1152 | * redrawn notify the top activity by calling |
| 1153 | * {@link Activity#onTranslucentConversionComplete}. |
| 1154 | * |
| 1155 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1156 | * occurred and the activity will be notified immediately. |
| 1157 | */ |
| 1158 | void notifyActivityDrawnLocked(ActivityRecord r) { |
| 1159 | if ((r == null) |
| 1160 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1161 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1162 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1163 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1164 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1165 | mTranslucentActivityWaiting = null; |
| 1166 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1167 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1168 | |
| 1169 | if (waitingActivity != null && waitingActivity.app != null && |
| 1170 | waitingActivity.app.thread != null) { |
| 1171 | try { |
| 1172 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1173 | waitingActivity.appToken, r != null); |
| 1174 | } catch (RemoteException e) { |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1180 | /** |
| 1181 | * Ensure that the top activity in the stack is resumed. |
| 1182 | * |
| 1183 | * @param prev The previously resumed activity, for when in the process |
| 1184 | * of pausing; can be null to call from elsewhere. |
| 1185 | * |
| 1186 | * @return Returns true if something is being resumed, or false if |
| 1187 | * nothing happened. |
| 1188 | */ |
| 1189 | final boolean resumeTopActivityLocked(ActivityRecord prev) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1190 | return resumeTopActivityLocked(prev, null); |
| 1191 | } |
| 1192 | |
| 1193 | final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1194 | // Find the first activity that is not finishing. |
| 1195 | ActivityRecord next = topRunningActivityLocked(null); |
| 1196 | |
| 1197 | // Remember how we'll process this pause/resume situation, and ensure |
| 1198 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1199 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1200 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1201 | |
| 1202 | if (next == null) { |
| 1203 | // There are no more activities! Let's just start up the |
| 1204 | // Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1205 | ActivityOptions.abort(options); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1206 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1207 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 1208 | return mStackSupervisor.resumeHomeActivity(prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1212 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1213 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1214 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1215 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1216 | // Make sure we have executed any pending transitions, since there |
| 1217 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1218 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1219 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1220 | ActivityOptions.abort(options); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1221 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1222 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1223 | return false; |
| 1224 | } |
| 1225 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1226 | final TaskRecord nextTask = next.task; |
| 1227 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1228 | if (prevTask != null && prevTask.mOnTopOfHome && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1229 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1230 | if (prevTask == nextTask) { |
| 1231 | ArrayList<ActivityRecord> activities = prevTask.mActivities; |
| 1232 | final int numActivities = activities.size(); |
| 1233 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 1234 | final ActivityRecord r = activities.get(activityNdx); |
| 1235 | // r is usually the same as next, but what if two activities were launched |
| 1236 | // before prev finished? |
| 1237 | if (!r.finishing) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1238 | r.frontOfTask = true; |
| 1239 | break; |
| 1240 | } |
| 1241 | } |
| 1242 | } else if (prevTask != topTask()) { |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1243 | // This task is going away but it was supposed to return to the home task. |
| 1244 | // 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] | 1245 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1246 | mTaskHistory.get(taskNdx).mOnTopOfHome = true; |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1247 | } else { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1248 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1249 | return mStackSupervisor.resumeHomeActivity(prev); |
| 1250 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1253 | // If we are sleeping, and there is no resumed activity, and the top |
| 1254 | // activity is paused, well that is the state we want. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1255 | if ((mService.isSleepingOrShuttingDown()) |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1256 | && mLastPausedActivity == next |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1257 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1258 | // Make sure we have executed any pending transitions, since there |
| 1259 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1260 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1261 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1262 | ActivityOptions.abort(options); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1263 | 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] | 1264 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1265 | return false; |
| 1266 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1267 | |
| 1268 | // Make sure that the user who owns this activity is started. If not, |
| 1269 | // we will just leave it as is because someone should be bringing |
| 1270 | // another user's activities to the top of the stack. |
| 1271 | if (mService.mStartedUsers.get(next.userId) == null) { |
| 1272 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 1273 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1274 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1275 | return false; |
| 1276 | } |
| 1277 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1278 | // The activity may be waiting for stop, but that is no longer |
| 1279 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1280 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1281 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1282 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1283 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1284 | |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1285 | next.updateOptionsLocked(options); |
| 1286 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1287 | if (DEBUG_SWITCH) Slog.v(TAG, "Resuming " + next); |
| 1288 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1289 | // If we are currently pausing an activity, then don't do anything |
| 1290 | // until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 1291 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1292 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG, |
| 1293 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1294 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1295 | return false; |
| 1296 | } |
| 1297 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1298 | // Okay we are now going to start a switch, to 'next'. We may first |
| 1299 | // have to pause the current activity, but this is an important point |
| 1300 | // 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] | 1301 | // XXX "App Redirected" dialog is getting too many false positives |
| 1302 | // at this point, so turn off for now. |
| 1303 | if (false) { |
| 1304 | if (mLastStartedActivity != null && !mLastStartedActivity.finishing) { |
| 1305 | long now = SystemClock.uptimeMillis(); |
| 1306 | final boolean inTime = mLastStartedActivity.startTime != 0 |
| 1307 | && (mLastStartedActivity.startTime + START_WARN_TIME) >= now; |
| 1308 | final int lastUid = mLastStartedActivity.info.applicationInfo.uid; |
| 1309 | final int nextUid = next.info.applicationInfo.uid; |
| 1310 | if (inTime && lastUid != nextUid |
| 1311 | && lastUid != next.launchedFromUid |
| 1312 | && mService.checkPermission( |
| 1313 | android.Manifest.permission.STOP_APP_SWITCHES, |
| 1314 | -1, next.launchedFromUid) |
| 1315 | != PackageManager.PERMISSION_GRANTED) { |
| 1316 | mService.showLaunchWarningLocked(mLastStartedActivity, next); |
| 1317 | } else { |
| 1318 | next.startTime = now; |
| 1319 | mLastStartedActivity = next; |
| 1320 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1321 | } else { |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1322 | next.startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1323 | mLastStartedActivity = next; |
| 1324 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1325 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1326 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1327 | // We need to start pausing the current activity so the top one |
| 1328 | // can be resumed... |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1329 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving); |
| 1330 | if (mResumedActivity != null) { |
| 1331 | pausing = true; |
| 1332 | startPausingLocked(userLeaving, false); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1333 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1334 | } |
| 1335 | if (pausing) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1336 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG, |
| 1337 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1338 | // At this point we want to put the upcoming activity's process |
| 1339 | // at the top of the LRU list, since we know we will be needing it |
| 1340 | // very soon and it would be a waste to let it get killed if it |
| 1341 | // happens to be sitting towards the end. |
| 1342 | if (next.app != null && next.app.thread != null) { |
| 1343 | // No reason to do full oom adj update here; we'll let that |
| 1344 | // happen whenever it needs to later. |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1345 | mService.updateLruProcessLocked(next.app, false); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1346 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1347 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1348 | return true; |
| 1349 | } |
| 1350 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1351 | // If the most recent activity was noHistory but was only stopped rather |
| 1352 | // than stopped+finished because the device went to sleep, we need to make |
| 1353 | // sure to finish it as we're making a new activity topmost. |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1354 | if (mService.mSleeping && mLastNoHistoryActivity != null && |
| 1355 | !mLastNoHistoryActivity.finishing) { |
| 1356 | if (DEBUG_STATES) Slog.d(TAG, "no-history finish of " + mLastNoHistoryActivity + |
| 1357 | " on new resume"); |
| 1358 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
| 1359 | null, "no-history", false); |
| 1360 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1363 | if (prev != null && prev != next) { |
| 1364 | if (!prev.waitingVisible && next != null && !next.nowVisible) { |
| 1365 | prev.waitingVisible = true; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1366 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1367 | if (DEBUG_SWITCH) Slog.v( |
| 1368 | TAG, "Resuming top, waiting visible to hide: " + prev); |
| 1369 | } else { |
| 1370 | // The next activity is already visible, so hide the previous |
| 1371 | // activity's windows right now so we can show the new one ASAP. |
| 1372 | // We only do this if the previous is finishing, which should mean |
| 1373 | // it is on top of the one being resumed so hiding it quickly |
| 1374 | // is good. Otherwise, we want to do the normal route of allowing |
| 1375 | // the resumed activity to be shown so we can decide if the |
| 1376 | // previous should actually be hidden depending on whether the |
| 1377 | // new one is found to be full-screen or not. |
| 1378 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1379 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1380 | if (DEBUG_SWITCH) Slog.v(TAG, "Not waiting for visible to hide: " |
| 1381 | + prev + ", waitingVisible=" |
| 1382 | + (prev != null ? prev.waitingVisible : null) |
| 1383 | + ", nowVisible=" + next.nowVisible); |
| 1384 | } else { |
| 1385 | if (DEBUG_SWITCH) Slog.v(TAG, "Previous already visible but still waiting to hide: " |
| 1386 | + prev + ", waitingVisible=" |
| 1387 | + (prev != null ? prev.waitingVisible : null) |
| 1388 | + ", nowVisible=" + next.nowVisible); |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1393 | // Launching this app's activity, make sure the app is no longer |
| 1394 | // considered stopped. |
| 1395 | try { |
| 1396 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1397 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1398 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 1399 | } catch (IllegalArgumentException e) { |
| 1400 | Slog.w(TAG, "Failed trying to unstop package " |
| 1401 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1404 | // We are starting up the next activity, so tell the window manager |
| 1405 | // that the previous one will be hidden soon. This way it can know |
| 1406 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1407 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1408 | if (prev != null) { |
| 1409 | if (prev.finishing) { |
| 1410 | if (DEBUG_TRANSITION) Slog.v(TAG, |
| 1411 | "Prepare close transition: prev=" + prev); |
| 1412 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1413 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1414 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1415 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1416 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1417 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 1418 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1419 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1420 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1421 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1422 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1423 | if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1424 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1425 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1426 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1427 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1428 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1429 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
| 1430 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | if (false) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1434 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1435 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1436 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1437 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1438 | if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1439 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1440 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1441 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1442 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1443 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1446 | if (anim) { |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1447 | next.applyOptionsLocked(); |
| 1448 | } else { |
| 1449 | next.clearOptionsLocked(); |
| 1450 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1451 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1452 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1453 | if (next.app != null && next.app.thread != null) { |
| 1454 | if (DEBUG_SWITCH) Slog.v(TAG, "Resume running: " + next); |
| 1455 | |
| 1456 | // This activity is now becoming visible. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1457 | mWindowManager.setAppVisibility(next.appToken, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1458 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1459 | // schedule launch ticks to collect information about slow apps. |
| 1460 | next.startLaunchTickingLocked(); |
| 1461 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1462 | ActivityRecord lastResumedActivity = |
| 1463 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1464 | ActivityState lastState = next.state; |
| 1465 | |
| 1466 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1467 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1468 | if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + next + " (in existing)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1469 | next.state = ActivityState.RESUMED; |
| 1470 | mResumedActivity = next; |
| 1471 | next.task.touchActiveTime(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1472 | mService.addRecentTaskLocked(next.task); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1473 | mService.updateLruProcessLocked(next.app, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1474 | updateLRUListLocked(next); |
| 1475 | |
| 1476 | // Have the window manager re-evaluate the orientation of |
| 1477 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1478 | boolean notUpdated = true; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1479 | if (mStackSupervisor.isFrontStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1480 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1481 | mService.mConfiguration, |
| 1482 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 1483 | if (config != null) { |
| 1484 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1485 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1486 | notUpdated = !mService.updateConfigurationLocked(config, next, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1487 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1488 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1489 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1490 | // The configuration update wasn't able to keep the existing |
| 1491 | // instance of the activity, and instead started a new one. |
| 1492 | // We should be all done, but let's just make sure our activity |
| 1493 | // is still at the top and schedule another run if something |
| 1494 | // weird happened. |
| 1495 | ActivityRecord nextNext = topRunningActivityLocked(null); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1496 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1497 | "Activity config changed during resume: " + next |
| 1498 | + ", new next: " + nextNext); |
| 1499 | if (nextNext != next) { |
| 1500 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1501 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1502 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1503 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1504 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1505 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1506 | return true; |
| 1507 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1508 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1509 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1510 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1511 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1512 | try { |
| 1513 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 1514 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1515 | if (a != null) { |
| 1516 | final int N = a.size(); |
| 1517 | if (!next.finishing && N > 0) { |
| 1518 | if (DEBUG_RESULTS) Slog.v( |
| 1519 | TAG, "Delivering results to " + next |
| 1520 | + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1521 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1526 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1530 | next.userId, System.identityHashCode(next), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1531 | next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1532 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1533 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1534 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 1535 | next.app.pendingUiClean = true; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1536 | next.app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP); |
| 1537 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1538 | mService.isNextTransitionForward()); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1539 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1540 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1541 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1542 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1543 | } catch (Exception e) { |
| 1544 | // Whoops, need to restart this activity! |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1545 | if (DEBUG_STATES) Slog.v(TAG, "Resume failed; resetting state to " |
| 1546 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1547 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1548 | if (lastStack != null) { |
| 1549 | lastStack.mResumedActivity = lastResumedActivity; |
| 1550 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1551 | Slog.i(TAG, "Restarting because process died: " + next); |
| 1552 | if (!next.hasBeenLaunched) { |
| 1553 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1554 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 1555 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1556 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1557 | next.appToken, next.packageName, next.theme, |
| 1558 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1559 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 1560 | next.windowFlags, null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1561 | } |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1562 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1563 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1564 | return true; |
| 1565 | } |
| 1566 | |
| 1567 | // From this point on, if something goes wrong there is no way |
| 1568 | // to recover the activity. |
| 1569 | try { |
| 1570 | next.visible = true; |
| 1571 | completeResumeLocked(next); |
| 1572 | } catch (Exception e) { |
| 1573 | // If any exception gets thrown, toss away this |
| 1574 | // activity and try the next one. |
| 1575 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1576 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1577 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1578 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1579 | return true; |
| 1580 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1581 | next.stopped = false; |
| 1582 | |
| 1583 | } else { |
| 1584 | // Whoops, need to restart this activity! |
| 1585 | if (!next.hasBeenLaunched) { |
| 1586 | next.hasBeenLaunched = true; |
| 1587 | } else { |
| 1588 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1589 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1590 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1591 | mService.compatibilityInfoForPackageLocked( |
| 1592 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1593 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1594 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1595 | null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1596 | } |
| 1597 | if (DEBUG_SWITCH) Slog.v(TAG, "Restarting: " + next); |
| 1598 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1599 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Restarting " + next); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1600 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1603 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1604 | return true; |
| 1605 | } |
| 1606 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1607 | private void insertTaskAtTop(TaskRecord task) { |
| 1608 | mTaskHistory.remove(task); |
| 1609 | // Now put task at top. |
| 1610 | int stackNdx = mTaskHistory.size(); |
| 1611 | if (task.userId != mCurrentUser) { |
| 1612 | // Put non-current user tasks below current user tasks. |
| 1613 | while (--stackNdx >= 0) { |
| 1614 | if (mTaskHistory.get(stackNdx).userId != mCurrentUser) { |
| 1615 | break; |
| 1616 | } |
| 1617 | } |
| 1618 | ++stackNdx; |
| 1619 | } |
| 1620 | mTaskHistory.add(stackNdx, task); |
| 1621 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1622 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1623 | final void startActivityLocked(ActivityRecord r, boolean newTask, |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1624 | boolean doResume, boolean keepCurTransition, Bundle options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1625 | TaskRecord rTask = r.task; |
| 1626 | final int taskId = rTask.taskId; |
| 1627 | if (taskForIdLocked(taskId) == null || newTask) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1628 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 1629 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1630 | // Might not even be in. |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1631 | insertTaskAtTop(rTask); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1632 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1633 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1634 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1635 | if (!newTask) { |
| 1636 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1637 | boolean startIt = true; |
| 1638 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1639 | task = mTaskHistory.get(taskNdx); |
| 1640 | if (task == r.task) { |
| 1641 | // Here it is! Now, if this is not yet visible to the |
| 1642 | // user, then just add it without starting; it will |
| 1643 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1644 | if (!startIt) { |
| 1645 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 1646 | + task, new RuntimeException("here").fillInStackTrace()); |
| 1647 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1648 | r.putInHistory(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1649 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 1650 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1651 | (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, |
| 1652 | r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1653 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1654 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1655 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1656 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1657 | return; |
| 1658 | } |
| 1659 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1660 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1661 | startIt = false; |
| 1662 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | // Place a new activity at top of stack, so it is next to interact |
| 1667 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1668 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1669 | // If we are not placing the new activity frontmost, we do not want |
| 1670 | // to deliver the onUserLeaving callback to the actual frontmost |
| 1671 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1672 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1673 | mStackSupervisor.mUserLeaving = false; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1674 | if (DEBUG_USER_LEAVING) Slog.v(TAG, |
| 1675 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1676 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1677 | |
| 1678 | task = r.task; |
| 1679 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1680 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1681 | 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] | 1682 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1683 | task.addActivityToTop(r); |
| 1684 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1685 | r.putInHistory(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1686 | r.frontOfTask = newTask; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1687 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1688 | // We want to show the starting preview window if we are |
| 1689 | // switching to a new task, or the next activity's process is |
| 1690 | // not currently running. |
| 1691 | boolean showStartingIcon = newTask; |
| 1692 | ProcessRecord proc = r.app; |
| 1693 | if (proc == null) { |
| 1694 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 1695 | } |
| 1696 | if (proc == null || proc.thread == null) { |
| 1697 | showStartingIcon = true; |
| 1698 | } |
| 1699 | if (DEBUG_TRANSITION) Slog.v(TAG, |
| 1700 | "Prepare open transition: starting " + r); |
| 1701 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1702 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1703 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1704 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1705 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1706 | ? AppTransition.TRANSIT_TASK_OPEN |
| 1707 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1708 | mNoAnimActivities.remove(r); |
| 1709 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1710 | r.updateOptionsLocked(options); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1711 | mWindowManager.addAppToken(task.mActivities.indexOf(r), |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 1712 | r.appToken, r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1713 | (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1714 | boolean doShow = true; |
| 1715 | if (newTask) { |
| 1716 | // Even though this activity is starting fresh, we still need |
| 1717 | // to reset it to make sure we apply affinities to move any |
| 1718 | // existing activities from other tasks in to it. |
| 1719 | // If the caller has requested that the target task be |
| 1720 | // reset, then do so. |
| 1721 | if ((r.intent.getFlags() |
| 1722 | &Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
| 1723 | resetTaskIfNeededLocked(r, r); |
| 1724 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 1725 | } |
| 1726 | } |
| 1727 | if (SHOW_APP_STARTING_PREVIEW && doShow) { |
| 1728 | // Figure out if we are transitioning from another activity that is |
| 1729 | // "has the same starting icon" as the next one. This allows the |
| 1730 | // window manager to keep the previous window it had previously |
| 1731 | // created, if it still had one. |
| 1732 | ActivityRecord prev = mResumedActivity; |
| 1733 | if (prev != null) { |
| 1734 | // We don't want to reuse the previous starting preview if: |
| 1735 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1736 | if (prev.task != r.task) { |
| 1737 | prev = null; |
| 1738 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1739 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1740 | else if (prev.nowVisible) { |
| 1741 | prev = null; |
| 1742 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1743 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1744 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1745 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1746 | mService.compatibilityInfoForPackageLocked( |
| 1747 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1748 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1749 | prev != null ? prev.appToken : null, showStartingIcon); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1750 | } |
| 1751 | } else { |
| 1752 | // If this is the first activity, don't do any fancy animations, |
| 1753 | // because there is nothing for it to animate on top of. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1754 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 1755 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1756 | (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1757 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1758 | } |
| 1759 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1760 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | if (doResume) { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 1764 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1768 | final void validateAppTokensLocked() { |
| 1769 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1770 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 1771 | final int numTasks = mTaskHistory.size(); |
| 1772 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 1773 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 1774 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 1775 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1776 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 1777 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1778 | TaskGroup group = new TaskGroup(); |
| 1779 | group.taskId = task.taskId; |
| 1780 | mValidateAppTokens.add(group); |
| 1781 | final int numActivities = activities.size(); |
| 1782 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 1783 | final ActivityRecord r = activities.get(activityNdx); |
| 1784 | group.tokens.add(r.appToken); |
| 1785 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1786 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1787 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1788 | } |
| 1789 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1790 | /** |
| 1791 | * Perform a reset of the given task, if needed as part of launching it. |
| 1792 | * Returns the new HistoryRecord at the top of the task. |
| 1793 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1794 | /** |
| 1795 | * Helper method for #resetTaskIfNeededLocked. |
| 1796 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 1797 | * for another task, or leave it as-is. |
| 1798 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 1799 | * @param forceReset |
| 1800 | * @return An ActivityOptions that needs to be processed. |
| 1801 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1802 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1803 | ActivityOptions topOptions = null; |
| 1804 | |
| 1805 | int replyChainEnd = -1; |
| 1806 | boolean canMoveOptions = true; |
| 1807 | |
| 1808 | // We only do this for activities that are not the root of the task (since if we finish |
| 1809 | // the root, we may no longer have the task!). |
| 1810 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1811 | final int numActivities = activities.size(); |
| 1812 | for (int i = numActivities - 1; i > 0; --i ) { |
| 1813 | ActivityRecord target = activities.get(i); |
| 1814 | |
| 1815 | final int flags = target.info.flags; |
| 1816 | final boolean finishOnTaskLaunch = |
| 1817 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 1818 | final boolean allowTaskReparenting = |
| 1819 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 1820 | final boolean clearWhenTaskReset = |
| 1821 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 1822 | |
| 1823 | if (!finishOnTaskLaunch |
| 1824 | && !clearWhenTaskReset |
| 1825 | && target.resultTo != null) { |
| 1826 | // If this activity is sending a reply to a previous |
| 1827 | // activity, we can't do anything with it now until |
| 1828 | // we reach the start of the reply chain. |
| 1829 | // XXX note that we are assuming the result is always |
| 1830 | // to the previous activity, which is almost always |
| 1831 | // the case but we really shouldn't count on. |
| 1832 | if (replyChainEnd < 0) { |
| 1833 | replyChainEnd = i; |
| 1834 | } |
| 1835 | } else if (!finishOnTaskLaunch |
| 1836 | && !clearWhenTaskReset |
| 1837 | && allowTaskReparenting |
| 1838 | && target.taskAffinity != null |
| 1839 | && !target.taskAffinity.equals(task.affinity)) { |
| 1840 | // If this activity has an affinity for another |
| 1841 | // task, then we need to move it out of here. We will |
| 1842 | // move it as far out of the way as possible, to the |
| 1843 | // bottom of the activity stack. This also keeps it |
| 1844 | // correctly ordered with any activities we previously |
| 1845 | // moved. |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 1846 | final ActivityRecord bottom = |
| 1847 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
| 1848 | mTaskHistory.get(0).mActivities.get(0) : null; |
| 1849 | if (bottom != null && target.taskAffinity != null |
| 1850 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1851 | // If the activity currently at the bottom has the |
| 1852 | // same task affinity as the one we are moving, |
| 1853 | // then merge it into the same task. |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 1854 | target.setTask(bottom.task, bottom.thumbHolder, false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1855 | if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 1856 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1857 | } else { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1858 | target.setTask(createTaskRecord(mStackSupervisor.getNextTaskId(), target.info, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1859 | null, false), null, false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1860 | target.task.affinityIntent = target.intent; |
| 1861 | if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target |
| 1862 | + " out to new task " + target.task); |
| 1863 | } |
| 1864 | |
| 1865 | final TaskRecord targetTask = target.task; |
| 1866 | final int targetTaskId = targetTask.taskId; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1867 | mWindowManager.setAppGroupId(target.appToken, targetTaskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1868 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1869 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1870 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 1871 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 1872 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1873 | if (p.finishing) { |
| 1874 | continue; |
| 1875 | } |
| 1876 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1877 | ThumbnailHolder curThumbHolder = p.thumbHolder; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1878 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1879 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1880 | topOptions = p.takeOptionsLocked(); |
| 1881 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1882 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1883 | } |
| 1884 | } |
| 1885 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing activity " + p + " from task=" |
| 1886 | + task + " adding to task=" + targetTask, |
| 1887 | new RuntimeException("here").fillInStackTrace()); |
| 1888 | if (DEBUG_TASKS) Slog.v(TAG, "Pushing next activity " + p |
| 1889 | + " out to target's task " + target.task); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1890 | p.setTask(targetTask, curThumbHolder, false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1891 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 1892 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1893 | mWindowManager.setAppGroupId(p.appToken, targetTaskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1894 | } |
| 1895 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1896 | mWindowManager.moveTaskToBottom(targetTaskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1897 | if (VALIDATE_TOKENS) { |
| 1898 | validateAppTokensLocked(); |
| 1899 | } |
| 1900 | |
| 1901 | replyChainEnd = -1; |
| 1902 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 1903 | // If the activity should just be removed -- either |
| 1904 | // because it asks for it, or the task should be |
| 1905 | // cleared -- then finish it and anything that is |
| 1906 | // part of its reply chain. |
| 1907 | int end; |
| 1908 | if (clearWhenTaskReset) { |
| 1909 | // In this case, we want to finish this activity |
| 1910 | // and everything above it, so be sneaky and pretend |
| 1911 | // like these are all in the reply chain. |
| 1912 | end = numActivities - 1; |
| 1913 | } else if (replyChainEnd < 0) { |
| 1914 | end = i; |
| 1915 | } else { |
| 1916 | end = replyChainEnd; |
| 1917 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1918 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1919 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1920 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1921 | if (p.finishing) { |
| 1922 | continue; |
| 1923 | } |
| 1924 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1925 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1926 | topOptions = p.takeOptionsLocked(); |
| 1927 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1928 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1929 | } |
| 1930 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1931 | if (DEBUG_TASKS) Slog.w(TAG, |
| 1932 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1933 | if (finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1934 | end--; |
| 1935 | srcPos--; |
| 1936 | } |
| 1937 | } |
| 1938 | replyChainEnd = -1; |
| 1939 | } else { |
| 1940 | // If we were in the middle of a chain, well the |
| 1941 | // activity that started it all doesn't want anything |
| 1942 | // special, so leave it all as-is. |
| 1943 | replyChainEnd = -1; |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | return topOptions; |
| 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 1952 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 1953 | * @param affinityTask The task we are looking for an affinity to. |
| 1954 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 1955 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 1956 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 1957 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1958 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1959 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 1960 | int replyChainEnd = -1; |
| 1961 | final int taskId = task.taskId; |
| 1962 | final String taskAffinity = task.affinity; |
| 1963 | |
| 1964 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 1965 | final int numActivities = activities.size(); |
| 1966 | // Do not operate on the root Activity. |
| 1967 | for (int i = numActivities - 1; i > 0; --i) { |
| 1968 | ActivityRecord target = activities.get(i); |
| 1969 | |
| 1970 | final int flags = target.info.flags; |
| 1971 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 1972 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 1973 | |
| 1974 | if (target.resultTo != null) { |
| 1975 | // If this activity is sending a reply to a previous |
| 1976 | // activity, we can't do anything with it now until |
| 1977 | // we reach the start of the reply chain. |
| 1978 | // XXX note that we are assuming the result is always |
| 1979 | // to the previous activity, which is almost always |
| 1980 | // the case but we really shouldn't count on. |
| 1981 | if (replyChainEnd < 0) { |
| 1982 | replyChainEnd = i; |
| 1983 | } |
| 1984 | } else if (topTaskIsHigher |
| 1985 | && allowTaskReparenting |
| 1986 | && taskAffinity != null |
| 1987 | && taskAffinity.equals(target.taskAffinity)) { |
| 1988 | // This activity has an affinity for our task. Either remove it if we are |
| 1989 | // clearing or move it over to our task. Note that |
| 1990 | // we currently punt on the case where we are resetting a |
| 1991 | // task that is not at the top but who has activities above |
| 1992 | // with an affinity to it... this is really not a normal |
| 1993 | // case, and we will need to later pull that task to the front |
| 1994 | // and usually at that point we will do the reset and pick |
| 1995 | // up those remaining activities. (This only happens if |
| 1996 | // someone starts an activity in a new task from an activity |
| 1997 | // in a task that is not currently on top.) |
| 1998 | if (forceReset || finishOnTaskLaunch) { |
| 1999 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
| 2000 | if (DEBUG_TASKS) Slog.v(TAG, "Finishing task at index " + start + " to " + i); |
| 2001 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2002 | final ActivityRecord p = activities.get(srcPos); |
| 2003 | if (p.finishing) { |
| 2004 | continue; |
| 2005 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2006 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2007 | } |
| 2008 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2009 | if (taskInsertionPoint < 0) { |
| 2010 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2011 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2012 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2013 | |
| 2014 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
| 2015 | if (DEBUG_TASKS) Slog.v(TAG, "Reparenting from task=" + affinityTask + ":" |
| 2016 | + start + "-" + i + " to task=" + task + ":" + taskInsertionPoint); |
| 2017 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2018 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2019 | p.setTask(task, null, false); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2020 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2021 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2022 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + p |
| 2023 | + " to stack at " + task, |
| 2024 | new RuntimeException("here").fillInStackTrace()); |
| 2025 | if (DEBUG_TASKS) Slog.v(TAG, "Pulling activity " + p + " from " + srcPos |
| 2026 | + " in to resetting task " + task); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2027 | mWindowManager.setAppGroupId(p.appToken, taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2028 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2029 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2030 | if (VALIDATE_TOKENS) { |
| 2031 | validateAppTokensLocked(); |
| 2032 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2033 | |
| 2034 | // Now we've moved it in to place... but what if this is |
| 2035 | // a singleTop activity and we have put it on top of another |
| 2036 | // instance of the same activity? Then we drop the instance |
| 2037 | // below so it remains singleTop. |
| 2038 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2039 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2040 | int targetNdx = taskActivities.indexOf(target); |
| 2041 | if (targetNdx > 0) { |
| 2042 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2043 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2044 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2045 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2046 | } |
| 2047 | } |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | replyChainEnd = -1; |
| 2052 | } |
| 2053 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2054 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2055 | } |
| 2056 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2057 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2058 | ActivityRecord newActivity) { |
| 2059 | boolean forceReset = |
| 2060 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2061 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2062 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2063 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2064 | forceReset = true; |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | final TaskRecord task = taskTop.task; |
| 2069 | |
| 2070 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2071 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2072 | boolean taskFound = false; |
| 2073 | |
| 2074 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2075 | ActivityOptions topOptions = null; |
| 2076 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2077 | // Preserve the location for reparenting in the new task. |
| 2078 | int reparentInsertionPoint = -1; |
| 2079 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2080 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2081 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2082 | |
| 2083 | if (targetTask == task) { |
| 2084 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2085 | taskFound = true; |
| 2086 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2087 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2088 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2092 | int taskNdx = mTaskHistory.indexOf(task); |
| 2093 | do { |
| 2094 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2095 | } while (taskTop == null && taskNdx >= 0); |
| 2096 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2097 | if (topOptions != null) { |
| 2098 | // If we got some ActivityOptions from an activity on top that |
| 2099 | // was removed from the task, propagate them to the new real top. |
| 2100 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2101 | taskTop.updateOptionsLocked(topOptions); |
| 2102 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2103 | topOptions.abort(); |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | return taskTop; |
| 2108 | } |
| 2109 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2110 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2111 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2112 | |
| 2113 | if (callingUid > 0) { |
| 2114 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 2115 | data, r.getUriPermissionsLocked()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2119 | + " : who=" + resultWho + " req=" + requestCode |
| 2120 | + " res=" + resultCode + " data=" + data); |
| 2121 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2122 | try { |
| 2123 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2124 | list.add(new ResultInfo(resultWho, requestCode, |
| 2125 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2126 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2127 | return; |
| 2128 | } catch (Exception e) { |
| 2129 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2134 | } |
| 2135 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2136 | final void stopActivityLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2137 | if (DEBUG_SWITCH) Slog.d(TAG, "Stopping: " + r); |
| 2138 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2139 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2140 | if (!r.finishing) { |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2141 | if (!mService.mSleeping) { |
| 2142 | if (DEBUG_STATES) { |
| 2143 | Slog.d(TAG, "no-history finish of " + r); |
| 2144 | } |
| 2145 | requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2146 | "no-history", false); |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2147 | } else { |
| 2148 | if (DEBUG_STATES) Slog.d(TAG, "Not finishing noHistory " + r |
| 2149 | + " on stop because we're just sleeping"); |
| 2150 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2151 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2155 | if (mStackSupervisor.isFrontStack(this)) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2156 | if (mService.mFocusedActivity == r) { |
| 2157 | mService.setFocusedActivityLocked(topRunningActivityLocked(null)); |
| 2158 | } |
| 2159 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2160 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2161 | try { |
| 2162 | r.stopped = false; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2163 | if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r |
| 2164 | + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2165 | r.state = ActivityState.STOPPING; |
| 2166 | if (DEBUG_VISBILITY) Slog.v( |
| 2167 | TAG, "Stopping visible=" + r.visible + " for " + r); |
| 2168 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2169 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2170 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2171 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 2172 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2173 | r.setSleeping(true); |
| 2174 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2175 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2176 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2177 | } catch (Exception e) { |
| 2178 | // Maybe just ignore exceptions here... if the process |
| 2179 | // has crashed, our death notification will clean things |
| 2180 | // up. |
| 2181 | Slog.w(TAG, "Exception thrown during pause", e); |
| 2182 | // Just in case, assume it to be stopped. |
| 2183 | r.stopped = true; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2184 | if (DEBUG_STATES) Slog.v(TAG, "Stop failed; moving to STOPPED: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2185 | r.state = ActivityState.STOPPED; |
| 2186 | if (r.configDestroy) { |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2187 | destroyActivityLocked(r, true, false, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2188 | } |
| 2189 | } |
| 2190 | } |
| 2191 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 2192 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2193 | /** |
| 2194 | * @return Returns true if the activity is being finished, false if for |
| 2195 | * some reason it is being left as-is. |
| 2196 | */ |
| 2197 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2198 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2199 | ActivityRecord r = isInStackLocked(token); |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2200 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v( |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2201 | TAG, "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2202 | + ", result=" + resultCode + ", data=" + resultData |
| 2203 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2204 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2205 | return false; |
| 2206 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2207 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2208 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2209 | return true; |
| 2210 | } |
| 2211 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2212 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2213 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2214 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2215 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2216 | ActivityRecord r = activities.get(activityNdx); |
| 2217 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 2218 | if ((r.resultWho == null && resultWho == null) || |
| 2219 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 2220 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 2221 | false); |
| 2222 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2223 | } |
| 2224 | } |
| 2225 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2226 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2227 | } |
| 2228 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2229 | final void finishTopRunningActivityLocked(ProcessRecord app) { |
| 2230 | ActivityRecord r = topRunningActivityLocked(null); |
| 2231 | if (r != null && r.app == app) { |
| 2232 | // If the top running activity is from this crashing |
| 2233 | // process, then terminate it to avoid getting in a loop. |
| 2234 | Slog.w(TAG, " Force finishing activity " |
| 2235 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2236 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 2237 | int activityNdx = r.task.mActivities.indexOf(r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2238 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2239 | // Also terminate any activities below it that aren't yet |
| 2240 | // stopped, to avoid a situation where one will get |
| 2241 | // re-start our crashing activity once it gets resumed again. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2242 | --activityNdx; |
| 2243 | if (activityNdx < 0) { |
| 2244 | do { |
| 2245 | --taskNdx; |
| 2246 | if (taskNdx < 0) { |
| 2247 | break; |
| 2248 | } |
| 2249 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 2250 | } while (activityNdx < 0); |
| 2251 | } |
| 2252 | if (activityNdx >= 0) { |
| 2253 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2254 | if (r.state == ActivityState.RESUMED |
| 2255 | || r.state == ActivityState.PAUSING |
| 2256 | || r.state == ActivityState.PAUSED) { |
Craig Mautner | e428a7f | 2013-08-17 17:04:56 -0700 | [diff] [blame] | 2257 | if (!r.isHomeActivity() || !mService.mHomeProcess.contains(r.app)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2258 | Slog.w(TAG, " Force finishing activity " |
| 2259 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2260 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2261 | } |
| 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | } |
| 2266 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2267 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2268 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 2269 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 2270 | ActivityRecord cur = activities.get(index); |
| 2271 | if (!Objects.equal(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2272 | break; |
| 2273 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2274 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2275 | } |
| 2276 | return true; |
| 2277 | } |
| 2278 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2279 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 2280 | // send the result |
| 2281 | ActivityRecord resultTo = r.resultTo; |
| 2282 | if (resultTo != null) { |
| 2283 | if (DEBUG_RESULTS) Slog.v(TAG, "Adding result to " + resultTo |
| 2284 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 2285 | + " res=" + resultCode + " data=" + resultData); |
| 2286 | if (r.info.applicationInfo.uid > 0) { |
| 2287 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 2288 | resultTo.packageName, resultData, |
| 2289 | resultTo.getUriPermissionsLocked()); |
| 2290 | } |
| 2291 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 2292 | resultData); |
| 2293 | r.resultTo = null; |
| 2294 | } |
| 2295 | else if (DEBUG_RESULTS) Slog.v(TAG, "No result destination from " + r); |
| 2296 | |
| 2297 | // Make sure this HistoryRecord is not holding on to other resources, |
| 2298 | // because clients have remote IPC references to this object so we |
| 2299 | // can't assume that will go away and want to avoid circular IPC refs. |
| 2300 | r.results = null; |
| 2301 | r.pendingResults = null; |
| 2302 | r.newIntents = null; |
| 2303 | r.icicle = null; |
| 2304 | } |
| 2305 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2306 | /** |
| 2307 | * @return Returns true if this activity has been removed from the history |
| 2308 | * list, or false if it is still in the list and will be removed later. |
| 2309 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2310 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 2311 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2312 | if (r.finishing) { |
| 2313 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 2314 | return false; |
| 2315 | } |
| 2316 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2317 | r.makeFinishing(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2318 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2319 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2320 | r.task.taskId, r.shortComponentName, reason); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2321 | final ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 2322 | final int index = activities.indexOf(r); |
| 2323 | if (index < (activities.size() - 1)) { |
| 2324 | ActivityRecord next = activities.get(index+1); |
| 2325 | if (r.frontOfTask) { |
| 2326 | // The next activity is now the front of the task. |
| 2327 | next.frontOfTask = true; |
| 2328 | } |
| 2329 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
| 2330 | // If the caller asked that this activity (and all above it) |
| 2331 | // be cleared when the task is reset, don't lose that information, |
| 2332 | // but propagate it up to the next activity. |
| 2333 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2338 | if (mStackSupervisor.isFrontStack(this)) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2339 | if (mService.mFocusedActivity == r) { |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2340 | mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2341 | } |
| 2342 | } |
| 2343 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2344 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2345 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2346 | if (!mService.mPendingThumbnails.isEmpty()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2347 | // There are clients waiting to receive thumbnails so, in case |
| 2348 | // this is an activity that someone is waiting for, add it |
| 2349 | // to the pending list so we can correctly update the clients. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2350 | mStackSupervisor.mCancelledThumbnails.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2353 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2354 | boolean endTask = index <= 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2355 | if (DEBUG_TRANSITION) Slog.v(TAG, |
| 2356 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2357 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2358 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 2359 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2360 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2361 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2362 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2363 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2364 | if (mPausingActivity == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2365 | if (DEBUG_PAUSE) Slog.v(TAG, "Finish needs to pause: " + r); |
| 2366 | if (DEBUG_USER_LEAVING) Slog.v(TAG, "finish() => pause with userLeaving=false"); |
| 2367 | startPausingLocked(false, false); |
| 2368 | } |
| 2369 | |
| 2370 | } else if (r.state != ActivityState.PAUSING) { |
| 2371 | // If the activity is PAUSING, we will complete the finish once |
| 2372 | // it is done pausing; else we can just directly finish it here. |
| 2373 | if (DEBUG_PAUSE) Slog.v(TAG, "Finish not pausing: " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2374 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2375 | } else { |
| 2376 | if (DEBUG_PAUSE) Slog.v(TAG, "Finish waiting for pause of: " + r); |
| 2377 | } |
| 2378 | |
| 2379 | return false; |
| 2380 | } |
| 2381 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2382 | static final int FINISH_IMMEDIATELY = 0; |
| 2383 | static final int FINISH_AFTER_PAUSE = 1; |
| 2384 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2385 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2386 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2387 | // First things first: if this activity is currently visible, |
| 2388 | // and the resumed activity is not yet visible, then hold off on |
| 2389 | // finishing until the resumed one becomes visible. |
| 2390 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2391 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 2392 | mStackSupervisor.mStoppingActivities.add(r); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2393 | if (mStackSupervisor.mStoppingActivities.size() > 3 |
| 2394 | || r.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2395 | // If we already have a few activities waiting to stop, |
| 2396 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2397 | // them out. Or if r is the last of activity of the last task the stack |
| 2398 | // will be empty and must be cleared immediately. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2399 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2400 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2401 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2402 | } |
| 2403 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2404 | if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r |
| 2405 | + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2406 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2407 | if (oomAdj) { |
| 2408 | mService.updateOomAdjLocked(); |
| 2409 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2410 | return r; |
| 2411 | } |
| 2412 | |
| 2413 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2414 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2415 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2416 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2417 | if (mResumedActivity == r) { |
| 2418 | mResumedActivity = null; |
| 2419 | } |
| 2420 | final ActivityState prevState = r.state; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2421 | if (DEBUG_STATES) Slog.v(TAG, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2422 | r.state = ActivityState.FINISHING; |
| 2423 | |
| 2424 | if (mode == FINISH_IMMEDIATELY |
| 2425 | || prevState == ActivityState.STOPPED |
| 2426 | || prevState == ActivityState.INITIALIZING) { |
| 2427 | // If this activity is already stopped, we can just finish |
| 2428 | // it right now. |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2429 | boolean activityRemoved = destroyActivityLocked(r, true, |
| 2430 | oomAdj, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2431 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2432 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2433 | } |
| 2434 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2435 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2436 | |
| 2437 | // Need to go through the full pause cycle to get this |
| 2438 | // activity into the stopped state and then finish it. |
| 2439 | if (localLOGV) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2440 | mStackSupervisor.mFinishingActivities.add(r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2441 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2442 | return r; |
| 2443 | } |
| 2444 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2445 | final boolean navigateUpToLocked(IBinder token, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2446 | Intent resultData) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2447 | final ActivityRecord srec = ActivityRecord.forToken(token); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2448 | final TaskRecord task = srec.task; |
| 2449 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2450 | final int start = activities.indexOf(srec); |
| 2451 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2455 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2456 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2457 | final ComponentName dest = destIntent.getComponent(); |
| 2458 | if (start > 0 && dest != null) { |
| 2459 | for (int i = finishTo; i >= 0; i--) { |
| 2460 | ActivityRecord r = activities.get(i); |
| 2461 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2462 | r.info.name.equals(dest.getClassName())) { |
| 2463 | finishTo = i; |
| 2464 | parent = r; |
| 2465 | foundParentInTask = true; |
| 2466 | break; |
| 2467 | } |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | IActivityController controller = mService.mController; |
| 2472 | if (controller != null) { |
| 2473 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 2474 | if (next != null) { |
| 2475 | // ask watcher if this is allowed |
| 2476 | boolean resumeOK = true; |
| 2477 | try { |
| 2478 | resumeOK = controller.activityResuming(next.packageName); |
| 2479 | } catch (RemoteException e) { |
| 2480 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 2481 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | if (!resumeOK) { |
| 2485 | return false; |
| 2486 | } |
| 2487 | } |
| 2488 | } |
| 2489 | final long origId = Binder.clearCallingIdentity(); |
| 2490 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2491 | ActivityRecord r = activities.get(i); |
| 2492 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2493 | // Only return the supplied result for the first activity finished |
| 2494 | resultCode = Activity.RESULT_CANCELED; |
| 2495 | resultData = null; |
| 2496 | } |
| 2497 | |
| 2498 | if (parent != null && foundParentInTask) { |
| 2499 | final int parentLaunchMode = parent.info.launchMode; |
| 2500 | final int destIntentFlags = destIntent.getFlags(); |
| 2501 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 2502 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 2503 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 2504 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
| 2505 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent); |
| 2506 | } else { |
| 2507 | try { |
| 2508 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 2509 | destIntent.getComponent(), 0, srec.userId); |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 2510 | int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2511 | null, aInfo, parent.appToken, null, |
| 2512 | 0, -1, parent.launchedFromUid, parent.launchedFromPackage, |
| 2513 | 0, null, true, null); |
| 2514 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 2515 | } catch (RemoteException e) { |
| 2516 | foundParentInTask = false; |
| 2517 | } |
| 2518 | requestFinishActivityLocked(parent.appToken, resultCode, |
| 2519 | resultData, "navigate-up", true); |
| 2520 | } |
| 2521 | } |
| 2522 | Binder.restoreCallingIdentity(origId); |
| 2523 | return foundParentInTask; |
| 2524 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2525 | /** |
| 2526 | * Perform the common clean-up of an activity record. This is called both |
| 2527 | * as part of destroyActivityLocked() (when destroying the client-side |
| 2528 | * representation) and cleaning things up as a result of its hosting |
| 2529 | * processing going away, in which case there is no remaining client-side |
| 2530 | * state to destroy so only the cleanup here is needed. |
| 2531 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2532 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 2533 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2534 | if (mResumedActivity == r) { |
| 2535 | mResumedActivity = null; |
| 2536 | } |
| 2537 | if (mService.mFocusedActivity == r) { |
| 2538 | mService.mFocusedActivity = null; |
| 2539 | } |
| 2540 | |
| 2541 | r.configDestroy = false; |
| 2542 | r.frozenBeforeDestroy = false; |
| 2543 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2544 | if (setState) { |
| 2545 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (cleaning up)"); |
| 2546 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 2547 | 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] | 2548 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2551 | // Make sure this record is no longer in the pending finishes list. |
| 2552 | // This could happen, for example, if we are trimming activities |
| 2553 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2554 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2555 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2556 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2557 | // Remove any pending results. |
| 2558 | if (r.finishing && r.pendingResults != null) { |
| 2559 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 2560 | PendingIntentRecord rec = apr.get(); |
| 2561 | if (rec != null) { |
| 2562 | mService.cancelIntentSenderLocked(rec, false); |
| 2563 | } |
| 2564 | } |
| 2565 | r.pendingResults = null; |
| 2566 | } |
| 2567 | |
| 2568 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2569 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2572 | if (!mService.mPendingThumbnails.isEmpty()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2573 | // There are clients waiting to receive thumbnails so, in case |
| 2574 | // this is an activity that someone is waiting for, add it |
| 2575 | // to the pending list so we can correctly update the clients. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2576 | mStackSupervisor.mCancelledThumbnails.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2580 | removeTimeoutsForActivityLocked(r); |
| 2581 | } |
| 2582 | |
| 2583 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2584 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2585 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2586 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2587 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2588 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2591 | final void removeActivityFromHistoryLocked(ActivityRecord r) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2592 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
| 2593 | r.makeFinishing(); |
| 2594 | if (DEBUG_ADD_REMOVE) { |
| 2595 | RuntimeException here = new RuntimeException("here"); |
| 2596 | here.fillInStackTrace(); |
| 2597 | Slog.i(TAG, "Removing activity " + r + " from stack"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2598 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2599 | final TaskRecord task = r.task; |
| 2600 | if (task != null && task.removeActivity(r)) { |
Craig Mautner | a9a3fb1 | 2013-04-18 10:01:00 -0700 | [diff] [blame] | 2601 | if (DEBUG_STACK) Slog.i(TAG, |
| 2602 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2603 | mStackSupervisor.removeTask(task); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 2604 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2605 | r.takeFromHistory(); |
| 2606 | removeTimeoutsForActivityLocked(r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2607 | 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] | 2608 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 2609 | 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] | 2610 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2611 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2612 | if (VALIDATE_TOKENS) { |
| 2613 | validateAppTokensLocked(); |
| 2614 | } |
| 2615 | cleanUpActivityServicesLocked(r); |
| 2616 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2617 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2618 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2619 | /** |
| 2620 | * Perform clean-up of service connections in an activity record. |
| 2621 | */ |
| 2622 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 2623 | // Throw away any services that have been bound by this activity. |
| 2624 | if (r.connections != null) { |
| 2625 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 2626 | while (it.hasNext()) { |
| 2627 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 2628 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2629 | } |
| 2630 | r.connections = null; |
| 2631 | } |
| 2632 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 2633 | |
| 2634 | final void scheduleDestroyActivities(ProcessRecord owner, boolean oomAdj, String reason) { |
| 2635 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
| 2636 | msg.obj = new ScheduleDestroyArgs(owner, oomAdj, reason); |
| 2637 | mHandler.sendMessage(msg); |
| 2638 | } |
| 2639 | |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2640 | final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 2641 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2642 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2643 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2644 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2645 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2646 | final ActivityRecord r = activities.get(activityNdx); |
| 2647 | if (r.finishing) { |
| 2648 | continue; |
| 2649 | } |
| 2650 | if (r.fullscreen) { |
| 2651 | lastIsOpaque = true; |
| 2652 | } |
| 2653 | if (owner != null && r.app != owner) { |
| 2654 | continue; |
| 2655 | } |
| 2656 | if (!lastIsOpaque) { |
| 2657 | continue; |
| 2658 | } |
| 2659 | // We can destroy this one if we have its icicle saved and |
| 2660 | // it is not in the process of pausing/stopping/finishing. |
| 2661 | if (r.app != null && r != mResumedActivity && r != mPausingActivity |
| 2662 | && r.haveState && !r.visible && r.stopped |
| 2663 | && r.state != ActivityState.DESTROYING |
| 2664 | && r.state != ActivityState.DESTROYED) { |
| 2665 | if (DEBUG_SWITCH) Slog.v(TAG, "Destroying " + r + " in state " + r.state |
| 2666 | + " resumed=" + mResumedActivity |
| 2667 | + " pausing=" + mPausingActivity); |
| 2668 | if (destroyActivityLocked(r, true, oomAdj, reason)) { |
| 2669 | activityRemoved = true; |
| 2670 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2671 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2672 | } |
| 2673 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2674 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2675 | mStackSupervisor.resumeTopActivitiesLocked(); |
| 2676 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2677 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2680 | /** |
| 2681 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 2682 | * called both when actually finishing an activity, or when performing |
| 2683 | * a configuration switch where we destroy the current client-side object |
| 2684 | * but then create a new client-side object for this same HistoryRecord. |
| 2685 | */ |
| 2686 | final boolean destroyActivityLocked(ActivityRecord r, |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2687 | boolean removeFromApp, boolean oomAdj, String reason) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2688 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v( |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 2689 | TAG, "Removing activity from " + reason + ": token=" + r |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2690 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
| 2691 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2692 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2693 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2694 | |
| 2695 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2696 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2697 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2698 | |
| 2699 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2700 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2701 | if (hadApp) { |
| 2702 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2703 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2704 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 2705 | mService.mHeavyWeightProcess = null; |
| 2706 | mService.mHandler.sendEmptyMessage( |
| 2707 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 2708 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2709 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2710 | // No longer have activities, so update oom adj. |
| 2711 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2716 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2717 | try { |
| 2718 | if (DEBUG_SWITCH) Slog.i(TAG, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2719 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2720 | r.configChangeFlags); |
| 2721 | } catch (Exception e) { |
| 2722 | // We can just ignore exceptions here... if the process |
| 2723 | // has crashed, our death notification will clean things |
| 2724 | // up. |
| 2725 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 2726 | if (r.finishing) { |
| 2727 | removeActivityFromHistoryLocked(r); |
| 2728 | removedFromHistory = true; |
| 2729 | skipDestroy = true; |
| 2730 | } |
| 2731 | } |
| 2732 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2733 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2734 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2735 | // If the activity is finishing, we need to wait on removing it |
| 2736 | // from the list to give it a chance to do its cleanup. During |
| 2737 | // that time it may make calls back with its token so we need to |
| 2738 | // be able to find it on the list and so we don't want to remove |
| 2739 | // it from the list yet. Otherwise, we can just immediately put |
| 2740 | // it in the destroyed state since we are not removing it from the |
| 2741 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2742 | if (r.finishing && !skipDestroy) { |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2743 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYING: " + r |
| 2744 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2745 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2746 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2747 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 2748 | } else { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2749 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2750 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 2751 | 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] | 2752 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2753 | } |
| 2754 | } else { |
| 2755 | // remove this record from the history. |
| 2756 | if (r.finishing) { |
| 2757 | removeActivityFromHistoryLocked(r); |
| 2758 | removedFromHistory = true; |
| 2759 | } else { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2760 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (no app)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2761 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 2762 | 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] | 2763 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2764 | } |
| 2765 | } |
| 2766 | |
| 2767 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2768 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2769 | if (!mLRUActivities.remove(r) && hadApp) { |
| 2770 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 2771 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2772 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2773 | return removedFromHistory; |
| 2774 | } |
| 2775 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2776 | final void activityDestroyedLocked(IBinder token) { |
| 2777 | final long origId = Binder.clearCallingIdentity(); |
| 2778 | try { |
| 2779 | ActivityRecord r = ActivityRecord.forToken(token); |
| 2780 | if (r != null) { |
| 2781 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2782 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2783 | |
| 2784 | if (isInStackLocked(token) != null) { |
| 2785 | if (r.state == ActivityState.DESTROYING) { |
| 2786 | cleanUpActivityLocked(r, true, false); |
| 2787 | removeActivityFromHistoryLocked(r); |
| 2788 | } |
| 2789 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2790 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2793 | } |
| 2794 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2795 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2796 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 2797 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2798 | int i = list.size(); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2799 | if (DEBUG_CLEANUP) Slog.v( |
| 2800 | TAG, "Removing app " + app + " from list " + listName |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2801 | + " with " + i + " entries"); |
| 2802 | while (i > 0) { |
| 2803 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2804 | ActivityRecord r = list.get(i); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2805 | if (DEBUG_CLEANUP) Slog.v(TAG, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2806 | if (r.app == app) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2807 | if (DEBUG_CLEANUP) Slog.v(TAG, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2808 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2809 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2810 | } |
| 2811 | } |
| 2812 | } |
| 2813 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2814 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 2815 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2816 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 2817 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2818 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 2819 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2820 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2821 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2822 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 2823 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2824 | |
| 2825 | boolean hasVisibleActivities = false; |
| 2826 | |
| 2827 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2828 | int i = numActivities(); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2829 | if (DEBUG_CLEANUP) Slog.v( |
| 2830 | TAG, "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2831 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2832 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2833 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2834 | final ActivityRecord r = activities.get(activityNdx); |
| 2835 | --i; |
| 2836 | if (DEBUG_CLEANUP) Slog.v( |
| 2837 | TAG, "Record #" + i + " " + r + ": app=" + r.app); |
| 2838 | if (r.app == app) { |
| 2839 | boolean remove; |
| 2840 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 2841 | // Don't currently have state for the activity, or |
| 2842 | // it is finishing -- always remove it. |
| 2843 | remove = true; |
| 2844 | } else if (r.launchCount > 2 && |
| 2845 | r.lastLaunchTime > (SystemClock.uptimeMillis()-60000)) { |
| 2846 | // We have launched this activity too many times since it was |
| 2847 | // able to run, so give up and remove it. |
| 2848 | remove = true; |
| 2849 | } else { |
| 2850 | // The process may be gone, but the activity lives on! |
| 2851 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2852 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2853 | if (remove) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2854 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2855 | RuntimeException here = new RuntimeException("here"); |
| 2856 | here.fillInStackTrace(); |
| 2857 | Slog.i(TAG, "Removing activity " + r + " from stack at " + i |
| 2858 | + ": haveState=" + r.haveState |
| 2859 | + " stateNotNeeded=" + r.stateNotNeeded |
| 2860 | + " finishing=" + r.finishing |
| 2861 | + " state=" + r.state, here); |
| 2862 | } |
| 2863 | if (!r.finishing) { |
| 2864 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 2865 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 2866 | r.userId, System.identityHashCode(r), |
| 2867 | r.task.taskId, r.shortComponentName, |
| 2868 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 2869 | if (r.state == ActivityState.RESUMED) { |
| 2870 | mService.updateUsageStats(r, false); |
| 2871 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2872 | } |
| 2873 | removeActivityFromHistoryLocked(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2874 | |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2875 | } else { |
| 2876 | // We have the current state for this activity, so |
| 2877 | // it can be restarted later when needed. |
| 2878 | if (localLOGV) Slog.v( |
| 2879 | TAG, "Keeping entry, setting app to null"); |
| 2880 | if (r.visible) { |
| 2881 | hasVisibleActivities = true; |
| 2882 | } |
| 2883 | if (DEBUG_APP) Slog.v(TAG, "Clearing app during removeHistory for activity " |
| 2884 | + r); |
| 2885 | r.app = null; |
| 2886 | r.nowVisible = false; |
| 2887 | if (!r.haveState) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2888 | if (DEBUG_SAVED_STATE) Slog.i(TAG, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2889 | "App died, clearing saved state of " + r); |
| 2890 | r.icicle = null; |
| 2891 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2892 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2893 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2894 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2895 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2900 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2901 | |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 2902 | final void updateTransitLocked(int transit, Bundle options) { |
| 2903 | if (options != null) { |
| 2904 | ActivityRecord r = topRunningActivityLocked(null); |
| 2905 | if (r != null && r.state != ActivityState.RESUMED) { |
| 2906 | r.updateOptionsLocked(options); |
| 2907 | } else { |
| 2908 | ActivityOptions.abort(options); |
| 2909 | } |
| 2910 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2911 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 2912 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2913 | |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 2914 | void moveHomeTaskToTop() { |
| 2915 | final int top = mTaskHistory.size() - 1; |
| 2916 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 2917 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2918 | if (task.isHomeTask()) { |
| 2919 | mTaskHistory.remove(taskNdx); |
| 2920 | mTaskHistory.add(top, task); |
| 2921 | mWindowManager.moveTaskToTop(task.taskId); |
| 2922 | return; |
| 2923 | } |
| 2924 | } |
| 2925 | } |
| 2926 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 2927 | final boolean findTaskToMoveToFrontLocked(int taskId, int flags, Bundle options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2928 | final TaskRecord task = taskForIdLocked(taskId); |
| 2929 | if (task != null) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 2930 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2931 | mStackSupervisor.mUserLeaving = true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 2932 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 2933 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) { |
| 2934 | // Caller wants the home activity moved with it. To accomplish this, |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 2935 | // we'll just indicate that this task returns to the home task. |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 2936 | task.mOnTopOfHome = true; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 2937 | } |
| 2938 | moveTaskToFrontLocked(task, null, options); |
| 2939 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 2940 | } |
| 2941 | return false; |
| 2942 | } |
| 2943 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2944 | final void moveTaskToFrontLocked(TaskRecord tr, ActivityRecord reason, Bundle options) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2945 | if (DEBUG_SWITCH) Slog.v(TAG, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2946 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2947 | final int numTasks = mTaskHistory.size(); |
| 2948 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 2949 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2950 | // nothing to do! |
| 2951 | if (reason != null && |
| 2952 | (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
| 2953 | ActivityOptions.abort(options); |
| 2954 | } else { |
| 2955 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 2956 | } |
| 2957 | return; |
| 2958 | } |
| 2959 | |
Craig Mautner | fb1e20d | 2013-06-23 21:24:13 -0700 | [diff] [blame] | 2960 | mStackSupervisor.moveHomeStack(isHomeStack()); |
| 2961 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2962 | // Shift all activities with this task up to the top |
| 2963 | // of the stack, keeping them in the same internal order. |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2964 | insertTaskAtTop(tr); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2965 | |
| 2966 | if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to front transition: task=" + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2967 | if (reason != null && |
| 2968 | (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2969 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2970 | ActivityRecord r = topRunningActivityLocked(null); |
| 2971 | if (r != null) { |
| 2972 | mNoAnimActivities.add(r); |
| 2973 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2974 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2975 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2976 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2977 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 2978 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2979 | mWindowManager.moveTaskToTop(tr.taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2980 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2981 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2982 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2983 | |
| 2984 | if (VALIDATE_TOKENS) { |
| 2985 | validateAppTokensLocked(); |
| 2986 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2990 | * Worker method for rearranging history stack. Implements the function of moving all |
| 2991 | * 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] | 2992 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2993 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2994 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 2995 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2996 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 2997 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2998 | * @return Returns true if the move completed, false if not. |
| 2999 | */ |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3000 | final boolean moveTaskToBackLocked(int taskId, ActivityRecord reason) { |
| 3001 | Slog.i(TAG, "moveTaskToBack: " + taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3002 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3003 | // If we have a watcher, preflight the move before committing to it. First check |
| 3004 | // for *other* available tasks, but if none are available, then try again allowing the |
| 3005 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3006 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3007 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3008 | if (next == null) { |
| 3009 | next = topRunningActivityLocked(null, 0); |
| 3010 | } |
| 3011 | if (next != null) { |
| 3012 | // ask watcher if this is allowed |
| 3013 | boolean moveOK = true; |
| 3014 | try { |
| 3015 | moveOK = mService.mController.activityResuming(next.packageName); |
| 3016 | } catch (RemoteException e) { |
| 3017 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3018 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3019 | } |
| 3020 | if (!moveOK) { |
| 3021 | return false; |
| 3022 | } |
| 3023 | } |
| 3024 | } |
| 3025 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3026 | if (DEBUG_TRANSITION) Slog.v(TAG, |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3027 | "Prepare to back transition: task=" + taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3028 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3029 | final TaskRecord tr = taskForIdLocked(taskId); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3030 | if (tr == null) { |
| 3031 | return false; |
| 3032 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3033 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3034 | mTaskHistory.remove(tr); |
| 3035 | mTaskHistory.add(0, tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3036 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3037 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 3038 | // We make sure here that some activity in the stack will launch home. |
| 3039 | ActivityRecord lastActivity = null; |
| 3040 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3041 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 3042 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3043 | if (task.mOnTopOfHome) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3044 | break; |
| 3045 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3046 | if (taskNdx == 1) { |
| 3047 | // Set the last task before tr to go to home. |
| 3048 | task.mOnTopOfHome = true; |
| 3049 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3050 | } |
| 3051 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3052 | if (reason != null && |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3053 | (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
| 3054 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3055 | ActivityRecord r = topRunningActivityLocked(null); |
| 3056 | if (r != null) { |
| 3057 | mNoAnimActivities.add(r); |
| 3058 | } |
| 3059 | } else { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3060 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3061 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3062 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3063 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3064 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3065 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3068 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
| 3069 | if (task == tr && task.mOnTopOfHome || numTasks <= 1) { |
| 3070 | task.mOnTopOfHome = false; |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 3071 | return mStackSupervisor.resumeHomeActivity(null); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3074 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3075 | return true; |
| 3076 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 3077 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3078 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3079 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3080 | final Uri data = r.intent.getData(); |
| 3081 | final String strData = data != null ? data.toSafeString() : null; |
| 3082 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3083 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3084 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3085 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3086 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | /** |
| 3090 | * Make sure the given activity matches the current configuration. Returns |
| 3091 | * false if the activity had to be destroyed. Returns true if the |
| 3092 | * configuration is the same, or the activity will remain running as-is |
| 3093 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 3094 | * correct configuration and all other bookkeeping is handled. |
| 3095 | */ |
| 3096 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, |
| 3097 | int globalChanges) { |
| 3098 | if (mConfigWillChange) { |
| 3099 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3100 | "Skipping config check (will change): " + r); |
| 3101 | return true; |
| 3102 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3103 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3104 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3105 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3106 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3107 | // Short circuit: if the two configurations are the exact same |
| 3108 | // object (the common case), then there is nothing to do. |
| 3109 | Configuration newConfig = mService.mConfiguration; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3110 | if (r.configuration == newConfig && !r.forceNewConfig) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3111 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3112 | "Configuration unchanged in " + r); |
| 3113 | return true; |
| 3114 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3115 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3116 | // We don't worry about activities that are finishing. |
| 3117 | if (r.finishing) { |
| 3118 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3119 | "Configuration doesn't matter in finishing " + r); |
| 3120 | r.stopFreezingScreenLocked(false); |
| 3121 | return true; |
| 3122 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3123 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3124 | // Okay we now are going to make this activity have the new config. |
| 3125 | // But then we need to figure out how it needs to deal with that. |
| 3126 | Configuration oldConfig = r.configuration; |
| 3127 | r.configuration = newConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3128 | |
| 3129 | // Determine what has changed. May be nothing, if this is a config |
| 3130 | // that has come back from the app after going idle. In that case |
| 3131 | // we just want to leave the official config object now in the |
| 3132 | // activity and do nothing else. |
| 3133 | final int changes = oldConfig.diff(newConfig); |
| 3134 | if (changes == 0 && !r.forceNewConfig) { |
| 3135 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3136 | "Configuration no differences in " + r); |
| 3137 | return true; |
| 3138 | } |
| 3139 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3140 | // If the activity isn't currently running, just leave the new |
| 3141 | // configuration and it will pick that up next time it starts. |
| 3142 | if (r.app == null || r.app.thread == null) { |
| 3143 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3144 | "Configuration doesn't matter not running " + r); |
| 3145 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3146 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3147 | return true; |
| 3148 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3149 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3150 | // Figure out how to handle the changes between the configurations. |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3151 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) { |
| 3152 | Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x" |
| 3153 | + Integer.toHexString(changes) + ", handles=0x" |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 3154 | + Integer.toHexString(r.info.getRealConfigChanged()) |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3155 | + ", newConfig=" + newConfig); |
| 3156 | } |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 3157 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3158 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 3159 | r.configChangeFlags |= changes; |
| 3160 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3161 | r.forceNewConfig = false; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3162 | if (r.app == null || r.app.thread == null) { |
| 3163 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3164 | "Config is destroying non-running " + r); |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3165 | destroyActivityLocked(r, true, false, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3166 | } else if (r.state == ActivityState.PAUSING) { |
| 3167 | // A little annoying: we are waiting for this activity to |
| 3168 | // finish pausing. Let's not do anything now, but just |
| 3169 | // flag that it needs to be restarted when done pausing. |
| 3170 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3171 | "Config is skipping already pausing " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3172 | r.configDestroy = true; |
| 3173 | return true; |
| 3174 | } else if (r.state == ActivityState.RESUMED) { |
| 3175 | // Try to optimize this case: the configuration is changing |
| 3176 | // and we need to restart the top, resumed activity. |
| 3177 | // Instead of doing the normal handshaking, just say |
| 3178 | // "restart!". |
| 3179 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3180 | "Config is relaunching resumed " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3181 | relaunchActivityLocked(r, r.configChangeFlags, true); |
| 3182 | r.configChangeFlags = 0; |
| 3183 | } else { |
| 3184 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3185 | "Config is relaunching non-resumed " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3186 | relaunchActivityLocked(r, r.configChangeFlags, false); |
| 3187 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3188 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3189 | |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3190 | // All done... tell the caller we weren't able to keep this |
| 3191 | // activity around. |
| 3192 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3193 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3194 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3195 | // Default case: the activity can handle this new configuration, so |
| 3196 | // hand it over. Note that we don't need to give it the new |
| 3197 | // configuration, since we always send configuration changes to all |
| 3198 | // process when they happen so it can just use whatever configuration |
| 3199 | // it last got. |
| 3200 | if (r.app != null && r.app.thread != null) { |
| 3201 | try { |
| 3202 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3203 | r.app.thread.scheduleActivityConfigurationChanged(r.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3204 | } catch (RemoteException e) { |
| 3205 | // If process died, whatever. |
| 3206 | } |
| 3207 | } |
| 3208 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3209 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3210 | return true; |
| 3211 | } |
| 3212 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3213 | private boolean relaunchActivityLocked(ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3214 | int changes, boolean andResume) { |
| 3215 | List<ResultInfo> results = null; |
| 3216 | List<Intent> newIntents = null; |
| 3217 | if (andResume) { |
| 3218 | results = r.results; |
| 3219 | newIntents = r.newIntents; |
| 3220 | } |
| 3221 | if (DEBUG_SWITCH) Slog.v(TAG, "Relaunching: " + r |
| 3222 | + " with results=" + results + " newIntents=" + newIntents |
| 3223 | + " andResume=" + andResume); |
| 3224 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3225 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3226 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3227 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3228 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3229 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3230 | try { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3231 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, |
| 3232 | (andResume ? "Relaunching to RESUMED " : "Relaunching to PAUSED ") |
| 3233 | + r); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3234 | r.forceNewConfig = false; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3235 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, |
Dianne Hackborn | 813075a6 | 2011-11-14 17:45:19 -0800 | [diff] [blame] | 3236 | changes, !andResume, new Configuration(mService.mConfiguration)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3237 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 3238 | // the caller will only pass in 'andResume' if this activity is |
| 3239 | // currently resumed, which implies we aren't sleeping. |
| 3240 | } catch (RemoteException e) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3241 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | if (andResume) { |
| 3245 | r.results = null; |
| 3246 | r.newIntents = null; |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3247 | r.state = ActivityState.RESUMED; |
| 3248 | } else { |
| 3249 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 3250 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | return true; |
| 3254 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3255 | |
| 3256 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3257 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3258 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3259 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3260 | final ActivityRecord r = activities.get(activityNdx); |
| 3261 | if (r.appToken == token) { |
| 3262 | return true; |
| 3263 | } |
| 3264 | if (r.fullscreen && !r.finishing) { |
| 3265 | return false; |
| 3266 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3267 | } |
| 3268 | } |
| 3269 | return true; |
| 3270 | } |
| 3271 | |
| 3272 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3273 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3274 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3275 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3276 | final ActivityRecord r = activities.get(activityNdx); |
| 3277 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3278 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3279 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | } |
| 3283 | |
| 3284 | boolean forceStopPackageLocked(String name, boolean doit, boolean evenPersistent, int userId) { |
| 3285 | boolean didSomething = false; |
| 3286 | TaskRecord lastTask = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 3287 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3288 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3289 | int numActivities = activities.size(); |
| 3290 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 3291 | ActivityRecord r = activities.get(activityNdx); |
| 3292 | final boolean samePackage = r.packageName.equals(name) |
| 3293 | || (name == null && r.userId == userId); |
| 3294 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
| 3295 | && (samePackage || r.task == lastTask) |
| 3296 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 3297 | if (!doit) { |
| 3298 | if (r.finishing) { |
| 3299 | // If this activity is just finishing, then it is not |
| 3300 | // interesting as far as something to stop. |
| 3301 | continue; |
| 3302 | } |
| 3303 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3304 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 3305 | didSomething = true; |
| 3306 | Slog.i(TAG, " Force finishing activity " + r); |
| 3307 | if (samePackage) { |
| 3308 | if (r.app != null) { |
| 3309 | r.app.removed = true; |
| 3310 | } |
| 3311 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3312 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 3313 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 3314 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 3315 | true)) { |
| 3316 | // r has been deleted from mActivities, accommodate. |
| 3317 | --numActivities; |
| 3318 | --activityNdx; |
| 3319 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3320 | } |
| 3321 | } |
| 3322 | } |
| 3323 | return didSomething; |
| 3324 | } |
| 3325 | |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame^] | 3326 | ActivityRecord getTasksLocked(IThumbnailReceiver receiver, |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3327 | PendingThumbnailsRecord pending, List<RunningTaskInfo> list) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3328 | ActivityRecord topRecord = null; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame^] | 3329 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3330 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3331 | ActivityRecord r = null; |
| 3332 | ActivityRecord top = null; |
| 3333 | int numActivities = 0; |
| 3334 | int numRunning = 0; |
| 3335 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3336 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3337 | r = activities.get(activityNdx); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3338 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3339 | // Initialize state for next task if needed. |
| 3340 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 3341 | top = r; |
| 3342 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3343 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3344 | |
| 3345 | // Add 'r' into the current task. |
| 3346 | numActivities++; |
| 3347 | if (r.app != null && r.app.thread != null) { |
| 3348 | numRunning++; |
| 3349 | } |
| 3350 | |
| 3351 | if (localLOGV) Slog.v( |
| 3352 | TAG, r.intent.getComponent().flattenToShortString() |
| 3353 | + ": task=" + r.task); |
| 3354 | } |
| 3355 | |
| 3356 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 3357 | ci.id = task.taskId; |
| 3358 | ci.baseActivity = r.intent.getComponent(); |
| 3359 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame^] | 3360 | ci.lastActiveTime = task.lastActiveTime; |
| 3361 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3362 | if (top.thumbHolder != null) { |
| 3363 | ci.description = top.thumbHolder.lastDescription; |
| 3364 | } |
| 3365 | ci.numActivities = numActivities; |
| 3366 | ci.numRunning = numRunning; |
| 3367 | //System.out.println( |
| 3368 | // "#" + maxNum + ": " + " descr=" + ci.description); |
| 3369 | if (receiver != null) { |
| 3370 | if (localLOGV) Slog.v( |
| 3371 | TAG, "State=" + top.state + "Idle=" + top.idle |
| 3372 | + " app=" + top.app |
| 3373 | + " thr=" + (top.app != null ? top.app.thread : null)); |
| 3374 | if (top.state == ActivityState.RESUMED || top.state == ActivityState.PAUSING) { |
| 3375 | if (top.idle && top.app != null && top.app.thread != null) { |
| 3376 | topRecord = top; |
| 3377 | } else { |
| 3378 | top.thumbnailNeeded = true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3379 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3380 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3381 | pending.pendingRecords.add(top); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3382 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3383 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3384 | } |
| 3385 | return topRecord; |
| 3386 | } |
| 3387 | |
| 3388 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3389 | final int top = mTaskHistory.size() - 1; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3390 | if (DEBUG_SWITCH) Slog.d( |
| 3391 | TAG, "Performing unhandledBack(): top activity at " + top); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3392 | if (top >= 0) { |
| 3393 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 3394 | int activityTop = activities.size() - 1; |
| 3395 | if (activityTop > 0) { |
| 3396 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 3397 | "unhandled-back", true); |
| 3398 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3402 | void handleAppDiedLocked(ProcessRecord app, boolean restarting) { |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 3403 | if (!containsApp(app)) { |
| 3404 | return; |
| 3405 | } |
| 3406 | // TODO: handle the case where an app spans multiple stacks. |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3407 | if (mPausingActivity != null && mPausingActivity.app == app) { |
| 3408 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG, |
| 3409 | "App died while pausing: " + mPausingActivity); |
| 3410 | mPausingActivity = null; |
| 3411 | } |
| 3412 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 3413 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 3414 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3415 | } |
Craig Mautner | 37f748d | 2013-06-24 16:19:55 -0700 | [diff] [blame] | 3416 | final ActivityRecord top = topRunningActivityLocked(null); |
| 3417 | final boolean launchHomeTaskNext = |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3418 | top != null && top.app == app && top.task.mOnTopOfHome; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3419 | |
| 3420 | // Remove this application's activities from active lists. |
| 3421 | boolean hasVisibleActivities = removeHistoryRecordsForAppLocked(app); |
| 3422 | |
| 3423 | if (!restarting) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3424 | ActivityStack stack = mStackSupervisor.getFocusedStack(); |
Craig Mautner | 37f748d | 2013-06-24 16:19:55 -0700 | [diff] [blame] | 3425 | if (stack == null || launchHomeTaskNext) { |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 3426 | mStackSupervisor.resumeHomeActivity(null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3427 | } else if (!mStackSupervisor.resumeTopActivitiesLocked(stack, null, null)) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3428 | // If there was nothing to resume, and we are not already |
| 3429 | // restarting this process, but there is a visible activity that |
| 3430 | // is hosted by the process... then make sure all visible |
| 3431 | // activities are running, taking care of restarting this |
| 3432 | // process. |
| 3433 | if (hasVisibleActivities) { |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 3434 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | } |
| 3439 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3440 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3441 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3442 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3443 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3444 | final ActivityRecord r = activities.get(activityNdx); |
| 3445 | if (r.app == app) { |
| 3446 | Slog.w(TAG, " Force finishing activity " |
| 3447 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3448 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3449 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3454 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3455 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3456 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3457 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3458 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3459 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 3460 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3461 | dumpClient, dumpPackage, needSep, header, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3462 | " Task id #" + task.taskId); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3463 | if (printed) { |
| 3464 | header = null; |
| 3465 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3466 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3467 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 3471 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 3472 | |
| 3473 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3474 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3475 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3476 | } |
| 3477 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3478 | final int top = mTaskHistory.size() - 1; |
| 3479 | if (top >= 0) { |
| 3480 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 3481 | int listTop = list.size() - 1; |
| 3482 | if (listTop >= 0) { |
| 3483 | activities.add(list.get(listTop)); |
| 3484 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3485 | } |
| 3486 | } else { |
| 3487 | ItemMatcher matcher = new ItemMatcher(); |
| 3488 | matcher.build(name); |
| 3489 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3490 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3491 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 3492 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 3493 | activities.add(r1); |
| 3494 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3495 | } |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | return activities; |
| 3500 | } |
| 3501 | |
| 3502 | ActivityRecord restartPackage(String packageName) { |
| 3503 | ActivityRecord starting = topRunningActivityLocked(null); |
| 3504 | |
| 3505 | // All activities that came from the package must be |
| 3506 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3507 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3508 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3509 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3510 | final ActivityRecord a = activities.get(activityNdx); |
| 3511 | if (a.info.packageName.equals(packageName)) { |
| 3512 | a.forceNewConfig = true; |
| 3513 | if (starting != null && a == starting && a.visible) { |
| 3514 | a.startFreezingScreenLocked(starting.app, |
| 3515 | ActivityInfo.CONFIG_SCREEN_LAYOUT); |
| 3516 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | return starting; |
| 3522 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 3523 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3524 | boolean removeTask(TaskRecord task) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3525 | final int taskNdx = mTaskHistory.indexOf(task); |
| 3526 | final int topTaskNdx = mTaskHistory.size() - 1; |
| 3527 | if (task.mOnTopOfHome && taskNdx < topTaskNdx) { |
| 3528 | mTaskHistory.get(taskNdx + 1).mOnTopOfHome = true; |
| 3529 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3530 | mTaskHistory.remove(task); |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3531 | return mTaskHistory.isEmpty(); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3532 | } |
| 3533 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3534 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, boolean toTop) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3535 | TaskRecord task = new TaskRecord(taskId, info, intent); |
| 3536 | addTask(task, toTop); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 3537 | return task; |
| 3538 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3539 | |
| 3540 | ArrayList<TaskRecord> getAllTasks() { |
| 3541 | return new ArrayList<TaskRecord>(mTaskHistory); |
| 3542 | } |
| 3543 | |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 3544 | void addTask(final TaskRecord task, final boolean toTop) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3545 | task.stack = this; |
| 3546 | if (toTop) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3547 | insertTaskAtTop(task); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3548 | } else { |
| 3549 | mTaskHistory.add(0, task); |
| 3550 | } |
| 3551 | } |
| 3552 | |
| 3553 | public int getStackId() { |
| 3554 | return mStackId; |
| 3555 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3556 | |
| 3557 | @Override |
| 3558 | public String toString() { |
| 3559 | return "stackId=" + mStackId + " tasks=" + mTaskHistory; |
| 3560 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3561 | } |