The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 20 | import static android.app.ActivityTaskManager.RESIZE_MODE_FORCED; |
| 21 | import static android.app.ActivityTaskManager.RESIZE_MODE_SYSTEM; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 29 | import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 30 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 31 | import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS; |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 32 | import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 33 | import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 34 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; |
| 35 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 36 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 37 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 38 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY; |
| 39 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY; |
| 40 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION; |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 41 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 42 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 43 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED; |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 44 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 45 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
Suprabh Shukla | 7745c14 | 2016-03-07 18:21:10 -0800 | [diff] [blame] | 46 | import static android.provider.Settings.Secure.USER_SETUP_COMPLETE; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 47 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 48 | |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 49 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 50 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK; |
| 51 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 52 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
| 53 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 54 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK; |
| 55 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 56 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 59 | import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 60 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 61 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING_TO_TOP; |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 62 | import static com.android.server.am.ActivityStackSupervisor.ON_TOP; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 63 | import static com.android.server.am.ActivityStackSupervisor.PAUSE_IMMEDIATELY; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 64 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 65 | import static com.android.server.am.TaskRecordProto.ACTIVITIES; |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 66 | import static com.android.server.am.TaskRecordProto.ACTIVITY_TYPE; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 67 | import static com.android.server.am.TaskRecordProto.BOUNDS; |
| 68 | import static com.android.server.am.TaskRecordProto.CONFIGURATION_CONTAINER; |
| 69 | import static com.android.server.am.TaskRecordProto.FULLSCREEN; |
| 70 | import static com.android.server.am.TaskRecordProto.ID; |
| 71 | import static com.android.server.am.TaskRecordProto.LAST_NON_FULLSCREEN_BOUNDS; |
| 72 | import static com.android.server.am.TaskRecordProto.MIN_HEIGHT; |
| 73 | import static com.android.server.am.TaskRecordProto.MIN_WIDTH; |
| 74 | import static com.android.server.am.TaskRecordProto.ORIG_ACTIVITY; |
| 75 | import static com.android.server.am.TaskRecordProto.REAL_ACTIVITY; |
| 76 | import static com.android.server.am.TaskRecordProto.RESIZE_MODE; |
| 77 | import static com.android.server.am.TaskRecordProto.STACK_ID; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 78 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 79 | import static java.lang.Integer.MAX_VALUE; |
| 80 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 81 | import android.annotation.IntDef; |
| 82 | import android.annotation.Nullable; |
| 83 | import android.app.Activity; |
| 84 | import android.app.ActivityManager; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 85 | import android.app.ActivityManager.TaskDescription; |
| 86 | import android.app.ActivityManager.TaskSnapshot; |
| 87 | import android.app.ActivityOptions; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 88 | import android.app.ActivityTaskManager; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 89 | import android.app.AppGlobals; |
Winson Chung | abfdcce | 2018-07-02 17:23:33 -0700 | [diff] [blame] | 90 | import android.app.TaskInfo; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 91 | import android.content.ComponentName; |
| 92 | import android.content.Intent; |
| 93 | import android.content.pm.ActivityInfo; |
| 94 | import android.content.pm.ApplicationInfo; |
| 95 | import android.content.pm.IPackageManager; |
| 96 | import android.content.pm.PackageManager; |
| 97 | import android.content.res.Configuration; |
| 98 | import android.graphics.Rect; |
| 99 | import android.os.Debug; |
| 100 | import android.os.RemoteException; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 101 | import android.os.SystemClock; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 102 | import android.os.Trace; |
| 103 | import android.os.UserHandle; |
| 104 | import android.provider.Settings; |
| 105 | import android.service.voice.IVoiceInteractionSession; |
| 106 | import android.util.DisplayMetrics; |
| 107 | import android.util.Slog; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 108 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 109 | |
| 110 | import com.android.internal.annotations.VisibleForTesting; |
| 111 | import com.android.internal.app.IVoiceInteractor; |
| 112 | import com.android.internal.util.XmlUtils; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 113 | import com.android.server.am.ActivityStack.ActivityState; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 114 | import com.android.server.wm.AppWindowContainerController; |
| 115 | import com.android.server.wm.ConfigurationContainer; |
| 116 | import com.android.server.wm.StackWindowController; |
| 117 | import com.android.server.wm.TaskWindowContainerController; |
| 118 | import com.android.server.wm.TaskWindowContainerListener; |
| 119 | import com.android.server.wm.WindowManagerService; |
| 120 | |
| 121 | import org.xmlpull.v1.XmlPullParser; |
| 122 | import org.xmlpull.v1.XmlPullParserException; |
| 123 | import org.xmlpull.v1.XmlSerializer; |
| 124 | |
| 125 | import java.io.IOException; |
| 126 | import java.io.PrintWriter; |
| 127 | import java.lang.annotation.Retention; |
| 128 | import java.lang.annotation.RetentionPolicy; |
| 129 | import java.util.ArrayList; |
| 130 | import java.util.Objects; |
| 131 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame^] | 132 | // TODO: Make package private again once move to WM package is complete. |
| 133 | public class TaskRecord extends ConfigurationContainer implements TaskWindowContainerListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 134 | private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 135 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 136 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 137 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 138 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 139 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 140 | private static final String ATTR_TASKID = "task_id"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 141 | private static final String TAG_INTENT = "intent"; |
| 142 | private static final String TAG_AFFINITYINTENT = "affinity_intent"; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 143 | private static final String ATTR_REALACTIVITY = "real_activity"; |
| 144 | private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 145 | private static final String ATTR_ORIGACTIVITY = "orig_activity"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 146 | private static final String TAG_ACTIVITY = "activity"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 147 | private static final String ATTR_AFFINITY = "affinity"; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 148 | private static final String ATTR_ROOT_AFFINITY = "root_affinity"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 149 | private static final String ATTR_ROOTHASRESET = "root_has_reset"; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 150 | private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 151 | private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode"; |
| 152 | private static final String ATTR_USERID = "user_id"; |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 153 | private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete"; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 154 | private static final String ATTR_EFFECTIVE_UID = "effective_uid"; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 155 | @Deprecated |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 156 | private static final String ATTR_TASKTYPE = "task_type"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 157 | private static final String ATTR_LASTDESCRIPTION = "last_description"; |
| 158 | private static final String ATTR_LASTTIMEMOVED = "last_time_moved"; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 159 | private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity"; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 160 | private static final String ATTR_TASK_AFFILIATION = "task_affiliation"; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 161 | private static final String ATTR_PREV_AFFILIATION = "prev_affiliation"; |
| 162 | private static final String ATTR_NEXT_AFFILIATION = "next_affiliation"; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 163 | private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color"; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 164 | private static final String ATTR_CALLING_UID = "calling_uid"; |
| 165 | private static final String ATTR_CALLING_PACKAGE = "calling_package"; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 166 | private static final String ATTR_SUPPORTS_PICTURE_IN_PICTURE = "supports_picture_in_picture"; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 167 | private static final String ATTR_RESIZE_MODE = "resize_mode"; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 168 | private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds"; |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 169 | private static final String ATTR_MIN_WIDTH = "min_width"; |
| 170 | private static final String ATTR_MIN_HEIGHT = "min_height"; |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 171 | private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version"; |
Andrii Kulian | 18d7512 | 2016-03-27 20:20:28 -0700 | [diff] [blame] | 172 | |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 173 | // Current version of the task record we persist. Used to check if we need to run any upgrade |
| 174 | // code. |
| 175 | private static final int PERSIST_TASK_VERSION = 1; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 176 | |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 177 | static final int INVALID_TASK_ID = -1; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 178 | private static final int INVALID_MIN_SIZE = -1; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 179 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 180 | /** |
| 181 | * The modes to control how the stack is moved to the front when calling |
| 182 | * {@link TaskRecord#reparent}. |
| 183 | */ |
| 184 | @Retention(RetentionPolicy.SOURCE) |
| 185 | @IntDef({ |
| 186 | REPARENT_MOVE_STACK_TO_FRONT, |
| 187 | REPARENT_KEEP_STACK_AT_FRONT, |
| 188 | REPARENT_LEAVE_STACK_IN_PLACE |
| 189 | }) |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 190 | @interface ReparentMoveStackMode {} |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 191 | // Moves the stack to the front if it was not at the front |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 192 | static final int REPARENT_MOVE_STACK_TO_FRONT = 0; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 193 | // Only moves the stack to the front if it was focused or front most already |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 194 | static final int REPARENT_KEEP_STACK_AT_FRONT = 1; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 195 | // Do not move the stack as a part of reparenting |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 196 | static final int REPARENT_LEAVE_STACK_IN_PLACE = 2; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 197 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 198 | /** |
| 199 | * The factory used to create {@link TaskRecord}. This allows OEM subclass {@link TaskRecord}. |
| 200 | */ |
| 201 | private static TaskRecordFactory sTaskRecordFactory; |
| 202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | final int taskId; // Unique identifier for this task. |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 204 | String affinity; // The affinity name for this task, or null; may change identity. |
| 205 | String rootAffinity; // Initial base affinity, or null; does not change from initial root. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 206 | final IVoiceInteractionSession voiceSession; // Voice interaction session driving task |
| 207 | final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 208 | Intent intent; // The original intent that started the task. Note that this value can |
| 209 | // be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | Intent affinityIntent; // Intent of affinity-moved activity that started this task. |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 211 | int effectiveUid; // The current effective uid of the identity of this task. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | ComponentName origActivity; // The non-alias activity component of the intent. |
| 213 | ComponentName realActivity; // The actual activity component that started the task. |
Andrei Stingaceanu | 4ccec53 | 2016-01-13 12:10:21 +0000 | [diff] [blame] | 214 | boolean realActivitySuspended; // True if the actual activity component that started the |
| 215 | // task is suspended. |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 216 | boolean inRecents; // Actually in the recents list? |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 217 | long lastActiveTime; // Last time this task was active in the current device session, |
| 218 | // including sleep. This time is initialized to the elapsed time when |
| 219 | // restored from disk. |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 220 | boolean isAvailable; // Is the activity available to be launched? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | boolean rootWasReset; // True if the intent at the root of the task had |
| 222 | // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 223 | boolean autoRemoveRecents; // If true, we should automatically remove the task from |
| 224 | // recents when activity finishes |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 225 | boolean askedCompatMode;// Have asked the user about compat mode for this task. |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 226 | boolean hasBeenVisible; // Set if any activities in the task have been visible to the user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 228 | String stringName; // caching of toString() result. |
Dianne Hackborn | 9da2d40 | 2012-03-15 13:43:08 -0700 | [diff] [blame] | 229 | int userId; // user for which this task was created |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 230 | boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity |
| 231 | // was changed. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 232 | |
| 233 | int numFullscreen; // Number of fullscreen activities. |
| 234 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 235 | int mResizeMode; // The resize mode of this task and its activities. |
| 236 | // Based on the {@link ActivityInfo#resizeMode} of the root activity. |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 237 | private boolean mSupportsPictureInPicture; // Whether or not this task and its activities |
| 238 | // support PiP. Based on the {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE} flag |
| 239 | // of the root activity. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 240 | /** Can't be put in lockTask mode. */ |
| 241 | final static int LOCK_TASK_AUTH_DONT_LOCK = 0; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 242 | /** Can enter app pinning with user approval. Can never start over existing lockTask task. */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 243 | final static int LOCK_TASK_AUTH_PINNABLE = 1; |
| 244 | /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */ |
| 245 | final static int LOCK_TASK_AUTH_LAUNCHABLE = 2; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 246 | /** Can enter lockTask without user approval. Can start over existing lockTask task. */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 247 | final static int LOCK_TASK_AUTH_WHITELISTED = 3; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 248 | /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing |
| 249 | * lockTask task. */ |
| 250 | final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 251 | int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE; |
| 252 | |
| 253 | int mLockTaskUid = -1; // The uid of the application that called startLockTask(). |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 254 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 255 | // This represents the last resolved activity values for this task |
| 256 | // NOTE: This value needs to be persisted with each task |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 257 | TaskDescription lastTaskDescription = new TaskDescription(); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 258 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 259 | /** List of all activities in the task arranged in history order */ |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 260 | final ArrayList<ActivityRecord> mActivities; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 261 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 262 | /** Current stack. Setter must always be used to update the value. */ |
| 263 | private ActivityStack mStack; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 264 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 265 | /** The process that had previously hosted the root activity of this task. |
| 266 | * Used to know that we should try harder to keep this process around, in case the |
| 267 | * user wants to return to it. */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 268 | private WindowProcessController mRootProcess; |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 269 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 270 | /** Takes on same value as first root activity */ |
| 271 | boolean isPersistable = false; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 272 | int maxRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 273 | |
| 274 | /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for |
| 275 | * determining the order when restoring. Sign indicates whether last task movement was to front |
| 276 | * (positive) or back (negative). Absolute value indicates time. */ |
| 277 | long mLastTimeMoved = System.currentTimeMillis(); |
| 278 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 279 | /** If original intent did not allow relinquishing task identity, save that information */ |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 280 | private boolean mNeverRelinquishIdentity = true; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 281 | |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 282 | // Used in the unique case where we are clearing the task in order to reuse it. In that case we |
| 283 | // do not want to delete the stack when the task goes empty. |
Filip Gruszczynski | be9dabd | 2016-01-19 12:23:10 -0800 | [diff] [blame] | 284 | private boolean mReuseTask = false; |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 285 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 286 | CharSequence lastDescription; // Last description captured for this item. |
| 287 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 288 | int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent. |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 289 | int mAffiliatedTaskColor; // color of the parent task affiliation. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 290 | TaskRecord mPrevAffiliate; // previous task in affiliated chain. |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 291 | int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 292 | TaskRecord mNextAffiliate; // next task in affiliated chain. |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 293 | int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 294 | |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 295 | // For relaunching the task from recents as though it was launched by the original launcher. |
| 296 | int mCallingUid; |
| 297 | String mCallingPackage; |
| 298 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 299 | final ActivityTaskManagerService mService; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 300 | |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 301 | private final Rect mTmpStableBounds = new Rect(); |
| 302 | private final Rect mTmpNonDecorBounds = new Rect(); |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 303 | private final Rect mTmpRect = new Rect(); |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 304 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 305 | // Last non-fullscreen bounds the task was launched in or resized to. |
| 306 | // The information is persisted and used to determine the appropriate stack to launch the |
| 307 | // task into on restore. |
| 308 | Rect mLastNonFullscreenBounds = null; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 309 | // Minimal width and height of this task when it's resizeable. -1 means it should use the |
| 310 | // default minimal width/height. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 311 | int mMinWidth; |
| 312 | int mMinHeight; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 313 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 314 | // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible) |
| 315 | // This number will be assigned when we evaluate OOM scores for all visible tasks. |
| 316 | int mLayerRank = -1; |
| 317 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 318 | /** Helper object used for updating override configuration. */ |
| 319 | private Configuration mTmpConfig = new Configuration(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 320 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 321 | private TaskWindowContainerController mWindowContainerController; |
| 322 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 323 | /** |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 324 | * Don't use constructor directly. Use {@link #create(ActivityTaskManagerService, int, |
| 325 | * ActivityInfo, Intent, TaskDescription)} instead. |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 326 | */ |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 327 | TaskRecord(ActivityTaskManagerService service, int _taskId, ActivityInfo info, Intent _intent, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 328 | IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 329 | mService = service; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 330 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | taskId = _taskId; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 332 | lastActiveTime = SystemClock.elapsedRealtime(); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 333 | mAffiliatedTaskId = _taskId; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 334 | voiceSession = _voiceSession; |
| 335 | voiceInteractor = _voiceInteractor; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 336 | isAvailable = true; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 337 | mActivities = new ArrayList<>(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 338 | mCallingUid = info.applicationInfo.uid; |
| 339 | mCallingPackage = info.packageName; |
Martijn Coenen | d4a6970 | 2014-06-30 11:12:17 -0700 | [diff] [blame] | 340 | setIntent(_intent, info); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 341 | setMinDimensions(info); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 342 | touchActiveTime(); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 343 | mService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 346 | /** |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 347 | * Don't use constructor directly. |
| 348 | * Use {@link #create(ActivityTaskManagerService, int, ActivityInfo, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 349 | * Intent, IVoiceInteractionSession, IVoiceInteractor)} instead. |
| 350 | */ |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 351 | TaskRecord(ActivityTaskManagerService service, int _taskId, ActivityInfo info, Intent _intent, |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 352 | TaskDescription _taskDescription) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 353 | mService = service; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 354 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 355 | taskId = _taskId; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 356 | lastActiveTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 357 | mAffiliatedTaskId = _taskId; |
| 358 | voiceSession = null; |
| 359 | voiceInteractor = null; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 360 | isAvailable = true; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 361 | mActivities = new ArrayList<>(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 362 | mCallingUid = info.applicationInfo.uid; |
| 363 | mCallingPackage = info.packageName; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 364 | setIntent(_intent, info); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 365 | setMinDimensions(info); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 366 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 367 | isPersistable = true; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 368 | // Clamp to [1, max]. |
| 369 | maxRecents = Math.min(Math.max(info.maxRecents, 1), |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 370 | ActivityTaskManager.getMaxAppRecentsLimitStatic()); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 371 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 372 | lastTaskDescription = _taskDescription; |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 373 | touchActiveTime(); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 374 | mService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 377 | /** |
| 378 | * Don't use constructor directly. This is only used by XML parser. |
| 379 | */ |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 380 | TaskRecord(ActivityTaskManagerService service, int _taskId, Intent _intent, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 381 | Intent _affinityIntent, String _affinity, String _rootAffinity, |
| 382 | ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 383 | boolean _autoRemoveRecents, boolean _askedCompatMode, int _userId, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 384 | int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities, |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 385 | long lastTimeMoved, boolean neverRelinquishIdentity, |
| 386 | TaskDescription _lastTaskDescription, int taskAffiliation, int prevTaskId, |
| 387 | int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage, |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 388 | int resizeMode, boolean supportsPictureInPicture, boolean _realActivitySuspended, |
| 389 | boolean userSetupComplete, int minWidth, int minHeight) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 390 | mService = service; |
| 391 | taskId = _taskId; |
| 392 | intent = _intent; |
| 393 | affinityIntent = _affinityIntent; |
| 394 | affinity = _affinity; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 395 | rootAffinity = _rootAffinity; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 396 | voiceSession = null; |
| 397 | voiceInteractor = null; |
| 398 | realActivity = _realActivity; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 399 | realActivitySuspended = _realActivitySuspended; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 400 | origActivity = _origActivity; |
| 401 | rootWasReset = _rootWasReset; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 402 | isAvailable = true; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 403 | autoRemoveRecents = _autoRemoveRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 404 | askedCompatMode = _askedCompatMode; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 405 | userId = _userId; |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 406 | mUserSetupComplete = userSetupComplete; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 407 | effectiveUid = _effectiveUid; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 408 | lastActiveTime = SystemClock.elapsedRealtime(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 409 | lastDescription = _lastDescription; |
| 410 | mActivities = activities; |
| 411 | mLastTimeMoved = lastTimeMoved; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 412 | mNeverRelinquishIdentity = neverRelinquishIdentity; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 413 | lastTaskDescription = _lastTaskDescription; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 414 | mAffiliatedTaskId = taskAffiliation; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 415 | mAffiliatedTaskColor = taskAffiliationColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 416 | mPrevAffiliateTaskId = prevTaskId; |
| 417 | mNextAffiliateTaskId = nextTaskId; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 418 | mCallingUid = callingUid; |
| 419 | mCallingPackage = callingPackage; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 420 | mResizeMode = resizeMode; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 421 | mSupportsPictureInPicture = supportsPictureInPicture; |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 422 | mMinWidth = minWidth; |
| 423 | mMinHeight = minHeight; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 424 | mService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 427 | TaskWindowContainerController getWindowContainerController() { |
| 428 | return mWindowContainerController; |
| 429 | } |
| 430 | |
| 431 | void createWindowContainer(boolean onTop, boolean showForAllUsers) { |
| 432 | if (mWindowContainerController != null) { |
| 433 | throw new IllegalArgumentException("Window container=" + mWindowContainerController |
| 434 | + " already created for task=" + this); |
| 435 | } |
| 436 | |
| 437 | final Rect bounds = updateOverrideConfigurationFromLaunchBounds(); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 438 | setWindowContainerController(new TaskWindowContainerController(taskId, this, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 439 | getStack().getWindowContainerController(), userId, bounds, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 440 | mResizeMode, mSupportsPictureInPicture, onTop, |
| 441 | showForAllUsers, lastTaskDescription)); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Should only be invoked from {@link #createWindowContainer(boolean, boolean)}. |
| 446 | */ |
| 447 | @VisibleForTesting |
| 448 | protected void setWindowContainerController(TaskWindowContainerController controller) { |
| 449 | if (mWindowContainerController != null) { |
| 450 | throw new IllegalArgumentException("Window container=" + mWindowContainerController |
| 451 | + " already created for task=" + this); |
| 452 | } |
| 453 | |
| 454 | mWindowContainerController = controller; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | void removeWindowContainer() { |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 458 | mService.getLockTaskController().clearLockedTask(this); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 459 | mWindowContainerController.removeContainer(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 460 | if (!getWindowConfiguration().persistTaskBounds()) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 461 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 462 | // default configuration the next time it launches. |
| 463 | updateOverrideConfiguration(null); |
| 464 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 465 | mService.getTaskChangeNotificationController().notifyTaskRemoved(taskId); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 466 | mWindowContainerController = null; |
| 467 | } |
| 468 | |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 469 | @Override |
| 470 | public void onSnapshotChanged(TaskSnapshot snapshot) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 471 | mService.getTaskChangeNotificationController().notifyTaskSnapshotChanged(taskId, snapshot); |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 472 | } |
| 473 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 474 | void setResizeMode(int resizeMode) { |
| 475 | if (mResizeMode == resizeMode) { |
| 476 | return; |
| 477 | } |
| 478 | mResizeMode = resizeMode; |
| 479 | mWindowContainerController.setResizeable(resizeMode); |
| 480 | mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 481 | mService.mStackSupervisor.resumeFocusedStacksTopActivitiesLocked(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | void setTaskDockedResizing(boolean resizing) { |
| 485 | mWindowContainerController.setTaskDockedResizing(resizing); |
| 486 | } |
| 487 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 488 | // TODO: Consolidate this with the resize() method below. |
| 489 | @Override |
| 490 | public void requestResize(Rect bounds, int resizeMode) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 491 | mService.resizeTask(taskId, bounds, resizeMode); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 492 | } |
| 493 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 494 | boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 495 | mService.mWindowManager.deferSurfaceLayout(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 496 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 497 | try { |
| 498 | if (!isResizeable()) { |
| 499 | Slog.w(TAG, "resizeTask: task " + this + " not resizeable."); |
| 500 | return true; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 501 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 502 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 503 | // If this is a forced resize, let it go through even if the bounds is not changing, |
| 504 | // as we might need a relayout due to surface size change (to/from fullscreen). |
| 505 | final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0; |
| 506 | if (equivalentOverrideBounds(bounds) && !forced) { |
| 507 | // Nothing to do here... |
| 508 | return true; |
| 509 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 510 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 511 | if (mWindowContainerController == null) { |
| 512 | // Task doesn't exist in window manager yet (e.g. was restored from recents). |
| 513 | // All we can do for now is update the bounds so it can be used when the task is |
| 514 | // added to window manager. |
| 515 | updateOverrideConfiguration(bounds); |
| 516 | if (!inFreeformWindowingMode()) { |
| 517 | // re-restore the task so it can have the proper stack association. |
| 518 | mService.mStackSupervisor.restoreRecentTaskLocked(this, null, !ON_TOP); |
| 519 | } |
| 520 | return true; |
| 521 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 522 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 523 | if (!canResizeToBounds(bounds)) { |
| 524 | throw new IllegalArgumentException("resizeTask: Can not resize task=" + this |
| 525 | + " to bounds=" + bounds + " resizeMode=" + mResizeMode); |
| 526 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 527 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 528 | // Do not move the task to another stack here. |
| 529 | // This method assumes that the task is already placed in the right stack. |
| 530 | // we do not mess with that decision and we only do the resize! |
| 531 | |
| 532 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId); |
| 533 | |
| 534 | final boolean updatedConfig = updateOverrideConfiguration(bounds); |
| 535 | // This variable holds information whether the configuration didn't change in a significant |
| 536 | |
| 537 | // way and the activity was kept the way it was. If it's false, it means the activity |
| 538 | // had |
| 539 | // to be relaunched due to configuration change. |
| 540 | boolean kept = true; |
| 541 | if (updatedConfig) { |
| 542 | final ActivityRecord r = topRunningActivityLocked(); |
| 543 | if (r != null && !deferResume) { |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 544 | kept = r.ensureActivityConfiguration(0 /* globalChanges */, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 545 | preserveWindow); |
Garfield Tan | b915118 | 2018-06-25 16:29:21 -0700 | [diff] [blame] | 546 | // Preserve other windows for resizing because if resizing happens when there |
| 547 | // is a dialog activity in the front, the activity that still shows some |
| 548 | // content to the user will become black and cause flickers. Note in most cases |
| 549 | // this won't cause tons of irrelevant windows being preserved because only |
| 550 | // activities in this task may experience a bounds change. Configs for other |
| 551 | // activities stay the same. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 552 | mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, |
Garfield Tan | b915118 | 2018-06-25 16:29:21 -0700 | [diff] [blame] | 553 | preserveWindow); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 554 | if (!kept) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 555 | mService.mStackSupervisor.resumeFocusedStacksTopActivitiesLocked(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 556 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 557 | } |
| 558 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 559 | mWindowContainerController.resize(kept, forced); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 560 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 561 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 562 | return kept; |
| 563 | } finally { |
| 564 | mService.mWindowManager.continueSurfaceLayout(); |
| 565 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | // TODO: Investigate combining with the resize() method above. |
| 569 | void resizeWindowContainer() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 570 | mWindowContainerController.resize(false /* relayout */, false /* forced */); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 573 | void getWindowContainerBounds(Rect bounds) { |
| 574 | mWindowContainerController.getBounds(bounds); |
| 575 | } |
| 576 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 577 | /** |
| 578 | * Convenience method to reparent a task to the top or bottom position of the stack. |
| 579 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 580 | boolean reparent(ActivityStack preferredStack, boolean toTop, |
| 581 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 582 | String reason) { |
| 583 | return reparent(preferredStack, toTop ? MAX_VALUE : 0, moveStackMode, animate, deferResume, |
| 584 | true /* schedulePictureInPictureModeChange */, reason); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** |
| 588 | * Convenience method to reparent a task to the top or bottom position of the stack, with |
| 589 | * an option to skip scheduling the picture-in-picture mode change. |
| 590 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 591 | boolean reparent(ActivityStack preferredStack, boolean toTop, |
| 592 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 593 | boolean schedulePictureInPictureModeChange, String reason) { |
| 594 | return reparent(preferredStack, toTop ? MAX_VALUE : 0, moveStackMode, animate, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 595 | deferResume, schedulePictureInPictureModeChange, reason); |
| 596 | } |
| 597 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 598 | /** Convenience method to reparent a task to a specific position of the stack. */ |
| 599 | boolean reparent(ActivityStack preferredStack, int position, |
| 600 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 601 | String reason) { |
| 602 | return reparent(preferredStack, position, moveStackMode, animate, deferResume, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 603 | true /* schedulePictureInPictureModeChange */, reason); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 604 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 605 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 606 | /** |
| 607 | * Reparents the task into a preferred stack, creating it if necessary. |
| 608 | * |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 609 | * @param preferredStack the target stack to move this task |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 610 | * @param position the position to place this task in the new stack |
| 611 | * @param animate whether or not we should wait for the new window created as a part of the |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 612 | * reparenting to be drawn and animated in |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 613 | * @param moveStackMode whether or not to move the stack to the front always, only if it was |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 614 | * previously focused & in front, or never |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 615 | * @param deferResume whether or not to update the visibility of other tasks and stacks that may |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 616 | * have changed as a result of this reparenting |
| 617 | * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode |
| 618 | * change. Callers may set this to false if they are explicitly scheduling PiP mode |
| 619 | * changes themselves, like during the PiP animation |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 620 | * @param reason the caller of this reparenting |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 621 | * @return whether the task was reparented |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 622 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 623 | // TODO: Inspect all call sites and change to just changing windowing mode of the stack vs. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 624 | // re-parenting the task. Can only be done when we are no longer using static stack Ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 625 | boolean reparent(ActivityStack preferredStack, int position, |
| 626 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 627 | boolean schedulePictureInPictureModeChange, String reason) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 628 | final ActivityStackSupervisor supervisor = mService.mStackSupervisor; |
| 629 | final WindowManagerService windowManager = mService.mWindowManager; |
| 630 | final ActivityStack sourceStack = getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 631 | final ActivityStack toStack = supervisor.getReparentTargetStack(this, preferredStack, |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 632 | position == MAX_VALUE); |
| 633 | if (toStack == sourceStack) { |
| 634 | return false; |
| 635 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 636 | if (!canBeLaunchedOnDisplay(toStack.mDisplayId)) { |
| 637 | return false; |
| 638 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 639 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 640 | final int toStackWindowingMode = toStack.getWindowingMode(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 641 | final ActivityRecord topActivity = getTopActivity(); |
| 642 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 643 | final boolean mightReplaceWindow = topActivity != null |
| 644 | && replaceWindowsOnTaskMove(getWindowingMode(), toStackWindowingMode); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 645 | if (mightReplaceWindow) { |
| 646 | // We are about to relaunch the activity because its configuration changed due to |
| 647 | // being maximized, i.e. size change. The activity will first remove the old window |
| 648 | // and then add a new one. This call will tell window manager about this, so it can |
| 649 | // preserve the old window until the new one is drawn. This prevents having a gap |
| 650 | // between the removal and addition, in which no window is visible. We also want the |
| 651 | // entrance of the new window to be properly animated. |
| 652 | // Note here we always set the replacing window first, as the flags might be needed |
| 653 | // during the relaunch. If we end up not doing any relaunch, we clear the flags later. |
| 654 | windowManager.setWillReplaceWindow(topActivity.appToken, animate); |
| 655 | } |
| 656 | |
| 657 | windowManager.deferSurfaceLayout(); |
| 658 | boolean kept = true; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 659 | try { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 660 | final ActivityRecord r = topRunningActivityLocked(); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 661 | final boolean wasFocused = r != null && supervisor.isTopDisplayFocusedStack(sourceStack) |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 662 | && (topRunningActivityLocked() == r); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 663 | final boolean wasResumed = r != null && sourceStack.getResumedActivity() == r; |
Winson Chung | 95f8f0e | 2017-03-24 09:20:17 -0700 | [diff] [blame] | 664 | final boolean wasPaused = r != null && sourceStack.mPausingActivity == r; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 665 | |
| 666 | // In some cases the focused stack isn't the front stack. E.g. pinned stack. |
| 667 | // Whenever we are moving the top activity from the front stack we want to make sure to |
| 668 | // move the stack to the front. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 669 | final boolean wasFront = r != null && sourceStack.isTopStackOnDisplay() |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 670 | && (sourceStack.topRunningActivityLocked() == r); |
| 671 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 672 | // Adjust the position for the new parent stack as needed. |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 673 | position = toStack.getAdjustedPositionForTask(this, position, null /* starting */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 674 | |
| 675 | // Must reparent first in window manager to avoid a situation where AM can delete the |
| 676 | // we are coming from in WM before we reparent because it became empty. |
Wale Ogunwale | 2719cc1 | 2017-04-14 09:45:27 -0700 | [diff] [blame] | 677 | mWindowContainerController.reparent(toStack.getWindowContainerController(), position, |
| 678 | moveStackMode == REPARENT_MOVE_STACK_TO_FRONT); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 679 | |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 680 | final boolean moveStackToFront = moveStackMode == REPARENT_MOVE_STACK_TO_FRONT |
| 681 | || (moveStackMode == REPARENT_KEEP_STACK_AT_FRONT && (wasFocused || wasFront)); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 682 | // Move the task |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 683 | sourceStack.removeTask(this, reason, moveStackToFront |
| 684 | ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 685 | toStack.addTask(this, position, false /* schedulePictureInPictureModeChange */, reason); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 686 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 687 | if (schedulePictureInPictureModeChange) { |
| 688 | // Notify of picture-in-picture mode changes |
| 689 | supervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, sourceStack); |
| 690 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 691 | |
| 692 | // TODO: Ensure that this is actually necessary here |
| 693 | // Notify the voice session if required |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 694 | if (voiceSession != null) { |
| 695 | try { |
| 696 | voiceSession.taskStarted(intent, taskId); |
| 697 | } catch (RemoteException e) { |
| 698 | } |
| 699 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 700 | |
| 701 | // If the task had focus before (or we're requested to move focus), move focus to the |
| 702 | // new stack by moving the stack to the front. |
Winson Chung | 95f8f0e | 2017-03-24 09:20:17 -0700 | [diff] [blame] | 703 | if (r != null) { |
| 704 | toStack.moveToFrontAndResumeStateIfNeeded(r, moveStackToFront, wasResumed, |
| 705 | wasPaused, reason); |
| 706 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 707 | if (!animate) { |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 708 | mService.mStackSupervisor.mNoAnimActivities.add(topActivity); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | // We might trigger a configuration change. Save the current task bounds for freezing. |
| 712 | // TODO: Should this call be moved inside the resize method in WM? |
| 713 | toStack.prepareFreezingTaskBounds(); |
| 714 | |
| 715 | // Make sure the task has the appropriate bounds/size for the stack it is in. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 716 | final boolean toStackSplitScreenPrimary = |
| 717 | toStackWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 718 | final Rect configBounds = getOverrideBounds(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 719 | if ((toStackWindowingMode == WINDOWING_MODE_FULLSCREEN |
| 720 | || toStackWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 721 | && !Objects.equals(configBounds, toStack.getOverrideBounds())) { |
| 722 | kept = resize(toStack.getOverrideBounds(), RESIZE_MODE_SYSTEM, !mightReplaceWindow, |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 723 | deferResume); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 724 | } else if (toStackWindowingMode == WINDOWING_MODE_FREEFORM) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 725 | Rect bounds = getLaunchBounds(); |
| 726 | if (bounds == null) { |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 727 | mService.mStackSupervisor.getLaunchParamsController().layoutTask(this, null); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 728 | bounds = configBounds; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 729 | } |
| 730 | kept = resize(bounds, RESIZE_MODE_FORCED, !mightReplaceWindow, deferResume); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 731 | } else if (toStackSplitScreenPrimary || toStackWindowingMode == WINDOWING_MODE_PINNED) { |
| 732 | if (toStackSplitScreenPrimary && moveStackMode == REPARENT_KEEP_STACK_AT_FRONT) { |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 733 | // Move recents to front so it is not behind home stack when going into docked |
| 734 | // mode |
| 735 | mService.mStackSupervisor.moveRecentsStackToFront(reason); |
| 736 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 737 | kept = resize(toStack.getOverrideBounds(), RESIZE_MODE_SYSTEM, !mightReplaceWindow, |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 738 | deferResume); |
| 739 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 740 | } finally { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 741 | windowManager.continueSurfaceLayout(); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 742 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 743 | |
| 744 | if (mightReplaceWindow) { |
| 745 | // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old |
| 746 | // window), we need to clear the replace window settings. Otherwise, we schedule a |
| 747 | // timeout to remove the old window if the replacing window is not coming in time. |
| 748 | windowManager.scheduleClearWillReplaceWindows(topActivity.appToken, !kept); |
| 749 | } |
| 750 | |
| 751 | if (!deferResume) { |
| 752 | // The task might have already been running and its visibility needs to be synchronized |
| 753 | // with the visibility of the stack / windows. |
| 754 | supervisor.ensureActivitiesVisibleLocked(null, 0, !mightReplaceWindow); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 755 | supervisor.resumeFocusedStacksTopActivitiesLocked(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 758 | // TODO: Handle incorrect request to move before the actual move, not after. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 759 | supervisor.handleNonResizableTaskIfNeeded(this, preferredStack.getWindowingMode(), |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 760 | DEFAULT_DISPLAY, toStack); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 761 | |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 762 | return (preferredStack == toStack); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 765 | /** |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 766 | * @return True if the windows of tasks being moved to the target stack from the source stack |
| 767 | * should be replaced, meaning that window manager will keep the old window around until the new |
| 768 | * is ready. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 769 | */ |
| 770 | private static boolean replaceWindowsOnTaskMove( |
| 771 | int sourceWindowingMode, int targetWindowingMode) { |
| 772 | return sourceWindowingMode == WINDOWING_MODE_FREEFORM |
| 773 | || targetWindowingMode == WINDOWING_MODE_FREEFORM; |
| 774 | } |
| 775 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 776 | void cancelWindowTransition() { |
| 777 | mWindowContainerController.cancelWindowTransition(); |
| 778 | } |
| 779 | |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 780 | /** |
| 781 | * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD! |
| 782 | */ |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 783 | TaskSnapshot getSnapshot(boolean reducedResolution) { |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 784 | |
| 785 | // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more |
| 786 | // synchronized between AM and WM. |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 787 | return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 788 | } |
| 789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | void touchActiveTime() { |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 791 | lastActiveTime = SystemClock.elapsedRealtime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | long getInactiveDuration() { |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 795 | return SystemClock.elapsedRealtime() - lastActiveTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 797 | |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 798 | /** Sets the original intent, and the calling uid and package. */ |
| 799 | void setIntent(ActivityRecord r) { |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 800 | mCallingUid = r.launchedFromUid; |
| 801 | mCallingPackage = r.launchedFromPackage; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 802 | setIntent(r.intent, r.info); |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 803 | setLockTaskAuth(r); |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /** Sets the original intent, _without_ updating the calling uid or package. */ |
| 807 | private void setIntent(Intent _intent, ActivityInfo info) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 808 | if (intent == null) { |
| 809 | mNeverRelinquishIdentity = |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 810 | (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 811 | } else if (mNeverRelinquishIdentity) { |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | affinity = info.taskAffinity; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 816 | if (intent == null) { |
| 817 | // If this task already has an intent associated with it, don't set the root |
| 818 | // affinity -- we don't want it changing after initially set, but the initially |
| 819 | // set value may be null. |
| 820 | rootAffinity = affinity; |
| 821 | } |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 822 | effectiveUid = info.applicationInfo.uid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 823 | stringName = null; |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | if (info.targetActivity == null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 826 | if (_intent != null) { |
| 827 | // If this Intent has a selector, we want to clear it for the |
| 828 | // recent task since it is not relevant if the user later wants |
| 829 | // to re-launch the app. |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 830 | if (_intent.getSelector() != null || _intent.getSourceBounds() != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 831 | _intent = new Intent(_intent); |
| 832 | _intent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 833 | _intent.setSourceBounds(null); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 834 | } |
| 835 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 836 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | intent = _intent; |
| 838 | realActivity = _intent != null ? _intent.getComponent() : null; |
| 839 | origActivity = null; |
| 840 | } else { |
| 841 | ComponentName targetComponent = new ComponentName( |
| 842 | info.packageName, info.targetActivity); |
| 843 | if (_intent != null) { |
| 844 | Intent targetIntent = new Intent(_intent); |
| 845 | targetIntent.setComponent(targetComponent); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 846 | targetIntent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 847 | targetIntent.setSourceBounds(null); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 848 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 849 | "Setting Intent of " + this + " to target " + targetIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | intent = targetIntent; |
| 851 | realActivity = targetComponent; |
| 852 | origActivity = _intent.getComponent(); |
| 853 | } else { |
| 854 | intent = null; |
| 855 | realActivity = targetComponent; |
| 856 | origActivity = new ComponentName(info.packageName, info.name); |
| 857 | } |
| 858 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 859 | |
Craig Mautner | 47b20ba | 2014-09-17 17:23:44 -0700 | [diff] [blame] | 860 | final int intentFlags = intent == null ? 0 : intent.getFlags(); |
| 861 | if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | // Once we are set to an Intent with this flag, we count this |
| 863 | // task as having a true root activity. |
| 864 | rootWasReset = true; |
| 865 | } |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 866 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 867 | mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(), |
| 868 | USER_SETUP_COMPLETE, 0, userId) != 0; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 869 | if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) { |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 870 | // If the activity itself has requested auto-remove, then just always do it. |
| 871 | autoRemoveRecents = true; |
Wale Ogunwale | 843bfb9 | 2015-03-27 11:06:48 -0700 | [diff] [blame] | 872 | } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS)) |
| 873 | == FLAG_ACTIVITY_NEW_DOCUMENT) { |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 874 | // If the caller has not asked for the document to be retained, then we may |
| 875 | // want to turn on auto-remove, depending on whether the target has set its |
| 876 | // own document launch mode. |
| 877 | if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) { |
| 878 | autoRemoveRecents = false; |
| 879 | } else { |
| 880 | autoRemoveRecents = true; |
| 881 | } |
| 882 | } else { |
| 883 | autoRemoveRecents = false; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 884 | } |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 885 | mResizeMode = info.resizeMode; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 886 | mSupportsPictureInPicture = info.supportsPictureInPicture(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 888 | |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 889 | /** Sets the original minimal width and height. */ |
| 890 | private void setMinDimensions(ActivityInfo info) { |
| 891 | if (info != null && info.windowLayout != null) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 892 | mMinWidth = info.windowLayout.minWidth; |
| 893 | mMinHeight = info.windowLayout.minHeight; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 894 | } else { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 895 | mMinWidth = INVALID_MIN_SIZE; |
| 896 | mMinHeight = INVALID_MIN_SIZE; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
Wale Ogunwale | 715a1dc | 2016-02-29 14:27:32 -0800 | [diff] [blame] | 900 | /** |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 901 | * Return true if the input activity has the same intent filter as the intent this task |
Wale Ogunwale | 715a1dc | 2016-02-29 14:27:32 -0800 | [diff] [blame] | 902 | * record is based on (normally the root activity intent). |
| 903 | */ |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 904 | boolean isSameIntentFilter(ActivityRecord r) { |
Wale Ogunwale | 715a1dc | 2016-02-29 14:27:32 -0800 | [diff] [blame] | 905 | final Intent intent = new Intent(r.intent); |
| 906 | // Correct the activity intent for aliasing. The task record intent will always be based on |
| 907 | // the real activity that will be launched not the alias, so we need to use an intent with |
| 908 | // the component name pointing to the real activity not the alias in the activity record. |
| 909 | intent.setComponent(r.realActivity); |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 910 | return intent.filterEquals(this.intent); |
Wale Ogunwale | 715a1dc | 2016-02-29 14:27:32 -0800 | [diff] [blame] | 911 | } |
| 912 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 913 | boolean returnsToHomeStack() { |
| 914 | final int returnHomeFlags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME; |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 915 | return intent != null && (intent.getFlags() & returnHomeFlags) == returnHomeFlags; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 916 | } |
| 917 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 918 | void setPrevAffiliate(TaskRecord prevAffiliate) { |
| 919 | mPrevAffiliate = prevAffiliate; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 920 | mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | void setNextAffiliate(TaskRecord nextAffiliate) { |
| 924 | mNextAffiliate = nextAffiliate; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 925 | mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 928 | <T extends ActivityStack> T getStack() { |
| 929 | return (T) mStack; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 932 | /** |
| 933 | * Must be used for setting parent stack because it performs configuration updates. |
| 934 | * Must be called after adding task as a child to the stack. |
| 935 | */ |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 936 | void setStack(ActivityStack stack) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 937 | if (stack != null && !stack.isInStackLocked(this)) { |
| 938 | throw new IllegalStateException("Task must be added as a Stack child first."); |
| 939 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 940 | final ActivityStack oldStack = mStack; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 941 | mStack = stack; |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 942 | |
| 943 | // If the new {@link TaskRecord} is from a different {@link ActivityStack}, remove this |
| 944 | // {@link ActivityRecord} from its current {@link ActivityStack}. |
| 945 | |
| 946 | if (oldStack != mStack) { |
| 947 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 948 | final ActivityRecord activity = getChildAt(i); |
| 949 | |
| 950 | if (oldStack != null) { |
| 951 | oldStack.onActivityRemovedFromStack(activity); |
| 952 | } |
| 953 | |
| 954 | if (mStack != null) { |
| 955 | stack.onActivityAddedToStack(activity); |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 960 | onParentChanged(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | /** |
| 964 | * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set. |
| 965 | */ |
| 966 | int getStackId() { |
| 967 | return mStack != null ? mStack.mStackId : INVALID_STACK_ID; |
| 968 | } |
| 969 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 970 | @Override |
| 971 | protected int getChildCount() { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 972 | return mActivities.size(); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | @Override |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 976 | protected ActivityRecord getChildAt(int index) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 977 | return mActivities.get(index); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | @Override |
| 981 | protected ConfigurationContainer getParent() { |
| 982 | return mStack; |
| 983 | } |
| 984 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 985 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 986 | protected void onParentChanged() { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 987 | super.onParentChanged(); |
| 988 | mService.mStackSupervisor.updateUIDsPresentOnDisplay(); |
| 989 | } |
| 990 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 991 | // Close up recents linked list. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 992 | private void closeRecentsChain() { |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 993 | if (mPrevAffiliate != null) { |
| 994 | mPrevAffiliate.setNextAffiliate(mNextAffiliate); |
| 995 | } |
| 996 | if (mNextAffiliate != null) { |
| 997 | mNextAffiliate.setPrevAffiliate(mPrevAffiliate); |
| 998 | } |
| 999 | setPrevAffiliate(null); |
| 1000 | setNextAffiliate(null); |
| 1001 | } |
| 1002 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1003 | void removedFromRecents() { |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1004 | closeRecentsChain(); |
| 1005 | if (inRecents) { |
| 1006 | inRecents = false; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1007 | mService.notifyTaskPersisterLocked(this, false); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1008 | } |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 1009 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1010 | clearRootProcess(); |
| 1011 | |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 1012 | // TODO: Use window container controller once tasks are better synced between AM and WM |
| 1013 | mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1016 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
| 1017 | closeRecentsChain(); |
| 1018 | mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1019 | mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1020 | // Find the end |
| 1021 | while (taskToAffiliateWith.mNextAffiliate != null) { |
| 1022 | final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate; |
| 1023 | if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) { |
| 1024 | Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId=" |
| 1025 | + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId); |
| 1026 | if (nextRecents.mPrevAffiliate == taskToAffiliateWith) { |
| 1027 | nextRecents.setPrevAffiliate(null); |
| 1028 | } |
| 1029 | taskToAffiliateWith.setNextAffiliate(null); |
| 1030 | break; |
| 1031 | } |
| 1032 | taskToAffiliateWith = nextRecents; |
| 1033 | } |
| 1034 | taskToAffiliateWith.setNextAffiliate(this); |
| 1035 | setPrevAffiliate(taskToAffiliateWith); |
| 1036 | setNextAffiliate(null); |
| 1037 | } |
| 1038 | |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1039 | /** Returns the intent for the root activity for this task */ |
| 1040 | Intent getBaseIntent() { |
| 1041 | return intent != null ? intent : affinityIntent; |
| 1042 | } |
| 1043 | |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 1044 | /** Returns the first non-finishing activity from the root. */ |
| 1045 | ActivityRecord getRootActivity() { |
| 1046 | for (int i = 0; i < mActivities.size(); i++) { |
| 1047 | final ActivityRecord r = mActivities.get(i); |
| 1048 | if (r.finishing) { |
| 1049 | continue; |
| 1050 | } |
| 1051 | return r; |
| 1052 | } |
| 1053 | return null; |
| 1054 | } |
| 1055 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1056 | ActivityRecord getTopActivity() { |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 1057 | return getTopActivity(true /* includeOverlays */); |
| 1058 | } |
| 1059 | |
| 1060 | ActivityRecord getTopActivity(boolean includeOverlays) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1061 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 1062 | final ActivityRecord r = mActivities.get(i); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 1063 | if (r.finishing || (!includeOverlays && r.mTaskOverlay)) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1064 | continue; |
| 1065 | } |
| 1066 | return r; |
| 1067 | } |
| 1068 | return null; |
| 1069 | } |
| 1070 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1071 | ActivityRecord topRunningActivityLocked() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1072 | if (mStack != null) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1073 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1074 | ActivityRecord r = mActivities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1075 | if (!r.finishing && r.okToShowLocked()) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1076 | return r; |
| 1077 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | return null; |
| 1081 | } |
| 1082 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 1083 | boolean isVisible() { |
| 1084 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 1085 | final ActivityRecord r = mActivities.get(i); |
| 1086 | if (r.visible) { |
| 1087 | return true; |
| 1088 | } |
| 1089 | } |
| 1090 | return false; |
| 1091 | } |
| 1092 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1093 | void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) { |
| 1094 | if (mStack != null) { |
| 1095 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1096 | ActivityRecord r = mActivities.get(activityNdx); |
Jorim Jaggi | 02f1d2f | 2017-08-04 14:29:16 +0200 | [diff] [blame] | 1097 | if (!r.finishing && r.okToShowLocked() && r.visibleIgnoringKeyguard) { |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1098 | outActivities.add(r); |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1104 | ActivityRecord topRunningActivityWithStartingWindowLocked() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1105 | if (mStack != null) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1106 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1107 | ActivityRecord r = mActivities.get(activityNdx); |
| 1108 | if (r.mStartingWindowState != STARTING_WINDOW_SHOWN |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1109 | || r.finishing || !r.okToShowLocked()) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1110 | continue; |
| 1111 | } |
| 1112 | return r; |
| 1113 | } |
| 1114 | } |
| 1115 | return null; |
| 1116 | } |
| 1117 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1118 | /** |
| 1119 | * Return the number of running activities, and the number of non-finishing/initializing |
| 1120 | * activities in the provided {@param reportOut} respectively. |
| 1121 | */ |
| 1122 | void getNumRunningActivities(TaskActivitiesReport reportOut) { |
| 1123 | reportOut.reset(); |
| 1124 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 1125 | final ActivityRecord r = mActivities.get(i); |
| 1126 | if (r.finishing) { |
| 1127 | continue; |
| 1128 | } |
| 1129 | |
| 1130 | reportOut.base = r; |
| 1131 | |
| 1132 | // Increment the total number of non-finishing activities |
| 1133 | reportOut.numActivities++; |
| 1134 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1135 | if (reportOut.top == null || (reportOut.top.isState(ActivityState.INITIALIZING))) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1136 | reportOut.top = r; |
| 1137 | // Reset the number of running activities until we hit the first non-initializing |
| 1138 | // activity |
| 1139 | reportOut.numRunning = 0; |
| 1140 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1141 | if (r.attachedToProcess()) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1142 | // Increment the number of actually running activities |
| 1143 | reportOut.numRunning++; |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1148 | boolean okToShowLocked() { |
| 1149 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 1150 | // okay to show the activity when locked. |
| 1151 | return mService.mStackSupervisor.isCurrentProfileLocked(userId) |
| 1152 | || topRunningActivityLocked() != null; |
| 1153 | } |
| 1154 | |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1155 | /** Call after activity movement or finish to make sure that frontOfTask is set correctly */ |
Bryce Lee | d71317c | 2017-02-07 14:27:22 -0800 | [diff] [blame] | 1156 | final void setFrontOfTask() { |
| 1157 | boolean foundFront = false; |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1158 | final int numActivities = mActivities.size(); |
Craig Mautner | 704e40b | 2013-12-18 16:43:51 -0800 | [diff] [blame] | 1159 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1160 | final ActivityRecord r = mActivities.get(activityNdx); |
| 1161 | if (foundFront || r.finishing) { |
| 1162 | r.frontOfTask = false; |
| 1163 | } else { |
| 1164 | r.frontOfTask = true; |
| 1165 | // Set frontOfTask false for every following activity. |
| 1166 | foundFront = true; |
| 1167 | } |
| 1168 | } |
Craig Mautner | 9587ee0 | 2014-06-23 15:00:10 +0000 | [diff] [blame] | 1169 | if (!foundFront && numActivities > 0) { |
| 1170 | // All activities of this task are finishing. As we ought to have a frontOfTask |
| 1171 | // activity, make the bottom activity front. |
| 1172 | mActivities.get(0).frontOfTask = true; |
| 1173 | } |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1174 | } |
| 1175 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1176 | /** |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1177 | * Reorder the history stack so that the passed activity is brought to the front. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1178 | */ |
| 1179 | final void moveActivityToFrontLocked(ActivityRecord newTop) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1180 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 1181 | "Removing and adding activity " + newTop |
| 1182 | + " to stack at top callers=" + Debug.getCallers(4)); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1183 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1184 | mActivities.remove(newTop); |
| 1185 | mActivities.add(newTop); |
Bryce Lee | d58d7b3 | 2017-09-08 15:55:22 -0700 | [diff] [blame] | 1186 | |
| 1187 | // Make sure window manager is aware of the position change. |
| 1188 | mWindowContainerController.positionChildAtTop(newTop.mWindowContainerController); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1189 | updateEffectiveIntent(); |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1190 | |
Bryce Lee | d71317c | 2017-02-07 14:27:22 -0800 | [diff] [blame] | 1191 | setFrontOfTask(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1194 | void addActivityAtBottom(ActivityRecord r) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1195 | addActivityAtIndex(0, r); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | void addActivityToTop(ActivityRecord r) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1199 | addActivityAtIndex(mActivities.size(), r); |
| 1200 | } |
| 1201 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1202 | @Override |
Wale Ogunwale | eea34ee9 | 2017-08-31 20:07:45 -0700 | [diff] [blame] | 1203 | /*@WindowConfiguration.ActivityType*/ |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1204 | public int getActivityType() { |
| 1205 | final int applicationType = super.getActivityType(); |
| 1206 | if (applicationType != ACTIVITY_TYPE_UNDEFINED || mActivities.isEmpty()) { |
| 1207 | return applicationType; |
| 1208 | } |
| 1209 | return mActivities.get(0).getActivityType(); |
| 1210 | } |
| 1211 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1212 | /** |
| 1213 | * Adds an activity {@param r} at the given {@param index}. The activity {@param r} must either |
| 1214 | * be in the current task or unparented to any task. |
| 1215 | */ |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1216 | void addActivityAtIndex(int index, ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1217 | TaskRecord task = r.getTask(); |
| 1218 | if (task != null && task != this) { |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1219 | throw new IllegalArgumentException("Can not add r=" + " to task=" + this |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1220 | + " current parent=" + task); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1221 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1222 | |
| 1223 | r.setTask(this); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1224 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 1225 | // Remove r first, and if it wasn't already in the list and it's fullscreen, count it. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1226 | if (!mActivities.remove(r) && r.fullscreen) { |
| 1227 | // Was not previously in list. |
| 1228 | numFullscreen++; |
| 1229 | } |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 1230 | // Only set this based on the first activity |
| 1231 | if (mActivities.isEmpty()) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1232 | if (r.getActivityType() == ACTIVITY_TYPE_UNDEFINED) { |
| 1233 | // Normally non-standard activity type for the activity record will be set when the |
| 1234 | // object is created, however we delay setting the standard application type until |
| 1235 | // this point so that the task can set the type for additional activities added in |
| 1236 | // the else condition below. |
| 1237 | r.setActivityType(ACTIVITY_TYPE_STANDARD); |
| 1238 | } |
| 1239 | setActivityType(r.getActivityType()); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1240 | isPersistable = r.isPersistable(); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 1241 | mCallingUid = r.launchedFromUid; |
| 1242 | mCallingPackage = r.launchedFromPackage; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1243 | // Clamp to [1, max]. |
| 1244 | maxRecents = Math.min(Math.max(r.info.maxRecents, 1), |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1245 | ActivityTaskManager.getMaxAppRecentsLimitStatic()); |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 1246 | } else { |
| 1247 | // Otherwise make all added activities match this one. |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1248 | r.setActivityType(getActivityType()); |
Craig Mautner | 7873300 | 2013-06-10 13:54:49 -0700 | [diff] [blame] | 1249 | } |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1250 | |
| 1251 | final int size = mActivities.size(); |
| 1252 | |
| 1253 | if (index == size && size > 0) { |
| 1254 | final ActivityRecord top = mActivities.get(size - 1); |
| 1255 | if (top.mTaskOverlay) { |
| 1256 | // Place below the task overlay activity since the overlay activity should always |
| 1257 | // be on top. |
| 1258 | index--; |
| 1259 | } |
| 1260 | } |
| 1261 | |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1262 | index = Math.min(size, index); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1263 | mActivities.add(index, r); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1264 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1265 | updateEffectiveIntent(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1266 | if (r.isPersistable()) { |
| 1267 | mService.notifyTaskPersisterLocked(this, false); |
| 1268 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1269 | |
| 1270 | // Sync. with window manager |
| 1271 | updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1272 | final AppWindowContainerController appController = r.getWindowContainerController(); |
| 1273 | if (appController != null) { |
| 1274 | // Only attempt to move in WM if the child has a controller. It is possible we haven't |
| 1275 | // created controller for the activity we are starting yet. |
| 1276 | mWindowContainerController.positionChildAt(appController, index); |
| 1277 | } |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1278 | |
| 1279 | // Make sure the list of display UID whitelists is updated |
| 1280 | // now that this record is in a new task. |
| 1281 | mService.mStackSupervisor.updateUIDsPresentOnDisplay(); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1282 | } |
| 1283 | |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1284 | /** |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1285 | * Removes the specified activity from this task. |
| 1286 | * @param r The {@link ActivityRecord} to remove. |
| 1287 | * @return true if this was the last activity in the task. |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1288 | */ |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1289 | boolean removeActivity(ActivityRecord r) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1290 | return removeActivity(r, false /* reparenting */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | boolean removeActivity(ActivityRecord r, boolean reparenting) { |
| 1294 | if (r.getTask() != this) { |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1295 | throw new IllegalArgumentException( |
| 1296 | "Activity=" + r + " does not belong to task=" + this); |
| 1297 | } |
| 1298 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1299 | r.setTask(null /* task */, reparenting /* reparenting */); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1300 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1301 | if (mActivities.remove(r) && r.fullscreen) { |
| 1302 | // Was previously in list. |
| 1303 | numFullscreen--; |
| 1304 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1305 | if (r.isPersistable()) { |
| 1306 | mService.notifyTaskPersisterLocked(this, false); |
| 1307 | } |
Wale Ogunwale | 89182d5 | 2016-03-11 10:38:36 -0800 | [diff] [blame] | 1308 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1309 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | 89182d5 | 2016-03-11 10:38:36 -0800 | [diff] [blame] | 1310 | // We normally notify listeners of task stack changes on pause, however pinned stack |
| 1311 | // activities are normally in the paused state so no notification will be sent there |
| 1312 | // before the activity is removed. We send it here so instead. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1313 | mService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Wale Ogunwale | 89182d5 | 2016-03-11 10:38:36 -0800 | [diff] [blame] | 1314 | } |
| 1315 | |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 1316 | if (mActivities.isEmpty()) { |
Craig Mautner | 5afcd4d | 2014-06-21 18:11:33 -0700 | [diff] [blame] | 1317 | return !mReuseTask; |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 1318 | } |
| 1319 | updateEffectiveIntent(); |
| 1320 | return false; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1323 | /** |
| 1324 | * @return whether or not there are ONLY task overlay activities in the stack. |
| 1325 | * If {@param excludeFinishing} is set, then ignore finishing activities in the check. |
| 1326 | * If there are no task overlay activities, this call returns false. |
| 1327 | */ |
| 1328 | boolean onlyHasTaskOverlayActivities(boolean excludeFinishing) { |
| 1329 | int count = 0; |
| 1330 | for (int i = mActivities.size() - 1; i >= 0; i--) { |
| 1331 | final ActivityRecord r = mActivities.get(i); |
| 1332 | if (excludeFinishing && r.finishing) { |
| 1333 | continue; |
| 1334 | } |
| 1335 | if (!r.mTaskOverlay) { |
| 1336 | return false; |
| 1337 | } |
| 1338 | count++; |
| 1339 | } |
| 1340 | return count > 0; |
| 1341 | } |
| 1342 | |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 1343 | boolean autoRemoveFromRecents() { |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 1344 | // We will automatically remove the task either if it has explicitly asked for |
| 1345 | // this, or it is empty and has never contained an activity that got shown to |
| 1346 | // the user. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 1347 | return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1350 | /** |
| 1351 | * Completely remove all activities associated with an existing |
| 1352 | * task starting at a specified index. |
| 1353 | */ |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1354 | final void performClearTaskAtIndexLocked(int activityNdx, boolean pauseImmediately, |
| 1355 | String reason) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1356 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1357 | for ( ; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1358 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1359 | if (r.finishing) { |
| 1360 | continue; |
| 1361 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1362 | if (mStack == null) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1363 | // Task was restored from persistent storage. |
| 1364 | r.takeFromHistory(); |
| 1365 | mActivities.remove(activityNdx); |
| 1366 | --activityNdx; |
| 1367 | --numActivities; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1368 | } else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1369 | reason, false, pauseImmediately)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1370 | --activityNdx; |
| 1371 | --numActivities; |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * Completely remove all activities associated with an existing task. |
| 1378 | */ |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 1379 | void performClearTaskLocked() { |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 1380 | mReuseTask = true; |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1381 | performClearTaskAtIndexLocked(0, !PAUSE_IMMEDIATELY, "clear-task-all"); |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 1382 | mReuseTask = false; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
Filip Gruszczynski | be9dabd | 2016-01-19 12:23:10 -0800 | [diff] [blame] | 1385 | ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) { |
| 1386 | mReuseTask = true; |
| 1387 | final ActivityRecord result = performClearTaskLocked(newR, launchFlags); |
| 1388 | mReuseTask = false; |
| 1389 | return result; |
| 1390 | } |
| 1391 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1392 | /** |
| 1393 | * Perform clear operation as requested by |
| 1394 | * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the |
| 1395 | * stack to the given task, then look for |
| 1396 | * an instance of that activity in the stack and, if found, finish all |
| 1397 | * activities on top of it and return the instance. |
| 1398 | * |
| 1399 | * @param newR Description of the new activity being started. |
| 1400 | * @return Returns the old activity that should be continued to be used, |
| 1401 | * or null if none was found. |
| 1402 | */ |
| 1403 | final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1404 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1405 | for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1406 | ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1407 | if (r.finishing) { |
| 1408 | continue; |
| 1409 | } |
| 1410 | if (r.realActivity.equals(newR.realActivity)) { |
| 1411 | // Here it is! Now finish everything in front... |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1412 | final ActivityRecord ret = r; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1413 | |
| 1414 | for (++activityNdx; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1415 | r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1416 | if (r.finishing) { |
| 1417 | continue; |
| 1418 | } |
| 1419 | ActivityOptions opts = r.takeOptionsLocked(); |
| 1420 | if (opts != null) { |
| 1421 | ret.updateOptionsLocked(opts); |
| 1422 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1423 | if (mStack != null && mStack.finishActivityLocked( |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 1424 | r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1425 | --activityNdx; |
| 1426 | --numActivities; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | // Finally, if this is a normal launch mode (that is, not |
| 1431 | // expecting onNewIntent()), then we will finish the current |
| 1432 | // instance of the activity so a new fresh one can be started. |
| 1433 | if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE |
Daichi Hirono | 15a0299 | 2016-04-27 18:47:01 +0900 | [diff] [blame] | 1434 | && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0 |
| 1435 | && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1436 | if (!ret.finishing) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1437 | if (mStack != null) { |
| 1438 | mStack.finishActivityLocked( |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1439 | ret, Activity.RESULT_CANCELED, null, "clear-task-top", false); |
| 1440 | } |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1441 | return null; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | return ret; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | return null; |
| 1450 | } |
| 1451 | |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1452 | void removeTaskActivitiesLocked(boolean pauseImmediately, String reason) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1453 | // Just remove the entire task. |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1454 | performClearTaskAtIndexLocked(0, pauseImmediately, reason); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1457 | String lockTaskAuthToString() { |
| 1458 | switch (mLockTaskAuth) { |
| 1459 | case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK"; |
| 1460 | case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE"; |
| 1461 | case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE"; |
| 1462 | case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED"; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1463 | case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV"; |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1464 | default: return "unknown=" + mLockTaskAuth; |
| 1465 | } |
| 1466 | } |
| 1467 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1468 | void setLockTaskAuth() { |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1469 | setLockTaskAuth(getRootActivity()); |
| 1470 | } |
| 1471 | |
| 1472 | private void setLockTaskAuth(@Nullable ActivityRecord r) { |
| 1473 | if (r == null) { |
| 1474 | mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE; |
| 1475 | return; |
| 1476 | } |
| 1477 | |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 1478 | final String pkg = (realActivity != null) ? realActivity.getPackageName() : null; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1479 | final LockTaskController lockTaskController = mService.getLockTaskController(); |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1480 | switch (r.lockTaskLaunchMode) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1481 | case LOCK_TASK_LAUNCH_MODE_DEFAULT: |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1482 | mLockTaskAuth = lockTaskController.isPackageWhitelisted(userId, pkg) |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 1483 | ? LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1484 | break; |
| 1485 | |
| 1486 | case LOCK_TASK_LAUNCH_MODE_NEVER: |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1487 | mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1488 | break; |
| 1489 | |
| 1490 | case LOCK_TASK_LAUNCH_MODE_ALWAYS: |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1491 | mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1492 | break; |
| 1493 | |
| 1494 | case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED: |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1495 | mLockTaskAuth = lockTaskController.isPackageWhitelisted(userId, pkg) |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 1496 | ? LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | } |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1499 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + |
| 1500 | " mLockTaskAuth=" + lockTaskAuthToString()); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1503 | private boolean isResizeable(boolean checkSupportsPip) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1504 | return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1505 | || (checkSupportsPip && mSupportsPictureInPicture)); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1506 | } |
| 1507 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1508 | boolean isResizeable() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1509 | return isResizeable(true /* checkSupportsPip */); |
| 1510 | } |
| 1511 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1512 | @Override |
| 1513 | public boolean supportsSplitScreenWindowingMode() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1514 | // A task can not be docked even if it is considered resizeable because it only supports |
| 1515 | // picture-in-picture mode but has a non-resizeable resizeMode |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1516 | return super.supportsSplitScreenWindowingMode() |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1517 | && mService.mSupportsSplitScreenMultiWindow |
| 1518 | && (mService.mForceResizableActivities |
Bryce Lee | c857a5b | 2017-08-16 10:04:52 -0700 | [diff] [blame] | 1519 | || (isResizeable(false /* checkSupportsPip */) |
| 1520 | && !ActivityInfo.isPreserveOrientationMode(mResizeMode))); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1521 | } |
| 1522 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1523 | /** |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1524 | * Check whether this task can be launched on the specified display. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1525 | * |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1526 | * @param displayId Target display id. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1527 | * @return {@code true} if either it is the default display or this activity can be put on a |
| 1528 | * secondary display. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1529 | */ |
| 1530 | boolean canBeLaunchedOnDisplay(int displayId) { |
| 1531 | return mService.mStackSupervisor.canPlaceEntityOnDisplay(displayId, |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1532 | -1 /* don't check PID */, -1 /* don't check UID */, null /* activityInfo */); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /** |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1536 | * Check that a given bounds matches the application requested orientation. |
| 1537 | * |
| 1538 | * @param bounds The bounds to be tested. |
| 1539 | * @return True if the requested bounds are okay for a resizing request. |
| 1540 | */ |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 1541 | private boolean canResizeToBounds(Rect bounds) { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1542 | if (bounds == null || !inFreeformWindowingMode()) { |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1543 | // Note: If not on the freeform workspace, we ignore the bounds. |
| 1544 | return true; |
| 1545 | } |
| 1546 | final boolean landscape = bounds.width() > bounds.height(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1547 | final Rect configBounds = getOverrideBounds(); |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1548 | if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1549 | return configBounds.isEmpty() |
| 1550 | || landscape == (configBounds.width() > configBounds.height()); |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1551 | } |
| 1552 | return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape) |
| 1553 | && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape); |
| 1554 | } |
| 1555 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1556 | /** |
Yorke Lee | bdef537 | 2017-04-10 16:38:51 -0700 | [diff] [blame] | 1557 | * @return {@code true} if the task is being cleared for the purposes of being reused. |
| 1558 | */ |
| 1559 | boolean isClearingToReuseTask() { |
| 1560 | return mReuseTask; |
| 1561 | } |
| 1562 | |
| 1563 | /** |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1564 | * Find the activity in the history stack within the given task. Returns |
| 1565 | * the index within the history at which it's found, or < 0 if not found. |
| 1566 | */ |
| 1567 | final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) { |
| 1568 | final ComponentName realActivity = r.realActivity; |
| 1569 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1570 | ActivityRecord candidate = mActivities.get(activityNdx); |
| 1571 | if (candidate.finishing) { |
| 1572 | continue; |
| 1573 | } |
| 1574 | if (candidate.realActivity.equals(realActivity)) { |
| 1575 | return candidate; |
| 1576 | } |
| 1577 | } |
| 1578 | return null; |
| 1579 | } |
| 1580 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1581 | /** Updates the last task description values. */ |
| 1582 | void updateTaskDescription() { |
| 1583 | // Traverse upwards looking for any break between main task activities and |
| 1584 | // utility activities. |
| 1585 | int activityNdx; |
| 1586 | final int numActivities = mActivities.size(); |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 1587 | final boolean relinquish = numActivities != 0 && |
| 1588 | (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1589 | for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1590 | ++activityNdx) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1591 | final ActivityRecord r = mActivities.get(activityNdx); |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 1592 | if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1593 | // This will be the top activity for determining taskDescription. Pre-inc to |
| 1594 | // overcome initial decrement below. |
| 1595 | ++activityNdx; |
| 1596 | break; |
| 1597 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1598 | if (r.intent != null && |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1599 | (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1600 | break; |
| 1601 | } |
| 1602 | } |
| 1603 | if (activityNdx > 0) { |
| 1604 | // Traverse downwards starting below break looking for set label, icon. |
| 1605 | // Note that if there are activities in the task but none of them set the |
| 1606 | // recent activity values, then we do not fall back to the last set |
| 1607 | // values in the TaskRecord. |
| 1608 | String label = null; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1609 | String iconFilename = null; |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 1610 | int iconResource = -1; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1611 | int colorPrimary = 0; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1612 | int colorBackground = 0; |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1613 | int statusBarColor = 0; |
| 1614 | int navigationBarColor = 0; |
| 1615 | boolean topActivity = true; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1616 | for (--activityNdx; activityNdx >= 0; --activityNdx) { |
| 1617 | final ActivityRecord r = mActivities.get(activityNdx); |
Winson Chung | 80f80db | 2018-05-30 21:13:25 -0700 | [diff] [blame] | 1618 | if (r.mTaskOverlay) { |
| 1619 | continue; |
| 1620 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1621 | if (r.taskDescription != null) { |
| 1622 | if (label == null) { |
| 1623 | label = r.taskDescription.getLabel(); |
| 1624 | } |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 1625 | if (iconResource == -1) { |
| 1626 | iconResource = r.taskDescription.getIconResource(); |
| 1627 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1628 | if (iconFilename == null) { |
| 1629 | iconFilename = r.taskDescription.getIconFilename(); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1630 | } |
| 1631 | if (colorPrimary == 0) { |
| 1632 | colorPrimary = r.taskDescription.getPrimaryColor(); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1633 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1634 | if (topActivity) { |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1635 | colorBackground = r.taskDescription.getBackgroundColor(); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1636 | statusBarColor = r.taskDescription.getStatusBarColor(); |
| 1637 | navigationBarColor = r.taskDescription.getNavigationBarColor(); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1638 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1639 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1640 | topActivity = false; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1641 | } |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 1642 | lastTaskDescription = new TaskDescription(label, null, iconResource, iconFilename, |
| 1643 | colorPrimary, colorBackground, statusBarColor, navigationBarColor); |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 1644 | if (mWindowContainerController != null) { |
| 1645 | mWindowContainerController.setTaskDescription(lastTaskDescription); |
| 1646 | } |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1647 | // Update the task affiliation color if we are the parent of the group |
| 1648 | if (taskId == mAffiliatedTaskId) { |
| 1649 | mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor(); |
| 1650 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1651 | } |
| 1652 | } |
| 1653 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1654 | int findEffectiveRootIndex() { |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1655 | int effectiveNdx = 0; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1656 | final int topActivityNdx = mActivities.size() - 1; |
Dianne Hackborn | 39569af | 2014-09-23 10:56:58 -0700 | [diff] [blame] | 1657 | for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1658 | final ActivityRecord r = mActivities.get(activityNdx); |
| 1659 | if (r.finishing) { |
| 1660 | continue; |
| 1661 | } |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1662 | effectiveNdx = activityNdx; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 1663 | if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1664 | break; |
| 1665 | } |
| 1666 | } |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1667 | return effectiveNdx; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | void updateEffectiveIntent() { |
| 1671 | final int effectiveRootIndex = findEffectiveRootIndex(); |
| 1672 | final ActivityRecord r = mActivities.get(effectiveRootIndex); |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 1673 | setIntent(r); |
Winson Chung | 8d9009e | 2017-11-16 15:43:05 -0800 | [diff] [blame] | 1674 | |
| 1675 | // Update the task description when the activities change |
| 1676 | updateTaskDescription(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1679 | private void adjustForMinimalTaskDimensions(Rect bounds) { |
| 1680 | if (bounds == null) { |
| 1681 | return; |
| 1682 | } |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1683 | int minWidth = mMinWidth; |
| 1684 | int minHeight = mMinHeight; |
Robert Carr | 9c5867d | 2016-03-10 15:52:46 -0800 | [diff] [blame] | 1685 | // If the task has no requested minimal size, we'd like to enforce a minimal size |
| 1686 | // so that the user can not render the task too small to manipulate. We don't need |
| 1687 | // to do this for the pinned stack as the bounds are controlled by the system. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1688 | if (!inPinnedWindowingMode()) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1689 | if (minWidth == INVALID_MIN_SIZE) { |
| 1690 | minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 1691 | } |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1692 | if (minHeight == INVALID_MIN_SIZE) { |
| 1693 | minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 1694 | } |
Robert Carr | 9c5867d | 2016-03-10 15:52:46 -0800 | [diff] [blame] | 1695 | } |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1696 | final boolean adjustWidth = minWidth > bounds.width(); |
| 1697 | final boolean adjustHeight = minHeight > bounds.height(); |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1698 | if (!(adjustWidth || adjustHeight)) { |
| 1699 | return; |
| 1700 | } |
| 1701 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1702 | final Rect configBounds = getOverrideBounds(); |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1703 | if (adjustWidth) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1704 | if (!configBounds.isEmpty() && bounds.right == configBounds.right) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1705 | bounds.left = bounds.right - minWidth; |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1706 | } else { |
| 1707 | // Either left bounds match, or neither match, or the previous bounds were |
| 1708 | // fullscreen and we default to keeping left. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1709 | bounds.right = bounds.left + minWidth; |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1710 | } |
| 1711 | } |
| 1712 | if (adjustHeight) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1713 | if (!configBounds.isEmpty() && bounds.bottom == configBounds.bottom) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1714 | bounds.top = bounds.bottom - minHeight; |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1715 | } else { |
| 1716 | // Either top bounds match, or neither match, or the previous bounds were |
| 1717 | // fullscreen and we default to keeping top. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1718 | bounds.bottom = bounds.top + minHeight; |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1723 | /** |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1724 | * @return a new Configuration for this Task, given the provided {@param bounds} and |
| 1725 | * {@param insetBounds}. |
| 1726 | */ |
| 1727 | Configuration computeNewOverrideConfigurationForBounds(Rect bounds, Rect insetBounds) { |
| 1728 | // Compute a new override configuration for the given bounds, if fullscreen bounds |
| 1729 | // (bounds == null), then leave the override config unset |
| 1730 | final Configuration newOverrideConfig = new Configuration(); |
| 1731 | if (bounds != null) { |
| 1732 | newOverrideConfig.setTo(getOverrideConfiguration()); |
| 1733 | mTmpRect.set(bounds); |
| 1734 | adjustForMinimalTaskDimensions(mTmpRect); |
| 1735 | computeOverrideConfiguration(newOverrideConfig, mTmpRect, insetBounds, |
| 1736 | mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom); |
| 1737 | } |
| 1738 | |
| 1739 | return newOverrideConfig; |
| 1740 | } |
| 1741 | |
| 1742 | /** |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1743 | * Update task's override configuration based on the bounds. |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1744 | * @param bounds The bounds of the task. |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 1745 | * @return True if the override configuration was updated. |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1746 | */ |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 1747 | boolean updateOverrideConfiguration(Rect bounds) { |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1748 | return updateOverrideConfiguration(bounds, null /* insetBounds */); |
| 1749 | } |
| 1750 | |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 1751 | void setLastNonFullscreenBounds(Rect bounds) { |
| 1752 | if (mLastNonFullscreenBounds == null) { |
| 1753 | mLastNonFullscreenBounds = new Rect(bounds); |
| 1754 | } else { |
| 1755 | mLastNonFullscreenBounds.set(bounds); |
| 1756 | } |
| 1757 | } |
| 1758 | |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1759 | /** |
| 1760 | * Update task's override configuration based on the bounds. |
| 1761 | * @param bounds The bounds of the task. |
| 1762 | * @param insetBounds The bounds used to calculate the system insets, which is used here to |
| 1763 | * subtract the navigation bar/status bar size from the screen size reported |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1764 | * to the application. See {@link IActivityTaskManager#resizeDockedStack}. |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 1765 | * @return True if the override configuration was updated. |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1766 | */ |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 1767 | boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1768 | if (equivalentOverrideBounds(bounds)) { |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 1769 | return false; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1770 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1771 | final Rect currentBounds = getOverrideBounds(); |
| 1772 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1773 | mTmpConfig.setTo(getOverrideConfiguration()); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1774 | final Configuration newConfig = getOverrideConfiguration(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 1775 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1776 | final boolean matchParentBounds = bounds == null || bounds.isEmpty(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1777 | final boolean persistBounds = getWindowConfiguration().persistTaskBounds(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1778 | if (matchParentBounds) { |
| 1779 | if (!currentBounds.isEmpty() && persistBounds) { |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 1780 | setLastNonFullscreenBounds(currentBounds); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1781 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1782 | setBounds(null); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1783 | newConfig.unset(); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1784 | } else { |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1785 | mTmpRect.set(bounds); |
| 1786 | adjustForMinimalTaskDimensions(mTmpRect); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1787 | setBounds(mTmpRect); |
| 1788 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1789 | if (mStack == null || persistBounds) { |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 1790 | setLastNonFullscreenBounds(getOverrideBounds()); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1791 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 1792 | computeOverrideConfiguration(newConfig, mTmpRect, insetBounds, |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 1793 | mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1794 | } |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1795 | onOverrideConfigurationChanged(newConfig); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 1796 | return !mTmpConfig.equals(newConfig); |
| 1797 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1798 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1799 | /** |
| 1800 | * This should be called when an child activity changes state. This should only |
| 1801 | * be called from |
| 1802 | * {@link ActivityRecord#setState(ActivityState, String)} . |
| 1803 | * @param record The {@link ActivityRecord} whose state has changed. |
| 1804 | * @param state The new state. |
| 1805 | * @param reason The reason for the change. |
| 1806 | */ |
| 1807 | void onActivityStateChanged(ActivityRecord record, ActivityState state, String reason) { |
| 1808 | final ActivityStack parent = getStack(); |
| 1809 | |
| 1810 | if (parent != null) { |
| 1811 | parent.onActivityStateChanged(record, state, reason); |
| 1812 | } |
| 1813 | } |
| 1814 | |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 1815 | @Override |
| 1816 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 1817 | final boolean wasInMultiWindowMode = inMultiWindowMode(); |
| 1818 | super.onConfigurationChanged(newParentConfig); |
| 1819 | if (wasInMultiWindowMode != inMultiWindowMode()) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1820 | mService.mStackSupervisor.scheduleUpdateMultiWindowMode(this); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1821 | } |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 1822 | // TODO: Should also take care of Pip mode changes here. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1825 | /** Clears passed config and fills it with new override values. */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 1826 | // TODO(b/36505427): TaskRecord.computeOverrideConfiguration() is a utility method that doesn't |
| 1827 | // depend on task or stacks, but uses those object to get the display to base the calculation |
| 1828 | // on. Probably best to centralize calculations like this in ConfigurationContainer. |
| 1829 | void computeOverrideConfiguration(Configuration config, Rect bounds, Rect insetBounds, |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 1830 | boolean overrideWidth, boolean overrideHeight) { |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1831 | mTmpNonDecorBounds.set(bounds); |
| 1832 | mTmpStableBounds.set(bounds); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1833 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1834 | config.unset(); |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 1835 | final Configuration parentConfig = getParent().getConfiguration(); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1836 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1837 | final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1838 | |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 1839 | if (mStack != null) { |
| 1840 | final StackWindowController stackController = mStack.getWindowContainerController(); |
| 1841 | stackController.adjustConfigurationForBounds(bounds, insetBounds, |
| 1842 | mTmpNonDecorBounds, mTmpStableBounds, overrideWidth, overrideHeight, density, |
Evan Rosky | b0e3888 | 2018-04-25 12:48:54 -0700 | [diff] [blame] | 1843 | config, parentConfig, getWindowingMode()); |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 1844 | } else { |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1845 | throw new IllegalArgumentException("Expected stack when calculating override config"); |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 1846 | } |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1847 | |
Winson Chung | 60c1aba | 2017-03-14 17:47:42 -0700 | [diff] [blame] | 1848 | config.orientation = (config.screenWidthDp <= config.screenHeightDp) |
| 1849 | ? Configuration.ORIENTATION_PORTRAIT |
| 1850 | : Configuration.ORIENTATION_LANDSCAPE; |
| 1851 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 1852 | // For calculating screen layout, we need to use the non-decor inset screen area for the |
| 1853 | // calculation for compatibility reasons, i.e. screen area without system bars that could |
| 1854 | // never go away in Honeycomb. |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 1855 | final int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density); |
| 1856 | final int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1857 | // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override |
| 1858 | // calculation with partial default. |
Louis Chang | 8b58016 | 2018-06-26 17:58:29 +0800 | [diff] [blame] | 1859 | // Reducing the screen layout starting from its parent config. |
| 1860 | final int sl = parentConfig.screenLayout & |
| 1861 | (Configuration.SCREENLAYOUT_LONG_MASK | Configuration.SCREENLAYOUT_SIZE_MASK); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 1862 | final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1863 | final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 1864 | config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize); |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 1867 | Rect updateOverrideConfigurationFromLaunchBounds() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1868 | final Rect bounds = getLaunchBounds(); |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 1869 | updateOverrideConfiguration(bounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1870 | if (bounds != null && !bounds.isEmpty()) { |
| 1871 | // TODO: Review if we actually want to do this - we are setting the launch bounds |
| 1872 | // directly here. |
| 1873 | bounds.set(getOverrideBounds()); |
Andrii Kulian | 73336d81 | 2016-03-24 12:56:08 -0700 | [diff] [blame] | 1874 | } |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 1875 | return bounds; |
| 1876 | } |
| 1877 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1878 | /** Updates the task's bounds and override configuration to match what is expected for the |
| 1879 | * input stack. */ |
| 1880 | void updateOverrideConfigurationForStack(ActivityStack inStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1881 | if (mStack != null && mStack == inStack) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1882 | return; |
| 1883 | } |
| 1884 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1885 | if (inStack.inFreeformWindowingMode()) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1886 | if (!isResizeable()) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1887 | throw new IllegalArgumentException("Can not position non-resizeable task=" |
| 1888 | + this + " in stack=" + inStack); |
| 1889 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1890 | if (!matchParentBounds()) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1891 | return; |
| 1892 | } |
| 1893 | if (mLastNonFullscreenBounds != null) { |
| 1894 | updateOverrideConfiguration(mLastNonFullscreenBounds); |
| 1895 | } else { |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 1896 | mService.mStackSupervisor.getLaunchParamsController().layoutTask(this, null); |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1897 | } |
| 1898 | } else { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1899 | updateOverrideConfiguration(inStack.getOverrideBounds()); |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1903 | /** Returns the bounds that should be used to launch this task. */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1904 | Rect getLaunchBounds() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1905 | if (mStack == null) { |
Chong Zhang | 7d5f510 | 2016-01-13 10:29:24 -0800 | [diff] [blame] | 1906 | return null; |
| 1907 | } |
| 1908 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1909 | final int windowingMode = getWindowingMode(); |
| 1910 | if (!isActivityTypeStandardOrUndefined() |
| 1911 | || windowingMode == WINDOWING_MODE_FULLSCREEN |
| 1912 | || (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && !isResizeable())) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1913 | return isResizeable() ? mStack.getOverrideBounds() : null; |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1914 | } else if (!getWindowConfiguration().persistTaskBounds()) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1915 | return mStack.getOverrideBounds(); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1916 | } |
| 1917 | return mLastNonFullscreenBounds; |
| 1918 | } |
| 1919 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 1920 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 1921 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1922 | final ActivityRecord r = mActivities.get(activityNdx); |
| 1923 | if (r.visible) { |
| 1924 | r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch); |
| 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1929 | void setRootProcess(WindowProcessController proc) { |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1930 | clearRootProcess(); |
| 1931 | if (intent != null && |
| 1932 | (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0) { |
| 1933 | mRootProcess = proc; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1934 | mRootProcess.addRecentTask(this); |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | void clearRootProcess() { |
| 1939 | if (mRootProcess != null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1940 | mRootProcess.removeRecentTask(this); |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1941 | mRootProcess = null; |
| 1942 | } |
| 1943 | } |
| 1944 | |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1945 | void clearAllPendingOptions() { |
| 1946 | for (int i = getChildCount() - 1; i >= 0; i--) { |
| 1947 | getChildAt(i).clearOptionsLocked(false /* withAbort */); |
| 1948 | } |
| 1949 | } |
| 1950 | |
Winson Chung | abfdcce | 2018-07-02 17:23:33 -0700 | [diff] [blame] | 1951 | /** |
| 1952 | * Fills in a {@link TaskInfo} with information from this task. |
| 1953 | * @param info the {@link TaskInfo} to fill in |
| 1954 | * @param reuseActivitiesReport a temporary activities report that we can reuse to fetch the |
| 1955 | * running activities |
| 1956 | */ |
| 1957 | void fillTaskInfo(TaskInfo info, TaskActivitiesReport reuseActivitiesReport) { |
| 1958 | getNumRunningActivities(reuseActivitiesReport); |
| 1959 | info.userId = userId; |
| 1960 | info.stackId = getStackId(); |
| 1961 | info.taskId = taskId; |
| 1962 | info.isRunning = getTopActivity() != null; |
| 1963 | info.baseIntent = getBaseIntent(); |
| 1964 | info.baseActivity = reuseActivitiesReport.base != null |
| 1965 | ? reuseActivitiesReport.base.intent.getComponent() |
| 1966 | : null; |
| 1967 | info.topActivity = reuseActivitiesReport.top != null |
| 1968 | ? reuseActivitiesReport.top.intent.getComponent() |
| 1969 | : null; |
| 1970 | info.origActivity = origActivity; |
| 1971 | info.realActivity = realActivity; |
| 1972 | info.numActivities = reuseActivitiesReport.numActivities; |
| 1973 | info.lastActiveTime = lastActiveTime; |
| 1974 | info.taskDescription = new ActivityManager.TaskDescription(lastTaskDescription); |
| 1975 | info.supportsSplitScreenMultiWindow = supportsSplitScreenWindowingMode(); |
| 1976 | info.resizeMode = mResizeMode; |
| 1977 | info.configuration.setTo(getConfiguration()); |
| 1978 | } |
| 1979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1981 | pw.print(prefix); pw.print("userId="); pw.print(userId); |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1982 | pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid); |
| 1983 | pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid); |
Suprabh Shukla | 7745c14 | 2016-03-07 18:21:10 -0800 | [diff] [blame] | 1984 | pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1985 | pw.print(" mCallingPackage="); pw.println(mCallingPackage); |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 1986 | if (affinity != null || rootAffinity != null) { |
| 1987 | pw.print(prefix); pw.print("affinity="); pw.print(affinity); |
| 1988 | if (affinity == null || !affinity.equals(rootAffinity)) { |
| 1989 | pw.print(" root="); pw.println(rootAffinity); |
| 1990 | } else { |
| 1991 | pw.println(); |
| 1992 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1993 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1994 | if (voiceSession != null || voiceInteractor != null) { |
| 1995 | pw.print(prefix); pw.print("VOICE: session=0x"); |
| 1996 | pw.print(Integer.toHexString(System.identityHashCode(voiceSession))); |
| 1997 | pw.print(" interactor=0x"); |
| 1998 | pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor))); |
| 1999 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2000 | if (intent != null) { |
| 2001 | StringBuilder sb = new StringBuilder(128); |
| 2002 | sb.append(prefix); sb.append("intent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 2003 | intent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2004 | sb.append('}'); |
| 2005 | pw.println(sb.toString()); |
| 2006 | } |
| 2007 | if (affinityIntent != null) { |
| 2008 | StringBuilder sb = new StringBuilder(128); |
| 2009 | sb.append(prefix); sb.append("affinityIntent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 2010 | affinityIntent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2011 | sb.append('}'); |
| 2012 | pw.println(sb.toString()); |
| 2013 | } |
| 2014 | if (origActivity != null) { |
| 2015 | pw.print(prefix); pw.print("origActivity="); |
| 2016 | pw.println(origActivity.flattenToShortString()); |
| 2017 | } |
| 2018 | if (realActivity != null) { |
| 2019 | pw.print(prefix); pw.print("realActivity="); |
| 2020 | pw.println(realActivity.flattenToShortString()); |
| 2021 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2022 | if (autoRemoveRecents || isPersistable || !isActivityTypeStandard() || numFullscreen != 0) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2023 | pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 2024 | pw.print(" isPersistable="); pw.print(isPersistable); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2025 | pw.print(" numFullscreen="); pw.print(numFullscreen); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2026 | pw.print(" activityType="); pw.println(getActivityType()); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2027 | } |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 2028 | if (rootWasReset || mNeverRelinquishIdentity || mReuseTask |
| 2029 | || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2030 | pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset); |
| 2031 | pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity); |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 2032 | pw.print(" mReuseTask="); pw.print(mReuseTask); |
| 2033 | pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString()); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2034 | } |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2035 | if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID |
| 2036 | || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID |
| 2037 | || mNextAffiliate != null) { |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 2038 | pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId); |
| 2039 | pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId); |
| 2040 | pw.print(" ("); |
| 2041 | if (mPrevAffiliate == null) { |
| 2042 | pw.print("null"); |
| 2043 | } else { |
| 2044 | pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate))); |
| 2045 | } |
| 2046 | pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId); |
| 2047 | pw.print(" ("); |
| 2048 | if (mNextAffiliate == null) { |
| 2049 | pw.print("null"); |
| 2050 | } else { |
| 2051 | pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate))); |
| 2052 | } |
| 2053 | pw.println(")"); |
| 2054 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 2055 | pw.print(prefix); pw.print("Activities="); pw.println(mActivities); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 2056 | if (!askedCompatMode || !inRecents || !isAvailable) { |
| 2057 | pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode); |
| 2058 | pw.print(" inRecents="); pw.print(inRecents); |
| 2059 | pw.print(" isAvailable="); pw.println(isAvailable); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 2060 | } |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 2061 | if (lastDescription != null) { |
| 2062 | pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription); |
| 2063 | } |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 2064 | if (mRootProcess != null) { |
| 2065 | pw.print(prefix); pw.print("mRootProcess="); pw.println(mRootProcess); |
| 2066 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2067 | pw.print(prefix); pw.print("stackId="); pw.println(getStackId()); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2068 | pw.print(prefix + "hasBeenVisible=" + hasBeenVisible); |
| 2069 | pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode)); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2070 | pw.print(" mSupportsPictureInPicture=" + mSupportsPictureInPicture); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2071 | pw.print(" isResizeable=" + isResizeable()); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2072 | pw.print(" lastActiveTime=" + lastActiveTime); |
| 2073 | pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | } |
| 2075 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 2076 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2078 | StringBuilder sb = new StringBuilder(128); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2079 | if (stringName != null) { |
| 2080 | sb.append(stringName); |
| 2081 | sb.append(" U="); |
| 2082 | sb.append(userId); |
Wale Ogunwale | 6c5eb1c | 2015-11-10 07:52:22 -0800 | [diff] [blame] | 2083 | sb.append(" StackId="); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2084 | sb.append(getStackId()); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2085 | sb.append(" sz="); |
| 2086 | sb.append(mActivities.size()); |
| 2087 | sb.append('}'); |
| 2088 | return sb.toString(); |
| 2089 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2090 | sb.append("TaskRecord{"); |
| 2091 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 2092 | sb.append(" #"); |
| 2093 | sb.append(taskId); |
| 2094 | if (affinity != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 2095 | sb.append(" A="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2096 | sb.append(affinity); |
| 2097 | } else if (intent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 2098 | sb.append(" I="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2099 | sb.append(intent.getComponent().flattenToShortString()); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 2100 | } else if (affinityIntent != null && affinityIntent.getComponent() != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 2101 | sb.append(" aI="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2102 | sb.append(affinityIntent.getComponent().flattenToShortString()); |
| 2103 | } else { |
| 2104 | sb.append(" ??"); |
| 2105 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2106 | stringName = sb.toString(); |
| 2107 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2108 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 2109 | |
| 2110 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2111 | final long token = proto.start(fieldId); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 2112 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 2113 | proto.write(ID, taskId); |
| 2114 | for (int i = mActivities.size() - 1; i >= 0; i--) { |
| 2115 | ActivityRecord activity = mActivities.get(i); |
| 2116 | activity.writeToProto(proto, ACTIVITIES); |
| 2117 | } |
| 2118 | proto.write(STACK_ID, mStack.mStackId); |
| 2119 | if (mLastNonFullscreenBounds != null) { |
| 2120 | mLastNonFullscreenBounds.writeToProto(proto, LAST_NON_FULLSCREEN_BOUNDS); |
| 2121 | } |
| 2122 | if (realActivity != null) { |
| 2123 | proto.write(REAL_ACTIVITY, realActivity.flattenToShortString()); |
| 2124 | } |
| 2125 | if (origActivity != null) { |
| 2126 | proto.write(ORIG_ACTIVITY, origActivity.flattenToShortString()); |
| 2127 | } |
| 2128 | proto.write(ACTIVITY_TYPE, getActivityType()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 2129 | proto.write(RESIZE_MODE, mResizeMode); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2130 | // TODO: Remove, no longer needed with windowingMode. |
| 2131 | proto.write(FULLSCREEN, matchParentBounds()); |
| 2132 | |
| 2133 | if (!matchParentBounds()) { |
| 2134 | final Rect bounds = getOverrideBounds(); |
| 2135 | bounds.writeToProto(proto, BOUNDS); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 2136 | } |
| 2137 | proto.write(MIN_WIDTH, mMinWidth); |
| 2138 | proto.write(MIN_HEIGHT, mMinHeight); |
| 2139 | proto.end(token); |
| 2140 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 2141 | |
| 2142 | /** |
| 2143 | * See {@link #getNumRunningActivities(TaskActivitiesReport)}. |
| 2144 | */ |
| 2145 | static class TaskActivitiesReport { |
| 2146 | int numRunning; |
| 2147 | int numActivities; |
| 2148 | ActivityRecord top; |
| 2149 | ActivityRecord base; |
| 2150 | |
| 2151 | void reset() { |
| 2152 | numRunning = numActivities = 0; |
| 2153 | top = base = null; |
| 2154 | } |
| 2155 | } |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2156 | |
| 2157 | /** |
| 2158 | * Saves this {@link TaskRecord} to XML using given serializer. |
| 2159 | */ |
| 2160 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 2161 | if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this); |
| 2162 | |
| 2163 | out.attribute(null, ATTR_TASKID, String.valueOf(taskId)); |
| 2164 | if (realActivity != null) { |
| 2165 | out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString()); |
| 2166 | } |
| 2167 | out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended)); |
| 2168 | if (origActivity != null) { |
| 2169 | out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString()); |
| 2170 | } |
| 2171 | // Write affinity, and root affinity if it is different from affinity. |
| 2172 | // We use the special string "@" for a null root affinity, so we can identify |
| 2173 | // later whether we were given a root affinity or should just make it the |
| 2174 | // same as the affinity. |
| 2175 | if (affinity != null) { |
| 2176 | out.attribute(null, ATTR_AFFINITY, affinity); |
| 2177 | if (!affinity.equals(rootAffinity)) { |
| 2178 | out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@"); |
| 2179 | } |
| 2180 | } else if (rootAffinity != null) { |
| 2181 | out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@"); |
| 2182 | } |
| 2183 | out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset)); |
| 2184 | out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents)); |
| 2185 | out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode)); |
| 2186 | out.attribute(null, ATTR_USERID, String.valueOf(userId)); |
| 2187 | out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete)); |
| 2188 | out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid)); |
| 2189 | out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved)); |
| 2190 | out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity)); |
| 2191 | if (lastDescription != null) { |
| 2192 | out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString()); |
| 2193 | } |
| 2194 | if (lastTaskDescription != null) { |
| 2195 | lastTaskDescription.saveToXml(out); |
| 2196 | } |
| 2197 | out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor)); |
| 2198 | out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId)); |
| 2199 | out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId)); |
| 2200 | out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId)); |
| 2201 | out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid)); |
| 2202 | out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage); |
| 2203 | out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode)); |
| 2204 | out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE, |
| 2205 | String.valueOf(mSupportsPictureInPicture)); |
| 2206 | if (mLastNonFullscreenBounds != null) { |
| 2207 | out.attribute( |
| 2208 | null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString()); |
| 2209 | } |
| 2210 | out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth)); |
| 2211 | out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight)); |
| 2212 | out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION)); |
| 2213 | |
| 2214 | if (affinityIntent != null) { |
| 2215 | out.startTag(null, TAG_AFFINITYINTENT); |
| 2216 | affinityIntent.saveToXml(out); |
| 2217 | out.endTag(null, TAG_AFFINITYINTENT); |
| 2218 | } |
| 2219 | |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 2220 | if (intent != null) { |
| 2221 | out.startTag(null, TAG_INTENT); |
| 2222 | intent.saveToXml(out); |
| 2223 | out.endTag(null, TAG_INTENT); |
| 2224 | } |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2225 | |
| 2226 | final ArrayList<ActivityRecord> activities = mActivities; |
| 2227 | final int numActivities = activities.size(); |
| 2228 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2229 | final ActivityRecord r = activities.get(activityNdx); |
| 2230 | if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() || |
| 2231 | ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT |
| 2232 | | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) && |
| 2233 | activityNdx > 0) { |
| 2234 | // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET). |
| 2235 | break; |
| 2236 | } |
| 2237 | out.startTag(null, TAG_ACTIVITY); |
| 2238 | r.saveToXml(out); |
| 2239 | out.endTag(null, TAG_ACTIVITY); |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | @VisibleForTesting |
| 2244 | static TaskRecordFactory getTaskRecordFactory() { |
| 2245 | if (sTaskRecordFactory == null) { |
| 2246 | setTaskRecordFactory(new TaskRecordFactory()); |
| 2247 | } |
| 2248 | return sTaskRecordFactory; |
| 2249 | } |
| 2250 | |
| 2251 | static void setTaskRecordFactory(TaskRecordFactory factory) { |
| 2252 | sTaskRecordFactory = factory; |
| 2253 | } |
| 2254 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2255 | static TaskRecord create(ActivityTaskManagerService service, int taskId, ActivityInfo info, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2256 | Intent intent, IVoiceInteractionSession voiceSession, |
| 2257 | IVoiceInteractor voiceInteractor) { |
| 2258 | return getTaskRecordFactory().create( |
| 2259 | service, taskId, info, intent, voiceSession, voiceInteractor); |
| 2260 | } |
| 2261 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2262 | static TaskRecord create(ActivityTaskManagerService service, int taskId, ActivityInfo info, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2263 | Intent intent, TaskDescription taskDescription) { |
| 2264 | return getTaskRecordFactory().create(service, taskId, info, intent, taskDescription); |
| 2265 | } |
| 2266 | |
| 2267 | static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) |
| 2268 | throws IOException, XmlPullParserException { |
| 2269 | return getTaskRecordFactory().restoreFromXml(in, stackSupervisor); |
| 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * A factory class used to create {@link TaskRecord} or its subclass if any. This can be |
| 2274 | * specified when system boots by setting it with |
| 2275 | * {@link #setTaskRecordFactory(TaskRecordFactory)}. |
| 2276 | */ |
| 2277 | static class TaskRecordFactory { |
| 2278 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2279 | TaskRecord create(ActivityTaskManagerService service, int taskId, ActivityInfo info, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2280 | Intent intent, IVoiceInteractionSession voiceSession, |
| 2281 | IVoiceInteractor voiceInteractor) { |
| 2282 | return new TaskRecord( |
| 2283 | service, taskId, info, intent, voiceSession, voiceInteractor); |
| 2284 | } |
| 2285 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2286 | TaskRecord create(ActivityTaskManagerService service, int taskId, ActivityInfo info, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2287 | Intent intent, TaskDescription taskDescription) { |
| 2288 | return new TaskRecord(service, taskId, info, intent, taskDescription); |
| 2289 | } |
| 2290 | |
| 2291 | /** |
| 2292 | * Should only be used when we're restoring {@link TaskRecord} from storage. |
| 2293 | */ |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2294 | TaskRecord create(ActivityTaskManagerService service, int taskId, Intent intent, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2295 | Intent affinityIntent, String affinity, String rootAffinity, |
| 2296 | ComponentName realActivity, ComponentName origActivity, boolean rootWasReset, |
| 2297 | boolean autoRemoveRecents, boolean askedCompatMode, int userId, |
| 2298 | int effectiveUid, String lastDescription, ArrayList<ActivityRecord> activities, |
| 2299 | long lastTimeMoved, boolean neverRelinquishIdentity, |
| 2300 | TaskDescription lastTaskDescription, int taskAffiliation, int prevTaskId, |
| 2301 | int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage, |
| 2302 | int resizeMode, boolean supportsPictureInPicture, boolean realActivitySuspended, |
| 2303 | boolean userSetupComplete, int minWidth, int minHeight) { |
| 2304 | return new TaskRecord(service, taskId, intent, affinityIntent, affinity, |
| 2305 | rootAffinity, realActivity, origActivity, rootWasReset, autoRemoveRecents, |
| 2306 | askedCompatMode, userId, effectiveUid, lastDescription, activities, |
| 2307 | lastTimeMoved, neverRelinquishIdentity, lastTaskDescription, taskAffiliation, |
| 2308 | prevTaskId, nextTaskId, taskAffiliationColor, callingUid, callingPackage, |
| 2309 | resizeMode, supportsPictureInPicture, realActivitySuspended, userSetupComplete, |
| 2310 | minWidth, minHeight); |
| 2311 | } |
| 2312 | |
| 2313 | TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) |
| 2314 | throws IOException, XmlPullParserException { |
| 2315 | Intent intent = null; |
| 2316 | Intent affinityIntent = null; |
| 2317 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 2318 | ComponentName realActivity = null; |
| 2319 | boolean realActivitySuspended = false; |
| 2320 | ComponentName origActivity = null; |
| 2321 | String affinity = null; |
| 2322 | String rootAffinity = null; |
| 2323 | boolean hasRootAffinity = false; |
| 2324 | boolean rootHasReset = false; |
| 2325 | boolean autoRemoveRecents = false; |
| 2326 | boolean askedCompatMode = false; |
| 2327 | int taskType = 0; |
| 2328 | int userId = 0; |
| 2329 | boolean userSetupComplete = true; |
| 2330 | int effectiveUid = -1; |
| 2331 | String lastDescription = null; |
| 2332 | long lastTimeOnTop = 0; |
| 2333 | boolean neverRelinquishIdentity = true; |
| 2334 | int taskId = INVALID_TASK_ID; |
| 2335 | final int outerDepth = in.getDepth(); |
| 2336 | TaskDescription taskDescription = new TaskDescription(); |
| 2337 | int taskAffiliation = INVALID_TASK_ID; |
| 2338 | int taskAffiliationColor = 0; |
| 2339 | int prevTaskId = INVALID_TASK_ID; |
| 2340 | int nextTaskId = INVALID_TASK_ID; |
| 2341 | int callingUid = -1; |
| 2342 | String callingPackage = ""; |
| 2343 | int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
| 2344 | boolean supportsPictureInPicture = false; |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 2345 | Rect lastNonFullscreenBounds = null; |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2346 | int minWidth = INVALID_MIN_SIZE; |
| 2347 | int minHeight = INVALID_MIN_SIZE; |
| 2348 | int persistTaskVersion = 0; |
| 2349 | |
| 2350 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 2351 | final String attrName = in.getAttributeName(attrNdx); |
| 2352 | final String attrValue = in.getAttributeValue(attrNdx); |
| 2353 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" + |
| 2354 | attrName + " value=" + attrValue); |
| 2355 | switch (attrName) { |
| 2356 | case ATTR_TASKID: |
| 2357 | if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue); |
| 2358 | break; |
| 2359 | case ATTR_REALACTIVITY: |
| 2360 | realActivity = ComponentName.unflattenFromString(attrValue); |
| 2361 | break; |
| 2362 | case ATTR_REALACTIVITY_SUSPENDED: |
| 2363 | realActivitySuspended = Boolean.valueOf(attrValue); |
| 2364 | break; |
| 2365 | case ATTR_ORIGACTIVITY: |
| 2366 | origActivity = ComponentName.unflattenFromString(attrValue); |
| 2367 | break; |
| 2368 | case ATTR_AFFINITY: |
| 2369 | affinity = attrValue; |
| 2370 | break; |
| 2371 | case ATTR_ROOT_AFFINITY: |
| 2372 | rootAffinity = attrValue; |
| 2373 | hasRootAffinity = true; |
| 2374 | break; |
| 2375 | case ATTR_ROOTHASRESET: |
| 2376 | rootHasReset = Boolean.parseBoolean(attrValue); |
| 2377 | break; |
| 2378 | case ATTR_AUTOREMOVERECENTS: |
| 2379 | autoRemoveRecents = Boolean.parseBoolean(attrValue); |
| 2380 | break; |
| 2381 | case ATTR_ASKEDCOMPATMODE: |
| 2382 | askedCompatMode = Boolean.parseBoolean(attrValue); |
| 2383 | break; |
| 2384 | case ATTR_USERID: |
| 2385 | userId = Integer.parseInt(attrValue); |
| 2386 | break; |
| 2387 | case ATTR_USER_SETUP_COMPLETE: |
| 2388 | userSetupComplete = Boolean.parseBoolean(attrValue); |
| 2389 | break; |
| 2390 | case ATTR_EFFECTIVE_UID: |
| 2391 | effectiveUid = Integer.parseInt(attrValue); |
| 2392 | break; |
| 2393 | case ATTR_TASKTYPE: |
| 2394 | taskType = Integer.parseInt(attrValue); |
| 2395 | break; |
| 2396 | case ATTR_LASTDESCRIPTION: |
| 2397 | lastDescription = attrValue; |
| 2398 | break; |
| 2399 | case ATTR_LASTTIMEMOVED: |
| 2400 | lastTimeOnTop = Long.parseLong(attrValue); |
| 2401 | break; |
| 2402 | case ATTR_NEVERRELINQUISH: |
| 2403 | neverRelinquishIdentity = Boolean.parseBoolean(attrValue); |
| 2404 | break; |
| 2405 | case ATTR_TASK_AFFILIATION: |
| 2406 | taskAffiliation = Integer.parseInt(attrValue); |
| 2407 | break; |
| 2408 | case ATTR_PREV_AFFILIATION: |
| 2409 | prevTaskId = Integer.parseInt(attrValue); |
| 2410 | break; |
| 2411 | case ATTR_NEXT_AFFILIATION: |
| 2412 | nextTaskId = Integer.parseInt(attrValue); |
| 2413 | break; |
| 2414 | case ATTR_TASK_AFFILIATION_COLOR: |
| 2415 | taskAffiliationColor = Integer.parseInt(attrValue); |
| 2416 | break; |
| 2417 | case ATTR_CALLING_UID: |
| 2418 | callingUid = Integer.parseInt(attrValue); |
| 2419 | break; |
| 2420 | case ATTR_CALLING_PACKAGE: |
| 2421 | callingPackage = attrValue; |
| 2422 | break; |
| 2423 | case ATTR_RESIZE_MODE: |
| 2424 | resizeMode = Integer.parseInt(attrValue); |
| 2425 | break; |
| 2426 | case ATTR_SUPPORTS_PICTURE_IN_PICTURE: |
| 2427 | supportsPictureInPicture = Boolean.parseBoolean(attrValue); |
| 2428 | break; |
| 2429 | case ATTR_NON_FULLSCREEN_BOUNDS: |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 2430 | lastNonFullscreenBounds = Rect.unflattenFromString(attrValue); |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2431 | break; |
| 2432 | case ATTR_MIN_WIDTH: |
| 2433 | minWidth = Integer.parseInt(attrValue); |
| 2434 | break; |
| 2435 | case ATTR_MIN_HEIGHT: |
| 2436 | minHeight = Integer.parseInt(attrValue); |
| 2437 | break; |
| 2438 | case ATTR_PERSIST_TASK_VERSION: |
| 2439 | persistTaskVersion = Integer.parseInt(attrValue); |
| 2440 | break; |
| 2441 | default: |
| 2442 | if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) { |
| 2443 | taskDescription.restoreFromXml(attrName, attrValue); |
| 2444 | } else { |
| 2445 | Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName); |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | int event; |
| 2451 | while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && |
| 2452 | (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) { |
| 2453 | if (event == XmlPullParser.START_TAG) { |
| 2454 | final String name = in.getName(); |
| 2455 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, |
| 2456 | "TaskRecord: START_TAG name=" + name); |
| 2457 | if (TAG_AFFINITYINTENT.equals(name)) { |
| 2458 | affinityIntent = Intent.restoreFromXml(in); |
| 2459 | } else if (TAG_INTENT.equals(name)) { |
| 2460 | intent = Intent.restoreFromXml(in); |
| 2461 | } else if (TAG_ACTIVITY.equals(name)) { |
| 2462 | ActivityRecord activity = |
| 2463 | ActivityRecord.restoreFromXml(in, stackSupervisor); |
| 2464 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" + |
| 2465 | activity); |
| 2466 | if (activity != null) { |
| 2467 | activities.add(activity); |
| 2468 | } |
| 2469 | } else { |
Garfield Tan | 1e74019 | 2017-12-12 14:37:42 -0800 | [diff] [blame] | 2470 | handleUnknownTag(name, in); |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | } |
| 2474 | if (!hasRootAffinity) { |
| 2475 | rootAffinity = affinity; |
| 2476 | } else if ("@".equals(rootAffinity)) { |
| 2477 | rootAffinity = null; |
| 2478 | } |
| 2479 | if (effectiveUid <= 0) { |
| 2480 | Intent checkIntent = intent != null ? intent : affinityIntent; |
| 2481 | effectiveUid = 0; |
| 2482 | if (checkIntent != null) { |
| 2483 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 2484 | try { |
| 2485 | ApplicationInfo ai = pm.getApplicationInfo( |
| 2486 | checkIntent.getComponent().getPackageName(), |
| 2487 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 2488 | | PackageManager.MATCH_DISABLED_COMPONENTS, userId); |
| 2489 | if (ai != null) { |
| 2490 | effectiveUid = ai.uid; |
| 2491 | } |
| 2492 | } catch (RemoteException e) { |
| 2493 | } |
| 2494 | } |
| 2495 | Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent |
| 2496 | + ": effectiveUid=" + effectiveUid); |
| 2497 | } |
| 2498 | |
| 2499 | if (persistTaskVersion < 1) { |
| 2500 | // We need to convert the resize mode of home activities saved before version one if |
| 2501 | // they are marked as RESIZE_MODE_RESIZEABLE to |
| 2502 | // RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION since we didn't have that differentiation |
| 2503 | // before version 1 and the system didn't resize home activities before then. |
| 2504 | if (taskType == 1 /* old home type */ && resizeMode == RESIZE_MODE_RESIZEABLE) { |
| 2505 | resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
| 2506 | } |
| 2507 | } else { |
| 2508 | // This activity has previously marked itself explicitly as both resizeable and |
| 2509 | // supporting picture-in-picture. Since there is no longer a requirement for |
| 2510 | // picture-in-picture activities to be resizeable, we can mark this simply as |
| 2511 | // resizeable and supporting picture-in-picture separately. |
| 2512 | if (resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED) { |
| 2513 | resizeMode = RESIZE_MODE_RESIZEABLE; |
| 2514 | supportsPictureInPicture = true; |
| 2515 | } |
| 2516 | } |
| 2517 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2518 | final TaskRecord task = create(stackSupervisor.mService, |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2519 | taskId, intent, affinityIntent, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2520 | affinity, rootAffinity, realActivity, origActivity, rootHasReset, |
| 2521 | autoRemoveRecents, askedCompatMode, userId, effectiveUid, lastDescription, |
| 2522 | activities, lastTimeOnTop, neverRelinquishIdentity, taskDescription, |
| 2523 | taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor, callingUid, |
| 2524 | callingPackage, resizeMode, supportsPictureInPicture, realActivitySuspended, |
| 2525 | userSetupComplete, minWidth, minHeight); |
Garfield Tan | 367b35a | 2017-12-13 12:16:21 -0800 | [diff] [blame] | 2526 | task.mLastNonFullscreenBounds = lastNonFullscreenBounds; |
| 2527 | task.setBounds(lastNonFullscreenBounds); |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2528 | |
| 2529 | for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) { |
| 2530 | activities.get(activityNdx).setTask(task); |
| 2531 | } |
| 2532 | |
| 2533 | if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task); |
| 2534 | return task; |
| 2535 | } |
Garfield Tan | 1e74019 | 2017-12-12 14:37:42 -0800 | [diff] [blame] | 2536 | |
| 2537 | void handleUnknownTag(String name, XmlPullParser in) |
| 2538 | throws IOException, XmlPullParserException { |
| 2539 | Slog.e(TAG, "restoreTask: Unexpected name=" + name); |
| 2540 | XmlUtils.skipCurrentTag(in); |
| 2541 | } |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 2542 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | } |