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