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 | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 28 | import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 29 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 30 | |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 31 | import static android.content.res.Configuration.SCREENLAYOUT_UNDEFINED; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 32 | import static com.android.server.am.ActivityManagerDebugConfig.*; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 33 | import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 34 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
| 35 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 36 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 37 | import static com.android.server.am.ActivityRecord.STARTING_WINDOW_REMOVED; |
| 38 | import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 39 | import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 40 | import static com.android.server.am.ActivityStackSupervisor.MOVING; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 41 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 42 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 43 | import android.graphics.Point; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 44 | import android.graphics.Rect; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 45 | import android.util.ArraySet; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 46 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 47 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 48 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 49 | import com.android.internal.os.BatteryStatsImpl; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 50 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 51 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 52 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 53 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 54 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 55 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 56 | |
| 57 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 58 | import android.app.ActivityManager; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 59 | import android.app.ActivityManager.StackId; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 60 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 61 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 62 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 63 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 64 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 65 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 66 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 67 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 68 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 69 | import android.graphics.Bitmap; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 70 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 71 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 72 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 73 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 74 | import android.os.Handler; |
| 75 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 76 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 77 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 78 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 79 | import android.os.RemoteException; |
| 80 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 81 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 82 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 83 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 84 | import android.util.EventLog; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 85 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 86 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 87 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 88 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 89 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 90 | import java.lang.ref.WeakReference; |
| 91 | import java.util.ArrayList; |
| 92 | import java.util.Iterator; |
| 93 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 94 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 95 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * State and management of a single stack of activities. |
| 99 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 100 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 101 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 102 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 103 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 104 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 105 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 106 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 107 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 108 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 109 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 110 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 111 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 112 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 113 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 114 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 115 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 116 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 117 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 118 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 119 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 120 | |
| 121 | private static final boolean VALIDATE_TOKENS = false; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 122 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 123 | // Ticks during which we check progress while waiting for an app to launch. |
| 124 | static final int LAUNCH_TICK = 500; |
| 125 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 126 | // How long we wait until giving up on the last activity to pause. This |
| 127 | // is short because it directly impacts the responsiveness of starting the |
| 128 | // next activity. |
| 129 | static final int PAUSE_TIMEOUT = 500; |
| 130 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 131 | // How long we wait for the activity to tell us it has stopped before |
| 132 | // giving up. This is a good amount of time because we really need this |
| 133 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 134 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 135 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 136 | // How long we wait until giving up on an activity telling us it has |
| 137 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 138 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 139 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 140 | // 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] | 141 | // disabled. |
| 142 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 143 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 144 | // How long between activity launches that we consider safe to not warn |
| 145 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 146 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 147 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 148 | // Set to false to disable the preview that is shown while a new activity |
| 149 | // is being started. |
| 150 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 151 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 152 | // How long to wait for all background Activities to redraw following a call to |
| 153 | // convertToTranslucent(). |
| 154 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 155 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 156 | // How many activities have to be scheduled to stop to force a stop pass. |
| 157 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 158 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 159 | enum ActivityState { |
| 160 | INITIALIZING, |
| 161 | RESUMED, |
| 162 | PAUSING, |
| 163 | PAUSED, |
| 164 | STOPPING, |
| 165 | STOPPED, |
| 166 | FINISHING, |
| 167 | DESTROYING, |
| 168 | DESTROYED |
| 169 | } |
| 170 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 171 | // Stack is not considered visible. |
| 172 | static final int STACK_INVISIBLE = 0; |
| 173 | // Stack is considered visible |
| 174 | static final int STACK_VISIBLE = 1; |
| 175 | // Stack is considered visible, but only becuase it has activity that is visible behind other |
| 176 | // activities and there is a specific combination of stacks. |
| 177 | static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2; |
| 178 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 179 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 180 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 181 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 182 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 183 | /** |
| 184 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 185 | * running) activities. It contains #TaskRecord objects. |
| 186 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 187 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 188 | |
| 189 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 190 | * Used for validating app tokens with window manager. |
| 191 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 192 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 193 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 194 | /** |
| 195 | * List of running activities, sorted by recent usage. |
| 196 | * The first entry in the list is the least recently used. |
| 197 | * It contains HistoryRecord objects. |
| 198 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 199 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 200 | |
| 201 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 202 | * Animations that for the current transition have requested not to |
| 203 | * be considered for the transition animation. |
| 204 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 205 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 206 | |
| 207 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 208 | * When we are in the process of pausing an activity, before starting the |
| 209 | * next one, this variable holds the activity that is currently being paused. |
| 210 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 211 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * This is the last activity that we put into the paused state. This is |
| 215 | * used to determine if we need to do an activity transition while sleeping, |
| 216 | * when we normally hold the top activity paused. |
| 217 | */ |
| 218 | ActivityRecord mLastPausedActivity = null; |
| 219 | |
| 220 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 221 | * Activities that specify No History must be removed once the user navigates away from them. |
| 222 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 223 | * and finish it later if another activity replaces it on wakeup. |
| 224 | */ |
| 225 | ActivityRecord mLastNoHistoryActivity = null; |
| 226 | |
| 227 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 228 | * Current activity that is resumed, or null if there is none. |
| 229 | */ |
| 230 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 231 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 232 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 233 | * This is the last activity that has been started. It is only used to |
| 234 | * identify when multiple activities are started at once so that the user |
| 235 | * can be warned they may not be in the activity they think they are. |
| 236 | */ |
| 237 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 238 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 239 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 240 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 241 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 242 | // Activity in mTranslucentActivityWaiting is notified via |
| 243 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 244 | // background activity being drawn then the same call will be made with a true value. |
| 245 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 246 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 247 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 248 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 249 | * Set when we know we are going to be calling updateConfiguration() |
| 250 | * soon, so want to skip intermediate config checks. |
| 251 | */ |
| 252 | boolean mConfigWillChange; |
| 253 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 254 | // 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] | 255 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 256 | // Current bounds of the stack or null if fullscreen. |
| 257 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 258 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 259 | long mLaunchStartTime = 0; |
| 260 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 261 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 262 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 263 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 264 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 265 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 266 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 267 | ArrayList<ActivityStack> mStacks; |
| 268 | /** The attached Display's unique identifier, or -1 if detached */ |
| 269 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 270 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 271 | /** Run all ActivityStacks through this */ |
| 272 | final ActivityStackSupervisor mStackSupervisor; |
| 273 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 274 | private final LaunchingTaskPositioner mTaskPositioner; |
| 275 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 276 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 277 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 278 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 279 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 280 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 281 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 282 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 283 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 284 | |
| 285 | static class ScheduleDestroyArgs { |
| 286 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 287 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 288 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 289 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 290 | mReason = reason; |
| 291 | } |
| 292 | } |
| 293 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 294 | final Handler mHandler; |
| 295 | |
| 296 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 297 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 298 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 299 | super(looper); |
| 300 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 301 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 302 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 303 | public void handleMessage(Message msg) { |
| 304 | switch (msg.what) { |
| 305 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 306 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 307 | // We don't at this point know if the activity is fullscreen, |
| 308 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 309 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 310 | synchronized (mService) { |
| 311 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 312 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 313 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 314 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 315 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 316 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 317 | case LAUNCH_TICK_MSG: { |
| 318 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 319 | synchronized (mService) { |
| 320 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 321 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 325 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 326 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 327 | // We don't at this point know if the activity is fullscreen, |
| 328 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 329 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 330 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 331 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 332 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 333 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 334 | case STOP_TIMEOUT_MSG: { |
| 335 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 336 | // We don't at this point know if the activity is fullscreen, |
| 337 | // so we need to be conservative and assume it isn't. |
| 338 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 339 | synchronized (mService) { |
| 340 | if (r.isInHistory()) { |
| 341 | activityStoppedLocked(r, null, null, null); |
| 342 | } |
| 343 | } |
| 344 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 345 | case DESTROY_ACTIVITIES_MSG: { |
| 346 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 347 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 348 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 349 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 350 | } break; |
| 351 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 352 | synchronized (mService) { |
| 353 | notifyActivityDrawnLocked(null); |
| 354 | } |
| 355 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 356 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 357 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 358 | final ActivityRecord r = getVisibleBehindActivity(); |
| 359 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 360 | if (r != null) { |
| 361 | mService.killAppAtUsersRequest(r.app, null); |
| 362 | } |
| 363 | } |
| 364 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 369 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 370 | int count = 0; |
| 371 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 372 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 373 | } |
| 374 | return count; |
| 375 | } |
| 376 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 377 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 378 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 379 | mActivityContainer = activityContainer; |
| 380 | mStackSupervisor = activityContainer.getOuter(); |
| 381 | mService = mStackSupervisor.mService; |
| 382 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 383 | mWindowManager = mService.mWindowManager; |
| 384 | mStackId = activityContainer.mStackId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 385 | mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 386 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 387 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 388 | ? new LaunchingTaskPositioner() : null; |
| 389 | } |
| 390 | |
| 391 | void attachDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 392 | mDisplayId = activityDisplay.mDisplayId; |
| 393 | mStacks = activityDisplay.mStacks; |
| 394 | mBounds = mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId, onTop); |
| 395 | mFullscreen = mBounds == null; |
| 396 | if (mTaskPositioner != null) { |
| 397 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 398 | mTaskPositioner.configure(mBounds); |
| 399 | } |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 400 | |
| 401 | if (mStackId == DOCKED_STACK_ID) { |
| 402 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 403 | // in the system. |
| 404 | mStackSupervisor.resizeDockedStackLocked( |
| 405 | mBounds, null, null, null, null, PRESERVE_WINDOWS); |
| 406 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void detachDisplay() { |
| 410 | mDisplayId = Display.INVALID_DISPLAY; |
| 411 | mStacks = null; |
| 412 | if (mTaskPositioner != null) { |
| 413 | mTaskPositioner.reset(); |
| 414 | } |
| 415 | mWindowManager.detachStack(mStackId); |
| 416 | } |
| 417 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 418 | public void getDisplaySize(Point out) { |
| 419 | mActivityContainer.mActivityDisplay.mDisplay.getSize(out); |
| 420 | } |
| 421 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 422 | void setBounds(Rect bounds) { |
| 423 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 424 | if (mTaskPositioner != null) { |
| 425 | mTaskPositioner.configure(bounds); |
| 426 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 427 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 428 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 429 | boolean okToShowLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 430 | return mStackSupervisor.okToShowLocked(r); |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 433 | final ActivityRecord topRunningActivityLocked() { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 434 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 435 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 436 | if (r != null) { |
| 437 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 438 | } |
| 439 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 440 | return null; |
| 441 | } |
| 442 | |
| 443 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 444 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 445 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 446 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 447 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 448 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 449 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 450 | return r; |
| 451 | } |
| 452 | } |
| 453 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 454 | return null; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 459 | * 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] | 460 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 461 | * @param token If non-null, any history records matching this token will be skipped. |
| 462 | * @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] | 463 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 464 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 465 | */ |
| 466 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 467 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 468 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 469 | if (task.taskId == taskId) { |
| 470 | continue; |
| 471 | } |
| 472 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 473 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 474 | final ActivityRecord r = activities.get(i); |
| 475 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 476 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 477 | return r; |
| 478 | } |
| 479 | } |
| 480 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 481 | return null; |
| 482 | } |
| 483 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 484 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 485 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 486 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 487 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 488 | final ActivityRecord r = activities.get(activityNdx); |
| 489 | if (!r.finishing) { |
| 490 | return r; |
| 491 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 492 | } |
| 493 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 494 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 497 | final TaskRecord topTask() { |
| 498 | final int size = mTaskHistory.size(); |
| 499 | if (size > 0) { |
| 500 | return mTaskHistory.get(size - 1); |
| 501 | } |
| 502 | return null; |
| 503 | } |
| 504 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 505 | TaskRecord taskForIdLocked(int id) { |
| 506 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 507 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 508 | if (task.taskId == id) { |
| 509 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 510 | } |
| 511 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 512 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 515 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 516 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 517 | return isInStackLocked(r); |
| 518 | } |
| 519 | |
| 520 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 521 | if (r == null) { |
| 522 | return null; |
| 523 | } |
| 524 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 525 | if (task != null && task.stack != null |
| 526 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 527 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 528 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 529 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 530 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 531 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 534 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 535 | final boolean hadit = mLRUActivities.remove(r); |
| 536 | mLRUActivities.add(r); |
| 537 | return hadit; |
| 538 | } |
| 539 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 540 | final boolean isHomeStack() { |
| 541 | return mStackId == HOME_STACK_ID; |
| 542 | } |
| 543 | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 544 | final boolean isDockedStack() { |
| 545 | return mStackId == DOCKED_STACK_ID; |
| 546 | } |
| 547 | |
| 548 | final boolean isPinnedStack() { |
| 549 | return mStackId == PINNED_STACK_ID; |
| 550 | } |
| 551 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 552 | final boolean isOnHomeDisplay() { |
| 553 | return isAttached() && |
| 554 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 555 | } |
| 556 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 557 | void moveToFront(String reason) { |
| 558 | moveToFront(reason, null); |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * @param reason The reason for moving the stack to the front. |
| 563 | * @param task If non-null, the task will be moved to the top of the stack. |
| 564 | * */ |
| 565 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 566 | if (!isAttached()) { |
| 567 | return; |
| 568 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 569 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 570 | mStacks.remove(this); |
| 571 | int addIndex = mStacks.size(); |
| 572 | |
| 573 | if (addIndex > 0) { |
| 574 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 575 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 576 | // 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] | 577 | addIndex--; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 578 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | mStacks.add(addIndex, this); |
| 582 | |
| 583 | // TODO(multi-display): Needs to also work if focus is moving to the non-home display. |
| 584 | if (isOnHomeDisplay()) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 585 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 586 | } |
| 587 | if (task != null) { |
| 588 | insertTaskAtTop(task, null); |
| 589 | } else { |
| 590 | task = topTask(); |
| 591 | } |
| 592 | if (task != null) { |
| 593 | mWindowManager.moveTaskToTop(task.taskId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 594 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 597 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 598 | if (StackId.canReceiveKeys(mStackId)) { |
| 599 | return true; |
| 600 | } |
| 601 | // The stack isn't focusable. See if its top activity is focusable to force focus on the |
| 602 | // stack. |
| 603 | final ActivityRecord r = topRunningActivityLocked(); |
| 604 | return r != null && r.isFocusable(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 605 | } |
| 606 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 607 | final boolean isAttached() { |
| 608 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 609 | } |
| 610 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 611 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 612 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 613 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 614 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 615 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 616 | Intent intent = target.intent; |
| 617 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 618 | ComponentName cls = intent.getComponent(); |
| 619 | if (info.targetActivity != null) { |
| 620 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 621 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 622 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 623 | boolean isDocument = intent != null & intent.isDocument(); |
| 624 | // If documentData is non-null then it must match the existing task data. |
| 625 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 626 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 627 | 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] | 628 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 629 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 630 | if (task.voiceSession != null) { |
| 631 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 632 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 633 | continue; |
| 634 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 635 | if (task.userId != userId) { |
| 636 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 637 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 638 | continue; |
| 639 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 640 | final ActivityRecord r = task.getTopActivity(); |
| 641 | if (r == null || r.finishing || r.userId != userId || |
| 642 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 643 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 644 | continue; |
| 645 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 646 | if (r.mActivityType != target.mActivityType) { |
| 647 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 648 | continue; |
| 649 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 650 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 651 | final Intent taskIntent = task.intent; |
| 652 | final Intent affinityIntent = task.affinityIntent; |
| 653 | final boolean taskIsDocument; |
| 654 | final Uri taskDocumentData; |
| 655 | if (taskIntent != null && taskIntent.isDocument()) { |
| 656 | taskIsDocument = true; |
| 657 | taskDocumentData = taskIntent.getData(); |
| 658 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 659 | taskIsDocument = true; |
| 660 | taskDocumentData = affinityIntent.getData(); |
| 661 | } else { |
| 662 | taskIsDocument = false; |
| 663 | taskDocumentData = null; |
| 664 | } |
| 665 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 666 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 667 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 668 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 669 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 670 | if (!isDocument && !taskIsDocument |
| 671 | && result.r == null && task.canMatchRootAffinity()) { |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 672 | if (task.rootAffinity.equals(target.taskAffinity)) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 673 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 674 | // It is possible for multiple tasks to have the same root affinity especially |
| 675 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 676 | // to see if there is a better candidate. |
| 677 | result.r = r; |
| 678 | result.matchedByRootAffinity = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 679 | } |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 680 | } else if (taskIntent != null && taskIntent.getComponent() != null && |
| 681 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 682 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 683 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 684 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 685 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 686 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 687 | result.r = r; |
| 688 | result.matchedByRootAffinity = false; |
| 689 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 690 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 691 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 692 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 693 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 694 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 695 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 696 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 697 | result.r = r; |
| 698 | result.matchedByRootAffinity = false; |
| 699 | break; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 700 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 701 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Returns the first activity (starting from the top of the stack) that |
| 706 | * is the same as the given activity. Returns null if no such activity |
| 707 | * is found. |
| 708 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 709 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 710 | ComponentName cls = intent.getComponent(); |
| 711 | if (info.targetActivity != null) { |
| 712 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 713 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 714 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 715 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 716 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 717 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 718 | final boolean notCurrentUserTask = |
| 719 | !mStackSupervisor.isCurrentProfileLocked(task.userId); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 720 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 721 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 722 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 723 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 724 | if (notCurrentUserTask && (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 725 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 726 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 727 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 728 | return r; |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | return null; |
| 734 | } |
| 735 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 736 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 737 | * 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] | 738 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 739 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 740 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 741 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 742 | } |
| 743 | mCurrentUser = userId; |
| 744 | |
| 745 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 746 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 747 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 748 | final TaskRecord task = mTaskHistory.get(i); |
| 749 | |
| 750 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 751 | // okay to show the activity when locked. |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 752 | if (mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 753 | || task.topRunningActivityLocked() != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 754 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 755 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 756 | mTaskHistory.remove(i); |
| 757 | mTaskHistory.add(task); |
| 758 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 759 | // Use same value for i. |
| 760 | } else { |
| 761 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 762 | } |
| 763 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 764 | if (VALIDATE_TOKENS) { |
| 765 | validateAppTokensLocked(); |
| 766 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 769 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 770 | r.state = ActivityState.RESUMED; |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 771 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 772 | + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 773 | mResumedActivity = r; |
| 774 | r.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 775 | mRecentTasks.addLocked(r.task); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 776 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 777 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 778 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 779 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 780 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 783 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 784 | if (r != null) { |
| 785 | mRecentTasks.addLocked(r.task); |
| 786 | r.task.touchActiveTime(); |
| 787 | } |
| 788 | } |
| 789 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 790 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 791 | if (mFullyDrawnStartTime != 0) { |
| 792 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 793 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 794 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 795 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 796 | } |
| 797 | |
| 798 | private void stopFullyDrawnTraceIfNeeded() { |
| 799 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 800 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 801 | mFullyDrawnStartTime = 0; |
| 802 | } |
| 803 | } |
| 804 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 805 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 806 | if (r.displayStartTime == 0) { |
| 807 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 808 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 809 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 810 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 811 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 812 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 813 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 814 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 815 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 816 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 817 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 818 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 819 | // Make sure that there is no activity waiting for this to launch. |
| 820 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 821 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 822 | } else { |
| 823 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 824 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 825 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 828 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 829 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 830 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 831 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 832 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 833 | activities.get(activityNdx).setSleeping(false); |
| 834 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 835 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 836 | if (mPausingActivity != null) { |
| 837 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 838 | activityPausedLocked(mPausingActivity.appToken, true); |
| 839 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 842 | /** |
| 843 | * @return true if something must be done before going to sleep. |
| 844 | */ |
| 845 | boolean checkReadyForSleepLocked() { |
| 846 | if (mResumedActivity != null) { |
| 847 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 848 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 849 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 850 | "Sleep => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 851 | startPausingLocked(false, true, false, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 852 | return true; |
| 853 | } |
| 854 | if (mPausingActivity != null) { |
| 855 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 856 | 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] | 857 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 858 | } |
| 859 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 860 | if (hasVisibleBehindActivity()) { |
| 861 | // Stop visible behind activity before going to sleep. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 862 | final ActivityRecord r = getVisibleBehindActivity(); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 863 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 864 | 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] | 865 | return true; |
| 866 | } |
| 867 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 868 | return false; |
| 869 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 870 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 871 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 872 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 873 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 874 | // Make sure any stopped but visible activities are now sleeping. |
| 875 | // This ensures that the activity's onStop() is called. |
| 876 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 877 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 878 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 879 | final ActivityRecord r = activities.get(activityNdx); |
| 880 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 881 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 882 | } |
| 883 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 884 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 885 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 886 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 887 | public final Bitmap screenshotActivitiesLocked(ActivityRecord who) { |
| 888 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 889 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 890 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 891 | return null; |
| 892 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 893 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 894 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 895 | // 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] | 896 | // 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] | 897 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 898 | return null; |
| 899 | } |
| 900 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 901 | int w = mService.mThumbnailWidth; |
| 902 | int h = mService.mThumbnailHeight; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 903 | float scale = 1f; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 904 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 905 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 906 | |
| 907 | // 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] | 908 | // but scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to |
| 909 | // use within SystemUI while keeping memory usage low. |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 910 | if (ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 911 | w = h = -1; |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 912 | scale = 0.5f; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 913 | } |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 914 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 915 | w, h, scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 916 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 917 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 918 | return null; |
| 919 | } |
| 920 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 921 | /** |
| 922 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 923 | * is already an activity being paused or there is no resumed activity. |
| 924 | * |
| 925 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 926 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 927 | * screen turning off). |
| 928 | * @param resuming True if this is being called as part of resuming the top activity, so |
| 929 | * we shouldn't try to instigate a resume here. |
| 930 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 931 | * set to true, we will immediately complete the pause here before returning. |
| 932 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 933 | * it to tell us when it is done. |
| 934 | */ |
| 935 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming, |
| 936 | boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 937 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 938 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 939 | + " state=" + mPausingActivity.state); |
| 940 | if (!mService.isSleeping()) { |
| 941 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 942 | // Because activity will be paused immediately after resume, just let pause |
| 943 | // be completed by the order of activity paused from clients. |
| 944 | completePauseLocked(false); |
| 945 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 946 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 947 | ActivityRecord prev = mResumedActivity; |
| 948 | if (prev == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 949 | if (!resuming) { |
| 950 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 951 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 952 | } |
| 953 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 954 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 955 | |
| 956 | if (mActivityContainer.mParentActivity == null) { |
| 957 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 958 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 961 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 962 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 963 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 964 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 965 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 966 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 967 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 968 | prev.state = ActivityState.PAUSING; |
| 969 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 970 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 971 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | 979f5ed | 2015-10-12 11:22:50 -0700 | [diff] [blame] | 972 | if (mService.mHasRecents |
| 973 | && (next == null || next.noDisplay || next.task != prev.task || uiSleeping)) { |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 974 | prev.mUpdateTaskThumbnailWhenHidden = true; |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 975 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 976 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 977 | |
| 978 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 979 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 980 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 981 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 982 | try { |
| 983 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 984 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 985 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 986 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 987 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 988 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 989 | } catch (Exception e) { |
| 990 | // Ignore exception, if process died other code will cleanup. |
| 991 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 992 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 993 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 994 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 995 | } |
| 996 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 997 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 998 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 999 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | // If we are not going to sleep, we want to ensure the device is |
| 1003 | // awake until the next activity is started. |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1004 | if (!uiSleeping && !mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1005 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1008 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1009 | // Have the window manager pause its key dispatching until the new |
| 1010 | // activity has started. If we're pausing the activity just because |
| 1011 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1012 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1013 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1014 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1015 | } else if (DEBUG_PAUSE) { |
| 1016 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1019 | if (dontWait) { |
| 1020 | // If the caller said they don't want to wait for the pause, then complete |
| 1021 | // the pause now. |
| 1022 | completePauseLocked(false); |
| 1023 | return false; |
| 1024 | |
| 1025 | } else { |
| 1026 | // Schedule a pause timeout in case the app doesn't respond. |
| 1027 | // We don't give it much time because this directly impacts the |
| 1028 | // responsiveness seen by the user. |
| 1029 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1030 | msg.obj = prev; |
| 1031 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 1032 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1033 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1034 | return true; |
| 1035 | } |
| 1036 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1037 | } else { |
| 1038 | // This activity failed to schedule the |
| 1039 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1040 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1041 | if (!resuming) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1042 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1043 | } |
| 1044 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1047 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1048 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1049 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1050 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1051 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1052 | final ActivityRecord r = isInStackLocked(token); |
| 1053 | if (r != null) { |
| 1054 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1055 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1056 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1057 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1058 | completePauseLocked(true); |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1059 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1060 | } else { |
| 1061 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1062 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1063 | mPausingActivity != null |
| 1064 | ? mPausingActivity.shortComponentName : "(none)"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1065 | if (r.state == ActivityState.PAUSING) { |
| 1066 | r.state = ActivityState.PAUSED; |
| 1067 | if (r.finishing) { |
| 1068 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1069 | "Executing finish of failed to pause activity: " + r); |
| 1070 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1071 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1072 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1073 | } |
| 1074 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1075 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1078 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 1079 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 1080 | if (r.state != ActivityState.STOPPING) { |
| 1081 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 1082 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1083 | return; |
| 1084 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1085 | if (persistentState != null) { |
| 1086 | r.persistentState = persistentState; |
| 1087 | mService.notifyTaskPersisterLocked(r.task, false); |
| 1088 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1089 | 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] | 1090 | if (icicle != null) { |
| 1091 | // If icicle is null, this is happening due to a timeout, so we |
| 1092 | // haven't really saved the state. |
| 1093 | r.icicle = icicle; |
| 1094 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 1095 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1096 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1097 | } |
| 1098 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1099 | 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] | 1100 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1101 | r.stopped = true; |
| 1102 | r.state = ActivityState.STOPPED; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 1103 | |
| 1104 | mWindowManager.notifyAppStopped(r.appToken); |
| 1105 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1106 | if (getVisibleBehindActivity() == r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1107 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1108 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1109 | if (r.finishing) { |
| 1110 | r.clearOptionsLocked(); |
| 1111 | } else { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1112 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1113 | destroyActivityLocked(r, true, "stop-config"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1114 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1115 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1116 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1117 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1122 | private void completePauseLocked(boolean resumeNext) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1123 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1124 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1125 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1126 | if (prev != null) { |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1127 | final boolean wasStopping = prev.state == ActivityState.STOPPING; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1128 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1129 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1130 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1131 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1132 | } else if (prev.app != null) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1133 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1134 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1135 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1136 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1137 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1138 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1139 | if (prev.deferRelaunchUntilPaused) { |
| 1140 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1141 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
| 1142 | relaunchActivityLocked(prev, prev.configChangeFlags, false, |
| 1143 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1144 | } else if (wasStopping) { |
| 1145 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1146 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1147 | // We don't need to schedule another stop, we only need to let it happen. |
| 1148 | prev.state = ActivityState.STOPPING; |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1149 | } else if ((!prev.visible && !hasVisibleBehindActivity()) |
| 1150 | || mService.isSleepingOrShuttingDown()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1151 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1152 | // stopping. |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1153 | addToStopping(prev, true /* immediate */); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1154 | } |
| 1155 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1156 | 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] | 1157 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1158 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1159 | // It is possible the activity was freezing the screen before it was paused. |
| 1160 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1161 | // since it is no longer visible. |
| 1162 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1163 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1164 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1165 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1166 | if (resumeNext) { |
| 1167 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
| 1168 | if (!mService.isSleepingOrShuttingDown()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1169 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1170 | } else { |
| 1171 | mStackSupervisor.checkReadyForSleepLocked(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1172 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1173 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1174 | // If there are no more activities available to run, do resume anyway to start |
| 1175 | // something. Also if the top activity on the stack is not the just paused |
| 1176 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1177 | // in-flight app switch. |
| 1178 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1179 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1180 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1181 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1182 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1183 | if (prev != null) { |
| 1184 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1185 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1186 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1187 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1188 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1189 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1190 | if (diff > 0) { |
| 1191 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1192 | synchronized (bsi) { |
| 1193 | BatteryStatsImpl.Uid.Proc ps = |
| 1194 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1195 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1196 | if (ps != null) { |
| 1197 | ps.addForegroundTimeLocked(diff); |
| 1198 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1202 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1203 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1204 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1205 | // Notify when the task stack has changed, but only if visibilities changed (not just focus) |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1206 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause) { |
| 1207 | mService.notifyTaskStackChangedLocked(); |
| 1208 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1209 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1210 | |
| 1211 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1214 | private void addToStopping(ActivityRecord r, boolean immediate) { |
| 1215 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1216 | mStackSupervisor.mStoppingActivities.add(r); |
| 1217 | } |
| 1218 | |
| 1219 | // If we already have a few activities waiting to stop, then give up |
| 1220 | // on things going idle and start clearing them out. Or if r is the |
| 1221 | // last of activity of the last task the stack will be empty and must |
| 1222 | // be cleared immediately. |
| 1223 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1224 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
| 1225 | |
| 1226 | if (immediate || forceIdle) { |
| 1227 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
| 1228 | + forceIdle + "immediate=" + immediate); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1229 | mStackSupervisor.scheduleIdleLocked(); |
| 1230 | } else { |
| 1231 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1232 | } |
| 1233 | } |
| 1234 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1235 | /** |
| 1236 | * Once we know that we have asked an application to put an activity in |
| 1237 | * the resumed state (either by launching it or explicitly telling it), |
| 1238 | * this function updates the rest of our state to match that fact. |
| 1239 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1240 | private void completeResumeLocked(ActivityRecord next) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1241 | next.visible = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1242 | next.idle = false; |
| 1243 | next.results = null; |
| 1244 | next.newIntents = null; |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1245 | next.stopped = false; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1246 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1247 | if (next.isHomeActivity()) { |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1248 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1249 | if (app != null && app != mService.mHomeProcess) { |
| 1250 | mService.mHomeProcess = app; |
| 1251 | } |
| 1252 | } |
| 1253 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1254 | if (next.nowVisible) { |
| 1255 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1256 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1257 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1258 | |
| 1259 | // 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] | 1260 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1261 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1262 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1263 | |
| 1264 | next.resumeKeyDispatchingLocked(); |
| 1265 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1266 | |
| 1267 | // Mark the point when the activity is resuming |
| 1268 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1269 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1270 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1271 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1272 | } else { |
| 1273 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1274 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1275 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1276 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1277 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1278 | if (getVisibleBehindActivity() == next) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1279 | // When resuming an activity, require it to call requestVisibleBehind() again. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1280 | setVisibleBehindActivity(null); |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1281 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1284 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1285 | r.visible = visible; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1286 | if (!visible && r.mUpdateTaskThumbnailWhenHidden) { |
| 1287 | r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null); |
| 1288 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1289 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1290 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1291 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1292 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1293 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1294 | container.setVisible(visible); |
| 1295 | } |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1296 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1299 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1300 | // otherwise return null; |
| 1301 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1302 | TaskRecord task = r.task; |
| 1303 | if (task == null) { |
| 1304 | return null; |
| 1305 | } |
| 1306 | |
| 1307 | ActivityStack stack = task.stack; |
| 1308 | if (stack == null) { |
| 1309 | return null; |
| 1310 | } |
| 1311 | |
| 1312 | int stackNdx = mStacks.indexOf(stack); |
| 1313 | |
| 1314 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1315 | int taskNdx = tasks.indexOf(task); |
| 1316 | |
| 1317 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1318 | int activityNdx = activities.indexOf(r) + 1; |
| 1319 | |
| 1320 | final int numStacks = mStacks.size(); |
| 1321 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1322 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1323 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1324 | final int numTasks = tasks.size(); |
| 1325 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1326 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1327 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1328 | final int numActivities = activities.size(); |
| 1329 | while (activityNdx < numActivities) { |
| 1330 | final ActivityRecord activity = activities.get(activityNdx); |
| 1331 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1332 | return historyStack.mFullscreen |
| 1333 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1334 | } |
| 1335 | ++activityNdx; |
| 1336 | } |
| 1337 | activityNdx = 0; |
| 1338 | ++taskNdx; |
| 1339 | } |
| 1340 | taskNdx = 0; |
| 1341 | ++stackNdx; |
| 1342 | } |
| 1343 | |
| 1344 | return null; |
| 1345 | } |
| 1346 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1347 | ActivityStack getNextFocusableStackLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1348 | ArrayList<ActivityStack> stacks = mStacks; |
| 1349 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1350 | if (parent != null) { |
| 1351 | stacks = parent.task.stack.mStacks; |
| 1352 | } |
| 1353 | if (stacks != null) { |
| 1354 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1355 | ActivityStack stack = stacks.get(i); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1356 | if (stack != this && stack.isFocusable() |
| 1357 | && stack.getStackVisibilityLocked() != STACK_INVISIBLE) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1358 | return stack; |
| 1359 | } |
| 1360 | } |
| 1361 | } |
| 1362 | return null; |
| 1363 | } |
| 1364 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1365 | /** Returns true if the stack contains a fullscreen task. */ |
| 1366 | private boolean hasFullscreenTask() { |
| 1367 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1368 | final TaskRecord task = mTaskHistory.get(i); |
| 1369 | if (task.mFullscreen) { |
| 1370 | return true; |
| 1371 | } |
| 1372 | } |
| 1373 | return false; |
| 1374 | } |
| 1375 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1376 | private boolean hasTranslucentActivity(ActivityStack stack) { |
| 1377 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1378 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1379 | final TaskRecord task = tasks.get(taskNdx); |
| 1380 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1381 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1382 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1383 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1384 | // Conditions for an activity to obscure the stack we're |
| 1385 | // examining: |
| 1386 | // 1. Not Finishing AND Visible AND: |
| 1387 | // 2. Either: |
| 1388 | // - Full Screen Activity OR |
| 1389 | // - On top of Home and our stack is NOT home |
| 1390 | if (!r.finishing && r.visible && (r.fullscreen || |
| 1391 | (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()))) { |
| 1392 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1393 | } |
| 1394 | } |
| 1395 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1396 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1399 | /** |
| 1400 | * Returns stack's visibility: {@link #STACK_INVISIBLE}, {@link #STACK_VISIBLE} or |
| 1401 | * {@link #STACK_VISIBLE_ACTIVITY_BEHIND}. |
| 1402 | */ |
| 1403 | int getStackVisibilityLocked() { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1404 | if (!isAttached()) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1405 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1408 | if (mStackSupervisor.isFrontStack(this) || mStackSupervisor.isFocusedStack(this)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1409 | return STACK_VISIBLE; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1412 | final int stackIndex = mStacks.indexOf(this); |
| 1413 | |
| 1414 | if (stackIndex == mStacks.size() - 1) { |
| 1415 | Slog.wtf(TAG, |
| 1416 | "Stack=" + this + " isn't front stack but is at the top of the stack list"); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1417 | return STACK_INVISIBLE; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1420 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 1421 | if (isLockscreenShown && !StackId.isAllowedOverLockscreen(mStackId)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1422 | return STACK_INVISIBLE; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1425 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1426 | final int focusedStackId = focusedStack.mStackId; |
| 1427 | |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1428 | if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1429 | && hasVisibleBehindActivity() && focusedStackId == HOME_STACK_ID |
| 1430 | && !focusedStack.topActivity().fullscreen) { |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1431 | // The fullscreen stack should be visible if it has a visible behind activity behind |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1432 | // the home stack that is translucent. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1433 | return STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1434 | } |
| 1435 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1436 | if (mStackId == DOCKED_STACK_ID) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1437 | // Docked stack is always visible, except in the case where the top running activity |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1438 | // task in the focus stack doesn't support any form of resizing but we show it for the |
| 1439 | // home task even though it's not resizable. |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1440 | final ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1441 | final TaskRecord task = r != null ? r.task : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1442 | return task == null || task.canGoInDockedStack() || task.isHomeTask() ? STACK_VISIBLE |
| 1443 | : STACK_INVISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1446 | // Find the first stack below focused stack that actually got something visible. |
| 1447 | int belowFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1448 | while (belowFocusedIndex >= 0 && |
| 1449 | mStacks.get(belowFocusedIndex).topRunningActivityLocked() == null) { |
| 1450 | belowFocusedIndex--; |
| 1451 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1452 | if ((focusedStackId == DOCKED_STACK_ID || focusedStackId == PINNED_STACK_ID) |
| 1453 | && stackIndex == belowFocusedIndex) { |
| 1454 | // Stacks directly behind the docked or pinned stack are always visible. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1455 | return STACK_VISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1458 | if (focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 1459 | && hasTranslucentActivity(focusedStack)) { |
| 1460 | // Stacks behind the fullscreen stack with a translucent activity are always |
| 1461 | // visible so they can act as a backdrop to the translucent activity. |
| 1462 | // For example, dialog activities |
| 1463 | if (stackIndex == belowFocusedIndex) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1464 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1465 | } |
| 1466 | if (belowFocusedIndex >= 0) { |
| 1467 | final ActivityStack stack = mStacks.get(belowFocusedIndex); |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1468 | if ((stack.mStackId == DOCKED_STACK_ID || stack.mStackId == PINNED_STACK_ID) |
| 1469 | && stackIndex == (belowFocusedIndex - 1)) { |
| 1470 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1471 | // complete backdrop to the translucent activity when the docked stack is up. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1472 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1473 | } |
| 1474 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1477 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1478 | // Visibility of any static stack should have been determined by the conditions above. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1479 | return STACK_INVISIBLE; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1482 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1483 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1484 | |
| 1485 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1486 | continue; |
| 1487 | } |
| 1488 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1489 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1490 | // These stacks can't have any dynamic stacks visible behind them. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1491 | return STACK_INVISIBLE; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1492 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1493 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1494 | if (!hasTranslucentActivity(stack)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1495 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1499 | return STACK_VISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1502 | final int rankTaskLayers(int baseLayer) { |
| 1503 | int layer = 0; |
| 1504 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1505 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1506 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1507 | if (r == null || r.finishing || !r.visible) { |
| 1508 | task.mLayerRank = -1; |
| 1509 | } else { |
| 1510 | task.mLayerRank = baseLayer + layer++; |
| 1511 | } |
| 1512 | } |
| 1513 | return layer; |
| 1514 | } |
| 1515 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1516 | /** |
| 1517 | * Make sure that all activities that need to be visible (that is, they |
| 1518 | * currently can be seen by the user) actually are. |
| 1519 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1520 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1521 | boolean preserveWindows) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1522 | ActivityRecord top = topRunningActivityLocked(); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1523 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1524 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1525 | if (top != null) { |
| 1526 | checkTranslucentActivityWaiting(top); |
| 1527 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1528 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1529 | // If the top activity is not fullscreen, then we need to |
| 1530 | // make sure any activities under it are now visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1531 | boolean aboveTop = top != null; |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1532 | final int stackVisibility = getStackVisibilityLocked(); |
| 1533 | final boolean stackInvisible = stackVisibility != STACK_VISIBLE; |
| 1534 | final boolean stackVisibleBehind = stackVisibility == STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1535 | boolean behindFullscreenActivity = stackInvisible; |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1536 | boolean resumeNextActivity = isFocusable() && (isInStackLocked(starting) == null); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1537 | boolean behindTranslucentActivity = false; |
| 1538 | final ActivityRecord visibleBehind = getVisibleBehindActivity(); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1539 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1540 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1541 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1542 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1543 | final ActivityRecord r = activities.get(activityNdx); |
| 1544 | if (r.finishing) { |
| 1545 | continue; |
| 1546 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1547 | final boolean isTop = r == top; |
| 1548 | if (aboveTop && !isTop) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1549 | continue; |
| 1550 | } |
| 1551 | aboveTop = false; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1552 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1553 | // but must be drawn initially for the animation as though they were visible. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1554 | final boolean activityVisibleBehind = |
| 1555 | (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == r; |
| 1556 | final boolean isVisible = (!behindFullscreenActivity || r.mLaunchTaskBehind |
| 1557 | || activityVisibleBehind) && okToShowLocked(r); |
| 1558 | if (isVisible) { |
| 1559 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
| 1560 | + " finishing=" + r.finishing + " state=" + r.state); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1561 | // First: if this is not the current activity being started, make |
| 1562 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1563 | if (r != starting) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1564 | ensureActivityConfigurationLocked(r, 0, preserveWindows); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1565 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1566 | |
| 1567 | if (r.app == null || r.app.thread == null) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1568 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1569 | resumeNextActivity, r)) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1570 | if (activityNdx >= activities.size()) { |
| 1571 | // Record may be removed if its process needs to restart. |
| 1572 | activityNdx = activities.size() - 1; |
| 1573 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1574 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1575 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1576 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1577 | } else if (r.visible) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1578 | // If this activity is already visible, then there is nothing to do here. |
| 1579 | if (handleAlreadyVisible(r)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1580 | resumeNextActivity = false; |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1581 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1582 | } else { |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1583 | makeVisibleIfNeeded(starting, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1584 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1585 | // Aggregate current change flags. |
| 1586 | configChanges |= r.configChangeFlags; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1587 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1588 | behindFullscreenActivity, task, r); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1589 | if (behindFullscreenActivity && !r.fullscreen) { |
| 1590 | behindTranslucentActivity = true; |
| 1591 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1592 | } else { |
Wale Ogunwale | 834c236 | 2016-01-23 18:14:58 -0800 | [diff] [blame] | 1593 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1594 | + " finishing=" + r.finishing + " state=" + r.state + " stackInvisible=" |
| 1595 | + stackInvisible + " behindFullscreenActivity=" |
| 1596 | + behindFullscreenActivity + " mLaunchTaskBehind=" |
| 1597 | + r.mLaunchTaskBehind); |
| 1598 | makeInvisible(r, visibleBehind); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1599 | } |
| 1600 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1601 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1602 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1603 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1604 | // status of an activity in a previous task affects other. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1605 | behindFullscreenActivity = stackVisibility == STACK_INVISIBLE; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1606 | } else if (mStackId == HOME_STACK_ID) { |
| 1607 | if (task.isHomeTask()) { |
| 1608 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
| 1609 | + " stackInvisible=" + stackInvisible |
| 1610 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1611 | // No other task in the home stack should be visible behind the home activity. |
| 1612 | // Home activities is usually a translucent activity with the wallpaper behind |
| 1613 | // them. However, when they don't have the wallpaper behind them, we want to |
| 1614 | // show activities in the next application stack behind them vs. another |
| 1615 | // task in the home stack like recents. |
| 1616 | behindFullscreenActivity = true; |
| 1617 | } else if (task.isRecentsTask() |
| 1618 | && task.getTaskToReturnTo() == APPLICATION_ACTIVITY_TYPE) { |
| 1619 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1620 | "Recents task returning to app: at " + task |
| 1621 | + " stackInvisible=" + stackInvisible |
| 1622 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1623 | // We don't want any other tasks in the home stack visible if the recents |
| 1624 | // activity is going to be returning to an application activity type. |
| 1625 | // We do this to preserve the visible order the user used to get into the |
| 1626 | // recents activity. The recents activity is normally translucent and if it |
| 1627 | // doesn't have the wallpaper behind it the next activity in the home stack |
| 1628 | // shouldn't be visible when the home stack is brought to the front to display |
| 1629 | // the recents activity from an app. |
| 1630 | behindFullscreenActivity = true; |
| 1631 | } |
| 1632 | |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1633 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1634 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1635 | |
| 1636 | if (mTranslucentActivityWaiting != null && |
| 1637 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1638 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1639 | notifyActivityDrawnLocked(null); |
| 1640 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1641 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1642 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1643 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 1644 | if (mTranslucentActivityWaiting != top) { |
| 1645 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1646 | if (mTranslucentActivityWaiting != null) { |
| 1647 | // Call the callback with a timeout indication. |
| 1648 | notifyActivityDrawnLocked(null); |
| 1649 | mTranslucentActivityWaiting = null; |
| 1650 | } |
| 1651 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1656 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1657 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 1658 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 1659 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 1660 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1661 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1662 | // This activity needs to be visible, but isn't even running... |
| 1663 | // get it started and resume if no other stack in this stack is resumed. |
| 1664 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 1665 | if (r != starting) { |
| 1666 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1667 | } |
| 1668 | if (!r.visible || r.mLaunchTaskBehind) { |
| 1669 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
| 1670 | setVisible(r, true); |
| 1671 | } |
| 1672 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1673 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1674 | return true; |
| 1675 | } |
| 1676 | } |
| 1677 | return false; |
| 1678 | } |
| 1679 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1680 | private void makeInvisible(ActivityRecord r, ActivityRecord visibleBehind) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1681 | if (!r.visible) { |
| 1682 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 1683 | return; |
| 1684 | } |
| 1685 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 1686 | // keeping the screen frozen. |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1687 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.state); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1688 | try { |
| 1689 | setVisible(r, false); |
| 1690 | switch (r.state) { |
| 1691 | case STOPPING: |
| 1692 | case STOPPED: |
| 1693 | if (r.app != null && r.app.thread != null) { |
| 1694 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1695 | "Scheduling invisibility: " + r); |
| 1696 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1697 | } |
| 1698 | break; |
| 1699 | |
| 1700 | case INITIALIZING: |
| 1701 | case RESUMED: |
| 1702 | case PAUSING: |
| 1703 | case PAUSED: |
| 1704 | // This case created for transitioning activities from |
| 1705 | // translucent to opaque {@link Activity#convertToOpaque}. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1706 | if (visibleBehind == r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1707 | releaseBackgroundResources(r); |
| 1708 | } else { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1709 | addToStopping(r, true /* immediate */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1710 | } |
| 1711 | break; |
| 1712 | |
| 1713 | default: |
| 1714 | break; |
| 1715 | } |
| 1716 | } catch (Exception e) { |
| 1717 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1718 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 1723 | TaskRecord task, ActivityRecord r) { |
| 1724 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1725 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 1726 | + " stackInvisible=" + stackInvisible |
| 1727 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1728 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1729 | behindFullscreenActivity = true; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1730 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1731 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 1732 | + " stackInvisible=" + stackInvisible |
| 1733 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1734 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1735 | } |
| 1736 | return behindFullscreenActivity; |
| 1737 | } |
| 1738 | |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1739 | private void makeVisibleIfNeeded(ActivityRecord starting, ActivityRecord r) { |
| 1740 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1741 | // This activity is not currently visible, but is running. Tell it to become visible. |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1742 | if (r.state == ActivityState.RESUMED || r == starting) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 1743 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
| 1744 | "Not making visible, r=" + r + " state=" + r.state + " starting=" + starting); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1745 | return; |
| 1746 | } |
| 1747 | |
| 1748 | // If this activity is paused, tell it to now show its window. |
| 1749 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1750 | "Making visible and scheduling visibility: " + r); |
| 1751 | try { |
| 1752 | if (mTranslucentActivityWaiting != null) { |
| 1753 | r.updateOptionsLocked(r.returningOptions); |
| 1754 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1755 | } |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1756 | setVisible(r, true); |
| 1757 | r.sleeping = false; |
| 1758 | r.app.pendingUiClean = true; |
| 1759 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1760 | r.stopFreezingScreenLocked(false); |
| 1761 | } catch (Exception e) { |
| 1762 | // Just skip on any failure; we'll make it |
| 1763 | // visible when it next restarts. |
| 1764 | Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1768 | private boolean handleAlreadyVisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1769 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Skipping: already visible at " + r); |
| 1770 | r.stopFreezingScreenLocked(false); |
| 1771 | try { |
| 1772 | if (r.returningOptions != null) { |
| 1773 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions); |
| 1774 | } |
| 1775 | } catch(RemoteException e) { |
| 1776 | } |
| 1777 | return r.state == ActivityState.RESUMED; |
| 1778 | } |
| 1779 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1780 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1781 | mTranslucentActivityWaiting = r; |
| 1782 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1783 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1784 | } |
| 1785 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1786 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1787 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1788 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1789 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1790 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1791 | final ActivityRecord r = activities.get(activityNdx); |
| 1792 | if ( r.appTimeTracker != except) { |
| 1793 | r.appTimeTracker = null; |
| 1794 | } |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1799 | /** |
| 1800 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1801 | * redrawn notify the top activity by calling |
| 1802 | * {@link Activity#onTranslucentConversionComplete}. |
| 1803 | * |
| 1804 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1805 | * occurred and the activity will be notified immediately. |
| 1806 | */ |
| 1807 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1808 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1809 | if ((r == null) |
| 1810 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1811 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1812 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1813 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1814 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1815 | mTranslucentActivityWaiting = null; |
| 1816 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1817 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1818 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1819 | if (waitingActivity != null) { |
| 1820 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 1821 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 1822 | try { |
| 1823 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1824 | waitingActivity.appToken, r != null); |
| 1825 | } catch (RemoteException e) { |
| 1826 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1832 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 1833 | * starting window displayed then remove that starting window. It is possible that the activity |
| 1834 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 1835 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1836 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1837 | boolean aboveTop = true; |
| 1838 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1839 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1840 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1841 | final ActivityRecord r = activities.get(activityNdx); |
| 1842 | if (aboveTop) { |
| 1843 | if (r == topActivity) { |
| 1844 | aboveTop = false; |
| 1845 | } |
| 1846 | continue; |
| 1847 | } |
| 1848 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 1849 | if (r.state == ActivityState.INITIALIZING |
| 1850 | && r.mStartingWindowState == STARTING_WINDOW_SHOWN) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1851 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 1852 | "Found orphaned starting window " + r); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 1853 | r.mStartingWindowState = STARTING_WINDOW_REMOVED; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1854 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 1855 | } |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1860 | /** |
| 1861 | * Ensure that the top activity in the stack is resumed. |
| 1862 | * |
| 1863 | * @param prev The previously resumed activity, for when in the process |
| 1864 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1865 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1866 | * |
| 1867 | * @return Returns true if something is being resumed, or false if |
| 1868 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1869 | * |
| 1870 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 1871 | * non-focused stack to be resumed. |
| 1872 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 1873 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1874 | */ |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1875 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1876 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1877 | // Don't even start recursing. |
| 1878 | return false; |
| 1879 | } |
| 1880 | |
| 1881 | boolean result = false; |
| 1882 | try { |
| 1883 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1884 | mStackSupervisor.inResumeTopActivity = true; |
| 1885 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 1886 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 1887 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1888 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1889 | result = resumeTopActivityInnerLocked(prev, options); |
| 1890 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1891 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1892 | } |
| 1893 | return result; |
| 1894 | } |
| 1895 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1896 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1897 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1898 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1899 | if (!mService.mBooting && !mService.mBooted) { |
| 1900 | // Not ready yet! |
| 1901 | return false; |
| 1902 | } |
| 1903 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1904 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1905 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 1906 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1907 | // Do not resume this stack if its parent is not resumed. |
| 1908 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 1909 | return false; |
| 1910 | } |
| 1911 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1912 | mStackSupervisor.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1913 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1914 | // Find the first activity that is not finishing. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1915 | final ActivityRecord next = topRunningActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1916 | |
| 1917 | // Remember how we'll process this pause/resume situation, and ensure |
| 1918 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1919 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1920 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1921 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1922 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1923 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1924 | // There are no more activities! |
| 1925 | final String reason = "noMoreActivities"; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1926 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(reason)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1927 | // Try to move focus to the next visible stack with a running activity if this |
| 1928 | // stack is not covering the entire screen. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1929 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 1930 | mStackSupervisor.getFocusedStack(), prev, null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1931 | } |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1932 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1933 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1934 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1935 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1936 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1937 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1938 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1939 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1940 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1941 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1942 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1946 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1947 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1948 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1949 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1950 | // Make sure we have executed any pending transitions, since there |
| 1951 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1952 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1953 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1954 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1955 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1956 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1957 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1958 | return false; |
| 1959 | } |
| 1960 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1961 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 1962 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1963 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1964 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1965 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1966 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1967 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1968 | // 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] | 1969 | // 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] | 1970 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1971 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 1972 | } else if (!isOnHomeDisplay()) { |
| 1973 | return false; |
| 1974 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1975 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1976 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1977 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1978 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1979 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 1980 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1981 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1984 | // If we are sleeping, and there is no resumed activity, and the top |
| 1985 | // activity is paused, well that is the state we want. |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1986 | if (mService.isSleepingOrShuttingDown() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1987 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1988 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1989 | // Make sure we have executed any pending transitions, since there |
| 1990 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1991 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1992 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1993 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1994 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1995 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1996 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1997 | return false; |
| 1998 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1999 | |
| 2000 | // Make sure that the user who owns this activity is started. If not, |
| 2001 | // we will just leave it as is because someone should be bringing |
| 2002 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2003 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2004 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 2005 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2006 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2007 | return false; |
| 2008 | } |
| 2009 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2010 | // The activity may be waiting for stop, but that is no longer |
| 2011 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2012 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2013 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2014 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2015 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2016 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2017 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2018 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2019 | // If we are currently pausing an activity, then don't do anything until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 2020 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2021 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2022 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2023 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2024 | return false; |
| 2025 | } |
| 2026 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2027 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2028 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2029 | // We need to start pausing the current activity so the top one can be resumed... |
| 2030 | final boolean dontWaitForPause = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 2031 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2032 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2033 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2034 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | e042bf2 | 2014-11-11 11:28:43 -0800 | [diff] [blame] | 2035 | pausing |= startPausingLocked(userLeaving, false, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2036 | } |
| 2037 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2038 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2039 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2040 | // At this point we want to put the upcoming activity's process |
| 2041 | // at the top of the LRU list, since we know we will be needing it |
| 2042 | // very soon and it would be a waste to let it get killed if it |
| 2043 | // happens to be sitting towards the end. |
| 2044 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2045 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2046 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2047 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2048 | return true; |
| 2049 | } |
| 2050 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2051 | // If the most recent activity was noHistory but was only stopped rather |
| 2052 | // than stopped+finished because the device went to sleep, we need to make |
| 2053 | // sure to finish it as we're making a new activity topmost. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2054 | if (mService.isSleeping() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2055 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2056 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2057 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2058 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2059 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2060 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2063 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2064 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2065 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2066 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2067 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2068 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2069 | } else { |
| 2070 | // The next activity is already visible, so hide the previous |
| 2071 | // activity's windows right now so we can show the new one ASAP. |
| 2072 | // We only do this if the previous is finishing, which should mean |
| 2073 | // it is on top of the one being resumed so hiding it quickly |
| 2074 | // is good. Otherwise, we want to do the normal route of allowing |
| 2075 | // the resumed activity to be shown so we can decide if the |
| 2076 | // previous should actually be hidden depending on whether the |
| 2077 | // new one is found to be full-screen or not. |
| 2078 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2079 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2080 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2081 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2082 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2083 | + ", nowVisible=" + next.nowVisible); |
| 2084 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2085 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2086 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2087 | + ", waitingVisible=" |
| 2088 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2089 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2094 | // Launching this app's activity, make sure the app is no longer |
| 2095 | // considered stopped. |
| 2096 | try { |
| 2097 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2098 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2099 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2100 | } catch (IllegalArgumentException e) { |
| 2101 | Slog.w(TAG, "Failed trying to unstop package " |
| 2102 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2103 | } |
| 2104 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2105 | // We are starting up the next activity, so tell the window manager |
| 2106 | // that the previous one will be hidden soon. This way it can know |
| 2107 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2108 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2109 | if (prev != null) { |
| 2110 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2111 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2112 | "Prepare close transition: prev=" + prev); |
| 2113 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2114 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2115 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2116 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2117 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2118 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 2119 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2120 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2121 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2122 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2123 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2124 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2125 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2126 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2127 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2128 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2129 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2130 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2131 | : next.mLaunchTaskBehind |
| 2132 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2133 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2134 | } |
| 2135 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2136 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2137 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2138 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2139 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2140 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2141 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2142 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2143 | } |
| 2144 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2145 | |
| 2146 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2147 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2148 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2149 | if (opts != null) { |
| 2150 | resumeAnimOptions = opts.toBundle(); |
| 2151 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2152 | next.applyOptionsLocked(); |
| 2153 | } else { |
| 2154 | next.clearOptionsLocked(); |
| 2155 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2156 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2157 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2158 | if (next.app != null && next.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2159 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2160 | |
| 2161 | // This activity is now becoming visible. |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 2162 | if (!next.visible) { |
| 2163 | mWindowManager.setAppVisibility(next.appToken, true); |
| 2164 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2165 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2166 | // schedule launch ticks to collect information about slow apps. |
| 2167 | next.startLaunchTickingLocked(); |
| 2168 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2169 | ActivityRecord lastResumedActivity = |
| 2170 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2171 | ActivityState lastState = next.state; |
| 2172 | |
| 2173 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2174 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2175 | 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] | 2176 | next.state = ActivityState.RESUMED; |
| 2177 | mResumedActivity = next; |
| 2178 | next.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 2179 | mRecentTasks.addLocked(next.task); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2180 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2181 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2182 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2183 | |
| 2184 | // Have the window manager re-evaluate the orientation of |
| 2185 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2186 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2187 | if (mStackSupervisor.isFocusedStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2188 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2189 | mService.mConfiguration, |
| 2190 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2191 | if (config != null) { |
| 2192 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2193 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2194 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2195 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2196 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2197 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2198 | // The configuration update wasn't able to keep the existing |
| 2199 | // instance of the activity, and instead started a new one. |
| 2200 | // We should be all done, but let's just make sure our activity |
| 2201 | // is still at the top and schedule another run if something |
| 2202 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2203 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2204 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2205 | "Activity config changed during resume: " + next |
| 2206 | + ", new next: " + nextNext); |
| 2207 | if (nextNext != next) { |
| 2208 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2209 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2210 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2211 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2212 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2213 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2214 | return true; |
| 2215 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2216 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2217 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2218 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2219 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2220 | try { |
| 2221 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2222 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2223 | if (a != null) { |
| 2224 | final int N = a.size(); |
| 2225 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2226 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2227 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2228 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2233 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2236 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2237 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2238 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2239 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2240 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2241 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2242 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2243 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2244 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2245 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2246 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2247 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2248 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2249 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2250 | } catch (Exception e) { |
| 2251 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2252 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2253 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2254 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2255 | if (lastStack != null) { |
| 2256 | lastStack.mResumedActivity = lastResumedActivity; |
| 2257 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2258 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2259 | if (!next.hasBeenLaunched) { |
| 2260 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2261 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2262 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2263 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2264 | next.appToken, next.packageName, next.theme, |
| 2265 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2266 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 2267 | next.windowFlags, null, true); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2268 | next.mStartingWindowState = STARTING_WINDOW_SHOWN; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2269 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2270 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2271 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2272 | return true; |
| 2273 | } |
| 2274 | |
| 2275 | // From this point on, if something goes wrong there is no way |
| 2276 | // to recover the activity. |
| 2277 | try { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2278 | completeResumeLocked(next); |
| 2279 | } catch (Exception e) { |
| 2280 | // If any exception gets thrown, toss away this |
| 2281 | // activity and try the next one. |
| 2282 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2283 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2284 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2285 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2286 | return true; |
| 2287 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2288 | } else { |
| 2289 | // Whoops, need to restart this activity! |
| 2290 | if (!next.hasBeenLaunched) { |
| 2291 | next.hasBeenLaunched = true; |
| 2292 | } else { |
| 2293 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2294 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2295 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2296 | mService.compatibilityInfoForPackageLocked( |
| 2297 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2298 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2299 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2300 | null, true); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2301 | next.mStartingWindowState = STARTING_WINDOW_SHOWN; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2302 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2303 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2304 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2305 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2306 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2309 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2310 | return true; |
| 2311 | } |
| 2312 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2313 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2314 | final int index = mTaskHistory.indexOf(targetTask); |
| 2315 | if (index >= 0) { |
| 2316 | final int numTasks = mTaskHistory.size(); |
| 2317 | for (int i = index + 1; i < numTasks; ++i) { |
| 2318 | TaskRecord task = mTaskHistory.get(i); |
| 2319 | if (task.userId == targetTask.userId) { |
| 2320 | return task; |
| 2321 | } |
| 2322 | } |
| 2323 | } |
| 2324 | return null; |
| 2325 | } |
| 2326 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2327 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2328 | if (position >= mTaskHistory.size()) { |
| 2329 | insertTaskAtTop(task, null); |
| 2330 | return; |
| 2331 | } |
| 2332 | // Calculate maximum possible position for this task. |
| 2333 | int maxPosition = mTaskHistory.size(); |
| 2334 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2335 | && task.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2336 | // Put non-current user tasks below current user tasks. |
| 2337 | while (maxPosition > 0) { |
| 2338 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2339 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2340 | || tmpTask.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2341 | break; |
| 2342 | } |
| 2343 | maxPosition--; |
| 2344 | } |
| 2345 | } |
| 2346 | position = Math.min(position, maxPosition); |
| 2347 | mTaskHistory.remove(task); |
| 2348 | mTaskHistory.add(position, task); |
| 2349 | updateTaskMovement(task, true); |
| 2350 | } |
| 2351 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2352 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2353 | // If the moving task is over home stack, transfer its return type to next task |
| 2354 | if (task.isOverHomeStack()) { |
| 2355 | final TaskRecord nextTask = getNextTask(task); |
| 2356 | if (nextTask != null) { |
| 2357 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
| 2358 | } |
| 2359 | } |
| 2360 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2361 | // 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] | 2362 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2363 | if (isOnHomeDisplay()) { |
| 2364 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2365 | final boolean fromHome = lastStack.isHomeStack(); |
| 2366 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2367 | int returnToType = APPLICATION_ACTIVITY_TYPE; |
| 2368 | if (fromHome && StackId.allowTopTaskToReturnHome(mStackId)) { |
| 2369 | returnToType = lastStack.topTask() == null |
| 2370 | ? HOME_ACTIVITY_TYPE : lastStack.topTask().taskType; |
| 2371 | } |
| 2372 | task.setTaskToReturnTo(returnToType); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2373 | } |
| 2374 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2375 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2376 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2377 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2378 | mTaskHistory.remove(task); |
| 2379 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2380 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2381 | final boolean notShownWhenLocked = |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2382 | (newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2383 | || (newActivity == null && task.topRunningActivityLocked() == null); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2384 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2385 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2386 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2387 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2388 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2389 | || tmpTask.topRunningActivityLocked() == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2390 | break; |
| 2391 | } |
| 2392 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2393 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2394 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2395 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2396 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2397 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2398 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 2399 | final void startActivityLocked(ActivityRecord r, boolean newTask, boolean keepCurTransition, |
| 2400 | ActivityOptions options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2401 | TaskRecord rTask = r.task; |
| 2402 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2403 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2404 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2405 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2406 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2407 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2408 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2409 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2410 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2411 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2412 | if (!newTask) { |
| 2413 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2414 | boolean startIt = true; |
| 2415 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2416 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2417 | if (task.getTopActivity() == null) { |
| 2418 | // All activities in task are finishing. |
| 2419 | continue; |
| 2420 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2421 | if (task == r.task) { |
| 2422 | // Here it is! Now, if this is not yet visible to the |
| 2423 | // user, then just add it without starting; it will |
| 2424 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2425 | if (!startIt) { |
| 2426 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2427 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2428 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2429 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2430 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2431 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2432 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2433 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2434 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2435 | return; |
| 2436 | } |
| 2437 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2438 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2439 | startIt = false; |
| 2440 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | // Place a new activity at top of stack, so it is next to interact |
| 2445 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2446 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2447 | // If we are not placing the new activity frontmost, we do not want |
| 2448 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2449 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2450 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2451 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2452 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2453 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2454 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2455 | |
| 2456 | task = r.task; |
| 2457 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2458 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2459 | 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] | 2460 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2461 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2462 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2463 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2464 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2465 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2466 | // We want to show the starting preview window if we are |
| 2467 | // switching to a new task, or the next activity's process is |
| 2468 | // not currently running. |
| 2469 | boolean showStartingIcon = newTask; |
| 2470 | ProcessRecord proc = r.app; |
| 2471 | if (proc == null) { |
| 2472 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2473 | } |
| 2474 | if (proc == null || proc.thread == null) { |
| 2475 | showStartingIcon = true; |
| 2476 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2477 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2478 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2479 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2480 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2481 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2482 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2483 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2484 | ? r.mLaunchTaskBehind |
| 2485 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2486 | : AppTransition.TRANSIT_TASK_OPEN |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2487 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2488 | mNoAnimActivities.remove(r); |
| 2489 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2490 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2491 | boolean doShow = true; |
| 2492 | if (newTask) { |
| 2493 | // Even though this activity is starting fresh, we still need |
| 2494 | // to reset it to make sure we apply affinities to move any |
| 2495 | // existing activities from other tasks in to it. |
| 2496 | // If the caller has requested that the target task be |
| 2497 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2498 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2499 | resetTaskIfNeededLocked(r, r); |
| 2500 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2501 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2502 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2503 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2504 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2505 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2506 | if (r.mLaunchTaskBehind) { |
| 2507 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2508 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2509 | mWindowManager.setAppVisibility(r.appToken, true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2510 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2511 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2512 | // Figure out if we are transitioning from another activity that is |
| 2513 | // "has the same starting icon" as the next one. This allows the |
| 2514 | // window manager to keep the previous window it had previously |
| 2515 | // created, if it still had one. |
| 2516 | ActivityRecord prev = mResumedActivity; |
| 2517 | if (prev != null) { |
| 2518 | // We don't want to reuse the previous starting preview if: |
| 2519 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2520 | if (prev.task != r.task) { |
| 2521 | prev = null; |
| 2522 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2523 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2524 | else if (prev.nowVisible) { |
| 2525 | prev = null; |
| 2526 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2527 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2528 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2529 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2530 | mService.compatibilityInfoForPackageLocked( |
| 2531 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2532 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2533 | prev != null ? prev.appToken : null, showStartingIcon); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2534 | r.mStartingWindowState = STARTING_WINDOW_SHOWN; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2535 | } |
| 2536 | } else { |
| 2537 | // If this is the first activity, don't do any fancy animations, |
| 2538 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2539 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2540 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2541 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2542 | } |
| 2543 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2544 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2545 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2548 | final void validateAppTokensLocked() { |
| 2549 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2550 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2551 | final int numTasks = mTaskHistory.size(); |
| 2552 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2553 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2554 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2555 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2556 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2557 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2558 | TaskGroup group = new TaskGroup(); |
| 2559 | group.taskId = task.taskId; |
| 2560 | mValidateAppTokens.add(group); |
| 2561 | final int numActivities = activities.size(); |
| 2562 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2563 | final ActivityRecord r = activities.get(activityNdx); |
| 2564 | group.tokens.add(r.appToken); |
| 2565 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2566 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2567 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2568 | } |
| 2569 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2570 | /** |
| 2571 | * Perform a reset of the given task, if needed as part of launching it. |
| 2572 | * Returns the new HistoryRecord at the top of the task. |
| 2573 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2574 | /** |
| 2575 | * Helper method for #resetTaskIfNeededLocked. |
| 2576 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2577 | * for another task, or leave it as-is. |
| 2578 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2579 | * @param forceReset |
| 2580 | * @return An ActivityOptions that needs to be processed. |
| 2581 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2582 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2583 | ActivityOptions topOptions = null; |
| 2584 | |
| 2585 | int replyChainEnd = -1; |
| 2586 | boolean canMoveOptions = true; |
| 2587 | |
| 2588 | // We only do this for activities that are not the root of the task (since if we finish |
| 2589 | // the root, we may no longer have the task!). |
| 2590 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2591 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2592 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2593 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2594 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2595 | if (target.frontOfTask) |
| 2596 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2597 | |
| 2598 | final int flags = target.info.flags; |
| 2599 | final boolean finishOnTaskLaunch = |
| 2600 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2601 | final boolean allowTaskReparenting = |
| 2602 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2603 | final boolean clearWhenTaskReset = |
| 2604 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2605 | |
| 2606 | if (!finishOnTaskLaunch |
| 2607 | && !clearWhenTaskReset |
| 2608 | && target.resultTo != null) { |
| 2609 | // If this activity is sending a reply to a previous |
| 2610 | // activity, we can't do anything with it now until |
| 2611 | // we reach the start of the reply chain. |
| 2612 | // XXX note that we are assuming the result is always |
| 2613 | // to the previous activity, which is almost always |
| 2614 | // the case but we really shouldn't count on. |
| 2615 | if (replyChainEnd < 0) { |
| 2616 | replyChainEnd = i; |
| 2617 | } |
| 2618 | } else if (!finishOnTaskLaunch |
| 2619 | && !clearWhenTaskReset |
| 2620 | && allowTaskReparenting |
| 2621 | && target.taskAffinity != null |
| 2622 | && !target.taskAffinity.equals(task.affinity)) { |
| 2623 | // If this activity has an affinity for another |
| 2624 | // task, then we need to move it out of here. We will |
| 2625 | // move it as far out of the way as possible, to the |
| 2626 | // bottom of the activity stack. This also keeps it |
| 2627 | // correctly ordered with any activities we previously |
| 2628 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2629 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2630 | final ActivityRecord bottom = |
| 2631 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2632 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2633 | if (bottom != null && target.taskAffinity != null |
| 2634 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2635 | // If the activity currently at the bottom has the |
| 2636 | // same task affinity as the one we are moving, |
| 2637 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2638 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2639 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2640 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2641 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 2642 | targetTask = createTaskRecord( |
| 2643 | mStackSupervisor.getNextTaskIdForUserLocked(target.userId), |
| 2644 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2645 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2646 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2647 | + " out to new task " + target.task); |
| 2648 | } |
| 2649 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2650 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 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 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2654 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2655 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2656 | if (p.finishing) { |
| 2657 | continue; |
| 2658 | } |
| 2659 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2660 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2661 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2662 | topOptions = p.takeOptionsLocked(); |
| 2663 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2664 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2665 | } |
| 2666 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2667 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2668 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2669 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2670 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2671 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2672 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2673 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2674 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2675 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2676 | } |
| 2677 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2678 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2679 | if (VALIDATE_TOKENS) { |
| 2680 | validateAppTokensLocked(); |
| 2681 | } |
| 2682 | |
| 2683 | replyChainEnd = -1; |
| 2684 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2685 | // If the activity should just be removed -- either |
| 2686 | // because it asks for it, or the task should be |
| 2687 | // cleared -- then finish it and anything that is |
| 2688 | // part of its reply chain. |
| 2689 | int end; |
| 2690 | if (clearWhenTaskReset) { |
| 2691 | // In this case, we want to finish this activity |
| 2692 | // and everything above it, so be sneaky and pretend |
| 2693 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2694 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2695 | } else if (replyChainEnd < 0) { |
| 2696 | end = i; |
| 2697 | } else { |
| 2698 | end = replyChainEnd; |
| 2699 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2700 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2701 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2702 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2703 | if (p.finishing) { |
| 2704 | continue; |
| 2705 | } |
| 2706 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2707 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2708 | topOptions = p.takeOptionsLocked(); |
| 2709 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2710 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2711 | } |
| 2712 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2713 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2714 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2715 | if (finishActivityLocked( |
| 2716 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2717 | end--; |
| 2718 | srcPos--; |
| 2719 | } |
| 2720 | } |
| 2721 | replyChainEnd = -1; |
| 2722 | } else { |
| 2723 | // If we were in the middle of a chain, well the |
| 2724 | // activity that started it all doesn't want anything |
| 2725 | // special, so leave it all as-is. |
| 2726 | replyChainEnd = -1; |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | return topOptions; |
| 2731 | } |
| 2732 | |
| 2733 | /** |
| 2734 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2735 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2736 | * @param affinityTask The task we are looking for an affinity to. |
| 2737 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2738 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2739 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2740 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2741 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2742 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2743 | int replyChainEnd = -1; |
| 2744 | final int taskId = task.taskId; |
| 2745 | final String taskAffinity = task.affinity; |
| 2746 | |
| 2747 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2748 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2749 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 2750 | |
| 2751 | // Do not operate on or below the effective root Activity. |
| 2752 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2753 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2754 | if (target.frontOfTask) |
| 2755 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2756 | |
| 2757 | final int flags = target.info.flags; |
| 2758 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2759 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2760 | |
| 2761 | if (target.resultTo != null) { |
| 2762 | // If this activity is sending a reply to a previous |
| 2763 | // activity, we can't do anything with it now until |
| 2764 | // we reach the start of the reply chain. |
| 2765 | // XXX note that we are assuming the result is always |
| 2766 | // to the previous activity, which is almost always |
| 2767 | // the case but we really shouldn't count on. |
| 2768 | if (replyChainEnd < 0) { |
| 2769 | replyChainEnd = i; |
| 2770 | } |
| 2771 | } else if (topTaskIsHigher |
| 2772 | && allowTaskReparenting |
| 2773 | && taskAffinity != null |
| 2774 | && taskAffinity.equals(target.taskAffinity)) { |
| 2775 | // This activity has an affinity for our task. Either remove it if we are |
| 2776 | // clearing or move it over to our task. Note that |
| 2777 | // we currently punt on the case where we are resetting a |
| 2778 | // task that is not at the top but who has activities above |
| 2779 | // with an affinity to it... this is really not a normal |
| 2780 | // case, and we will need to later pull that task to the front |
| 2781 | // and usually at that point we will do the reset and pick |
| 2782 | // up those remaining activities. (This only happens if |
| 2783 | // someone starts an activity in a new task from an activity |
| 2784 | // in a task that is not currently on top.) |
| 2785 | if (forceReset || finishOnTaskLaunch) { |
| 2786 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2787 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2788 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2789 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2790 | final ActivityRecord p = activities.get(srcPos); |
| 2791 | if (p.finishing) { |
| 2792 | continue; |
| 2793 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2794 | finishActivityLocked( |
| 2795 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2796 | } |
| 2797 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2798 | if (taskInsertionPoint < 0) { |
| 2799 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2800 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2801 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2802 | |
| 2803 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2804 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2805 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 2806 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2807 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2808 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2809 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2810 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2811 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2812 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2813 | "Removing and adding activity " + p + " to stack at " + task |
| 2814 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2815 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 2816 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2817 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2818 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2819 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2820 | if (VALIDATE_TOKENS) { |
| 2821 | validateAppTokensLocked(); |
| 2822 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2823 | |
| 2824 | // Now we've moved it in to place... but what if this is |
| 2825 | // a singleTop activity and we have put it on top of another |
| 2826 | // instance of the same activity? Then we drop the instance |
| 2827 | // below so it remains singleTop. |
| 2828 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2829 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2830 | int targetNdx = taskActivities.indexOf(target); |
| 2831 | if (targetNdx > 0) { |
| 2832 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2833 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2834 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2835 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | } |
| 2839 | } |
| 2840 | |
| 2841 | replyChainEnd = -1; |
| 2842 | } |
| 2843 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2844 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2845 | } |
| 2846 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2847 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2848 | ActivityRecord newActivity) { |
| 2849 | boolean forceReset = |
| 2850 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2851 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2852 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2853 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2854 | forceReset = true; |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | final TaskRecord task = taskTop.task; |
| 2859 | |
| 2860 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2861 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2862 | boolean taskFound = false; |
| 2863 | |
| 2864 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2865 | ActivityOptions topOptions = null; |
| 2866 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2867 | // Preserve the location for reparenting in the new task. |
| 2868 | int reparentInsertionPoint = -1; |
| 2869 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2870 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2871 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2872 | |
| 2873 | if (targetTask == task) { |
| 2874 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2875 | taskFound = true; |
| 2876 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2877 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2878 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2879 | } |
| 2880 | } |
| 2881 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2882 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 2883 | if (taskNdx >= 0) { |
| 2884 | do { |
| 2885 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2886 | } while (taskTop == null && taskNdx >= 0); |
| 2887 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2888 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2889 | if (topOptions != null) { |
| 2890 | // If we got some ActivityOptions from an activity on top that |
| 2891 | // was removed from the task, propagate them to the new real top. |
| 2892 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2893 | taskTop.updateOptionsLocked(topOptions); |
| 2894 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2895 | topOptions.abort(); |
| 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | return taskTop; |
| 2900 | } |
| 2901 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2902 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2903 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2904 | |
| 2905 | if (callingUid > 0) { |
| 2906 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2907 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2911 | + " : who=" + resultWho + " req=" + requestCode |
| 2912 | + " res=" + resultCode + " data=" + data); |
| 2913 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2914 | try { |
| 2915 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2916 | list.add(new ResultInfo(resultWho, requestCode, |
| 2917 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2918 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2919 | return; |
| 2920 | } catch (Exception e) { |
| 2921 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2926 | } |
| 2927 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2928 | private void adjustFocusedActivityLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2929 | if (!mStackSupervisor.isFocusedStack(this) || mService.mFocusedActivity != r) { |
| 2930 | return; |
| 2931 | } |
| 2932 | |
| 2933 | final ActivityRecord next = topRunningActivityLocked(); |
| 2934 | final String myReason = reason + " adjustFocus"; |
| 2935 | if (next != r) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2936 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2937 | // For freeform, docked, and pinned stacks we always keep the focus within the |
| 2938 | // stack as long as there is a running activity in the stack that we can adjust |
| 2939 | // focus to. |
| 2940 | mService.setFocusedActivityLocked(next, myReason); |
| 2941 | return; |
| 2942 | } else { |
| 2943 | final TaskRecord task = r.task; |
| 2944 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
| 2945 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 2946 | // stack to prevent the home screen from moving to the top and obscuring |
| 2947 | // other visible stacks. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2948 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2949 | return; |
| 2950 | } |
| 2951 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 2952 | // other visible stack. |
| 2953 | if (mStackSupervisor.moveHomeStackTaskToTop( |
| 2954 | task.getTaskToReturnTo(), myReason)) { |
| 2955 | // Activity focus was already adjusted. Nothing else to do... |
| 2956 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 2957 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2958 | } |
| 2959 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2960 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2961 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2962 | mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked(), myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2965 | private boolean adjustFocusToNextFocusableStackLocked(String reason) { |
| 2966 | final ActivityStack stack = getNextFocusableStackLocked(); |
| 2967 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2968 | if (stack == null) { |
| 2969 | return false; |
| 2970 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2971 | return mService.setFocusedActivityLocked(stack.topRunningActivityLocked(), myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2972 | } |
| 2973 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2974 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2975 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2976 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2977 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2978 | if (!r.finishing) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2979 | if (!mService.isSleeping()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2980 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 2981 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 2982 | "stop-no-history", false)) { |
| 2983 | // Activity was finished, no need to continue trying to schedule stop. |
| 2984 | adjustFocusedActivityLocked(r, "stopActivityFinished"); |
| 2985 | r.resumeKeyDispatchingLocked(); |
| 2986 | return; |
| 2987 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2988 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2989 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2990 | + " on stop because we're just sleeping"); |
| 2991 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2992 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2996 | adjustFocusedActivityLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2997 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2998 | try { |
| 2999 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3000 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3001 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3002 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3003 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3004 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3005 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3006 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3007 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3008 | EventLogTags.writeAmStopActivity( |
| 3009 | r.userId, System.identityHashCode(r), r.shortComponentName); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3010 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 3011 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3012 | r.setSleeping(true); |
| 3013 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3014 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3015 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3016 | } catch (Exception e) { |
| 3017 | // Maybe just ignore exceptions here... if the process |
| 3018 | // has crashed, our death notification will clean things |
| 3019 | // up. |
| 3020 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3021 | // Just in case, assume it to be stopped. |
| 3022 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3023 | 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] | 3024 | r.state = ActivityState.STOPPED; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3025 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3026 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3027 | } |
| 3028 | } |
| 3029 | } |
| 3030 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3031 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3032 | /** |
| 3033 | * @return Returns true if the activity is being finished, false if for |
| 3034 | * some reason it is being left as-is. |
| 3035 | */ |
| 3036 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3037 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3038 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3039 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3040 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3041 | + ", result=" + resultCode + ", data=" + resultData |
| 3042 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3043 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3044 | return false; |
| 3045 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3046 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3047 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3048 | return true; |
| 3049 | } |
| 3050 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3051 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3052 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3053 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3054 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3055 | ActivityRecord r = activities.get(activityNdx); |
| 3056 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3057 | if ((r.resultWho == null && resultWho == null) || |
| 3058 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3059 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3060 | false); |
| 3061 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3065 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3068 | final TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3069 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3070 | TaskRecord finishedTask = null; |
| 3071 | if (r == null || r.app != app) { |
| 3072 | return null; |
| 3073 | } |
| 3074 | Slog.w(TAG, " Force finishing activity " |
| 3075 | + r.intent.getComponent().flattenToShortString()); |
| 3076 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 3077 | int activityNdx = r.task.mActivities.indexOf(r); |
| 3078 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
| 3079 | finishedTask = r.task; |
| 3080 | // Also terminate any activities below it that aren't yet |
| 3081 | // stopped, to avoid a situation where one will get |
| 3082 | // re-start our crashing activity once it gets resumed again. |
| 3083 | --activityNdx; |
| 3084 | if (activityNdx < 0) { |
| 3085 | do { |
| 3086 | --taskNdx; |
| 3087 | if (taskNdx < 0) { |
| 3088 | break; |
| 3089 | } |
| 3090 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3091 | } while (activityNdx < 0); |
| 3092 | } |
| 3093 | if (activityNdx >= 0) { |
| 3094 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
| 3095 | if (r.state == ActivityState.RESUMED |
| 3096 | || r.state == ActivityState.PAUSING |
| 3097 | || r.state == ActivityState.PAUSED) { |
| 3098 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
| 3099 | Slog.w(TAG, " Force finishing activity " |
| 3100 | + r.intent.getComponent().flattenToShortString()); |
| 3101 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3102 | } |
| 3103 | } |
| 3104 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3105 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3106 | } |
| 3107 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3108 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3109 | IBinder sessionBinder = session.asBinder(); |
| 3110 | boolean didOne = false; |
| 3111 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3112 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3113 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3114 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3115 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3116 | if (!r.finishing) { |
| 3117 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3118 | false); |
| 3119 | didOne = true; |
| 3120 | } |
| 3121 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3122 | } else { |
| 3123 | // Check if any of the activities are using voice |
| 3124 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3125 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3126 | if (r.voiceSession != null |
| 3127 | && r.voiceSession.asBinder() == sessionBinder) { |
| 3128 | // Inform of cancellation |
| 3129 | r.clearVoiceSessionLocked(); |
| 3130 | try { |
| 3131 | r.app.thread.scheduleLocalVoiceInteractionStarted((IBinder) r.appToken, |
| 3132 | null); |
| 3133 | } catch (RemoteException re) { |
| 3134 | // Ok |
| 3135 | } |
| 3136 | // TODO: VI This is redundant in some cases |
| 3137 | mService.finishRunningVoiceLocked(); |
| 3138 | break; |
| 3139 | } |
| 3140 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3141 | } |
| 3142 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3143 | Slog.d(TAG, "ActivityStack.finishVoiceTask()"); |
| 3144 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3145 | if (didOne) { |
| 3146 | mService.updateOomAdjLocked(); |
| 3147 | } |
| 3148 | } |
| 3149 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3150 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3151 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 3152 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3153 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3154 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3155 | break; |
| 3156 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3157 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3158 | } |
| 3159 | return true; |
| 3160 | } |
| 3161 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3162 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 3163 | // send the result |
| 3164 | ActivityRecord resultTo = r.resultTo; |
| 3165 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3166 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3167 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3168 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3169 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3170 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3171 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3172 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3173 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3174 | if (r.info.applicationInfo.uid > 0) { |
| 3175 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3176 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3177 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3178 | } |
| 3179 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3180 | resultData); |
| 3181 | r.resultTo = null; |
| 3182 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3183 | 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] | 3184 | |
| 3185 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3186 | // because clients have remote IPC references to this object so we |
| 3187 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3188 | r.results = null; |
| 3189 | r.pendingResults = null; |
| 3190 | r.newIntents = null; |
| 3191 | r.icicle = null; |
| 3192 | } |
| 3193 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3194 | /** |
| 3195 | * @return Returns true if this activity has been removed from the history |
| 3196 | * list, or false if it is still in the list and will be removed later. |
| 3197 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3198 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3199 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3200 | if (r.finishing) { |
| 3201 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3202 | return false; |
| 3203 | } |
| 3204 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3205 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3206 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3207 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3208 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3209 | task.taskId, r.shortComponentName, reason); |
| 3210 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3211 | final int index = activities.indexOf(r); |
| 3212 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3213 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3214 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3215 | // If the caller asked that this activity (and all above it) |
| 3216 | // be cleared when the task is reset, don't lose that information, |
| 3217 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3218 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3219 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3224 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3225 | adjustFocusedActivityLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3226 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3227 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3228 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3229 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3230 | boolean endTask = index <= 0; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3231 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3232 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3233 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3234 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 3235 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3236 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3237 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3238 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3239 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3240 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3241 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3242 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3243 | "finish() => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3244 | startPausingLocked(false, false, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3247 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3248 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3249 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3250 | } else if (r.state != ActivityState.PAUSING) { |
| 3251 | // If the activity is PAUSING, we will complete the finish once |
| 3252 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3253 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3254 | if (r.visible) { |
| 3255 | mWindowManager.setAppVisibility(r.appToken, false); |
| 3256 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3257 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3258 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3259 | 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] | 3260 | } |
| 3261 | |
| 3262 | return false; |
| 3263 | } |
| 3264 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3265 | static final int FINISH_IMMEDIATELY = 0; |
| 3266 | static final int FINISH_AFTER_PAUSE = 1; |
| 3267 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3268 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3269 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3270 | // First things first: if this activity is currently visible, |
| 3271 | // and the resumed activity is not yet visible, then hold off on |
| 3272 | // finishing until the resumed one becomes visible. |
| 3273 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3274 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 3275 | addToStopping(r, false /* immediate */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3276 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3277 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3278 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3279 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3280 | if (oomAdj) { |
| 3281 | mService.updateOomAdjLocked(); |
| 3282 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3283 | return r; |
| 3284 | } |
| 3285 | |
| 3286 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3287 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3288 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3289 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3290 | if (mResumedActivity == r) { |
| 3291 | mResumedActivity = null; |
| 3292 | } |
| 3293 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3294 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3295 | r.state = ActivityState.FINISHING; |
| 3296 | |
| 3297 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3298 | || (mode == FINISH_AFTER_PAUSE && prevState == ActivityState.PAUSED) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3299 | || prevState == ActivityState.STOPPED |
| 3300 | || prevState == ActivityState.INITIALIZING) { |
| 3301 | // If this activity is already stopped, we can just finish |
| 3302 | // it right now. |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3303 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3304 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3305 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3306 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3307 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3308 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3309 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3310 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3311 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3312 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3313 | |
| 3314 | // Need to go through the full pause cycle to get this |
| 3315 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3316 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3317 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3318 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3319 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3320 | return r; |
| 3321 | } |
| 3322 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3323 | void finishAllActivitiesLocked(boolean immediately) { |
| 3324 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3325 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3326 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3327 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3328 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3329 | noActivitiesInStack = false; |
| 3330 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3331 | continue; |
| 3332 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3333 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3334 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3335 | } |
| 3336 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3337 | if (noActivitiesInStack) { |
| 3338 | mActivityContainer.onTaskListEmptyLocked(); |
| 3339 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3342 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3343 | // Basic case: for simple app-centric recents, we need to recreate |
| 3344 | // the task if the affinity has changed. |
| 3345 | if (srec == null || srec.task.affinity == null || |
| 3346 | !srec.task.affinity.equals(destAffinity)) { |
| 3347 | return true; |
| 3348 | } |
| 3349 | // Document-centric case: an app may be split in to multiple documents; |
| 3350 | // they need to re-create their task if this current activity is the root |
| 3351 | // of a document, unless simply finishing it will return them to the the |
| 3352 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3353 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3354 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3355 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3356 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3357 | // Finishing won't return to an application, so we need to recreate. |
| 3358 | return true; |
| 3359 | } |
| 3360 | // We now need to get the task below it to determine what to do. |
| 3361 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3362 | if (taskIdx <= 0) { |
| 3363 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3364 | return false; |
| 3365 | } |
| 3366 | if (taskIdx == 0) { |
| 3367 | // At the bottom of the stack, nothing to go back to. |
| 3368 | return true; |
| 3369 | } |
| 3370 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3371 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3372 | // These are different apps, so need to recreate. |
| 3373 | return true; |
| 3374 | } |
| 3375 | } |
| 3376 | return false; |
| 3377 | } |
| 3378 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3379 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3380 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3381 | final TaskRecord task = srec.task; |
| 3382 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3383 | final int start = activities.indexOf(srec); |
| 3384 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3385 | return false; |
| 3386 | } |
| 3387 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3388 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3389 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3390 | final ComponentName dest = destIntent.getComponent(); |
| 3391 | if (start > 0 && dest != null) { |
| 3392 | for (int i = finishTo; i >= 0; i--) { |
| 3393 | ActivityRecord r = activities.get(i); |
| 3394 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3395 | r.info.name.equals(dest.getClassName())) { |
| 3396 | finishTo = i; |
| 3397 | parent = r; |
| 3398 | foundParentInTask = true; |
| 3399 | break; |
| 3400 | } |
| 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | IActivityController controller = mService.mController; |
| 3405 | if (controller != null) { |
| 3406 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3407 | if (next != null) { |
| 3408 | // ask watcher if this is allowed |
| 3409 | boolean resumeOK = true; |
| 3410 | try { |
| 3411 | resumeOK = controller.activityResuming(next.packageName); |
| 3412 | } catch (RemoteException e) { |
| 3413 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3414 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | if (!resumeOK) { |
| 3418 | return false; |
| 3419 | } |
| 3420 | } |
| 3421 | } |
| 3422 | final long origId = Binder.clearCallingIdentity(); |
| 3423 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3424 | ActivityRecord r = activities.get(i); |
| 3425 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3426 | // Only return the supplied result for the first activity finished |
| 3427 | resultCode = Activity.RESULT_CANCELED; |
| 3428 | resultData = null; |
| 3429 | } |
| 3430 | |
| 3431 | if (parent != null && foundParentInTask) { |
| 3432 | final int parentLaunchMode = parent.info.launchMode; |
| 3433 | final int destIntentFlags = destIntent.getFlags(); |
| 3434 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3435 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3436 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3437 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3438 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3439 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3440 | } else { |
| 3441 | try { |
| 3442 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3443 | destIntent.getComponent(), 0, srec.userId); |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 3444 | int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, |
| 3445 | destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, |
| 3446 | null, parent.appToken, null, 0, -1, parent.launchedFromUid, |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 3447 | parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, |
| 3448 | false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3449 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3450 | } catch (RemoteException e) { |
| 3451 | foundParentInTask = false; |
| 3452 | } |
| 3453 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3454 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | Binder.restoreCallingIdentity(origId); |
| 3458 | return foundParentInTask; |
| 3459 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3460 | /** |
| 3461 | * Perform the common clean-up of an activity record. This is called both |
| 3462 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3463 | * representation) and cleaning things up as a result of its hosting |
| 3464 | * processing going away, in which case there is no remaining client-side |
| 3465 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3466 | * |
| 3467 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3468 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3469 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3470 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3471 | if (mResumedActivity == r) { |
| 3472 | mResumedActivity = null; |
| 3473 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3474 | if (mPausingActivity == r) { |
| 3475 | mPausingActivity = null; |
| 3476 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3477 | mService.resetFocusedActivityIfNeededLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3478 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3479 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3480 | r.frozenBeforeDestroy = false; |
| 3481 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3482 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3483 | 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] | 3484 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3485 | 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] | 3486 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3489 | // Make sure this record is no longer in the pending finishes list. |
| 3490 | // This could happen, for example, if we are trimming activities |
| 3491 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3492 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3493 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3494 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3495 | // Remove any pending results. |
| 3496 | if (r.finishing && r.pendingResults != null) { |
| 3497 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3498 | PendingIntentRecord rec = apr.get(); |
| 3499 | if (rec != null) { |
| 3500 | mService.cancelIntentSenderLocked(rec, false); |
| 3501 | } |
| 3502 | } |
| 3503 | r.pendingResults = null; |
| 3504 | } |
| 3505 | |
| 3506 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3507 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3510 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3511 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3512 | if (getVisibleBehindActivity() == r) { |
| 3513 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3514 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3518 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3519 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3520 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3521 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3522 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3525 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3526 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3527 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3528 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3529 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3530 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3531 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3532 | r.takeFromHistory(); |
| 3533 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3534 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3535 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3536 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3537 | 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] | 3538 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3539 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3540 | if (VALIDATE_TOKENS) { |
| 3541 | validateAppTokensLocked(); |
| 3542 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3543 | final TaskRecord task = r.task; |
| 3544 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3545 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3546 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3547 | if (mStackSupervisor.isFocusedStack(this) && task == topTask() && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3548 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3549 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3550 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3551 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3552 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3553 | cleanUpActivityServicesLocked(r); |
| 3554 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3555 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3556 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3557 | /** |
| 3558 | * Perform clean-up of service connections in an activity record. |
| 3559 | */ |
| 3560 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3561 | // Throw away any services that have been bound by this activity. |
| 3562 | if (r.connections != null) { |
| 3563 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3564 | while (it.hasNext()) { |
| 3565 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3566 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3567 | } |
| 3568 | r.connections = null; |
| 3569 | } |
| 3570 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3571 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3572 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3573 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3574 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3575 | mHandler.sendMessage(msg); |
| 3576 | } |
| 3577 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3578 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3579 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3580 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3581 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3582 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3583 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3584 | final ActivityRecord r = activities.get(activityNdx); |
| 3585 | if (r.finishing) { |
| 3586 | continue; |
| 3587 | } |
| 3588 | if (r.fullscreen) { |
| 3589 | lastIsOpaque = true; |
| 3590 | } |
| 3591 | if (owner != null && r.app != owner) { |
| 3592 | continue; |
| 3593 | } |
| 3594 | if (!lastIsOpaque) { |
| 3595 | continue; |
| 3596 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3597 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3598 | 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] | 3599 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3600 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3601 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3602 | activityRemoved = true; |
| 3603 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3604 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3605 | } |
| 3606 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3607 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3608 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3609 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3612 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3613 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3614 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3615 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3616 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3617 | return destroyActivityLocked(r, true, reason); |
| 3618 | } |
| 3619 | return false; |
| 3620 | } |
| 3621 | |
| 3622 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3623 | String reason) { |
| 3624 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3625 | 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] | 3626 | int maxTasks = tasks.size() / 4; |
| 3627 | if (maxTasks < 1) { |
| 3628 | maxTasks = 1; |
| 3629 | } |
| 3630 | int numReleased = 0; |
| 3631 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3632 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3633 | if (!tasks.contains(task)) { |
| 3634 | continue; |
| 3635 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3636 | 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] | 3637 | int curNum = 0; |
| 3638 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3639 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3640 | final ActivityRecord activity = activities.get(actNdx); |
| 3641 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3642 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3643 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3644 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3645 | destroyActivityLocked(activity, true, reason); |
| 3646 | if (activities.get(actNdx) != activity) { |
| 3647 | // Was removed from list, back up so we don't miss the next one. |
| 3648 | actNdx--; |
| 3649 | } |
| 3650 | curNum++; |
| 3651 | } |
| 3652 | } |
| 3653 | if (curNum > 0) { |
| 3654 | numReleased += curNum; |
| 3655 | maxTasks--; |
| 3656 | if (mTaskHistory.get(taskNdx) != task) { |
| 3657 | // The entire task got removed, back up so we don't miss the next one. |
| 3658 | taskNdx--; |
| 3659 | } |
| 3660 | } |
| 3661 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3662 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3663 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3664 | return numReleased; |
| 3665 | } |
| 3666 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3667 | /** |
| 3668 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3669 | * called both when actually finishing an activity, or when performing |
| 3670 | * a configuration switch where we destroy the current client-side object |
| 3671 | * but then create a new client-side object for this same HistoryRecord. |
| 3672 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3673 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3674 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3675 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3676 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3677 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3678 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3679 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3680 | |
| 3681 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3682 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3683 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3684 | |
| 3685 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3686 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3687 | if (hadApp) { |
| 3688 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3689 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3690 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 3691 | mService.mHeavyWeightProcess = null; |
| 3692 | mService.mHandler.sendEmptyMessage( |
| 3693 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 3694 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3695 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 3696 | // Update any services we are bound to that might care about whether |
| 3697 | // their client may have activities. |
| 3698 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 3699 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 3700 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3701 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3706 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3707 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3708 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3709 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3710 | r.configChangeFlags); |
| 3711 | } catch (Exception e) { |
| 3712 | // We can just ignore exceptions here... if the process |
| 3713 | // has crashed, our death notification will clean things |
| 3714 | // up. |
| 3715 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 3716 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3717 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3718 | removedFromHistory = true; |
| 3719 | skipDestroy = true; |
| 3720 | } |
| 3721 | } |
| 3722 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3723 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3724 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3725 | // If the activity is finishing, we need to wait on removing it |
| 3726 | // from the list to give it a chance to do its cleanup. During |
| 3727 | // that time it may make calls back with its token so we need to |
| 3728 | // be able to find it on the list and so we don't want to remove |
| 3729 | // it from the list yet. Otherwise, we can just immediately put |
| 3730 | // it in the destroyed state since we are not removing it from the |
| 3731 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3732 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3733 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3734 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3735 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3736 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3737 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 3738 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3739 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3740 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3741 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3742 | 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] | 3743 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3744 | } |
| 3745 | } else { |
| 3746 | // remove this record from the history. |
| 3747 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3748 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3749 | removedFromHistory = true; |
| 3750 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3751 | 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] | 3752 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3753 | 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] | 3754 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3759 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3760 | if (!mLRUActivities.remove(r) && hadApp) { |
| 3761 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 3762 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3763 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3764 | return removedFromHistory; |
| 3765 | } |
| 3766 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3767 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3768 | final long origId = Binder.clearCallingIdentity(); |
| 3769 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3770 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3771 | if (r != null) { |
| 3772 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3773 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3774 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3775 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3776 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3777 | if (r.state == ActivityState.DESTROYING) { |
| 3778 | cleanUpActivityLocked(r, true, false); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3779 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3780 | } |
| 3781 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3782 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3783 | } finally { |
| 3784 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3785 | } |
| 3786 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3787 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 3788 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3789 | if (hasVisibleBehindActivity() && |
| 3790 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 3791 | if (r == topRunningActivityLocked() && getStackVisibilityLocked() == STACK_VISIBLE) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3792 | // Don't release the top activity if it has requested to run behind the next |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 3793 | // activity and the stack is currently visible. |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3794 | return; |
| 3795 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3796 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3797 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3798 | " thread=" + r.app.thread); |
| 3799 | if (r != null && r.app != null && r.app.thread != null) { |
| 3800 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3801 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3802 | } catch (RemoteException e) { |
| 3803 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3804 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3805 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3806 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3807 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3812 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3813 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 3814 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3815 | if (r != null) { |
| 3816 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3817 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3818 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3819 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3820 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3823 | boolean hasVisibleBehindActivity() { |
| 3824 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3825 | } |
| 3826 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3827 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3828 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3829 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3833 | ActivityRecord getVisibleBehindActivity() { |
| 3834 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3837 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 3838 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3839 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3840 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3841 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3842 | while (i > 0) { |
| 3843 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3844 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3845 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3846 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3847 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3848 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3849 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3850 | } |
| 3851 | } |
| 3852 | } |
| 3853 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3854 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 3855 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3856 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 3857 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3858 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 3859 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3860 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3861 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3862 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 3863 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3864 | |
| 3865 | boolean hasVisibleActivities = false; |
| 3866 | |
| 3867 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3868 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3869 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3870 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3871 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3872 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3873 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3874 | final ActivityRecord r = activities.get(activityNdx); |
| 3875 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3876 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3877 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3878 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 3879 | if (r.visible) { |
| 3880 | hasVisibleActivities = true; |
| 3881 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3882 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3883 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 3884 | // Don't currently have state for the activity, or |
| 3885 | // it is finishing -- always remove it. |
| 3886 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3887 | } else if (!r.visible && r.launchCount > 2 && |
| 3888 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3889 | // We have launched this activity too many times since it was |
| 3890 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3891 | // (Note if the activity is visible, we don't remove the record. |
| 3892 | // We leave the dead window on the screen but the process will |
| 3893 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3894 | remove = true; |
| 3895 | } else { |
| 3896 | // The process may be gone, but the activity lives on! |
| 3897 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3898 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3899 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3900 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 3901 | "Removing activity " + r + " from stack at " + i |
| 3902 | + ": haveState=" + r.haveState |
| 3903 | + " stateNotNeeded=" + r.stateNotNeeded |
| 3904 | + " finishing=" + r.finishing |
| 3905 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3906 | if (!r.finishing) { |
| 3907 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 3908 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3909 | r.userId, System.identityHashCode(r), |
| 3910 | r.task.taskId, r.shortComponentName, |
| 3911 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3912 | if (r.state == ActivityState.RESUMED) { |
| 3913 | mService.updateUsageStats(r, false); |
| 3914 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3915 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3916 | } else { |
| 3917 | // We have the current state for this activity, so |
| 3918 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3919 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 3920 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 3921 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3922 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3923 | // Set nowVisible to previous visible state. If the app was visible while |
| 3924 | // it died, we leave the dead window on screen so it's basically visible. |
| 3925 | // This is needed when user later tap on the dead window, we need to stop |
| 3926 | // other apps when user transfers focus to the restarted activity. |
| 3927 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3928 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3929 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3930 | "App died, clearing saved state of " + r); |
| 3931 | r.icicle = null; |
| 3932 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3933 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3934 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3935 | if (remove) { |
| 3936 | removeActivityFromHistoryLocked(r, "appDied"); |
| 3937 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3938 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3943 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3944 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3945 | final void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3946 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3947 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3948 | if (r != null && r.state != ActivityState.RESUMED) { |
| 3949 | r.updateOptionsLocked(options); |
| 3950 | } else { |
| 3951 | ActivityOptions.abort(options); |
| 3952 | } |
| 3953 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3954 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3955 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 3956 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3957 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 3958 | if (task.isPersistable) { |
| 3959 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 3960 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 3961 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 3962 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 3963 | if (!toFront) { |
| 3964 | task.mLastTimeMoved *= -1; |
| 3965 | } |
| 3966 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3967 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3970 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3971 | final int top = mTaskHistory.size() - 1; |
| 3972 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 3973 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3974 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3975 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 3976 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3977 | mTaskHistory.remove(taskNdx); |
| 3978 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3979 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3980 | return; |
| 3981 | } |
| 3982 | } |
| 3983 | } |
| 3984 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3985 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3986 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3987 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3988 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3989 | final int numTasks = mTaskHistory.size(); |
| 3990 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3991 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3992 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3993 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3994 | ActivityOptions.abort(options); |
| 3995 | } else { |
| 3996 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 3997 | } |
| 3998 | return; |
| 3999 | } |
| 4000 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4001 | if (timeTracker != null) { |
| 4002 | // The caller wants a time tracker associated with this task. |
| 4003 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4004 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4005 | } |
| 4006 | } |
| 4007 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4008 | // Shift all activities with this task up to the top |
| 4009 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4010 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4011 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4012 | // Don't refocus if invisible to current user |
| 4013 | ActivityRecord top = tr.getTopActivity(); |
| 4014 | if (!okToShowLocked(top)) { |
| 4015 | addRecentActivityLocked(top); |
| 4016 | ActivityOptions.abort(options); |
| 4017 | return; |
| 4018 | } |
| 4019 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4020 | // Set focus to the top running activity of this stack. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4021 | ActivityRecord r = topRunningActivityLocked(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4022 | mService.setFocusedActivityLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4023 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4024 | 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] | 4025 | if (noAnimation) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4026 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4027 | if (r != null) { |
| 4028 | mNoAnimActivities.add(r); |
| 4029 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4030 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4031 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 4032 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4033 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 4034 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4035 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 4036 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4037 | |
| 4038 | if (VALIDATE_TOKENS) { |
| 4039 | validateAppTokensLocked(); |
| 4040 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4044 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4045 | * 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] | 4046 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4047 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4048 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4049 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4050 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4051 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4052 | * @return Returns true if the move completed, false if not. |
| 4053 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4054 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4055 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4056 | if (tr == null) { |
| 4057 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4058 | return false; |
| 4059 | } |
| 4060 | |
| 4061 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4062 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4063 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4064 | // If we have a watcher, preflight the move before committing to it. First check |
| 4065 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4066 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4067 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4068 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4069 | if (next == null) { |
| 4070 | next = topRunningActivityLocked(null, 0); |
| 4071 | } |
| 4072 | if (next != null) { |
| 4073 | // ask watcher if this is allowed |
| 4074 | boolean moveOK = true; |
| 4075 | try { |
| 4076 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4077 | } catch (RemoteException e) { |
| 4078 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4079 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4080 | } |
| 4081 | if (!moveOK) { |
| 4082 | return false; |
| 4083 | } |
| 4084 | } |
| 4085 | } |
| 4086 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4087 | 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] | 4088 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4089 | if (mStackId == HOME_STACK_ID && topTask().isHomeTask()) { |
| 4090 | // For the case where we are moving the home task back and there is an activity visible |
| 4091 | // behind it on the fullscreen stack, we want to move the focus to the visible behind |
| 4092 | // activity to maintain order with what the user is seeing. |
| 4093 | final ActivityStack fullscreenStack = |
| 4094 | mStackSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
| 4095 | if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) { |
| 4096 | final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity(); |
| 4097 | mService.setFocusedActivityLocked(visibleBehind, "moveTaskToBack"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4098 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4099 | return true; |
| 4100 | } |
| 4101 | } |
| 4102 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4103 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4104 | |
| 4105 | // If true, we should resume the home activity next if the task we are moving to the |
| 4106 | // back is over the home stack. We force to false if the task we are moving to back |
| 4107 | // is the home task and we don't want it resumed after moving to the back. |
| 4108 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4109 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4110 | final TaskRecord nextTask = getNextTask(tr); |
| 4111 | if (nextTask != null) { |
| 4112 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4113 | } else { |
| 4114 | prevIsHome = true; |
| 4115 | } |
| 4116 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4117 | mTaskHistory.remove(tr); |
| 4118 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4119 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4120 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4121 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 4122 | // 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] | 4123 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4124 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4125 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4126 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4127 | break; |
| 4128 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4129 | if (taskNdx == 1) { |
| 4130 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4131 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4132 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4135 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4136 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4137 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4138 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4139 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4142 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4143 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4144 | if (!mService.mBooting && !mService.mBooted) { |
| 4145 | // Not ready yet! |
| 4146 | return false; |
| 4147 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4148 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 4149 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4150 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4153 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4154 | return true; |
| 4155 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4156 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 4157 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4158 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4159 | final Uri data = r.intent.getData(); |
| 4160 | final String strData = data != null ? data.toSafeString() : null; |
| 4161 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4162 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4163 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4164 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4165 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | /** |
| 4169 | * Make sure the given activity matches the current configuration. Returns |
| 4170 | * false if the activity had to be destroyed. Returns true if the |
| 4171 | * configuration is the same, or the activity will remain running as-is |
| 4172 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 4173 | * correct configuration and all other bookkeeping is handled. |
| 4174 | */ |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4175 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, int globalChanges, |
| 4176 | boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4177 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4178 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4179 | "Skipping config check (will change): " + r); |
| 4180 | return true; |
| 4181 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4182 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4183 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4184 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4185 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4186 | // Short circuit: if the two configurations are the exact same |
| 4187 | // object (the common case), then there is nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4188 | final Configuration newConfig = mService.mConfiguration; |
| 4189 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4190 | if (r.configuration == newConfig |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4191 | && r.taskConfigOverride == taskConfig |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4192 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4193 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4194 | "Configuration unchanged in " + r); |
| 4195 | return true; |
| 4196 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4197 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4198 | // We don't worry about activities that are finishing. |
| 4199 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4200 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4201 | "Configuration doesn't matter in finishing " + r); |
| 4202 | r.stopFreezingScreenLocked(false); |
| 4203 | return true; |
| 4204 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4205 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4206 | // Okay we now are going to make this activity have the new config. |
| 4207 | // 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] | 4208 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4209 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4210 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4211 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4212 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4213 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4214 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4215 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4216 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4217 | "Configuration no differences in " + r); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4218 | // There are no significant differences, so we won't relaunch but should still deliver |
| 4219 | // the new configuration to the client process. |
| 4220 | r.scheduleConfigurationChanged(taskConfig, false); |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4221 | return true; |
| 4222 | } |
| 4223 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 4224 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4225 | "Configuration changes for " + r + " ; taskChanges=" |
| 4226 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 4227 | + Configuration.configurationDiffToString(changes)); |
| 4228 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4229 | // If the activity isn't currently running, just leave the new |
| 4230 | // configuration and it will pick that up next time it starts. |
| 4231 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4232 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4233 | "Configuration doesn't matter not running " + r); |
| 4234 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4235 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4236 | return true; |
| 4237 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4238 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4239 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4240 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4241 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4242 | + Integer.toHexString(changes) + ", handles=0x" |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4243 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig |
| 4244 | + ", taskConfig=" + taskConfig); |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4245 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4246 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4247 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4248 | r.configChangeFlags |= changes; |
| 4249 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4250 | r.forceNewConfig = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4251 | preserveWindow &= isResizeOnlyChange(changes); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4252 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4253 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4254 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4255 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4256 | } else if (r.state == ActivityState.PAUSING) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4257 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 4258 | // do anything now, but just flag that it needs to be restarted when done pausing. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4259 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4260 | "Config is skipping already pausing " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4261 | r.deferRelaunchUntilPaused = true; |
| 4262 | r.preserveWindowOnDeferredRelaunch = preserveWindow; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4263 | return true; |
| 4264 | } else if (r.state == ActivityState.RESUMED) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4265 | // Try to optimize this case: the configuration is changing and we need to restart |
| 4266 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4267 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4268 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4269 | "Config is relaunching resumed " + r); |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4270 | |
| 4271 | if (DEBUG_STATES && !r.visible) { |
| 4272 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + r |
| 4273 | + " called by " + Debug.getCallers(4)); |
| 4274 | } |
| 4275 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4276 | relaunchActivityLocked(r, r.configChangeFlags, true, preserveWindow); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4277 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4278 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4279 | "Config is relaunching non-resumed " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4280 | relaunchActivityLocked(r, r.configChangeFlags, false, preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4281 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4282 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4283 | // All done... tell the caller we weren't able to keep this activity around. |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4284 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4285 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4286 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4287 | // 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] | 4288 | // 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] | 4289 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4290 | // system level configuration it last got. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4291 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4292 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4293 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4294 | return true; |
| 4295 | } |
| 4296 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4297 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4298 | Configuration oldTaskOverride) { |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 4299 | |
| 4300 | // If we went from full-screen to non-full-screen, make sure to use the correct |
| 4301 | // configuration task diff, so the diff stays as small as possible. |
| 4302 | if (Configuration.EMPTY.equals(oldTaskOverride) |
| 4303 | && !Configuration.EMPTY.equals(taskConfig)) { |
| 4304 | oldTaskOverride = record.task.extractOverrideConfig(record.configuration); |
| 4305 | } |
| 4306 | |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 4307 | // Conversely, do the same when going the other direction. |
| 4308 | if (Configuration.EMPTY.equals(taskConfig) |
| 4309 | && !Configuration.EMPTY.equals(oldTaskOverride)) { |
| 4310 | taskConfig = record.task.extractOverrideConfig(record.configuration); |
| 4311 | } |
| 4312 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4313 | // Determine what has changed. May be nothing, if this is a config |
| 4314 | // that has come back from the app after going idle. In that case |
| 4315 | // we just want to leave the official config object now in the |
| 4316 | // activity and do nothing else. |
| 4317 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4318 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4319 | // the app. |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4320 | if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4321 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4322 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4323 | || record.crossesVerticalSizeThreshold( |
| 4324 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4325 | if (!crosses) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4326 | taskChanges &= ~CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4327 | } |
| 4328 | } |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4329 | if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4330 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4331 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 4332 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4333 | taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4337 | } |
| 4338 | |
| 4339 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4340 | Configuration oldTaskOverride, int taskChanges) { |
| 4341 | if (taskChanges == 0) { |
| 4342 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4343 | // Check for changes we care about. |
| 4344 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4345 | taskChanges |= CONFIG_ORIENTATION; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4346 | } |
| 4347 | // We want to explicitly track situations where the size configuration goes from |
| 4348 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4349 | // because there is no threshold. |
| 4350 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4351 | final int newHeight = taskConfig.screenHeightDp; |
| 4352 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4353 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4354 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4355 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4356 | } |
| 4357 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4358 | final int newWidth = taskConfig.screenWidthDp; |
| 4359 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4360 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4361 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4362 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4363 | } |
| 4364 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4365 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4366 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4367 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4368 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4369 | taskChanges |= CONFIG_SMALLEST_SCREEN_SIZE; |
| 4370 | } |
| 4371 | final int oldLayout = oldTaskOverride.screenLayout; |
| 4372 | final int newLayout = taskConfig.screenLayout; |
| 4373 | if ((oldLayout == SCREENLAYOUT_UNDEFINED && newLayout != SCREENLAYOUT_UNDEFINED) |
| 4374 | || (oldLayout != SCREENLAYOUT_UNDEFINED && newLayout == SCREENLAYOUT_UNDEFINED)) { |
| 4375 | taskChanges |= CONFIG_SCREEN_LAYOUT; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | return taskChanges; |
| 4379 | } |
| 4380 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4381 | private static boolean isResizeOnlyChange(int change) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4382 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 4383 | | CONFIG_SCREEN_LAYOUT)) == 0; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4386 | private void relaunchActivityLocked( |
| 4387 | ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) { |
| 4388 | if (mService.mSuppressResizeConfigChanges && preserveWindow) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4389 | r.configChangeFlags = 0; |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4390 | return; |
| 4391 | } |
| 4392 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4393 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4394 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4395 | if (andResume) { |
| 4396 | results = r.results; |
| 4397 | newIntents = r.newIntents; |
| 4398 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4399 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4400 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4401 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4402 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4403 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4404 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4405 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4406 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4407 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4408 | mStackSupervisor.removeChildActivityContainers(r); |
| 4409 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4410 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4411 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 4412 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r |
| 4413 | + " callers=" + Debug.getCallers(6)); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4414 | r.forceNewConfig = false; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4415 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4416 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4417 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4418 | mStackSupervisor.activityRelaunchingLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4419 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4420 | // the caller will only pass in 'andResume' if this activity is |
| 4421 | // currently resumed, which implies we aren't sleeping. |
| 4422 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4423 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | if (andResume) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4427 | if (DEBUG_STATES) { |
| 4428 | Slog.d(TAG_STATES, "Resumed after relaunch " + r); |
| 4429 | } |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4430 | r.state = ActivityState.RESUMED; |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4431 | // Relaunch-resume could happen either when the app is already in the front, |
| 4432 | // or while it's being brought to front. In the latter case, it's marked RESUMED |
| 4433 | // but not yet visible (or stopped). We need to complete the resume here as the |
| 4434 | // code in resumeTopActivityInnerLocked to complete the resume might be skipped. |
| 4435 | if (!r.visible || r.stopped) { |
| 4436 | mWindowManager.setAppVisibility(r.appToken, true); |
| 4437 | completeResumeLocked(r); |
| 4438 | } else { |
| 4439 | r.results = null; |
| 4440 | r.newIntents = null; |
| 4441 | } |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4442 | } else { |
| 4443 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4444 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4445 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4446 | |
| 4447 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4448 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4449 | |
| 4450 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4451 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4452 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4453 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4454 | final ActivityRecord r = activities.get(activityNdx); |
| 4455 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4456 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4457 | } |
| 4458 | if (r.fullscreen && !r.finishing) { |
| 4459 | return false; |
| 4460 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4461 | } |
| 4462 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4463 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4464 | if (r == null) { |
| 4465 | return false; |
| 4466 | } |
| 4467 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4468 | + " would have returned true for r=" + r); |
| 4469 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4473 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4474 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4475 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4476 | final ActivityRecord r = activities.get(activityNdx); |
| 4477 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4478 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4479 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | } |
| 4483 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4484 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4485 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4486 | boolean didSomething = false; |
| 4487 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4488 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4489 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4490 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4491 | int numActivities = activities.size(); |
| 4492 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4493 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4494 | final boolean sameComponent = |
| 4495 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4496 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4497 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4498 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4499 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4500 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4501 | if (!doit) { |
| 4502 | if (r.finishing) { |
| 4503 | // If this activity is just finishing, then it is not |
| 4504 | // interesting as far as something to stop. |
| 4505 | continue; |
| 4506 | } |
| 4507 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4508 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4509 | if (r.isHomeActivity()) { |
| 4510 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4511 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4512 | continue; |
| 4513 | } else { |
| 4514 | homeActivity = r.realActivity; |
| 4515 | } |
| 4516 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4517 | didSomething = true; |
| 4518 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4519 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4520 | if (r.app != null) { |
| 4521 | r.app.removed = true; |
| 4522 | } |
| 4523 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4524 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4525 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4526 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4527 | true)) { |
| 4528 | // r has been deleted from mActivities, accommodate. |
| 4529 | --numActivities; |
| 4530 | --activityNdx; |
| 4531 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | } |
| 4535 | return didSomething; |
| 4536 | } |
| 4537 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4538 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4539 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4540 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4541 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4542 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4543 | if (task.getTopActivity() == null) { |
| 4544 | continue; |
| 4545 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4546 | ActivityRecord r = null; |
| 4547 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4548 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4549 | int numActivities = 0; |
| 4550 | int numRunning = 0; |
| 4551 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4552 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4553 | continue; |
| 4554 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4555 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4556 | tmp = activities.get(activityNdx); |
| 4557 | if (tmp.finishing) { |
| 4558 | continue; |
| 4559 | } |
| 4560 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4561 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4562 | // Initialize state for next task if needed. |
| 4563 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4564 | top = r; |
| 4565 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4566 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4567 | |
| 4568 | // Add 'r' into the current task. |
| 4569 | numActivities++; |
| 4570 | if (r.app != null && r.app.thread != null) { |
| 4571 | numRunning++; |
| 4572 | } |
| 4573 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4574 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4575 | TAG, r.intent.getComponent().flattenToShortString() |
| 4576 | + ": task=" + r.task); |
| 4577 | } |
| 4578 | |
| 4579 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4580 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4581 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4582 | ci.baseActivity = r.intent.getComponent(); |
| 4583 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4584 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4585 | if (focusedStack && topTask) { |
| 4586 | // Give the latest time to ensure foreground task can be sorted |
| 4587 | // at the first, because lastActiveTime of creating task is 0. |
| 4588 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4589 | topTask = false; |
| 4590 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4591 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4592 | if (top.task != null) { |
| 4593 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4594 | } |
| 4595 | ci.numActivities = numActivities; |
| 4596 | ci.numRunning = numRunning; |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 4597 | ci.isDockable = task.canGoInDockedStack(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4598 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4599 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4603 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4604 | 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] | 4605 | if (top >= 0) { |
| 4606 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4607 | int activityTop = activities.size() - 1; |
| 4608 | if (activityTop > 0) { |
| 4609 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4610 | "unhandled-back", true); |
| 4611 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4612 | } |
| 4613 | } |
| 4614 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4615 | /** |
| 4616 | * Reset local parameters because an app's activity died. |
| 4617 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4618 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4619 | */ |
| 4620 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4621 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4622 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4623 | "App died while pausing: " + mPausingActivity); |
| 4624 | mPausingActivity = null; |
| 4625 | } |
| 4626 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4627 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4628 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4631 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4632 | } |
| 4633 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4634 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4635 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4636 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4637 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4638 | final ActivityRecord r = activities.get(activityNdx); |
| 4639 | if (r.app == app) { |
| 4640 | Slog.w(TAG, " Force finishing activity " |
| 4641 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 4642 | // Force the destroy to skip right to removal. |
| 4643 | r.app = null; |
| 4644 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4645 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4646 | } |
| 4647 | } |
| 4648 | } |
| 4649 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4650 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4651 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4652 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4653 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4654 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4655 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 4656 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4657 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 4658 | " Task id #" + task.taskId + "\n" + |
| 4659 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 4660 | " mBounds=" + task.mBounds + "\n" + |
| 4661 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4662 | if (printed) { |
| 4663 | header = null; |
| 4664 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4665 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4666 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 4670 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 4671 | |
| 4672 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4673 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4674 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4675 | } |
| 4676 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4677 | final int top = mTaskHistory.size() - 1; |
| 4678 | if (top >= 0) { |
| 4679 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 4680 | int listTop = list.size() - 1; |
| 4681 | if (listTop >= 0) { |
| 4682 | activities.add(list.get(listTop)); |
| 4683 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4684 | } |
| 4685 | } else { |
| 4686 | ItemMatcher matcher = new ItemMatcher(); |
| 4687 | matcher.build(name); |
| 4688 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4689 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4690 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 4691 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 4692 | activities.add(r1); |
| 4693 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4694 | } |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | return activities; |
| 4699 | } |
| 4700 | |
| 4701 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4702 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4703 | |
| 4704 | // All activities that came from the package must be |
| 4705 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4706 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4707 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4708 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4709 | final ActivityRecord a = activities.get(activityNdx); |
| 4710 | if (a.info.packageName.equals(packageName)) { |
| 4711 | a.forceNewConfig = true; |
| 4712 | if (starting != null && a == starting && a.visible) { |
| 4713 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4714 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4715 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | } |
| 4719 | |
| 4720 | return starting; |
| 4721 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4722 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4723 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4724 | removeTask(task, reason, !MOVING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4725 | } |
| 4726 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4727 | /** |
| 4728 | * Removes the input task from this stack. |
| 4729 | * @param task to remove. |
| 4730 | * @param reason for removal. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4731 | * @param moving task to another stack. In the case we are moving we don't want to perform |
| 4732 | * 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] | 4733 | */ |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4734 | void removeTask(TaskRecord task, String reason, boolean moving) { |
| 4735 | if (!moving) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4736 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4737 | mWindowManager.removeTask(task.taskId); |
Wale Ogunwale | b317b22 | 2015-11-09 11:14:10 -0800 | [diff] [blame] | 4738 | if (!StackId.persistTaskBounds(mStackId)) { |
| 4739 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 4740 | // default configuration the next time it launches. |
| 4741 | task.updateOverrideConfiguration(null); |
| 4742 | } |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4743 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4744 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4745 | final ActivityRecord r = mResumedActivity; |
| 4746 | if (r != null && r.task == task) { |
| 4747 | mResumedActivity = null; |
| 4748 | } |
| 4749 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4750 | final int taskNdx = mTaskHistory.indexOf(task); |
| 4751 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4752 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 4753 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 4754 | if (!nextTask.isOverHomeStack()) { |
| 4755 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 4756 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4757 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4758 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4759 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4760 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4761 | if (!moving && task.mActivities.isEmpty()) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 4762 | // TODO: VI what about activity? |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4763 | final boolean isVoiceSession = task.voiceSession != null; |
| 4764 | if (isVoiceSession) { |
| 4765 | try { |
| 4766 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 4767 | } catch (RemoteException e) { |
| 4768 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4769 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4770 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 4771 | // Task creator asked to remove this when done, or this task was a voice |
| 4772 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 4773 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 4774 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4775 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4776 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4777 | |
| 4778 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4779 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Chong Zhang | a8be5e5 | 2015-10-05 17:06:28 -0700 | [diff] [blame] | 4780 | // 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] | 4781 | if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4782 | String myReason = reason + " leftTaskHistoryEmpty"; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 4783 | if (mFullscreen || !adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4784 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4785 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4786 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 4787 | if (mStacks != null) { |
| 4788 | mStacks.remove(this); |
| 4789 | mStacks.add(0, this); |
| 4790 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4791 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 4792 | mActivityContainer.onTaskListEmptyLocked(); |
| 4793 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4794 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 4795 | |
| 4796 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4797 | } |
| 4798 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4799 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 4800 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 4801 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4802 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 4803 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4804 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4805 | addTask(task, toTop, "createTaskRecord"); |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 4806 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 4807 | if (!layoutTaskInStack(task, info.layout) && mBounds != null && task.isResizeable() |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 4808 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 4809 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4810 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4811 | return task; |
| 4812 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4813 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 4814 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.Layout layout) { |
| 4815 | if (mTaskPositioner == null) { |
| 4816 | return false; |
| 4817 | } |
| 4818 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, layout); |
| 4819 | return true; |
| 4820 | } |
| 4821 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4822 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4823 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4824 | } |
| 4825 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4826 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
| 4827 | final ActivityStack prevStack = preAddTask(task, reason); |
| 4828 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4829 | task.stack = this; |
| 4830 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4831 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4832 | } else { |
| 4833 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4834 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4835 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4836 | postAddTask(task, prevStack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4837 | } |
| 4838 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4839 | void positionTask(final TaskRecord task, int position) { |
| 4840 | final ActivityStack prevStack = preAddTask(task, "positionTask"); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4841 | task.stack = this; |
| 4842 | insertTaskAtPosition(task, position); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4843 | postAddTask(task, prevStack); |
| 4844 | } |
| 4845 | |
| 4846 | private ActivityStack preAddTask(TaskRecord task, String reason) { |
| 4847 | final ActivityStack prevStack = task.stack; |
| 4848 | if (prevStack != null && prevStack != this) { |
| 4849 | prevStack.removeTask(task, reason, MOVING); |
| 4850 | } |
| 4851 | return prevStack; |
| 4852 | } |
| 4853 | |
| 4854 | private void postAddTask(TaskRecord task, ActivityStack prevStack) { |
| 4855 | if (prevStack != null) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4856 | mStackSupervisor.scheduleReportPictureInPictureChangedIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4857 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4858 | try { |
| 4859 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4860 | } catch (RemoteException e) { |
| 4861 | } |
| 4862 | } |
| 4863 | } |
| 4864 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4865 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 4866 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 4867 | // TODO: VI deal with activity |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 4868 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 4869 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4870 | (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges, |
| 4871 | task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig, |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 4872 | task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4873 | r.taskConfigOverride = task.mOverrideConfig; |
| 4874 | } |
| 4875 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4876 | void moveToFrontAndResumeStateIfNeeded( |
| 4877 | ActivityRecord r, boolean moveToFront, boolean setResume, String reason) { |
| 4878 | if (!moveToFront) { |
| 4879 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4880 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4881 | |
| 4882 | // If the activity owns the last resumed activity, transfer that together, |
| 4883 | // so that we don't resume the same activity again in the new stack. |
| 4884 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 4885 | if (setResume) { |
| 4886 | mResumedActivity = r; |
| 4887 | } |
| 4888 | // Move the stack in which we are placing the activity to the front. The call will also |
| 4889 | // make sure the activity focus is set. |
| 4890 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | /** |
| 4894 | * Moves the input activity from its current stack to this one. |
| 4895 | * NOTE: The current task of the activity isn't moved to this stack. Instead a new task is |
| 4896 | * created on this stack which the activity is added to. |
| 4897 | * */ |
| 4898 | void moveActivityToStack(ActivityRecord r) { |
| 4899 | final ActivityStack prevStack = r.task.stack; |
| 4900 | if (prevStack.mStackId == mStackId) { |
| 4901 | // You are already in the right stack silly... |
| 4902 | return; |
| 4903 | } |
| 4904 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 4905 | final boolean wasFocused = mStackSupervisor.isFocusedStack(prevStack) |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4906 | && (mStackSupervisor.topRunningActivityLocked() == r); |
| 4907 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 4908 | |
| 4909 | final TaskRecord task = createTaskRecord( |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 4910 | mStackSupervisor.getNextTaskIdForUserLocked(r.userId), |
| 4911 | r.info, r.intent, null, null, true); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4912 | r.setTask(task, null); |
| 4913 | task.addActivityToTop(r); |
| 4914 | setAppTask(r, task); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4915 | mStackSupervisor.scheduleReportPictureInPictureChangedIfNeeded(task, prevStack); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4916 | moveToFrontAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack"); |
| 4917 | if (wasResumed) { |
| 4918 | prevStack.mResumedActivity = null; |
| 4919 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4920 | } |
| 4921 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4922 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 4923 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 4924 | mWindowManager.setAppTask(r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig, |
| 4925 | task.mResizeMode, task.isHomeTask()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4926 | r.taskConfigOverride = task.mOverrideConfig; |
| 4927 | } |
| 4928 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4929 | public int getStackId() { |
| 4930 | return mStackId; |
| 4931 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4932 | |
| 4933 | @Override |
| 4934 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 4935 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 4936 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4937 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4938 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4939 | void onLockTaskPackagesUpdatedLocked() { |
| 4940 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4941 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 4942 | } |
| 4943 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4944 | } |