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