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