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 | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 23 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 25 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 26 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
| 27 | import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 28 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 29 | |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 30 | import static android.content.res.Configuration.SCREENLAYOUT_UNDEFINED; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 31 | import static com.android.server.am.ActivityManagerDebugConfig.*; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 32 | import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 33 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
| 34 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 35 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 36 | import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 37 | import static com.android.server.am.ActivityStackSupervisor.MOVING; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 38 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 39 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 40 | import android.graphics.Point; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 41 | import android.graphics.Rect; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 42 | import android.util.ArraySet; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 43 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 44 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 45 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 46 | import com.android.internal.os.BatteryStatsImpl; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 47 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 48 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 49 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 50 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 51 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 52 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 53 | |
| 54 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 55 | import android.app.ActivityManager; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 56 | import android.app.ActivityManager.StackId; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 57 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 58 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 59 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 60 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 61 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 62 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 63 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 64 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 65 | import android.content.pm.PackageManager; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 66 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 67 | import android.graphics.Bitmap; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 68 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 69 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 70 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 71 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 72 | import android.os.Handler; |
| 73 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 74 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 75 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 76 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 77 | import android.os.RemoteException; |
| 78 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 79 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 80 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 81 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 82 | import android.util.EventLog; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 83 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 84 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 85 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 86 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 87 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 88 | import java.lang.ref.WeakReference; |
| 89 | import java.util.ArrayList; |
| 90 | import java.util.Iterator; |
| 91 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 92 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 93 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * State and management of a single stack of activities. |
| 97 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 98 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 99 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 100 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 101 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 102 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 103 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 104 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 105 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 106 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 107 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 108 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 109 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 110 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 111 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 112 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 113 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 114 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 115 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 116 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 117 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 118 | |
| 119 | private static final boolean VALIDATE_TOKENS = false; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 120 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 121 | // Ticks during which we check progress while waiting for an app to launch. |
| 122 | static final int LAUNCH_TICK = 500; |
| 123 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 124 | // How long we wait until giving up on the last activity to pause. This |
| 125 | // is short because it directly impacts the responsiveness of starting the |
| 126 | // next activity. |
| 127 | static final int PAUSE_TIMEOUT = 500; |
| 128 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 129 | // How long we wait for the activity to tell us it has stopped before |
| 130 | // giving up. This is a good amount of time because we really need this |
| 131 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 132 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 133 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 134 | // How long we wait until giving up on an activity telling us it has |
| 135 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 136 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 137 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 138 | // 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] | 139 | // disabled. |
| 140 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 141 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 142 | // How long between activity launches that we consider safe to not warn |
| 143 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 144 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 145 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 146 | // Set to false to disable the preview that is shown while a new activity |
| 147 | // is being started. |
| 148 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 149 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 150 | // How long to wait for all background Activities to redraw following a call to |
| 151 | // convertToTranslucent(). |
| 152 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 153 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 154 | // How many activities have to be scheduled to stop to force a stop pass. |
| 155 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 156 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 157 | enum ActivityState { |
| 158 | INITIALIZING, |
| 159 | RESUMED, |
| 160 | PAUSING, |
| 161 | PAUSED, |
| 162 | STOPPING, |
| 163 | STOPPED, |
| 164 | FINISHING, |
| 165 | DESTROYING, |
| 166 | DESTROYED |
| 167 | } |
| 168 | |
| 169 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 170 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 171 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 172 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 173 | /** |
| 174 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 175 | * running) activities. It contains #TaskRecord objects. |
| 176 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 177 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 178 | |
| 179 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 180 | * Used for validating app tokens with window manager. |
| 181 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 182 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 183 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 184 | /** |
| 185 | * List of running activities, sorted by recent usage. |
| 186 | * The first entry in the list is the least recently used. |
| 187 | * It contains HistoryRecord objects. |
| 188 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 189 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 190 | |
| 191 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 192 | * Animations that for the current transition have requested not to |
| 193 | * be considered for the transition animation. |
| 194 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 195 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 198 | * When we are in the process of pausing an activity, before starting the |
| 199 | * next one, this variable holds the activity that is currently being paused. |
| 200 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 201 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * This is the last activity that we put into the paused state. This is |
| 205 | * used to determine if we need to do an activity transition while sleeping, |
| 206 | * when we normally hold the top activity paused. |
| 207 | */ |
| 208 | ActivityRecord mLastPausedActivity = null; |
| 209 | |
| 210 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 211 | * Activities that specify No History must be removed once the user navigates away from them. |
| 212 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 213 | * and finish it later if another activity replaces it on wakeup. |
| 214 | */ |
| 215 | ActivityRecord mLastNoHistoryActivity = null; |
| 216 | |
| 217 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 218 | * Current activity that is resumed, or null if there is none. |
| 219 | */ |
| 220 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 221 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 222 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 223 | * This is the last activity that has been started. It is only used to |
| 224 | * identify when multiple activities are started at once so that the user |
| 225 | * can be warned they may not be in the activity they think they are. |
| 226 | */ |
| 227 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 228 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 229 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 230 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 231 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 232 | // Activity in mTranslucentActivityWaiting is notified via |
| 233 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 234 | // background activity being drawn then the same call will be made with a true value. |
| 235 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 236 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 237 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 238 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 239 | * Set when we know we are going to be calling updateConfiguration() |
| 240 | * soon, so want to skip intermediate config checks. |
| 241 | */ |
| 242 | boolean mConfigWillChange; |
| 243 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 244 | // Whether or not this stack covers the entire screen; by default stacks are fullscreen |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 245 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 246 | // Current bounds of the stack or null if fullscreen. |
| 247 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 248 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 249 | long mLaunchStartTime = 0; |
| 250 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 251 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 252 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 253 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 254 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 255 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 256 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 257 | ArrayList<ActivityStack> mStacks; |
| 258 | /** The attached Display's unique identifier, or -1 if detached */ |
| 259 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 260 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 261 | /** Run all ActivityStacks through this */ |
| 262 | final ActivityStackSupervisor mStackSupervisor; |
| 263 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 264 | private final LaunchingTaskPositioner mTaskPositioner; |
| 265 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 266 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 267 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 268 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 269 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 270 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 271 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 272 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 273 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 274 | |
| 275 | static class ScheduleDestroyArgs { |
| 276 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 277 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 278 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 279 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 280 | mReason = reason; |
| 281 | } |
| 282 | } |
| 283 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 284 | final Handler mHandler; |
| 285 | |
| 286 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 287 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 288 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 289 | super(looper); |
| 290 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 291 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 292 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 293 | public void handleMessage(Message msg) { |
| 294 | switch (msg.what) { |
| 295 | case PAUSE_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 pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 300 | synchronized (mService) { |
| 301 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 302 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 303 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 304 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 305 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 306 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 307 | case LAUNCH_TICK_MSG: { |
| 308 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 309 | synchronized (mService) { |
| 310 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 311 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 315 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 316 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 317 | // We don't at this point know if the activity is fullscreen, |
| 318 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 319 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 320 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 321 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 322 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 323 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 324 | case STOP_TIMEOUT_MSG: { |
| 325 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 326 | // We don't at this point know if the activity is fullscreen, |
| 327 | // so we need to be conservative and assume it isn't. |
| 328 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 329 | synchronized (mService) { |
| 330 | if (r.isInHistory()) { |
| 331 | activityStoppedLocked(r, null, null, null); |
| 332 | } |
| 333 | } |
| 334 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 335 | case DESTROY_ACTIVITIES_MSG: { |
| 336 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 337 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 338 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 339 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 340 | } break; |
| 341 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 342 | synchronized (mService) { |
| 343 | notifyActivityDrawnLocked(null); |
| 344 | } |
| 345 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 346 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 347 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 348 | final ActivityRecord r = getVisibleBehindActivity(); |
| 349 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 350 | if (r != null) { |
| 351 | mService.killAppAtUsersRequest(r.app, null); |
| 352 | } |
| 353 | } |
| 354 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 355 | } |
| 356 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 359 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 360 | int count = 0; |
| 361 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 362 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 363 | } |
| 364 | return count; |
| 365 | } |
| 366 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 367 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 368 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 369 | mActivityContainer = activityContainer; |
| 370 | mStackSupervisor = activityContainer.getOuter(); |
| 371 | mService = mStackSupervisor.mService; |
| 372 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 373 | mWindowManager = mService.mWindowManager; |
| 374 | mStackId = activityContainer.mStackId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 375 | mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 376 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 377 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 378 | ? new LaunchingTaskPositioner() : null; |
| 379 | } |
| 380 | |
| 381 | void attachDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 382 | mDisplayId = activityDisplay.mDisplayId; |
| 383 | mStacks = activityDisplay.mStacks; |
| 384 | mBounds = mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId, onTop); |
| 385 | mFullscreen = mBounds == null; |
| 386 | if (mTaskPositioner != null) { |
| 387 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 388 | mTaskPositioner.configure(mBounds); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | void detachDisplay() { |
| 393 | mDisplayId = Display.INVALID_DISPLAY; |
| 394 | mStacks = null; |
| 395 | if (mTaskPositioner != null) { |
| 396 | mTaskPositioner.reset(); |
| 397 | } |
| 398 | mWindowManager.detachStack(mStackId); |
| 399 | } |
| 400 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 401 | public void getDisplaySize(Point out) { |
| 402 | mActivityContainer.mActivityDisplay.mDisplay.getSize(out); |
| 403 | } |
| 404 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 405 | void setBounds(Rect bounds) { |
| 406 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 407 | if (mTaskPositioner != null) { |
| 408 | mTaskPositioner.configure(bounds); |
| 409 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 410 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 411 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 412 | boolean okToShowLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 413 | return mStackSupervisor.okToShowLocked(r); |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 416 | final ActivityRecord topRunningActivityLocked() { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 417 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 418 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 419 | if (r != null) { |
| 420 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 421 | } |
| 422 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 423 | return null; |
| 424 | } |
| 425 | |
| 426 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 427 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 428 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 429 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 430 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 431 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 432 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 433 | return r; |
| 434 | } |
| 435 | } |
| 436 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 437 | return null; |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 442 | * 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] | 443 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 444 | * @param token If non-null, any history records matching this token will be skipped. |
| 445 | * @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] | 446 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 447 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 448 | */ |
| 449 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 450 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 451 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 452 | if (task.taskId == taskId) { |
| 453 | continue; |
| 454 | } |
| 455 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 456 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 457 | final ActivityRecord r = activities.get(i); |
| 458 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 459 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 460 | return r; |
| 461 | } |
| 462 | } |
| 463 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 464 | return null; |
| 465 | } |
| 466 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 467 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 468 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 469 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 470 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 471 | final ActivityRecord r = activities.get(activityNdx); |
| 472 | if (!r.finishing) { |
| 473 | return r; |
| 474 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 475 | } |
| 476 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 477 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 480 | final TaskRecord topTask() { |
| 481 | final int size = mTaskHistory.size(); |
| 482 | if (size > 0) { |
| 483 | return mTaskHistory.get(size - 1); |
| 484 | } |
| 485 | return null; |
| 486 | } |
| 487 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 488 | TaskRecord taskForIdLocked(int id) { |
| 489 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 490 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 491 | if (task.taskId == id) { |
| 492 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 493 | } |
| 494 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 495 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 498 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 499 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 500 | return isInStackLocked(r); |
| 501 | } |
| 502 | |
| 503 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 504 | if (r == null) { |
| 505 | return null; |
| 506 | } |
| 507 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 508 | if (task != null && task.stack != null |
| 509 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 510 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 511 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 512 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 513 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 514 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 517 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 518 | final boolean hadit = mLRUActivities.remove(r); |
| 519 | mLRUActivities.add(r); |
| 520 | return hadit; |
| 521 | } |
| 522 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 523 | final boolean isHomeStack() { |
| 524 | return mStackId == HOME_STACK_ID; |
| 525 | } |
| 526 | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 527 | final boolean isDockedStack() { |
| 528 | return mStackId == DOCKED_STACK_ID; |
| 529 | } |
| 530 | |
| 531 | final boolean isPinnedStack() { |
| 532 | return mStackId == PINNED_STACK_ID; |
| 533 | } |
| 534 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 535 | final boolean isOnHomeDisplay() { |
| 536 | return isAttached() && |
| 537 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 538 | } |
| 539 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 540 | void moveToFront(String reason) { |
| 541 | moveToFront(reason, null); |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * @param reason The reason for moving the stack to the front. |
| 546 | * @param task If non-null, the task will be moved to the top of the stack. |
| 547 | * */ |
| 548 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 549 | if (!isAttached()) { |
| 550 | return; |
| 551 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 552 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 553 | mStacks.remove(this); |
| 554 | int addIndex = mStacks.size(); |
| 555 | |
| 556 | if (addIndex > 0) { |
| 557 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 558 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 559 | // If the top stack is always on top, we move this stack just below it. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 560 | addIndex--; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 561 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | mStacks.add(addIndex, this); |
| 565 | |
| 566 | // TODO(multi-display): Needs to also work if focus is moving to the non-home display. |
| 567 | if (isOnHomeDisplay()) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 568 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 569 | } |
| 570 | if (task != null) { |
| 571 | insertTaskAtTop(task, null); |
| 572 | } else { |
| 573 | task = topTask(); |
| 574 | } |
| 575 | if (task != null) { |
| 576 | mWindowManager.moveTaskToTop(task.taskId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 577 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 580 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 581 | if (StackId.canReceiveKeys(mStackId)) { |
| 582 | return true; |
| 583 | } |
| 584 | // The stack isn't focusable. See if its top activity is focusable to force focus on the |
| 585 | // stack. |
| 586 | final ActivityRecord r = topRunningActivityLocked(); |
| 587 | return r != null && r.isFocusable(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 590 | final boolean isAttached() { |
| 591 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 594 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 595 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 596 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 597 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 598 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 599 | Intent intent = target.intent; |
| 600 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 601 | ComponentName cls = intent.getComponent(); |
| 602 | if (info.targetActivity != null) { |
| 603 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 604 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 605 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 606 | boolean isDocument = intent != null & intent.isDocument(); |
| 607 | // If documentData is non-null then it must match the existing task data. |
| 608 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 609 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 610 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + target + " in " + this); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 611 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 612 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 613 | if (task.voiceSession != null) { |
| 614 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 615 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 616 | continue; |
| 617 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 618 | if (task.userId != userId) { |
| 619 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 620 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 621 | continue; |
| 622 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 623 | final ActivityRecord r = task.getTopActivity(); |
| 624 | if (r == null || r.finishing || r.userId != userId || |
| 625 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 626 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 627 | continue; |
| 628 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 629 | if (r.mActivityType != target.mActivityType) { |
| 630 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 631 | continue; |
| 632 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 633 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 634 | final Intent taskIntent = task.intent; |
| 635 | final Intent affinityIntent = task.affinityIntent; |
| 636 | final boolean taskIsDocument; |
| 637 | final Uri taskDocumentData; |
| 638 | if (taskIntent != null && taskIntent.isDocument()) { |
| 639 | taskIsDocument = true; |
| 640 | taskDocumentData = taskIntent.getData(); |
| 641 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 642 | taskIsDocument = true; |
| 643 | taskDocumentData = affinityIntent.getData(); |
| 644 | } else { |
| 645 | taskIsDocument = false; |
| 646 | taskDocumentData = null; |
| 647 | } |
| 648 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 649 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 650 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 651 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 652 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 653 | if (!isDocument && !taskIsDocument |
| 654 | && result.r == null && task.canMatchRootAffinity()) { |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 655 | if (task.rootAffinity.equals(target.taskAffinity)) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 656 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 657 | // It is possible for multiple tasks to have the same root affinity especially |
| 658 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 659 | // to see if there is a better candidate. |
| 660 | result.r = r; |
| 661 | result.matchedByRootAffinity = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 662 | } |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 663 | } else if (taskIntent != null && taskIntent.getComponent() != null && |
| 664 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 665 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 666 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 667 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 668 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 669 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 670 | result.r = r; |
| 671 | result.matchedByRootAffinity = false; |
| 672 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 673 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 674 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 675 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 676 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 677 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 678 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 679 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 680 | result.r = r; |
| 681 | result.matchedByRootAffinity = false; |
| 682 | break; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 683 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 684 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Returns the first activity (starting from the top of the stack) that |
| 689 | * is the same as the given activity. Returns null if no such activity |
| 690 | * is found. |
| 691 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 692 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 693 | ComponentName cls = intent.getComponent(); |
| 694 | if (info.targetActivity != null) { |
| 695 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 696 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 697 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 698 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 699 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 700 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 701 | final boolean notCurrentUserTask = |
| 702 | !mStackSupervisor.isCurrentProfileLocked(task.userId); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 703 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 704 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 705 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 706 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 707 | if (notCurrentUserTask && (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 708 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 709 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 710 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 711 | return r; |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | return null; |
| 717 | } |
| 718 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 719 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 720 | * 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] | 721 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 722 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 723 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 724 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 725 | } |
| 726 | mCurrentUser = userId; |
| 727 | |
| 728 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 729 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 730 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 731 | final TaskRecord task = mTaskHistory.get(i); |
| 732 | |
| 733 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 734 | // okay to show the activity when locked. |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 735 | if (mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 736 | || task.topRunningActivityLocked() != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 737 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 738 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 739 | mTaskHistory.remove(i); |
| 740 | mTaskHistory.add(task); |
| 741 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 742 | // Use same value for i. |
| 743 | } else { |
| 744 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 745 | } |
| 746 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 747 | if (VALIDATE_TOKENS) { |
| 748 | validateAppTokensLocked(); |
| 749 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 752 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 753 | r.state = ActivityState.RESUMED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 754 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 755 | "Moving to RESUMED: " + r + " (starting new instance)"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 756 | r.stopped = false; |
| 757 | mResumedActivity = r; |
| 758 | r.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 759 | mRecentTasks.addLocked(r.task); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 760 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 761 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 762 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 763 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 764 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 767 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 768 | if (r != null) { |
| 769 | mRecentTasks.addLocked(r.task); |
| 770 | r.task.touchActiveTime(); |
| 771 | } |
| 772 | } |
| 773 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 774 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 775 | if (mFullyDrawnStartTime != 0) { |
| 776 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 777 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 778 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 779 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 780 | } |
| 781 | |
| 782 | private void stopFullyDrawnTraceIfNeeded() { |
| 783 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 784 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 785 | mFullyDrawnStartTime = 0; |
| 786 | } |
| 787 | } |
| 788 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 789 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 790 | if (r.displayStartTime == 0) { |
| 791 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 792 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 793 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 794 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 795 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 796 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 797 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 798 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 799 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 800 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 801 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 802 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 803 | // Make sure that there is no activity waiting for this to launch. |
| 804 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 805 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 806 | } else { |
| 807 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 808 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 809 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 812 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 813 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 814 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 815 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 816 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 817 | activities.get(activityNdx).setSleeping(false); |
| 818 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 819 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 820 | if (mPausingActivity != null) { |
| 821 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 822 | activityPausedLocked(mPausingActivity.appToken, true); |
| 823 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 824 | } |
| 825 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 826 | /** |
| 827 | * @return true if something must be done before going to sleep. |
| 828 | */ |
| 829 | boolean checkReadyForSleepLocked() { |
| 830 | if (mResumedActivity != null) { |
| 831 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 832 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 833 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 834 | "Sleep => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 835 | startPausingLocked(false, true, false, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 836 | return true; |
| 837 | } |
| 838 | if (mPausingActivity != null) { |
| 839 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 840 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still waiting to pause " + mPausingActivity); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 841 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 844 | if (hasVisibleBehindActivity()) { |
| 845 | // Stop visible behind activity before going to sleep. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 846 | final ActivityRecord r = getVisibleBehindActivity(); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 847 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 848 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Sleep still waiting to stop visible behind " + r); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 849 | return true; |
| 850 | } |
| 851 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 852 | return false; |
| 853 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 854 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 855 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 856 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 857 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 858 | // Make sure any stopped but visible activities are now sleeping. |
| 859 | // This ensures that the activity's onStop() is called. |
| 860 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 861 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 862 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 863 | final ActivityRecord r = activities.get(activityNdx); |
| 864 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 865 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 866 | } |
| 867 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 868 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 869 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 870 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 871 | public final Bitmap screenshotActivitiesLocked(ActivityRecord who) { |
| 872 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 873 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 874 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 875 | return null; |
| 876 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 877 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 878 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 879 | // 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] | 880 | // we can just go ahead and skip taking the screenshot if this is the home stack. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 881 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 882 | return null; |
| 883 | } |
| 884 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 885 | int w = mService.mThumbnailWidth; |
| 886 | int h = mService.mThumbnailHeight; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 887 | float scale = 1f; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 888 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 889 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 890 | |
| 891 | // When this flag is set, we currently take the fullscreen screenshot of the activity |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 892 | // but scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to |
| 893 | // use within SystemUI while keeping memory usage low. |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 894 | if (ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 895 | w = h = -1; |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 896 | scale = 0.5f; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 897 | } |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 898 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 899 | w, h, scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 900 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 901 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 902 | return null; |
| 903 | } |
| 904 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 905 | /** |
| 906 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 907 | * is already an activity being paused or there is no resumed activity. |
| 908 | * |
| 909 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 910 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 911 | * screen turning off). |
| 912 | * @param resuming True if this is being called as part of resuming the top activity, so |
| 913 | * we shouldn't try to instigate a resume here. |
| 914 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 915 | * set to true, we will immediately complete the pause here before returning. |
| 916 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 917 | * it to tell us when it is done. |
| 918 | */ |
| 919 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming, |
| 920 | boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 921 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 922 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 923 | + " state=" + mPausingActivity.state); |
| 924 | if (!mService.isSleeping()) { |
| 925 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 926 | // Because activity will be paused immediately after resume, just let pause |
| 927 | // be completed by the order of activity paused from clients. |
| 928 | completePauseLocked(false); |
| 929 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 930 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 931 | ActivityRecord prev = mResumedActivity; |
| 932 | if (prev == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 933 | if (!resuming) { |
| 934 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 935 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 936 | } |
| 937 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 938 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 939 | |
| 940 | if (mActivityContainer.mParentActivity == null) { |
| 941 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 942 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 943 | } |
| 944 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 945 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 946 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 947 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 948 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 949 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 950 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 951 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 952 | prev.state = ActivityState.PAUSING; |
| 953 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 954 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 955 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | 979f5ed | 2015-10-12 11:22:50 -0700 | [diff] [blame] | 956 | if (mService.mHasRecents |
| 957 | && (next == null || next.noDisplay || next.task != prev.task || uiSleeping)) { |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 958 | prev.mUpdateTaskThumbnailWhenHidden = true; |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 959 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 960 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 961 | |
| 962 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 963 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 964 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 965 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 966 | try { |
| 967 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 968 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 969 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 970 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 971 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 972 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 973 | } catch (Exception e) { |
| 974 | // Ignore exception, if process died other code will cleanup. |
| 975 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 976 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 977 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 978 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 979 | } |
| 980 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 981 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 982 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 983 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | // If we are not going to sleep, we want to ensure the device is |
| 987 | // awake until the next activity is started. |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 988 | if (!uiSleeping && !mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 989 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 992 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 993 | // Have the window manager pause its key dispatching until the new |
| 994 | // activity has started. If we're pausing the activity just because |
| 995 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 996 | // key dispatch; the same activity will pick it up again on wakeup. |
| 997 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 998 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 999 | } else if (DEBUG_PAUSE) { |
| 1000 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1003 | if (dontWait) { |
| 1004 | // If the caller said they don't want to wait for the pause, then complete |
| 1005 | // the pause now. |
| 1006 | completePauseLocked(false); |
| 1007 | return false; |
| 1008 | |
| 1009 | } else { |
| 1010 | // Schedule a pause timeout in case the app doesn't respond. |
| 1011 | // We don't give it much time because this directly impacts the |
| 1012 | // responsiveness seen by the user. |
| 1013 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1014 | msg.obj = prev; |
| 1015 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 1016 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1017 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1018 | return true; |
| 1019 | } |
| 1020 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1021 | } else { |
| 1022 | // This activity failed to schedule the |
| 1023 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1024 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1025 | if (!resuming) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1026 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1027 | } |
| 1028 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1029 | } |
| 1030 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1031 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1032 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1033 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1034 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1035 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1036 | final ActivityRecord r = isInStackLocked(token); |
| 1037 | if (r != null) { |
| 1038 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1039 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1040 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1041 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1042 | completePauseLocked(true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1043 | } else { |
| 1044 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1045 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1046 | mPausingActivity != null |
| 1047 | ? mPausingActivity.shortComponentName : "(none)"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1048 | if (r.state == ActivityState.PAUSING) { |
| 1049 | r.state = ActivityState.PAUSED; |
| 1050 | if (r.finishing) { |
| 1051 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1052 | "Executing finish of failed to pause activity: " + r); |
| 1053 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1054 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1055 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1060 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 1061 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 1062 | if (r.state != ActivityState.STOPPING) { |
| 1063 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 1064 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1065 | return; |
| 1066 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1067 | if (persistentState != null) { |
| 1068 | r.persistentState = persistentState; |
| 1069 | mService.notifyTaskPersisterLocked(r.task, false); |
| 1070 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1071 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + r + ": " + icicle); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1072 | if (icicle != null) { |
| 1073 | // If icicle is null, this is happening due to a timeout, so we |
| 1074 | // haven't really saved the state. |
| 1075 | r.icicle = icicle; |
| 1076 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 1077 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1078 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1079 | } |
| 1080 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1081 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + r + " (stop complete)"); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1082 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1083 | r.stopped = true; |
| 1084 | r.state = ActivityState.STOPPED; |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1085 | if (getVisibleBehindActivity() == r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1086 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1087 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1088 | if (r.finishing) { |
| 1089 | r.clearOptionsLocked(); |
| 1090 | } else { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1091 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1092 | destroyActivityLocked(r, true, "stop-config"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1093 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1094 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1095 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1096 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1101 | private void completePauseLocked(boolean resumeNext) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1102 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1103 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1104 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1105 | if (prev != null) { |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1106 | final boolean wasStopping = prev.state == ActivityState.STOPPING; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1107 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1108 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1109 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1110 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1111 | } else if (prev.app != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1112 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending stop: " + prev); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1113 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1114 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1115 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1116 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1117 | if (prev.configDestroy) { |
| 1118 | // The previous is being paused because the configuration |
| 1119 | // is changing, which means it is actually stopping... |
| 1120 | // To juggle the fact that we are also starting a new |
| 1121 | // instance right now, we need to first completely stop |
| 1122 | // the current instance before starting the new one. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1123 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Destroying after pause: " + prev); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1124 | destroyActivityLocked(prev, true, "pause-config"); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1125 | } else if (wasStopping) { |
| 1126 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1127 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1128 | // We don't need to schedule another stop, we only need to let it happen. |
| 1129 | prev.state = ActivityState.STOPPING; |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 1130 | } else if (!hasVisibleBehindActivity() || mService.isSleepingOrShuttingDown()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1131 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1132 | // stopping. |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1133 | addToStopping(prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1134 | } |
| 1135 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1136 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "App died during pause, not stopping: " + prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1137 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1138 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1139 | // It is possible the activity was freezing the screen before it was paused. |
| 1140 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1141 | // since it is no longer visible. |
| 1142 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1143 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1144 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1145 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1146 | if (resumeNext) { |
| 1147 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
| 1148 | if (!mService.isSleepingOrShuttingDown()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1149 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1150 | } else { |
| 1151 | mStackSupervisor.checkReadyForSleepLocked(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1152 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1153 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1154 | // If there are no more activities available to run, do resume anyway to start |
| 1155 | // something. Also if the top activity on the stack is not the just paused |
| 1156 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1157 | // in-flight app switch. |
| 1158 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1159 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1160 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1161 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1162 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1163 | if (prev != null) { |
| 1164 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1165 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1166 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1167 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1168 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1169 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1170 | if (diff > 0) { |
| 1171 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1172 | synchronized (bsi) { |
| 1173 | BatteryStatsImpl.Uid.Proc ps = |
| 1174 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1175 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1176 | if (ps != null) { |
| 1177 | ps.addForegroundTimeLocked(diff); |
| 1178 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1182 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1183 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1184 | |
| 1185 | // Notfiy when the task stack has changed |
| 1186 | mService.notifyTaskStackChangedLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1189 | private void addToStopping(ActivityRecord r) { |
| 1190 | mStackSupervisor.mStoppingActivities.add(r); |
| 1191 | if (mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE || |
| 1192 | r.frontOfTask && mTaskHistory.size() <= 1) { |
| 1193 | // If we already have a few activities waiting to stop, |
| 1194 | // then give up on things going idle and start clearing |
| 1195 | // them out. Or if r is the last of activity of the last task the stack |
| 1196 | // will be empty and must be cleared immediately. |
| 1197 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "To many pending stops, forcing idle"); |
| 1198 | mStackSupervisor.scheduleIdleLocked(); |
| 1199 | } else { |
| 1200 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1201 | } |
| 1202 | } |
| 1203 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1204 | /** |
| 1205 | * Once we know that we have asked an application to put an activity in |
| 1206 | * the resumed state (either by launching it or explicitly telling it), |
| 1207 | * this function updates the rest of our state to match that fact. |
| 1208 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1209 | private void completeResumeLocked(ActivityRecord next) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1210 | next.idle = false; |
| 1211 | next.results = null; |
| 1212 | next.newIntents = null; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1213 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1214 | if (next.isHomeActivity()) { |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1215 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1216 | if (app != null && app != mService.mHomeProcess) { |
| 1217 | mService.mHomeProcess = app; |
| 1218 | } |
| 1219 | } |
| 1220 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1221 | if (next.nowVisible) { |
| 1222 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1223 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1224 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1225 | |
| 1226 | // 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] | 1227 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1228 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1229 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1230 | |
| 1231 | next.resumeKeyDispatchingLocked(); |
| 1232 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1233 | |
| 1234 | // Mark the point when the activity is resuming |
| 1235 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1236 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1237 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1238 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1239 | } else { |
| 1240 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1241 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1242 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1243 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1244 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1245 | if (getVisibleBehindActivity() == next) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1246 | // When resuming an activity, require it to call requestVisibleBehind() again. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1247 | setVisibleBehindActivity(null); |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1248 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1251 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1252 | r.visible = visible; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1253 | if (!visible && r.mUpdateTaskThumbnailWhenHidden) { |
| 1254 | r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null); |
| 1255 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1256 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1257 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1258 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1259 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1260 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1261 | container.setVisible(visible); |
| 1262 | } |
| 1263 | } |
| 1264 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1265 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1266 | // otherwise return null; |
| 1267 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1268 | TaskRecord task = r.task; |
| 1269 | if (task == null) { |
| 1270 | return null; |
| 1271 | } |
| 1272 | |
| 1273 | ActivityStack stack = task.stack; |
| 1274 | if (stack == null) { |
| 1275 | return null; |
| 1276 | } |
| 1277 | |
| 1278 | int stackNdx = mStacks.indexOf(stack); |
| 1279 | |
| 1280 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1281 | int taskNdx = tasks.indexOf(task); |
| 1282 | |
| 1283 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1284 | int activityNdx = activities.indexOf(r) + 1; |
| 1285 | |
| 1286 | final int numStacks = mStacks.size(); |
| 1287 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1288 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1289 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1290 | final int numTasks = tasks.size(); |
| 1291 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1292 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1293 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1294 | final int numActivities = activities.size(); |
| 1295 | while (activityNdx < numActivities) { |
| 1296 | final ActivityRecord activity = activities.get(activityNdx); |
| 1297 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1298 | return historyStack.mFullscreen |
| 1299 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1300 | } |
| 1301 | ++activityNdx; |
| 1302 | } |
| 1303 | activityNdx = 0; |
| 1304 | ++taskNdx; |
| 1305 | } |
| 1306 | taskNdx = 0; |
| 1307 | ++stackNdx; |
| 1308 | } |
| 1309 | |
| 1310 | return null; |
| 1311 | } |
| 1312 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1313 | ActivityStack getNextFocusableStackLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1314 | ArrayList<ActivityStack> stacks = mStacks; |
| 1315 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1316 | if (parent != null) { |
| 1317 | stacks = parent.task.stack.mStacks; |
| 1318 | } |
| 1319 | if (stacks != null) { |
| 1320 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1321 | ActivityStack stack = stacks.get(i); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1322 | if (stack != this && stack.isFocusable() && stack.isStackVisibleLocked()) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1323 | return stack; |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | return null; |
| 1328 | } |
| 1329 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1330 | /** Returns true if the stack contains a fullscreen task. */ |
| 1331 | private boolean hasFullscreenTask() { |
| 1332 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1333 | final TaskRecord task = mTaskHistory.get(i); |
| 1334 | if (task.mFullscreen) { |
| 1335 | return true; |
| 1336 | } |
| 1337 | } |
| 1338 | return false; |
| 1339 | } |
| 1340 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1341 | private boolean hasTranslucentActivity(ActivityStack stack) { |
| 1342 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1343 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1344 | final TaskRecord task = tasks.get(taskNdx); |
| 1345 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1346 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1347 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1348 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1349 | // Conditions for an activity to obscure the stack we're |
| 1350 | // examining: |
| 1351 | // 1. Not Finishing AND Visible AND: |
| 1352 | // 2. Either: |
| 1353 | // - Full Screen Activity OR |
| 1354 | // - On top of Home and our stack is NOT home |
| 1355 | if (!r.finishing && r.visible && (r.fullscreen || |
| 1356 | (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()))) { |
| 1357 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1358 | } |
| 1359 | } |
| 1360 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1361 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | /** Returns true if the stack is considered visible. */ |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 1365 | boolean isStackVisibleLocked() { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1366 | if (!isAttached()) { |
| 1367 | return false; |
| 1368 | } |
| 1369 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1370 | if (mStackSupervisor.isFrontStack(this) || mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1371 | return true; |
| 1372 | } |
| 1373 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1374 | final int stackIndex = mStacks.indexOf(this); |
| 1375 | |
| 1376 | if (stackIndex == mStacks.size() - 1) { |
| 1377 | Slog.wtf(TAG, |
| 1378 | "Stack=" + this + " isn't front stack but is at the top of the stack list"); |
| 1379 | return false; |
| 1380 | } |
| 1381 | |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1382 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 1383 | if (isLockscreenShown && !StackId.isAllowedOverLockscreen(mStackId)) { |
| 1384 | return false; |
| 1385 | } |
| 1386 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1387 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1388 | final int focusedStackId = focusedStack.mStackId; |
| 1389 | |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1390 | if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 1391 | && hasVisibleBehindActivity() && focusedStackId == HOME_STACK_ID) { |
| 1392 | // The fullscreen stack should be visible if it has a visible behind activity behind |
| 1393 | // the home stack that will be translucent. |
| 1394 | return true; |
| 1395 | } |
| 1396 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1397 | if (mStackId == DOCKED_STACK_ID) { |
| 1398 | // Docked stack is always visible, except in the case where the home activity |
| 1399 | // is the top running activity in the focused home stack. |
| 1400 | if (focusedStackId != HOME_STACK_ID) { |
| 1401 | return true; |
| 1402 | } |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1403 | ActivityRecord topHomeActivity = focusedStack.topRunningActivityLocked(); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1404 | return topHomeActivity == null || !topHomeActivity.isHomeActivity(); |
| 1405 | } |
| 1406 | |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1407 | // Find the first stack below focused stack that actually got something visible. |
| 1408 | int belowFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1409 | while (belowFocusedIndex >= 0 && |
| 1410 | mStacks.get(belowFocusedIndex).topRunningActivityLocked() == null) { |
| 1411 | belowFocusedIndex--; |
| 1412 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1413 | if ((focusedStackId == DOCKED_STACK_ID || focusedStackId == PINNED_STACK_ID) |
| 1414 | && stackIndex == belowFocusedIndex) { |
| 1415 | // Stacks directly behind the docked or pinned stack are always visible. |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1416 | return true; |
| 1417 | } |
| 1418 | |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1419 | if (focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 1420 | && hasTranslucentActivity(focusedStack)) { |
| 1421 | // Stacks behind the fullscreen stack with a translucent activity are always |
| 1422 | // visible so they can act as a backdrop to the translucent activity. |
| 1423 | // For example, dialog activities |
| 1424 | if (stackIndex == belowFocusedIndex) { |
| 1425 | return true; |
| 1426 | } |
| 1427 | if (belowFocusedIndex >= 0) { |
| 1428 | final ActivityStack stack = mStacks.get(belowFocusedIndex); |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1429 | if ((stack.mStackId == DOCKED_STACK_ID || stack.mStackId == PINNED_STACK_ID) |
| 1430 | && stackIndex == (belowFocusedIndex - 1)) { |
| 1431 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1432 | // complete backdrop to the translucent activity when the docked stack is up. |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1433 | return true; |
| 1434 | } |
| 1435 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1438 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1439 | // Visibility of any static stack should have been determined by the conditions above. |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1440 | return false; |
| 1441 | } |
| 1442 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1443 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1444 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1445 | |
| 1446 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1447 | continue; |
| 1448 | } |
| 1449 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1450 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1451 | // These stacks can't have any dynamic stacks visible behind them. |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1452 | return false; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1453 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1454 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1455 | if (!hasTranslucentActivity(stack)) { |
| 1456 | return false; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | return true; |
| 1461 | } |
| 1462 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1463 | final int rankTaskLayers(int baseLayer) { |
| 1464 | int layer = 0; |
| 1465 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1466 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1467 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1468 | if (r == null || r.finishing || !r.visible) { |
| 1469 | task.mLayerRank = -1; |
| 1470 | } else { |
| 1471 | task.mLayerRank = baseLayer + layer++; |
| 1472 | } |
| 1473 | } |
| 1474 | return layer; |
| 1475 | } |
| 1476 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1477 | /** |
| 1478 | * Make sure that all activities that need to be visible (that is, they |
| 1479 | * currently can be seen by the user) actually are. |
| 1480 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1481 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1482 | boolean preserveWindows) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1483 | ActivityRecord top = topRunningActivityLocked(); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1484 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1485 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1486 | if (top != null) { |
| 1487 | checkTranslucentActivityWaiting(top); |
| 1488 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1489 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1490 | // If the top activity is not fullscreen, then we need to |
| 1491 | // make sure any activities under it are now visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1492 | boolean aboveTop = top != null; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1493 | final boolean stackInvisible = !isStackVisibleLocked(); |
| 1494 | boolean behindFullscreenActivity = stackInvisible; |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1495 | boolean resumeNextActivity = isFocusable() && (isInStackLocked(starting) == null); |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1496 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1497 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1498 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1499 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1500 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1501 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1502 | final ActivityRecord r = activities.get(activityNdx); |
| 1503 | if (r.finishing) { |
| 1504 | continue; |
| 1505 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1506 | final boolean isTop = r == top; |
| 1507 | if (aboveTop && !isTop) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1508 | continue; |
| 1509 | } |
| 1510 | aboveTop = false; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1511 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1512 | // but must be drawn initially for the animation as though they were visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1513 | if ((!behindFullscreenActivity || r.mLaunchTaskBehind) |
| 1514 | && okToShowLocked(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1515 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1516 | "Make visible? " + r + " finishing=" + r.finishing |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1517 | + " state=" + r.state); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1518 | // First: if this is not the current activity being started, make |
| 1519 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1520 | if (r != starting) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1521 | ensureActivityConfigurationLocked(r, 0, preserveWindows); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1522 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1523 | |
| 1524 | if (r.app == null || r.app.thread == null) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1525 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1526 | resumeNextActivity, r)) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1527 | if (activityNdx >= activities.size()) { |
| 1528 | // Record may be removed if its process needs to restart. |
| 1529 | activityNdx = activities.size() - 1; |
| 1530 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1531 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1532 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1533 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1534 | } else if (r.visible) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1535 | // If this activity is already visible, then there is nothing to do here. |
| 1536 | if (handleAlreadyVisible(r)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1537 | resumeNextActivity = false; |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1538 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1539 | } else { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1540 | makeVisible(starting, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1541 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1542 | // Aggregate current change flags. |
| 1543 | configChanges |= r.configChangeFlags; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1544 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1545 | behindFullscreenActivity, task, r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1546 | } else { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1547 | makeInvisible(stackInvisible, behindFullscreenActivity, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1548 | } |
| 1549 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1550 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1551 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1552 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1553 | // status of an activity in a previous task affects other. |
| 1554 | behindFullscreenActivity = stackInvisible; |
| 1555 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1556 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1557 | |
| 1558 | if (mTranslucentActivityWaiting != null && |
| 1559 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1560 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1561 | notifyActivityDrawnLocked(null); |
| 1562 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1563 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1564 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1565 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 1566 | if (mTranslucentActivityWaiting != top) { |
| 1567 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1568 | if (mTranslucentActivityWaiting != null) { |
| 1569 | // Call the callback with a timeout indication. |
| 1570 | notifyActivityDrawnLocked(null); |
| 1571 | mTranslucentActivityWaiting = null; |
| 1572 | } |
| 1573 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1578 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1579 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 1580 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 1581 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 1582 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1583 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1584 | // This activity needs to be visible, but isn't even running... |
| 1585 | // get it started and resume if no other stack in this stack is resumed. |
| 1586 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 1587 | if (r != starting) { |
| 1588 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1589 | } |
| 1590 | if (!r.visible || r.mLaunchTaskBehind) { |
| 1591 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
| 1592 | setVisible(r, true); |
| 1593 | } |
| 1594 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1595 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1596 | return true; |
| 1597 | } |
| 1598 | } |
| 1599 | return false; |
| 1600 | } |
| 1601 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1602 | private void makeInvisible(boolean stackInvisible, boolean behindFullscreenActivity, |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1603 | ActivityRecord r) { |
| 1604 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r + " finishing=" |
| 1605 | + r.finishing + " state=" + r.state + " stackInvisible=" + stackInvisible |
| 1606 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1607 | if (!r.visible) { |
| 1608 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 1609 | return; |
| 1610 | } |
| 1611 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 1612 | // keeping the screen frozen. |
| 1613 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r); |
| 1614 | try { |
| 1615 | setVisible(r, false); |
| 1616 | switch (r.state) { |
| 1617 | case STOPPING: |
| 1618 | case STOPPED: |
| 1619 | if (r.app != null && r.app.thread != null) { |
| 1620 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1621 | "Scheduling invisibility: " + r); |
| 1622 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1623 | } |
| 1624 | break; |
| 1625 | |
| 1626 | case INITIALIZING: |
| 1627 | case RESUMED: |
| 1628 | case PAUSING: |
| 1629 | case PAUSED: |
| 1630 | // This case created for transitioning activities from |
| 1631 | // translucent to opaque {@link Activity#convertToOpaque}. |
| 1632 | if (getVisibleBehindActivity() == r) { |
| 1633 | releaseBackgroundResources(r); |
| 1634 | } else { |
| 1635 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1636 | mStackSupervisor.mStoppingActivities.add(r); |
| 1637 | } |
| 1638 | mStackSupervisor.scheduleIdleLocked(); |
| 1639 | } |
| 1640 | break; |
| 1641 | |
| 1642 | default: |
| 1643 | break; |
| 1644 | } |
| 1645 | } catch (Exception e) { |
| 1646 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1647 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 1652 | TaskRecord task, ActivityRecord r) { |
| 1653 | if (r.fullscreen) { |
| 1654 | // At this point, nothing else needs to be shown in this task. |
| 1655 | behindFullscreenActivity = true; |
| 1656 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
| 1657 | + " stackInvisible=" + stackInvisible |
| 1658 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1659 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
| 1660 | behindFullscreenActivity = true; |
| 1661 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 1662 | + " stackInvisible=" + stackInvisible |
| 1663 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1664 | } |
| 1665 | return behindFullscreenActivity; |
| 1666 | } |
| 1667 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1668 | private void makeVisible(ActivityRecord starting, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1669 | // This activity is not currently visible, but is running. Tell it to become visible. |
| 1670 | r.visible = true; |
| 1671 | if (r.state != ActivityState.RESUMED && r != starting) { |
| 1672 | // If this activity is paused, tell it to now show its window. |
| 1673 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1674 | "Making visible and scheduling visibility: " + r); |
| 1675 | try { |
| 1676 | if (mTranslucentActivityWaiting != null) { |
| 1677 | r.updateOptionsLocked(r.returningOptions); |
| 1678 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
| 1679 | } |
| 1680 | setVisible(r, true); |
| 1681 | r.sleeping = false; |
| 1682 | r.app.pendingUiClean = true; |
| 1683 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1684 | r.stopFreezingScreenLocked(false); |
| 1685 | } catch (Exception e) { |
| 1686 | // Just skip on any failure; we'll make it |
| 1687 | // visible when it next restarts. |
| 1688 | Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e); |
| 1689 | } |
| 1690 | } |
| 1691 | } |
| 1692 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1693 | private boolean handleAlreadyVisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1694 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Skipping: already visible at " + r); |
| 1695 | r.stopFreezingScreenLocked(false); |
| 1696 | try { |
| 1697 | if (r.returningOptions != null) { |
| 1698 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions); |
| 1699 | } |
| 1700 | } catch(RemoteException e) { |
| 1701 | } |
| 1702 | return r.state == ActivityState.RESUMED; |
| 1703 | } |
| 1704 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1705 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1706 | mTranslucentActivityWaiting = r; |
| 1707 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1708 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1709 | } |
| 1710 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1711 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1712 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1713 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1714 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1715 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1716 | final ActivityRecord r = activities.get(activityNdx); |
| 1717 | if ( r.appTimeTracker != except) { |
| 1718 | r.appTimeTracker = null; |
| 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1724 | /** |
| 1725 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1726 | * redrawn notify the top activity by calling |
| 1727 | * {@link Activity#onTranslucentConversionComplete}. |
| 1728 | * |
| 1729 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1730 | * occurred and the activity will be notified immediately. |
| 1731 | */ |
| 1732 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1733 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1734 | if ((r == null) |
| 1735 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1736 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1737 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1738 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1739 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1740 | mTranslucentActivityWaiting = null; |
| 1741 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1742 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1743 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1744 | if (waitingActivity != null) { |
| 1745 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 1746 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 1747 | try { |
| 1748 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1749 | waitingActivity.appToken, r != null); |
| 1750 | } catch (RemoteException e) { |
| 1751 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1757 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 1758 | * starting window displayed then remove that starting window. It is possible that the activity |
| 1759 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 1760 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1761 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1762 | boolean aboveTop = true; |
| 1763 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1764 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1765 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1766 | final ActivityRecord r = activities.get(activityNdx); |
| 1767 | if (aboveTop) { |
| 1768 | if (r == topActivity) { |
| 1769 | aboveTop = false; |
| 1770 | } |
| 1771 | continue; |
| 1772 | } |
| 1773 | |
| 1774 | if (r.state == ActivityState.INITIALIZING && r.mStartingWindowShown) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1775 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 1776 | "Found orphaned starting window " + r); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1777 | r.mStartingWindowShown = false; |
| 1778 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 1779 | } |
| 1780 | } |
| 1781 | } |
| 1782 | } |
| 1783 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1784 | /** |
| 1785 | * Ensure that the top activity in the stack is resumed. |
| 1786 | * |
| 1787 | * @param prev The previously resumed activity, for when in the process |
| 1788 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1789 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1790 | * |
| 1791 | * @return Returns true if something is being resumed, or false if |
| 1792 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1793 | * |
| 1794 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 1795 | * non-focused stack to be resumed. |
| 1796 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 1797 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1798 | */ |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1799 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1800 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1801 | // Don't even start recursing. |
| 1802 | return false; |
| 1803 | } |
| 1804 | |
| 1805 | boolean result = false; |
| 1806 | try { |
| 1807 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1808 | mStackSupervisor.inResumeTopActivity = true; |
| 1809 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 1810 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 1811 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1812 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1813 | result = resumeTopActivityInnerLocked(prev, options); |
| 1814 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1815 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1816 | } |
| 1817 | return result; |
| 1818 | } |
| 1819 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1820 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1821 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1822 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1823 | if (!mService.mBooting && !mService.mBooted) { |
| 1824 | // Not ready yet! |
| 1825 | return false; |
| 1826 | } |
| 1827 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1828 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1829 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 1830 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1831 | // Do not resume this stack if its parent is not resumed. |
| 1832 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 1833 | return false; |
| 1834 | } |
| 1835 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1836 | cancelInitializingActivities(); |
| 1837 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1838 | // Find the first activity that is not finishing. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1839 | final ActivityRecord next = topRunningActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1840 | |
| 1841 | // Remember how we'll process this pause/resume situation, and ensure |
| 1842 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1843 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1844 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1845 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1846 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1847 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1848 | // There are no more activities! |
| 1849 | final String reason = "noMoreActivities"; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1850 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(reason)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1851 | // Try to move focus to the next visible stack with a running activity if this |
| 1852 | // stack is not covering the entire screen. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1853 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 1854 | mStackSupervisor.getFocusedStack(), prev, null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1855 | } |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1856 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1857 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1858 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1859 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1860 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1861 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1862 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1863 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1864 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1865 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1866 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1870 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1871 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1872 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1873 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1874 | // Make sure we have executed any pending transitions, since there |
| 1875 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1876 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1877 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1878 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1879 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1880 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1881 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1882 | return false; |
| 1883 | } |
| 1884 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1885 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 1886 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1887 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1888 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1889 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1890 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1891 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1892 | // 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] | 1893 | // 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] | 1894 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1895 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 1896 | } else if (!isOnHomeDisplay()) { |
| 1897 | return false; |
| 1898 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1899 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1900 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1901 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1902 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1903 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 1904 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1905 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1908 | // If we are sleeping, and there is no resumed activity, and the top |
| 1909 | // activity is paused, well that is the state we want. |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1910 | if (mService.isSleepingOrShuttingDown() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1911 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1912 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1913 | // Make sure we have executed any pending transitions, since there |
| 1914 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1915 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1916 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1917 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1918 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1919 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1920 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1921 | return false; |
| 1922 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1923 | |
| 1924 | // Make sure that the user who owns this activity is started. If not, |
| 1925 | // we will just leave it as is because someone should be bringing |
| 1926 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1927 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1928 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 1929 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1930 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1931 | return false; |
| 1932 | } |
| 1933 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1934 | // The activity may be waiting for stop, but that is no longer |
| 1935 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1936 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1937 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1938 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1939 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1940 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1941 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1942 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1943 | // If we are currently pausing an activity, then don't do anything |
| 1944 | // until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 1945 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1946 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1947 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1948 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1949 | return false; |
| 1950 | } |
| 1951 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1952 | // Okay we are now going to start a switch, to 'next'. We may first |
| 1953 | // have to pause the current activity, but this is an important point |
| 1954 | // 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] | 1955 | // XXX "App Redirected" dialog is getting too many false positives |
| 1956 | // at this point, so turn off for now. |
| 1957 | if (false) { |
| 1958 | if (mLastStartedActivity != null && !mLastStartedActivity.finishing) { |
| 1959 | long now = SystemClock.uptimeMillis(); |
| 1960 | final boolean inTime = mLastStartedActivity.startTime != 0 |
| 1961 | && (mLastStartedActivity.startTime + START_WARN_TIME) >= now; |
| 1962 | final int lastUid = mLastStartedActivity.info.applicationInfo.uid; |
| 1963 | final int nextUid = next.info.applicationInfo.uid; |
| 1964 | if (inTime && lastUid != nextUid |
| 1965 | && lastUid != next.launchedFromUid |
| 1966 | && mService.checkPermission( |
| 1967 | android.Manifest.permission.STOP_APP_SWITCHES, |
| 1968 | -1, next.launchedFromUid) |
| 1969 | != PackageManager.PERMISSION_GRANTED) { |
| 1970 | mService.showLaunchWarningLocked(mLastStartedActivity, next); |
| 1971 | } else { |
| 1972 | next.startTime = now; |
| 1973 | mLastStartedActivity = next; |
| 1974 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1975 | } else { |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1976 | next.startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1977 | mLastStartedActivity = next; |
| 1978 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1979 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1980 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1981 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 1982 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1983 | // We need to start pausing the current activity so the top one |
| 1984 | // can be resumed... |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1985 | boolean dontWaitForPause = (next.info.flags&ActivityInfo.FLAG_RESUME_WHILE_PAUSING) != 0; |
| 1986 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1987 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1988 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1989 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | e042bf2 | 2014-11-11 11:28:43 -0800 | [diff] [blame] | 1990 | pausing |= startPausingLocked(userLeaving, false, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1991 | } |
| 1992 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1993 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1994 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1995 | // At this point we want to put the upcoming activity's process |
| 1996 | // at the top of the LRU list, since we know we will be needing it |
| 1997 | // very soon and it would be a waste to let it get killed if it |
| 1998 | // happens to be sitting towards the end. |
| 1999 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2000 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2001 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2002 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2003 | return true; |
| 2004 | } |
| 2005 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2006 | // If the most recent activity was noHistory but was only stopped rather |
| 2007 | // than stopped+finished because the device went to sleep, we need to make |
| 2008 | // sure to finish it as we're making a new activity topmost. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2009 | if (mService.isSleeping() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2010 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2011 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2012 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2013 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2014 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2015 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2018 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2019 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2020 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2021 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2022 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2023 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2024 | } else { |
| 2025 | // The next activity is already visible, so hide the previous |
| 2026 | // activity's windows right now so we can show the new one ASAP. |
| 2027 | // We only do this if the previous is finishing, which should mean |
| 2028 | // it is on top of the one being resumed so hiding it quickly |
| 2029 | // is good. Otherwise, we want to do the normal route of allowing |
| 2030 | // the resumed activity to be shown so we can decide if the |
| 2031 | // previous should actually be hidden depending on whether the |
| 2032 | // new one is found to be full-screen or not. |
| 2033 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2034 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2035 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2036 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2037 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2038 | + ", nowVisible=" + next.nowVisible); |
| 2039 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2040 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2041 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2042 | + ", waitingVisible=" |
| 2043 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2044 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2049 | // Launching this app's activity, make sure the app is no longer |
| 2050 | // considered stopped. |
| 2051 | try { |
| 2052 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2053 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2054 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2055 | } catch (IllegalArgumentException e) { |
| 2056 | Slog.w(TAG, "Failed trying to unstop package " |
| 2057 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2058 | } |
| 2059 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2060 | // We are starting up the next activity, so tell the window manager |
| 2061 | // that the previous one will be hidden soon. This way it can know |
| 2062 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2063 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2064 | if (prev != null) { |
| 2065 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2066 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2067 | "Prepare close transition: prev=" + prev); |
| 2068 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2069 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2070 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2071 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2072 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2073 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 2074 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2075 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2076 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2077 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2078 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2079 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2080 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2081 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2082 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2083 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2084 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2085 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2086 | : next.mLaunchTaskBehind |
| 2087 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2088 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2089 | } |
| 2090 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2091 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2092 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2093 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2094 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2095 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2096 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2097 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2098 | } |
| 2099 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2100 | |
| 2101 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2102 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2103 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2104 | if (opts != null) { |
| 2105 | resumeAnimOptions = opts.toBundle(); |
| 2106 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2107 | next.applyOptionsLocked(); |
| 2108 | } else { |
| 2109 | next.clearOptionsLocked(); |
| 2110 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2111 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2112 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2113 | if (next.app != null && next.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2114 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2115 | |
| 2116 | // This activity is now becoming visible. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2117 | mWindowManager.setAppVisibility(next.appToken, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2118 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2119 | // schedule launch ticks to collect information about slow apps. |
| 2120 | next.startLaunchTickingLocked(); |
| 2121 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2122 | ActivityRecord lastResumedActivity = |
| 2123 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2124 | ActivityState lastState = next.state; |
| 2125 | |
| 2126 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2127 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2128 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next + " (in existing)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2129 | next.state = ActivityState.RESUMED; |
| 2130 | mResumedActivity = next; |
| 2131 | next.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 2132 | mRecentTasks.addLocked(next.task); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2133 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2134 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2135 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2136 | |
| 2137 | // Have the window manager re-evaluate the orientation of |
| 2138 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2139 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2140 | if (mStackSupervisor.isFocusedStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2141 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2142 | mService.mConfiguration, |
| 2143 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2144 | if (config != null) { |
| 2145 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2146 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2147 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2148 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2149 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2150 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2151 | // The configuration update wasn't able to keep the existing |
| 2152 | // instance of the activity, and instead started a new one. |
| 2153 | // We should be all done, but let's just make sure our activity |
| 2154 | // is still at the top and schedule another run if something |
| 2155 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2156 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2157 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2158 | "Activity config changed during resume: " + next |
| 2159 | + ", new next: " + nextNext); |
| 2160 | if (nextNext != next) { |
| 2161 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2162 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2163 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2164 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2165 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2166 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2167 | return true; |
| 2168 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2169 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2170 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2171 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2172 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2173 | try { |
| 2174 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2175 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2176 | if (a != null) { |
| 2177 | final int N = a.size(); |
| 2178 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2179 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2180 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2181 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2186 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2189 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2190 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2191 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2192 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2193 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2194 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2195 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2196 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2197 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2198 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2199 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2200 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2201 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2202 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2203 | } catch (Exception e) { |
| 2204 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2205 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2206 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2207 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2208 | if (lastStack != null) { |
| 2209 | lastStack.mResumedActivity = lastResumedActivity; |
| 2210 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2211 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2212 | if (!next.hasBeenLaunched) { |
| 2213 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2214 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2215 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2216 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2217 | next.appToken, next.packageName, next.theme, |
| 2218 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2219 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 2220 | next.windowFlags, null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2221 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2222 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2223 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2224 | return true; |
| 2225 | } |
| 2226 | |
| 2227 | // From this point on, if something goes wrong there is no way |
| 2228 | // to recover the activity. |
| 2229 | try { |
| 2230 | next.visible = true; |
| 2231 | completeResumeLocked(next); |
| 2232 | } catch (Exception e) { |
| 2233 | // If any exception gets thrown, toss away this |
| 2234 | // activity and try the next one. |
| 2235 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2236 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2237 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2238 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2239 | return true; |
| 2240 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2241 | next.stopped = false; |
| 2242 | |
| 2243 | } else { |
| 2244 | // Whoops, need to restart this activity! |
| 2245 | if (!next.hasBeenLaunched) { |
| 2246 | next.hasBeenLaunched = true; |
| 2247 | } else { |
| 2248 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2249 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2250 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2251 | mService.compatibilityInfoForPackageLocked( |
| 2252 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2253 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2254 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2255 | null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2256 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2257 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2258 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2259 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2260 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2263 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2264 | return true; |
| 2265 | } |
| 2266 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2267 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2268 | final int index = mTaskHistory.indexOf(targetTask); |
| 2269 | if (index >= 0) { |
| 2270 | final int numTasks = mTaskHistory.size(); |
| 2271 | for (int i = index + 1; i < numTasks; ++i) { |
| 2272 | TaskRecord task = mTaskHistory.get(i); |
| 2273 | if (task.userId == targetTask.userId) { |
| 2274 | return task; |
| 2275 | } |
| 2276 | } |
| 2277 | } |
| 2278 | return null; |
| 2279 | } |
| 2280 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2281 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2282 | if (position >= mTaskHistory.size()) { |
| 2283 | insertTaskAtTop(task, null); |
| 2284 | return; |
| 2285 | } |
| 2286 | // Calculate maximum possible position for this task. |
| 2287 | int maxPosition = mTaskHistory.size(); |
| 2288 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2289 | && task.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2290 | // Put non-current user tasks below current user tasks. |
| 2291 | while (maxPosition > 0) { |
| 2292 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2293 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2294 | || tmpTask.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2295 | break; |
| 2296 | } |
| 2297 | maxPosition--; |
| 2298 | } |
| 2299 | } |
| 2300 | position = Math.min(position, maxPosition); |
| 2301 | mTaskHistory.remove(task); |
| 2302 | mTaskHistory.add(position, task); |
| 2303 | updateTaskMovement(task, true); |
| 2304 | } |
| 2305 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2306 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2307 | // If the moving task is over home stack, transfer its return type to next task |
| 2308 | if (task.isOverHomeStack()) { |
| 2309 | final TaskRecord nextTask = getNextTask(task); |
| 2310 | if (nextTask != null) { |
| 2311 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
| 2312 | } |
| 2313 | } |
| 2314 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2315 | // 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] | 2316 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2317 | if (isOnHomeDisplay()) { |
| 2318 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2319 | final boolean fromHome = lastStack.isHomeStack(); |
| 2320 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Craig Mautner | 3b1dac8 | 2014-07-15 09:51:33 -0700 | [diff] [blame] | 2321 | task.setTaskToReturnTo(fromHome |
| 2322 | ? lastStack.topTask() == null |
| 2323 | ? HOME_ACTIVITY_TYPE |
| 2324 | : lastStack.topTask().taskType |
| 2325 | : APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2326 | } |
| 2327 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2328 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2329 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2330 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2331 | mTaskHistory.remove(task); |
| 2332 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2333 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2334 | final boolean notShownWhenLocked = |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2335 | (newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2336 | || (newActivity == null && task.topRunningActivityLocked() == null); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2337 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2338 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2339 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2340 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2341 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2342 | || tmpTask.topRunningActivityLocked() == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2343 | break; |
| 2344 | } |
| 2345 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2346 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2347 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2348 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2349 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2350 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2351 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 2352 | final void startActivityLocked(ActivityRecord r, boolean newTask, boolean keepCurTransition, |
| 2353 | ActivityOptions options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2354 | TaskRecord rTask = r.task; |
| 2355 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2356 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2357 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2358 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2359 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2360 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2361 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2362 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2363 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2364 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2365 | if (!newTask) { |
| 2366 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2367 | boolean startIt = true; |
| 2368 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2369 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2370 | if (task.getTopActivity() == null) { |
| 2371 | // All activities in task are finishing. |
| 2372 | continue; |
| 2373 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2374 | if (task == r.task) { |
| 2375 | // Here it is! Now, if this is not yet visible to the |
| 2376 | // user, then just add it without starting; it will |
| 2377 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2378 | if (!startIt) { |
| 2379 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2380 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2381 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2382 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2383 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2384 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2385 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2386 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2387 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2388 | return; |
| 2389 | } |
| 2390 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2391 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2392 | startIt = false; |
| 2393 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | // Place a new activity at top of stack, so it is next to interact |
| 2398 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2399 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2400 | // If we are not placing the new activity frontmost, we do not want |
| 2401 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2402 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2403 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2404 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2405 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2406 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2407 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2408 | |
| 2409 | task = r.task; |
| 2410 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2411 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2412 | 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] | 2413 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2414 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2415 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2416 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2417 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2418 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2419 | // We want to show the starting preview window if we are |
| 2420 | // switching to a new task, or the next activity's process is |
| 2421 | // not currently running. |
| 2422 | boolean showStartingIcon = newTask; |
| 2423 | ProcessRecord proc = r.app; |
| 2424 | if (proc == null) { |
| 2425 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2426 | } |
| 2427 | if (proc == null || proc.thread == null) { |
| 2428 | showStartingIcon = true; |
| 2429 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2430 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2431 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2432 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2433 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2434 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2435 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2436 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2437 | ? r.mLaunchTaskBehind |
| 2438 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2439 | : AppTransition.TRANSIT_TASK_OPEN |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2440 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2441 | mNoAnimActivities.remove(r); |
| 2442 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2443 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2444 | boolean doShow = true; |
| 2445 | if (newTask) { |
| 2446 | // Even though this activity is starting fresh, we still need |
| 2447 | // to reset it to make sure we apply affinities to move any |
| 2448 | // existing activities from other tasks in to it. |
| 2449 | // If the caller has requested that the target task be |
| 2450 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2451 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2452 | resetTaskIfNeededLocked(r, r); |
| 2453 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2454 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2455 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2456 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2457 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2458 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2459 | if (r.mLaunchTaskBehind) { |
| 2460 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2461 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2462 | mWindowManager.setAppVisibility(r.appToken, true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2463 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2464 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2465 | // Figure out if we are transitioning from another activity that is |
| 2466 | // "has the same starting icon" as the next one. This allows the |
| 2467 | // window manager to keep the previous window it had previously |
| 2468 | // created, if it still had one. |
| 2469 | ActivityRecord prev = mResumedActivity; |
| 2470 | if (prev != null) { |
| 2471 | // We don't want to reuse the previous starting preview if: |
| 2472 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2473 | if (prev.task != r.task) { |
| 2474 | prev = null; |
| 2475 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2476 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2477 | else if (prev.nowVisible) { |
| 2478 | prev = null; |
| 2479 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2480 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2481 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2482 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2483 | mService.compatibilityInfoForPackageLocked( |
| 2484 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2485 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2486 | prev != null ? prev.appToken : null, showStartingIcon); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2487 | r.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2488 | } |
| 2489 | } else { |
| 2490 | // If this is the first activity, don't do any fancy animations, |
| 2491 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2492 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2493 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2494 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2495 | } |
| 2496 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2497 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2498 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2501 | final void validateAppTokensLocked() { |
| 2502 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2503 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2504 | final int numTasks = mTaskHistory.size(); |
| 2505 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2506 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2507 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2508 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2509 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2510 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2511 | TaskGroup group = new TaskGroup(); |
| 2512 | group.taskId = task.taskId; |
| 2513 | mValidateAppTokens.add(group); |
| 2514 | final int numActivities = activities.size(); |
| 2515 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2516 | final ActivityRecord r = activities.get(activityNdx); |
| 2517 | group.tokens.add(r.appToken); |
| 2518 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2519 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2520 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2521 | } |
| 2522 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2523 | /** |
| 2524 | * Perform a reset of the given task, if needed as part of launching it. |
| 2525 | * Returns the new HistoryRecord at the top of the task. |
| 2526 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2527 | /** |
| 2528 | * Helper method for #resetTaskIfNeededLocked. |
| 2529 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2530 | * for another task, or leave it as-is. |
| 2531 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2532 | * @param forceReset |
| 2533 | * @return An ActivityOptions that needs to be processed. |
| 2534 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2535 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2536 | ActivityOptions topOptions = null; |
| 2537 | |
| 2538 | int replyChainEnd = -1; |
| 2539 | boolean canMoveOptions = true; |
| 2540 | |
| 2541 | // We only do this for activities that are not the root of the task (since if we finish |
| 2542 | // the root, we may no longer have the task!). |
| 2543 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2544 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2545 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2546 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2547 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2548 | if (target.frontOfTask) |
| 2549 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2550 | |
| 2551 | final int flags = target.info.flags; |
| 2552 | final boolean finishOnTaskLaunch = |
| 2553 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2554 | final boolean allowTaskReparenting = |
| 2555 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2556 | final boolean clearWhenTaskReset = |
| 2557 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2558 | |
| 2559 | if (!finishOnTaskLaunch |
| 2560 | && !clearWhenTaskReset |
| 2561 | && target.resultTo != null) { |
| 2562 | // If this activity is sending a reply to a previous |
| 2563 | // activity, we can't do anything with it now until |
| 2564 | // we reach the start of the reply chain. |
| 2565 | // XXX note that we are assuming the result is always |
| 2566 | // to the previous activity, which is almost always |
| 2567 | // the case but we really shouldn't count on. |
| 2568 | if (replyChainEnd < 0) { |
| 2569 | replyChainEnd = i; |
| 2570 | } |
| 2571 | } else if (!finishOnTaskLaunch |
| 2572 | && !clearWhenTaskReset |
| 2573 | && allowTaskReparenting |
| 2574 | && target.taskAffinity != null |
| 2575 | && !target.taskAffinity.equals(task.affinity)) { |
| 2576 | // If this activity has an affinity for another |
| 2577 | // task, then we need to move it out of here. We will |
| 2578 | // move it as far out of the way as possible, to the |
| 2579 | // bottom of the activity stack. This also keeps it |
| 2580 | // correctly ordered with any activities we previously |
| 2581 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2582 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2583 | final ActivityRecord bottom = |
| 2584 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2585 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2586 | if (bottom != null && target.taskAffinity != null |
| 2587 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2588 | // If the activity currently at the bottom has the |
| 2589 | // same task affinity as the one we are moving, |
| 2590 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2591 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2592 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2593 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2594 | } else { |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2595 | targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2596 | null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2597 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2598 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2599 | + " out to new task " + target.task); |
| 2600 | } |
| 2601 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2602 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2603 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2604 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2605 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2606 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2607 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2608 | if (p.finishing) { |
| 2609 | continue; |
| 2610 | } |
| 2611 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2612 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2613 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2614 | topOptions = p.takeOptionsLocked(); |
| 2615 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2616 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2617 | } |
| 2618 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2619 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2620 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2621 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2622 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2623 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2624 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2625 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2626 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2627 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2628 | } |
| 2629 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2630 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2631 | if (VALIDATE_TOKENS) { |
| 2632 | validateAppTokensLocked(); |
| 2633 | } |
| 2634 | |
| 2635 | replyChainEnd = -1; |
| 2636 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2637 | // If the activity should just be removed -- either |
| 2638 | // because it asks for it, or the task should be |
| 2639 | // cleared -- then finish it and anything that is |
| 2640 | // part of its reply chain. |
| 2641 | int end; |
| 2642 | if (clearWhenTaskReset) { |
| 2643 | // In this case, we want to finish this activity |
| 2644 | // and everything above it, so be sneaky and pretend |
| 2645 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2646 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2647 | } else if (replyChainEnd < 0) { |
| 2648 | end = i; |
| 2649 | } else { |
| 2650 | end = replyChainEnd; |
| 2651 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2652 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2653 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2654 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2655 | if (p.finishing) { |
| 2656 | continue; |
| 2657 | } |
| 2658 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2659 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2660 | topOptions = p.takeOptionsLocked(); |
| 2661 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2662 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2663 | } |
| 2664 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2665 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2666 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2667 | if (finishActivityLocked( |
| 2668 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2669 | end--; |
| 2670 | srcPos--; |
| 2671 | } |
| 2672 | } |
| 2673 | replyChainEnd = -1; |
| 2674 | } else { |
| 2675 | // If we were in the middle of a chain, well the |
| 2676 | // activity that started it all doesn't want anything |
| 2677 | // special, so leave it all as-is. |
| 2678 | replyChainEnd = -1; |
| 2679 | } |
| 2680 | } |
| 2681 | |
| 2682 | return topOptions; |
| 2683 | } |
| 2684 | |
| 2685 | /** |
| 2686 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2687 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2688 | * @param affinityTask The task we are looking for an affinity to. |
| 2689 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2690 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2691 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2692 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2693 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2694 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2695 | int replyChainEnd = -1; |
| 2696 | final int taskId = task.taskId; |
| 2697 | final String taskAffinity = task.affinity; |
| 2698 | |
| 2699 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2700 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2701 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 2702 | |
| 2703 | // Do not operate on or below the effective root Activity. |
| 2704 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2705 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2706 | if (target.frontOfTask) |
| 2707 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2708 | |
| 2709 | final int flags = target.info.flags; |
| 2710 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2711 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2712 | |
| 2713 | if (target.resultTo != null) { |
| 2714 | // If this activity is sending a reply to a previous |
| 2715 | // activity, we can't do anything with it now until |
| 2716 | // we reach the start of the reply chain. |
| 2717 | // XXX note that we are assuming the result is always |
| 2718 | // to the previous activity, which is almost always |
| 2719 | // the case but we really shouldn't count on. |
| 2720 | if (replyChainEnd < 0) { |
| 2721 | replyChainEnd = i; |
| 2722 | } |
| 2723 | } else if (topTaskIsHigher |
| 2724 | && allowTaskReparenting |
| 2725 | && taskAffinity != null |
| 2726 | && taskAffinity.equals(target.taskAffinity)) { |
| 2727 | // This activity has an affinity for our task. Either remove it if we are |
| 2728 | // clearing or move it over to our task. Note that |
| 2729 | // we currently punt on the case where we are resetting a |
| 2730 | // task that is not at the top but who has activities above |
| 2731 | // with an affinity to it... this is really not a normal |
| 2732 | // case, and we will need to later pull that task to the front |
| 2733 | // and usually at that point we will do the reset and pick |
| 2734 | // up those remaining activities. (This only happens if |
| 2735 | // someone starts an activity in a new task from an activity |
| 2736 | // in a task that is not currently on top.) |
| 2737 | if (forceReset || finishOnTaskLaunch) { |
| 2738 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2739 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2740 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2741 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2742 | final ActivityRecord p = activities.get(srcPos); |
| 2743 | if (p.finishing) { |
| 2744 | continue; |
| 2745 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2746 | finishActivityLocked( |
| 2747 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2748 | } |
| 2749 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2750 | if (taskInsertionPoint < 0) { |
| 2751 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2752 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2753 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2754 | |
| 2755 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2756 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2757 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 2758 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2759 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2760 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2761 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2762 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2763 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2764 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2765 | "Removing and adding activity " + p + " to stack at " + task |
| 2766 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2767 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 2768 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2769 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2770 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2771 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2772 | if (VALIDATE_TOKENS) { |
| 2773 | validateAppTokensLocked(); |
| 2774 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2775 | |
| 2776 | // Now we've moved it in to place... but what if this is |
| 2777 | // a singleTop activity and we have put it on top of another |
| 2778 | // instance of the same activity? Then we drop the instance |
| 2779 | // below so it remains singleTop. |
| 2780 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2781 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2782 | int targetNdx = taskActivities.indexOf(target); |
| 2783 | if (targetNdx > 0) { |
| 2784 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2785 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2786 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2787 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2788 | } |
| 2789 | } |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | replyChainEnd = -1; |
| 2794 | } |
| 2795 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2796 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2797 | } |
| 2798 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2799 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2800 | ActivityRecord newActivity) { |
| 2801 | boolean forceReset = |
| 2802 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2803 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2804 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2805 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2806 | forceReset = true; |
| 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | final TaskRecord task = taskTop.task; |
| 2811 | |
| 2812 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2813 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2814 | boolean taskFound = false; |
| 2815 | |
| 2816 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2817 | ActivityOptions topOptions = null; |
| 2818 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2819 | // Preserve the location for reparenting in the new task. |
| 2820 | int reparentInsertionPoint = -1; |
| 2821 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2822 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2823 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2824 | |
| 2825 | if (targetTask == task) { |
| 2826 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2827 | taskFound = true; |
| 2828 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2829 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2830 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2831 | } |
| 2832 | } |
| 2833 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2834 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 2835 | if (taskNdx >= 0) { |
| 2836 | do { |
| 2837 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2838 | } while (taskTop == null && taskNdx >= 0); |
| 2839 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2840 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2841 | if (topOptions != null) { |
| 2842 | // If we got some ActivityOptions from an activity on top that |
| 2843 | // was removed from the task, propagate them to the new real top. |
| 2844 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2845 | taskTop.updateOptionsLocked(topOptions); |
| 2846 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2847 | topOptions.abort(); |
| 2848 | } |
| 2849 | } |
| 2850 | |
| 2851 | return taskTop; |
| 2852 | } |
| 2853 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2854 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2855 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2856 | |
| 2857 | if (callingUid > 0) { |
| 2858 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2859 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2863 | + " : who=" + resultWho + " req=" + requestCode |
| 2864 | + " res=" + resultCode + " data=" + data); |
| 2865 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2866 | try { |
| 2867 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2868 | list.add(new ResultInfo(resultWho, requestCode, |
| 2869 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2870 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2871 | return; |
| 2872 | } catch (Exception e) { |
| 2873 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2878 | } |
| 2879 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2880 | private void adjustFocusedActivityLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2881 | if (!mStackSupervisor.isFocusedStack(this) || mService.mFocusedActivity != r) { |
| 2882 | return; |
| 2883 | } |
| 2884 | |
| 2885 | final ActivityRecord next = topRunningActivityLocked(); |
| 2886 | final String myReason = reason + " adjustFocus"; |
| 2887 | if (next != r) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2888 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2889 | // For freeform, docked, and pinned stacks we always keep the focus within the |
| 2890 | // stack as long as there is a running activity in the stack that we can adjust |
| 2891 | // focus to. |
| 2892 | mService.setFocusedActivityLocked(next, myReason); |
| 2893 | return; |
| 2894 | } else { |
| 2895 | final TaskRecord task = r.task; |
| 2896 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
| 2897 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 2898 | // stack to prevent the home screen from moving to the top and obscuring |
| 2899 | // other visible stacks. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2900 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2901 | return; |
| 2902 | } |
| 2903 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 2904 | // other visible stack. |
| 2905 | if (mStackSupervisor.moveHomeStackTaskToTop( |
| 2906 | task.getTaskToReturnTo(), myReason)) { |
| 2907 | // Activity focus was already adjusted. Nothing else to do... |
| 2908 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 2909 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2910 | } |
| 2911 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2912 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2913 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2914 | mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked(), myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2915 | } |
| 2916 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2917 | private boolean adjustFocusToNextFocusableStackLocked(String reason) { |
| 2918 | final ActivityStack stack = getNextFocusableStackLocked(); |
| 2919 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2920 | if (stack == null) { |
| 2921 | return false; |
| 2922 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2923 | return mService.setFocusedActivityLocked(stack.topRunningActivityLocked(), myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2924 | } |
| 2925 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2926 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2927 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2928 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2929 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2930 | if (!r.finishing) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2931 | if (!mService.isSleeping()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2932 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 2933 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 2934 | "stop-no-history", false)) { |
| 2935 | // Activity was finished, no need to continue trying to schedule stop. |
| 2936 | adjustFocusedActivityLocked(r, "stopActivityFinished"); |
| 2937 | r.resumeKeyDispatchingLocked(); |
| 2938 | return; |
| 2939 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2940 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2941 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2942 | + " on stop because we're just sleeping"); |
| 2943 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2944 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2948 | adjustFocusedActivityLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2949 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2950 | try { |
| 2951 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2952 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 2953 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2954 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2955 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2956 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2957 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2958 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2959 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2960 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 2961 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2962 | r.setSleeping(true); |
| 2963 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2964 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2965 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2966 | } catch (Exception e) { |
| 2967 | // Maybe just ignore exceptions here... if the process |
| 2968 | // has crashed, our death notification will clean things |
| 2969 | // up. |
| 2970 | Slog.w(TAG, "Exception thrown during pause", e); |
| 2971 | // Just in case, assume it to be stopped. |
| 2972 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2973 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Stop failed; moving to STOPPED: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2974 | r.state = ActivityState.STOPPED; |
| 2975 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2976 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2977 | } |
| 2978 | } |
| 2979 | } |
| 2980 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 2981 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2982 | /** |
| 2983 | * @return Returns true if the activity is being finished, false if for |
| 2984 | * some reason it is being left as-is. |
| 2985 | */ |
| 2986 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2987 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2988 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2989 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 2990 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2991 | + ", result=" + resultCode + ", data=" + resultData |
| 2992 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2993 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2994 | return false; |
| 2995 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2996 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2997 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2998 | return true; |
| 2999 | } |
| 3000 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3001 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3002 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3003 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3004 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3005 | ActivityRecord r = activities.get(activityNdx); |
| 3006 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3007 | if ((r.resultWho == null && resultWho == null) || |
| 3008 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3009 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3010 | false); |
| 3011 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3012 | } |
| 3013 | } |
| 3014 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3015 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3018 | final void finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3019 | ActivityRecord r = topRunningActivityLocked(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3020 | if (r != null && r.app == app) { |
| 3021 | // If the top running activity is from this crashing |
| 3022 | // process, then terminate it to avoid getting in a loop. |
| 3023 | Slog.w(TAG, " Force finishing activity " |
| 3024 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3025 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 3026 | int activityNdx = r.task.mActivities.indexOf(r); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3027 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3028 | // Also terminate any activities below it that aren't yet |
| 3029 | // stopped, to avoid a situation where one will get |
| 3030 | // re-start our crashing activity once it gets resumed again. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3031 | --activityNdx; |
| 3032 | if (activityNdx < 0) { |
| 3033 | do { |
| 3034 | --taskNdx; |
| 3035 | if (taskNdx < 0) { |
| 3036 | break; |
| 3037 | } |
| 3038 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3039 | } while (activityNdx < 0); |
| 3040 | } |
| 3041 | if (activityNdx >= 0) { |
| 3042 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3043 | if (r.state == ActivityState.RESUMED |
| 3044 | || r.state == ActivityState.PAUSING |
| 3045 | || r.state == ActivityState.PAUSED) { |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 3046 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3047 | Slog.w(TAG, " Force finishing activity " |
| 3048 | + r.intent.getComponent().flattenToShortString()); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3049 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3050 | } |
| 3051 | } |
| 3052 | } |
| 3053 | } |
| 3054 | } |
| 3055 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3056 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3057 | IBinder sessionBinder = session.asBinder(); |
| 3058 | boolean didOne = false; |
| 3059 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3060 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3061 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3062 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3063 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3064 | if (!r.finishing) { |
| 3065 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3066 | false); |
| 3067 | didOne = true; |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | } |
| 3072 | if (didOne) { |
| 3073 | mService.updateOomAdjLocked(); |
| 3074 | } |
| 3075 | } |
| 3076 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3077 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3078 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 3079 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3080 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3081 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3082 | break; |
| 3083 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3084 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3085 | } |
| 3086 | return true; |
| 3087 | } |
| 3088 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3089 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 3090 | // send the result |
| 3091 | ActivityRecord resultTo = r.resultTo; |
| 3092 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3093 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3094 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3095 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3096 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3097 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3098 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3099 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3100 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3101 | if (r.info.applicationInfo.uid > 0) { |
| 3102 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3103 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3104 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3105 | } |
| 3106 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3107 | resultData); |
| 3108 | r.resultTo = null; |
| 3109 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3110 | else if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "No result destination from " + r); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3111 | |
| 3112 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3113 | // because clients have remote IPC references to this object so we |
| 3114 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3115 | r.results = null; |
| 3116 | r.pendingResults = null; |
| 3117 | r.newIntents = null; |
| 3118 | r.icicle = null; |
| 3119 | } |
| 3120 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3121 | /** |
| 3122 | * @return Returns true if this activity has been removed from the history |
| 3123 | * list, or false if it is still in the list and will be removed later. |
| 3124 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3125 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3126 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3127 | if (r.finishing) { |
| 3128 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3129 | return false; |
| 3130 | } |
| 3131 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3132 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3133 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3134 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3135 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3136 | task.taskId, r.shortComponentName, reason); |
| 3137 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3138 | final int index = activities.indexOf(r); |
| 3139 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3140 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3141 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3142 | // If the caller asked that this activity (and all above it) |
| 3143 | // be cleared when the task is reset, don't lose that information, |
| 3144 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3145 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3146 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3151 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3152 | adjustFocusedActivityLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3153 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3154 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3155 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3156 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3157 | boolean endTask = index <= 0; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3158 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3159 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3160 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3161 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 3162 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3163 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3164 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3165 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3166 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3167 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3168 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3169 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3170 | "finish() => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3171 | startPausingLocked(false, false, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3174 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3175 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3176 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3177 | } else if (r.state != ActivityState.PAUSING) { |
| 3178 | // If the activity is PAUSING, we will complete the finish once |
| 3179 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3180 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3181 | if (r.visible) { |
| 3182 | mWindowManager.setAppVisibility(r.appToken, false); |
| 3183 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3184 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3185 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3186 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | return false; |
| 3190 | } |
| 3191 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3192 | static final int FINISH_IMMEDIATELY = 0; |
| 3193 | static final int FINISH_AFTER_PAUSE = 1; |
| 3194 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3195 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3196 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3197 | // First things first: if this activity is currently visible, |
| 3198 | // and the resumed activity is not yet visible, then hold off on |
| 3199 | // finishing until the resumed one becomes visible. |
| 3200 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3201 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 3202 | addToStopping(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3203 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3204 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3205 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3206 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3207 | if (oomAdj) { |
| 3208 | mService.updateOomAdjLocked(); |
| 3209 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3210 | return r; |
| 3211 | } |
| 3212 | |
| 3213 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3214 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3215 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3216 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3217 | if (mResumedActivity == r) { |
| 3218 | mResumedActivity = null; |
| 3219 | } |
| 3220 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3221 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3222 | r.state = ActivityState.FINISHING; |
| 3223 | |
| 3224 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3225 | || (mode == FINISH_AFTER_PAUSE && prevState == ActivityState.PAUSED) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3226 | || prevState == ActivityState.STOPPED |
| 3227 | || prevState == ActivityState.INITIALIZING) { |
| 3228 | // If this activity is already stopped, we can just finish |
| 3229 | // it right now. |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3230 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3231 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3232 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3233 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3234 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3235 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3236 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3237 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3238 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3239 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3240 | |
| 3241 | // Need to go through the full pause cycle to get this |
| 3242 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3243 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3244 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3245 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3246 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3247 | return r; |
| 3248 | } |
| 3249 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3250 | void finishAllActivitiesLocked(boolean immediately) { |
| 3251 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3252 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3253 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3254 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3255 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3256 | noActivitiesInStack = false; |
| 3257 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3258 | continue; |
| 3259 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3260 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3261 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3262 | } |
| 3263 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3264 | if (noActivitiesInStack) { |
| 3265 | mActivityContainer.onTaskListEmptyLocked(); |
| 3266 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3269 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3270 | // Basic case: for simple app-centric recents, we need to recreate |
| 3271 | // the task if the affinity has changed. |
| 3272 | if (srec == null || srec.task.affinity == null || |
| 3273 | !srec.task.affinity.equals(destAffinity)) { |
| 3274 | return true; |
| 3275 | } |
| 3276 | // Document-centric case: an app may be split in to multiple documents; |
| 3277 | // they need to re-create their task if this current activity is the root |
| 3278 | // of a document, unless simply finishing it will return them to the the |
| 3279 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3280 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3281 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3282 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3283 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3284 | // Finishing won't return to an application, so we need to recreate. |
| 3285 | return true; |
| 3286 | } |
| 3287 | // We now need to get the task below it to determine what to do. |
| 3288 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3289 | if (taskIdx <= 0) { |
| 3290 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3291 | return false; |
| 3292 | } |
| 3293 | if (taskIdx == 0) { |
| 3294 | // At the bottom of the stack, nothing to go back to. |
| 3295 | return true; |
| 3296 | } |
| 3297 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3298 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3299 | // These are different apps, so need to recreate. |
| 3300 | return true; |
| 3301 | } |
| 3302 | } |
| 3303 | return false; |
| 3304 | } |
| 3305 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3306 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3307 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3308 | final TaskRecord task = srec.task; |
| 3309 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3310 | final int start = activities.indexOf(srec); |
| 3311 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3312 | return false; |
| 3313 | } |
| 3314 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3315 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3316 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3317 | final ComponentName dest = destIntent.getComponent(); |
| 3318 | if (start > 0 && dest != null) { |
| 3319 | for (int i = finishTo; i >= 0; i--) { |
| 3320 | ActivityRecord r = activities.get(i); |
| 3321 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3322 | r.info.name.equals(dest.getClassName())) { |
| 3323 | finishTo = i; |
| 3324 | parent = r; |
| 3325 | foundParentInTask = true; |
| 3326 | break; |
| 3327 | } |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | IActivityController controller = mService.mController; |
| 3332 | if (controller != null) { |
| 3333 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3334 | if (next != null) { |
| 3335 | // ask watcher if this is allowed |
| 3336 | boolean resumeOK = true; |
| 3337 | try { |
| 3338 | resumeOK = controller.activityResuming(next.packageName); |
| 3339 | } catch (RemoteException e) { |
| 3340 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3341 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | if (!resumeOK) { |
| 3345 | return false; |
| 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | final long origId = Binder.clearCallingIdentity(); |
| 3350 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3351 | ActivityRecord r = activities.get(i); |
| 3352 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3353 | // Only return the supplied result for the first activity finished |
| 3354 | resultCode = Activity.RESULT_CANCELED; |
| 3355 | resultData = null; |
| 3356 | } |
| 3357 | |
| 3358 | if (parent != null && foundParentInTask) { |
| 3359 | final int parentLaunchMode = parent.info.launchMode; |
| 3360 | final int destIntentFlags = destIntent.getFlags(); |
| 3361 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3362 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3363 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3364 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3365 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3366 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3367 | } else { |
| 3368 | try { |
| 3369 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3370 | destIntent.getComponent(), 0, srec.userId); |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 3371 | int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, |
| 3372 | destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, |
| 3373 | null, parent.appToken, null, 0, -1, parent.launchedFromUid, |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 3374 | parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, |
| 3375 | false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3376 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3377 | } catch (RemoteException e) { |
| 3378 | foundParentInTask = false; |
| 3379 | } |
| 3380 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3381 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3382 | } |
| 3383 | } |
| 3384 | Binder.restoreCallingIdentity(origId); |
| 3385 | return foundParentInTask; |
| 3386 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3387 | /** |
| 3388 | * Perform the common clean-up of an activity record. This is called both |
| 3389 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3390 | * representation) and cleaning things up as a result of its hosting |
| 3391 | * processing going away, in which case there is no remaining client-side |
| 3392 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3393 | * |
| 3394 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3395 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3396 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3397 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3398 | if (mResumedActivity == r) { |
| 3399 | mResumedActivity = null; |
| 3400 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3401 | if (mPausingActivity == r) { |
| 3402 | mPausingActivity = null; |
| 3403 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3404 | mService.resetFocusedActivityIfNeededLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3405 | |
| 3406 | r.configDestroy = false; |
| 3407 | r.frozenBeforeDestroy = false; |
| 3408 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3409 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3410 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (cleaning up)"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3411 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3412 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during cleanUp for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3413 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3416 | // Make sure this record is no longer in the pending finishes list. |
| 3417 | // This could happen, for example, if we are trimming activities |
| 3418 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3419 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3420 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3421 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3422 | // Remove any pending results. |
| 3423 | if (r.finishing && r.pendingResults != null) { |
| 3424 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3425 | PendingIntentRecord rec = apr.get(); |
| 3426 | if (rec != null) { |
| 3427 | mService.cancelIntentSenderLocked(rec, false); |
| 3428 | } |
| 3429 | } |
| 3430 | r.pendingResults = null; |
| 3431 | } |
| 3432 | |
| 3433 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3434 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3437 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3438 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3439 | if (getVisibleBehindActivity() == r) { |
| 3440 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3441 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3445 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3446 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3447 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3448 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3449 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3452 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3453 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3454 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3455 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3456 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3457 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3458 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3459 | r.takeFromHistory(); |
| 3460 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3461 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3462 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3463 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3464 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during remove for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3465 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3466 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3467 | if (VALIDATE_TOKENS) { |
| 3468 | validateAppTokensLocked(); |
| 3469 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3470 | final TaskRecord task = r.task; |
| 3471 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3472 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3473 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3474 | if (mStackSupervisor.isFocusedStack(this) && task == topTask() && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3475 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3476 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3477 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3478 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3479 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3480 | cleanUpActivityServicesLocked(r); |
| 3481 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3482 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3483 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3484 | /** |
| 3485 | * Perform clean-up of service connections in an activity record. |
| 3486 | */ |
| 3487 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3488 | // Throw away any services that have been bound by this activity. |
| 3489 | if (r.connections != null) { |
| 3490 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3491 | while (it.hasNext()) { |
| 3492 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3493 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3494 | } |
| 3495 | r.connections = null; |
| 3496 | } |
| 3497 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3498 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3499 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3500 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3501 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3502 | mHandler.sendMessage(msg); |
| 3503 | } |
| 3504 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3505 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3506 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3507 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3508 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3509 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3510 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3511 | final ActivityRecord r = activities.get(activityNdx); |
| 3512 | if (r.finishing) { |
| 3513 | continue; |
| 3514 | } |
| 3515 | if (r.fullscreen) { |
| 3516 | lastIsOpaque = true; |
| 3517 | } |
| 3518 | if (owner != null && r.app != owner) { |
| 3519 | continue; |
| 3520 | } |
| 3521 | if (!lastIsOpaque) { |
| 3522 | continue; |
| 3523 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3524 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3525 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Destroying " + r + " in state " + r.state |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3526 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3527 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3528 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3529 | activityRemoved = true; |
| 3530 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3531 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3532 | } |
| 3533 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3534 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3535 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3536 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3539 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3540 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3541 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3542 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3543 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3544 | return destroyActivityLocked(r, true, reason); |
| 3545 | } |
| 3546 | return false; |
| 3547 | } |
| 3548 | |
| 3549 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3550 | String reason) { |
| 3551 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3552 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3553 | int maxTasks = tasks.size() / 4; |
| 3554 | if (maxTasks < 1) { |
| 3555 | maxTasks = 1; |
| 3556 | } |
| 3557 | int numReleased = 0; |
| 3558 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3559 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3560 | if (!tasks.contains(task)) { |
| 3561 | continue; |
| 3562 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3563 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Looking for activities to release in " + task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3564 | int curNum = 0; |
| 3565 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3566 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3567 | final ActivityRecord activity = activities.get(actNdx); |
| 3568 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3569 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3570 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3571 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3572 | destroyActivityLocked(activity, true, reason); |
| 3573 | if (activities.get(actNdx) != activity) { |
| 3574 | // Was removed from list, back up so we don't miss the next one. |
| 3575 | actNdx--; |
| 3576 | } |
| 3577 | curNum++; |
| 3578 | } |
| 3579 | } |
| 3580 | if (curNum > 0) { |
| 3581 | numReleased += curNum; |
| 3582 | maxTasks--; |
| 3583 | if (mTaskHistory.get(taskNdx) != task) { |
| 3584 | // The entire task got removed, back up so we don't miss the next one. |
| 3585 | taskNdx--; |
| 3586 | } |
| 3587 | } |
| 3588 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3589 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3590 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3591 | return numReleased; |
| 3592 | } |
| 3593 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3594 | /** |
| 3595 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3596 | * called both when actually finishing an activity, or when performing |
| 3597 | * a configuration switch where we destroy the current client-side object |
| 3598 | * but then create a new client-side object for this same HistoryRecord. |
| 3599 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3600 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3601 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3602 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3603 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3604 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3605 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3606 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3607 | |
| 3608 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3609 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3610 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3611 | |
| 3612 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3613 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3614 | if (hadApp) { |
| 3615 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3616 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3617 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 3618 | mService.mHeavyWeightProcess = null; |
| 3619 | mService.mHandler.sendEmptyMessage( |
| 3620 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 3621 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3622 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 3623 | // Update any services we are bound to that might care about whether |
| 3624 | // their client may have activities. |
| 3625 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 3626 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 3627 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3628 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3633 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3634 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3635 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3636 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3637 | r.configChangeFlags); |
| 3638 | } catch (Exception e) { |
| 3639 | // We can just ignore exceptions here... if the process |
| 3640 | // has crashed, our death notification will clean things |
| 3641 | // up. |
| 3642 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 3643 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3644 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3645 | removedFromHistory = true; |
| 3646 | skipDestroy = true; |
| 3647 | } |
| 3648 | } |
| 3649 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3650 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3651 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3652 | // If the activity is finishing, we need to wait on removing it |
| 3653 | // from the list to give it a chance to do its cleanup. During |
| 3654 | // that time it may make calls back with its token so we need to |
| 3655 | // be able to find it on the list and so we don't want to remove |
| 3656 | // it from the list yet. Otherwise, we can just immediately put |
| 3657 | // it in the destroyed state since we are not removing it from the |
| 3658 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3659 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3660 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3661 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3662 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3663 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3664 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 3665 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3666 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3667 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3668 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3669 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3670 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3671 | } |
| 3672 | } else { |
| 3673 | // remove this record from the history. |
| 3674 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3675 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3676 | removedFromHistory = true; |
| 3677 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3678 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (no app)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3679 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3680 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3681 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3686 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3687 | if (!mLRUActivities.remove(r) && hadApp) { |
| 3688 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 3689 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3690 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3691 | return removedFromHistory; |
| 3692 | } |
| 3693 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3694 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3695 | final long origId = Binder.clearCallingIdentity(); |
| 3696 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3697 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3698 | if (r != null) { |
| 3699 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3700 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3701 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3702 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3703 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3704 | if (r.state == ActivityState.DESTROYING) { |
| 3705 | cleanUpActivityLocked(r, true, false); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3706 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3707 | } |
| 3708 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3709 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3710 | } finally { |
| 3711 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3712 | } |
| 3713 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3714 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 3715 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3716 | if (hasVisibleBehindActivity() && |
| 3717 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3718 | if (r == topRunningActivityLocked()) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3719 | // Don't release the top activity if it has requested to run behind the next |
| 3720 | // activity. |
| 3721 | return; |
| 3722 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3723 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3724 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3725 | " thread=" + r.app.thread); |
| 3726 | if (r != null && r.app != null && r.app.thread != null) { |
| 3727 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3728 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3729 | } catch (RemoteException e) { |
| 3730 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3731 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3732 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3733 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3734 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3735 | } |
| 3736 | } |
| 3737 | } |
| 3738 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3739 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3740 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 3741 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3742 | if (r != null) { |
| 3743 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3744 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3745 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3746 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3747 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3750 | boolean hasVisibleBehindActivity() { |
| 3751 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3754 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3755 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3756 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3757 | } |
| 3758 | } |
| 3759 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3760 | ActivityRecord getVisibleBehindActivity() { |
| 3761 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3764 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 3765 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3766 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3767 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3768 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3769 | while (i > 0) { |
| 3770 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3771 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3772 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3773 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3774 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3775 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3776 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3777 | } |
| 3778 | } |
| 3779 | } |
| 3780 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3781 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 3782 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3783 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 3784 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3785 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 3786 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3787 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3788 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3789 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 3790 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3791 | |
| 3792 | boolean hasVisibleActivities = false; |
| 3793 | |
| 3794 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3795 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3796 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3797 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3798 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3799 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3800 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3801 | final ActivityRecord r = activities.get(activityNdx); |
| 3802 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3803 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3804 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3805 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 3806 | if (r.visible) { |
| 3807 | hasVisibleActivities = true; |
| 3808 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3809 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3810 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 3811 | // Don't currently have state for the activity, or |
| 3812 | // it is finishing -- always remove it. |
| 3813 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3814 | } else if (!r.visible && r.launchCount > 2 && |
| 3815 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3816 | // We have launched this activity too many times since it was |
| 3817 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3818 | // (Note if the activity is visible, we don't remove the record. |
| 3819 | // We leave the dead window on the screen but the process will |
| 3820 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3821 | remove = true; |
| 3822 | } else { |
| 3823 | // The process may be gone, but the activity lives on! |
| 3824 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3825 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3826 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3827 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 3828 | "Removing activity " + r + " from stack at " + i |
| 3829 | + ": haveState=" + r.haveState |
| 3830 | + " stateNotNeeded=" + r.stateNotNeeded |
| 3831 | + " finishing=" + r.finishing |
| 3832 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3833 | if (!r.finishing) { |
| 3834 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 3835 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3836 | r.userId, System.identityHashCode(r), |
| 3837 | r.task.taskId, r.shortComponentName, |
| 3838 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3839 | if (r.state == ActivityState.RESUMED) { |
| 3840 | mService.updateUsageStats(r, false); |
| 3841 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3842 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3843 | } else { |
| 3844 | // We have the current state for this activity, so |
| 3845 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3846 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 3847 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 3848 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3849 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3850 | // Set nowVisible to previous visible state. If the app was visible while |
| 3851 | // it died, we leave the dead window on screen so it's basically visible. |
| 3852 | // This is needed when user later tap on the dead window, we need to stop |
| 3853 | // other apps when user transfers focus to the restarted activity. |
| 3854 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3855 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3856 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3857 | "App died, clearing saved state of " + r); |
| 3858 | r.icicle = null; |
| 3859 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3860 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3861 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3862 | if (remove) { |
| 3863 | removeActivityFromHistoryLocked(r, "appDied"); |
| 3864 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3865 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3870 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3871 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3872 | final void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3873 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3874 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3875 | if (r != null && r.state != ActivityState.RESUMED) { |
| 3876 | r.updateOptionsLocked(options); |
| 3877 | } else { |
| 3878 | ActivityOptions.abort(options); |
| 3879 | } |
| 3880 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3881 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3882 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 3883 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3884 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 3885 | if (task.isPersistable) { |
| 3886 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 3887 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 3888 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 3889 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 3890 | if (!toFront) { |
| 3891 | task.mLastTimeMoved *= -1; |
| 3892 | } |
| 3893 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3894 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3897 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3898 | final int top = mTaskHistory.size() - 1; |
| 3899 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 3900 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3901 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3902 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 3903 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3904 | mTaskHistory.remove(taskNdx); |
| 3905 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3906 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3907 | return; |
| 3908 | } |
| 3909 | } |
| 3910 | } |
| 3911 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3912 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3913 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3914 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3915 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3916 | final int numTasks = mTaskHistory.size(); |
| 3917 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3918 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3919 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3920 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3921 | ActivityOptions.abort(options); |
| 3922 | } else { |
| 3923 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 3924 | } |
| 3925 | return; |
| 3926 | } |
| 3927 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3928 | if (timeTracker != null) { |
| 3929 | // The caller wants a time tracker associated with this task. |
| 3930 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 3931 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 3932 | } |
| 3933 | } |
| 3934 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3935 | // Shift all activities with this task up to the top |
| 3936 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 3937 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3938 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 3939 | // Don't refocus if invisible to current user |
| 3940 | ActivityRecord top = tr.getTopActivity(); |
| 3941 | if (!okToShowLocked(top)) { |
| 3942 | addRecentActivityLocked(top); |
| 3943 | ActivityOptions.abort(options); |
| 3944 | return; |
| 3945 | } |
| 3946 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3947 | // Set focus to the top running activity of this stack. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3948 | ActivityRecord r = topRunningActivityLocked(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3949 | mService.setFocusedActivityLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3950 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3951 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3952 | if (noAnimation) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3953 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3954 | if (r != null) { |
| 3955 | mNoAnimActivities.add(r); |
| 3956 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3957 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3958 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3959 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3960 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 3961 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3962 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3963 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3964 | |
| 3965 | if (VALIDATE_TOKENS) { |
| 3966 | validateAppTokensLocked(); |
| 3967 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3971 | * Worker method for rearranging history stack. Implements the function of moving all |
| 3972 | * 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] | 3973 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3974 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3975 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 3976 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3977 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3978 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3979 | * @return Returns true if the move completed, false if not. |
| 3980 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3981 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3982 | final TaskRecord tr = taskForIdLocked(taskId); |
| 3983 | if (tr == null) { |
| 3984 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 3985 | return false; |
| 3986 | } |
| 3987 | |
| 3988 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3989 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3990 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3991 | // If we have a watcher, preflight the move before committing to it. First check |
| 3992 | // for *other* available tasks, but if none are available, then try again allowing the |
| 3993 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3994 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3995 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3996 | if (next == null) { |
| 3997 | next = topRunningActivityLocked(null, 0); |
| 3998 | } |
| 3999 | if (next != null) { |
| 4000 | // ask watcher if this is allowed |
| 4001 | boolean moveOK = true; |
| 4002 | try { |
| 4003 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4004 | } catch (RemoteException e) { |
| 4005 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4006 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4007 | } |
| 4008 | if (!moveOK) { |
| 4009 | return false; |
| 4010 | } |
| 4011 | } |
| 4012 | } |
| 4013 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4014 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to back transition: task=" + taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4015 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4016 | if (mStackId == HOME_STACK_ID && topTask().isHomeTask()) { |
| 4017 | // For the case where we are moving the home task back and there is an activity visible |
| 4018 | // behind it on the fullscreen stack, we want to move the focus to the visible behind |
| 4019 | // activity to maintain order with what the user is seeing. |
| 4020 | final ActivityStack fullscreenStack = |
| 4021 | mStackSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
| 4022 | if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) { |
| 4023 | final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity(); |
| 4024 | mService.setFocusedActivityLocked(visibleBehind, "moveTaskToBack"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4025 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4026 | return true; |
| 4027 | } |
| 4028 | } |
| 4029 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4030 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4031 | |
| 4032 | // If true, we should resume the home activity next if the task we are moving to the |
| 4033 | // back is over the home stack. We force to false if the task we are moving to back |
| 4034 | // is the home task and we don't want it resumed after moving to the back. |
| 4035 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4036 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4037 | final TaskRecord nextTask = getNextTask(tr); |
| 4038 | if (nextTask != null) { |
| 4039 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4040 | } else { |
| 4041 | prevIsHome = true; |
| 4042 | } |
| 4043 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4044 | mTaskHistory.remove(tr); |
| 4045 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4046 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4047 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4048 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 4049 | // 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] | 4050 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4051 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4052 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4053 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4054 | break; |
| 4055 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4056 | if (taskNdx == 1) { |
| 4057 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4058 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4059 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4062 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4063 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4064 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4065 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4066 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4067 | } |
| 4068 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4069 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4070 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4071 | if (!mService.mBooting && !mService.mBooted) { |
| 4072 | // Not ready yet! |
| 4073 | return false; |
| 4074 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4075 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 4076 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4077 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4078 | } |
| 4079 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4080 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4081 | return true; |
| 4082 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4083 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 4084 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4085 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4086 | final Uri data = r.intent.getData(); |
| 4087 | final String strData = data != null ? data.toSafeString() : null; |
| 4088 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4089 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4090 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4091 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4092 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | /** |
| 4096 | * Make sure the given activity matches the current configuration. Returns |
| 4097 | * false if the activity had to be destroyed. Returns true if the |
| 4098 | * configuration is the same, or the activity will remain running as-is |
| 4099 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 4100 | * correct configuration and all other bookkeeping is handled. |
| 4101 | */ |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4102 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, int globalChanges, |
| 4103 | boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4104 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4105 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4106 | "Skipping config check (will change): " + r); |
| 4107 | return true; |
| 4108 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4109 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4110 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4111 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4112 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4113 | // Short circuit: if the two configurations are the exact same |
| 4114 | // object (the common case), then there is nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4115 | final Configuration newConfig = mService.mConfiguration; |
| 4116 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4117 | if (r.configuration == newConfig |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4118 | && r.taskConfigOverride == taskConfig |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4119 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4120 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4121 | "Configuration unchanged in " + r); |
| 4122 | return true; |
| 4123 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4124 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4125 | // We don't worry about activities that are finishing. |
| 4126 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4127 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4128 | "Configuration doesn't matter in finishing " + r); |
| 4129 | r.stopFreezingScreenLocked(false); |
| 4130 | return true; |
| 4131 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4132 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4133 | // Okay we now are going to make this activity have the new config. |
| 4134 | // 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] | 4135 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4136 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4137 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4138 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4139 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4140 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4141 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4142 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4143 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4144 | "Configuration no differences in " + r); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4145 | // There are no significant differences, so we won't relaunch but should still deliver |
| 4146 | // the new configuration to the client process. |
| 4147 | r.scheduleConfigurationChanged(taskConfig, false); |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4148 | return true; |
| 4149 | } |
| 4150 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 4151 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4152 | "Configuration changes for " + r + " ; taskChanges=" |
| 4153 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 4154 | + Configuration.configurationDiffToString(changes)); |
| 4155 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4156 | // If the activity isn't currently running, just leave the new |
| 4157 | // configuration and it will pick that up next time it starts. |
| 4158 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4159 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4160 | "Configuration doesn't matter not running " + r); |
| 4161 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4162 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4163 | return true; |
| 4164 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4165 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4166 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4167 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4168 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4169 | + Integer.toHexString(changes) + ", handles=0x" |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4170 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig |
| 4171 | + ", taskConfig=" + taskConfig); |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4172 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4173 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4174 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4175 | r.configChangeFlags |= changes; |
| 4176 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4177 | r.forceNewConfig = false; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4178 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4179 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4180 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4181 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4182 | } else if (r.state == ActivityState.PAUSING) { |
| 4183 | // A little annoying: we are waiting for this activity to |
| 4184 | // finish pausing. Let's not do anything now, but just |
| 4185 | // flag that it needs to be restarted when done pausing. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4186 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4187 | "Config is skipping already pausing " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4188 | r.configDestroy = true; |
| 4189 | return true; |
| 4190 | } else if (r.state == ActivityState.RESUMED) { |
| 4191 | // Try to optimize this case: the configuration is changing |
| 4192 | // and we need to restart the top, resumed activity. |
| 4193 | // Instead of doing the normal handshaking, just say |
| 4194 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4195 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4196 | "Config is relaunching resumed " + r); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4197 | relaunchActivityLocked(r, r.configChangeFlags, true, |
| 4198 | preserveWindow && isResizeOnlyChange(changes)); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4199 | r.configChangeFlags = 0; |
| 4200 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4201 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4202 | "Config is relaunching non-resumed " + r); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4203 | relaunchActivityLocked(r, r.configChangeFlags, false, |
| 4204 | preserveWindow && isResizeOnlyChange(changes)); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4205 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4206 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4207 | |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4208 | // All done... tell the caller we weren't able to keep this |
| 4209 | // activity around. |
| 4210 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4211 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4212 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4213 | // Default case: the activity can handle this new configuration, so hand it over. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4214 | // NOTE: We only forward the task override configuration as the system level configuration |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4215 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4216 | // system level configuration it last got. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4217 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4218 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4219 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4220 | return true; |
| 4221 | } |
| 4222 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4223 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4224 | Configuration oldTaskOverride) { |
| 4225 | // Determine what has changed. May be nothing, if this is a config |
| 4226 | // that has come back from the app after going idle. In that case |
| 4227 | // we just want to leave the official config object now in the |
| 4228 | // activity and do nothing else. |
| 4229 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4230 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4231 | // the app. |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4232 | if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4233 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4234 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4235 | || record.crossesVerticalSizeThreshold( |
| 4236 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4237 | if (!crosses) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4238 | taskChanges &= ~CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4239 | } |
| 4240 | } |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4241 | if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4242 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4243 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 4244 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4245 | taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4246 | } |
| 4247 | } |
| 4248 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4249 | } |
| 4250 | |
| 4251 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4252 | Configuration oldTaskOverride, int taskChanges) { |
| 4253 | if (taskChanges == 0) { |
| 4254 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4255 | // Check for changes we care about. |
| 4256 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4257 | taskChanges |= CONFIG_ORIENTATION; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4258 | } |
| 4259 | // We want to explicitly track situations where the size configuration goes from |
| 4260 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4261 | // because there is no threshold. |
| 4262 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4263 | final int newHeight = taskConfig.screenHeightDp; |
| 4264 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4265 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4266 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4267 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4268 | } |
| 4269 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4270 | final int newWidth = taskConfig.screenWidthDp; |
| 4271 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4272 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4273 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4274 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4275 | } |
| 4276 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4277 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4278 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4279 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4280 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4281 | taskChanges |= CONFIG_SMALLEST_SCREEN_SIZE; |
| 4282 | } |
| 4283 | final int oldLayout = oldTaskOverride.screenLayout; |
| 4284 | final int newLayout = taskConfig.screenLayout; |
| 4285 | if ((oldLayout == SCREENLAYOUT_UNDEFINED && newLayout != SCREENLAYOUT_UNDEFINED) |
| 4286 | || (oldLayout != SCREENLAYOUT_UNDEFINED && newLayout == SCREENLAYOUT_UNDEFINED)) { |
| 4287 | taskChanges |= CONFIG_SCREEN_LAYOUT; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4288 | } |
| 4289 | } |
| 4290 | return taskChanges; |
| 4291 | } |
| 4292 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4293 | private static boolean isResizeOnlyChange(int change) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4294 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 4295 | | CONFIG_SCREEN_LAYOUT)) == 0; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4296 | } |
| 4297 | |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4298 | private void relaunchActivityLocked( |
| 4299 | ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) { |
| 4300 | if (mService.mSuppressResizeConfigChanges && preserveWindow) { |
| 4301 | return; |
| 4302 | } |
| 4303 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4304 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4305 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4306 | if (andResume) { |
| 4307 | results = r.results; |
| 4308 | newIntents = r.newIntents; |
| 4309 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4310 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4311 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4312 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4313 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4314 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4315 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4316 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4317 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4318 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4319 | mStackSupervisor.removeChildActivityContainers(r); |
| 4320 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4321 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4322 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 4323 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4324 | r.forceNewConfig = false; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4325 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4326 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4327 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4328 | mStackSupervisor.activityRelaunchingLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4329 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4330 | // the caller will only pass in 'andResume' if this activity is |
| 4331 | // currently resumed, which implies we aren't sleeping. |
| 4332 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4333 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4334 | } |
| 4335 | |
| 4336 | if (andResume) { |
| 4337 | r.results = null; |
| 4338 | r.newIntents = null; |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4339 | r.state = ActivityState.RESUMED; |
| 4340 | } else { |
| 4341 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4342 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4343 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4344 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4345 | |
| 4346 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4347 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4348 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4349 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4350 | final ActivityRecord r = activities.get(activityNdx); |
| 4351 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4352 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4353 | } |
| 4354 | if (r.fullscreen && !r.finishing) { |
| 4355 | return false; |
| 4356 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4357 | } |
| 4358 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4359 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4360 | if (r == null) { |
| 4361 | return false; |
| 4362 | } |
| 4363 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4364 | + " would have returned true for r=" + r); |
| 4365 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4369 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4370 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4371 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4372 | final ActivityRecord r = activities.get(activityNdx); |
| 4373 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4374 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4375 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | } |
| 4379 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4380 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4381 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4382 | boolean didSomething = false; |
| 4383 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4384 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4385 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4386 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4387 | int numActivities = activities.size(); |
| 4388 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4389 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4390 | final boolean sameComponent = |
| 4391 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4392 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4393 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4394 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4395 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4396 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4397 | if (!doit) { |
| 4398 | if (r.finishing) { |
| 4399 | // If this activity is just finishing, then it is not |
| 4400 | // interesting as far as something to stop. |
| 4401 | continue; |
| 4402 | } |
| 4403 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4404 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4405 | if (r.isHomeActivity()) { |
| 4406 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4407 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4408 | continue; |
| 4409 | } else { |
| 4410 | homeActivity = r.realActivity; |
| 4411 | } |
| 4412 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4413 | didSomething = true; |
| 4414 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4415 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4416 | if (r.app != null) { |
| 4417 | r.app.removed = true; |
| 4418 | } |
| 4419 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4420 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4421 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4422 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4423 | true)) { |
| 4424 | // r has been deleted from mActivities, accommodate. |
| 4425 | --numActivities; |
| 4426 | --activityNdx; |
| 4427 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | } |
| 4431 | return didSomething; |
| 4432 | } |
| 4433 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4434 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4435 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4436 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4437 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4438 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4439 | if (task.getTopActivity() == null) { |
| 4440 | continue; |
| 4441 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4442 | ActivityRecord r = null; |
| 4443 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4444 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4445 | int numActivities = 0; |
| 4446 | int numRunning = 0; |
| 4447 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4448 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4449 | continue; |
| 4450 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4451 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4452 | tmp = activities.get(activityNdx); |
| 4453 | if (tmp.finishing) { |
| 4454 | continue; |
| 4455 | } |
| 4456 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4457 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4458 | // Initialize state for next task if needed. |
| 4459 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4460 | top = r; |
| 4461 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4462 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4463 | |
| 4464 | // Add 'r' into the current task. |
| 4465 | numActivities++; |
| 4466 | if (r.app != null && r.app.thread != null) { |
| 4467 | numRunning++; |
| 4468 | } |
| 4469 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4470 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4471 | TAG, r.intent.getComponent().flattenToShortString() |
| 4472 | + ": task=" + r.task); |
| 4473 | } |
| 4474 | |
| 4475 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4476 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4477 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4478 | ci.baseActivity = r.intent.getComponent(); |
| 4479 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4480 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4481 | if (focusedStack && topTask) { |
| 4482 | // Give the latest time to ensure foreground task can be sorted |
| 4483 | // at the first, because lastActiveTime of creating task is 0. |
| 4484 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4485 | topTask = false; |
| 4486 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4487 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4488 | if (top.task != null) { |
| 4489 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4490 | } |
| 4491 | ci.numActivities = numActivities; |
| 4492 | ci.numRunning = numRunning; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4493 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4494 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4498 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4499 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Performing unhandledBack(): top activity at " + top); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4500 | if (top >= 0) { |
| 4501 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4502 | int activityTop = activities.size() - 1; |
| 4503 | if (activityTop > 0) { |
| 4504 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4505 | "unhandled-back", true); |
| 4506 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4507 | } |
| 4508 | } |
| 4509 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4510 | /** |
| 4511 | * Reset local parameters because an app's activity died. |
| 4512 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4513 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4514 | */ |
| 4515 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4516 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4517 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4518 | "App died while pausing: " + mPausingActivity); |
| 4519 | mPausingActivity = null; |
| 4520 | } |
| 4521 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4522 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4523 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4526 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4529 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4530 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4531 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4532 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4533 | final ActivityRecord r = activities.get(activityNdx); |
| 4534 | if (r.app == app) { |
| 4535 | Slog.w(TAG, " Force finishing activity " |
| 4536 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 4537 | // Force the destroy to skip right to removal. |
| 4538 | r.app = null; |
| 4539 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4540 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4541 | } |
| 4542 | } |
| 4543 | } |
| 4544 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4545 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4546 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4547 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4548 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4549 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4550 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 4551 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4552 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 4553 | " Task id #" + task.taskId + "\n" + |
| 4554 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 4555 | " mBounds=" + task.mBounds + "\n" + |
| 4556 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4557 | if (printed) { |
| 4558 | header = null; |
| 4559 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4560 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4561 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 4565 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 4566 | |
| 4567 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4568 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4569 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4570 | } |
| 4571 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4572 | final int top = mTaskHistory.size() - 1; |
| 4573 | if (top >= 0) { |
| 4574 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 4575 | int listTop = list.size() - 1; |
| 4576 | if (listTop >= 0) { |
| 4577 | activities.add(list.get(listTop)); |
| 4578 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4579 | } |
| 4580 | } else { |
| 4581 | ItemMatcher matcher = new ItemMatcher(); |
| 4582 | matcher.build(name); |
| 4583 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4584 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4585 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 4586 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 4587 | activities.add(r1); |
| 4588 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4589 | } |
| 4590 | } |
| 4591 | } |
| 4592 | |
| 4593 | return activities; |
| 4594 | } |
| 4595 | |
| 4596 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4597 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4598 | |
| 4599 | // All activities that came from the package must be |
| 4600 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4601 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4602 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4603 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4604 | final ActivityRecord a = activities.get(activityNdx); |
| 4605 | if (a.info.packageName.equals(packageName)) { |
| 4606 | a.forceNewConfig = true; |
| 4607 | if (starting != null && a == starting && a.visible) { |
| 4608 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4609 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4610 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4611 | } |
| 4612 | } |
| 4613 | } |
| 4614 | |
| 4615 | return starting; |
| 4616 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4617 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4618 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4619 | removeTask(task, reason, !MOVING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4620 | } |
| 4621 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4622 | /** |
| 4623 | * Removes the input task from this stack. |
| 4624 | * @param task to remove. |
| 4625 | * @param reason for removal. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4626 | * @param moving task to another stack. In the case we are moving we don't want to perform |
| 4627 | * some operations on the task like removing it from window manager or recents. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4628 | */ |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4629 | void removeTask(TaskRecord task, String reason, boolean moving) { |
| 4630 | if (!moving) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4631 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4632 | mWindowManager.removeTask(task.taskId); |
Wale Ogunwale | b317b22 | 2015-11-09 11:14:10 -0800 | [diff] [blame] | 4633 | if (!StackId.persistTaskBounds(mStackId)) { |
| 4634 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 4635 | // default configuration the next time it launches. |
| 4636 | task.updateOverrideConfiguration(null); |
| 4637 | } |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4638 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4639 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4640 | final ActivityRecord r = mResumedActivity; |
| 4641 | if (r != null && r.task == task) { |
| 4642 | mResumedActivity = null; |
| 4643 | } |
| 4644 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4645 | final int taskNdx = mTaskHistory.indexOf(task); |
| 4646 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4647 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 4648 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 4649 | if (!nextTask.isOverHomeStack()) { |
| 4650 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 4651 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4652 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4653 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4654 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4655 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4656 | if (!moving && task.mActivities.isEmpty()) { |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4657 | final boolean isVoiceSession = task.voiceSession != null; |
| 4658 | if (isVoiceSession) { |
| 4659 | try { |
| 4660 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 4661 | } catch (RemoteException e) { |
| 4662 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4663 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4664 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 4665 | // Task creator asked to remove this when done, or this task was a voice |
| 4666 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 4667 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 4668 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4669 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4670 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4671 | |
| 4672 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4673 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Chong Zhang | a8be5e5 | 2015-10-05 17:06:28 -0700 | [diff] [blame] | 4674 | // We only need to adjust focused stack if this stack is in focus. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 4675 | if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4676 | String myReason = reason + " leftTaskHistoryEmpty"; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 4677 | if (mFullscreen || !adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4678 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4679 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4680 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 4681 | if (mStacks != null) { |
| 4682 | mStacks.remove(this); |
| 4683 | mStacks.add(0, this); |
| 4684 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4685 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 4686 | mActivityContainer.onTaskListEmptyLocked(); |
| 4687 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4688 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 4689 | |
| 4690 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4691 | } |
| 4692 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4693 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 4694 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 4695 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4696 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 4697 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4698 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4699 | addTask(task, toTop, "createTaskRecord"); |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 4700 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 4701 | if (!layoutTaskInStack(task, info.layout) && mBounds != null && task.mResizeable |
| 4702 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 4703 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4704 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4705 | return task; |
| 4706 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4707 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 4708 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.Layout layout) { |
| 4709 | if (mTaskPositioner == null) { |
| 4710 | return false; |
| 4711 | } |
| 4712 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, layout); |
| 4713 | return true; |
| 4714 | } |
| 4715 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4716 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4717 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4718 | } |
| 4719 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4720 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
| 4721 | final ActivityStack prevStack = preAddTask(task, reason); |
| 4722 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4723 | task.stack = this; |
| 4724 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4725 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4726 | } else { |
| 4727 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4728 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4729 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4730 | postAddTask(task, prevStack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4731 | } |
| 4732 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4733 | void positionTask(final TaskRecord task, int position) { |
| 4734 | final ActivityStack prevStack = preAddTask(task, "positionTask"); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4735 | task.stack = this; |
| 4736 | insertTaskAtPosition(task, position); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4737 | postAddTask(task, prevStack); |
| 4738 | } |
| 4739 | |
| 4740 | private ActivityStack preAddTask(TaskRecord task, String reason) { |
| 4741 | final ActivityStack prevStack = task.stack; |
| 4742 | if (prevStack != null && prevStack != this) { |
| 4743 | prevStack.removeTask(task, reason, MOVING); |
| 4744 | } |
| 4745 | return prevStack; |
| 4746 | } |
| 4747 | |
| 4748 | private void postAddTask(TaskRecord task, ActivityStack prevStack) { |
| 4749 | if (prevStack != null) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4750 | task.reportPictureInPictureModeChangeIfNeeded(prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4751 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4752 | try { |
| 4753 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4754 | } catch (RemoteException e) { |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4759 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame^] | 4760 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 4761 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 4762 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4763 | (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges, |
| 4764 | task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig, |
| 4765 | !r.isHomeActivity(), r.isAlwaysFocusable()); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4766 | mWindowManager.setTaskResizeable(task.taskId, task.mResizeable); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4767 | r.taskConfigOverride = task.mOverrideConfig; |
| 4768 | } |
| 4769 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4770 | void moveToFrontAndResumeStateIfNeeded( |
| 4771 | ActivityRecord r, boolean moveToFront, boolean setResume, String reason) { |
| 4772 | if (!moveToFront) { |
| 4773 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4774 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4775 | |
| 4776 | // If the activity owns the last resumed activity, transfer that together, |
| 4777 | // so that we don't resume the same activity again in the new stack. |
| 4778 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 4779 | if (setResume) { |
| 4780 | mResumedActivity = r; |
| 4781 | } |
| 4782 | // Move the stack in which we are placing the activity to the front. The call will also |
| 4783 | // make sure the activity focus is set. |
| 4784 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | /** |
| 4788 | * Moves the input activity from its current stack to this one. |
| 4789 | * NOTE: The current task of the activity isn't moved to this stack. Instead a new task is |
| 4790 | * created on this stack which the activity is added to. |
| 4791 | * */ |
| 4792 | void moveActivityToStack(ActivityRecord r) { |
| 4793 | final ActivityStack prevStack = r.task.stack; |
| 4794 | if (prevStack.mStackId == mStackId) { |
| 4795 | // You are already in the right stack silly... |
| 4796 | return; |
| 4797 | } |
| 4798 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 4799 | final boolean wasFocused = mStackSupervisor.isFocusedStack(prevStack) |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4800 | && (mStackSupervisor.topRunningActivityLocked() == r); |
| 4801 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 4802 | |
| 4803 | final TaskRecord task = createTaskRecord( |
| 4804 | mStackSupervisor.getNextTaskId(), r.info, r.intent, null, null, true); |
| 4805 | r.setTask(task, null); |
| 4806 | task.addActivityToTop(r); |
| 4807 | setAppTask(r, task); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4808 | task.reportPictureInPictureModeChangeIfNeeded(prevStack); |
| 4809 | moveToFrontAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack"); |
| 4810 | if (wasResumed) { |
| 4811 | prevStack.mResumedActivity = null; |
| 4812 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4813 | } |
| 4814 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4815 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame^] | 4816 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4817 | mWindowManager.setAppTask( |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame^] | 4818 | r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4819 | mWindowManager.setTaskResizeable(task.taskId, task.mResizeable); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4820 | r.taskConfigOverride = task.mOverrideConfig; |
| 4821 | } |
| 4822 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4823 | public int getStackId() { |
| 4824 | return mStackId; |
| 4825 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4826 | |
| 4827 | @Override |
| 4828 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 4829 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 4830 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4831 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4832 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4833 | void onLockTaskPackagesUpdatedLocked() { |
| 4834 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4835 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 4836 | } |
| 4837 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4838 | } |