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 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 23 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 24 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 25 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 26 | import static android.app.ActivityManager.StackId.RECENTS_STACK_ID; |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 27 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
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 | f5d1e35 | 2016-09-22 08:34:42 -0700 | [diff] [blame] | 30 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 31 | import static android.view.Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 32 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 33 | import static android.view.Display.INVALID_DISPLAY; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 34 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 35 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
| 36 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_APP; |
| 37 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CLEANUP; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 38 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 39 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 40 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 41 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RESULTS; |
| 42 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 43 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 44 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 45 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 46 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
| 47 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TRANSITION; |
| 48 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_USER_LEAVING; |
| 49 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY; |
| 50 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 51 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_APP; |
| 52 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CLEANUP; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 53 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS; |
| 54 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 55 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 56 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RESULTS; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 58 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 59 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 61 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TRANSITION; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_USER_LEAVING; |
| 64 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY; |
| 65 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 66 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 67 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 68 | import static com.android.server.am.ActivityRecord.ASSISTANT_ACTIVITY_TYPE; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 69 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 70 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 71 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 72 | import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; |
Winson Chung | 7c3ede3 | 2017-03-14 14:18:34 -0700 | [diff] [blame] | 73 | import static com.android.server.am.ActivityStackSupervisor.ON_TOP; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 74 | import static com.android.server.am.ActivityStackSupervisor.PAUSE_IMMEDIATELY; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 75 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 76 | import static com.android.server.am.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 77 | import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_CLOSE; |
| 78 | import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN; |
| 79 | import static com.android.server.wm.AppTransition.TRANSIT_NONE; |
| 80 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_CLOSE; |
| 81 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN; |
| 82 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN_BEHIND; |
| 83 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_TO_BACK; |
| 84 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_TO_FRONT; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 85 | import static java.lang.Integer.MAX_VALUE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 86 | |
| 87 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 88 | import android.app.ActivityManager; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 89 | import android.app.ActivityManager.RunningTaskInfo; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 90 | import android.app.ActivityManager.StackId; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 91 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 92 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 93 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 94 | import android.app.ResultInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 95 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 96 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 97 | import android.content.pm.ActivityInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 98 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 99 | import android.content.res.Configuration; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 100 | import android.graphics.Point; |
| 101 | import android.graphics.Rect; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 102 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 103 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 104 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 105 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 106 | import android.os.Handler; |
| 107 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 108 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 109 | import android.os.Message; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 110 | import android.os.RemoteException; |
| 111 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 112 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 113 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 114 | import android.service.voice.IVoiceInteractionSession; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 115 | import android.util.ArraySet; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 116 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 117 | import android.util.IntArray; |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 119 | import android.util.Slog; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 120 | import android.util.SparseArray; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 121 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 122 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 123 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 124 | import com.android.internal.app.IVoiceInteractor; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 125 | import com.android.internal.os.BatteryStatsImpl; |
| 126 | import com.android.server.Watchdog; |
| 127 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 128 | import com.android.server.wm.StackWindowController; |
| 129 | import com.android.server.wm.StackWindowListener; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 130 | import com.android.server.wm.WindowManagerService; |
| 131 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 132 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 133 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 134 | import java.lang.ref.WeakReference; |
| 135 | import java.util.ArrayList; |
| 136 | import java.util.Iterator; |
| 137 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 138 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 139 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * State and management of a single stack of activities. |
| 143 | */ |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 144 | class ActivityStack<T extends StackWindowController> extends ConfigurationContainer |
| 145 | implements StackWindowListener { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 146 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 147 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 148 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 149 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 150 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 151 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 152 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 153 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 154 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 155 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 156 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 157 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 158 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 159 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 160 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 161 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 162 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 163 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 164 | // Ticks during which we check progress while waiting for an app to launch. |
| 165 | static final int LAUNCH_TICK = 500; |
| 166 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 167 | // How long we wait until giving up on the last activity to pause. This |
| 168 | // is short because it directly impacts the responsiveness of starting the |
| 169 | // next activity. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 170 | private static final int PAUSE_TIMEOUT = 500; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 171 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 172 | // How long we wait for the activity to tell us it has stopped before |
| 173 | // giving up. This is a good amount of time because we really need this |
| 174 | // from the application in order to get its saved state. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 175 | private static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 176 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 177 | // How long we wait until giving up on an activity telling us it has |
| 178 | // finished destroying itself. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 179 | private static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 180 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 181 | // 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] | 182 | // disabled. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 183 | private static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 184 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 185 | // Set to false to disable the preview that is shown while a new activity |
| 186 | // is being started. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 187 | private static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 188 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 189 | // How long to wait for all background Activities to redraw following a call to |
| 190 | // convertToTranslucent(). |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 191 | private static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 192 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 193 | // How many activities have to be scheduled to stop to force a stop pass. |
| 194 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 195 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 196 | @Override |
| 197 | protected int getChildCount() { |
| 198 | return mTaskHistory.size(); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | protected ConfigurationContainer getChildAt(int index) { |
| 203 | return mTaskHistory.get(index); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | protected ConfigurationContainer getParent() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 208 | return getDisplay(); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 211 | @Override |
| 212 | void onParentChanged() { |
| 213 | super.onParentChanged(); |
| 214 | mStackSupervisor.updateUIDsPresentOnDisplay(); |
| 215 | } |
| 216 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 217 | enum ActivityState { |
| 218 | INITIALIZING, |
| 219 | RESUMED, |
| 220 | PAUSING, |
| 221 | PAUSED, |
| 222 | STOPPING, |
| 223 | STOPPED, |
| 224 | FINISHING, |
| 225 | DESTROYING, |
| 226 | DESTROYED |
| 227 | } |
| 228 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 229 | // Stack is not considered visible. |
| 230 | static final int STACK_INVISIBLE = 0; |
| 231 | // Stack is considered visible |
| 232 | static final int STACK_VISIBLE = 1; |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 233 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 234 | @VisibleForTesting |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 235 | /* The various modes for the method {@link #removeTask}. */ |
| 236 | // Task is being completely removed from all stacks in the system. |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 237 | protected static final int REMOVE_TASK_MODE_DESTROYING = 0; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 238 | // Task is being removed from this stack so we can add it to another stack. In the case we are |
| 239 | // moving we don't want to perform some operations on the task like removing it from window |
| 240 | // manager or recents. |
| 241 | static final int REMOVE_TASK_MODE_MOVING = 1; |
| 242 | // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new |
| 243 | // stack and the new stack will be on top of all stacks. |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 244 | static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 245 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 246 | // The height/width divide used when fitting a task within a bounds with method |
| 247 | // {@link #fitWithinBounds}. |
| 248 | // We always want the task to to be visible in the bounds without affecting its size when |
| 249 | // fitting. To make sure this is the case, we don't adjust the task left or top side pass |
| 250 | // the input bounds right or bottom side minus the width or height divided by this value. |
| 251 | private static final int FIT_WITHIN_BOUNDS_DIVIDER = 3; |
| 252 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 253 | final ActivityManagerService mService; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 254 | private final WindowManagerService mWindowManager; |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 255 | T mWindowContainerController; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 256 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 257 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 258 | /** |
| 259 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 260 | * running) activities. It contains #TaskRecord objects. |
| 261 | */ |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 262 | private final ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 263 | |
| 264 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 265 | * List of running activities, sorted by recent usage. |
| 266 | * The first entry in the list is the least recently used. |
| 267 | * It contains HistoryRecord objects. |
| 268 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 269 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 272 | * Animations that for the current transition have requested not to |
| 273 | * be considered for the transition animation. |
| 274 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 275 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 276 | |
| 277 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 278 | * When we are in the process of pausing an activity, before starting the |
| 279 | * next one, this variable holds the activity that is currently being paused. |
| 280 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 281 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * This is the last activity that we put into the paused state. This is |
| 285 | * used to determine if we need to do an activity transition while sleeping, |
| 286 | * when we normally hold the top activity paused. |
| 287 | */ |
| 288 | ActivityRecord mLastPausedActivity = null; |
| 289 | |
| 290 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 291 | * Activities that specify No History must be removed once the user navigates away from them. |
| 292 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 293 | * and finish it later if another activity replaces it on wakeup. |
| 294 | */ |
| 295 | ActivityRecord mLastNoHistoryActivity = null; |
| 296 | |
| 297 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 298 | * Current activity that is resumed, or null if there is none. |
| 299 | */ |
| 300 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 301 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 302 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 303 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 304 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 305 | // Activity in mTranslucentActivityWaiting is notified via |
| 306 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 307 | // background activity being drawn then the same call will be made with a true value. |
| 308 | ActivityRecord mTranslucentActivityWaiting = null; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 309 | ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 310 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 311 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 312 | * Set when we know we are going to be calling updateConfiguration() |
| 313 | * soon, so want to skip intermediate config checks. |
| 314 | */ |
| 315 | boolean mConfigWillChange; |
| 316 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 317 | /** |
| 318 | * When set, will force the stack to report as invisible. |
| 319 | */ |
| 320 | boolean mForceHidden = false; |
| 321 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 322 | // 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] | 323 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 324 | // Current bounds of the stack or null if fullscreen. |
| 325 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 326 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 327 | private boolean mUpdateBoundsDeferred; |
| 328 | private boolean mUpdateBoundsDeferredCalled; |
| 329 | private final Rect mDeferredBounds = new Rect(); |
| 330 | private final Rect mDeferredTaskBounds = new Rect(); |
| 331 | private final Rect mDeferredTaskInsetBounds = new Rect(); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 332 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 333 | long mLaunchStartTime = 0; |
| 334 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 335 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 336 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 337 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 338 | final int mStackId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 339 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 340 | // TODO: This list doesn't belong here... |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 341 | ArrayList<ActivityStack> mStacks; |
| 342 | /** The attached Display's unique identifier, or -1 if detached */ |
| 343 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 344 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 345 | /** Temp variables used during override configuration update. */ |
| 346 | private final SparseArray<Configuration> mTmpConfigs = new SparseArray<>(); |
| 347 | private final SparseArray<Rect> mTmpBounds = new SparseArray<>(); |
| 348 | private final SparseArray<Rect> mTmpInsetBounds = new SparseArray<>(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 349 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 350 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 351 | /** Run all ActivityStacks through this */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 352 | protected final ActivityStackSupervisor mStackSupervisor; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 353 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 354 | private final LaunchingTaskPositioner mTaskPositioner; |
| 355 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 356 | private boolean mTopActivityOccludesKeyguard; |
| 357 | private ActivityRecord mTopDismissingKeyguardActivity; |
| 358 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 359 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 360 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 361 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 362 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 363 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 364 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 365 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 366 | private static class ScheduleDestroyArgs { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 367 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 368 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 369 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 370 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 371 | mReason = reason; |
| 372 | } |
| 373 | } |
| 374 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 375 | final Handler mHandler; |
| 376 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 377 | private class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 378 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 379 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 380 | super(looper); |
| 381 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 382 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 383 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 384 | public void handleMessage(Message msg) { |
| 385 | switch (msg.what) { |
| 386 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 387 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 388 | // We don't at this point know if the activity is fullscreen, |
| 389 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 390 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 391 | synchronized (mService) { |
| 392 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 393 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 394 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 395 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 396 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 397 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 398 | case LAUNCH_TICK_MSG: { |
| 399 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 400 | synchronized (mService) { |
| 401 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 402 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 406 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 407 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 408 | // We don't at this point know if the activity is fullscreen, |
| 409 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 410 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 411 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 412 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 413 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 414 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 415 | case STOP_TIMEOUT_MSG: { |
| 416 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 417 | // We don't at this point know if the activity is fullscreen, |
| 418 | // so we need to be conservative and assume it isn't. |
| 419 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 420 | synchronized (mService) { |
| 421 | if (r.isInHistory()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 422 | r.activityStoppedLocked(null /* icicle */, |
| 423 | null /* persistentState */, null /* description */); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 427 | case DESTROY_ACTIVITIES_MSG: { |
| 428 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 429 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 430 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 431 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 432 | } break; |
| 433 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 434 | synchronized (mService) { |
| 435 | notifyActivityDrawnLocked(null); |
| 436 | } |
| 437 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 438 | } |
| 439 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 442 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 443 | int count = 0; |
| 444 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 445 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 446 | } |
| 447 | return count; |
| 448 | } |
| 449 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 450 | ActivityStack(ActivityStackSupervisor.ActivityDisplay display, int stackId, |
| 451 | ActivityStackSupervisor supervisor, RecentTasks recentTasks, boolean onTop) { |
| 452 | mStackSupervisor = supervisor; |
| 453 | mService = supervisor.mService; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 454 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 455 | mWindowManager = mService.mWindowManager; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 456 | mStackId = stackId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 457 | mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 458 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 459 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 460 | ? new LaunchingTaskPositioner() : null; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 461 | mTmpRect2.setEmpty(); |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 462 | mWindowContainerController = createStackWindowController(display.mDisplayId, onTop, |
| 463 | mTmpRect2); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 464 | mStackSupervisor.mStacks.put(mStackId, this); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 465 | postAddToDisplay(display, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop); |
| 466 | } |
| 467 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 468 | T createStackWindowController(int displayId, boolean onTop, Rect outBounds) { |
| 469 | return (T) new StackWindowController(mStackId, this, displayId, onTop, outBounds); |
| 470 | } |
| 471 | |
| 472 | T getWindowContainerController() { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 473 | return mWindowContainerController; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 476 | /** Adds the stack to specified display and calls WindowManager to do the same. */ |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 477 | void reparent(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 478 | removeFromDisplay(); |
| 479 | mTmpRect2.setEmpty(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 480 | postAddToDisplay(activityDisplay, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 481 | adjustFocusToNextFocusableStackLocked("reparent", true /* allowFocusSelf */); |
| 482 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 483 | // Update visibility of activities before notifying WM. This way it won't try to resize |
| 484 | // windows that are no longer visible. |
| 485 | mStackSupervisor.ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 486 | !PRESERVE_WINDOWS); |
| 487 | mWindowContainerController.reparent(activityDisplay.mDisplayId, mTmpRect2, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Updates internal state after adding to new display. |
| 492 | * @param activityDisplay New display to which this stack was attached. |
| 493 | * @param bounds Updated bounds. |
| 494 | */ |
| 495 | private void postAddToDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 496 | Rect bounds, boolean onTop) { |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 497 | mDisplayId = activityDisplay.mDisplayId; |
| 498 | mStacks = activityDisplay.mStacks; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 499 | mBounds = bounds != null ? new Rect(bounds) : null; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 500 | mFullscreen = mBounds == null; |
| 501 | if (mTaskPositioner != null) { |
| 502 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 503 | mTaskPositioner.configure(mBounds); |
| 504 | } |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 505 | onParentChanged(); |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 506 | |
Winson Chung | 7c3ede3 | 2017-03-14 14:18:34 -0700 | [diff] [blame] | 507 | activityDisplay.attachStack(this, findStackInsertIndex(onTop)); |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 508 | if (mStackId == DOCKED_STACK_ID) { |
| 509 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 510 | // in the system. |
| 511 | mStackSupervisor.resizeDockedStackLocked( |
| 512 | mBounds, null, null, null, null, PRESERVE_WINDOWS); |
| 513 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 516 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 517 | * Updates the inner state of the stack to remove it from its current parent, so it can be |
| 518 | * either destroyed completely or re-parented. |
| 519 | */ |
| 520 | private void removeFromDisplay() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 521 | final ActivityStackSupervisor.ActivityDisplay display = getDisplay(); |
| 522 | if (display != null) { |
| 523 | display.detachStack(this); |
| 524 | } |
| 525 | mDisplayId = INVALID_DISPLAY; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 526 | mStacks = null; |
| 527 | if (mTaskPositioner != null) { |
| 528 | mTaskPositioner.reset(); |
| 529 | } |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 530 | if (mStackId == DOCKED_STACK_ID) { |
| 531 | // If we removed a docked stack we want to resize it so it resizes all other stacks |
| 532 | // in the system to fullscreen. |
| 533 | mStackSupervisor.resizeDockedStackLocked( |
| 534 | null, null, null, null, null, PRESERVE_WINDOWS); |
| 535 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /** Removes the stack completely. Also calls WindowManager to do the same on its side. */ |
| 539 | void remove() { |
| 540 | removeFromDisplay(); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 541 | mStackSupervisor.mStacks.remove(mStackId); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 542 | mWindowContainerController.removeContainer(); |
| 543 | mWindowContainerController = null; |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 544 | onParentChanged(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 547 | ActivityStackSupervisor.ActivityDisplay getDisplay() { |
| 548 | return mStackSupervisor.getActivityDisplay(mDisplayId); |
| 549 | } |
| 550 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 551 | void getDisplaySize(Point out) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 552 | getDisplay().mDisplay.getSize(out); |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 555 | /** |
| 556 | * @see ActivityStack.getStackDockedModeBounds(Rect, Rect, Rect, boolean) |
| 557 | */ |
| 558 | void getStackDockedModeBounds(Rect currentTempTaskBounds, Rect outStackBounds, |
| 559 | Rect outTempTaskBounds, boolean ignoreVisibility) { |
| 560 | mWindowContainerController.getStackDockedModeBounds(currentTempTaskBounds, |
| 561 | outStackBounds, outTempTaskBounds, ignoreVisibility); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | void prepareFreezingTaskBounds() { |
| 565 | mWindowContainerController.prepareFreezingTaskBounds(); |
| 566 | } |
| 567 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 568 | void getWindowContainerBounds(Rect outBounds) { |
| 569 | if (mWindowContainerController != null) { |
| 570 | mWindowContainerController.getBounds(outBounds); |
Winson Chung | b00dc5e | 2017-01-25 09:44:25 -0800 | [diff] [blame] | 571 | return; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 572 | } |
| 573 | outBounds.setEmpty(); |
| 574 | } |
| 575 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 576 | void getBoundsForNewConfiguration(Rect outBounds) { |
| 577 | mWindowContainerController.getBoundsForNewConfiguration(outBounds); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | void positionChildWindowContainerAtTop(TaskRecord child) { |
| 581 | mWindowContainerController.positionChildAtTop(child.getWindowContainerController(), |
| 582 | true /* includingParents */); |
| 583 | } |
| 584 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 585 | /** |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 586 | * Returns whether to defer the scheduling of the multi-window mode. |
| 587 | */ |
| 588 | boolean deferScheduleMultiWindowModeChanged() { |
| 589 | return false; |
| 590 | } |
| 591 | |
| 592 | /** |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 593 | * Defers updating the bounds of the stack. If the stack was resized/repositioned while |
| 594 | * deferring, the bounds will update in {@link #continueUpdateBounds()}. |
| 595 | */ |
| 596 | void deferUpdateBounds() { |
| 597 | if (!mUpdateBoundsDeferred) { |
| 598 | mUpdateBoundsDeferred = true; |
| 599 | mUpdateBoundsDeferredCalled = false; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Continues updating bounds after updates have been deferred. If there was a resize attempt |
| 605 | * between {@link #deferUpdateBounds()} and {@link #continueUpdateBounds()}, the stack will |
| 606 | * be resized to that bounds. |
| 607 | */ |
| 608 | void continueUpdateBounds() { |
| 609 | final boolean wasDeferred = mUpdateBoundsDeferred; |
| 610 | mUpdateBoundsDeferred = false; |
| 611 | if (wasDeferred && mUpdateBoundsDeferredCalled) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 612 | resize(mDeferredBounds.isEmpty() ? null : mDeferredBounds, |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 613 | mDeferredTaskBounds.isEmpty() ? null : mDeferredTaskBounds, |
| 614 | mDeferredTaskInsetBounds.isEmpty() ? null : mDeferredTaskInsetBounds); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | boolean updateBoundsAllowed(Rect bounds, Rect tempTaskBounds, |
| 619 | Rect tempTaskInsetBounds) { |
| 620 | if (!mUpdateBoundsDeferred) { |
| 621 | return true; |
| 622 | } |
| 623 | if (bounds != null) { |
| 624 | mDeferredBounds.set(bounds); |
| 625 | } else { |
| 626 | mDeferredBounds.setEmpty(); |
| 627 | } |
| 628 | if (tempTaskBounds != null) { |
| 629 | mDeferredTaskBounds.set(tempTaskBounds); |
| 630 | } else { |
| 631 | mDeferredTaskBounds.setEmpty(); |
| 632 | } |
| 633 | if (tempTaskInsetBounds != null) { |
| 634 | mDeferredTaskInsetBounds.set(tempTaskInsetBounds); |
| 635 | } else { |
| 636 | mDeferredTaskInsetBounds.setEmpty(); |
| 637 | } |
| 638 | mUpdateBoundsDeferredCalled = true; |
| 639 | return false; |
| 640 | } |
| 641 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 642 | void setBounds(Rect bounds) { |
| 643 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 644 | if (mTaskPositioner != null) { |
| 645 | mTaskPositioner.configure(bounds); |
| 646 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 647 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 648 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 649 | ActivityRecord topRunningActivityLocked() { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 650 | return topRunningActivityLocked(false /* focusableOnly */); |
| 651 | } |
| 652 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 653 | void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) { |
| 654 | outActivities.clear(); |
| 655 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 656 | mTaskHistory.get(taskNdx).getAllRunningVisibleActivitiesLocked(outActivities); |
| 657 | } |
| 658 | } |
| 659 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 660 | private ActivityRecord topRunningActivityLocked(boolean focusableOnly) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 661 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 662 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 663 | if (r != null && (!focusableOnly || r.isFocusable())) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 664 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 665 | } |
| 666 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 667 | return null; |
| 668 | } |
| 669 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 670 | ActivityRecord topRunningNonOverlayTaskActivity() { |
| 671 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 672 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 673 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 674 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 675 | final ActivityRecord r = activities.get(activityNdx); |
| 676 | if (!r.finishing && !r.mTaskOverlay) { |
| 677 | return r; |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | return null; |
| 682 | } |
| 683 | |
| 684 | ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 685 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 686 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 687 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 688 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 689 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 690 | if (!r.finishing && !r.delayedResume && r != notTop && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 691 | return r; |
| 692 | } |
| 693 | } |
| 694 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 695 | return null; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 700 | * 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] | 701 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 702 | * @param token If non-null, any history records matching this token will be skipped. |
| 703 | * @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] | 704 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 705 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 706 | */ |
| 707 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 708 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 709 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 710 | if (task.taskId == taskId) { |
| 711 | continue; |
| 712 | } |
| 713 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 714 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 715 | final ActivityRecord r = activities.get(i); |
| 716 | // Note: the taskId check depends on real taskId fields being non-zero |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 717 | if (!r.finishing && (token != r.appToken) && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 718 | return r; |
| 719 | } |
| 720 | } |
| 721 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 722 | return null; |
| 723 | } |
| 724 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 725 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 726 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 727 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 728 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 729 | final ActivityRecord r = activities.get(activityNdx); |
| 730 | if (!r.finishing) { |
| 731 | return r; |
| 732 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 733 | } |
| 734 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 735 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 738 | final TaskRecord topTask() { |
| 739 | final int size = mTaskHistory.size(); |
| 740 | if (size > 0) { |
| 741 | return mTaskHistory.get(size - 1); |
| 742 | } |
| 743 | return null; |
| 744 | } |
| 745 | |
Winson Chung | 1cebea6 | 2017-06-26 17:22:27 -0700 | [diff] [blame] | 746 | final TaskRecord bottomTask() { |
| 747 | if (mTaskHistory.isEmpty()) { |
| 748 | return null; |
| 749 | } |
| 750 | return mTaskHistory.get(0); |
| 751 | } |
| 752 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 753 | TaskRecord taskForIdLocked(int id) { |
| 754 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 755 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 756 | if (task.taskId == id) { |
| 757 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 758 | } |
| 759 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 760 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 763 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 764 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 765 | return isInStackLocked(r); |
| 766 | } |
| 767 | |
| 768 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 769 | if (r == null) { |
| 770 | return null; |
| 771 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 772 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 773 | final ActivityStack stack = r.getStack(); |
| 774 | if (stack != null && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
| 775 | if (stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 776 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 777 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 778 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 779 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 782 | boolean isInStackLocked(TaskRecord task) { |
| 783 | return mTaskHistory.contains(task); |
| 784 | } |
| 785 | |
| 786 | /** Checks if there are tasks with specific UID in the stack. */ |
| 787 | boolean isUidPresent(int uid) { |
| 788 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 789 | for (ActivityRecord r : task.mActivities) { |
| 790 | if (r.getUid() == uid) { |
| 791 | return true; |
| 792 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | return false; |
| 796 | } |
| 797 | |
| 798 | /** Get all UIDs that are present in the stack. */ |
| 799 | void getPresentUIDs(IntArray presentUIDs) { |
| 800 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 801 | for (ActivityRecord r : task.mActivities) { |
| 802 | presentUIDs.add(r.getUid()); |
| 803 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 807 | final void removeActivitiesFromLRUListLocked(TaskRecord task) { |
| 808 | for (ActivityRecord r : task.mActivities) { |
| 809 | mLRUActivities.remove(r); |
| 810 | } |
| 811 | } |
| 812 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 813 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 814 | final boolean hadit = mLRUActivities.remove(r); |
| 815 | mLRUActivities.add(r); |
| 816 | return hadit; |
| 817 | } |
| 818 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 819 | final boolean isHomeStack() { |
| 820 | return mStackId == HOME_STACK_ID; |
| 821 | } |
| 822 | |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 823 | final boolean isRecentsStack() { |
| 824 | return mStackId == RECENTS_STACK_ID; |
| 825 | } |
| 826 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 827 | final boolean isHomeOrRecentsStack() { |
| 828 | return StackId.isHomeOrRecentsStack(mStackId); |
| 829 | } |
| 830 | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 831 | final boolean isDockedStack() { |
| 832 | return mStackId == DOCKED_STACK_ID; |
| 833 | } |
| 834 | |
| 835 | final boolean isPinnedStack() { |
| 836 | return mStackId == PINNED_STACK_ID; |
| 837 | } |
| 838 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 839 | final boolean isAssistantStack() { |
| 840 | return mStackId == ASSISTANT_STACK_ID; |
| 841 | } |
| 842 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 843 | final boolean isOnHomeDisplay() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 844 | return isAttached() && mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 847 | void moveToFront(String reason) { |
| 848 | moveToFront(reason, null); |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * @param reason The reason for moving the stack to the front. |
| 853 | * @param task If non-null, the task will be moved to the top of the stack. |
| 854 | * */ |
| 855 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 856 | if (!isAttached()) { |
| 857 | return; |
| 858 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 859 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 860 | mStacks.remove(this); |
Winson Chung | 7c3ede3 | 2017-03-14 14:18:34 -0700 | [diff] [blame] | 861 | mStacks.add(findStackInsertIndex(ON_TOP), this); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 862 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 863 | if (task != null) { |
| 864 | insertTaskAtTop(task, null); |
Wale Ogunwale | aa47c12 | 2016-09-23 16:39:53 -0700 | [diff] [blame] | 865 | return; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 866 | } |
Wale Ogunwale | aa47c12 | 2016-09-23 16:39:53 -0700 | [diff] [blame] | 867 | |
| 868 | task = topTask(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 869 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 870 | mWindowContainerController.positionChildAtTop(task.getWindowContainerController(), |
| 871 | true /* includingParents */); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 872 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 875 | /** |
| 876 | * @param task If non-null, the task will be moved to the back of the stack. |
| 877 | * */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 878 | private void moveToBack(TaskRecord task) { |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 879 | if (!isAttached()) { |
| 880 | return; |
| 881 | } |
| 882 | |
| 883 | mStacks.remove(this); |
| 884 | mStacks.add(0, this); |
| 885 | |
| 886 | if (task != null) { |
| 887 | mTaskHistory.remove(task); |
| 888 | mTaskHistory.add(0, task); |
| 889 | updateTaskMovement(task, false); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 890 | mWindowContainerController.positionChildAtBottom(task.getWindowContainerController()); |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Winson Chung | 7c3ede3 | 2017-03-14 14:18:34 -0700 | [diff] [blame] | 894 | /** |
| 895 | * @return the index to insert a new stack into, taking the always-on-top stacks into account. |
| 896 | */ |
| 897 | private int findStackInsertIndex(boolean onTop) { |
| 898 | if (onTop) { |
| 899 | int addIndex = mStacks.size(); |
| 900 | if (addIndex > 0) { |
| 901 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
| 902 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 903 | // If the top stack is always on top, we move this stack just below it. |
| 904 | addIndex--; |
| 905 | } |
| 906 | } |
| 907 | return addIndex; |
| 908 | } else { |
| 909 | return 0; |
| 910 | } |
| 911 | } |
| 912 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 913 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 914 | if (StackId.canReceiveKeys(mStackId)) { |
| 915 | return true; |
| 916 | } |
| 917 | // The stack isn't focusable. See if its top activity is focusable to force focus on the |
| 918 | // stack. |
| 919 | final ActivityRecord r = topRunningActivityLocked(); |
| 920 | return r != null && r.isFocusable(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 921 | } |
| 922 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 923 | final boolean isAttached() { |
| 924 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 925 | } |
| 926 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 927 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 928 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 929 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 930 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 931 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 932 | Intent intent = target.intent; |
| 933 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 934 | ComponentName cls = intent.getComponent(); |
| 935 | if (info.targetActivity != null) { |
| 936 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 937 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 938 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 939 | boolean isDocument = intent != null & intent.isDocument(); |
| 940 | // If documentData is non-null then it must match the existing task data. |
| 941 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 942 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 943 | 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] | 944 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 945 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 946 | if (task.voiceSession != null) { |
| 947 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 948 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 949 | continue; |
| 950 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 951 | if (task.userId != userId) { |
| 952 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 953 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 954 | continue; |
| 955 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 956 | final ActivityRecord r = task.getTopActivity(); |
| 957 | if (r == null || r.finishing || r.userId != userId || |
| 958 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 959 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 960 | continue; |
| 961 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 962 | if (r.mActivityType != target.mActivityType) { |
| 963 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 964 | continue; |
| 965 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 966 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 967 | final Intent taskIntent = task.intent; |
| 968 | final Intent affinityIntent = task.affinityIntent; |
| 969 | final boolean taskIsDocument; |
| 970 | final Uri taskDocumentData; |
| 971 | if (taskIntent != null && taskIntent.isDocument()) { |
| 972 | taskIsDocument = true; |
| 973 | taskDocumentData = taskIntent.getData(); |
| 974 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 975 | taskIsDocument = true; |
| 976 | taskDocumentData = affinityIntent.getData(); |
| 977 | } else { |
| 978 | taskIsDocument = false; |
| 979 | taskDocumentData = null; |
| 980 | } |
| 981 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 982 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 983 | + taskIntent.getComponent().flattenToShortString() |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 984 | + "/aff=" + r.getTask().rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 985 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 986 | // TODO Refactor to remove duplications. Check if logic can be simplified. |
| 987 | if (taskIntent != null && taskIntent.getComponent() != null && |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 988 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 989 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 990 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 991 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 992 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 993 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 994 | result.r = r; |
| 995 | result.matchedByRootAffinity = false; |
| 996 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 997 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 998 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 999 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1000 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1001 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1002 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 1003 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1004 | result.r = r; |
| 1005 | result.matchedByRootAffinity = false; |
| 1006 | break; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1007 | } else if (!isDocument && !taskIsDocument |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 1008 | && result.r == null && task.rootAffinity != null) { |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1009 | if (task.rootAffinity.equals(target.taskAffinity)) { |
| 1010 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 1011 | // It is possible for multiple tasks to have the same root affinity especially |
| 1012 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 1013 | // to see if there is a better candidate. |
| 1014 | result.r = r; |
| 1015 | result.matchedByRootAffinity = true; |
| 1016 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1017 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1018 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * Returns the first activity (starting from the top of the stack) that |
| 1023 | * is the same as the given activity. Returns null if no such activity |
| 1024 | * is found. |
| 1025 | */ |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1026 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 1027 | boolean compareIntentFilters) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1028 | ComponentName cls = intent.getComponent(); |
| 1029 | if (info.targetActivity != null) { |
| 1030 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 1031 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1032 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1033 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1034 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1035 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1036 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1037 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1038 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1039 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1040 | if (!r.okToShowLocked()) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 1041 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1042 | } |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1043 | if (!r.finishing && r.userId == userId) { |
| 1044 | if (compareIntentFilters) { |
| 1045 | if (r.intent.filterEquals(intent)) { |
| 1046 | return r; |
| 1047 | } |
| 1048 | } else { |
| 1049 | if (r.intent.getComponent().equals(cls)) { |
| 1050 | return r; |
| 1051 | } |
| 1052 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | return null; |
| 1058 | } |
| 1059 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1060 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1061 | * 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] | 1062 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1063 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1064 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1065 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1066 | } |
| 1067 | mCurrentUser = userId; |
| 1068 | |
| 1069 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1070 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1071 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1072 | final TaskRecord task = mTaskHistory.get(i); |
| 1073 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1074 | if (task.okToShowLocked()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1075 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 1076 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1077 | mTaskHistory.remove(i); |
| 1078 | mTaskHistory.add(task); |
| 1079 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1080 | // Use same value for i. |
| 1081 | } else { |
| 1082 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1083 | } |
| 1084 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1087 | void minimalResumeActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1088 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 1089 | + " callers=" + Debug.getCallers(5)); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 1090 | setResumedActivityLocked(r, "minimalResumeActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1091 | r.completeResumeLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 1092 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1093 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 1094 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 1097 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 1098 | if (r != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1099 | final TaskRecord task = r.getTask(); |
| 1100 | mRecentTasks.addLocked(task); |
| 1101 | task.touchActiveTime(); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 1105 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 1106 | if (mFullyDrawnStartTime != 0) { |
| 1107 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 1108 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 1109 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 1110 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 1111 | } |
| 1112 | |
| 1113 | private void stopFullyDrawnTraceIfNeeded() { |
| 1114 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 1115 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 1116 | mFullyDrawnStartTime = 0; |
| 1117 | } |
| 1118 | } |
| 1119 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1120 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1121 | if (r.displayStartTime == 0) { |
| 1122 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 1123 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 1124 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1125 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1126 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1127 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 1128 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1129 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1130 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1131 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1132 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1133 | private void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 1134 | // Make sure that there is no activity waiting for this to launch. |
| 1135 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 1136 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 1137 | } else { |
| 1138 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 1139 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1140 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1143 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1144 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1145 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1146 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1147 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1148 | activities.get(activityNdx).setSleeping(false); |
| 1149 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1150 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 1151 | if (mPausingActivity != null) { |
| 1152 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 1153 | activityPausedLocked(mPausingActivity.appToken, true); |
| 1154 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1155 | } |
| 1156 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1157 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 1158 | final String packageName = aInfo.packageName; |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1159 | final int userId = UserHandle.getUserId(aInfo.uid); |
| 1160 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1161 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1162 | final List<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1163 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1164 | final ActivityRecord ar = activities.get(activityNdx); |
| 1165 | |
| 1166 | if ((userId == ar.userId) && packageName.equals(ar.packageName)) { |
| 1167 | ar.info.applicationInfo = aInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1173 | void checkReadyForSleep() { |
| 1174 | if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) { |
| 1175 | mStackSupervisor.checkReadyForSleepLocked(true /* allowDelay */); |
| 1176 | } |
| 1177 | } |
| 1178 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1179 | /** |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1180 | * Tries to put the activities in the stack to sleep. |
| 1181 | * |
| 1182 | * If the stack is not in a state where its activities can be put to sleep, this function will |
| 1183 | * start any necessary actions to move the stack into such a state. It is expected that this |
| 1184 | * function get called again when those actions complete. |
| 1185 | * |
| 1186 | * @param shuttingDown true when the called because the device is shutting down. |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1187 | * @return true if the stack finished going to sleep, false if the stack only started the |
| 1188 | * process of going to sleep (checkReadyForSleep will be called when that process finishes). |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1189 | */ |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1190 | boolean goToSleepIfPossible(boolean shuttingDown) { |
| 1191 | boolean shouldSleep = true; |
| 1192 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1193 | if (mResumedActivity != null) { |
| 1194 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1195 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 1196 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 1197 | "Sleep => pause with userLeaving=false"); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1198 | |
| 1199 | // If we are in the middle of resuming the top activity in |
| 1200 | // {@link #resumeTopActivityUncheckedLocked}, mResumedActivity will be set but not |
| 1201 | // resumed yet. We must not proceed pausing the activity here. This method will be |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1202 | // called again if necessary as part of {@link #checkReadyForSleep} or |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1203 | // {@link ActivityStackSupervisor#checkReadyForSleepLocked}. |
| 1204 | if (mStackSupervisor.inResumeTopActivity) { |
| 1205 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "In the middle of resuming top activity " |
| 1206 | + mResumedActivity); |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1207 | } else { |
| 1208 | startPausingLocked(false, true, null, false); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1209 | } |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1210 | shouldSleep = false ; |
| 1211 | } else if (mPausingActivity != null) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1212 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1213 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still waiting to pause " + mPausingActivity); |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1214 | shouldSleep = false; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1215 | } |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1216 | |
| 1217 | if (!shuttingDown) { |
| 1218 | if (containsActivityFromStack(mStackSupervisor.mStoppingActivities)) { |
| 1219 | // Still need to tell some activities to stop; can't sleep yet. |
| 1220 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " |
| 1221 | + mStackSupervisor.mStoppingActivities.size() + " activities"); |
| 1222 | |
| 1223 | mStackSupervisor.scheduleIdleLocked(); |
| 1224 | shouldSleep = false; |
| 1225 | } |
| 1226 | |
| 1227 | if (containsActivityFromStack(mStackSupervisor.mGoingToSleepActivities)) { |
| 1228 | // Still need to tell some activities to sleep; can't sleep yet. |
| 1229 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to sleep " |
| 1230 | + mStackSupervisor.mGoingToSleepActivities.size() + " activities"); |
| 1231 | shouldSleep = false; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | if (shouldSleep) { |
| 1236 | goToSleep(); |
| 1237 | } |
| 1238 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1239 | return shouldSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1240 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1241 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1242 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1243 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1244 | |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1245 | // Make sure any paused or stopped but visible activities are now sleeping. |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1246 | // This ensures that the activity's onStop() is called. |
| 1247 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1248 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1249 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1250 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 1251 | if (r.state == STOPPING || r.state == STOPPED |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1252 | || r.state == ActivityState.PAUSED || r.state == ActivityState.PAUSING) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1253 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1254 | } |
| 1255 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1256 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1257 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1258 | |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1259 | private boolean containsActivityFromStack(List<ActivityRecord> rs) { |
| 1260 | for (ActivityRecord r : rs) { |
| 1261 | if (r.getStack() == this) { |
| 1262 | return true; |
| 1263 | } |
| 1264 | } |
| 1265 | return false; |
| 1266 | } |
| 1267 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1268 | /** |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1269 | * Schedule a pause timeout in case the app doesn't respond. We don't give it much time because |
| 1270 | * this directly impacts the responsiveness seen by the user. |
| 1271 | */ |
| 1272 | private void schedulePauseTimeout(ActivityRecord r) { |
| 1273 | final Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1274 | msg.obj = r; |
| 1275 | r.pauseTime = SystemClock.uptimeMillis(); |
| 1276 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
| 1277 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
| 1278 | } |
| 1279 | |
| 1280 | /** |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1281 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 1282 | * is already an activity being paused or there is no resumed activity. |
| 1283 | * |
| 1284 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 1285 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 1286 | * screen turning off). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1287 | * @param resuming The activity we are currently trying to resume or null if this is not being |
| 1288 | * called as part of resuming the top activity, so we shouldn't try to instigate |
| 1289 | * a resume here if not null. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1290 | * @param pauseImmediately True if the caller does not want to wait for the activity callback to |
| 1291 | * complete pausing. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1292 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 1293 | * it to tell us when it is done. |
| 1294 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1295 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1296 | ActivityRecord resuming, boolean pauseImmediately) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1297 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1298 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 1299 | + " state=" + mPausingActivity.state); |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1300 | if (!shouldSleepActivities()) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1301 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 1302 | // Because activity will be paused immediately after resume, just let pause |
| 1303 | // be completed by the order of activity paused from clients. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1304 | completePauseLocked(false, resuming); |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1305 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1306 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1307 | ActivityRecord prev = mResumedActivity; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1308 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1309 | if (prev == null) { |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1310 | if (resuming == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1311 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1312 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1313 | } |
| 1314 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1315 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1316 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1317 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1318 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1319 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1320 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1321 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1322 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 1323 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1324 | prev.state = ActivityState.PAUSING; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1325 | prev.getTask().touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1326 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 1327 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | 979f5ed | 2015-10-12 11:22:50 -0700 | [diff] [blame] | 1328 | if (mService.mHasRecents |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1329 | && (next == null || next.noDisplay || next.getTask() != prev.getTask() |
| 1330 | || uiSleeping)) { |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1331 | prev.mUpdateTaskThumbnailWhenHidden = true; |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 1332 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 1333 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1334 | |
| 1335 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1336 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1337 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1338 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1339 | try { |
| 1340 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1341 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1342 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 1343 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1344 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1345 | userLeaving, prev.configChangeFlags, pauseImmediately); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1346 | } catch (Exception e) { |
| 1347 | // Ignore exception, if process died other code will cleanup. |
| 1348 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1349 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1350 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1351 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1352 | } |
| 1353 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1354 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1355 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1356 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | // If we are not going to sleep, we want to ensure the device is |
| 1360 | // awake until the next activity is started. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1361 | if (!uiSleeping && !mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1362 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1365 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1366 | // Have the window manager pause its key dispatching until the new |
| 1367 | // activity has started. If we're pausing the activity just because |
| 1368 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1369 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1370 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1371 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1372 | } else if (DEBUG_PAUSE) { |
| 1373 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1376 | if (pauseImmediately) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1377 | // If the caller said they don't want to wait for the pause, then complete |
| 1378 | // the pause now. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1379 | completePauseLocked(false, resuming); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1380 | return false; |
| 1381 | |
| 1382 | } else { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1383 | schedulePauseTimeout(prev); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1384 | return true; |
| 1385 | } |
| 1386 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1387 | } else { |
| 1388 | // This activity failed to schedule the |
| 1389 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1390 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1391 | if (resuming == null) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1392 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1393 | } |
| 1394 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1397 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1398 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1399 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1400 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1401 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1402 | final ActivityRecord r = isInStackLocked(token); |
| 1403 | if (r != null) { |
| 1404 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1405 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1406 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1407 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1408 | mService.mWindowManager.deferSurfaceLayout(); |
| 1409 | try { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1410 | completePauseLocked(true /* resumeNext */, null /* resumingActivity */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1411 | } finally { |
| 1412 | mService.mWindowManager.continueSurfaceLayout(); |
| 1413 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1414 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1415 | } else { |
| 1416 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1417 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1418 | mPausingActivity != null |
| 1419 | ? mPausingActivity.shortComponentName : "(none)"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1420 | if (r.state == ActivityState.PAUSING) { |
| 1421 | r.state = ActivityState.PAUSED; |
| 1422 | if (r.finishing) { |
| 1423 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1424 | "Executing finish of failed to pause activity: " + r); |
| 1425 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1426 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1427 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1428 | } |
| 1429 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1430 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1433 | private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1434 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1435 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1436 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1437 | if (prev != null) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 1438 | final boolean wasStopping = prev.state == STOPPING; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1439 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1440 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1441 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1442 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1443 | } else if (prev.app != null) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1444 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1445 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1446 | if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1447 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1448 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1449 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1450 | if (prev.deferRelaunchUntilPaused) { |
| 1451 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1452 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1453 | prev.relaunchActivityLocked(false /* andResume */, |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1454 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1455 | } else if (wasStopping) { |
| 1456 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1457 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1458 | // We don't need to schedule another stop, we only need to let it happen. |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 1459 | prev.state = STOPPING; |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1460 | } else if (!prev.visible || shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1461 | // Clear out any deferred client hide we might currently have. |
| 1462 | prev.setDeferHidingClient(false); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1463 | // If we were visible then resumeTopActivities will release resources before |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1464 | // stopping. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1465 | addToStopping(prev, true /* scheduleIdle */, false /* idleDelayed */); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1466 | } |
| 1467 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1468 | 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] | 1469 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1470 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1471 | // It is possible the activity was freezing the screen before it was paused. |
| 1472 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1473 | // since it is no longer visible. |
Wale Ogunwale | e852400 | 2016-09-13 16:34:57 -0700 | [diff] [blame] | 1474 | if (prev != null) { |
| 1475 | prev.stopFreezingScreenLocked(true /*force*/); |
| 1476 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1477 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1478 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1479 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1480 | if (resumeNext) { |
| 1481 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1482 | if (!topStack.shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1483 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1484 | } else { |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1485 | checkReadyForSleep(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1486 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1487 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1488 | // If there are no more activities available to run, do resume anyway to start |
| 1489 | // something. Also if the top activity on the stack is not the just paused |
| 1490 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1491 | // in-flight app switch. |
| 1492 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1493 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1494 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1495 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1496 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1497 | if (prev != null) { |
| 1498 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1499 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1500 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1501 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1502 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1503 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1504 | if (diff > 0) { |
| 1505 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1506 | synchronized (bsi) { |
| 1507 | BatteryStatsImpl.Uid.Proc ps = |
| 1508 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1509 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1510 | if (ps != null) { |
| 1511 | ps.addForegroundTimeLocked(diff); |
| 1512 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1516 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1517 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1518 | |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 1519 | // Notify when the task stack has changed, but only if visibilities changed (not just |
| 1520 | // focus). Also if there is an active pinned stack - we always want to notify it about |
| 1521 | // task stack changes, because its positioning may depend on it. |
| 1522 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause |
| 1523 | || mService.mStackSupervisor.getStack(PINNED_STACK_ID) != null) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 1524 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1525 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1526 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1527 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1528 | mStackSupervisor.ensureActivitiesVisibleLocked(resuming, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1531 | void addToStopping(ActivityRecord r, boolean scheduleIdle, boolean idleDelayed) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1532 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1533 | mStackSupervisor.mStoppingActivities.add(r); |
| 1534 | } |
| 1535 | |
| 1536 | // If we already have a few activities waiting to stop, then give up |
| 1537 | // on things going idle and start clearing them out. Or if r is the |
| 1538 | // last of activity of the last task the stack will be empty and must |
| 1539 | // be cleared immediately. |
| 1540 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1541 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1542 | if (scheduleIdle || forceIdle) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1543 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1544 | + forceIdle + "immediate=" + !idleDelayed); |
| 1545 | if (!idleDelayed) { |
| 1546 | mStackSupervisor.scheduleIdleLocked(); |
| 1547 | } else { |
| 1548 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1549 | } |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1550 | } else { |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1551 | checkReadyForSleep(); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1555 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1556 | // otherwise return null; |
| 1557 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1558 | TaskRecord task = r.getTask(); |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1559 | if (task == null) { |
| 1560 | return null; |
| 1561 | } |
| 1562 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1563 | final ActivityStack stack = task.getStack(); |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1564 | if (stack == null) { |
| 1565 | return null; |
| 1566 | } |
| 1567 | |
| 1568 | int stackNdx = mStacks.indexOf(stack); |
| 1569 | |
| 1570 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1571 | int taskNdx = tasks.indexOf(task); |
| 1572 | |
| 1573 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1574 | int activityNdx = activities.indexOf(r) + 1; |
| 1575 | |
| 1576 | final int numStacks = mStacks.size(); |
| 1577 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1578 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1579 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1580 | final int numTasks = tasks.size(); |
| 1581 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1582 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1583 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1584 | final int numActivities = activities.size(); |
| 1585 | while (activityNdx < numActivities) { |
| 1586 | final ActivityRecord activity = activities.get(activityNdx); |
| 1587 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1588 | return historyStack.mFullscreen |
| 1589 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1590 | } |
| 1591 | ++activityNdx; |
| 1592 | } |
| 1593 | activityNdx = 0; |
| 1594 | ++taskNdx; |
| 1595 | } |
| 1596 | taskNdx = 0; |
| 1597 | ++stackNdx; |
| 1598 | } |
| 1599 | |
| 1600 | return null; |
| 1601 | } |
| 1602 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1603 | /** Returns true if the stack contains a fullscreen task. */ |
| 1604 | private boolean hasFullscreenTask() { |
| 1605 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1606 | final TaskRecord task = mTaskHistory.get(i); |
| 1607 | if (task.mFullscreen) { |
| 1608 | return true; |
| 1609 | } |
| 1610 | } |
| 1611 | return false; |
| 1612 | } |
| 1613 | |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1614 | /** |
| 1615 | * Returns true if the stack is translucent and can have other contents visible behind it if |
| 1616 | * needed. A stack is considered translucent if it don't contain a visible or |
| 1617 | * starting (about to be visible) activity that is fullscreen (opaque). |
| 1618 | * @param starting The currently starting activity or null if there is none. |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1619 | * @param stackBehindId The id of the stack directly behind this one. |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1620 | */ |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1621 | private boolean isStackTranslucent(ActivityRecord starting, int stackBehindId) { |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1622 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1623 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1624 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1625 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1626 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1627 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1628 | if (r.finishing) { |
| 1629 | // We don't factor in finishing activities when determining translucency since |
| 1630 | // they will be gone soon. |
| 1631 | continue; |
| 1632 | } |
| 1633 | |
| 1634 | if (!r.visible && r != starting) { |
| 1635 | // Also ignore invisible activities that are not the currently starting |
| 1636 | // activity (about to be visible). |
| 1637 | continue; |
| 1638 | } |
| 1639 | |
| 1640 | if (r.fullscreen) { |
| 1641 | // Stack isn't translucent if it has at least one fullscreen activity |
| 1642 | // that is visible. |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
Winson Chung | e74ad8d | 2017-02-17 15:12:25 -0800 | [diff] [blame] | 1646 | if (!isHomeOrRecentsStack() && r.frontOfTask && task.isOverHomeStack() |
| 1647 | && !StackId.isHomeOrRecentsStack(stackBehindId) && !isAssistantStack()) { |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1648 | // Stack isn't translucent if it's top activity should have the home stack |
Winson Chung | e74ad8d | 2017-02-17 15:12:25 -0800 | [diff] [blame] | 1649 | // behind it and the stack currently behind it isn't the home or recents stack |
| 1650 | // or the assistant stack. |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1651 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1652 | } |
| 1653 | } |
| 1654 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1655 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1658 | /** Returns true if the stack is currently considered visible. */ |
| 1659 | boolean isVisible() { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 1660 | return mWindowContainerController != null && mWindowContainerController.isVisible() |
| 1661 | && !mForceHidden; |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1664 | /** |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1665 | * Returns what the stack visibility should be: {@link #STACK_INVISIBLE} or |
| 1666 | * {@link #STACK_VISIBLE}. |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1667 | * |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1668 | * @param starting The currently starting activity or null if there is none. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1669 | */ |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1670 | int shouldBeVisible(ActivityRecord starting) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 1671 | if (!isAttached() || mForceHidden) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1672 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Andrii Kulian | e8d928a | 2016-11-14 18:38:14 -0800 | [diff] [blame] | 1675 | if (mStackSupervisor.isFrontStackOnDisplay(this) || mStackSupervisor.isFocusedStack(this)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1676 | return STACK_VISIBLE; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1679 | final int stackIndex = mStacks.indexOf(this); |
| 1680 | |
| 1681 | if (stackIndex == mStacks.size() - 1) { |
| 1682 | Slog.wtf(TAG, |
| 1683 | "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] | 1684 | return STACK_INVISIBLE; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 1687 | // Check position and visibility of this stack relative to the front stack on its display. |
| 1688 | final ActivityStack topStack = getTopStackOnDisplay(); |
| 1689 | final int topStackId = topStack.mStackId; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1690 | |
| 1691 | if (mStackId == DOCKED_STACK_ID) { |
Winson Chung | e74ad8d | 2017-02-17 15:12:25 -0800 | [diff] [blame] | 1692 | // If the assistant stack is focused and translucent, then the docked stack is always |
| 1693 | // visible |
Winson Chung | 521f011 | 2017-03-13 16:14:45 -0700 | [diff] [blame] | 1694 | if (topStack.isAssistantStack()) { |
| 1695 | return (topStack.isStackTranslucent(starting, DOCKED_STACK_ID)) ? STACK_VISIBLE |
| 1696 | : STACK_INVISIBLE; |
Winson Chung | e74ad8d | 2017-02-17 15:12:25 -0800 | [diff] [blame] | 1697 | } |
Matthew Ng | 6875d47 | 2017-05-01 13:59:50 -0700 | [diff] [blame] | 1698 | return STACK_VISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 1701 | // Set home stack to invisible when it is below but not immediately below the docked stack |
| 1702 | // A case would be if recents stack exists but has no tasks and is below the docked stack |
| 1703 | // and home stack is below recents |
| 1704 | if (mStackId == HOME_STACK_ID) { |
| 1705 | int dockedStackIndex = mStacks.indexOf(mStackSupervisor.getStack(DOCKED_STACK_ID)); |
| 1706 | if (dockedStackIndex > stackIndex && stackIndex != dockedStackIndex - 1) { |
| 1707 | return STACK_INVISIBLE; |
| 1708 | } |
| 1709 | } |
| 1710 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 1711 | // Find the first stack behind front stack that actually got something visible. |
| 1712 | int stackBehindTopIndex = mStacks.indexOf(topStack) - 1; |
| 1713 | while (stackBehindTopIndex >= 0 && |
| 1714 | mStacks.get(stackBehindTopIndex).topRunningActivityLocked() == null) { |
| 1715 | stackBehindTopIndex--; |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1716 | } |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 1717 | final int stackBehindTopId = (stackBehindTopIndex >= 0) |
| 1718 | ? mStacks.get(stackBehindTopIndex).mStackId : INVALID_STACK_ID; |
Winson Chung | dd7593a | 2017-07-05 18:02:36 -0700 | [diff] [blame] | 1719 | if (topStackId == DOCKED_STACK_ID || StackId.isAlwaysOnTop(topStackId)) { |
| 1720 | if (stackIndex == stackBehindTopIndex) { |
| 1721 | // Stacks directly behind the docked or pinned stack are always visible. |
| 1722 | return STACK_VISIBLE; |
| 1723 | } else if (StackId.isAlwaysOnTop(topStackId) && stackIndex == stackBehindTopIndex - 1) { |
| 1724 | // Otherwise, this stack can also be visible if it is directly behind a docked stack |
| 1725 | // or translucent assistant stack behind an always-on-top top-most stack |
| 1726 | if (stackBehindTopId == DOCKED_STACK_ID) { |
| 1727 | return STACK_VISIBLE; |
| 1728 | } else if (stackBehindTopId == ASSISTANT_STACK_ID) { |
| 1729 | return mStacks.get(stackBehindTopIndex).isStackTranslucent(starting, mStackId) |
| 1730 | ? STACK_VISIBLE : STACK_INVISIBLE; |
| 1731 | } |
| 1732 | } |
Matthew Ng | 6875d47 | 2017-05-01 13:59:50 -0700 | [diff] [blame] | 1733 | } |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1734 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 1735 | if (StackId.isBackdropToTranslucentActivity(topStackId) |
| 1736 | && topStack.isStackTranslucent(starting, stackBehindTopId)) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1737 | // Stacks behind the fullscreen or assistant stack with a translucent activity are |
| 1738 | // always visible so they can act as a backdrop to the translucent activity. |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1739 | // For example, dialog activities |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 1740 | if (stackIndex == stackBehindTopIndex) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1741 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1742 | } |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 1743 | if (stackBehindTopIndex >= 0) { |
| 1744 | if ((stackBehindTopId == DOCKED_STACK_ID |
| 1745 | || stackBehindTopId == PINNED_STACK_ID) |
| 1746 | && stackIndex == (stackBehindTopIndex - 1)) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1747 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1748 | // complete backdrop to the translucent activity when the docked stack is up. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1749 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1750 | } |
| 1751 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1754 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1755 | // 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] | 1756 | return STACK_INVISIBLE; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1759 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1760 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1761 | |
| 1762 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1763 | continue; |
| 1764 | } |
| 1765 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1766 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1767 | // These stacks can't have any dynamic stacks visible behind them. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1768 | return STACK_INVISIBLE; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1769 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1770 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1771 | if (!stack.isStackTranslucent(starting, INVALID_STACK_ID)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1772 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1773 | } |
| 1774 | } |
| 1775 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1776 | return STACK_VISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1779 | final int rankTaskLayers(int baseLayer) { |
| 1780 | int layer = 0; |
| 1781 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1782 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1783 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1784 | if (r == null || r.finishing || !r.visible) { |
| 1785 | task.mLayerRank = -1; |
| 1786 | } else { |
| 1787 | task.mLayerRank = baseLayer + layer++; |
| 1788 | } |
| 1789 | } |
| 1790 | return layer; |
| 1791 | } |
| 1792 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1793 | /** |
| 1794 | * Make sure that all activities that need to be visible (that is, they |
| 1795 | * currently can be seen by the user) actually are. |
| 1796 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1797 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1798 | boolean preserveWindows) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1799 | mTopActivityOccludesKeyguard = false; |
| 1800 | mTopDismissingKeyguardActivity = null; |
| 1801 | mStackSupervisor.mKeyguardController.beginActivityVisibilityUpdate(); |
| 1802 | try { |
| 1803 | ActivityRecord top = topRunningActivityLocked(); |
| 1804 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
| 1805 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 1806 | if (top != null) { |
| 1807 | checkTranslucentActivityWaiting(top); |
| 1808 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1809 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1810 | // If the top activity is not fullscreen, then we need to |
| 1811 | // make sure any activities under it are now visible. |
| 1812 | boolean aboveTop = top != null; |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1813 | final int stackVisibility = shouldBeVisible(starting); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1814 | final boolean stackInvisible = stackVisibility != STACK_VISIBLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1815 | boolean behindFullscreenActivity = stackInvisible; |
| 1816 | boolean resumeNextActivity = mStackSupervisor.isFocusedStack(this) |
| 1817 | && (isInStackLocked(starting) == null); |
| 1818 | boolean behindTranslucentActivity = false; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1819 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1820 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1821 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1822 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1823 | final ActivityRecord r = activities.get(activityNdx); |
| 1824 | if (r.finishing) { |
| 1825 | // Normally the screenshot will be taken in makeInvisible(). When an activity |
| 1826 | // is finishing, we no longer change its visibility, but we still need to take |
| 1827 | // the screenshots if startPausingLocked decided it should be taken. |
| 1828 | if (r.mUpdateTaskThumbnailWhenHidden) { |
| 1829 | r.updateThumbnailLocked(r.screenshotActivityLocked(), |
| 1830 | null /* description */); |
| 1831 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1832 | } |
| 1833 | continue; |
Chong Zhang | 22bc851 | 2016-04-07 13:47:18 -0700 | [diff] [blame] | 1834 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1835 | final boolean isTop = r == top; |
| 1836 | if (aboveTop && !isTop) { |
| 1837 | continue; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1838 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1839 | aboveTop = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1840 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1841 | // Check whether activity should be visible without Keyguard influence |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1842 | final boolean visibleIgnoringKeyguard = r.shouldBeVisibleIgnoringKeyguard( |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1843 | behindFullscreenActivity); |
| 1844 | r.visibleIgnoringKeyguard = visibleIgnoringKeyguard; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1845 | |
| 1846 | // Now check whether it's really visible depending on Keyguard state. |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1847 | final boolean reallyVisible = checkKeyguardVisibility(r, |
| 1848 | visibleIgnoringKeyguard, isTop); |
| 1849 | if (visibleIgnoringKeyguard) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1850 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1851 | behindFullscreenActivity, task, r); |
| 1852 | if (behindFullscreenActivity && !r.fullscreen) { |
| 1853 | behindTranslucentActivity = true; |
| 1854 | } |
| 1855 | } |
| 1856 | if (reallyVisible) { |
| 1857 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
| 1858 | + " finishing=" + r.finishing + " state=" + r.state); |
| 1859 | // First: if this is not the current activity being started, make |
| 1860 | // sure it matches the current configuration. |
| 1861 | if (r != starting) { |
| 1862 | r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindows); |
| 1863 | } |
| 1864 | |
| 1865 | if (r.app == null || r.app.thread == null) { |
| 1866 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
| 1867 | resumeNextActivity, r)) { |
| 1868 | if (activityNdx >= activities.size()) { |
| 1869 | // Record may be removed if its process needs to restart. |
| 1870 | activityNdx = activities.size() - 1; |
| 1871 | } else { |
| 1872 | resumeNextActivity = false; |
| 1873 | } |
| 1874 | } |
| 1875 | } else if (r.visible) { |
| 1876 | // If this activity is already visible, then there is nothing to do here. |
| 1877 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1878 | "Skipping: already visible at " + r); |
| 1879 | |
| 1880 | if (r.handleAlreadyVisible()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1881 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1882 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1883 | } else { |
| 1884 | r.makeVisibleIfNeeded(starting); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1885 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1886 | // Aggregate current change flags. |
| 1887 | configChanges |= r.configChangeFlags; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1888 | } else { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1889 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
| 1890 | + " finishing=" + r.finishing + " state=" + r.state + " stackInvisible=" |
| 1891 | + stackInvisible + " behindFullscreenActivity=" |
| 1892 | + behindFullscreenActivity + " mLaunchTaskBehind=" |
| 1893 | + r.mLaunchTaskBehind); |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1894 | makeInvisible(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1895 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1896 | } |
| 1897 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1898 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1899 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1900 | // status of an activity in a previous task affects other. |
| 1901 | behindFullscreenActivity = stackVisibility == STACK_INVISIBLE; |
| 1902 | } else if (mStackId == HOME_STACK_ID) { |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 1903 | if (task.isHomeTask()) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1904 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
| 1905 | + " stackInvisible=" + stackInvisible |
| 1906 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1907 | // No other task in the home stack should be visible behind the home activity. |
| 1908 | // Home activities is usually a translucent activity with the wallpaper behind |
| 1909 | // them. However, when they don't have the wallpaper behind them, we want to |
| 1910 | // show activities in the next application stack behind them vs. another |
| 1911 | // task in the home stack like recents. |
| 1912 | behindFullscreenActivity = true; |
| 1913 | } else if (task.isRecentsTask() |
| 1914 | && task.getTaskToReturnTo() == APPLICATION_ACTIVITY_TYPE) { |
| 1915 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1916 | "Recents task returning to app: at " + task |
| 1917 | + " stackInvisible=" + stackInvisible |
| 1918 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1919 | // We don't want any other tasks in the home stack visible if the recents |
| 1920 | // activity is going to be returning to an application activity type. |
| 1921 | // We do this to preserve the visible order the user used to get into the |
| 1922 | // recents activity. The recents activity is normally translucent and if it |
| 1923 | // doesn't have the wallpaper behind it the next activity in the home stack |
| 1924 | // shouldn't be visible when the home stack is brought to the front to display |
| 1925 | // the recents activity from an app. |
| 1926 | behindFullscreenActivity = true; |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1927 | } |
Winson Chung | 1cebea6 | 2017-06-26 17:22:27 -0700 | [diff] [blame] | 1928 | } else if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID) { |
| 1929 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Skipping after task=" + task |
| 1930 | + " returning to non-application type=" + task.getTaskToReturnTo()); |
Winson Chung | 0315702 | 2017-07-19 11:58:59 -0700 | [diff] [blame] | 1931 | // Once we reach a fullscreen stack task that has a running activity and should |
| 1932 | // return to another stack task, then no other activities behind that one should |
| 1933 | // be visible. |
| 1934 | if (task.topRunningActivityLocked() != null && |
| 1935 | task.getTaskToReturnTo() != APPLICATION_ACTIVITY_TYPE) { |
Winson Chung | 1cebea6 | 2017-06-26 17:22:27 -0700 | [diff] [blame] | 1936 | behindFullscreenActivity = true; |
| 1937 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1938 | } |
| 1939 | } |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1940 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1941 | if (mTranslucentActivityWaiting != null && |
| 1942 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1943 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1944 | notifyActivityDrawnLocked(null); |
| 1945 | } |
| 1946 | } finally { |
| 1947 | mStackSupervisor.mKeyguardController.endActivityVisibilityUpdate(); |
| 1948 | } |
| 1949 | } |
| 1950 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 1951 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 1952 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1953 | mTaskHistory.get(taskNdx).addStartingWindowsForVisibleActivities(taskSwitch); |
| 1954 | } |
| 1955 | } |
| 1956 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1957 | /** |
| 1958 | * @return true if the top visible activity wants to occlude the Keyguard, false otherwise |
| 1959 | */ |
| 1960 | boolean topActivityOccludesKeyguard() { |
| 1961 | return mTopActivityOccludesKeyguard; |
| 1962 | } |
| 1963 | |
| 1964 | /** |
| 1965 | * @return the top most visible activity that wants to dismiss Keyguard |
| 1966 | */ |
| 1967 | ActivityRecord getTopDismissingKeyguardActivity() { |
| 1968 | return mTopDismissingKeyguardActivity; |
| 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * Checks whether {@param r} should be visible depending on Keyguard state and updates |
| 1973 | * {@link #mTopActivityOccludesKeyguard} and {@link #mTopDismissingKeyguardActivity} if |
| 1974 | * necessary. |
| 1975 | * |
| 1976 | * @return true if {@param r} is visible taken Keyguard state into account, false otherwise |
| 1977 | */ |
Wale Ogunwale | d334a05 | 2017-05-12 07:17:36 -0700 | [diff] [blame] | 1978 | boolean checkKeyguardVisibility(ActivityRecord r, boolean shouldBeVisible, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1979 | boolean isTop) { |
Winson Chung | 0655da0 | 2016-12-16 17:05:01 -0800 | [diff] [blame] | 1980 | final boolean isInPinnedStack = r.getStack().getStackId() == PINNED_STACK_ID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1981 | final boolean keyguardShowing = mStackSupervisor.mKeyguardController.isKeyguardShowing(); |
| 1982 | final boolean keyguardLocked = mStackSupervisor.mKeyguardController.isKeyguardLocked(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1983 | final boolean showWhenLocked = r.canShowWhenLocked() && !isInPinnedStack; |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 1984 | final boolean dismissKeyguard = r.hasDismissKeyguardWindows(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1985 | if (shouldBeVisible) { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 1986 | if (dismissKeyguard && mTopDismissingKeyguardActivity == null) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1987 | mTopDismissingKeyguardActivity = r; |
| 1988 | } |
| 1989 | |
| 1990 | // Only the top activity may control occluded, as we can't occlude the Keyguard if the |
| 1991 | // top app doesn't want to occlude it. |
| 1992 | if (isTop) { |
| 1993 | mTopActivityOccludesKeyguard |= showWhenLocked; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1994 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1995 | |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 1996 | final boolean canShowWithKeyguard = canShowWithInsecureKeyguard() |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 1997 | && mStackSupervisor.mKeyguardController.canDismissKeyguard(); |
| 1998 | if (canShowWithKeyguard) { |
| 1999 | return true; |
| 2000 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2001 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2002 | if (keyguardShowing) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2003 | |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2004 | // If keyguard is showing, nothing is visible, except if we are able to dismiss Keyguard |
| 2005 | // right away. |
| 2006 | return shouldBeVisible && mStackSupervisor.mKeyguardController |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2007 | .canShowActivityWhileKeyguardShowing(r, dismissKeyguard); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2008 | } else if (keyguardLocked) { |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2009 | return shouldBeVisible && mStackSupervisor.mKeyguardController.canShowWhileOccluded( |
| 2010 | dismissKeyguard, showWhenLocked); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2011 | } else { |
| 2012 | return shouldBeVisible; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2013 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2014 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2015 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2016 | /** |
| 2017 | * Check if the display to which this stack is attached has |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2018 | * {@link Display#FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD} applied. |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2019 | */ |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2020 | private boolean canShowWithInsecureKeyguard() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2021 | final ActivityStackSupervisor.ActivityDisplay activityDisplay = getDisplay(); |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2022 | if (activityDisplay == null) { |
| 2023 | throw new IllegalStateException("Stack is not attached to any display, stackId=" |
| 2024 | + mStackId); |
| 2025 | } |
| 2026 | |
| 2027 | final int flags = activityDisplay.mDisplay.getFlags(); |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2028 | return (flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2029 | } |
| 2030 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2031 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 2032 | if (mTranslucentActivityWaiting != top) { |
| 2033 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2034 | if (mTranslucentActivityWaiting != null) { |
| 2035 | // Call the callback with a timeout indication. |
| 2036 | notifyActivityDrawnLocked(null); |
| 2037 | mTranslucentActivityWaiting = null; |
| 2038 | } |
| 2039 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2044 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2045 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 2046 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 2047 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 2048 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2049 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2050 | // This activity needs to be visible, but isn't even running... |
| 2051 | // get it started and resume if no other stack in this stack is resumed. |
| 2052 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 2053 | if (r != starting) { |
| 2054 | r.startFreezingScreenLocked(r.app, configChanges); |
| 2055 | } |
| 2056 | if (!r.visible || r.mLaunchTaskBehind) { |
| 2057 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2058 | r.setVisible(true); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2059 | } |
| 2060 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2061 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2062 | return true; |
| 2063 | } |
| 2064 | } |
| 2065 | return false; |
| 2066 | } |
| 2067 | |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2068 | // TODO: Should probably be moved into ActivityRecord. |
| 2069 | private void makeInvisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2070 | if (!r.visible) { |
| 2071 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 2072 | return; |
| 2073 | } |
| 2074 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 2075 | // keeping the screen frozen. |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 2076 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.state); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2077 | try { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2078 | final boolean canEnterPictureInPicture = r.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2079 | "makeInvisible", true /* beforeStopping */); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2080 | // Defer telling the client it is hidden if it can enter Pip and isn't current stopped |
| 2081 | // or stopping. This gives it a chance to enter Pip in onPause(). |
| 2082 | final boolean deferHidingClient = canEnterPictureInPicture |
| 2083 | && r.state != STOPPING && r.state != STOPPED; |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 2084 | r.setDeferHidingClient(deferHidingClient); |
| 2085 | r.setVisible(false); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2086 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2087 | switch (r.state) { |
| 2088 | case STOPPING: |
| 2089 | case STOPPED: |
| 2090 | if (r.app != null && r.app.thread != null) { |
| 2091 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2092 | "Scheduling invisibility: " + r); |
| 2093 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 2094 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2095 | |
| 2096 | // Reset the flag indicating that an app can enter picture-in-picture once the |
| 2097 | // activity is hidden |
| 2098 | r.supportsPictureInPictureWhilePausing = false; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2099 | break; |
| 2100 | |
| 2101 | case INITIALIZING: |
| 2102 | case RESUMED: |
| 2103 | case PAUSING: |
| 2104 | case PAUSED: |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2105 | addToStopping(r, true /* scheduleIdle */, |
| 2106 | canEnterPictureInPicture /* idleDelayed */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2107 | break; |
| 2108 | |
| 2109 | default: |
| 2110 | break; |
| 2111 | } |
| 2112 | } catch (Exception e) { |
| 2113 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 2114 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 2119 | TaskRecord task, ActivityRecord r) { |
| 2120 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2121 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 2122 | + " stackInvisible=" + stackInvisible |
| 2123 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 2124 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2125 | behindFullscreenActivity = true; |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 2126 | } else if (!isHomeOrRecentsStack() && r.frontOfTask && task.isOverHomeStack()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2127 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 2128 | + " stackInvisible=" + stackInvisible |
| 2129 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 2130 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2131 | } |
| 2132 | return behindFullscreenActivity; |
| 2133 | } |
| 2134 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 2135 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2136 | mTranslucentActivityWaiting = r; |
| 2137 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2138 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 2139 | } |
| 2140 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 2141 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 2142 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2143 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2144 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2145 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2146 | final ActivityRecord r = activities.get(activityNdx); |
| 2147 | if ( r.appTimeTracker != except) { |
| 2148 | r.appTimeTracker = null; |
| 2149 | } |
| 2150 | } |
| 2151 | } |
| 2152 | } |
| 2153 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2154 | /** |
| 2155 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 2156 | * redrawn notify the top activity by calling |
| 2157 | * {@link Activity#onTranslucentConversionComplete}. |
| 2158 | * |
| 2159 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 2160 | * occurred and the activity will be notified immediately. |
| 2161 | */ |
| 2162 | void notifyActivityDrawnLocked(ActivityRecord r) { |
| 2163 | if ((r == null) |
| 2164 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 2165 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 2166 | // The last undrawn activity below the top has just been drawn. If there is an |
| 2167 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 2168 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 2169 | mTranslucentActivityWaiting = null; |
| 2170 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2171 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2172 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2173 | if (waitingActivity != null) { |
| 2174 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 2175 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 2176 | try { |
| 2177 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 2178 | waitingActivity.appToken, r != null); |
| 2179 | } catch (RemoteException e) { |
| 2180 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | } |
| 2184 | } |
| 2185 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2186 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 2187 | * starting window displayed then remove that starting window. It is possible that the activity |
| 2188 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 2189 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2190 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2191 | boolean aboveTop = true; |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2192 | // We don't want to clear starting window for activities that aren't behind fullscreen |
| 2193 | // activities as we need to display their starting window until they are done initializing. |
| 2194 | boolean behindFullscreenActivity = false; |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2195 | |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 2196 | if (shouldBeVisible(null) == STACK_INVISIBLE) { |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2197 | // The stack is not visible, so no activity in it should be displaying a starting |
| 2198 | // window. Mark all activities below top and behind fullscreen. |
| 2199 | aboveTop = false; |
| 2200 | behindFullscreenActivity = true; |
| 2201 | } |
| 2202 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2203 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2204 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2205 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2206 | final ActivityRecord r = activities.get(activityNdx); |
| 2207 | if (aboveTop) { |
| 2208 | if (r == topActivity) { |
| 2209 | aboveTop = false; |
| 2210 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2211 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2212 | continue; |
| 2213 | } |
| 2214 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2215 | r.removeOrphanedStartingWindow(behindFullscreenActivity); |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2216 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2221 | /** |
| 2222 | * Ensure that the top activity in the stack is resumed. |
| 2223 | * |
| 2224 | * @param prev The previously resumed activity, for when in the process |
| 2225 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2226 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2227 | * |
| 2228 | * @return Returns true if something is being resumed, or false if |
| 2229 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2230 | * |
| 2231 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 2232 | * non-focused stack to be resumed. |
| 2233 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 2234 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2235 | */ |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2236 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2237 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2238 | // Don't even start recursing. |
| 2239 | return false; |
| 2240 | } |
| 2241 | |
| 2242 | boolean result = false; |
| 2243 | try { |
| 2244 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2245 | mStackSupervisor.inResumeTopActivity = true; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2246 | result = resumeTopActivityInnerLocked(prev, options); |
| 2247 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2248 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2249 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2250 | |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 2251 | // When resuming the top activity, it may be necessary to pause the top activity (for |
| 2252 | // example, returning to the lock screen. We suppress the normal pause logic in |
| 2253 | // {@link #resumeTopActivityUncheckedLocked}, since the top activity is resumed at the end. |
| 2254 | // We call the {@link ActivityStackSupervisor#checkReadyForSleepLocked} again here to ensure |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2255 | // any necessary pause logic occurs. In the case where the Activity will be shown regardless |
| 2256 | // of the lock screen, the call to {@link ActivityStackSupervisor#checkReadyForSleepLocked} |
| 2257 | // is skipped. |
| 2258 | final ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
| 2259 | if (next == null || !next.canTurnScreenOn()) { |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2260 | checkReadyForSleep(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2261 | } |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 2262 | |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2263 | return result; |
| 2264 | } |
| 2265 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2266 | void setResumedActivityLocked(ActivityRecord r, String reason) { |
| 2267 | // TODO: move mResumedActivity to stack supervisor, |
| 2268 | // there should only be 1 global copy of resumed activity. |
| 2269 | mResumedActivity = r; |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2270 | r.state = ActivityState.RESUMED; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2271 | mService.setResumedActivityUncheckLocked(r, reason); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2272 | final TaskRecord task = r.getTask(); |
| 2273 | task.touchActiveTime(); |
| 2274 | mRecentTasks.addLocked(task); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2277 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2278 | if (!mService.mBooting && !mService.mBooted) { |
| 2279 | // Not ready yet! |
| 2280 | return false; |
| 2281 | } |
| 2282 | |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 2283 | // Find the next top-most activity to resume in this stack that is not finishing and is |
| 2284 | // focusable. If it is not focusable, we will fall into the case below to resume the |
| 2285 | // top activity in the next focusable task. |
| 2286 | final ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2287 | |
| 2288 | final boolean hasRunningActivity = next != null; |
| 2289 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2290 | // TODO: Maybe this entire condition can get removed? |
| 2291 | if (hasRunningActivity && getDisplay() == null) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2292 | return false; |
| 2293 | } |
| 2294 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 2295 | mStackSupervisor.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2296 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2297 | // Remember how we'll process this pause/resume situation, and ensure |
| 2298 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2299 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 2300 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2301 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2302 | if (!hasRunningActivity) { |
| 2303 | // There are no activities left in the stack, let's look somewhere else. |
| 2304 | return resumeTopActivityInNextFocusableStack(prev, options, "noMoreActivities"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2308 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2309 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2310 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2311 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2312 | // Make sure we have executed any pending transitions, since there |
| 2313 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2314 | executeAppTransition(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2315 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2316 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2317 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2318 | return false; |
| 2319 | } |
| 2320 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2321 | final TaskRecord nextTask = next.getTask(); |
| 2322 | final TaskRecord prevTask = prev != null ? prev.getTask() : null; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2323 | if (prevTask != null && prevTask.getStack() == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2324 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2325 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2326 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2327 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2328 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2329 | // 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] | 2330 | // 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] | 2331 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2332 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 2333 | } else if (!isOnHomeDisplay()) { |
| 2334 | return false; |
| 2335 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2336 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2337 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2338 | return isOnHomeDisplay() && |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 2339 | mStackSupervisor.resumeHomeStackTask(prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 2340 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2343 | // If we are sleeping, and there is no resumed activity, and the top |
| 2344 | // activity is paused, well that is the state we want. |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2345 | if (shouldSleepOrShutDownActivities() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 2346 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2347 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2348 | // Make sure we have executed any pending transitions, since there |
| 2349 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2350 | executeAppTransition(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2351 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2352 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2353 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2354 | return false; |
| 2355 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2356 | |
| 2357 | // Make sure that the user who owns this activity is started. If not, |
| 2358 | // we will just leave it as is because someone should be bringing |
| 2359 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2360 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2361 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 2362 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2363 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2364 | return false; |
| 2365 | } |
| 2366 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2367 | // The activity may be waiting for stop, but that is no longer |
| 2368 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2369 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2370 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2371 | next.sleeping = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2372 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2373 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2374 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2375 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2376 | // 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] | 2377 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2378 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2379 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2380 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2381 | return false; |
| 2382 | } |
| 2383 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2384 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2385 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2386 | boolean lastResumedCanPip = false; |
| 2387 | final ActivityStack lastFocusedStack = mStackSupervisor.getLastStack(); |
| 2388 | if (lastFocusedStack != null && lastFocusedStack != this) { |
| 2389 | // So, why aren't we using prev here??? See the param comment on the method. prev doesn't |
| 2390 | // represent the last resumed activity. However, the last focus stack does if it isn't null. |
| 2391 | final ActivityRecord lastResumed = lastFocusedStack.mResumedActivity; |
| 2392 | lastResumedCanPip = lastResumed != null && lastResumed.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2393 | "resumeTopActivity", userLeaving /* beforeStopping */); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2394 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2395 | // If the flag RESUME_WHILE_PAUSING is set, then continue to schedule the previous activity |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2396 | // to be paused, while at the same time resuming the new resume activity only if the |
| 2397 | // previous activity can't go into Pip since we want to give Pip activities a chance to |
| 2398 | // enter Pip before resuming the next activity. |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2399 | final boolean resumeWhilePausing = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0 |
| 2400 | && !lastResumedCanPip; |
| 2401 | |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2402 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2403 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2404 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2405 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2406 | pausing |= startPausingLocked(userLeaving, false, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2407 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2408 | if (pausing && !resumeWhilePausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2409 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2410 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2411 | // At this point we want to put the upcoming activity's process |
| 2412 | // at the top of the LRU list, since we know we will be needing it |
| 2413 | // very soon and it would be a waste to let it get killed if it |
| 2414 | // happens to be sitting towards the end. |
| 2415 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2416 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2417 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2418 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2419 | return true; |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2420 | } else if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2421 | mStackSupervisor.allResumedActivitiesComplete()) { |
| 2422 | // It is possible for the activity to be resumed when we paused back stacks above if the |
| 2423 | // next activity doesn't have to wait for pause to complete. |
| 2424 | // So, nothing else to-do except: |
| 2425 | // Make sure we have executed any pending transitions, since there |
| 2426 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2427 | executeAppTransition(options); |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2428 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2429 | "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); |
| 2430 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2431 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2434 | // If the most recent activity was noHistory but was only stopped rather |
| 2435 | // than stopped+finished because the device went to sleep, we need to make |
| 2436 | // sure to finish it as we're making a new activity topmost. |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2437 | if (shouldSleepActivities() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2438 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2439 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2440 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2441 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2442 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2443 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2446 | if (prev != null && prev != next) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2447 | if (!mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(prev) |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2448 | && next != null && !next.nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2449 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2450 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2451 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2452 | } else { |
| 2453 | // The next activity is already visible, so hide the previous |
| 2454 | // activity's windows right now so we can show the new one ASAP. |
| 2455 | // We only do this if the previous is finishing, which should mean |
| 2456 | // it is on top of the one being resumed so hiding it quickly |
| 2457 | // is good. Otherwise, we want to do the normal route of allowing |
| 2458 | // the resumed activity to be shown so we can decide if the |
| 2459 | // previous should actually be hidden depending on whether the |
| 2460 | // new one is found to be full-screen or not. |
| 2461 | if (prev.finishing) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2462 | prev.setVisibility(false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2463 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2464 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2465 | + mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2466 | + ", nowVisible=" + next.nowVisible); |
| 2467 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2468 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2469 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2470 | + ", waitingVisible=" |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2471 | + mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(prev) |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2472 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2477 | // Launching this app's activity, make sure the app is no longer |
| 2478 | // considered stopped. |
| 2479 | try { |
| 2480 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2481 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2482 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2483 | } catch (IllegalArgumentException e) { |
| 2484 | Slog.w(TAG, "Failed trying to unstop package " |
| 2485 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2488 | // We are starting up the next activity, so tell the window manager |
| 2489 | // that the previous one will be hidden soon. This way it can know |
| 2490 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2491 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2492 | if (prev != null) { |
| 2493 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2494 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2495 | "Prepare close transition: prev=" + prev); |
| 2496 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2497 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2498 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2499 | } else { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2500 | mWindowManager.prepareAppTransition(prev.getTask() == next.getTask() |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2501 | ? TRANSIT_ACTIVITY_CLOSE |
| 2502 | : TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2503 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2504 | prev.setVisibility(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2505 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2506 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2507 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2508 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2509 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2510 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2511 | } else { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2512 | mWindowManager.prepareAppTransition(prev.getTask() == next.getTask() |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2513 | ? TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2514 | : next.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2515 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2516 | : TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2517 | } |
| 2518 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2519 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2520 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2521 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2522 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2523 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2524 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2525 | mWindowManager.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2526 | } |
| 2527 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2528 | |
| 2529 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2530 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2531 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2532 | if (opts != null) { |
| 2533 | resumeAnimOptions = opts.toBundle(); |
| 2534 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2535 | next.applyOptionsLocked(); |
| 2536 | } else { |
| 2537 | next.clearOptionsLocked(); |
| 2538 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2539 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2540 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2541 | if (next.app != null && next.app.thread != null) { |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2542 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next |
| 2543 | + " stopped=" + next.stopped + " visible=" + next.visible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2544 | |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2545 | // If the previous activity is translucent, force a visibility update of |
| 2546 | // the next activity, so that it's added to WM's opening app list, and |
| 2547 | // transition animation can be set up properly. |
| 2548 | // For example, pressing Home button with a translucent activity in focus. |
| 2549 | // Launcher is already visible in this case. If we don't add it to opening |
| 2550 | // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a |
| 2551 | // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. |
| 2552 | final boolean lastActivityTranslucent = lastStack != null |
| 2553 | && (!lastStack.mFullscreen |
| 2554 | || (lastStack.mLastPausedActivity != null |
| 2555 | && !lastStack.mLastPausedActivity.fullscreen)); |
| 2556 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2557 | // This activity is now becoming visible. |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2558 | if (!next.visible || next.stopped || lastActivityTranslucent) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2559 | next.setVisibility(true); |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 2560 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2561 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2562 | // schedule launch ticks to collect information about slow apps. |
| 2563 | next.startLaunchTickingLocked(); |
| 2564 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2565 | ActivityRecord lastResumedActivity = |
| 2566 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2567 | ActivityState lastState = next.state; |
| 2568 | |
| 2569 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2570 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2571 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next + " (in existing)"); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2572 | |
| 2573 | setResumedActivityLocked(next, "resumeTopActivityInnerLocked"); |
| 2574 | |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2575 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2576 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2577 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2578 | |
| 2579 | // Have the window manager re-evaluate the orientation of |
| 2580 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2581 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2582 | if (mStackSupervisor.isFocusedStack(this)) { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2583 | final Configuration config = mWindowManager.updateOrientationFromAppTokens( |
| 2584 | mStackSupervisor.getDisplayOverrideConfiguration(mDisplayId), |
| 2585 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null, mDisplayId); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2586 | if (config != null) { |
| 2587 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2588 | } |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2589 | notUpdated = !mService.updateDisplayOverrideConfigurationLocked(config, next, |
| 2590 | false /* deferResume */, mDisplayId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2591 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2592 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2593 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2594 | // The configuration update wasn't able to keep the existing |
| 2595 | // instance of the activity, and instead started a new one. |
| 2596 | // We should be all done, but let's just make sure our activity |
| 2597 | // is still at the top and schedule another run if something |
| 2598 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2599 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2600 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2601 | "Activity config changed during resume: " + next |
| 2602 | + ", new next: " + nextNext); |
| 2603 | if (nextNext != next) { |
| 2604 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2605 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2606 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2607 | if (!next.visible || next.stopped) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2608 | next.setVisibility(true); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2609 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2610 | next.completeResumeLocked(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2611 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2612 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2613 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2614 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2615 | try { |
| 2616 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2617 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2618 | if (a != null) { |
| 2619 | final int N = a.size(); |
| 2620 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2621 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2622 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2623 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | if (next.newIntents != null) { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2628 | next.app.thread.scheduleNewIntent( |
| 2629 | next.newIntents, next.appToken, false /* andPause */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2632 | // Well the app will no longer be stopped. |
| 2633 | // Clear app token stopped state in window manager if needed. |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2634 | next.notifyAppResumed(next.stopped); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2635 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2636 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2637 | System.identityHashCode(next), next.getTask().taskId, |
| 2638 | next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2639 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2640 | next.sleeping = false; |
Alan Viverette | 5f31b98 | 2016-06-21 14:46:14 -0400 | [diff] [blame] | 2641 | mService.showUnsupportedZoomDialogIfNeededLocked(next); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2642 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2643 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2644 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2645 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2646 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2647 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2648 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2649 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2650 | } catch (Exception e) { |
| 2651 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2652 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2653 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2654 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2655 | if (lastStack != null) { |
| 2656 | lastStack.mResumedActivity = lastResumedActivity; |
| 2657 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2658 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2659 | if (!next.hasBeenLaunched) { |
| 2660 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2661 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 2662 | mStackSupervisor.isFrontStackOnDisplay(lastStack)) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2663 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 2664 | false /* taskSwitch */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2665 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2666 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2667 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2668 | return true; |
| 2669 | } |
| 2670 | |
| 2671 | // From this point on, if something goes wrong there is no way |
| 2672 | // to recover the activity. |
| 2673 | try { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2674 | next.completeResumeLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2675 | } catch (Exception e) { |
| 2676 | // If any exception gets thrown, toss away this |
| 2677 | // activity and try the next one. |
| 2678 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2679 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2680 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2681 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2682 | return true; |
| 2683 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2684 | } else { |
| 2685 | // Whoops, need to restart this activity! |
| 2686 | if (!next.hasBeenLaunched) { |
| 2687 | next.hasBeenLaunched = true; |
| 2688 | } else { |
| 2689 | if (SHOW_APP_STARTING_PREVIEW) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2690 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 2691 | false /* taskSwich */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2692 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2693 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2694 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2695 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2696 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2699 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2700 | return true; |
| 2701 | } |
| 2702 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2703 | private boolean resumeTopActivityInNextFocusableStack(ActivityRecord prev, |
| 2704 | ActivityOptions options, String reason) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2705 | if ((!mFullscreen || !isOnHomeDisplay()) && adjustFocusToNextFocusableStackLocked(reason)) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2706 | // Try to move focus to the next visible stack with a running activity if this |
| 2707 | // stack is not covering the entire screen or is on a secondary display (with no home |
| 2708 | // stack). |
| 2709 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 2710 | mStackSupervisor.getFocusedStack(), prev, null); |
| 2711 | } |
| 2712 | |
| 2713 | // Let's just start up the Launcher... |
| 2714 | ActivityOptions.abort(options); |
| 2715 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2716 | "resumeTopActivityInNextFocusableStack: " + reason + ", go home"); |
| 2717 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2718 | // Only resume home if on home display |
| 2719 | return isOnHomeDisplay() && |
| 2720 | mStackSupervisor.resumeHomeStackTask(prev, reason); |
| 2721 | } |
| 2722 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2723 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2724 | final int index = mTaskHistory.indexOf(targetTask); |
| 2725 | if (index >= 0) { |
| 2726 | final int numTasks = mTaskHistory.size(); |
| 2727 | for (int i = index + 1; i < numTasks; ++i) { |
| 2728 | TaskRecord task = mTaskHistory.get(i); |
| 2729 | if (task.userId == targetTask.userId) { |
| 2730 | return task; |
| 2731 | } |
| 2732 | } |
| 2733 | } |
| 2734 | return null; |
| 2735 | } |
| 2736 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2737 | /** Returns the position the input task should be placed in this stack. */ |
| 2738 | int getAdjustedPositionForTask(TaskRecord task, int suggestedPosition, |
| 2739 | ActivityRecord starting) { |
| 2740 | |
| 2741 | int maxPosition = mTaskHistory.size(); |
| 2742 | if ((starting != null && starting.okToShowLocked()) |
| 2743 | || (starting == null && task.okToShowLocked())) { |
| 2744 | // If the task or starting activity can be shown, then whatever position is okay. |
| 2745 | return Math.min(suggestedPosition, maxPosition); |
| 2746 | } |
| 2747 | |
| 2748 | // The task can't be shown, put non-current user tasks below current user tasks. |
| 2749 | while (maxPosition > 0) { |
| 2750 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2751 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
| 2752 | || tmpTask.topRunningActivityLocked() == null) { |
| 2753 | break; |
| 2754 | } |
| 2755 | maxPosition--; |
| 2756 | } |
| 2757 | |
| 2758 | return Math.min(suggestedPosition, maxPosition); |
| 2759 | } |
| 2760 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2761 | /** |
| 2762 | * Used from {@link ActivityStack#positionTask(TaskRecord, int)}. |
| 2763 | * @see ActivityManagerService#positionTaskInStack(int, int, int). |
| 2764 | */ |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2765 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2766 | if (position >= mTaskHistory.size()) { |
| 2767 | insertTaskAtTop(task, null); |
| 2768 | return; |
| 2769 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2770 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2771 | mTaskHistory.remove(task); |
| 2772 | mTaskHistory.add(position, task); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2773 | mWindowContainerController.positionChildAt(task.getWindowContainerController(), position, |
| 2774 | task.mBounds, task.getOverrideConfiguration()); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2775 | updateTaskMovement(task, true); |
| 2776 | } |
| 2777 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2778 | private void insertTaskAtTop(TaskRecord task, ActivityRecord starting) { |
| 2779 | updateTaskReturnToForTopInsertion(task); |
| 2780 | // TODO: Better place to put all the code below...may be addTask... |
| 2781 | mTaskHistory.remove(task); |
| 2782 | // Now put task at top. |
| 2783 | final int position = getAdjustedPositionForTask(task, mTaskHistory.size(), starting); |
| 2784 | mTaskHistory.add(position, task); |
| 2785 | updateTaskMovement(task, true); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2786 | mWindowContainerController.positionChildAtTop(task.getWindowContainerController(), |
| 2787 | true /* includingParents */); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2788 | } |
| 2789 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2790 | /** |
| 2791 | * Updates the {@param task}'s return type before it is moved to the top. |
| 2792 | */ |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2793 | private void updateTaskReturnToForTopInsertion(TaskRecord task) { |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2794 | boolean isLastTaskOverHome = false; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2795 | // If the moving task is over the home or assistant stack, transfer its return type to next |
| 2796 | // task so that they return to the same stack |
| 2797 | if (task.isOverHomeStack() || task.isOverAssistantStack()) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2798 | final TaskRecord nextTask = getNextTask(task); |
| 2799 | if (nextTask != null) { |
| 2800 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2801 | } else { |
| 2802 | isLastTaskOverHome = true; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2806 | // If this is not on the default display, then just set the return type to application |
| 2807 | if (!isOnHomeDisplay()) { |
| 2808 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
| 2809 | return; |
| 2810 | } |
| 2811 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2812 | final ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2813 | |
| 2814 | // If there is no last task, do not set task to return to |
| 2815 | if (lastStack == null) { |
| 2816 | return; |
| 2817 | } |
| 2818 | |
| 2819 | // If the task was launched from the assistant stack, set the return type to assistant |
| 2820 | if (lastStack.isAssistantStack()) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2821 | task.setTaskToReturnTo(ASSISTANT_ACTIVITY_TYPE); |
| 2822 | return; |
| 2823 | } |
| 2824 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2825 | // 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] | 2826 | // activity, set mTaskToReturnTo accordingly. |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2827 | final boolean fromHomeOrRecents = lastStack.isHomeOrRecentsStack(); |
| 2828 | final TaskRecord topTask = lastStack.topTask(); |
| 2829 | if (!isHomeOrRecentsStack() && (fromHomeOrRecents || topTask() != task)) { |
| 2830 | // If it's a last task over home - we default to keep its return to type not to |
| 2831 | // make underlying task focused when this one will be finished. |
| 2832 | int returnToType = isLastTaskOverHome |
| 2833 | ? task.getTaskToReturnTo() : APPLICATION_ACTIVITY_TYPE; |
| 2834 | if (fromHomeOrRecents && StackId.allowTopTaskToReturnHome(mStackId)) { |
| 2835 | returnToType = topTask == null ? HOME_ACTIVITY_TYPE : topTask.taskType; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2836 | } |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2837 | task.setTaskToReturnTo(returnToType); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2838 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2839 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2840 | |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2841 | final void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, |
| 2842 | boolean newTask, boolean keepCurTransition, ActivityOptions options) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2843 | TaskRecord rTask = r.getTask(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2844 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2845 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2846 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2847 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2848 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2849 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2850 | insertTaskAtTop(rTask, r); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2851 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2852 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2853 | if (!newTask) { |
| 2854 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2855 | boolean startIt = true; |
| 2856 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2857 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2858 | if (task.getTopActivity() == null) { |
| 2859 | // All activities in task are finishing. |
| 2860 | continue; |
| 2861 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2862 | if (task == rTask) { |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2863 | // Here it is! Now, if this is not yet visible to the |
| 2864 | // user, then just add it without starting; it will |
| 2865 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2866 | if (!startIt) { |
| 2867 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2868 | + task, new RuntimeException("here").fillInStackTrace()); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2869 | r.createWindowContainer(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2870 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2871 | return; |
| 2872 | } |
| 2873 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2874 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2875 | startIt = false; |
| 2876 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2880 | // Place a new activity at top of stack, so it is next to interact with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2881 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2882 | // If we are not placing the new activity frontmost, we do not want to deliver the |
| 2883 | // onUserLeaving callback to the actual frontmost activity |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2884 | final TaskRecord activityTask = r.getTask(); |
| 2885 | if (task == activityTask && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2886 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2887 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2888 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2889 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2890 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2891 | task = activityTask; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2892 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2893 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2894 | 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] | 2895 | new RuntimeException("here").fillInStackTrace()); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 2896 | // TODO: Need to investigate if it is okay for the controller to already be created by the |
| 2897 | // time we get to this point. I think it is, but need to double check. |
| 2898 | // Use test in b/34179495 to trace the call path. |
| 2899 | if (r.getWindowContainerController() == null) { |
| 2900 | r.createWindowContainer(); |
| 2901 | } |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2902 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2903 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 2904 | if (!isHomeOrRecentsStack() || numActivities() > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2905 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2906 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2907 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2908 | mWindowManager.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2909 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2910 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2911 | int transit = TRANSIT_ACTIVITY_OPEN; |
| 2912 | if (newTask) { |
| 2913 | if (r.mLaunchTaskBehind) { |
| 2914 | transit = TRANSIT_TASK_OPEN_BEHIND; |
| 2915 | } else { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2916 | // If a new task is being launched, then mark the existing top activity as |
Winson Chung | 942a85c | 2017-07-11 15:07:45 -0700 | [diff] [blame] | 2917 | // supporting picture-in-picture while pausing only if the starting activity |
| 2918 | // would not be considered an overlay on top of the current activity |
| 2919 | // (eg. not fullscreen, or the assistant) |
Winson Chung | 4aede8a | 2017-07-05 12:23:25 -0700 | [diff] [blame] | 2920 | if (focusedTopActivity != null |
| 2921 | && focusedTopActivity.getStackId() != PINNED_STACK_ID |
Winson Chung | 942a85c | 2017-07-11 15:07:45 -0700 | [diff] [blame] | 2922 | && r.getStackId() != ASSISTANT_STACK_ID |
| 2923 | && r.fullscreen) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2924 | focusedTopActivity.supportsPictureInPictureWhilePausing = true; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2925 | } |
| 2926 | transit = TRANSIT_TASK_OPEN; |
| 2927 | } |
| 2928 | } |
| 2929 | mWindowManager.prepareAppTransition(transit, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2930 | mNoAnimActivities.remove(r); |
| 2931 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2932 | boolean doShow = true; |
| 2933 | if (newTask) { |
| 2934 | // Even though this activity is starting fresh, we still need |
| 2935 | // to reset it to make sure we apply affinities to move any |
| 2936 | // existing activities from other tasks in to it. |
| 2937 | // If the caller has requested that the target task be |
| 2938 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2939 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2940 | resetTaskIfNeededLocked(r, r); |
| 2941 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2942 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2943 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2944 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2945 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2946 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2947 | if (r.mLaunchTaskBehind) { |
| 2948 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2949 | // tell WindowManager that r is visible even though it is at the back of the stack. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2950 | r.setVisibility(true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2951 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2952 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2953 | // Figure out if we are transitioning from another activity that is |
| 2954 | // "has the same starting icon" as the next one. This allows the |
| 2955 | // window manager to keep the previous window it had previously |
| 2956 | // created, if it still had one. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2957 | TaskRecord prevTask = r.getTask(); |
| 2958 | ActivityRecord prev = prevTask.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2959 | if (prev != null) { |
| 2960 | // We don't want to reuse the previous starting preview if: |
| 2961 | // (1) The current activity is in a different task. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2962 | if (prev.getTask() != prevTask) { |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2963 | prev = null; |
| 2964 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2965 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2966 | else if (prev.nowVisible) { |
| 2967 | prev = null; |
| 2968 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2969 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2970 | r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2971 | } |
| 2972 | } else { |
| 2973 | // If this is the first activity, don't do any fancy animations, |
| 2974 | // because there is nothing for it to animate on top of. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2975 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2976 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2977 | } |
| 2978 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2979 | private boolean isTaskSwitch(ActivityRecord r, |
| 2980 | ActivityRecord topFocusedActivity) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2981 | return topFocusedActivity != null && r.getTask() != topFocusedActivity.getTask(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2982 | } |
| 2983 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2984 | /** |
| 2985 | * Perform a reset of the given task, if needed as part of launching it. |
| 2986 | * Returns the new HistoryRecord at the top of the task. |
| 2987 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2988 | /** |
| 2989 | * Helper method for #resetTaskIfNeededLocked. |
| 2990 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2991 | * for another task, or leave it as-is. |
| 2992 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2993 | * @param forceReset |
| 2994 | * @return An ActivityOptions that needs to be processed. |
| 2995 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2996 | private ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2997 | ActivityOptions topOptions = null; |
| 2998 | |
| 2999 | int replyChainEnd = -1; |
| 3000 | boolean canMoveOptions = true; |
| 3001 | |
| 3002 | // We only do this for activities that are not the root of the task (since if we finish |
| 3003 | // the root, we may no longer have the task!). |
| 3004 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3005 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3006 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 3007 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3008 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3009 | if (target.frontOfTask) |
| 3010 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3011 | |
| 3012 | final int flags = target.info.flags; |
| 3013 | final boolean finishOnTaskLaunch = |
| 3014 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3015 | final boolean allowTaskReparenting = |
| 3016 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3017 | final boolean clearWhenTaskReset = |
| 3018 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 3019 | |
| 3020 | if (!finishOnTaskLaunch |
| 3021 | && !clearWhenTaskReset |
| 3022 | && target.resultTo != null) { |
| 3023 | // If this activity is sending a reply to a previous |
| 3024 | // activity, we can't do anything with it now until |
| 3025 | // we reach the start of the reply chain. |
| 3026 | // XXX note that we are assuming the result is always |
| 3027 | // to the previous activity, which is almost always |
| 3028 | // the case but we really shouldn't count on. |
| 3029 | if (replyChainEnd < 0) { |
| 3030 | replyChainEnd = i; |
| 3031 | } |
| 3032 | } else if (!finishOnTaskLaunch |
| 3033 | && !clearWhenTaskReset |
| 3034 | && allowTaskReparenting |
| 3035 | && target.taskAffinity != null |
| 3036 | && !target.taskAffinity.equals(task.affinity)) { |
| 3037 | // If this activity has an affinity for another |
| 3038 | // task, then we need to move it out of here. We will |
| 3039 | // move it as far out of the way as possible, to the |
| 3040 | // bottom of the activity stack. This also keeps it |
| 3041 | // correctly ordered with any activities we previously |
| 3042 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3043 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3044 | final ActivityRecord bottom = |
| 3045 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3046 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3047 | if (bottom != null && target.taskAffinity != null |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3048 | && target.taskAffinity.equals(bottom.getTask().affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3049 | // If the activity currently at the bottom has the |
| 3050 | // same task affinity as the one we are moving, |
| 3051 | // then merge it into the same task. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3052 | targetTask = bottom.getTask(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3053 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3054 | + " out to bottom task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3055 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3056 | targetTask = createTaskRecord( |
| 3057 | mStackSupervisor.getNextTaskIdForUserLocked(target.userId), |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 3058 | target.info, null, null, null, false, target.mActivityType); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3059 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3060 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3061 | + " out to new task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3062 | } |
| 3063 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3064 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3065 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 3066 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3067 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3068 | if (p.finishing) { |
| 3069 | continue; |
| 3070 | } |
| 3071 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3072 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3073 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3074 | topOptions = p.takeOptionsLocked(); |
| 3075 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3076 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3077 | } |
| 3078 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3079 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3080 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 3081 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3082 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3083 | "Pushing next activity " + p + " out to target's task " + target); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3084 | p.reparent(targetTask, 0 /* position - bottom */, "resetTargetTaskIfNeeded"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3085 | } |
| 3086 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3087 | mWindowContainerController.positionChildAtBottom( |
| 3088 | targetTask.getWindowContainerController()); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3089 | replyChainEnd = -1; |
| 3090 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 3091 | // If the activity should just be removed -- either |
| 3092 | // because it asks for it, or the task should be |
| 3093 | // cleared -- then finish it and anything that is |
| 3094 | // part of its reply chain. |
| 3095 | int end; |
| 3096 | if (clearWhenTaskReset) { |
| 3097 | // In this case, we want to finish this activity |
| 3098 | // and everything above it, so be sneaky and pretend |
| 3099 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 3100 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3101 | } else if (replyChainEnd < 0) { |
| 3102 | end = i; |
| 3103 | } else { |
| 3104 | end = replyChainEnd; |
| 3105 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3106 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3107 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3108 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3109 | if (p.finishing) { |
| 3110 | continue; |
| 3111 | } |
| 3112 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3113 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3114 | topOptions = p.takeOptionsLocked(); |
| 3115 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3116 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3117 | } |
| 3118 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3119 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3120 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3121 | if (finishActivityLocked( |
| 3122 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3123 | end--; |
| 3124 | srcPos--; |
| 3125 | } |
| 3126 | } |
| 3127 | replyChainEnd = -1; |
| 3128 | } else { |
| 3129 | // If we were in the middle of a chain, well the |
| 3130 | // activity that started it all doesn't want anything |
| 3131 | // special, so leave it all as-is. |
| 3132 | replyChainEnd = -1; |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | return topOptions; |
| 3137 | } |
| 3138 | |
| 3139 | /** |
| 3140 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 3141 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 3142 | * @param affinityTask The task we are looking for an affinity to. |
| 3143 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 3144 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 3145 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 3146 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3147 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3148 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3149 | int replyChainEnd = -1; |
| 3150 | final int taskId = task.taskId; |
| 3151 | final String taskAffinity = task.affinity; |
| 3152 | |
| 3153 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 3154 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3155 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3156 | |
| 3157 | // Do not operate on or below the effective root Activity. |
| 3158 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3159 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3160 | if (target.frontOfTask) |
| 3161 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3162 | |
| 3163 | final int flags = target.info.flags; |
| 3164 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3165 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3166 | |
| 3167 | if (target.resultTo != null) { |
| 3168 | // If this activity is sending a reply to a previous |
| 3169 | // activity, we can't do anything with it now until |
| 3170 | // we reach the start of the reply chain. |
| 3171 | // XXX note that we are assuming the result is always |
| 3172 | // to the previous activity, which is almost always |
| 3173 | // the case but we really shouldn't count on. |
| 3174 | if (replyChainEnd < 0) { |
| 3175 | replyChainEnd = i; |
| 3176 | } |
| 3177 | } else if (topTaskIsHigher |
| 3178 | && allowTaskReparenting |
| 3179 | && taskAffinity != null |
| 3180 | && taskAffinity.equals(target.taskAffinity)) { |
| 3181 | // This activity has an affinity for our task. Either remove it if we are |
| 3182 | // clearing or move it over to our task. Note that |
| 3183 | // we currently punt on the case where we are resetting a |
| 3184 | // task that is not at the top but who has activities above |
| 3185 | // with an affinity to it... this is really not a normal |
| 3186 | // case, and we will need to later pull that task to the front |
| 3187 | // and usually at that point we will do the reset and pick |
| 3188 | // up those remaining activities. (This only happens if |
| 3189 | // someone starts an activity in a new task from an activity |
| 3190 | // in a task that is not currently on top.) |
| 3191 | if (forceReset || finishOnTaskLaunch) { |
| 3192 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3193 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3194 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3195 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3196 | final ActivityRecord p = activities.get(srcPos); |
| 3197 | if (p.finishing) { |
| 3198 | continue; |
| 3199 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3200 | finishActivityLocked( |
| 3201 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3202 | } |
| 3203 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3204 | if (taskInsertionPoint < 0) { |
| 3205 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3206 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3207 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3208 | |
| 3209 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3210 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3211 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3212 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3213 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3214 | final ActivityRecord p = activities.get(srcPos); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 3215 | p.reparent(task, taskInsertionPoint, "resetAffinityTaskIfNeededLocked"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3216 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3217 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3218 | "Removing and adding activity " + p + " to stack at " + task |
| 3219 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3220 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3221 | + " from " + srcPos + " in to resetting task " + task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3222 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3223 | mWindowContainerController.positionChildAtTop( |
| 3224 | task.getWindowContainerController(), true /* includingParents */); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3225 | |
| 3226 | // Now we've moved it in to place... but what if this is |
| 3227 | // a singleTop activity and we have put it on top of another |
| 3228 | // instance of the same activity? Then we drop the instance |
| 3229 | // below so it remains singleTop. |
| 3230 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3231 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3232 | int targetNdx = taskActivities.indexOf(target); |
| 3233 | if (targetNdx > 0) { |
| 3234 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3235 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3236 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3237 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | replyChainEnd = -1; |
| 3244 | } |
| 3245 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3246 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3247 | } |
| 3248 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3249 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3250 | ActivityRecord newActivity) { |
| 3251 | boolean forceReset = |
| 3252 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 3253 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3254 | && taskTop.getTask().getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3255 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 3256 | forceReset = true; |
| 3257 | } |
| 3258 | } |
| 3259 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3260 | final TaskRecord task = taskTop.getTask(); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3261 | |
| 3262 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3263 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3264 | boolean taskFound = false; |
| 3265 | |
| 3266 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3267 | ActivityOptions topOptions = null; |
| 3268 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3269 | // Preserve the location for reparenting in the new task. |
| 3270 | int reparentInsertionPoint = -1; |
| 3271 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3272 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3273 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3274 | |
| 3275 | if (targetTask == task) { |
| 3276 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3277 | taskFound = true; |
| 3278 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3279 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3280 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3281 | } |
| 3282 | } |
| 3283 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3284 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3285 | if (taskNdx >= 0) { |
| 3286 | do { |
| 3287 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3288 | } while (taskTop == null && taskNdx >= 0); |
| 3289 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3290 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3291 | if (topOptions != null) { |
| 3292 | // If we got some ActivityOptions from an activity on top that |
| 3293 | // was removed from the task, propagate them to the new real top. |
| 3294 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3295 | taskTop.updateOptionsLocked(topOptions); |
| 3296 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3297 | topOptions.abort(); |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | return taskTop; |
| 3302 | } |
| 3303 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3304 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3305 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3306 | |
| 3307 | if (callingUid > 0) { |
| 3308 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3309 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3313 | + " : who=" + resultWho + " req=" + requestCode |
| 3314 | + " res=" + resultCode + " data=" + data); |
| 3315 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 3316 | try { |
| 3317 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3318 | list.add(new ResultInfo(resultWho, requestCode, |
| 3319 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3320 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3321 | return; |
| 3322 | } catch (Exception e) { |
| 3323 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 3328 | } |
| 3329 | |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3330 | /** Returns true if the task is one of the task finishing on-top of the top running task. */ |
| 3331 | boolean isATopFinishingTask(TaskRecord task) { |
| 3332 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3333 | final TaskRecord current = mTaskHistory.get(i); |
| 3334 | final ActivityRecord r = current.topRunningActivityLocked(); |
| 3335 | if (r != null) { |
| 3336 | // We got a top running activity, so there isn't a top finishing task... |
| 3337 | return false; |
| 3338 | } |
| 3339 | if (current == task) { |
| 3340 | return true; |
| 3341 | } |
| 3342 | } |
| 3343 | return false; |
| 3344 | } |
| 3345 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3346 | private void adjustFocusedActivityStackLocked(ActivityRecord r, String reason) { |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3347 | if (!mStackSupervisor.isFocusedStack(this) || |
| 3348 | ((mResumedActivity != r) && (mResumedActivity != null))) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3349 | return; |
| 3350 | } |
| 3351 | |
| 3352 | final ActivityRecord next = topRunningActivityLocked(); |
| 3353 | final String myReason = reason + " adjustFocus"; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3354 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3355 | if (next != r) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3356 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3357 | // For freeform, docked, and pinned stacks we always keep the focus within the |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3358 | // stack as long as there is a running activity. |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3359 | return; |
| 3360 | } else { |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3361 | // Task is not guaranteed to be non-null. For example, destroying the |
| 3362 | // {@link ActivityRecord} will disassociate the task from the activity. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3363 | final TaskRecord task = r.getTask(); |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3364 | |
| 3365 | if (task == null) { |
| 3366 | throw new IllegalStateException("activity no longer associated with task:" + r); |
| 3367 | } |
| 3368 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 3369 | final boolean isAssistantOrOverAssistant = task.getStack().isAssistantStack() || |
| 3370 | task.isOverAssistantStack(); |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3371 | if (r.frontOfTask && isATopFinishingTask(task) |
| 3372 | && (task.isOverHomeStack() || isAssistantOrOverAssistant)) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 3373 | // For non-fullscreen or assistant stack, we want to move the focus to the next |
| 3374 | // visible stack to prevent the home screen from moving to the top and obscuring |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3375 | // other visible stacks. |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 3376 | if ((!mFullscreen || isAssistantOrOverAssistant) |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3377 | && adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3378 | return; |
| 3379 | } |
| 3380 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 3381 | // other visible stack. |
Winson Chung | 521f011 | 2017-03-13 16:14:45 -0700 | [diff] [blame] | 3382 | if (task.isOverHomeStack() && |
| 3383 | mStackSupervisor.moveHomeStackTaskToTop(myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3384 | // Activity focus was already adjusted. Nothing else to do... |
| 3385 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3386 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3387 | } |
| 3388 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3389 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3390 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3391 | mStackSupervisor.moveFocusableActivityStackToFrontLocked( |
| 3392 | mStackSupervisor.topRunningActivityLocked(), myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3395 | /** Find next proper focusable stack and make it focused. */ |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3396 | private boolean adjustFocusToNextFocusableStackLocked(String reason) { |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3397 | return adjustFocusToNextFocusableStackLocked(reason, false /* allowFocusSelf */); |
| 3398 | } |
| 3399 | |
| 3400 | /** |
| 3401 | * Find next proper focusable stack and make it focused. |
| 3402 | * @param allowFocusSelf Is the focus allowed to remain on the same stack. |
| 3403 | */ |
| 3404 | private boolean adjustFocusToNextFocusableStackLocked(String reason, boolean allowFocusSelf) { |
Winson Chung | 1cebea6 | 2017-06-26 17:22:27 -0700 | [diff] [blame] | 3405 | if (isAssistantStack() && bottomTask() != null && |
| 3406 | bottomTask().getTaskToReturnTo() == HOME_ACTIVITY_TYPE) { |
| 3407 | // If the current stack is the assistant stack, then use the return-to type to determine |
| 3408 | // whether to return to the home screen. This is needed to workaround an issue where |
| 3409 | // launching a fullscreen task (and subequently returning from that task) will cause |
| 3410 | // the fullscreen stack to be found as the next focusable stack below, even if the |
| 3411 | // assistant was launched over home. |
| 3412 | return mStackSupervisor.moveHomeStackTaskToTop(reason); |
| 3413 | } |
| 3414 | |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3415 | final ActivityStack stack = mStackSupervisor.getNextFocusableStackLocked( |
| 3416 | allowFocusSelf ? null : this); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3417 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3418 | if (stack == null) { |
| 3419 | return false; |
| 3420 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3421 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3422 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3423 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3424 | if (stack.isHomeOrRecentsStack() && (top == null || !top.visible)) { |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3425 | // If we will be focusing on the home stack next and its current top activity isn't |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3426 | // visible, then use the task return to value to determine the home task to display |
| 3427 | // next. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3428 | return mStackSupervisor.moveHomeStackTaskToTop(reason); |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3429 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3430 | |
Bryce Lee | 43f2721 | 2017-08-07 16:10:43 -0700 | [diff] [blame] | 3431 | if (stack.isAssistantStack() && top != null |
| 3432 | && top.getTask().getTaskToReturnTo() == HOME_ACTIVITY_TYPE) { |
| 3433 | // It is possible for the home stack to not be directly underneath the assistant stack. |
| 3434 | // For example, the assistant may start an activity in the fullscreen stack. Upon |
| 3435 | // returning to the assistant stack, we must ensure that the home stack is underneath |
| 3436 | // when appropriate. |
| 3437 | mStackSupervisor.moveHomeStackTaskToTop("adjustAssistantReturnToHome"); |
| 3438 | } |
| 3439 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3440 | stack.moveToFront(myReason); |
| 3441 | return true; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3442 | } |
| 3443 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3444 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3445 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3446 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3447 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3448 | if (!r.finishing) { |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3449 | if (!shouldSleepActivities()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3450 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3451 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3452 | "stop-no-history", false)) { |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3453 | // If {@link requestFinishActivityLocked} returns {@code true}, |
| 3454 | // {@link adjustFocusedActivityStackLocked} would have been already called. |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3455 | r.resumeKeyDispatchingLocked(); |
| 3456 | return; |
| 3457 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3458 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3459 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3460 | + " on stop because we're just sleeping"); |
| 3461 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3462 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | if (r.app != null && r.app.thread != null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3466 | adjustFocusedActivityStackLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3467 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3468 | try { |
| 3469 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3470 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3471 | "Moving to STOPPING: " + r + " (stop requested)"); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3472 | r.state = STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3473 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3474 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3475 | if (!r.visible) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3476 | r.setVisible(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3477 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3478 | EventLogTags.writeAmStopActivity( |
| 3479 | r.userId, System.identityHashCode(r), r.shortComponentName); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3480 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3481 | if (shouldSleepOrShutDownActivities()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3482 | r.setSleeping(true); |
| 3483 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3484 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3485 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3486 | } catch (Exception e) { |
| 3487 | // Maybe just ignore exceptions here... if the process |
| 3488 | // has crashed, our death notification will clean things |
| 3489 | // up. |
| 3490 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3491 | // Just in case, assume it to be stopped. |
| 3492 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3493 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Stop failed; moving to STOPPED: " + r); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3494 | r.state = STOPPED; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3495 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3496 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3497 | } |
| 3498 | } |
| 3499 | } |
| 3500 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3501 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3502 | /** |
| 3503 | * @return Returns true if the activity is being finished, false if for |
| 3504 | * some reason it is being left as-is. |
| 3505 | */ |
| 3506 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3507 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3508 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3509 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3510 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3511 | + ", result=" + resultCode + ", data=" + resultData |
| 3512 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3513 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3514 | return false; |
| 3515 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3516 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3517 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3518 | return true; |
| 3519 | } |
| 3520 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3521 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3522 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3523 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3524 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3525 | ActivityRecord r = activities.get(activityNdx); |
| 3526 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3527 | if ((r.resultWho == null && resultWho == null) || |
| 3528 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3529 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3530 | false); |
| 3531 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3532 | } |
| 3533 | } |
| 3534 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3535 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3538 | final TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3539 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3540 | TaskRecord finishedTask = null; |
| 3541 | if (r == null || r.app != app) { |
| 3542 | return null; |
| 3543 | } |
| 3544 | Slog.w(TAG, " Force finishing activity " |
| 3545 | + r.intent.getComponent().flattenToShortString()); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3546 | finishedTask = r.getTask(); |
| 3547 | int taskNdx = mTaskHistory.indexOf(finishedTask); |
| 3548 | final TaskRecord task = finishedTask; |
| 3549 | int activityNdx = task.mActivities.indexOf(r); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3550 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3551 | finishedTask = task; |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3552 | // Also terminate any activities below it that aren't yet |
| 3553 | // stopped, to avoid a situation where one will get |
| 3554 | // re-start our crashing activity once it gets resumed again. |
| 3555 | --activityNdx; |
| 3556 | if (activityNdx < 0) { |
| 3557 | do { |
| 3558 | --taskNdx; |
| 3559 | if (taskNdx < 0) { |
| 3560 | break; |
| 3561 | } |
| 3562 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3563 | } while (activityNdx < 0); |
| 3564 | } |
| 3565 | if (activityNdx >= 0) { |
| 3566 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
| 3567 | if (r.state == ActivityState.RESUMED |
| 3568 | || r.state == ActivityState.PAUSING |
| 3569 | || r.state == ActivityState.PAUSED) { |
| 3570 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
| 3571 | Slog.w(TAG, " Force finishing activity " |
| 3572 | + r.intent.getComponent().flattenToShortString()); |
| 3573 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3577 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3578 | } |
| 3579 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3580 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3581 | IBinder sessionBinder = session.asBinder(); |
| 3582 | boolean didOne = false; |
| 3583 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3584 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3585 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3586 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3587 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3588 | if (!r.finishing) { |
| 3589 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3590 | false); |
| 3591 | didOne = true; |
| 3592 | } |
| 3593 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3594 | } else { |
| 3595 | // Check if any of the activities are using voice |
| 3596 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3597 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3598 | if (r.voiceSession != null |
| 3599 | && r.voiceSession.asBinder() == sessionBinder) { |
| 3600 | // Inform of cancellation |
| 3601 | r.clearVoiceSessionLocked(); |
| 3602 | try { |
| 3603 | r.app.thread.scheduleLocalVoiceInteractionStarted((IBinder) r.appToken, |
| 3604 | null); |
| 3605 | } catch (RemoteException re) { |
| 3606 | // Ok |
| 3607 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3608 | mService.finishRunningVoiceLocked(); |
| 3609 | break; |
| 3610 | } |
| 3611 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3612 | } |
| 3613 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3614 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3615 | if (didOne) { |
| 3616 | mService.updateOomAdjLocked(); |
| 3617 | } |
| 3618 | } |
| 3619 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3620 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3621 | ArrayList<ActivityRecord> activities = r.getTask().mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3622 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3623 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3624 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3625 | break; |
| 3626 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3627 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3628 | } |
| 3629 | return true; |
| 3630 | } |
| 3631 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3632 | private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3633 | // send the result |
| 3634 | ActivityRecord resultTo = r.resultTo; |
| 3635 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3636 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3637 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3638 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3639 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3640 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3641 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3642 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3643 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3644 | if (r.info.applicationInfo.uid > 0) { |
| 3645 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3646 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3647 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3648 | } |
| 3649 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3650 | resultData); |
| 3651 | r.resultTo = null; |
| 3652 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3653 | 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] | 3654 | |
| 3655 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3656 | // because clients have remote IPC references to this object so we |
| 3657 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3658 | r.results = null; |
| 3659 | r.pendingResults = null; |
| 3660 | r.newIntents = null; |
| 3661 | r.icicle = null; |
| 3662 | } |
| 3663 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3664 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3665 | * See {@link #finishActivityLocked(ActivityRecord, int, Intent, String, boolean, boolean)} |
| 3666 | */ |
| 3667 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3668 | String reason, boolean oomAdj) { |
| 3669 | return finishActivityLocked(r, resultCode, resultData, reason, oomAdj, !PAUSE_IMMEDIATELY); |
| 3670 | } |
| 3671 | |
| 3672 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3673 | * @return Returns true if this activity has been removed from the history |
| 3674 | * list, or false if it is still in the list and will be removed later. |
| 3675 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3676 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3677 | String reason, boolean oomAdj, boolean pauseImmediately) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3678 | if (r.finishing) { |
| 3679 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3680 | return false; |
| 3681 | } |
| 3682 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3683 | mWindowManager.deferSurfaceLayout(); |
| 3684 | try { |
| 3685 | r.makeFinishingLocked(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3686 | final TaskRecord task = r.getTask(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3687 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3688 | r.userId, System.identityHashCode(r), |
| 3689 | task.taskId, r.shortComponentName, reason); |
| 3690 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3691 | final int index = activities.indexOf(r); |
| 3692 | if (index < (activities.size() - 1)) { |
| 3693 | task.setFrontOfTask(); |
| 3694 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
| 3695 | // If the caller asked that this activity (and all above it) |
| 3696 | // be cleared when the task is reset, don't lose that information, |
| 3697 | // but propagate it up to the next activity. |
| 3698 | ActivityRecord next = activities.get(index+1); |
| 3699 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
| 3700 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3701 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3702 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3703 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3704 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3705 | adjustFocusedActivityStackLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3706 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3707 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3708 | |
Yorke Lee | bdef537 | 2017-04-10 16:38:51 -0700 | [diff] [blame] | 3709 | final boolean endTask = index <= 0 && !task.isClearingToReuseTask(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3710 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
| 3711 | if (mResumedActivity == r) { |
| 3712 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 3713 | "Prepare close transition: finishing " + r); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3714 | if (endTask) { |
| 3715 | mService.mTaskChangeNotificationController.notifyTaskRemovalStarted( |
| 3716 | task.taskId); |
| 3717 | } |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3718 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3719 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3720 | // Tell window manager to prepare for this one to be removed. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3721 | r.setVisibility(false); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3722 | |
| 3723 | if (mPausingActivity == null) { |
| 3724 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3725 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3726 | "finish() => pause with userLeaving=false"); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3727 | startPausingLocked(false, false, null, pauseImmediately); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | if (endTask) { |
| 3731 | mStackSupervisor.removeLockedTaskLocked(task); |
| 3732 | } |
| 3733 | } else if (r.state != ActivityState.PAUSING) { |
| 3734 | // If the activity is PAUSING, we will complete the finish once |
| 3735 | // it is done pausing; else we can just directly finish it here. |
| 3736 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
| 3737 | if (r.visible) { |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3738 | prepareActivityHideTransitionAnimation(r, transit); |
| 3739 | } |
| 3740 | |
| 3741 | final int finishMode = (r.visible || r.nowVisible) ? FINISH_AFTER_VISIBLE |
| 3742 | : FINISH_AFTER_PAUSE; |
| 3743 | final boolean removedActivity = finishCurrentActivityLocked(r, finishMode, oomAdj) |
| 3744 | == null; |
| 3745 | |
| 3746 | // The following code is an optimization. When the last non-task overlay activity |
| 3747 | // is removed from the task, we remove the entire task from the stack. However, |
| 3748 | // since that is done after the scheduled destroy callback from the activity, that |
| 3749 | // call to change the visibility of the task overlay activities would be out of |
| 3750 | // sync with the activitiy visibility being set for this finishing activity above. |
| 3751 | // In this case, we can set the visibility of all the task overlay activities when |
| 3752 | // we detect the last one is finishing to keep them in sync. |
| 3753 | if (task.onlyHasTaskOverlayActivities(true /* excludeFinishing */)) { |
| 3754 | for (ActivityRecord taskOverlay : task.mActivities) { |
| 3755 | if (!taskOverlay.mTaskOverlay) { |
| 3756 | continue; |
| 3757 | } |
| 3758 | prepareActivityHideTransitionAnimation(taskOverlay, transit); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3759 | } |
| 3760 | } |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3761 | return removedActivity; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3762 | } else { |
| 3763 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
| 3764 | } |
| 3765 | |
| 3766 | return false; |
| 3767 | } finally { |
| 3768 | mWindowManager.continueSurfaceLayout(); |
| 3769 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3770 | } |
| 3771 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3772 | private void prepareActivityHideTransitionAnimation(ActivityRecord r, int transit) { |
| 3773 | mWindowManager.prepareAppTransition(transit, false); |
| 3774 | r.setVisibility(false); |
| 3775 | mWindowManager.executeAppTransition(); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3776 | if (!mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(r)) { |
| 3777 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.add(r); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3778 | } |
| 3779 | } |
| 3780 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3781 | static final int FINISH_IMMEDIATELY = 0; |
| 3782 | static final int FINISH_AFTER_PAUSE = 1; |
| 3783 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3784 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3785 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3786 | // First things first: if this activity is currently visible, |
| 3787 | // and the resumed activity is not yet visible, then hold off on |
| 3788 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3789 | |
| 3790 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
| 3791 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 3792 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3793 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3794 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3795 | addToStopping(r, false /* scheduleIdle */, false /* idleDelayed */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3796 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3797 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3798 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3799 | r.state = STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3800 | if (oomAdj) { |
| 3801 | mService.updateOomAdjLocked(); |
| 3802 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3803 | return r; |
| 3804 | } |
| 3805 | |
| 3806 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3807 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3808 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3809 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3810 | if (mResumedActivity == r) { |
| 3811 | mResumedActivity = null; |
| 3812 | } |
| 3813 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3814 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3815 | r.state = ActivityState.FINISHING; |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3816 | final boolean finishingActivityInNonFocusedStack |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3817 | = r.getStack() != mStackSupervisor.getFocusedStack() |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3818 | && prevState == ActivityState.PAUSED && mode == FINISH_AFTER_VISIBLE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3819 | |
| 3820 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | ae30f30 | 2016-05-02 10:35:45 -0700 | [diff] [blame] | 3821 | || (prevState == ActivityState.PAUSED |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3822 | && (mode == FINISH_AFTER_PAUSE || mStackId == PINNED_STACK_ID)) |
| 3823 | || finishingActivityInNonFocusedStack |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3824 | || prevState == STOPPING |
| 3825 | || prevState == STOPPED |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3826 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3827 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3828 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3829 | |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3830 | if (finishingActivityInNonFocusedStack) { |
| 3831 | // Finishing activity that was in paused state and it was in not currently focused |
| 3832 | // stack, need to make something visible in its place. |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3833 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 3834 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3835 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3836 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3837 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3838 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3839 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3840 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3841 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3842 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3843 | |
| 3844 | // Need to go through the full pause cycle to get this |
| 3845 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3846 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3847 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3848 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3849 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3850 | return r; |
| 3851 | } |
| 3852 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3853 | void finishAllActivitiesLocked(boolean immediately) { |
| 3854 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3855 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3856 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3857 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3858 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3859 | noActivitiesInStack = false; |
| 3860 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3861 | continue; |
| 3862 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3863 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3864 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3865 | } |
| 3866 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3867 | if (noActivitiesInStack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3868 | remove(); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3869 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3870 | } |
| 3871 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3872 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3873 | // Basic case: for simple app-centric recents, we need to recreate |
| 3874 | // the task if the affinity has changed. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3875 | if (srec == null || srec.getTask().affinity == null || |
| 3876 | !srec.getTask().affinity.equals(destAffinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3877 | return true; |
| 3878 | } |
| 3879 | // Document-centric case: an app may be split in to multiple documents; |
| 3880 | // they need to re-create their task if this current activity is the root |
| 3881 | // of a document, unless simply finishing it will return them to the the |
| 3882 | // correct app behind. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3883 | final TaskRecord task = srec.getTask(); |
| 3884 | if (srec.frontOfTask && task != null && task.getBaseIntent() != null |
| 3885 | && task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3886 | // Okay, this activity is at the root of its task. What to do, what to do... |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3887 | if (task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3888 | // Finishing won't return to an application, so we need to recreate. |
| 3889 | return true; |
| 3890 | } |
| 3891 | // We now need to get the task below it to determine what to do. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3892 | int taskIdx = mTaskHistory.indexOf(task); |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3893 | if (taskIdx <= 0) { |
| 3894 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3895 | return false; |
| 3896 | } |
| 3897 | if (taskIdx == 0) { |
| 3898 | // At the bottom of the stack, nothing to go back to. |
| 3899 | return true; |
| 3900 | } |
| 3901 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3902 | if (!task.affinity.equals(prevTask.affinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3903 | // These are different apps, so need to recreate. |
| 3904 | return true; |
| 3905 | } |
| 3906 | } |
| 3907 | return false; |
| 3908 | } |
| 3909 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3910 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3911 | Intent resultData) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3912 | final TaskRecord task = srec.getTask(); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3913 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3914 | final int start = activities.indexOf(srec); |
| 3915 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3916 | return false; |
| 3917 | } |
| 3918 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3919 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3920 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3921 | final ComponentName dest = destIntent.getComponent(); |
| 3922 | if (start > 0 && dest != null) { |
| 3923 | for (int i = finishTo; i >= 0; i--) { |
| 3924 | ActivityRecord r = activities.get(i); |
| 3925 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3926 | r.info.name.equals(dest.getClassName())) { |
| 3927 | finishTo = i; |
| 3928 | parent = r; |
| 3929 | foundParentInTask = true; |
| 3930 | break; |
| 3931 | } |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | IActivityController controller = mService.mController; |
| 3936 | if (controller != null) { |
| 3937 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3938 | if (next != null) { |
| 3939 | // ask watcher if this is allowed |
| 3940 | boolean resumeOK = true; |
| 3941 | try { |
| 3942 | resumeOK = controller.activityResuming(next.packageName); |
| 3943 | } catch (RemoteException e) { |
| 3944 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3945 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | if (!resumeOK) { |
| 3949 | return false; |
| 3950 | } |
| 3951 | } |
| 3952 | } |
| 3953 | final long origId = Binder.clearCallingIdentity(); |
| 3954 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3955 | ActivityRecord r = activities.get(i); |
| 3956 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3957 | // Only return the supplied result for the first activity finished |
| 3958 | resultCode = Activity.RESULT_CANCELED; |
| 3959 | resultData = null; |
| 3960 | } |
| 3961 | |
| 3962 | if (parent != null && foundParentInTask) { |
| 3963 | final int parentLaunchMode = parent.info.launchMode; |
| 3964 | final int destIntentFlags = destIntent.getFlags(); |
| 3965 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3966 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3967 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3968 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3969 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3970 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3971 | } else { |
| 3972 | try { |
| 3973 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3974 | destIntent.getComponent(), 0, srec.userId); |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 3975 | int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, |
| 3976 | destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, |
| 3977 | null, parent.appToken, null, 0, -1, parent.launchedFromUid, |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 3978 | parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3979 | false, true, null, null, "navigateUpTo"); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3980 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3981 | } catch (RemoteException e) { |
| 3982 | foundParentInTask = false; |
| 3983 | } |
| 3984 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3985 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3986 | } |
| 3987 | } |
| 3988 | Binder.restoreCallingIdentity(origId); |
| 3989 | return foundParentInTask; |
| 3990 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3991 | |
| 3992 | /** |
| 3993 | * Remove any state associated with the {@link ActivityRecord}. This should be called whenever |
| 3994 | * an activity moves away from the stack. |
| 3995 | */ |
| 3996 | void onActivityRemovedFromStack(ActivityRecord r) { |
| 3997 | if (mResumedActivity == r) { |
| 3998 | mResumedActivity = null; |
| 3999 | } |
| 4000 | if (mPausingActivity == r) { |
| 4001 | mPausingActivity = null; |
| 4002 | } |
| 4003 | |
| 4004 | removeTimeoutsForActivityLocked(r); |
| 4005 | } |
| 4006 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4007 | /** |
| 4008 | * Perform the common clean-up of an activity record. This is called both |
| 4009 | * as part of destroyActivityLocked() (when destroying the client-side |
| 4010 | * representation) and cleaning things up as a result of its hosting |
| 4011 | * processing going away, in which case there is no remaining client-side |
| 4012 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4013 | * |
| 4014 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4015 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4016 | private void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, boolean setState) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4017 | onActivityRemovedFromStack(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4018 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4019 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4020 | r.frozenBeforeDestroy = false; |
| 4021 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4022 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4023 | 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] | 4024 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4025 | 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] | 4026 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4029 | // Inform supervisor the activity has been removed. |
| 4030 | mStackSupervisor.cleanupActivity(r); |
| 4031 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4032 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4033 | // Remove any pending results. |
| 4034 | if (r.finishing && r.pendingResults != null) { |
| 4035 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 4036 | PendingIntentRecord rec = apr.get(); |
| 4037 | if (rec != null) { |
| 4038 | mService.cancelIntentSenderLocked(rec, false); |
| 4039 | } |
| 4040 | } |
| 4041 | r.pendingResults = null; |
| 4042 | } |
| 4043 | |
| 4044 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4045 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4048 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4049 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 4050 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 4051 | // manager so it can update its bookkeeping. |
| 4052 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4055 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4056 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4057 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4058 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4059 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 4060 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4063 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4064 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4065 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4066 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 4067 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 4068 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4069 | r.takeFromHistory(); |
| 4070 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4071 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4072 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4073 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4074 | 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] | 4075 | r.app = null; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4076 | r.removeWindowContainer(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4077 | final TaskRecord task = r.getTask(); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4078 | final boolean lastActivity = task != null ? task.removeActivity(r) : false; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4079 | // If we are removing the last activity in the task, not including task overlay activities, |
| 4080 | // then fall through into the block below to remove the entire task itself |
| 4081 | final boolean onlyHasTaskOverlays = task != null |
| 4082 | ? task.onlyHasTaskOverlayActivities(false /* excludingFinishing */) : false; |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4083 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4084 | if (lastActivity || onlyHasTaskOverlays) { |
| 4085 | if (DEBUG_STACK) { |
| 4086 | Slog.i(TAG_STACK, |
| 4087 | "removeActivityFromHistoryLocked: last activity removed from " + this |
| 4088 | + " onlyHasTaskOverlays=" + onlyHasTaskOverlays); |
| 4089 | } |
| 4090 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4091 | if (mStackSupervisor.isFocusedStack(this) && task == topTask() && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4092 | task.isOverHomeStack()) { |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4093 | mStackSupervisor.moveHomeStackTaskToTop(reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 4094 | } |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4095 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4096 | // The following block can be executed multiple times if there is more than one overlay. |
| 4097 | // {@link ActivityStackSupervisor#removeTaskByIdLocked} handles this by reverse lookup |
| 4098 | // of the task by id and exiting early if not found. |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4099 | if (onlyHasTaskOverlays) { |
| 4100 | // When destroying a task, tell the supervisor to remove it so that any activity it |
| 4101 | // has can be cleaned up correctly. This is currently the only place where we remove |
| 4102 | // a task with the DESTROYING mode, so instead of passing the onlyHasTaskOverlays |
| 4103 | // state into removeTask(), we just clear the task here before the other residual |
| 4104 | // work. |
| 4105 | // TODO: If the callers to removeTask() changes such that we have multiple places |
| 4106 | // where we are destroying the task, move this back into removeTask() |
| 4107 | mStackSupervisor.removeTaskByIdLocked(task.taskId, false /* killProcess */, |
| 4108 | !REMOVE_FROM_RECENTS, PAUSE_IMMEDIATELY); |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4109 | } |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4110 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4111 | // We must keep the task around until all activities are destroyed. The following |
| 4112 | // statement will only execute once since overlays are also considered activities. |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4113 | if (lastActivity) { |
| 4114 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
| 4115 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 4116 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4117 | cleanUpActivityServicesLocked(r); |
| 4118 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4119 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4120 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4121 | /** |
| 4122 | * Perform clean-up of service connections in an activity record. |
| 4123 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4124 | private void cleanUpActivityServicesLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4125 | // Throw away any services that have been bound by this activity. |
| 4126 | if (r.connections != null) { |
| 4127 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 4128 | while (it.hasNext()) { |
| 4129 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 4130 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4131 | } |
| 4132 | r.connections = null; |
| 4133 | } |
| 4134 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4135 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4136 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4137 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4138 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4139 | mHandler.sendMessage(msg); |
| 4140 | } |
| 4141 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4142 | private void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4143 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4144 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4145 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4146 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4147 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4148 | final ActivityRecord r = activities.get(activityNdx); |
| 4149 | if (r.finishing) { |
| 4150 | continue; |
| 4151 | } |
| 4152 | if (r.fullscreen) { |
| 4153 | lastIsOpaque = true; |
| 4154 | } |
| 4155 | if (owner != null && r.app != owner) { |
| 4156 | continue; |
| 4157 | } |
| 4158 | if (!lastIsOpaque) { |
| 4159 | continue; |
| 4160 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4161 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4162 | 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] | 4163 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4164 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4165 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4166 | activityRemoved = true; |
| 4167 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4168 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4169 | } |
| 4170 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4171 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4172 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4173 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4176 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 4177 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4178 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4179 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4180 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4181 | return destroyActivityLocked(r, true, reason); |
| 4182 | } |
| 4183 | return false; |
| 4184 | } |
| 4185 | |
| 4186 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 4187 | String reason) { |
| 4188 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4189 | 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] | 4190 | int maxTasks = tasks.size() / 4; |
| 4191 | if (maxTasks < 1) { |
| 4192 | maxTasks = 1; |
| 4193 | } |
| 4194 | int numReleased = 0; |
| 4195 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 4196 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 4197 | if (!tasks.contains(task)) { |
| 4198 | continue; |
| 4199 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4200 | 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] | 4201 | int curNum = 0; |
| 4202 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4203 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 4204 | final ActivityRecord activity = activities.get(actNdx); |
| 4205 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4206 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4207 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 4208 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4209 | destroyActivityLocked(activity, true, reason); |
| 4210 | if (activities.get(actNdx) != activity) { |
| 4211 | // Was removed from list, back up so we don't miss the next one. |
| 4212 | actNdx--; |
| 4213 | } |
| 4214 | curNum++; |
| 4215 | } |
| 4216 | } |
| 4217 | if (curNum > 0) { |
| 4218 | numReleased += curNum; |
| 4219 | maxTasks--; |
| 4220 | if (mTaskHistory.get(taskNdx) != task) { |
| 4221 | // The entire task got removed, back up so we don't miss the next one. |
| 4222 | taskNdx--; |
| 4223 | } |
| 4224 | } |
| 4225 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4226 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 4227 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4228 | return numReleased; |
| 4229 | } |
| 4230 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4231 | /** |
| 4232 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 4233 | * called both when actually finishing an activity, or when performing |
| 4234 | * a configuration switch where we destroy the current client-side object |
| 4235 | * but then create a new client-side object for this same HistoryRecord. |
| 4236 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4237 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4238 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 4239 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4240 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4241 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4242 | r.userId, System.identityHashCode(r), |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4243 | r.getTask().taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4244 | |
| 4245 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4246 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4247 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4248 | |
| 4249 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4250 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4251 | if (hadApp) { |
| 4252 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4253 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4254 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 4255 | mService.mHeavyWeightProcess = null; |
| 4256 | mService.mHandler.sendEmptyMessage( |
| 4257 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 4258 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4259 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 4260 | // Update any services we are bound to that might care about whether |
| 4261 | // their client may have activities. |
| 4262 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 4263 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 4264 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4265 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4270 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4271 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4272 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4273 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4274 | r.configChangeFlags); |
| 4275 | } catch (Exception e) { |
| 4276 | // We can just ignore exceptions here... if the process |
| 4277 | // has crashed, our death notification will clean things |
| 4278 | // up. |
| 4279 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 4280 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4281 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4282 | removedFromHistory = true; |
| 4283 | skipDestroy = true; |
| 4284 | } |
| 4285 | } |
| 4286 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4287 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4288 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4289 | // If the activity is finishing, we need to wait on removing it |
| 4290 | // from the list to give it a chance to do its cleanup. During |
| 4291 | // that time it may make calls back with its token so we need to |
| 4292 | // be able to find it on the list and so we don't want to remove |
| 4293 | // it from the list yet. Otherwise, we can just immediately put |
| 4294 | // it in the destroyed state since we are not removing it from the |
| 4295 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4296 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4297 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4298 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4299 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4300 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4301 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4302 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4303 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4304 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4305 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4306 | 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] | 4307 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4308 | } |
| 4309 | } else { |
| 4310 | // remove this record from the history. |
| 4311 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4312 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4313 | removedFromHistory = true; |
| 4314 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4315 | 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] | 4316 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4317 | 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] | 4318 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4319 | } |
| 4320 | } |
| 4321 | |
| 4322 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4323 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4324 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4325 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4326 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4327 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4328 | return removedFromHistory; |
| 4329 | } |
| 4330 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4331 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4332 | final long origId = Binder.clearCallingIdentity(); |
| 4333 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4334 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4335 | if (r != null) { |
| 4336 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4337 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4338 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4339 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4340 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4341 | if (r.state == ActivityState.DESTROYING) { |
| 4342 | cleanUpActivityLocked(r, true, false); |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4343 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4344 | } |
| 4345 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4346 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4347 | } finally { |
| 4348 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4349 | } |
| 4350 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4351 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4352 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 4353 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4354 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4355 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4356 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4357 | while (i > 0) { |
| 4358 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4359 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4360 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4361 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4362 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4363 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4364 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4369 | private boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4370 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4371 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4372 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4373 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4374 | "mGoingToSleepActivities"); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4375 | removeHistoryRecordsForAppLocked(mStackSupervisor.mActivitiesWaitingForVisibleActivity, app, |
| 4376 | "mActivitiesWaitingForVisibleActivity"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4377 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4378 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4379 | |
| 4380 | boolean hasVisibleActivities = false; |
| 4381 | |
| 4382 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4383 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4384 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4385 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4386 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4387 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4388 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4389 | final ActivityRecord r = activities.get(activityNdx); |
| 4390 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4391 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4392 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4393 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4394 | if (r.visible) { |
| 4395 | hasVisibleActivities = true; |
| 4396 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4397 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4398 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 4399 | // Don't currently have state for the activity, or |
| 4400 | // it is finishing -- always remove it. |
| 4401 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4402 | } else if (!r.visible && r.launchCount > 2 && |
| 4403 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4404 | // We have launched this activity too many times since it was |
| 4405 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4406 | // (Note if the activity is visible, we don't remove the record. |
| 4407 | // We leave the dead window on the screen but the process will |
| 4408 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4409 | remove = true; |
| 4410 | } else { |
| 4411 | // The process may be gone, but the activity lives on! |
| 4412 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4413 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4414 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4415 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4416 | "Removing activity " + r + " from stack at " + i |
| 4417 | + ": haveState=" + r.haveState |
| 4418 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4419 | + " finishing=" + r.finishing |
| 4420 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4421 | if (!r.finishing) { |
| 4422 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4423 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 4424 | r.userId, System.identityHashCode(r), |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4425 | r.getTask().taskId, r.shortComponentName, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4426 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 4427 | if (r.state == ActivityState.RESUMED) { |
| 4428 | mService.updateUsageStats(r, false); |
| 4429 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4430 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4431 | } else { |
| 4432 | // We have the current state for this activity, so |
| 4433 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4434 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4435 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4436 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4437 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4438 | // Set nowVisible to previous visible state. If the app was visible while |
| 4439 | // it died, we leave the dead window on screen so it's basically visible. |
| 4440 | // This is needed when user later tap on the dead window, we need to stop |
| 4441 | // other apps when user transfers focus to the restarted activity. |
| 4442 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4443 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4444 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4445 | "App died, clearing saved state of " + r); |
| 4446 | r.icicle = null; |
| 4447 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4448 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4449 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4450 | if (remove) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4451 | removeActivityFromHistoryLocked(r, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4452 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4453 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4458 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4459 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4460 | private void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4461 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4462 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4463 | if (r != null && r.state != ActivityState.RESUMED) { |
| 4464 | r.updateOptionsLocked(options); |
| 4465 | } else { |
| 4466 | ActivityOptions.abort(options); |
| 4467 | } |
| 4468 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4469 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4470 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4471 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4472 | private void updateTaskMovement(TaskRecord task, boolean toFront) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4473 | if (task.isPersistable) { |
| 4474 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4475 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4476 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4477 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4478 | if (!toFront) { |
| 4479 | task.mLastTimeMoved *= -1; |
| 4480 | } |
| 4481 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 4482 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4485 | void moveHomeStackTaskToTop() { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4486 | final int top = mTaskHistory.size() - 1; |
| 4487 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 4488 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4489 | if (task.taskType == HOME_ACTIVITY_TYPE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4490 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 4491 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4492 | mTaskHistory.remove(taskNdx); |
| 4493 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4494 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4495 | return; |
| 4496 | } |
| 4497 | } |
| 4498 | } |
| 4499 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 4500 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4501 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4502 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4503 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4504 | final ActivityStack topStack = getTopStackOnDisplay(); |
| 4505 | final ActivityRecord topActivity = topStack != null ? topStack.topActivity() : null; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4506 | final int numTasks = mTaskHistory.size(); |
| 4507 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4508 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4509 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4510 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4511 | ActivityOptions.abort(options); |
| 4512 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4513 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4514 | } |
| 4515 | return; |
| 4516 | } |
| 4517 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4518 | if (timeTracker != null) { |
| 4519 | // The caller wants a time tracker associated with this task. |
| 4520 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4521 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4522 | } |
| 4523 | } |
| 4524 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4525 | // Shift all activities with this task up to the top |
| 4526 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4527 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4528 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4529 | // Don't refocus if invisible to current user |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4530 | final ActivityRecord top = tr.getTopActivity(); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 4531 | if (top == null || !top.okToShowLocked()) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4532 | addRecentActivityLocked(top); |
| 4533 | ActivityOptions.abort(options); |
| 4534 | return; |
| 4535 | } |
| 4536 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4537 | // Set focus to the top running activity of this stack. |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4538 | final ActivityRecord r = topRunningActivityLocked(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 4539 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4540 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4541 | 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] | 4542 | if (noAnimation) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4543 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4544 | if (r != null) { |
| 4545 | mNoAnimActivities.add(r); |
| 4546 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4547 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4548 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4549 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4550 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 4551 | // If a new task is moved to the front, then mark the existing top activity as supporting |
Winson Chung | 942a85c | 2017-07-11 15:07:45 -0700 | [diff] [blame] | 4552 | // picture-in-picture while paused only if the task would not be considered an oerlay on top |
| 4553 | // of the current activity (eg. not fullscreen, or the assistant) |
Winson Chung | 4aede8a | 2017-07-05 12:23:25 -0700 | [diff] [blame] | 4554 | if (topActivity != null && topActivity.getStackId() != PINNED_STACK_ID |
Winson Chung | 942a85c | 2017-07-11 15:07:45 -0700 | [diff] [blame] | 4555 | && tr.getStackId() != ASSISTANT_STACK_ID && tr.containsOnlyFullscreenActivities()) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4556 | topActivity.supportsPictureInPictureWhilePausing = true; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 4557 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 4558 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4559 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 4560 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 4561 | |
| 4562 | mService.mTaskChangeNotificationController.notifyTaskMovedToFront(tr.taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4563 | } |
| 4564 | |
| 4565 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4566 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4567 | * 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] | 4568 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4569 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4570 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4571 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4572 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4573 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4574 | * @return Returns true if the move completed, false if not. |
| 4575 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4576 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4577 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4578 | if (tr == null) { |
| 4579 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4580 | return false; |
| 4581 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4582 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4583 | |
| 4584 | // If the task is locked, then show the lock task toast |
| 4585 | if (mStackSupervisor.isLockedTask(tr)) { |
| 4586 | mStackSupervisor.showLockTaskToast(); |
| 4587 | return false; |
| 4588 | } |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4589 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4590 | // If we have a watcher, preflight the move before committing to it. First check |
| 4591 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4592 | // current task to be selected. |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 4593 | if (mStackSupervisor.isFrontStackOnDisplay(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4594 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4595 | if (next == null) { |
| 4596 | next = topRunningActivityLocked(null, 0); |
| 4597 | } |
| 4598 | if (next != null) { |
| 4599 | // ask watcher if this is allowed |
| 4600 | boolean moveOK = true; |
| 4601 | try { |
| 4602 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4603 | } catch (RemoteException e) { |
| 4604 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4605 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4606 | } |
| 4607 | if (!moveOK) { |
| 4608 | return false; |
| 4609 | } |
| 4610 | } |
| 4611 | } |
| 4612 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4613 | 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] | 4614 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4615 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4616 | |
| 4617 | // If true, we should resume the home activity next if the task we are moving to the |
| 4618 | // back is over the home stack. We force to false if the task we are moving to back |
| 4619 | // is the home task and we don't want it resumed after moving to the back. |
| 4620 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4621 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4622 | final TaskRecord nextTask = getNextTask(tr); |
| 4623 | if (nextTask != null) { |
| 4624 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4625 | } else { |
| 4626 | prevIsHome = true; |
| 4627 | } |
| 4628 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4629 | |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4630 | boolean requiresMove = mTaskHistory.indexOf(tr) != 0; |
| 4631 | if (requiresMove) { |
| 4632 | mTaskHistory.remove(tr); |
| 4633 | mTaskHistory.add(0, tr); |
| 4634 | updateTaskMovement(tr, false); |
| 4635 | |
| 4636 | mWindowManager.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
| 4637 | mWindowContainerController.positionChildAtBottom(tr.getWindowContainerController()); |
| 4638 | } |
| 4639 | |
| 4640 | if (mStackId == PINNED_STACK_ID) { |
| 4641 | mStackSupervisor.removeStackLocked(PINNED_STACK_ID); |
| 4642 | return true; |
| 4643 | } |
| 4644 | |
| 4645 | // Otherwise, there is an assumption that moving a task to the back moves it behind the |
| 4646 | // home activity. 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] | 4647 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4648 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4649 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4650 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4651 | break; |
| 4652 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4653 | if (taskNdx == 1) { |
| 4654 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4655 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4656 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4657 | } |
| 4658 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4659 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.getTask() : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4660 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4661 | if (!mService.mBooting && !mService.mBooted) { |
| 4662 | // Not ready yet! |
| 4663 | return false; |
| 4664 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4665 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4666 | return mStackSupervisor.resumeHomeStackTask(null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4667 | } |
| 4668 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4669 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4670 | return true; |
| 4671 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4672 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4673 | /** |
| 4674 | * Get the topmost stack on the current display. It may be different from focused stack, because |
| 4675 | * focus may be on another display. |
| 4676 | */ |
| 4677 | private ActivityStack getTopStackOnDisplay() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4678 | final ArrayList<ActivityStack> stacks = getDisplay().mStacks; |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4679 | return stacks.isEmpty() ? null : stacks.get(stacks.size() - 1); |
| 4680 | } |
| 4681 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4682 | static void logStartActivity(int tag, ActivityRecord r, TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4683 | final Uri data = r.intent.getData(); |
| 4684 | final String strData = data != null ? data.toSafeString() : null; |
| 4685 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4686 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4687 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4688 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4689 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4693 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 4694 | */ |
| 4695 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 4696 | if (start == null || !start.visible) { |
| 4697 | return; |
| 4698 | } |
| 4699 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4700 | final TaskRecord startTask = start.getTask(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4701 | boolean behindFullscreen = false; |
| 4702 | boolean updatedConfig = false; |
| 4703 | |
| 4704 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 4705 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 4706 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4707 | int activityIndex = |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4708 | (start.getTask() == task) ? activities.indexOf(start) : activities.size() - 1; |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4709 | for (; activityIndex >= 0; --activityIndex) { |
| 4710 | final ActivityRecord r = activities.get(activityIndex); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4711 | updatedConfig |= r.ensureActivityConfigurationLocked(0 /* globalChanges */, |
| 4712 | preserveWindow); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4713 | if (r.fullscreen) { |
| 4714 | behindFullscreen = true; |
| 4715 | break; |
| 4716 | } |
| 4717 | } |
| 4718 | if (behindFullscreen) { |
| 4719 | break; |
| 4720 | } |
| 4721 | } |
| 4722 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 4723 | // Ensure the resumed state of the focus activity if we updated the configuration of |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4724 | // any activity. |
| 4725 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4726 | } |
| 4727 | } |
| 4728 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4729 | // TODO: Figure-out a way to consolidate with resize() method below. |
| 4730 | @Override |
| 4731 | public void requestResize(Rect bounds) { |
| 4732 | mService.resizeStack(mStackId, bounds, true /* allowResizeInDockedMode */, |
| 4733 | false /* preserveWindows */, false /* animate */, -1 /* animationDuration */); |
| 4734 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4735 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4736 | // TODO: Can only be called from special methods in ActivityStackSupervisor. |
| 4737 | // Need to consolidate those calls points into this resize method so anyone can call directly. |
| 4738 | void resize(Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds) { |
| 4739 | bounds = TaskRecord.validateBounds(bounds); |
| 4740 | |
| 4741 | if (!updateBoundsAllowed(bounds, tempTaskBounds, tempTaskInsetBounds)) { |
| 4742 | return; |
| 4743 | } |
| 4744 | |
| 4745 | // Update override configurations of all tasks in the stack. |
| 4746 | final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : bounds; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4747 | final Rect insetBounds = tempTaskInsetBounds != null ? tempTaskInsetBounds : taskBounds; |
| 4748 | |
| 4749 | mTmpBounds.clear(); |
| 4750 | mTmpConfigs.clear(); |
| 4751 | mTmpInsetBounds.clear(); |
| 4752 | |
| 4753 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 4754 | final TaskRecord task = mTaskHistory.get(i); |
| 4755 | if (task.isResizeable()) { |
| 4756 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 4757 | // For freeform stack we don't adjust the size of the tasks to match that |
| 4758 | // of the stack, but we do try to make sure the tasks are still contained |
| 4759 | // with the bounds of the stack. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4760 | mTmpRect2.set(task.mBounds); |
| 4761 | fitWithinBounds(mTmpRect2, bounds); |
| 4762 | task.updateOverrideConfiguration(mTmpRect2); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4763 | } else { |
| 4764 | task.updateOverrideConfiguration(taskBounds, insetBounds); |
| 4765 | } |
| 4766 | } |
| 4767 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 4768 | mTmpConfigs.put(task.taskId, task.getOverrideConfiguration()); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4769 | mTmpBounds.put(task.taskId, task.mBounds); |
| 4770 | if (tempTaskInsetBounds != null) { |
| 4771 | mTmpInsetBounds.put(task.taskId, tempTaskInsetBounds); |
| 4772 | } |
| 4773 | } |
| 4774 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4775 | mFullscreen = mWindowContainerController.resize(bounds, mTmpConfigs, mTmpBounds, |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4776 | mTmpInsetBounds); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4777 | setBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | |
| 4781 | /** |
| 4782 | * Adjust bounds to stay within stack bounds. |
| 4783 | * |
| 4784 | * Since bounds might be outside of stack bounds, this method tries to move the bounds in a way |
| 4785 | * that keep them unchanged, but be contained within the stack bounds. |
| 4786 | * |
| 4787 | * @param bounds Bounds to be adjusted. |
| 4788 | * @param stackBounds Bounds within which the other bounds should remain. |
| 4789 | */ |
| 4790 | private static void fitWithinBounds(Rect bounds, Rect stackBounds) { |
| 4791 | if (stackBounds == null || stackBounds.contains(bounds)) { |
| 4792 | return; |
| 4793 | } |
| 4794 | |
| 4795 | if (bounds.left < stackBounds.left || bounds.right > stackBounds.right) { |
| 4796 | final int maxRight = stackBounds.right |
| 4797 | - (stackBounds.width() / FIT_WITHIN_BOUNDS_DIVIDER); |
| 4798 | int horizontalDiff = stackBounds.left - bounds.left; |
| 4799 | if ((horizontalDiff < 0 && bounds.left >= maxRight) |
| 4800 | || (bounds.left + horizontalDiff >= maxRight)) { |
| 4801 | horizontalDiff = maxRight - bounds.left; |
| 4802 | } |
| 4803 | bounds.left += horizontalDiff; |
| 4804 | bounds.right += horizontalDiff; |
| 4805 | } |
| 4806 | |
| 4807 | if (bounds.top < stackBounds.top || bounds.bottom > stackBounds.bottom) { |
| 4808 | final int maxBottom = stackBounds.bottom |
| 4809 | - (stackBounds.height() / FIT_WITHIN_BOUNDS_DIVIDER); |
| 4810 | int verticalDiff = stackBounds.top - bounds.top; |
| 4811 | if ((verticalDiff < 0 && bounds.top >= maxBottom) |
| 4812 | || (bounds.top + verticalDiff >= maxBottom)) { |
| 4813 | verticalDiff = maxBottom - bounds.top; |
| 4814 | } |
| 4815 | bounds.top += verticalDiff; |
| 4816 | bounds.bottom += verticalDiff; |
| 4817 | } |
| 4818 | } |
| 4819 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4820 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4821 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4822 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4823 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4824 | final ActivityRecord r = activities.get(activityNdx); |
| 4825 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4826 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4827 | } |
| 4828 | if (r.fullscreen && !r.finishing) { |
| 4829 | return false; |
| 4830 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4831 | } |
| 4832 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4833 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4834 | if (r == null) { |
| 4835 | return false; |
| 4836 | } |
| 4837 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4838 | + " would have returned true for r=" + r); |
| 4839 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4843 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4844 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4845 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4846 | final ActivityRecord r = activities.get(activityNdx); |
| 4847 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4848 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4849 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4850 | } |
| 4851 | } |
| 4852 | } |
| 4853 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4854 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4855 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4856 | boolean didSomething = false; |
| 4857 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4858 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4859 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4860 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4861 | int numActivities = activities.size(); |
| 4862 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4863 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4864 | final boolean sameComponent = |
| 4865 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4866 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4867 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4868 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4869 | && (sameComponent || r.getTask() == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4870 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4871 | if (!doit) { |
| 4872 | if (r.finishing) { |
| 4873 | // If this activity is just finishing, then it is not |
| 4874 | // interesting as far as something to stop. |
| 4875 | continue; |
| 4876 | } |
| 4877 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4878 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4879 | if (r.isHomeActivity()) { |
| 4880 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4881 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4882 | continue; |
| 4883 | } else { |
| 4884 | homeActivity = r.realActivity; |
| 4885 | } |
| 4886 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4887 | didSomething = true; |
| 4888 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4889 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4890 | if (r.app != null) { |
| 4891 | r.app.removed = true; |
| 4892 | } |
| 4893 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4894 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4895 | lastTask = r.getTask(); |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4896 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4897 | true)) { |
| 4898 | // r has been deleted from mActivities, accommodate. |
| 4899 | --numActivities; |
| 4900 | --activityNdx; |
| 4901 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4902 | } |
| 4903 | } |
| 4904 | } |
| 4905 | return didSomething; |
| 4906 | } |
| 4907 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4908 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4909 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4910 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4911 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4912 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4913 | if (task.getTopActivity() == null) { |
| 4914 | continue; |
| 4915 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4916 | ActivityRecord r = null; |
| 4917 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4918 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4919 | int numActivities = 0; |
| 4920 | int numRunning = 0; |
| 4921 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4922 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4923 | continue; |
| 4924 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4925 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4926 | tmp = activities.get(activityNdx); |
| 4927 | if (tmp.finishing) { |
| 4928 | continue; |
| 4929 | } |
| 4930 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4931 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4932 | // Initialize state for next task if needed. |
| 4933 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4934 | top = r; |
| 4935 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4936 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4937 | |
| 4938 | // Add 'r' into the current task. |
| 4939 | numActivities++; |
| 4940 | if (r.app != null && r.app.thread != null) { |
| 4941 | numRunning++; |
| 4942 | } |
| 4943 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4944 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4945 | TAG, r.intent.getComponent().flattenToShortString() |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4946 | + ": task=" + r.getTask()); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4947 | } |
| 4948 | |
| 4949 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4950 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4951 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4952 | ci.baseActivity = r.intent.getComponent(); |
| 4953 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4954 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4955 | if (focusedStack && topTask) { |
| 4956 | // Give the latest time to ensure foreground task can be sorted |
| 4957 | // at the first, because lastActiveTime of creating task is 0. |
| 4958 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4959 | topTask = false; |
| 4960 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4961 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4962 | if (top.getTask() != null) { |
| 4963 | ci.description = top.getTask().lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4964 | } |
| 4965 | ci.numActivities = numActivities; |
| 4966 | ci.numRunning = numRunning; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4967 | ci.supportsSplitScreenMultiWindow = task.supportsSplitScreen(); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 4968 | ci.resizeMode = task.mResizeMode; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4969 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4970 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4971 | } |
| 4972 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4973 | void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4974 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4975 | 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] | 4976 | if (top >= 0) { |
| 4977 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4978 | int activityTop = activities.size() - 1; |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 4979 | if (activityTop >= 0) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4980 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4981 | "unhandled-back", true); |
| 4982 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4983 | } |
| 4984 | } |
| 4985 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4986 | /** |
| 4987 | * Reset local parameters because an app's activity died. |
| 4988 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4989 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4990 | */ |
| 4991 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4992 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4993 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4994 | "App died while pausing: " + mPausingActivity); |
| 4995 | mPausingActivity = null; |
| 4996 | } |
| 4997 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4998 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4999 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5000 | } |
| 5001 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5002 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5003 | } |
| 5004 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5005 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5006 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5007 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5008 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5009 | final ActivityRecord r = activities.get(activityNdx); |
| 5010 | if (r.app == app) { |
| 5011 | Slog.w(TAG, " Force finishing activity " |
| 5012 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 5013 | // Force the destroy to skip right to removal. |
| 5014 | r.app = null; |
| 5015 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5016 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5017 | } |
| 5018 | } |
| 5019 | } |
| 5020 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5021 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5022 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5023 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5024 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5025 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5026 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 5027 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5028 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 5029 | " Task id #" + task.taskId + "\n" + |
| 5030 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 5031 | " mBounds=" + task.mBounds + "\n" + |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 5032 | " mMinWidth=" + task.mMinWidth + "\n" + |
| 5033 | " mMinHeight=" + task.mMinHeight + "\n" + |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 5034 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5035 | if (printed) { |
| 5036 | header = null; |
| 5037 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5038 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5039 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 5043 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5044 | |
| 5045 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5046 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5047 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5048 | } |
| 5049 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5050 | final int top = mTaskHistory.size() - 1; |
| 5051 | if (top >= 0) { |
| 5052 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5053 | int listTop = list.size() - 1; |
| 5054 | if (listTop >= 0) { |
| 5055 | activities.add(list.get(listTop)); |
| 5056 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5057 | } |
| 5058 | } else { |
| 5059 | ItemMatcher matcher = new ItemMatcher(); |
| 5060 | matcher.build(name); |
| 5061 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5062 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5063 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5064 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5065 | activities.add(r1); |
| 5066 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | } |
| 5070 | |
| 5071 | return activities; |
| 5072 | } |
| 5073 | |
| 5074 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5075 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5076 | |
| 5077 | // All activities that came from the package must be |
| 5078 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5079 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5080 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5081 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5082 | final ActivityRecord a = activities.get(activityNdx); |
| 5083 | if (a.info.packageName.equals(packageName)) { |
| 5084 | a.forceNewConfig = true; |
| 5085 | if (starting != null && a == starting && a.visible) { |
| 5086 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5087 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5088 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5089 | } |
| 5090 | } |
| 5091 | } |
| 5092 | |
| 5093 | return starting; |
| 5094 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5095 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5096 | /** |
| 5097 | * Removes the input task from this stack. |
| 5098 | * @param task to remove. |
| 5099 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5100 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5101 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5102 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5103 | void removeTask(TaskRecord task, String reason, int mode) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 5104 | for (ActivityRecord record : task.mActivities) { |
| 5105 | onActivityRemovedFromStack(record); |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5106 | } |
| 5107 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5108 | final int taskNdx = mTaskHistory.indexOf(task); |
| 5109 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 5110 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 5111 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 5112 | if (!nextTask.isOverHomeStack() && !nextTask.isOverAssistantStack()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 5113 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 5114 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5115 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5116 | mTaskHistory.remove(task); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5117 | removeActivitiesFromLRUListLocked(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5118 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5119 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5120 | if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5121 | // TODO: VI what about activity? |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5122 | final boolean isVoiceSession = task.voiceSession != null; |
| 5123 | if (isVoiceSession) { |
| 5124 | try { |
| 5125 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 5126 | } catch (RemoteException e) { |
| 5127 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 5128 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5129 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 5130 | // Task creator asked to remove this when done, or this task was a voice |
| 5131 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 5132 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 5133 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5134 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 5135 | |
| 5136 | task.removeWindowContainer(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5137 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5138 | |
| 5139 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5140 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5141 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5142 | // process of moving the task to the top of the stack that will be focused. |
| 5143 | if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
| 5144 | && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5145 | String myReason = reason + " leftTaskHistoryEmpty"; |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 5146 | if (mFullscreen || !adjustFocusToNextFocusableStackLocked(myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5147 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5148 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5149 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5150 | if (mStacks != null) { |
| 5151 | mStacks.remove(this); |
| 5152 | mStacks.add(0, this); |
| 5153 | } |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 5154 | if (!isHomeOrRecentsStack()) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 5155 | remove(); |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5156 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5157 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5158 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5159 | task.setStack(null); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5160 | |
| 5161 | // Notify if a task from the pinned stack is being removed (or moved depending on the mode) |
| 5162 | if (mStackId == PINNED_STACK_ID) { |
| 5163 | mService.mTaskChangeNotificationController.notifyActivityUnpinned(); |
| 5164 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5165 | } |
| 5166 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5167 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5168 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 5169 | boolean toTop, int type) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5170 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 5171 | voiceInteractor, type); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5172 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5173 | addTask(task, toTop, "createTaskRecord"); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 5174 | final boolean isLockscreenShown = |
| 5175 | mService.mStackSupervisor.mKeyguardController.isKeyguardShowing(); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5176 | if (!layoutTaskInStack(task, info.windowLayout) && mBounds != null && task.isResizeable() |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 5177 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 5178 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5179 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5180 | task.createWindowContainer(toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5181 | return task; |
| 5182 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5183 | |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5184 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.WindowLayout windowLayout) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5185 | if (mTaskPositioner == null) { |
| 5186 | return false; |
| 5187 | } |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5188 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, windowLayout); |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5189 | return true; |
| 5190 | } |
| 5191 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5192 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5193 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5194 | } |
| 5195 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5196 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5197 | addTask(task, toTop ? MAX_VALUE : 0, true /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5198 | if (toTop) { |
| 5199 | // TODO: figure-out a way to remove this call. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5200 | mWindowContainerController.positionChildAtTop(task.getWindowContainerController(), |
| 5201 | true /* includingParents */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5202 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5203 | } |
| 5204 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5205 | // TODO: This shouldn't allow automatic reparenting. Remove the call to preAddTask and deal |
| 5206 | // with the fall-out... |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5207 | void addTask(final TaskRecord task, int position, boolean schedulePictureInPictureModeChange, |
| 5208 | String reason) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5209 | // TODO: Is this remove really needed? Need to look into the call path for the other addTask |
| 5210 | mTaskHistory.remove(task); |
| 5211 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
| 5212 | final boolean toTop = position >= mTaskHistory.size(); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5213 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5214 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5215 | mTaskHistory.add(position, task); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5216 | task.setStack(this); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5217 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5218 | if (toTop) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5219 | updateTaskReturnToForTopInsertion(task); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5220 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5221 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5222 | updateTaskMovement(task, toTop); |
| 5223 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5224 | postAddTask(task, prevStack, schedulePictureInPictureModeChange); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5225 | } |
| 5226 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5227 | void positionChildAt(TaskRecord task, int index) { |
| 5228 | |
| 5229 | if (task.getStack() != this) { |
| 5230 | throw new IllegalArgumentException("AS.positionChildAt: task=" + task |
| 5231 | + " is not a child of stack=" + this + " current parent=" + task.getStack()); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | task.updateOverrideConfigurationForStack(this); |
| 5235 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5236 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5237 | final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5238 | insertTaskAtPosition(task, index); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5239 | task.setStack(this); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5240 | postAddTask(task, null /* prevStack */, true /* schedulePictureInPictureModeChange */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5241 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5242 | if (wasResumed) { |
| 5243 | if (mResumedActivity != null) { |
| 5244 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5245 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5246 | + " other mResumedActivity=" + topRunningActivity); |
| 5247 | } |
| 5248 | mResumedActivity = topRunningActivity; |
| 5249 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5250 | |
| 5251 | // The task might have already been running and its visibility needs to be synchronized with |
| 5252 | // the visibility of the stack / windows. |
| 5253 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 5254 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5255 | } |
| 5256 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5257 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5258 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5259 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5260 | prevStack.removeTask(task, reason, |
| 5261 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5262 | } |
| 5263 | return prevStack; |
| 5264 | } |
| 5265 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5266 | /** |
| 5267 | * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode |
| 5268 | * change. Callers may set this to false if they are explicitly scheduling PiP mode |
| 5269 | * changes themselves, like during the PiP animation |
| 5270 | */ |
| 5271 | private void postAddTask(TaskRecord task, ActivityStack prevStack, |
| 5272 | boolean schedulePictureInPictureModeChange) { |
| 5273 | if (schedulePictureInPictureModeChange && prevStack != null) { |
| 5274 | mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5275 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5276 | try { |
| 5277 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5278 | } catch (RemoteException e) { |
| 5279 | } |
| 5280 | } |
| 5281 | } |
| 5282 | |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5283 | void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume, |
| 5284 | boolean setPause, String reason) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5285 | if (!moveToFront) { |
| 5286 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5287 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5288 | |
| 5289 | // If the activity owns the last resumed activity, transfer that together, |
| 5290 | // so that we don't resume the same activity again in the new stack. |
| 5291 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5292 | if (setResume) { |
| 5293 | mResumedActivity = r; |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5294 | updateLRUListLocked(r); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5295 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5296 | // If the activity was previously pausing, then ensure we transfer that as well |
| 5297 | if (setPause) { |
| 5298 | mPausingActivity = r; |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 5299 | schedulePauseTimeout(r); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5300 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5301 | // Move the stack in which we are placing the activity to the front. The call will also |
| 5302 | // make sure the activity focus is set. |
| 5303 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5304 | } |
| 5305 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5306 | public int getStackId() { |
| 5307 | return mStackId; |
| 5308 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5309 | |
| 5310 | @Override |
| 5311 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5312 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 5313 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5314 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5315 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5316 | void onLockTaskPackagesUpdatedLocked() { |
| 5317 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5318 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5319 | } |
| 5320 | } |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5321 | |
| 5322 | void executeAppTransition(ActivityOptions options) { |
| 5323 | mWindowManager.executeAppTransition(); |
| 5324 | mNoAnimActivities.clear(); |
| 5325 | ActivityOptions.abort(options); |
| 5326 | } |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5327 | |
| 5328 | boolean shouldSleepActivities() { |
| 5329 | final ActivityStackSupervisor.ActivityDisplay display = getDisplay(); |
| 5330 | return display != null ? display.isSleeping() : mService.isSleepingLocked(); |
| 5331 | } |
| 5332 | |
| 5333 | boolean shouldSleepOrShutDownActivities() { |
| 5334 | return shouldSleepActivities() || mService.isShuttingDownLocked(); |
| 5335 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5336 | } |