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 | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 37 | import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 38 | import static com.android.server.am.ActivityStackSupervisor.MOVING; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 39 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 40 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 41 | import android.graphics.Point; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 42 | import android.graphics.Rect; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 43 | import android.util.ArraySet; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 44 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 45 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 46 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 47 | import com.android.internal.os.BatteryStatsImpl; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 48 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 49 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 50 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 51 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 52 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 53 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 54 | |
| 55 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 56 | import android.app.ActivityManager; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 57 | import android.app.ActivityManager.StackId; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 58 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 59 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 60 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 61 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 62 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 63 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 64 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 65 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 66 | import android.content.pm.PackageManager; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 67 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 68 | import android.graphics.Bitmap; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 69 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 70 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 71 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 75 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 76 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 77 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 78 | import android.os.RemoteException; |
| 79 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 80 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 81 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 82 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 83 | import android.util.EventLog; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 84 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 85 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 86 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 87 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 88 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 89 | import java.lang.ref.WeakReference; |
| 90 | import java.util.ArrayList; |
| 91 | import java.util.Iterator; |
| 92 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 93 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 94 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * State and management of a single stack of activities. |
| 98 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 99 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 100 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 101 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 102 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 103 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 104 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 105 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 106 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 107 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 108 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 109 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 110 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 111 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 112 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 113 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 114 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 115 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 116 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 117 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 118 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 119 | |
| 120 | private static final boolean VALIDATE_TOKENS = false; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 121 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 122 | // Ticks during which we check progress while waiting for an app to launch. |
| 123 | static final int LAUNCH_TICK = 500; |
| 124 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 125 | // How long we wait until giving up on the last activity to pause. This |
| 126 | // is short because it directly impacts the responsiveness of starting the |
| 127 | // next activity. |
| 128 | static final int PAUSE_TIMEOUT = 500; |
| 129 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 130 | // How long we wait for the activity to tell us it has stopped before |
| 131 | // giving up. This is a good amount of time because we really need this |
| 132 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 133 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 134 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 135 | // How long we wait until giving up on an activity telling us it has |
| 136 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 137 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 138 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 139 | // 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] | 140 | // disabled. |
| 141 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 142 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 143 | // How long between activity launches that we consider safe to not warn |
| 144 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 145 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 146 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 147 | // Set to false to disable the preview that is shown while a new activity |
| 148 | // is being started. |
| 149 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 150 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 151 | // How long to wait for all background Activities to redraw following a call to |
| 152 | // convertToTranslucent(). |
| 153 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 154 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 155 | // How many activities have to be scheduled to stop to force a stop pass. |
| 156 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 157 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 158 | enum ActivityState { |
| 159 | INITIALIZING, |
| 160 | RESUMED, |
| 161 | PAUSING, |
| 162 | PAUSED, |
| 163 | STOPPING, |
| 164 | STOPPED, |
| 165 | FINISHING, |
| 166 | DESTROYING, |
| 167 | DESTROYED |
| 168 | } |
| 169 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 170 | // Stack is not considered visible. |
| 171 | static final int STACK_INVISIBLE = 0; |
| 172 | // Stack is considered visible |
| 173 | static final int STACK_VISIBLE = 1; |
| 174 | // Stack is considered visible, but only becuase it has activity that is visible behind other |
| 175 | // activities and there is a specific combination of stacks. |
| 176 | static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2; |
| 177 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 178 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 179 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 180 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 181 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 182 | /** |
| 183 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 184 | * running) activities. It contains #TaskRecord objects. |
| 185 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 186 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 187 | |
| 188 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 189 | * Used for validating app tokens with window manager. |
| 190 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 191 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 192 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 193 | /** |
| 194 | * List of running activities, sorted by recent usage. |
| 195 | * The first entry in the list is the least recently used. |
| 196 | * It contains HistoryRecord objects. |
| 197 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 198 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 199 | |
| 200 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 201 | * Animations that for the current transition have requested not to |
| 202 | * be considered for the transition animation. |
| 203 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 204 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 205 | |
| 206 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 207 | * When we are in the process of pausing an activity, before starting the |
| 208 | * next one, this variable holds the activity that is currently being paused. |
| 209 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 210 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * This is the last activity that we put into the paused state. This is |
| 214 | * used to determine if we need to do an activity transition while sleeping, |
| 215 | * when we normally hold the top activity paused. |
| 216 | */ |
| 217 | ActivityRecord mLastPausedActivity = null; |
| 218 | |
| 219 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 220 | * Activities that specify No History must be removed once the user navigates away from them. |
| 221 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 222 | * and finish it later if another activity replaces it on wakeup. |
| 223 | */ |
| 224 | ActivityRecord mLastNoHistoryActivity = null; |
| 225 | |
| 226 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 227 | * Current activity that is resumed, or null if there is none. |
| 228 | */ |
| 229 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 230 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 231 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 232 | * This is the last activity that has been started. It is only used to |
| 233 | * identify when multiple activities are started at once so that the user |
| 234 | * can be warned they may not be in the activity they think they are. |
| 235 | */ |
| 236 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 237 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 238 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 239 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 240 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 241 | // Activity in mTranslucentActivityWaiting is notified via |
| 242 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 243 | // background activity being drawn then the same call will be made with a true value. |
| 244 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 245 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 246 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 247 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 248 | * Set when we know we are going to be calling updateConfiguration() |
| 249 | * soon, so want to skip intermediate config checks. |
| 250 | */ |
| 251 | boolean mConfigWillChange; |
| 252 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 253 | // 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] | 254 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 255 | // Current bounds of the stack or null if fullscreen. |
| 256 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 257 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 258 | long mLaunchStartTime = 0; |
| 259 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 260 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 261 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 262 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 263 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 264 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 265 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 266 | ArrayList<ActivityStack> mStacks; |
| 267 | /** The attached Display's unique identifier, or -1 if detached */ |
| 268 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 269 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 270 | /** Run all ActivityStacks through this */ |
| 271 | final ActivityStackSupervisor mStackSupervisor; |
| 272 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 273 | private final LaunchingTaskPositioner mTaskPositioner; |
| 274 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 275 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 276 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 277 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 278 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 279 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 280 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 281 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 282 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 283 | |
| 284 | static class ScheduleDestroyArgs { |
| 285 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 286 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 287 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 288 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 289 | mReason = reason; |
| 290 | } |
| 291 | } |
| 292 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 293 | final Handler mHandler; |
| 294 | |
| 295 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 296 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 297 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 298 | super(looper); |
| 299 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 300 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 301 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 302 | public void handleMessage(Message msg) { |
| 303 | switch (msg.what) { |
| 304 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 305 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 306 | // We don't at this point know if the activity is fullscreen, |
| 307 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 308 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 309 | synchronized (mService) { |
| 310 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 311 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 312 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 313 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 314 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 315 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 316 | case LAUNCH_TICK_MSG: { |
| 317 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 318 | synchronized (mService) { |
| 319 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 320 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 324 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 325 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 326 | // We don't at this point know if the activity is fullscreen, |
| 327 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 328 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 329 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 330 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 331 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 332 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 333 | case STOP_TIMEOUT_MSG: { |
| 334 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 335 | // We don't at this point know if the activity is fullscreen, |
| 336 | // so we need to be conservative and assume it isn't. |
| 337 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 338 | synchronized (mService) { |
| 339 | if (r.isInHistory()) { |
| 340 | activityStoppedLocked(r, null, null, null); |
| 341 | } |
| 342 | } |
| 343 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 344 | case DESTROY_ACTIVITIES_MSG: { |
| 345 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 346 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 347 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 348 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 349 | } break; |
| 350 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 351 | synchronized (mService) { |
| 352 | notifyActivityDrawnLocked(null); |
| 353 | } |
| 354 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 355 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 356 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 357 | final ActivityRecord r = getVisibleBehindActivity(); |
| 358 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 359 | if (r != null) { |
| 360 | mService.killAppAtUsersRequest(r.app, null); |
| 361 | } |
| 362 | } |
| 363 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 364 | } |
| 365 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 368 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 369 | int count = 0; |
| 370 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 371 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 372 | } |
| 373 | return count; |
| 374 | } |
| 375 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 376 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 377 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 378 | mActivityContainer = activityContainer; |
| 379 | mStackSupervisor = activityContainer.getOuter(); |
| 380 | mService = mStackSupervisor.mService; |
| 381 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 382 | mWindowManager = mService.mWindowManager; |
| 383 | mStackId = activityContainer.mStackId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 384 | mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 385 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 386 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 387 | ? new LaunchingTaskPositioner() : null; |
| 388 | } |
| 389 | |
| 390 | void attachDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 391 | mDisplayId = activityDisplay.mDisplayId; |
| 392 | mStacks = activityDisplay.mStacks; |
| 393 | mBounds = mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId, onTop); |
| 394 | mFullscreen = mBounds == null; |
| 395 | if (mTaskPositioner != null) { |
| 396 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 397 | mTaskPositioner.configure(mBounds); |
| 398 | } |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 399 | |
| 400 | if (mStackId == DOCKED_STACK_ID) { |
| 401 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 402 | // in the system. |
| 403 | mStackSupervisor.resizeDockedStackLocked( |
| 404 | mBounds, null, null, null, null, PRESERVE_WINDOWS); |
| 405 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | void detachDisplay() { |
| 409 | mDisplayId = Display.INVALID_DISPLAY; |
| 410 | mStacks = null; |
| 411 | if (mTaskPositioner != null) { |
| 412 | mTaskPositioner.reset(); |
| 413 | } |
| 414 | mWindowManager.detachStack(mStackId); |
| 415 | } |
| 416 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 417 | public void getDisplaySize(Point out) { |
| 418 | mActivityContainer.mActivityDisplay.mDisplay.getSize(out); |
| 419 | } |
| 420 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 421 | void setBounds(Rect bounds) { |
| 422 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 423 | if (mTaskPositioner != null) { |
| 424 | mTaskPositioner.configure(bounds); |
| 425 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 426 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 427 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 428 | boolean okToShowLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 429 | return mStackSupervisor.okToShowLocked(r); |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 432 | final ActivityRecord topRunningActivityLocked() { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 433 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 434 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 435 | if (r != null) { |
| 436 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 437 | } |
| 438 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 439 | return null; |
| 440 | } |
| 441 | |
| 442 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 443 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 444 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 445 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 446 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 447 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 448 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 449 | return r; |
| 450 | } |
| 451 | } |
| 452 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 453 | return null; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 458 | * 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] | 459 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 460 | * @param token If non-null, any history records matching this token will be skipped. |
| 461 | * @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] | 462 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 463 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 464 | */ |
| 465 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 466 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 467 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 468 | if (task.taskId == taskId) { |
| 469 | continue; |
| 470 | } |
| 471 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 472 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 473 | final ActivityRecord r = activities.get(i); |
| 474 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 475 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 476 | return r; |
| 477 | } |
| 478 | } |
| 479 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 480 | return null; |
| 481 | } |
| 482 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 483 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 484 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 485 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 486 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 487 | final ActivityRecord r = activities.get(activityNdx); |
| 488 | if (!r.finishing) { |
| 489 | return r; |
| 490 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 493 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 496 | final TaskRecord topTask() { |
| 497 | final int size = mTaskHistory.size(); |
| 498 | if (size > 0) { |
| 499 | return mTaskHistory.get(size - 1); |
| 500 | } |
| 501 | return null; |
| 502 | } |
| 503 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 504 | TaskRecord taskForIdLocked(int id) { |
| 505 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 506 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 507 | if (task.taskId == id) { |
| 508 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 509 | } |
| 510 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 511 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 514 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 515 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 516 | return isInStackLocked(r); |
| 517 | } |
| 518 | |
| 519 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 520 | if (r == null) { |
| 521 | return null; |
| 522 | } |
| 523 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 524 | if (task != null && task.stack != null |
| 525 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 526 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 527 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 528 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 529 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 530 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 533 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 534 | final boolean hadit = mLRUActivities.remove(r); |
| 535 | mLRUActivities.add(r); |
| 536 | return hadit; |
| 537 | } |
| 538 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 539 | final boolean isHomeStack() { |
| 540 | return mStackId == HOME_STACK_ID; |
| 541 | } |
| 542 | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 543 | final boolean isDockedStack() { |
| 544 | return mStackId == DOCKED_STACK_ID; |
| 545 | } |
| 546 | |
| 547 | final boolean isPinnedStack() { |
| 548 | return mStackId == PINNED_STACK_ID; |
| 549 | } |
| 550 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 551 | final boolean isOnHomeDisplay() { |
| 552 | return isAttached() && |
| 553 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 554 | } |
| 555 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 556 | void moveToFront(String reason) { |
| 557 | moveToFront(reason, null); |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * @param reason The reason for moving the stack to the front. |
| 562 | * @param task If non-null, the task will be moved to the top of the stack. |
| 563 | * */ |
| 564 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 565 | if (!isAttached()) { |
| 566 | return; |
| 567 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 568 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 569 | mStacks.remove(this); |
| 570 | int addIndex = mStacks.size(); |
| 571 | |
| 572 | if (addIndex > 0) { |
| 573 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 574 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 575 | // 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] | 576 | addIndex--; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 577 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | mStacks.add(addIndex, this); |
| 581 | |
| 582 | // TODO(multi-display): Needs to also work if focus is moving to the non-home display. |
| 583 | if (isOnHomeDisplay()) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 584 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 585 | } |
| 586 | if (task != null) { |
| 587 | insertTaskAtTop(task, null); |
| 588 | } else { |
| 589 | task = topTask(); |
| 590 | } |
| 591 | if (task != null) { |
| 592 | mWindowManager.moveTaskToTop(task.taskId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 593 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 594 | } |
| 595 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 596 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 597 | if (StackId.canReceiveKeys(mStackId)) { |
| 598 | return true; |
| 599 | } |
| 600 | // The stack isn't focusable. See if its top activity is focusable to force focus on the |
| 601 | // stack. |
| 602 | final ActivityRecord r = topRunningActivityLocked(); |
| 603 | return r != null && r.isFocusable(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 606 | final boolean isAttached() { |
| 607 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 610 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 611 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 612 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 613 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 614 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 615 | Intent intent = target.intent; |
| 616 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 617 | ComponentName cls = intent.getComponent(); |
| 618 | if (info.targetActivity != null) { |
| 619 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 620 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 621 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 622 | boolean isDocument = intent != null & intent.isDocument(); |
| 623 | // If documentData is non-null then it must match the existing task data. |
| 624 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 625 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 626 | 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] | 627 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 628 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 629 | if (task.voiceSession != null) { |
| 630 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 631 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 632 | continue; |
| 633 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 634 | if (task.userId != userId) { |
| 635 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 636 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 637 | continue; |
| 638 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 639 | final ActivityRecord r = task.getTopActivity(); |
| 640 | if (r == null || r.finishing || r.userId != userId || |
| 641 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 642 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 643 | continue; |
| 644 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 645 | if (r.mActivityType != target.mActivityType) { |
| 646 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 647 | continue; |
| 648 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 649 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 650 | final Intent taskIntent = task.intent; |
| 651 | final Intent affinityIntent = task.affinityIntent; |
| 652 | final boolean taskIsDocument; |
| 653 | final Uri taskDocumentData; |
| 654 | if (taskIntent != null && taskIntent.isDocument()) { |
| 655 | taskIsDocument = true; |
| 656 | taskDocumentData = taskIntent.getData(); |
| 657 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 658 | taskIsDocument = true; |
| 659 | taskDocumentData = affinityIntent.getData(); |
| 660 | } else { |
| 661 | taskIsDocument = false; |
| 662 | taskDocumentData = null; |
| 663 | } |
| 664 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 665 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 666 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 667 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 668 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 669 | if (!isDocument && !taskIsDocument |
| 670 | && result.r == null && task.canMatchRootAffinity()) { |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 671 | if (task.rootAffinity.equals(target.taskAffinity)) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 672 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 673 | // It is possible for multiple tasks to have the same root affinity especially |
| 674 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 675 | // to see if there is a better candidate. |
| 676 | result.r = r; |
| 677 | result.matchedByRootAffinity = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 678 | } |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 679 | } else if (taskIntent != null && taskIntent.getComponent() != null && |
| 680 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 681 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 682 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 683 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 684 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 685 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 686 | result.r = r; |
| 687 | result.matchedByRootAffinity = false; |
| 688 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 689 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 690 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 691 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 692 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 693 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 694 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 695 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 696 | result.r = r; |
| 697 | result.matchedByRootAffinity = false; |
| 698 | break; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 699 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 700 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Returns the first activity (starting from the top of the stack) that |
| 705 | * is the same as the given activity. Returns null if no such activity |
| 706 | * is found. |
| 707 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 708 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 709 | ComponentName cls = intent.getComponent(); |
| 710 | if (info.targetActivity != null) { |
| 711 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 712 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 713 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 714 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 715 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 716 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 717 | final boolean notCurrentUserTask = |
| 718 | !mStackSupervisor.isCurrentProfileLocked(task.userId); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 719 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 720 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 721 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 722 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 723 | if (notCurrentUserTask && (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 724 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 725 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 726 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 727 | return r; |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | return null; |
| 733 | } |
| 734 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 735 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 736 | * 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] | 737 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 738 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 739 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 740 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 741 | } |
| 742 | mCurrentUser = userId; |
| 743 | |
| 744 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 745 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 746 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 747 | final TaskRecord task = mTaskHistory.get(i); |
| 748 | |
| 749 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 750 | // okay to show the activity when locked. |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 751 | if (mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 752 | || task.topRunningActivityLocked() != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 753 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 754 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 755 | mTaskHistory.remove(i); |
| 756 | mTaskHistory.add(task); |
| 757 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 758 | // Use same value for i. |
| 759 | } else { |
| 760 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 761 | } |
| 762 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 763 | if (VALIDATE_TOKENS) { |
| 764 | validateAppTokensLocked(); |
| 765 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 768 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 769 | r.state = ActivityState.RESUMED; |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 770 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 771 | + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 772 | mResumedActivity = r; |
| 773 | r.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 774 | mRecentTasks.addLocked(r.task); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 775 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 776 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 777 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 778 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 779 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 782 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 783 | if (r != null) { |
| 784 | mRecentTasks.addLocked(r.task); |
| 785 | r.task.touchActiveTime(); |
| 786 | } |
| 787 | } |
| 788 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 789 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 790 | if (mFullyDrawnStartTime != 0) { |
| 791 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 792 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 793 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 794 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 795 | } |
| 796 | |
| 797 | private void stopFullyDrawnTraceIfNeeded() { |
| 798 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 799 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 800 | mFullyDrawnStartTime = 0; |
| 801 | } |
| 802 | } |
| 803 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 804 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 805 | if (r.displayStartTime == 0) { |
| 806 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 807 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 808 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 809 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 810 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 811 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 812 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 813 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 814 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 815 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 816 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 817 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 818 | // Make sure that there is no activity waiting for this to launch. |
| 819 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 820 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 821 | } else { |
| 822 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 823 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 824 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 827 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 828 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 829 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 830 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 831 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 832 | activities.get(activityNdx).setSleeping(false); |
| 833 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 834 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 835 | if (mPausingActivity != null) { |
| 836 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 837 | activityPausedLocked(mPausingActivity.appToken, true); |
| 838 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 841 | /** |
| 842 | * @return true if something must be done before going to sleep. |
| 843 | */ |
| 844 | boolean checkReadyForSleepLocked() { |
| 845 | if (mResumedActivity != null) { |
| 846 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 847 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 848 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 849 | "Sleep => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 850 | startPausingLocked(false, true, false, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 851 | return true; |
| 852 | } |
| 853 | if (mPausingActivity != null) { |
| 854 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 855 | 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] | 856 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 859 | if (hasVisibleBehindActivity()) { |
| 860 | // Stop visible behind activity before going to sleep. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 861 | final ActivityRecord r = getVisibleBehindActivity(); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 862 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 863 | 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] | 864 | return true; |
| 865 | } |
| 866 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 867 | return false; |
| 868 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 869 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 870 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 871 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 872 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 873 | // Make sure any stopped but visible activities are now sleeping. |
| 874 | // This ensures that the activity's onStop() is called. |
| 875 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 876 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 877 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 878 | final ActivityRecord r = activities.get(activityNdx); |
| 879 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 880 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 881 | } |
| 882 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 883 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 884 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 885 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 886 | public final Bitmap screenshotActivitiesLocked(ActivityRecord who) { |
| 887 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 888 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 889 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 890 | return null; |
| 891 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 892 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 893 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 894 | // 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] | 895 | // 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] | 896 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 897 | return null; |
| 898 | } |
| 899 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 900 | int w = mService.mThumbnailWidth; |
| 901 | int h = mService.mThumbnailHeight; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 902 | float scale = 1f; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 903 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 904 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 905 | |
| 906 | // 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] | 907 | // but scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to |
| 908 | // use within SystemUI while keeping memory usage low. |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 909 | if (ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 910 | w = h = -1; |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 911 | scale = 0.5f; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 912 | } |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 913 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 914 | w, h, scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 915 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 916 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 917 | return null; |
| 918 | } |
| 919 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 920 | /** |
| 921 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 922 | * is already an activity being paused or there is no resumed activity. |
| 923 | * |
| 924 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 925 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 926 | * screen turning off). |
| 927 | * @param resuming True if this is being called as part of resuming the top activity, so |
| 928 | * we shouldn't try to instigate a resume here. |
| 929 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 930 | * set to true, we will immediately complete the pause here before returning. |
| 931 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 932 | * it to tell us when it is done. |
| 933 | */ |
| 934 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming, |
| 935 | boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 936 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 937 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 938 | + " state=" + mPausingActivity.state); |
| 939 | if (!mService.isSleeping()) { |
| 940 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 941 | // Because activity will be paused immediately after resume, just let pause |
| 942 | // be completed by the order of activity paused from clients. |
| 943 | completePauseLocked(false); |
| 944 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 945 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 946 | ActivityRecord prev = mResumedActivity; |
| 947 | if (prev == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 948 | if (!resuming) { |
| 949 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 950 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 951 | } |
| 952 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 953 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 954 | |
| 955 | if (mActivityContainer.mParentActivity == null) { |
| 956 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 957 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 958 | } |
| 959 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 960 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 961 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 962 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 963 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 964 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 965 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 966 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 967 | prev.state = ActivityState.PAUSING; |
| 968 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 969 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 970 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | 979f5ed | 2015-10-12 11:22:50 -0700 | [diff] [blame] | 971 | if (mService.mHasRecents |
| 972 | && (next == null || next.noDisplay || next.task != prev.task || uiSleeping)) { |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 973 | prev.mUpdateTaskThumbnailWhenHidden = true; |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 974 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 975 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 976 | |
| 977 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 978 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 979 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 980 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 981 | try { |
| 982 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 983 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 984 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 985 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 986 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 987 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 988 | } catch (Exception e) { |
| 989 | // Ignore exception, if process died other code will cleanup. |
| 990 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 991 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 992 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 993 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 994 | } |
| 995 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 996 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 997 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 998 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | // If we are not going to sleep, we want to ensure the device is |
| 1002 | // awake until the next activity is started. |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1003 | if (!uiSleeping && !mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1004 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1007 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1008 | // Have the window manager pause its key dispatching until the new |
| 1009 | // activity has started. If we're pausing the activity just because |
| 1010 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1011 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1012 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1013 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1014 | } else if (DEBUG_PAUSE) { |
| 1015 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1018 | if (dontWait) { |
| 1019 | // If the caller said they don't want to wait for the pause, then complete |
| 1020 | // the pause now. |
| 1021 | completePauseLocked(false); |
| 1022 | return false; |
| 1023 | |
| 1024 | } else { |
| 1025 | // Schedule a pause timeout in case the app doesn't respond. |
| 1026 | // We don't give it much time because this directly impacts the |
| 1027 | // responsiveness seen by the user. |
| 1028 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1029 | msg.obj = prev; |
| 1030 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 1031 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1032 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1033 | return true; |
| 1034 | } |
| 1035 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1036 | } else { |
| 1037 | // This activity failed to schedule the |
| 1038 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1039 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1040 | if (!resuming) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1041 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1042 | } |
| 1043 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1044 | } |
| 1045 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1046 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1047 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1048 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1049 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1050 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1051 | final ActivityRecord r = isInStackLocked(token); |
| 1052 | if (r != null) { |
| 1053 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1054 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1055 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1056 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1057 | completePauseLocked(true); |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1058 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1059 | } else { |
| 1060 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1061 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1062 | mPausingActivity != null |
| 1063 | ? mPausingActivity.shortComponentName : "(none)"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1064 | if (r.state == ActivityState.PAUSING) { |
| 1065 | r.state = ActivityState.PAUSED; |
| 1066 | if (r.finishing) { |
| 1067 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1068 | "Executing finish of failed to pause activity: " + r); |
| 1069 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1070 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1071 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1074 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1077 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 1078 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 1079 | if (r.state != ActivityState.STOPPING) { |
| 1080 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 1081 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1082 | return; |
| 1083 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1084 | if (persistentState != null) { |
| 1085 | r.persistentState = persistentState; |
| 1086 | mService.notifyTaskPersisterLocked(r.task, false); |
| 1087 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1088 | 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] | 1089 | if (icicle != null) { |
| 1090 | // If icicle is null, this is happening due to a timeout, so we |
| 1091 | // haven't really saved the state. |
| 1092 | r.icicle = icicle; |
| 1093 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 1094 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1095 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1096 | } |
| 1097 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1098 | 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] | 1099 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1100 | r.stopped = true; |
| 1101 | r.state = ActivityState.STOPPED; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 1102 | |
| 1103 | mWindowManager.notifyAppStopped(r.appToken); |
| 1104 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1105 | if (getVisibleBehindActivity() == r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1106 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1107 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1108 | if (r.finishing) { |
| 1109 | r.clearOptionsLocked(); |
| 1110 | } else { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1111 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1112 | destroyActivityLocked(r, true, "stop-config"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1113 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1114 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1115 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1116 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1121 | private void completePauseLocked(boolean resumeNext) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1122 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1123 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1124 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1125 | if (prev != null) { |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1126 | final boolean wasStopping = prev.state == ActivityState.STOPPING; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1127 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1128 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1129 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1130 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1131 | } else if (prev.app != null) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1132 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1133 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1134 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1135 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1136 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1137 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1138 | if (prev.deferRelaunchUntilPaused) { |
| 1139 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1140 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
| 1141 | relaunchActivityLocked(prev, prev.configChangeFlags, false, |
| 1142 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1143 | } else if (wasStopping) { |
| 1144 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1145 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1146 | // We don't need to schedule another stop, we only need to let it happen. |
| 1147 | prev.state = ActivityState.STOPPING; |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1148 | } else if ((!prev.visible && !hasVisibleBehindActivity()) |
| 1149 | || mService.isSleepingOrShuttingDown()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1150 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1151 | // stopping. |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1152 | addToStopping(prev, true /* immediate */); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1153 | } |
| 1154 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1155 | 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] | 1156 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1157 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1158 | // It is possible the activity was freezing the screen before it was paused. |
| 1159 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1160 | // since it is no longer visible. |
| 1161 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1162 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1163 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1164 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1165 | if (resumeNext) { |
| 1166 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
| 1167 | if (!mService.isSleepingOrShuttingDown()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1168 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1169 | } else { |
| 1170 | mStackSupervisor.checkReadyForSleepLocked(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1171 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1172 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1173 | // If there are no more activities available to run, do resume anyway to start |
| 1174 | // something. Also if the top activity on the stack is not the just paused |
| 1175 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1176 | // in-flight app switch. |
| 1177 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1178 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1179 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1180 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1181 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1182 | if (prev != null) { |
| 1183 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1184 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1185 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1186 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1187 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1188 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1189 | if (diff > 0) { |
| 1190 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1191 | synchronized (bsi) { |
| 1192 | BatteryStatsImpl.Uid.Proc ps = |
| 1193 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1194 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1195 | if (ps != null) { |
| 1196 | ps.addForegroundTimeLocked(diff); |
| 1197 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1201 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1202 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1203 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1204 | // 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] | 1205 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause) { |
| 1206 | mService.notifyTaskStackChangedLocked(); |
| 1207 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1208 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1209 | |
| 1210 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1213 | private void addToStopping(ActivityRecord r, boolean immediate) { |
| 1214 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1215 | mStackSupervisor.mStoppingActivities.add(r); |
| 1216 | } |
| 1217 | |
| 1218 | // If we already have a few activities waiting to stop, then give up |
| 1219 | // on things going idle and start clearing them out. Or if r is the |
| 1220 | // last of activity of the last task the stack will be empty and must |
| 1221 | // be cleared immediately. |
| 1222 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1223 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
| 1224 | |
| 1225 | if (immediate || forceIdle) { |
| 1226 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
| 1227 | + forceIdle + "immediate=" + immediate); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1228 | mStackSupervisor.scheduleIdleLocked(); |
| 1229 | } else { |
| 1230 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1231 | } |
| 1232 | } |
| 1233 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1234 | /** |
| 1235 | * Once we know that we have asked an application to put an activity in |
| 1236 | * the resumed state (either by launching it or explicitly telling it), |
| 1237 | * this function updates the rest of our state to match that fact. |
| 1238 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1239 | private void completeResumeLocked(ActivityRecord next) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1240 | next.visible = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1241 | next.idle = false; |
| 1242 | next.results = null; |
| 1243 | next.newIntents = null; |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1244 | next.stopped = false; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1245 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1246 | if (next.isHomeActivity()) { |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1247 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1248 | if (app != null && app != mService.mHomeProcess) { |
| 1249 | mService.mHomeProcess = app; |
| 1250 | } |
| 1251 | } |
| 1252 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1253 | if (next.nowVisible) { |
| 1254 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1255 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1256 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1257 | |
| 1258 | // 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] | 1259 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1260 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1261 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1262 | |
| 1263 | next.resumeKeyDispatchingLocked(); |
| 1264 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1265 | |
| 1266 | // Mark the point when the activity is resuming |
| 1267 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1268 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1269 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1270 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1271 | } else { |
| 1272 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1273 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1274 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1275 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1276 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1277 | if (getVisibleBehindActivity() == next) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1278 | // When resuming an activity, require it to call requestVisibleBehind() again. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1279 | setVisibleBehindActivity(null); |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1280 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1283 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1284 | r.visible = visible; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1285 | if (!visible && r.mUpdateTaskThumbnailWhenHidden) { |
| 1286 | r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null); |
| 1287 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1288 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1289 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1290 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1291 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1292 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1293 | container.setVisible(visible); |
| 1294 | } |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1295 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1298 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1299 | // otherwise return null; |
| 1300 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1301 | TaskRecord task = r.task; |
| 1302 | if (task == null) { |
| 1303 | return null; |
| 1304 | } |
| 1305 | |
| 1306 | ActivityStack stack = task.stack; |
| 1307 | if (stack == null) { |
| 1308 | return null; |
| 1309 | } |
| 1310 | |
| 1311 | int stackNdx = mStacks.indexOf(stack); |
| 1312 | |
| 1313 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1314 | int taskNdx = tasks.indexOf(task); |
| 1315 | |
| 1316 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1317 | int activityNdx = activities.indexOf(r) + 1; |
| 1318 | |
| 1319 | final int numStacks = mStacks.size(); |
| 1320 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1321 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1322 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1323 | final int numTasks = tasks.size(); |
| 1324 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1325 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1326 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1327 | final int numActivities = activities.size(); |
| 1328 | while (activityNdx < numActivities) { |
| 1329 | final ActivityRecord activity = activities.get(activityNdx); |
| 1330 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1331 | return historyStack.mFullscreen |
| 1332 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1333 | } |
| 1334 | ++activityNdx; |
| 1335 | } |
| 1336 | activityNdx = 0; |
| 1337 | ++taskNdx; |
| 1338 | } |
| 1339 | taskNdx = 0; |
| 1340 | ++stackNdx; |
| 1341 | } |
| 1342 | |
| 1343 | return null; |
| 1344 | } |
| 1345 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1346 | ActivityStack getNextFocusableStackLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1347 | ArrayList<ActivityStack> stacks = mStacks; |
| 1348 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1349 | if (parent != null) { |
| 1350 | stacks = parent.task.stack.mStacks; |
| 1351 | } |
| 1352 | if (stacks != null) { |
| 1353 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1354 | ActivityStack stack = stacks.get(i); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1355 | if (stack != this && stack.isFocusable() |
| 1356 | && stack.getStackVisibilityLocked() != STACK_INVISIBLE) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1357 | return stack; |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | return null; |
| 1362 | } |
| 1363 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1364 | /** Returns true if the stack contains a fullscreen task. */ |
| 1365 | private boolean hasFullscreenTask() { |
| 1366 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1367 | final TaskRecord task = mTaskHistory.get(i); |
| 1368 | if (task.mFullscreen) { |
| 1369 | return true; |
| 1370 | } |
| 1371 | } |
| 1372 | return false; |
| 1373 | } |
| 1374 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1375 | private boolean hasTranslucentActivity(ActivityStack stack) { |
| 1376 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1377 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1378 | final TaskRecord task = tasks.get(taskNdx); |
| 1379 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1380 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1381 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1382 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1383 | // Conditions for an activity to obscure the stack we're |
| 1384 | // examining: |
| 1385 | // 1. Not Finishing AND Visible AND: |
| 1386 | // 2. Either: |
| 1387 | // - Full Screen Activity OR |
| 1388 | // - On top of Home and our stack is NOT home |
| 1389 | if (!r.finishing && r.visible && (r.fullscreen || |
| 1390 | (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()))) { |
| 1391 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1395 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1398 | /** |
| 1399 | * Returns stack's visibility: {@link #STACK_INVISIBLE}, {@link #STACK_VISIBLE} or |
| 1400 | * {@link #STACK_VISIBLE_ACTIVITY_BEHIND}. |
| 1401 | */ |
| 1402 | int getStackVisibilityLocked() { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1403 | if (!isAttached()) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1404 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1407 | if (mStackSupervisor.isFrontStack(this) || mStackSupervisor.isFocusedStack(this)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1408 | return STACK_VISIBLE; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1411 | final int stackIndex = mStacks.indexOf(this); |
| 1412 | |
| 1413 | if (stackIndex == mStacks.size() - 1) { |
| 1414 | Slog.wtf(TAG, |
| 1415 | "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] | 1416 | return STACK_INVISIBLE; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1419 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 1420 | if (isLockscreenShown && !StackId.isAllowedOverLockscreen(mStackId)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1421 | return STACK_INVISIBLE; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1424 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1425 | final int focusedStackId = focusedStack.mStackId; |
| 1426 | |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1427 | if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1428 | && hasVisibleBehindActivity() && focusedStackId == HOME_STACK_ID |
| 1429 | && !focusedStack.topActivity().fullscreen) { |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1430 | // 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] | 1431 | // the home stack that is translucent. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1432 | return STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1435 | if (mStackId == DOCKED_STACK_ID) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1436 | // 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] | 1437 | // task in the focus stack doesn't support any form of resizing but we show it for the |
| 1438 | // home task even though it's not resizable. |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1439 | final ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1440 | final TaskRecord task = r != null ? r.task : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1441 | return task == null || task.canGoInDockedStack() || task.isHomeTask() ? STACK_VISIBLE |
| 1442 | : STACK_INVISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1445 | // Find the first stack below focused stack that actually got something visible. |
| 1446 | int belowFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1447 | while (belowFocusedIndex >= 0 && |
| 1448 | mStacks.get(belowFocusedIndex).topRunningActivityLocked() == null) { |
| 1449 | belowFocusedIndex--; |
| 1450 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1451 | if ((focusedStackId == DOCKED_STACK_ID || focusedStackId == PINNED_STACK_ID) |
| 1452 | && stackIndex == belowFocusedIndex) { |
| 1453 | // Stacks directly behind the docked or pinned stack are always visible. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1454 | return STACK_VISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1457 | if (focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 1458 | && hasTranslucentActivity(focusedStack)) { |
| 1459 | // Stacks behind the fullscreen stack with a translucent activity are always |
| 1460 | // visible so they can act as a backdrop to the translucent activity. |
| 1461 | // For example, dialog activities |
| 1462 | if (stackIndex == belowFocusedIndex) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1463 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1464 | } |
| 1465 | if (belowFocusedIndex >= 0) { |
| 1466 | final ActivityStack stack = mStacks.get(belowFocusedIndex); |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1467 | if ((stack.mStackId == DOCKED_STACK_ID || stack.mStackId == PINNED_STACK_ID) |
| 1468 | && stackIndex == (belowFocusedIndex - 1)) { |
| 1469 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1470 | // complete backdrop to the translucent activity when the docked stack is up. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1471 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1472 | } |
| 1473 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1476 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1477 | // 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] | 1478 | return STACK_INVISIBLE; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1481 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1482 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1483 | |
| 1484 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1485 | continue; |
| 1486 | } |
| 1487 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1488 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1489 | // These stacks can't have any dynamic stacks visible behind them. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1490 | return STACK_INVISIBLE; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1491 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1492 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1493 | if (!hasTranslucentActivity(stack)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1494 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1495 | } |
| 1496 | } |
| 1497 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1498 | return STACK_VISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1501 | final int rankTaskLayers(int baseLayer) { |
| 1502 | int layer = 0; |
| 1503 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1504 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1505 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1506 | if (r == null || r.finishing || !r.visible) { |
| 1507 | task.mLayerRank = -1; |
| 1508 | } else { |
| 1509 | task.mLayerRank = baseLayer + layer++; |
| 1510 | } |
| 1511 | } |
| 1512 | return layer; |
| 1513 | } |
| 1514 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1515 | /** |
| 1516 | * Make sure that all activities that need to be visible (that is, they |
| 1517 | * currently can be seen by the user) actually are. |
| 1518 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1519 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1520 | boolean preserveWindows) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1521 | ActivityRecord top = topRunningActivityLocked(); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1522 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1523 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1524 | if (top != null) { |
| 1525 | checkTranslucentActivityWaiting(top); |
| 1526 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1527 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1528 | // If the top activity is not fullscreen, then we need to |
| 1529 | // make sure any activities under it are now visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1530 | boolean aboveTop = top != null; |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1531 | final int stackVisibility = getStackVisibilityLocked(); |
| 1532 | final boolean stackInvisible = stackVisibility != STACK_VISIBLE; |
| 1533 | final boolean stackVisibleBehind = stackVisibility == STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1534 | boolean behindFullscreenActivity = stackInvisible; |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1535 | boolean resumeNextActivity = isFocusable() && (isInStackLocked(starting) == null); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1536 | boolean behindTranslucentActivity = false; |
| 1537 | final ActivityRecord visibleBehind = getVisibleBehindActivity(); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1538 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1539 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1540 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1541 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1542 | final ActivityRecord r = activities.get(activityNdx); |
| 1543 | if (r.finishing) { |
| 1544 | continue; |
| 1545 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1546 | final boolean isTop = r == top; |
| 1547 | if (aboveTop && !isTop) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1548 | continue; |
| 1549 | } |
| 1550 | aboveTop = false; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1551 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1552 | // 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] | 1553 | final boolean activityVisibleBehind = |
| 1554 | (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == r; |
| 1555 | final boolean isVisible = (!behindFullscreenActivity || r.mLaunchTaskBehind |
| 1556 | || activityVisibleBehind) && okToShowLocked(r); |
| 1557 | if (isVisible) { |
| 1558 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
| 1559 | + " finishing=" + r.finishing + " state=" + r.state); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1560 | // First: if this is not the current activity being started, make |
| 1561 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1562 | if (r != starting) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1563 | ensureActivityConfigurationLocked(r, 0, preserveWindows); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1564 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1565 | |
| 1566 | if (r.app == null || r.app.thread == null) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1567 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1568 | resumeNextActivity, r)) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1569 | if (activityNdx >= activities.size()) { |
| 1570 | // Record may be removed if its process needs to restart. |
| 1571 | activityNdx = activities.size() - 1; |
| 1572 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1573 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1574 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1575 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1576 | } else if (r.visible) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1577 | // If this activity is already visible, then there is nothing to do here. |
| 1578 | if (handleAlreadyVisible(r)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1579 | resumeNextActivity = false; |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1580 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1581 | } else { |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1582 | makeVisibleIfNeeded(starting, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1583 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1584 | // Aggregate current change flags. |
| 1585 | configChanges |= r.configChangeFlags; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1586 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1587 | behindFullscreenActivity, task, r); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1588 | if (behindFullscreenActivity && !r.fullscreen) { |
| 1589 | behindTranslucentActivity = true; |
| 1590 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1591 | } else { |
Wale Ogunwale | 834c236 | 2016-01-23 18:14:58 -0800 | [diff] [blame] | 1592 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1593 | + " finishing=" + r.finishing + " state=" + r.state + " stackInvisible=" |
| 1594 | + stackInvisible + " behindFullscreenActivity=" |
| 1595 | + behindFullscreenActivity + " mLaunchTaskBehind=" |
| 1596 | + r.mLaunchTaskBehind); |
| 1597 | makeInvisible(r, visibleBehind); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1598 | } |
| 1599 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1600 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1601 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1602 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1603 | // status of an activity in a previous task affects other. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1604 | behindFullscreenActivity = stackVisibility == STACK_INVISIBLE; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1605 | } else if (mStackId == HOME_STACK_ID) { |
| 1606 | if (task.isHomeTask()) { |
| 1607 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
| 1608 | + " stackInvisible=" + stackInvisible |
| 1609 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1610 | // No other task in the home stack should be visible behind the home activity. |
| 1611 | // Home activities is usually a translucent activity with the wallpaper behind |
| 1612 | // them. However, when they don't have the wallpaper behind them, we want to |
| 1613 | // show activities in the next application stack behind them vs. another |
| 1614 | // task in the home stack like recents. |
| 1615 | behindFullscreenActivity = true; |
| 1616 | } else if (task.isRecentsTask() |
| 1617 | && task.getTaskToReturnTo() == APPLICATION_ACTIVITY_TYPE) { |
| 1618 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1619 | "Recents task returning to app: at " + task |
| 1620 | + " stackInvisible=" + stackInvisible |
| 1621 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1622 | // We don't want any other tasks in the home stack visible if the recents |
| 1623 | // activity is going to be returning to an application activity type. |
| 1624 | // We do this to preserve the visible order the user used to get into the |
| 1625 | // recents activity. The recents activity is normally translucent and if it |
| 1626 | // doesn't have the wallpaper behind it the next activity in the home stack |
| 1627 | // shouldn't be visible when the home stack is brought to the front to display |
| 1628 | // the recents activity from an app. |
| 1629 | behindFullscreenActivity = true; |
| 1630 | } |
| 1631 | |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1632 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1633 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1634 | |
| 1635 | if (mTranslucentActivityWaiting != null && |
| 1636 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1637 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1638 | notifyActivityDrawnLocked(null); |
| 1639 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1640 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1641 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1642 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 1643 | if (mTranslucentActivityWaiting != top) { |
| 1644 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1645 | if (mTranslucentActivityWaiting != null) { |
| 1646 | // Call the callback with a timeout indication. |
| 1647 | notifyActivityDrawnLocked(null); |
| 1648 | mTranslucentActivityWaiting = null; |
| 1649 | } |
| 1650 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1655 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1656 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 1657 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 1658 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 1659 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1660 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1661 | // This activity needs to be visible, but isn't even running... |
| 1662 | // get it started and resume if no other stack in this stack is resumed. |
| 1663 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 1664 | if (r != starting) { |
| 1665 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1666 | } |
| 1667 | if (!r.visible || r.mLaunchTaskBehind) { |
| 1668 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
| 1669 | setVisible(r, true); |
| 1670 | } |
| 1671 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1672 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1673 | return true; |
| 1674 | } |
| 1675 | } |
| 1676 | return false; |
| 1677 | } |
| 1678 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1679 | private void makeInvisible(ActivityRecord r, ActivityRecord visibleBehind) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1680 | if (!r.visible) { |
| 1681 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 1682 | return; |
| 1683 | } |
| 1684 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 1685 | // keeping the screen frozen. |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1686 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.state); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1687 | try { |
| 1688 | setVisible(r, false); |
| 1689 | switch (r.state) { |
| 1690 | case STOPPING: |
| 1691 | case STOPPED: |
| 1692 | if (r.app != null && r.app.thread != null) { |
| 1693 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1694 | "Scheduling invisibility: " + r); |
| 1695 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1696 | } |
| 1697 | break; |
| 1698 | |
| 1699 | case INITIALIZING: |
| 1700 | case RESUMED: |
| 1701 | case PAUSING: |
| 1702 | case PAUSED: |
| 1703 | // This case created for transitioning activities from |
| 1704 | // translucent to opaque {@link Activity#convertToOpaque}. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1705 | if (visibleBehind == r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1706 | releaseBackgroundResources(r); |
| 1707 | } else { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1708 | addToStopping(r, true /* immediate */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1709 | } |
| 1710 | break; |
| 1711 | |
| 1712 | default: |
| 1713 | break; |
| 1714 | } |
| 1715 | } catch (Exception e) { |
| 1716 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1717 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 1722 | TaskRecord task, ActivityRecord r) { |
| 1723 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1724 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 1725 | + " stackInvisible=" + stackInvisible |
| 1726 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1727 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1728 | behindFullscreenActivity = true; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1729 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1730 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 1731 | + " stackInvisible=" + stackInvisible |
| 1732 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1733 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1734 | } |
| 1735 | return behindFullscreenActivity; |
| 1736 | } |
| 1737 | |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1738 | private void makeVisibleIfNeeded(ActivityRecord starting, ActivityRecord r) { |
| 1739 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1740 | // 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] | 1741 | if (r.state == ActivityState.RESUMED || r == starting) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 1742 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
| 1743 | "Not making visible, r=" + r + " state=" + r.state + " starting=" + starting); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1744 | return; |
| 1745 | } |
| 1746 | |
| 1747 | // If this activity is paused, tell it to now show its window. |
| 1748 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1749 | "Making visible and scheduling visibility: " + r); |
| 1750 | try { |
| 1751 | if (mTranslucentActivityWaiting != null) { |
| 1752 | r.updateOptionsLocked(r.returningOptions); |
| 1753 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1754 | } |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1755 | setVisible(r, true); |
| 1756 | r.sleeping = false; |
| 1757 | r.app.pendingUiClean = true; |
| 1758 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1759 | r.stopFreezingScreenLocked(false); |
| 1760 | } catch (Exception e) { |
| 1761 | // Just skip on any failure; we'll make it |
| 1762 | // visible when it next restarts. |
| 1763 | Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1767 | private boolean handleAlreadyVisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1768 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Skipping: already visible at " + r); |
| 1769 | r.stopFreezingScreenLocked(false); |
| 1770 | try { |
| 1771 | if (r.returningOptions != null) { |
| 1772 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions); |
| 1773 | } |
| 1774 | } catch(RemoteException e) { |
| 1775 | } |
| 1776 | return r.state == ActivityState.RESUMED; |
| 1777 | } |
| 1778 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1779 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1780 | mTranslucentActivityWaiting = r; |
| 1781 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1782 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1783 | } |
| 1784 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1785 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1786 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1787 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1788 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1789 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1790 | final ActivityRecord r = activities.get(activityNdx); |
| 1791 | if ( r.appTimeTracker != except) { |
| 1792 | r.appTimeTracker = null; |
| 1793 | } |
| 1794 | } |
| 1795 | } |
| 1796 | } |
| 1797 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1798 | /** |
| 1799 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1800 | * redrawn notify the top activity by calling |
| 1801 | * {@link Activity#onTranslucentConversionComplete}. |
| 1802 | * |
| 1803 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1804 | * occurred and the activity will be notified immediately. |
| 1805 | */ |
| 1806 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1807 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1808 | if ((r == null) |
| 1809 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1810 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1811 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1812 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1813 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1814 | mTranslucentActivityWaiting = null; |
| 1815 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1816 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1817 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1818 | if (waitingActivity != null) { |
| 1819 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 1820 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 1821 | try { |
| 1822 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1823 | waitingActivity.appToken, r != null); |
| 1824 | } catch (RemoteException e) { |
| 1825 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | } |
| 1830 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1831 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 1832 | * starting window displayed then remove that starting window. It is possible that the activity |
| 1833 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 1834 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1835 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1836 | boolean aboveTop = true; |
| 1837 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1838 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1839 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1840 | final ActivityRecord r = activities.get(activityNdx); |
| 1841 | if (aboveTop) { |
| 1842 | if (r == topActivity) { |
| 1843 | aboveTop = false; |
| 1844 | } |
| 1845 | continue; |
| 1846 | } |
| 1847 | |
| 1848 | if (r.state == ActivityState.INITIALIZING && r.mStartingWindowShown) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1849 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 1850 | "Found orphaned starting window " + r); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1851 | r.mStartingWindowShown = false; |
| 1852 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 1853 | } |
| 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1858 | /** |
| 1859 | * Ensure that the top activity in the stack is resumed. |
| 1860 | * |
| 1861 | * @param prev The previously resumed activity, for when in the process |
| 1862 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1863 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1864 | * |
| 1865 | * @return Returns true if something is being resumed, or false if |
| 1866 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1867 | * |
| 1868 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 1869 | * non-focused stack to be resumed. |
| 1870 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 1871 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1872 | */ |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1873 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1874 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1875 | // Don't even start recursing. |
| 1876 | return false; |
| 1877 | } |
| 1878 | |
| 1879 | boolean result = false; |
| 1880 | try { |
| 1881 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1882 | mStackSupervisor.inResumeTopActivity = true; |
| 1883 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 1884 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 1885 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1886 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1887 | result = resumeTopActivityInnerLocked(prev, options); |
| 1888 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1889 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1890 | } |
| 1891 | return result; |
| 1892 | } |
| 1893 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1894 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1895 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1896 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1897 | if (!mService.mBooting && !mService.mBooted) { |
| 1898 | // Not ready yet! |
| 1899 | return false; |
| 1900 | } |
| 1901 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1902 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1903 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 1904 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1905 | // Do not resume this stack if its parent is not resumed. |
| 1906 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 1907 | return false; |
| 1908 | } |
| 1909 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1910 | mStackSupervisor.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1911 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1912 | // Find the first activity that is not finishing. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1913 | final ActivityRecord next = topRunningActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1914 | |
| 1915 | // Remember how we'll process this pause/resume situation, and ensure |
| 1916 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1917 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1918 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1919 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1920 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1921 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1922 | // There are no more activities! |
| 1923 | final String reason = "noMoreActivities"; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1924 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(reason)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1925 | // Try to move focus to the next visible stack with a running activity if this |
| 1926 | // stack is not covering the entire screen. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1927 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 1928 | mStackSupervisor.getFocusedStack(), prev, null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1929 | } |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1930 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1931 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1932 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1933 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1934 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1935 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1936 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1937 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1938 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1939 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1940 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1944 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1945 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1946 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1947 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1948 | // Make sure we have executed any pending transitions, since there |
| 1949 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1950 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1951 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1952 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1953 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1954 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1955 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1956 | return false; |
| 1957 | } |
| 1958 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1959 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 1960 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1961 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1962 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1963 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1964 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1965 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1966 | // 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] | 1967 | // 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] | 1968 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1969 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 1970 | } else if (!isOnHomeDisplay()) { |
| 1971 | return false; |
| 1972 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1973 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1974 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1975 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1976 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1977 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 1978 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1979 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1982 | // If we are sleeping, and there is no resumed activity, and the top |
| 1983 | // activity is paused, well that is the state we want. |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1984 | if (mService.isSleepingOrShuttingDown() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1985 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1986 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1987 | // Make sure we have executed any pending transitions, since there |
| 1988 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1989 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1990 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1991 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1992 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1993 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1994 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1995 | return false; |
| 1996 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1997 | |
| 1998 | // Make sure that the user who owns this activity is started. If not, |
| 1999 | // we will just leave it as is because someone should be bringing |
| 2000 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2001 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2002 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 2003 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2004 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2005 | return false; |
| 2006 | } |
| 2007 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2008 | // The activity may be waiting for stop, but that is no longer |
| 2009 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2010 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2011 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2012 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2013 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2014 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2015 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2016 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2017 | // 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] | 2018 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2019 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2020 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2021 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2022 | return false; |
| 2023 | } |
| 2024 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2025 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2026 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2027 | // We need to start pausing the current activity so the top one can be resumed... |
| 2028 | final boolean dontWaitForPause = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 2029 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2030 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2031 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2032 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | e042bf2 | 2014-11-11 11:28:43 -0800 | [diff] [blame] | 2033 | pausing |= startPausingLocked(userLeaving, false, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2034 | } |
| 2035 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2036 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2037 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2038 | // At this point we want to put the upcoming activity's process |
| 2039 | // at the top of the LRU list, since we know we will be needing it |
| 2040 | // very soon and it would be a waste to let it get killed if it |
| 2041 | // happens to be sitting towards the end. |
| 2042 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2043 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2044 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2045 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2046 | return true; |
| 2047 | } |
| 2048 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2049 | // If the most recent activity was noHistory but was only stopped rather |
| 2050 | // than stopped+finished because the device went to sleep, we need to make |
| 2051 | // sure to finish it as we're making a new activity topmost. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2052 | if (mService.isSleeping() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2053 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2054 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2055 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2056 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2057 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2058 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2061 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2062 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2063 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2064 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2065 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2066 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2067 | } else { |
| 2068 | // The next activity is already visible, so hide the previous |
| 2069 | // activity's windows right now so we can show the new one ASAP. |
| 2070 | // We only do this if the previous is finishing, which should mean |
| 2071 | // it is on top of the one being resumed so hiding it quickly |
| 2072 | // is good. Otherwise, we want to do the normal route of allowing |
| 2073 | // the resumed activity to be shown so we can decide if the |
| 2074 | // previous should actually be hidden depending on whether the |
| 2075 | // new one is found to be full-screen or not. |
| 2076 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2077 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2078 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2079 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2080 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2081 | + ", nowVisible=" + next.nowVisible); |
| 2082 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2083 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2084 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2085 | + ", waitingVisible=" |
| 2086 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2087 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2092 | // Launching this app's activity, make sure the app is no longer |
| 2093 | // considered stopped. |
| 2094 | try { |
| 2095 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2096 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2097 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2098 | } catch (IllegalArgumentException e) { |
| 2099 | Slog.w(TAG, "Failed trying to unstop package " |
| 2100 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2101 | } |
| 2102 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2103 | // We are starting up the next activity, so tell the window manager |
| 2104 | // that the previous one will be hidden soon. This way it can know |
| 2105 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2106 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2107 | if (prev != null) { |
| 2108 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2109 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2110 | "Prepare close transition: prev=" + prev); |
| 2111 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2112 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2113 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2114 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2115 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2116 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 2117 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2118 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2119 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2120 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2121 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2122 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2123 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2124 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2125 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2126 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2127 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2128 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2129 | : next.mLaunchTaskBehind |
| 2130 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2131 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2132 | } |
| 2133 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2134 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2135 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2136 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2137 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2138 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2139 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2140 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2141 | } |
| 2142 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2143 | |
| 2144 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2145 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2146 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2147 | if (opts != null) { |
| 2148 | resumeAnimOptions = opts.toBundle(); |
| 2149 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2150 | next.applyOptionsLocked(); |
| 2151 | } else { |
| 2152 | next.clearOptionsLocked(); |
| 2153 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2154 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2155 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2156 | if (next.app != null && next.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2157 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2158 | |
| 2159 | // This activity is now becoming visible. |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 2160 | if (!next.visible) { |
| 2161 | mWindowManager.setAppVisibility(next.appToken, true); |
| 2162 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2163 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2164 | // schedule launch ticks to collect information about slow apps. |
| 2165 | next.startLaunchTickingLocked(); |
| 2166 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2167 | ActivityRecord lastResumedActivity = |
| 2168 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2169 | ActivityState lastState = next.state; |
| 2170 | |
| 2171 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2172 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2173 | 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] | 2174 | next.state = ActivityState.RESUMED; |
| 2175 | mResumedActivity = next; |
| 2176 | next.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 2177 | mRecentTasks.addLocked(next.task); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2178 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2179 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2180 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2181 | |
| 2182 | // Have the window manager re-evaluate the orientation of |
| 2183 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2184 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2185 | if (mStackSupervisor.isFocusedStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2186 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2187 | mService.mConfiguration, |
| 2188 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2189 | if (config != null) { |
| 2190 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2191 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2192 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2193 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2194 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2195 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2196 | // The configuration update wasn't able to keep the existing |
| 2197 | // instance of the activity, and instead started a new one. |
| 2198 | // We should be all done, but let's just make sure our activity |
| 2199 | // is still at the top and schedule another run if something |
| 2200 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2201 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2202 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2203 | "Activity config changed during resume: " + next |
| 2204 | + ", new next: " + nextNext); |
| 2205 | if (nextNext != next) { |
| 2206 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2207 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2208 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2209 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2210 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2211 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2212 | return true; |
| 2213 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2214 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2215 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2216 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2217 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2218 | try { |
| 2219 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2220 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2221 | if (a != null) { |
| 2222 | final int N = a.size(); |
| 2223 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2224 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2225 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2226 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2231 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2232 | } |
| 2233 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2234 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2235 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2236 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2237 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2238 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2239 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2240 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2241 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2242 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2243 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2244 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2245 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2246 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2247 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2248 | } catch (Exception e) { |
| 2249 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2250 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2251 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2252 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2253 | if (lastStack != null) { |
| 2254 | lastStack.mResumedActivity = lastResumedActivity; |
| 2255 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2256 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2257 | if (!next.hasBeenLaunched) { |
| 2258 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2259 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2260 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2261 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2262 | next.appToken, next.packageName, next.theme, |
| 2263 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2264 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 2265 | next.windowFlags, null, true); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 2266 | next.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2267 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2268 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2269 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2270 | return true; |
| 2271 | } |
| 2272 | |
| 2273 | // From this point on, if something goes wrong there is no way |
| 2274 | // to recover the activity. |
| 2275 | try { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2276 | completeResumeLocked(next); |
| 2277 | } catch (Exception e) { |
| 2278 | // If any exception gets thrown, toss away this |
| 2279 | // activity and try the next one. |
| 2280 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2281 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2282 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2283 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2284 | return true; |
| 2285 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2286 | } else { |
| 2287 | // Whoops, need to restart this activity! |
| 2288 | if (!next.hasBeenLaunched) { |
| 2289 | next.hasBeenLaunched = true; |
| 2290 | } else { |
| 2291 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2292 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2293 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2294 | mService.compatibilityInfoForPackageLocked( |
| 2295 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2296 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2297 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2298 | null, true); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 2299 | next.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2300 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2301 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2302 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2303 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2304 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2307 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2308 | return true; |
| 2309 | } |
| 2310 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2311 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2312 | final int index = mTaskHistory.indexOf(targetTask); |
| 2313 | if (index >= 0) { |
| 2314 | final int numTasks = mTaskHistory.size(); |
| 2315 | for (int i = index + 1; i < numTasks; ++i) { |
| 2316 | TaskRecord task = mTaskHistory.get(i); |
| 2317 | if (task.userId == targetTask.userId) { |
| 2318 | return task; |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | return null; |
| 2323 | } |
| 2324 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2325 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2326 | if (position >= mTaskHistory.size()) { |
| 2327 | insertTaskAtTop(task, null); |
| 2328 | return; |
| 2329 | } |
| 2330 | // Calculate maximum possible position for this task. |
| 2331 | int maxPosition = mTaskHistory.size(); |
| 2332 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2333 | && task.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2334 | // Put non-current user tasks below current user tasks. |
| 2335 | while (maxPosition > 0) { |
| 2336 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2337 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2338 | || tmpTask.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2339 | break; |
| 2340 | } |
| 2341 | maxPosition--; |
| 2342 | } |
| 2343 | } |
| 2344 | position = Math.min(position, maxPosition); |
| 2345 | mTaskHistory.remove(task); |
| 2346 | mTaskHistory.add(position, task); |
| 2347 | updateTaskMovement(task, true); |
| 2348 | } |
| 2349 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2350 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2351 | // If the moving task is over home stack, transfer its return type to next task |
| 2352 | if (task.isOverHomeStack()) { |
| 2353 | final TaskRecord nextTask = getNextTask(task); |
| 2354 | if (nextTask != null) { |
| 2355 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
| 2356 | } |
| 2357 | } |
| 2358 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2359 | // 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] | 2360 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2361 | if (isOnHomeDisplay()) { |
| 2362 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2363 | final boolean fromHome = lastStack.isHomeStack(); |
| 2364 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2365 | int returnToType = APPLICATION_ACTIVITY_TYPE; |
| 2366 | if (fromHome && StackId.allowTopTaskToReturnHome(mStackId)) { |
| 2367 | returnToType = lastStack.topTask() == null |
| 2368 | ? HOME_ACTIVITY_TYPE : lastStack.topTask().taskType; |
| 2369 | } |
| 2370 | task.setTaskToReturnTo(returnToType); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2371 | } |
| 2372 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2373 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2374 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2375 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2376 | mTaskHistory.remove(task); |
| 2377 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2378 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2379 | final boolean notShownWhenLocked = |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2380 | (newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2381 | || (newActivity == null && task.topRunningActivityLocked() == null); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2382 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2383 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2384 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2385 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2386 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2387 | || tmpTask.topRunningActivityLocked() == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2388 | break; |
| 2389 | } |
| 2390 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2391 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2392 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2393 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2394 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2395 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2396 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 2397 | final void startActivityLocked(ActivityRecord r, boolean newTask, boolean keepCurTransition, |
| 2398 | ActivityOptions options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2399 | TaskRecord rTask = r.task; |
| 2400 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2401 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2402 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2403 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2404 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2405 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2406 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2407 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2408 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2409 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2410 | if (!newTask) { |
| 2411 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2412 | boolean startIt = true; |
| 2413 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2414 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2415 | if (task.getTopActivity() == null) { |
| 2416 | // All activities in task are finishing. |
| 2417 | continue; |
| 2418 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2419 | if (task == r.task) { |
| 2420 | // Here it is! Now, if this is not yet visible to the |
| 2421 | // user, then just add it without starting; it will |
| 2422 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2423 | if (!startIt) { |
| 2424 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2425 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2426 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2427 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2428 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2429 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2430 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2431 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2432 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2433 | return; |
| 2434 | } |
| 2435 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2436 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2437 | startIt = false; |
| 2438 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | // Place a new activity at top of stack, so it is next to interact |
| 2443 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2444 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2445 | // If we are not placing the new activity frontmost, we do not want |
| 2446 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2447 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2448 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2449 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2450 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2451 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2452 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2453 | |
| 2454 | task = r.task; |
| 2455 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2456 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2457 | 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] | 2458 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2459 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2460 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2461 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2462 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2463 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2464 | // We want to show the starting preview window if we are |
| 2465 | // switching to a new task, or the next activity's process is |
| 2466 | // not currently running. |
| 2467 | boolean showStartingIcon = newTask; |
| 2468 | ProcessRecord proc = r.app; |
| 2469 | if (proc == null) { |
| 2470 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2471 | } |
| 2472 | if (proc == null || proc.thread == null) { |
| 2473 | showStartingIcon = true; |
| 2474 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2475 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2476 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2477 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2478 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2479 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2480 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2481 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2482 | ? r.mLaunchTaskBehind |
| 2483 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2484 | : AppTransition.TRANSIT_TASK_OPEN |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2485 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2486 | mNoAnimActivities.remove(r); |
| 2487 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2488 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2489 | boolean doShow = true; |
| 2490 | if (newTask) { |
| 2491 | // Even though this activity is starting fresh, we still need |
| 2492 | // to reset it to make sure we apply affinities to move any |
| 2493 | // existing activities from other tasks in to it. |
| 2494 | // If the caller has requested that the target task be |
| 2495 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2496 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2497 | resetTaskIfNeededLocked(r, r); |
| 2498 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2499 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2500 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2501 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2502 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2503 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2504 | if (r.mLaunchTaskBehind) { |
| 2505 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2506 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2507 | mWindowManager.setAppVisibility(r.appToken, true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2508 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2509 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2510 | // Figure out if we are transitioning from another activity that is |
| 2511 | // "has the same starting icon" as the next one. This allows the |
| 2512 | // window manager to keep the previous window it had previously |
| 2513 | // created, if it still had one. |
| 2514 | ActivityRecord prev = mResumedActivity; |
| 2515 | if (prev != null) { |
| 2516 | // We don't want to reuse the previous starting preview if: |
| 2517 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2518 | if (prev.task != r.task) { |
| 2519 | prev = null; |
| 2520 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2521 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2522 | else if (prev.nowVisible) { |
| 2523 | prev = null; |
| 2524 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2525 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2526 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2527 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2528 | mService.compatibilityInfoForPackageLocked( |
| 2529 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2530 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2531 | prev != null ? prev.appToken : null, showStartingIcon); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2532 | r.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2533 | } |
| 2534 | } else { |
| 2535 | // If this is the first activity, don't do any fancy animations, |
| 2536 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2537 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2538 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2539 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2540 | } |
| 2541 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2542 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2543 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2546 | final void validateAppTokensLocked() { |
| 2547 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2548 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2549 | final int numTasks = mTaskHistory.size(); |
| 2550 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2551 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2552 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2553 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2554 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2555 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2556 | TaskGroup group = new TaskGroup(); |
| 2557 | group.taskId = task.taskId; |
| 2558 | mValidateAppTokens.add(group); |
| 2559 | final int numActivities = activities.size(); |
| 2560 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2561 | final ActivityRecord r = activities.get(activityNdx); |
| 2562 | group.tokens.add(r.appToken); |
| 2563 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2564 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2565 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2566 | } |
| 2567 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2568 | /** |
| 2569 | * Perform a reset of the given task, if needed as part of launching it. |
| 2570 | * Returns the new HistoryRecord at the top of the task. |
| 2571 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2572 | /** |
| 2573 | * Helper method for #resetTaskIfNeededLocked. |
| 2574 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2575 | * for another task, or leave it as-is. |
| 2576 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2577 | * @param forceReset |
| 2578 | * @return An ActivityOptions that needs to be processed. |
| 2579 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2580 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2581 | ActivityOptions topOptions = null; |
| 2582 | |
| 2583 | int replyChainEnd = -1; |
| 2584 | boolean canMoveOptions = true; |
| 2585 | |
| 2586 | // We only do this for activities that are not the root of the task (since if we finish |
| 2587 | // the root, we may no longer have the task!). |
| 2588 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2589 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2590 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2591 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2592 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2593 | if (target.frontOfTask) |
| 2594 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2595 | |
| 2596 | final int flags = target.info.flags; |
| 2597 | final boolean finishOnTaskLaunch = |
| 2598 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2599 | final boolean allowTaskReparenting = |
| 2600 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2601 | final boolean clearWhenTaskReset = |
| 2602 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2603 | |
| 2604 | if (!finishOnTaskLaunch |
| 2605 | && !clearWhenTaskReset |
| 2606 | && target.resultTo != null) { |
| 2607 | // If this activity is sending a reply to a previous |
| 2608 | // activity, we can't do anything with it now until |
| 2609 | // we reach the start of the reply chain. |
| 2610 | // XXX note that we are assuming the result is always |
| 2611 | // to the previous activity, which is almost always |
| 2612 | // the case but we really shouldn't count on. |
| 2613 | if (replyChainEnd < 0) { |
| 2614 | replyChainEnd = i; |
| 2615 | } |
| 2616 | } else if (!finishOnTaskLaunch |
| 2617 | && !clearWhenTaskReset |
| 2618 | && allowTaskReparenting |
| 2619 | && target.taskAffinity != null |
| 2620 | && !target.taskAffinity.equals(task.affinity)) { |
| 2621 | // If this activity has an affinity for another |
| 2622 | // task, then we need to move it out of here. We will |
| 2623 | // move it as far out of the way as possible, to the |
| 2624 | // bottom of the activity stack. This also keeps it |
| 2625 | // correctly ordered with any activities we previously |
| 2626 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2627 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2628 | final ActivityRecord bottom = |
| 2629 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2630 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2631 | if (bottom != null && target.taskAffinity != null |
| 2632 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2633 | // If the activity currently at the bottom has the |
| 2634 | // same task affinity as the one we are moving, |
| 2635 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2636 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2637 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2638 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2639 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 2640 | targetTask = createTaskRecord( |
| 2641 | mStackSupervisor.getNextTaskIdForUserLocked(target.userId), |
| 2642 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2643 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2644 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2645 | + " out to new task " + target.task); |
| 2646 | } |
| 2647 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2648 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2649 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2650 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2651 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2652 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2653 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2654 | if (p.finishing) { |
| 2655 | continue; |
| 2656 | } |
| 2657 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2658 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2659 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2660 | topOptions = p.takeOptionsLocked(); |
| 2661 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2662 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2663 | } |
| 2664 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2665 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2666 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2667 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2668 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2669 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2670 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2671 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2672 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2673 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2674 | } |
| 2675 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2676 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2677 | if (VALIDATE_TOKENS) { |
| 2678 | validateAppTokensLocked(); |
| 2679 | } |
| 2680 | |
| 2681 | replyChainEnd = -1; |
| 2682 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2683 | // If the activity should just be removed -- either |
| 2684 | // because it asks for it, or the task should be |
| 2685 | // cleared -- then finish it and anything that is |
| 2686 | // part of its reply chain. |
| 2687 | int end; |
| 2688 | if (clearWhenTaskReset) { |
| 2689 | // In this case, we want to finish this activity |
| 2690 | // and everything above it, so be sneaky and pretend |
| 2691 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2692 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2693 | } else if (replyChainEnd < 0) { |
| 2694 | end = i; |
| 2695 | } else { |
| 2696 | end = replyChainEnd; |
| 2697 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2698 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2699 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2700 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2701 | if (p.finishing) { |
| 2702 | continue; |
| 2703 | } |
| 2704 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2705 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2706 | topOptions = p.takeOptionsLocked(); |
| 2707 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2708 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2709 | } |
| 2710 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2711 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2712 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2713 | if (finishActivityLocked( |
| 2714 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2715 | end--; |
| 2716 | srcPos--; |
| 2717 | } |
| 2718 | } |
| 2719 | replyChainEnd = -1; |
| 2720 | } else { |
| 2721 | // If we were in the middle of a chain, well the |
| 2722 | // activity that started it all doesn't want anything |
| 2723 | // special, so leave it all as-is. |
| 2724 | replyChainEnd = -1; |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | return topOptions; |
| 2729 | } |
| 2730 | |
| 2731 | /** |
| 2732 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2733 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2734 | * @param affinityTask The task we are looking for an affinity to. |
| 2735 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2736 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2737 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2738 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2739 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2740 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2741 | int replyChainEnd = -1; |
| 2742 | final int taskId = task.taskId; |
| 2743 | final String taskAffinity = task.affinity; |
| 2744 | |
| 2745 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2746 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2747 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 2748 | |
| 2749 | // Do not operate on or below the effective root Activity. |
| 2750 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2751 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2752 | if (target.frontOfTask) |
| 2753 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2754 | |
| 2755 | final int flags = target.info.flags; |
| 2756 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2757 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2758 | |
| 2759 | if (target.resultTo != null) { |
| 2760 | // If this activity is sending a reply to a previous |
| 2761 | // activity, we can't do anything with it now until |
| 2762 | // we reach the start of the reply chain. |
| 2763 | // XXX note that we are assuming the result is always |
| 2764 | // to the previous activity, which is almost always |
| 2765 | // the case but we really shouldn't count on. |
| 2766 | if (replyChainEnd < 0) { |
| 2767 | replyChainEnd = i; |
| 2768 | } |
| 2769 | } else if (topTaskIsHigher |
| 2770 | && allowTaskReparenting |
| 2771 | && taskAffinity != null |
| 2772 | && taskAffinity.equals(target.taskAffinity)) { |
| 2773 | // This activity has an affinity for our task. Either remove it if we are |
| 2774 | // clearing or move it over to our task. Note that |
| 2775 | // we currently punt on the case where we are resetting a |
| 2776 | // task that is not at the top but who has activities above |
| 2777 | // with an affinity to it... this is really not a normal |
| 2778 | // case, and we will need to later pull that task to the front |
| 2779 | // and usually at that point we will do the reset and pick |
| 2780 | // up those remaining activities. (This only happens if |
| 2781 | // someone starts an activity in a new task from an activity |
| 2782 | // in a task that is not currently on top.) |
| 2783 | if (forceReset || finishOnTaskLaunch) { |
| 2784 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2785 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2786 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2787 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2788 | final ActivityRecord p = activities.get(srcPos); |
| 2789 | if (p.finishing) { |
| 2790 | continue; |
| 2791 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2792 | finishActivityLocked( |
| 2793 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2794 | } |
| 2795 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2796 | if (taskInsertionPoint < 0) { |
| 2797 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2798 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2799 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2800 | |
| 2801 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2802 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2803 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 2804 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2805 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2806 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2807 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2808 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2809 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2810 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2811 | "Removing and adding activity " + p + " to stack at " + task |
| 2812 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2813 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 2814 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2815 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2816 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2817 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2818 | if (VALIDATE_TOKENS) { |
| 2819 | validateAppTokensLocked(); |
| 2820 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2821 | |
| 2822 | // Now we've moved it in to place... but what if this is |
| 2823 | // a singleTop activity and we have put it on top of another |
| 2824 | // instance of the same activity? Then we drop the instance |
| 2825 | // below so it remains singleTop. |
| 2826 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2827 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2828 | int targetNdx = taskActivities.indexOf(target); |
| 2829 | if (targetNdx > 0) { |
| 2830 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2831 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2832 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2833 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2834 | } |
| 2835 | } |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | replyChainEnd = -1; |
| 2840 | } |
| 2841 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2842 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2843 | } |
| 2844 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2845 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2846 | ActivityRecord newActivity) { |
| 2847 | boolean forceReset = |
| 2848 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2849 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2850 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2851 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2852 | forceReset = true; |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | final TaskRecord task = taskTop.task; |
| 2857 | |
| 2858 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2859 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2860 | boolean taskFound = false; |
| 2861 | |
| 2862 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2863 | ActivityOptions topOptions = null; |
| 2864 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2865 | // Preserve the location for reparenting in the new task. |
| 2866 | int reparentInsertionPoint = -1; |
| 2867 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2868 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2869 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2870 | |
| 2871 | if (targetTask == task) { |
| 2872 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2873 | taskFound = true; |
| 2874 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2875 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2876 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2880 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 2881 | if (taskNdx >= 0) { |
| 2882 | do { |
| 2883 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2884 | } while (taskTop == null && taskNdx >= 0); |
| 2885 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2886 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2887 | if (topOptions != null) { |
| 2888 | // If we got some ActivityOptions from an activity on top that |
| 2889 | // was removed from the task, propagate them to the new real top. |
| 2890 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2891 | taskTop.updateOptionsLocked(topOptions); |
| 2892 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2893 | topOptions.abort(); |
| 2894 | } |
| 2895 | } |
| 2896 | |
| 2897 | return taskTop; |
| 2898 | } |
| 2899 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2900 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2901 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2902 | |
| 2903 | if (callingUid > 0) { |
| 2904 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2905 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2909 | + " : who=" + resultWho + " req=" + requestCode |
| 2910 | + " res=" + resultCode + " data=" + data); |
| 2911 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2912 | try { |
| 2913 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2914 | list.add(new ResultInfo(resultWho, requestCode, |
| 2915 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2916 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2917 | return; |
| 2918 | } catch (Exception e) { |
| 2919 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2924 | } |
| 2925 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2926 | private void adjustFocusedActivityLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2927 | if (!mStackSupervisor.isFocusedStack(this) || mService.mFocusedActivity != r) { |
| 2928 | return; |
| 2929 | } |
| 2930 | |
| 2931 | final ActivityRecord next = topRunningActivityLocked(); |
| 2932 | final String myReason = reason + " adjustFocus"; |
| 2933 | if (next != r) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2934 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2935 | // For freeform, docked, and pinned stacks we always keep the focus within the |
| 2936 | // stack as long as there is a running activity in the stack that we can adjust |
| 2937 | // focus to. |
| 2938 | mService.setFocusedActivityLocked(next, myReason); |
| 2939 | return; |
| 2940 | } else { |
| 2941 | final TaskRecord task = r.task; |
| 2942 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
| 2943 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 2944 | // stack to prevent the home screen from moving to the top and obscuring |
| 2945 | // other visible stacks. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2946 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2947 | return; |
| 2948 | } |
| 2949 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 2950 | // other visible stack. |
| 2951 | if (mStackSupervisor.moveHomeStackTaskToTop( |
| 2952 | task.getTaskToReturnTo(), myReason)) { |
| 2953 | // Activity focus was already adjusted. Nothing else to do... |
| 2954 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 2955 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2956 | } |
| 2957 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2958 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2959 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2960 | mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked(), myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2963 | private boolean adjustFocusToNextFocusableStackLocked(String reason) { |
| 2964 | final ActivityStack stack = getNextFocusableStackLocked(); |
| 2965 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2966 | if (stack == null) { |
| 2967 | return false; |
| 2968 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2969 | return mService.setFocusedActivityLocked(stack.topRunningActivityLocked(), myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2970 | } |
| 2971 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2972 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2973 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2974 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2975 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2976 | if (!r.finishing) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2977 | if (!mService.isSleeping()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2978 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 2979 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 2980 | "stop-no-history", false)) { |
| 2981 | // Activity was finished, no need to continue trying to schedule stop. |
| 2982 | adjustFocusedActivityLocked(r, "stopActivityFinished"); |
| 2983 | r.resumeKeyDispatchingLocked(); |
| 2984 | return; |
| 2985 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2986 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2987 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2988 | + " on stop because we're just sleeping"); |
| 2989 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2990 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2994 | adjustFocusedActivityLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2995 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2996 | try { |
| 2997 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2998 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 2999 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3000 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3001 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3002 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3003 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3004 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3005 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3006 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 3007 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3008 | r.setSleeping(true); |
| 3009 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3010 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3011 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3012 | } catch (Exception e) { |
| 3013 | // Maybe just ignore exceptions here... if the process |
| 3014 | // has crashed, our death notification will clean things |
| 3015 | // up. |
| 3016 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3017 | // Just in case, assume it to be stopped. |
| 3018 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3019 | 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] | 3020 | r.state = ActivityState.STOPPED; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3021 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3022 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3023 | } |
| 3024 | } |
| 3025 | } |
| 3026 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3027 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3028 | /** |
| 3029 | * @return Returns true if the activity is being finished, false if for |
| 3030 | * some reason it is being left as-is. |
| 3031 | */ |
| 3032 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3033 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3034 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3035 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3036 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3037 | + ", result=" + resultCode + ", data=" + resultData |
| 3038 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3039 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3040 | return false; |
| 3041 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3042 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3043 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3044 | return true; |
| 3045 | } |
| 3046 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3047 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3048 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3049 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3050 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3051 | ActivityRecord r = activities.get(activityNdx); |
| 3052 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3053 | if ((r.resultWho == null && resultWho == null) || |
| 3054 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3055 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3056 | false); |
| 3057 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3058 | } |
| 3059 | } |
| 3060 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3061 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3064 | final TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3065 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3066 | TaskRecord finishedTask = null; |
| 3067 | if (r == null || r.app != app) { |
| 3068 | return null; |
| 3069 | } |
| 3070 | Slog.w(TAG, " Force finishing activity " |
| 3071 | + r.intent.getComponent().flattenToShortString()); |
| 3072 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 3073 | int activityNdx = r.task.mActivities.indexOf(r); |
| 3074 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
| 3075 | finishedTask = r.task; |
| 3076 | // Also terminate any activities below it that aren't yet |
| 3077 | // stopped, to avoid a situation where one will get |
| 3078 | // re-start our crashing activity once it gets resumed again. |
| 3079 | --activityNdx; |
| 3080 | if (activityNdx < 0) { |
| 3081 | do { |
| 3082 | --taskNdx; |
| 3083 | if (taskNdx < 0) { |
| 3084 | break; |
| 3085 | } |
| 3086 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3087 | } while (activityNdx < 0); |
| 3088 | } |
| 3089 | if (activityNdx >= 0) { |
| 3090 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
| 3091 | if (r.state == ActivityState.RESUMED |
| 3092 | || r.state == ActivityState.PAUSING |
| 3093 | || r.state == ActivityState.PAUSED) { |
| 3094 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
| 3095 | Slog.w(TAG, " Force finishing activity " |
| 3096 | + r.intent.getComponent().flattenToShortString()); |
| 3097 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3098 | } |
| 3099 | } |
| 3100 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3101 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3102 | } |
| 3103 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3104 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3105 | IBinder sessionBinder = session.asBinder(); |
| 3106 | boolean didOne = false; |
| 3107 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3108 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3109 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3110 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3111 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3112 | if (!r.finishing) { |
| 3113 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3114 | false); |
| 3115 | didOne = true; |
| 3116 | } |
| 3117 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3118 | } else { |
| 3119 | // Check if any of the activities are using voice |
| 3120 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3121 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3122 | if (r.voiceSession != null |
| 3123 | && r.voiceSession.asBinder() == sessionBinder) { |
| 3124 | // Inform of cancellation |
| 3125 | r.clearVoiceSessionLocked(); |
| 3126 | try { |
| 3127 | r.app.thread.scheduleLocalVoiceInteractionStarted((IBinder) r.appToken, |
| 3128 | null); |
| 3129 | } catch (RemoteException re) { |
| 3130 | // Ok |
| 3131 | } |
| 3132 | // TODO: VI This is redundant in some cases |
| 3133 | mService.finishRunningVoiceLocked(); |
| 3134 | break; |
| 3135 | } |
| 3136 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3137 | } |
| 3138 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3139 | Slog.d(TAG, "ActivityStack.finishVoiceTask()"); |
| 3140 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3141 | if (didOne) { |
| 3142 | mService.updateOomAdjLocked(); |
| 3143 | } |
| 3144 | } |
| 3145 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3146 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3147 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 3148 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3149 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3150 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3151 | break; |
| 3152 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3153 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3154 | } |
| 3155 | return true; |
| 3156 | } |
| 3157 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3158 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 3159 | // send the result |
| 3160 | ActivityRecord resultTo = r.resultTo; |
| 3161 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3162 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3163 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3164 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3165 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3166 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3167 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3168 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3169 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3170 | if (r.info.applicationInfo.uid > 0) { |
| 3171 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3172 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3173 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3174 | } |
| 3175 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3176 | resultData); |
| 3177 | r.resultTo = null; |
| 3178 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3179 | 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] | 3180 | |
| 3181 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3182 | // because clients have remote IPC references to this object so we |
| 3183 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3184 | r.results = null; |
| 3185 | r.pendingResults = null; |
| 3186 | r.newIntents = null; |
| 3187 | r.icicle = null; |
| 3188 | } |
| 3189 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3190 | /** |
| 3191 | * @return Returns true if this activity has been removed from the history |
| 3192 | * list, or false if it is still in the list and will be removed later. |
| 3193 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3194 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3195 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3196 | if (r.finishing) { |
| 3197 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3198 | return false; |
| 3199 | } |
| 3200 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3201 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3202 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3203 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3204 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3205 | task.taskId, r.shortComponentName, reason); |
| 3206 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3207 | final int index = activities.indexOf(r); |
| 3208 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3209 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3210 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3211 | // If the caller asked that this activity (and all above it) |
| 3212 | // be cleared when the task is reset, don't lose that information, |
| 3213 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3214 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3215 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3220 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3221 | adjustFocusedActivityLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3222 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3223 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3224 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3225 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3226 | boolean endTask = index <= 0; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3227 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3228 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3229 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3230 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 3231 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3232 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3233 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3234 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3235 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3236 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3237 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3238 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3239 | "finish() => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3240 | startPausingLocked(false, false, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3243 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3244 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3245 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3246 | } else if (r.state != ActivityState.PAUSING) { |
| 3247 | // If the activity is PAUSING, we will complete the finish once |
| 3248 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3249 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3250 | if (r.visible) { |
| 3251 | mWindowManager.setAppVisibility(r.appToken, false); |
| 3252 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3253 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3254 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3255 | 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] | 3256 | } |
| 3257 | |
| 3258 | return false; |
| 3259 | } |
| 3260 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3261 | static final int FINISH_IMMEDIATELY = 0; |
| 3262 | static final int FINISH_AFTER_PAUSE = 1; |
| 3263 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3264 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3265 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3266 | // First things first: if this activity is currently visible, |
| 3267 | // and the resumed activity is not yet visible, then hold off on |
| 3268 | // finishing until the resumed one becomes visible. |
| 3269 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3270 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 3271 | addToStopping(r, false /* immediate */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3272 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3273 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3274 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3275 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3276 | if (oomAdj) { |
| 3277 | mService.updateOomAdjLocked(); |
| 3278 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3279 | return r; |
| 3280 | } |
| 3281 | |
| 3282 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3283 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3284 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3285 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3286 | if (mResumedActivity == r) { |
| 3287 | mResumedActivity = null; |
| 3288 | } |
| 3289 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3290 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3291 | r.state = ActivityState.FINISHING; |
| 3292 | |
| 3293 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3294 | || (mode == FINISH_AFTER_PAUSE && prevState == ActivityState.PAUSED) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3295 | || prevState == ActivityState.STOPPED |
| 3296 | || prevState == ActivityState.INITIALIZING) { |
| 3297 | // If this activity is already stopped, we can just finish |
| 3298 | // it right now. |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3299 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3300 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3301 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3302 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3303 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3304 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3305 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3306 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3307 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3308 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3309 | |
| 3310 | // Need to go through the full pause cycle to get this |
| 3311 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3312 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3313 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3314 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3315 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3316 | return r; |
| 3317 | } |
| 3318 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3319 | void finishAllActivitiesLocked(boolean immediately) { |
| 3320 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3321 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3322 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3323 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3324 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3325 | noActivitiesInStack = false; |
| 3326 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3327 | continue; |
| 3328 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3329 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3330 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3331 | } |
| 3332 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3333 | if (noActivitiesInStack) { |
| 3334 | mActivityContainer.onTaskListEmptyLocked(); |
| 3335 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3336 | } |
| 3337 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3338 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3339 | // Basic case: for simple app-centric recents, we need to recreate |
| 3340 | // the task if the affinity has changed. |
| 3341 | if (srec == null || srec.task.affinity == null || |
| 3342 | !srec.task.affinity.equals(destAffinity)) { |
| 3343 | return true; |
| 3344 | } |
| 3345 | // Document-centric case: an app may be split in to multiple documents; |
| 3346 | // they need to re-create their task if this current activity is the root |
| 3347 | // of a document, unless simply finishing it will return them to the the |
| 3348 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3349 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3350 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3351 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3352 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3353 | // Finishing won't return to an application, so we need to recreate. |
| 3354 | return true; |
| 3355 | } |
| 3356 | // We now need to get the task below it to determine what to do. |
| 3357 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3358 | if (taskIdx <= 0) { |
| 3359 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3360 | return false; |
| 3361 | } |
| 3362 | if (taskIdx == 0) { |
| 3363 | // At the bottom of the stack, nothing to go back to. |
| 3364 | return true; |
| 3365 | } |
| 3366 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3367 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3368 | // These are different apps, so need to recreate. |
| 3369 | return true; |
| 3370 | } |
| 3371 | } |
| 3372 | return false; |
| 3373 | } |
| 3374 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3375 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3376 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3377 | final TaskRecord task = srec.task; |
| 3378 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3379 | final int start = activities.indexOf(srec); |
| 3380 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3381 | return false; |
| 3382 | } |
| 3383 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3384 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3385 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3386 | final ComponentName dest = destIntent.getComponent(); |
| 3387 | if (start > 0 && dest != null) { |
| 3388 | for (int i = finishTo; i >= 0; i--) { |
| 3389 | ActivityRecord r = activities.get(i); |
| 3390 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3391 | r.info.name.equals(dest.getClassName())) { |
| 3392 | finishTo = i; |
| 3393 | parent = r; |
| 3394 | foundParentInTask = true; |
| 3395 | break; |
| 3396 | } |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | IActivityController controller = mService.mController; |
| 3401 | if (controller != null) { |
| 3402 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3403 | if (next != null) { |
| 3404 | // ask watcher if this is allowed |
| 3405 | boolean resumeOK = true; |
| 3406 | try { |
| 3407 | resumeOK = controller.activityResuming(next.packageName); |
| 3408 | } catch (RemoteException e) { |
| 3409 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3410 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | if (!resumeOK) { |
| 3414 | return false; |
| 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | final long origId = Binder.clearCallingIdentity(); |
| 3419 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3420 | ActivityRecord r = activities.get(i); |
| 3421 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3422 | // Only return the supplied result for the first activity finished |
| 3423 | resultCode = Activity.RESULT_CANCELED; |
| 3424 | resultData = null; |
| 3425 | } |
| 3426 | |
| 3427 | if (parent != null && foundParentInTask) { |
| 3428 | final int parentLaunchMode = parent.info.launchMode; |
| 3429 | final int destIntentFlags = destIntent.getFlags(); |
| 3430 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3431 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3432 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3433 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3434 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3435 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3436 | } else { |
| 3437 | try { |
| 3438 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3439 | destIntent.getComponent(), 0, srec.userId); |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 3440 | int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, |
| 3441 | destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, |
| 3442 | null, parent.appToken, null, 0, -1, parent.launchedFromUid, |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 3443 | parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, |
| 3444 | false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3445 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3446 | } catch (RemoteException e) { |
| 3447 | foundParentInTask = false; |
| 3448 | } |
| 3449 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3450 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3451 | } |
| 3452 | } |
| 3453 | Binder.restoreCallingIdentity(origId); |
| 3454 | return foundParentInTask; |
| 3455 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3456 | /** |
| 3457 | * Perform the common clean-up of an activity record. This is called both |
| 3458 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3459 | * representation) and cleaning things up as a result of its hosting |
| 3460 | * processing going away, in which case there is no remaining client-side |
| 3461 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3462 | * |
| 3463 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3464 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3465 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3466 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3467 | if (mResumedActivity == r) { |
| 3468 | mResumedActivity = null; |
| 3469 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3470 | if (mPausingActivity == r) { |
| 3471 | mPausingActivity = null; |
| 3472 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3473 | mService.resetFocusedActivityIfNeededLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3474 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3475 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3476 | r.frozenBeforeDestroy = false; |
| 3477 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3478 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3479 | 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] | 3480 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3481 | 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] | 3482 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3485 | // Make sure this record is no longer in the pending finishes list. |
| 3486 | // This could happen, for example, if we are trimming activities |
| 3487 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3488 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3489 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3490 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3491 | // Remove any pending results. |
| 3492 | if (r.finishing && r.pendingResults != null) { |
| 3493 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3494 | PendingIntentRecord rec = apr.get(); |
| 3495 | if (rec != null) { |
| 3496 | mService.cancelIntentSenderLocked(rec, false); |
| 3497 | } |
| 3498 | } |
| 3499 | r.pendingResults = null; |
| 3500 | } |
| 3501 | |
| 3502 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3503 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3504 | } |
| 3505 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3506 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3507 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3508 | if (getVisibleBehindActivity() == r) { |
| 3509 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3510 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3514 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3515 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3516 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3517 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3518 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3521 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3522 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3523 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3524 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3525 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3526 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3527 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3528 | r.takeFromHistory(); |
| 3529 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3530 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3531 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3532 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3533 | 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] | 3534 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3535 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3536 | if (VALIDATE_TOKENS) { |
| 3537 | validateAppTokensLocked(); |
| 3538 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3539 | final TaskRecord task = r.task; |
| 3540 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3541 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3542 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3543 | if (mStackSupervisor.isFocusedStack(this) && task == topTask() && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3544 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3545 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3546 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3547 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3548 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3549 | cleanUpActivityServicesLocked(r); |
| 3550 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3551 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3552 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3553 | /** |
| 3554 | * Perform clean-up of service connections in an activity record. |
| 3555 | */ |
| 3556 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3557 | // Throw away any services that have been bound by this activity. |
| 3558 | if (r.connections != null) { |
| 3559 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3560 | while (it.hasNext()) { |
| 3561 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3562 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3563 | } |
| 3564 | r.connections = null; |
| 3565 | } |
| 3566 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3567 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3568 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3569 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3570 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3571 | mHandler.sendMessage(msg); |
| 3572 | } |
| 3573 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3574 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3575 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3576 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3577 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3578 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3579 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3580 | final ActivityRecord r = activities.get(activityNdx); |
| 3581 | if (r.finishing) { |
| 3582 | continue; |
| 3583 | } |
| 3584 | if (r.fullscreen) { |
| 3585 | lastIsOpaque = true; |
| 3586 | } |
| 3587 | if (owner != null && r.app != owner) { |
| 3588 | continue; |
| 3589 | } |
| 3590 | if (!lastIsOpaque) { |
| 3591 | continue; |
| 3592 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3593 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3594 | 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] | 3595 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3596 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3597 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3598 | activityRemoved = true; |
| 3599 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3600 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3601 | } |
| 3602 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3603 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3604 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3605 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3608 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3609 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3610 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3611 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3612 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3613 | return destroyActivityLocked(r, true, reason); |
| 3614 | } |
| 3615 | return false; |
| 3616 | } |
| 3617 | |
| 3618 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3619 | String reason) { |
| 3620 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3621 | 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] | 3622 | int maxTasks = tasks.size() / 4; |
| 3623 | if (maxTasks < 1) { |
| 3624 | maxTasks = 1; |
| 3625 | } |
| 3626 | int numReleased = 0; |
| 3627 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3628 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3629 | if (!tasks.contains(task)) { |
| 3630 | continue; |
| 3631 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3632 | 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] | 3633 | int curNum = 0; |
| 3634 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3635 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3636 | final ActivityRecord activity = activities.get(actNdx); |
| 3637 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3638 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3639 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3640 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3641 | destroyActivityLocked(activity, true, reason); |
| 3642 | if (activities.get(actNdx) != activity) { |
| 3643 | // Was removed from list, back up so we don't miss the next one. |
| 3644 | actNdx--; |
| 3645 | } |
| 3646 | curNum++; |
| 3647 | } |
| 3648 | } |
| 3649 | if (curNum > 0) { |
| 3650 | numReleased += curNum; |
| 3651 | maxTasks--; |
| 3652 | if (mTaskHistory.get(taskNdx) != task) { |
| 3653 | // The entire task got removed, back up so we don't miss the next one. |
| 3654 | taskNdx--; |
| 3655 | } |
| 3656 | } |
| 3657 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3658 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3659 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3660 | return numReleased; |
| 3661 | } |
| 3662 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3663 | /** |
| 3664 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3665 | * called both when actually finishing an activity, or when performing |
| 3666 | * a configuration switch where we destroy the current client-side object |
| 3667 | * but then create a new client-side object for this same HistoryRecord. |
| 3668 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3669 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3670 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3671 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3672 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3673 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3674 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3675 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3676 | |
| 3677 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3678 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3679 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3680 | |
| 3681 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3682 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3683 | if (hadApp) { |
| 3684 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3685 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3686 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 3687 | mService.mHeavyWeightProcess = null; |
| 3688 | mService.mHandler.sendEmptyMessage( |
| 3689 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 3690 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3691 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 3692 | // Update any services we are bound to that might care about whether |
| 3693 | // their client may have activities. |
| 3694 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 3695 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 3696 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3697 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3698 | } |
| 3699 | } |
| 3700 | |
| 3701 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3702 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3703 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3704 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3705 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3706 | r.configChangeFlags); |
| 3707 | } catch (Exception e) { |
| 3708 | // We can just ignore exceptions here... if the process |
| 3709 | // has crashed, our death notification will clean things |
| 3710 | // up. |
| 3711 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 3712 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3713 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3714 | removedFromHistory = true; |
| 3715 | skipDestroy = true; |
| 3716 | } |
| 3717 | } |
| 3718 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3719 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3720 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3721 | // If the activity is finishing, we need to wait on removing it |
| 3722 | // from the list to give it a chance to do its cleanup. During |
| 3723 | // that time it may make calls back with its token so we need to |
| 3724 | // be able to find it on the list and so we don't want to remove |
| 3725 | // it from the list yet. Otherwise, we can just immediately put |
| 3726 | // it in the destroyed state since we are not removing it from the |
| 3727 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3728 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3729 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3730 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3731 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3732 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3733 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 3734 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3735 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3736 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3737 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3738 | 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] | 3739 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3740 | } |
| 3741 | } else { |
| 3742 | // remove this record from the history. |
| 3743 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3744 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3745 | removedFromHistory = true; |
| 3746 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3747 | 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] | 3748 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3749 | 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] | 3750 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3751 | } |
| 3752 | } |
| 3753 | |
| 3754 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3755 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3756 | if (!mLRUActivities.remove(r) && hadApp) { |
| 3757 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 3758 | } |
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 | return removedFromHistory; |
| 3761 | } |
| 3762 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3763 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3764 | final long origId = Binder.clearCallingIdentity(); |
| 3765 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3766 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3767 | if (r != null) { |
| 3768 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3769 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3770 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3771 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3772 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3773 | if (r.state == ActivityState.DESTROYING) { |
| 3774 | cleanUpActivityLocked(r, true, false); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3775 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3776 | } |
| 3777 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3778 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3781 | } |
| 3782 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3783 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 3784 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3785 | if (hasVisibleBehindActivity() && |
| 3786 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 3787 | if (r == topRunningActivityLocked() && getStackVisibilityLocked() == STACK_VISIBLE) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3788 | // 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] | 3789 | // activity and the stack is currently visible. |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3790 | return; |
| 3791 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3792 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3793 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3794 | " thread=" + r.app.thread); |
| 3795 | if (r != null && r.app != null && r.app.thread != null) { |
| 3796 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3797 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3798 | } catch (RemoteException e) { |
| 3799 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3800 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3801 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3802 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3803 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | } |
| 3807 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3808 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3809 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 3810 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3811 | if (r != null) { |
| 3812 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3813 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3814 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3815 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3816 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3819 | boolean hasVisibleBehindActivity() { |
| 3820 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
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 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3824 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3825 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3826 | } |
| 3827 | } |
| 3828 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3829 | ActivityRecord getVisibleBehindActivity() { |
| 3830 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3833 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 3834 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3835 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3836 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3837 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3838 | while (i > 0) { |
| 3839 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3840 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3841 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3842 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3843 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3844 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3845 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3850 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 3851 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3852 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 3853 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3854 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 3855 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3856 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3857 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3858 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 3859 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3860 | |
| 3861 | boolean hasVisibleActivities = false; |
| 3862 | |
| 3863 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3864 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3865 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3866 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3867 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3868 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3869 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3870 | final ActivityRecord r = activities.get(activityNdx); |
| 3871 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3872 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3873 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3874 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 3875 | if (r.visible) { |
| 3876 | hasVisibleActivities = true; |
| 3877 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3878 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3879 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 3880 | // Don't currently have state for the activity, or |
| 3881 | // it is finishing -- always remove it. |
| 3882 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3883 | } else if (!r.visible && r.launchCount > 2 && |
| 3884 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3885 | // We have launched this activity too many times since it was |
| 3886 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3887 | // (Note if the activity is visible, we don't remove the record. |
| 3888 | // We leave the dead window on the screen but the process will |
| 3889 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3890 | remove = true; |
| 3891 | } else { |
| 3892 | // The process may be gone, but the activity lives on! |
| 3893 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3894 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3895 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3896 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 3897 | "Removing activity " + r + " from stack at " + i |
| 3898 | + ": haveState=" + r.haveState |
| 3899 | + " stateNotNeeded=" + r.stateNotNeeded |
| 3900 | + " finishing=" + r.finishing |
| 3901 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3902 | if (!r.finishing) { |
| 3903 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 3904 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3905 | r.userId, System.identityHashCode(r), |
| 3906 | r.task.taskId, r.shortComponentName, |
| 3907 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3908 | if (r.state == ActivityState.RESUMED) { |
| 3909 | mService.updateUsageStats(r, false); |
| 3910 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3911 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3912 | } else { |
| 3913 | // We have the current state for this activity, so |
| 3914 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3915 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 3916 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 3917 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3918 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3919 | // Set nowVisible to previous visible state. If the app was visible while |
| 3920 | // it died, we leave the dead window on screen so it's basically visible. |
| 3921 | // This is needed when user later tap on the dead window, we need to stop |
| 3922 | // other apps when user transfers focus to the restarted activity. |
| 3923 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3924 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3925 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3926 | "App died, clearing saved state of " + r); |
| 3927 | r.icicle = null; |
| 3928 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3929 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3930 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3931 | if (remove) { |
| 3932 | removeActivityFromHistoryLocked(r, "appDied"); |
| 3933 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3934 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3939 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3940 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3941 | final void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3942 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3943 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3944 | if (r != null && r.state != ActivityState.RESUMED) { |
| 3945 | r.updateOptionsLocked(options); |
| 3946 | } else { |
| 3947 | ActivityOptions.abort(options); |
| 3948 | } |
| 3949 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3950 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3951 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 3952 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3953 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 3954 | if (task.isPersistable) { |
| 3955 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 3956 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 3957 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 3958 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 3959 | if (!toFront) { |
| 3960 | task.mLastTimeMoved *= -1; |
| 3961 | } |
| 3962 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3963 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3964 | } |
| 3965 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3966 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3967 | final int top = mTaskHistory.size() - 1; |
| 3968 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 3969 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3970 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3971 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 3972 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3973 | mTaskHistory.remove(taskNdx); |
| 3974 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3975 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3976 | return; |
| 3977 | } |
| 3978 | } |
| 3979 | } |
| 3980 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3981 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3982 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3983 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3984 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3985 | final int numTasks = mTaskHistory.size(); |
| 3986 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3987 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3988 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3989 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3990 | ActivityOptions.abort(options); |
| 3991 | } else { |
| 3992 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 3993 | } |
| 3994 | return; |
| 3995 | } |
| 3996 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3997 | if (timeTracker != null) { |
| 3998 | // The caller wants a time tracker associated with this task. |
| 3999 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4000 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4001 | } |
| 4002 | } |
| 4003 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4004 | // Shift all activities with this task up to the top |
| 4005 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4006 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4007 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4008 | // Don't refocus if invisible to current user |
| 4009 | ActivityRecord top = tr.getTopActivity(); |
| 4010 | if (!okToShowLocked(top)) { |
| 4011 | addRecentActivityLocked(top); |
| 4012 | ActivityOptions.abort(options); |
| 4013 | return; |
| 4014 | } |
| 4015 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4016 | // Set focus to the top running activity of this stack. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4017 | ActivityRecord r = topRunningActivityLocked(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4018 | mService.setFocusedActivityLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4019 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4020 | 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] | 4021 | if (noAnimation) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4022 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4023 | if (r != null) { |
| 4024 | mNoAnimActivities.add(r); |
| 4025 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4026 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4027 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 4028 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4029 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 4030 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4031 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 4032 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4033 | |
| 4034 | if (VALIDATE_TOKENS) { |
| 4035 | validateAppTokensLocked(); |
| 4036 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4040 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4041 | * 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] | 4042 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4043 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4044 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4045 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4046 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4047 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4048 | * @return Returns true if the move completed, false if not. |
| 4049 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4050 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4051 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4052 | if (tr == null) { |
| 4053 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4054 | return false; |
| 4055 | } |
| 4056 | |
| 4057 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4058 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4059 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4060 | // If we have a watcher, preflight the move before committing to it. First check |
| 4061 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4062 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4063 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4064 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4065 | if (next == null) { |
| 4066 | next = topRunningActivityLocked(null, 0); |
| 4067 | } |
| 4068 | if (next != null) { |
| 4069 | // ask watcher if this is allowed |
| 4070 | boolean moveOK = true; |
| 4071 | try { |
| 4072 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4073 | } catch (RemoteException e) { |
| 4074 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4075 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4076 | } |
| 4077 | if (!moveOK) { |
| 4078 | return false; |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4083 | 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] | 4084 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4085 | if (mStackId == HOME_STACK_ID && topTask().isHomeTask()) { |
| 4086 | // For the case where we are moving the home task back and there is an activity visible |
| 4087 | // behind it on the fullscreen stack, we want to move the focus to the visible behind |
| 4088 | // activity to maintain order with what the user is seeing. |
| 4089 | final ActivityStack fullscreenStack = |
| 4090 | mStackSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
| 4091 | if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) { |
| 4092 | final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity(); |
| 4093 | mService.setFocusedActivityLocked(visibleBehind, "moveTaskToBack"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4094 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4095 | return true; |
| 4096 | } |
| 4097 | } |
| 4098 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4099 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4100 | |
| 4101 | // If true, we should resume the home activity next if the task we are moving to the |
| 4102 | // back is over the home stack. We force to false if the task we are moving to back |
| 4103 | // is the home task and we don't want it resumed after moving to the back. |
| 4104 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4105 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4106 | final TaskRecord nextTask = getNextTask(tr); |
| 4107 | if (nextTask != null) { |
| 4108 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4109 | } else { |
| 4110 | prevIsHome = true; |
| 4111 | } |
| 4112 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4113 | mTaskHistory.remove(tr); |
| 4114 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4115 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4116 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4117 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 4118 | // 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] | 4119 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4120 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4121 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4122 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4123 | break; |
| 4124 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4125 | if (taskNdx == 1) { |
| 4126 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4127 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4128 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4129 | } |
| 4130 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4131 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4132 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4133 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4134 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4135 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4138 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4139 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4140 | if (!mService.mBooting && !mService.mBooted) { |
| 4141 | // Not ready yet! |
| 4142 | return false; |
| 4143 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4144 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 4145 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4146 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4147 | } |
| 4148 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4149 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4150 | return true; |
| 4151 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4152 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 4153 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4154 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4155 | final Uri data = r.intent.getData(); |
| 4156 | final String strData = data != null ? data.toSafeString() : null; |
| 4157 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4158 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4159 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4160 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4161 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | /** |
| 4165 | * Make sure the given activity matches the current configuration. Returns |
| 4166 | * false if the activity had to be destroyed. Returns true if the |
| 4167 | * configuration is the same, or the activity will remain running as-is |
| 4168 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 4169 | * correct configuration and all other bookkeeping is handled. |
| 4170 | */ |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4171 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, int globalChanges, |
| 4172 | boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4173 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4174 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4175 | "Skipping config check (will change): " + r); |
| 4176 | return true; |
| 4177 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4178 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4179 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4180 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4181 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4182 | // Short circuit: if the two configurations are the exact same |
| 4183 | // object (the common case), then there is nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4184 | final Configuration newConfig = mService.mConfiguration; |
| 4185 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4186 | if (r.configuration == newConfig |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4187 | && r.taskConfigOverride == taskConfig |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4188 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4189 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4190 | "Configuration unchanged in " + r); |
| 4191 | return true; |
| 4192 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4193 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4194 | // We don't worry about activities that are finishing. |
| 4195 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4196 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4197 | "Configuration doesn't matter in finishing " + r); |
| 4198 | r.stopFreezingScreenLocked(false); |
| 4199 | return true; |
| 4200 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4201 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4202 | // Okay we now are going to make this activity have the new config. |
| 4203 | // 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] | 4204 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4205 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4206 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4207 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4208 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4209 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4210 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4211 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4212 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4213 | "Configuration no differences in " + r); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4214 | // There are no significant differences, so we won't relaunch but should still deliver |
| 4215 | // the new configuration to the client process. |
| 4216 | r.scheduleConfigurationChanged(taskConfig, false); |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4217 | return true; |
| 4218 | } |
| 4219 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 4220 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4221 | "Configuration changes for " + r + " ; taskChanges=" |
| 4222 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 4223 | + Configuration.configurationDiffToString(changes)); |
| 4224 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4225 | // If the activity isn't currently running, just leave the new |
| 4226 | // configuration and it will pick that up next time it starts. |
| 4227 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4228 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4229 | "Configuration doesn't matter not running " + r); |
| 4230 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4231 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4232 | return true; |
| 4233 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4234 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4235 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4236 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4237 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4238 | + Integer.toHexString(changes) + ", handles=0x" |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4239 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig |
| 4240 | + ", taskConfig=" + taskConfig); |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4241 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4242 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4243 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4244 | r.configChangeFlags |= changes; |
| 4245 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4246 | r.forceNewConfig = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4247 | preserveWindow &= isResizeOnlyChange(changes); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4248 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4249 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4250 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4251 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4252 | } else if (r.state == ActivityState.PAUSING) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4253 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 4254 | // 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] | 4255 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4256 | "Config is skipping already pausing " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4257 | r.deferRelaunchUntilPaused = true; |
| 4258 | r.preserveWindowOnDeferredRelaunch = preserveWindow; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4259 | return true; |
| 4260 | } else if (r.state == ActivityState.RESUMED) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4261 | // Try to optimize this case: the configuration is changing and we need to restart |
| 4262 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4263 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4264 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4265 | "Config is relaunching resumed " + r); |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4266 | |
| 4267 | if (DEBUG_STATES && !r.visible) { |
| 4268 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + r |
| 4269 | + " called by " + Debug.getCallers(4)); |
| 4270 | } |
| 4271 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4272 | relaunchActivityLocked(r, r.configChangeFlags, true, preserveWindow); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4273 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4274 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4275 | "Config is relaunching non-resumed " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4276 | relaunchActivityLocked(r, r.configChangeFlags, false, preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4277 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4278 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4279 | // 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] | 4280 | return false; |
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 | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4283 | // 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] | 4284 | // 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] | 4285 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4286 | // system level configuration it last got. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4287 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4288 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4289 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4290 | return true; |
| 4291 | } |
| 4292 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4293 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4294 | Configuration oldTaskOverride) { |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 4295 | |
| 4296 | // If we went from full-screen to non-full-screen, make sure to use the correct |
| 4297 | // configuration task diff, so the diff stays as small as possible. |
| 4298 | if (Configuration.EMPTY.equals(oldTaskOverride) |
| 4299 | && !Configuration.EMPTY.equals(taskConfig)) { |
| 4300 | oldTaskOverride = record.task.extractOverrideConfig(record.configuration); |
| 4301 | } |
| 4302 | |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 4303 | // Conversely, do the same when going the other direction. |
| 4304 | if (Configuration.EMPTY.equals(taskConfig) |
| 4305 | && !Configuration.EMPTY.equals(oldTaskOverride)) { |
| 4306 | taskConfig = record.task.extractOverrideConfig(record.configuration); |
| 4307 | } |
| 4308 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4309 | // Determine what has changed. May be nothing, if this is a config |
| 4310 | // that has come back from the app after going idle. In that case |
| 4311 | // we just want to leave the official config object now in the |
| 4312 | // activity and do nothing else. |
| 4313 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4314 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4315 | // the app. |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4316 | if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4317 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4318 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4319 | || record.crossesVerticalSizeThreshold( |
| 4320 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4321 | if (!crosses) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4322 | taskChanges &= ~CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4323 | } |
| 4324 | } |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4325 | if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4326 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4327 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 4328 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4329 | taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4330 | } |
| 4331 | } |
| 4332 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4333 | } |
| 4334 | |
| 4335 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4336 | Configuration oldTaskOverride, int taskChanges) { |
| 4337 | if (taskChanges == 0) { |
| 4338 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4339 | // Check for changes we care about. |
| 4340 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4341 | taskChanges |= CONFIG_ORIENTATION; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4342 | } |
| 4343 | // We want to explicitly track situations where the size configuration goes from |
| 4344 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4345 | // because there is no threshold. |
| 4346 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4347 | final int newHeight = taskConfig.screenHeightDp; |
| 4348 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4349 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4350 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4351 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4352 | } |
| 4353 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4354 | final int newWidth = taskConfig.screenWidthDp; |
| 4355 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4356 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4357 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4358 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4359 | } |
| 4360 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4361 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4362 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4363 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4364 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4365 | taskChanges |= CONFIG_SMALLEST_SCREEN_SIZE; |
| 4366 | } |
| 4367 | final int oldLayout = oldTaskOverride.screenLayout; |
| 4368 | final int newLayout = taskConfig.screenLayout; |
| 4369 | if ((oldLayout == SCREENLAYOUT_UNDEFINED && newLayout != SCREENLAYOUT_UNDEFINED) |
| 4370 | || (oldLayout != SCREENLAYOUT_UNDEFINED && newLayout == SCREENLAYOUT_UNDEFINED)) { |
| 4371 | taskChanges |= CONFIG_SCREEN_LAYOUT; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4372 | } |
| 4373 | } |
| 4374 | return taskChanges; |
| 4375 | } |
| 4376 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4377 | private static boolean isResizeOnlyChange(int change) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4378 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 4379 | | CONFIG_SCREEN_LAYOUT)) == 0; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4380 | } |
| 4381 | |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4382 | private void relaunchActivityLocked( |
| 4383 | ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) { |
| 4384 | if (mService.mSuppressResizeConfigChanges && preserveWindow) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4385 | r.configChangeFlags = 0; |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4386 | return; |
| 4387 | } |
| 4388 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4389 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4390 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4391 | if (andResume) { |
| 4392 | results = r.results; |
| 4393 | newIntents = r.newIntents; |
| 4394 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4395 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4396 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4397 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4398 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4399 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4400 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4401 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4402 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4403 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4404 | mStackSupervisor.removeChildActivityContainers(r); |
| 4405 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4406 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4407 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 4408 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r |
| 4409 | + " callers=" + Debug.getCallers(6)); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4410 | r.forceNewConfig = false; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4411 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4412 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4413 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4414 | mStackSupervisor.activityRelaunchingLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4415 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4416 | // the caller will only pass in 'andResume' if this activity is |
| 4417 | // currently resumed, which implies we aren't sleeping. |
| 4418 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4419 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | if (andResume) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4423 | if (DEBUG_STATES) { |
| 4424 | Slog.d(TAG_STATES, "Resumed after relaunch " + r); |
| 4425 | } |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4426 | r.state = ActivityState.RESUMED; |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4427 | // Relaunch-resume could happen either when the app is already in the front, |
| 4428 | // or while it's being brought to front. In the latter case, it's marked RESUMED |
| 4429 | // but not yet visible (or stopped). We need to complete the resume here as the |
| 4430 | // code in resumeTopActivityInnerLocked to complete the resume might be skipped. |
| 4431 | if (!r.visible || r.stopped) { |
| 4432 | mWindowManager.setAppVisibility(r.appToken, true); |
| 4433 | completeResumeLocked(r); |
| 4434 | } else { |
| 4435 | r.results = null; |
| 4436 | r.newIntents = null; |
| 4437 | } |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4438 | } else { |
| 4439 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4440 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4441 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4442 | |
| 4443 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4444 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4445 | |
| 4446 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4447 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4448 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4449 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4450 | final ActivityRecord r = activities.get(activityNdx); |
| 4451 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4452 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4453 | } |
| 4454 | if (r.fullscreen && !r.finishing) { |
| 4455 | return false; |
| 4456 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4457 | } |
| 4458 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4459 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4460 | if (r == null) { |
| 4461 | return false; |
| 4462 | } |
| 4463 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4464 | + " would have returned true for r=" + r); |
| 4465 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4469 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4470 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4471 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4472 | final ActivityRecord r = activities.get(activityNdx); |
| 4473 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4474 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4475 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4480 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4481 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4482 | boolean didSomething = false; |
| 4483 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4484 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4485 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4486 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4487 | int numActivities = activities.size(); |
| 4488 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4489 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4490 | final boolean sameComponent = |
| 4491 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4492 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4493 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4494 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4495 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4496 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4497 | if (!doit) { |
| 4498 | if (r.finishing) { |
| 4499 | // If this activity is just finishing, then it is not |
| 4500 | // interesting as far as something to stop. |
| 4501 | continue; |
| 4502 | } |
| 4503 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4504 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4505 | if (r.isHomeActivity()) { |
| 4506 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4507 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4508 | continue; |
| 4509 | } else { |
| 4510 | homeActivity = r.realActivity; |
| 4511 | } |
| 4512 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4513 | didSomething = true; |
| 4514 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4515 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4516 | if (r.app != null) { |
| 4517 | r.app.removed = true; |
| 4518 | } |
| 4519 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4520 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4521 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4522 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4523 | true)) { |
| 4524 | // r has been deleted from mActivities, accommodate. |
| 4525 | --numActivities; |
| 4526 | --activityNdx; |
| 4527 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4528 | } |
| 4529 | } |
| 4530 | } |
| 4531 | return didSomething; |
| 4532 | } |
| 4533 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4534 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4535 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4536 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4537 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4538 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4539 | if (task.getTopActivity() == null) { |
| 4540 | continue; |
| 4541 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4542 | ActivityRecord r = null; |
| 4543 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4544 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4545 | int numActivities = 0; |
| 4546 | int numRunning = 0; |
| 4547 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4548 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4549 | continue; |
| 4550 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4551 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4552 | tmp = activities.get(activityNdx); |
| 4553 | if (tmp.finishing) { |
| 4554 | continue; |
| 4555 | } |
| 4556 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4557 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4558 | // Initialize state for next task if needed. |
| 4559 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4560 | top = r; |
| 4561 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4562 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4563 | |
| 4564 | // Add 'r' into the current task. |
| 4565 | numActivities++; |
| 4566 | if (r.app != null && r.app.thread != null) { |
| 4567 | numRunning++; |
| 4568 | } |
| 4569 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4570 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4571 | TAG, r.intent.getComponent().flattenToShortString() |
| 4572 | + ": task=" + r.task); |
| 4573 | } |
| 4574 | |
| 4575 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4576 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4577 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4578 | ci.baseActivity = r.intent.getComponent(); |
| 4579 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4580 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4581 | if (focusedStack && topTask) { |
| 4582 | // Give the latest time to ensure foreground task can be sorted |
| 4583 | // at the first, because lastActiveTime of creating task is 0. |
| 4584 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4585 | topTask = false; |
| 4586 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4587 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4588 | if (top.task != null) { |
| 4589 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4590 | } |
| 4591 | ci.numActivities = numActivities; |
| 4592 | ci.numRunning = numRunning; |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 4593 | ci.isDockable = task.canGoInDockedStack(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4594 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4595 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4599 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4600 | 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] | 4601 | if (top >= 0) { |
| 4602 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4603 | int activityTop = activities.size() - 1; |
| 4604 | if (activityTop > 0) { |
| 4605 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4606 | "unhandled-back", true); |
| 4607 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4611 | /** |
| 4612 | * Reset local parameters because an app's activity died. |
| 4613 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4614 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4615 | */ |
| 4616 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4617 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4618 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4619 | "App died while pausing: " + mPausingActivity); |
| 4620 | mPausingActivity = null; |
| 4621 | } |
| 4622 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4623 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4624 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4625 | } |
| 4626 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4627 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4630 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4631 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4632 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4633 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4634 | final ActivityRecord r = activities.get(activityNdx); |
| 4635 | if (r.app == app) { |
| 4636 | Slog.w(TAG, " Force finishing activity " |
| 4637 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 4638 | // Force the destroy to skip right to removal. |
| 4639 | r.app = null; |
| 4640 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4641 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4646 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4647 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4648 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4649 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4650 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4651 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 4652 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4653 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 4654 | " Task id #" + task.taskId + "\n" + |
| 4655 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 4656 | " mBounds=" + task.mBounds + "\n" + |
| 4657 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4658 | if (printed) { |
| 4659 | header = null; |
| 4660 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4661 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4662 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 4666 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 4667 | |
| 4668 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4669 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4670 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4671 | } |
| 4672 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4673 | final int top = mTaskHistory.size() - 1; |
| 4674 | if (top >= 0) { |
| 4675 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 4676 | int listTop = list.size() - 1; |
| 4677 | if (listTop >= 0) { |
| 4678 | activities.add(list.get(listTop)); |
| 4679 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4680 | } |
| 4681 | } else { |
| 4682 | ItemMatcher matcher = new ItemMatcher(); |
| 4683 | matcher.build(name); |
| 4684 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4685 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4686 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 4687 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 4688 | activities.add(r1); |
| 4689 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | } |
| 4693 | |
| 4694 | return activities; |
| 4695 | } |
| 4696 | |
| 4697 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4698 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4699 | |
| 4700 | // All activities that came from the package must be |
| 4701 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4702 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4703 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4704 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4705 | final ActivityRecord a = activities.get(activityNdx); |
| 4706 | if (a.info.packageName.equals(packageName)) { |
| 4707 | a.forceNewConfig = true; |
| 4708 | if (starting != null && a == starting && a.visible) { |
| 4709 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4710 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4711 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4712 | } |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | return starting; |
| 4717 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4718 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4719 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4720 | removeTask(task, reason, !MOVING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4721 | } |
| 4722 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4723 | /** |
| 4724 | * Removes the input task from this stack. |
| 4725 | * @param task to remove. |
| 4726 | * @param reason for removal. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4727 | * @param moving task to another stack. In the case we are moving we don't want to perform |
| 4728 | * 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] | 4729 | */ |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4730 | void removeTask(TaskRecord task, String reason, boolean moving) { |
| 4731 | if (!moving) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4732 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4733 | mWindowManager.removeTask(task.taskId); |
Wale Ogunwale | b317b22 | 2015-11-09 11:14:10 -0800 | [diff] [blame] | 4734 | if (!StackId.persistTaskBounds(mStackId)) { |
| 4735 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 4736 | // default configuration the next time it launches. |
| 4737 | task.updateOverrideConfiguration(null); |
| 4738 | } |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4739 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4740 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4741 | final ActivityRecord r = mResumedActivity; |
| 4742 | if (r != null && r.task == task) { |
| 4743 | mResumedActivity = null; |
| 4744 | } |
| 4745 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4746 | final int taskNdx = mTaskHistory.indexOf(task); |
| 4747 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4748 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 4749 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 4750 | if (!nextTask.isOverHomeStack()) { |
| 4751 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 4752 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4753 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4754 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4755 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4756 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4757 | if (!moving && task.mActivities.isEmpty()) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 4758 | // TODO: VI what about activity? |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4759 | final boolean isVoiceSession = task.voiceSession != null; |
| 4760 | if (isVoiceSession) { |
| 4761 | try { |
| 4762 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 4763 | } catch (RemoteException e) { |
| 4764 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4765 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4766 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 4767 | // Task creator asked to remove this when done, or this task was a voice |
| 4768 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 4769 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 4770 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4771 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4772 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4773 | |
| 4774 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4775 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Chong Zhang | a8be5e5 | 2015-10-05 17:06:28 -0700 | [diff] [blame] | 4776 | // 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] | 4777 | if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4778 | String myReason = reason + " leftTaskHistoryEmpty"; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 4779 | if (mFullscreen || !adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4780 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4781 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4782 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 4783 | if (mStacks != null) { |
| 4784 | mStacks.remove(this); |
| 4785 | mStacks.add(0, this); |
| 4786 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 4787 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 4788 | mActivityContainer.onTaskListEmptyLocked(); |
| 4789 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4790 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 4791 | |
| 4792 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4793 | } |
| 4794 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4795 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 4796 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 4797 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4798 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 4799 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4800 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4801 | addTask(task, toTop, "createTaskRecord"); |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 4802 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 4803 | if (!layoutTaskInStack(task, info.layout) && mBounds != null && task.isResizeable() |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 4804 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 4805 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4806 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4807 | return task; |
| 4808 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4809 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 4810 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.Layout layout) { |
| 4811 | if (mTaskPositioner == null) { |
| 4812 | return false; |
| 4813 | } |
| 4814 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, layout); |
| 4815 | return true; |
| 4816 | } |
| 4817 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4818 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4819 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4820 | } |
| 4821 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4822 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
| 4823 | final ActivityStack prevStack = preAddTask(task, reason); |
| 4824 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4825 | task.stack = this; |
| 4826 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4827 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4828 | } else { |
| 4829 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4830 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4831 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4832 | postAddTask(task, prevStack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4833 | } |
| 4834 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4835 | void positionTask(final TaskRecord task, int position) { |
| 4836 | final ActivityStack prevStack = preAddTask(task, "positionTask"); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4837 | task.stack = this; |
| 4838 | insertTaskAtPosition(task, position); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4839 | postAddTask(task, prevStack); |
| 4840 | } |
| 4841 | |
| 4842 | private ActivityStack preAddTask(TaskRecord task, String reason) { |
| 4843 | final ActivityStack prevStack = task.stack; |
| 4844 | if (prevStack != null && prevStack != this) { |
| 4845 | prevStack.removeTask(task, reason, MOVING); |
| 4846 | } |
| 4847 | return prevStack; |
| 4848 | } |
| 4849 | |
| 4850 | private void postAddTask(TaskRecord task, ActivityStack prevStack) { |
| 4851 | if (prevStack != null) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4852 | mStackSupervisor.scheduleReportPictureInPictureChangedIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 4853 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4854 | try { |
| 4855 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4856 | } catch (RemoteException e) { |
| 4857 | } |
| 4858 | } |
| 4859 | } |
| 4860 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4861 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 4862 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 4863 | // TODO: VI deal with activity |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 4864 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 4865 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4866 | (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges, |
| 4867 | task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig, |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 4868 | task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4869 | r.taskConfigOverride = task.mOverrideConfig; |
| 4870 | } |
| 4871 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4872 | void moveToFrontAndResumeStateIfNeeded( |
| 4873 | ActivityRecord r, boolean moveToFront, boolean setResume, String reason) { |
| 4874 | if (!moveToFront) { |
| 4875 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4876 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4877 | |
| 4878 | // If the activity owns the last resumed activity, transfer that together, |
| 4879 | // so that we don't resume the same activity again in the new stack. |
| 4880 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 4881 | if (setResume) { |
| 4882 | mResumedActivity = r; |
| 4883 | } |
| 4884 | // Move the stack in which we are placing the activity to the front. The call will also |
| 4885 | // make sure the activity focus is set. |
| 4886 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | /** |
| 4890 | * Moves the input activity from its current stack to this one. |
| 4891 | * NOTE: The current task of the activity isn't moved to this stack. Instead a new task is |
| 4892 | * created on this stack which the activity is added to. |
| 4893 | * */ |
| 4894 | void moveActivityToStack(ActivityRecord r) { |
| 4895 | final ActivityStack prevStack = r.task.stack; |
| 4896 | if (prevStack.mStackId == mStackId) { |
| 4897 | // You are already in the right stack silly... |
| 4898 | return; |
| 4899 | } |
| 4900 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 4901 | final boolean wasFocused = mStackSupervisor.isFocusedStack(prevStack) |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4902 | && (mStackSupervisor.topRunningActivityLocked() == r); |
| 4903 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 4904 | |
| 4905 | final TaskRecord task = createTaskRecord( |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 4906 | mStackSupervisor.getNextTaskIdForUserLocked(r.userId), |
| 4907 | r.info, r.intent, null, null, true); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4908 | r.setTask(task, null); |
| 4909 | task.addActivityToTop(r); |
| 4910 | setAppTask(r, task); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4911 | mStackSupervisor.scheduleReportPictureInPictureChangedIfNeeded(task, prevStack); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4912 | moveToFrontAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack"); |
| 4913 | if (wasResumed) { |
| 4914 | prevStack.mResumedActivity = null; |
| 4915 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4918 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 4919 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 4920 | mWindowManager.setAppTask(r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig, |
| 4921 | task.mResizeMode, task.isHomeTask()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4922 | r.taskConfigOverride = task.mOverrideConfig; |
| 4923 | } |
| 4924 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4925 | public int getStackId() { |
| 4926 | return mStackId; |
| 4927 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4928 | |
| 4929 | @Override |
| 4930 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 4931 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 4932 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4933 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4934 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4935 | void onLockTaskPackagesUpdatedLocked() { |
| 4936 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4937 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 4938 | } |
| 4939 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4940 | } |