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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame^] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 20 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 21 | import static android.app.ActivityTaskManager.RESIZE_MODE_FORCED; |
| 22 | import static android.app.ActivityTaskManager.RESIZE_MODE_SYSTEM; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 24 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 29 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 30 | import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 31 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 32 | import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS; |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 33 | import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 34 | import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 35 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; |
| 36 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 37 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 38 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 39 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY; |
| 40 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY; |
| 41 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION; |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 42 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 43 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 44 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED; |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 45 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 46 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
Suprabh Shukla | 7745c14 | 2016-03-07 18:21:10 -0800 | [diff] [blame] | 47 | import static android.provider.Settings.Secure.USER_SETUP_COMPLETE; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 48 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame^] | 49 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 50 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 51 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS; |
| 52 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 53 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 54 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 55 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RECENTS; |
| 56 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; |
| 57 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 58 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 59 | import static com.android.server.wm.ActivityRecord.STARTING_WINDOW_SHOWN; |
| 60 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_MOVING; |
| 61 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_MOVING_TO_TOP; |
| 62 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 63 | import static com.android.server.wm.ActivityStackSupervisor.PAUSE_IMMEDIATELY; |
| 64 | import static com.android.server.wm.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; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 78 | import static java.lang.Integer.MAX_VALUE; |
| 79 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 80 | import android.annotation.IntDef; |
| 81 | import android.annotation.Nullable; |
| 82 | import android.app.Activity; |
| 83 | import android.app.ActivityManager; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 84 | import android.app.ActivityManager.TaskDescription; |
| 85 | import android.app.ActivityManager.TaskSnapshot; |
| 86 | import android.app.ActivityOptions; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 87 | import android.app.ActivityTaskManager; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 88 | import android.app.AppGlobals; |
Winson Chung | abfdcce | 2018-07-02 17:23:33 -0700 | [diff] [blame] | 89 | import android.app.TaskInfo; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 90 | import android.content.ComponentName; |
| 91 | import android.content.Intent; |
| 92 | import android.content.pm.ActivityInfo; |
| 93 | import android.content.pm.ApplicationInfo; |
| 94 | import android.content.pm.IPackageManager; |
| 95 | import android.content.pm.PackageManager; |
| 96 | import android.content.res.Configuration; |
| 97 | import android.graphics.Rect; |
| 98 | import android.os.Debug; |
| 99 | import android.os.RemoteException; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 100 | import android.os.SystemClock; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 101 | import android.os.Trace; |
| 102 | import android.os.UserHandle; |
| 103 | import android.provider.Settings; |
| 104 | import android.service.voice.IVoiceInteractionSession; |
| 105 | import android.util.DisplayMetrics; |
| 106 | import android.util.Slog; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 107 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 108 | |
| 109 | import com.android.internal.annotations.VisibleForTesting; |
| 110 | import com.android.internal.app.IVoiceInteractor; |
| 111 | import com.android.internal.util.XmlUtils; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame^] | 112 | import com.android.server.wm.ActivityStack.ActivityState; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 113 | |
| 114 | import org.xmlpull.v1.XmlPullParser; |
| 115 | import org.xmlpull.v1.XmlPullParserException; |
| 116 | import org.xmlpull.v1.XmlSerializer; |
| 117 | |
| 118 | import java.io.IOException; |
| 119 | import java.io.PrintWriter; |
| 120 | import java.lang.annotation.Retention; |
| 121 | import java.lang.annotation.RetentionPolicy; |
| 122 | import java.util.ArrayList; |
| 123 | import java.util.Objects; |
| 124 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 125 | // TODO: Make package private again once move to WM package is complete. |
| 126 | public class TaskRecord extends ConfigurationContainer implements TaskWindowContainerListener { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 127 | private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_ATM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 128 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 129 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 130 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 131 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 132 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 133 | private static final String ATTR_TASKID = "task_id"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 134 | private static final String TAG_INTENT = "intent"; |
| 135 | private static final String TAG_AFFINITYINTENT = "affinity_intent"; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 136 | private static final String ATTR_REALACTIVITY = "real_activity"; |
| 137 | private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 138 | private static final String ATTR_ORIGACTIVITY = "orig_activity"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 139 | private static final String TAG_ACTIVITY = "activity"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 140 | private static final String ATTR_AFFINITY = "affinity"; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 141 | private static final String ATTR_ROOT_AFFINITY = "root_affinity"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 142 | private static final String ATTR_ROOTHASRESET = "root_has_reset"; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 143 | private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 144 | private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode"; |
| 145 | private static final String ATTR_USERID = "user_id"; |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 146 | private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete"; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 147 | private static final String ATTR_EFFECTIVE_UID = "effective_uid"; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 148 | @Deprecated |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 149 | private static final String ATTR_TASKTYPE = "task_type"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 150 | private static final String ATTR_LASTDESCRIPTION = "last_description"; |
| 151 | private static final String ATTR_LASTTIMEMOVED = "last_time_moved"; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 152 | private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity"; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 153 | private static final String ATTR_TASK_AFFILIATION = "task_affiliation"; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 154 | private static final String ATTR_PREV_AFFILIATION = "prev_affiliation"; |
| 155 | private static final String ATTR_NEXT_AFFILIATION = "next_affiliation"; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 156 | private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color"; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 157 | private static final String ATTR_CALLING_UID = "calling_uid"; |
| 158 | private static final String ATTR_CALLING_PACKAGE = "calling_package"; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 159 | 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] | 160 | private static final String ATTR_RESIZE_MODE = "resize_mode"; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 161 | private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds"; |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 162 | private static final String ATTR_MIN_WIDTH = "min_width"; |
| 163 | private static final String ATTR_MIN_HEIGHT = "min_height"; |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 164 | private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version"; |
Andrii Kulian | 18d7512 | 2016-03-27 20:20:28 -0700 | [diff] [blame] | 165 | |
Wale Ogunwale | 625ed0c | 2016-10-18 08:50:31 -0700 | [diff] [blame] | 166 | // Current version of the task record we persist. Used to check if we need to run any upgrade |
| 167 | // code. |
| 168 | private static final int PERSIST_TASK_VERSION = 1; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 169 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 170 | private static final int INVALID_MIN_SIZE = -1; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 171 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 172 | /** |
| 173 | * The modes to control how the stack is moved to the front when calling |
| 174 | * {@link TaskRecord#reparent}. |
| 175 | */ |
| 176 | @Retention(RetentionPolicy.SOURCE) |
| 177 | @IntDef({ |
| 178 | REPARENT_MOVE_STACK_TO_FRONT, |
| 179 | REPARENT_KEEP_STACK_AT_FRONT, |
| 180 | REPARENT_LEAVE_STACK_IN_PLACE |
| 181 | }) |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 182 | @interface ReparentMoveStackMode {} |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 183 | // 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] | 184 | static final int REPARENT_MOVE_STACK_TO_FRONT = 0; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 185 | // 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] | 186 | static final int REPARENT_KEEP_STACK_AT_FRONT = 1; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 187 | // Do not move the stack as a part of reparenting |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 188 | static final int REPARENT_LEAVE_STACK_IN_PLACE = 2; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 189 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 190 | /** |
| 191 | * The factory used to create {@link TaskRecord}. This allows OEM subclass {@link TaskRecord}. |
| 192 | */ |
| 193 | private static TaskRecordFactory sTaskRecordFactory; |
| 194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | final int taskId; // Unique identifier for this task. |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 196 | String affinity; // The affinity name for this task, or null; may change identity. |
| 197 | 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] | 198 | final IVoiceInteractionSession voiceSession; // Voice interaction session driving task |
| 199 | final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 200 | Intent intent; // The original intent that started the task. Note that this value can |
| 201 | // be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | Intent affinityIntent; // Intent of affinity-moved activity that started this task. |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 203 | 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] | 204 | ComponentName origActivity; // The non-alias activity component of the intent. |
| 205 | ComponentName realActivity; // The actual activity component that started the task. |
Andrei Stingaceanu | 4ccec53 | 2016-01-13 12:10:21 +0000 | [diff] [blame] | 206 | boolean realActivitySuspended; // True if the actual activity component that started the |
| 207 | // task is suspended. |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 208 | boolean inRecents; // Actually in the recents list? |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 209 | long lastActiveTime; // Last time this task was active in the current device session, |
| 210 | // including sleep. This time is initialized to the elapsed time when |
| 211 | // restored from disk. |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 212 | boolean isAvailable; // Is the activity available to be launched? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | boolean rootWasReset; // True if the intent at the root of the task had |
| 214 | // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 215 | boolean autoRemoveRecents; // If true, we should automatically remove the task from |
| 216 | // recents when activity finishes |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 217 | boolean askedCompatMode;// Have asked the user about compat mode for this task. |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 218 | 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] | 219 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 220 | String stringName; // caching of toString() result. |
Dianne Hackborn | 9da2d40 | 2012-03-15 13:43:08 -0700 | [diff] [blame] | 221 | int userId; // user for which this task was created |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 222 | boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity |
| 223 | // was changed. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 224 | |
| 225 | int numFullscreen; // Number of fullscreen activities. |
| 226 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 227 | int mResizeMode; // The resize mode of this task and its activities. |
| 228 | // Based on the {@link ActivityInfo#resizeMode} of the root activity. |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 229 | private boolean mSupportsPictureInPicture; // Whether or not this task and its activities |
| 230 | // support PiP. Based on the {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE} flag |
| 231 | // of the root activity. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 232 | /** Can't be put in lockTask mode. */ |
| 233 | final static int LOCK_TASK_AUTH_DONT_LOCK = 0; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 234 | /** 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] | 235 | final static int LOCK_TASK_AUTH_PINNABLE = 1; |
| 236 | /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */ |
| 237 | final static int LOCK_TASK_AUTH_LAUNCHABLE = 2; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 238 | /** Can enter lockTask without user approval. Can start over existing lockTask task. */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 239 | final static int LOCK_TASK_AUTH_WHITELISTED = 3; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 240 | /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing |
| 241 | * lockTask task. */ |
| 242 | final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 243 | int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE; |
| 244 | |
| 245 | int mLockTaskUid = -1; // The uid of the application that called startLockTask(). |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 246 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 247 | // This represents the last resolved activity values for this task |
| 248 | // NOTE: This value needs to be persisted with each task |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 249 | TaskDescription lastTaskDescription = new TaskDescription(); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 250 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 251 | /** List of all activities in the task arranged in history order */ |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 252 | final ArrayList<ActivityRecord> mActivities; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 253 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 254 | /** Current stack. Setter must always be used to update the value. */ |
| 255 | private ActivityStack mStack; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 256 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 257 | /** The process that had previously hosted the root activity of this task. |
| 258 | * Used to know that we should try harder to keep this process around, in case the |
| 259 | * user wants to return to it. */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 260 | private WindowProcessController mRootProcess; |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 261 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 262 | /** Takes on same value as first root activity */ |
| 263 | boolean isPersistable = false; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 264 | int maxRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 265 | |
| 266 | /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for |
| 267 | * determining the order when restoring. Sign indicates whether last task movement was to front |
| 268 | * (positive) or back (negative). Absolute value indicates time. */ |
| 269 | long mLastTimeMoved = System.currentTimeMillis(); |
| 270 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 271 | /** If original intent did not allow relinquishing task identity, save that information */ |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 272 | private boolean mNeverRelinquishIdentity = true; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 273 | |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 274 | // Used in the unique case where we are clearing the task in order to reuse it. In that case we |
| 275 | // do not want to delete the stack when the task goes empty. |
Filip Gruszczynski | be9dabd | 2016-01-19 12:23:10 -0800 | [diff] [blame] | 276 | private boolean mReuseTask = false; |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 277 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 278 | CharSequence lastDescription; // Last description captured for this item. |
| 279 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 280 | int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent. |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 281 | int mAffiliatedTaskColor; // color of the parent task affiliation. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 282 | TaskRecord mPrevAffiliate; // previous task in affiliated chain. |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 283 | int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 284 | TaskRecord mNextAffiliate; // next task in affiliated chain. |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 285 | int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 286 | |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 287 | // For relaunching the task from recents as though it was launched by the original launcher. |
| 288 | int mCallingUid; |
| 289 | String mCallingPackage; |
| 290 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 291 | final ActivityTaskManagerService mService; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 292 | |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 293 | private final Rect mTmpStableBounds = new Rect(); |
| 294 | private final Rect mTmpNonDecorBounds = new Rect(); |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 295 | private final Rect mTmpRect = new Rect(); |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 296 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 297 | // Last non-fullscreen bounds the task was launched in or resized to. |
| 298 | // The information is persisted and used to determine the appropriate stack to launch the |
| 299 | // task into on restore. |
| 300 | Rect mLastNonFullscreenBounds = null; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 301 | // Minimal width and height of this task when it's resizeable. -1 means it should use the |
| 302 | // default minimal width/height. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 303 | int mMinWidth; |
| 304 | int mMinHeight; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 305 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 306 | // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible) |
| 307 | // This number will be assigned when we evaluate OOM scores for all visible tasks. |
| 308 | int mLayerRank = -1; |
| 309 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 310 | /** Helper object used for updating override configuration. */ |
| 311 | private Configuration mTmpConfig = new Configuration(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 312 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 313 | private TaskWindowContainerController mWindowContainerController; |
| 314 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 315 | /** |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 316 | * Don't use constructor directly. Use {@link #create(ActivityTaskManagerService, int, |
| 317 | * ActivityInfo, Intent, TaskDescription)} instead. |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 318 | */ |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 319 | TaskRecord(ActivityTaskManagerService service, int _taskId, ActivityInfo info, Intent _intent, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 320 | IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 321 | mService = service; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 322 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | taskId = _taskId; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 324 | lastActiveTime = SystemClock.elapsedRealtime(); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 325 | mAffiliatedTaskId = _taskId; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 326 | voiceSession = _voiceSession; |
| 327 | voiceInteractor = _voiceInteractor; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 328 | isAvailable = true; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 329 | mActivities = new ArrayList<>(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 330 | mCallingUid = info.applicationInfo.uid; |
| 331 | mCallingPackage = info.packageName; |
Martijn Coenen | d4a6970 | 2014-06-30 11:12:17 -0700 | [diff] [blame] | 332 | setIntent(_intent, info); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 333 | setMinDimensions(info); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 334 | touchActiveTime(); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 335 | mService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 338 | /** |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 339 | * Don't use constructor directly. |
| 340 | * Use {@link #create(ActivityTaskManagerService, int, ActivityInfo, |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 341 | * Intent, IVoiceInteractionSession, IVoiceInteractor)} instead. |
| 342 | */ |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 343 | TaskRecord(ActivityTaskManagerService service, int _taskId, ActivityInfo info, Intent _intent, |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 344 | TaskDescription _taskDescription) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 345 | mService = service; |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 346 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 347 | taskId = _taskId; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 348 | lastActiveTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 349 | mAffiliatedTaskId = _taskId; |
| 350 | voiceSession = null; |
| 351 | voiceInteractor = null; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 352 | isAvailable = true; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 353 | mActivities = new ArrayList<>(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 354 | mCallingUid = info.applicationInfo.uid; |
| 355 | mCallingPackage = info.packageName; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 356 | setIntent(_intent, info); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 357 | setMinDimensions(info); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 358 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 359 | isPersistable = true; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 360 | // Clamp to [1, max]. |
| 361 | maxRecents = Math.min(Math.max(info.maxRecents, 1), |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 362 | ActivityTaskManager.getMaxAppRecentsLimitStatic()); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 363 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 364 | lastTaskDescription = _taskDescription; |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 365 | touchActiveTime(); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 366 | mService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 369 | /** |
| 370 | * Don't use constructor directly. This is only used by XML parser. |
| 371 | */ |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 372 | TaskRecord(ActivityTaskManagerService service, int _taskId, Intent _intent, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 373 | Intent _affinityIntent, String _affinity, String _rootAffinity, |
| 374 | ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 375 | boolean _autoRemoveRecents, boolean _askedCompatMode, int _userId, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 376 | int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities, |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 377 | long lastTimeMoved, boolean neverRelinquishIdentity, |
| 378 | TaskDescription _lastTaskDescription, int taskAffiliation, int prevTaskId, |
| 379 | int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage, |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 380 | int resizeMode, boolean supportsPictureInPicture, boolean _realActivitySuspended, |
| 381 | boolean userSetupComplete, int minWidth, int minHeight) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 382 | mService = service; |
| 383 | taskId = _taskId; |
| 384 | intent = _intent; |
| 385 | affinityIntent = _affinityIntent; |
| 386 | affinity = _affinity; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 387 | rootAffinity = _rootAffinity; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 388 | voiceSession = null; |
| 389 | voiceInteractor = null; |
| 390 | realActivity = _realActivity; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 391 | realActivitySuspended = _realActivitySuspended; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 392 | origActivity = _origActivity; |
| 393 | rootWasReset = _rootWasReset; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 394 | isAvailable = true; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 395 | autoRemoveRecents = _autoRemoveRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 396 | askedCompatMode = _askedCompatMode; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 397 | userId = _userId; |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 398 | mUserSetupComplete = userSetupComplete; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 399 | effectiveUid = _effectiveUid; |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 400 | lastActiveTime = SystemClock.elapsedRealtime(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 401 | lastDescription = _lastDescription; |
| 402 | mActivities = activities; |
| 403 | mLastTimeMoved = lastTimeMoved; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 404 | mNeverRelinquishIdentity = neverRelinquishIdentity; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 405 | lastTaskDescription = _lastTaskDescription; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 406 | mAffiliatedTaskId = taskAffiliation; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 407 | mAffiliatedTaskColor = taskAffiliationColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 408 | mPrevAffiliateTaskId = prevTaskId; |
| 409 | mNextAffiliateTaskId = nextTaskId; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 410 | mCallingUid = callingUid; |
| 411 | mCallingPackage = callingPackage; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 412 | mResizeMode = resizeMode; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 413 | mSupportsPictureInPicture = supportsPictureInPicture; |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 414 | mMinWidth = minWidth; |
| 415 | mMinHeight = minHeight; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 416 | mService.getTaskChangeNotificationController().notifyTaskCreated(_taskId, realActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 419 | TaskWindowContainerController getWindowContainerController() { |
| 420 | return mWindowContainerController; |
| 421 | } |
| 422 | |
| 423 | void createWindowContainer(boolean onTop, boolean showForAllUsers) { |
| 424 | if (mWindowContainerController != null) { |
| 425 | throw new IllegalArgumentException("Window container=" + mWindowContainerController |
| 426 | + " already created for task=" + this); |
| 427 | } |
| 428 | |
| 429 | final Rect bounds = updateOverrideConfigurationFromLaunchBounds(); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 430 | setWindowContainerController(new TaskWindowContainerController(taskId, this, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 431 | getStack().getWindowContainerController(), userId, bounds, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 432 | mResizeMode, mSupportsPictureInPicture, onTop, |
| 433 | showForAllUsers, lastTaskDescription)); |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Should only be invoked from {@link #createWindowContainer(boolean, boolean)}. |
| 438 | */ |
| 439 | @VisibleForTesting |
| 440 | protected void setWindowContainerController(TaskWindowContainerController controller) { |
| 441 | if (mWindowContainerController != null) { |
| 442 | throw new IllegalArgumentException("Window container=" + mWindowContainerController |
| 443 | + " already created for task=" + this); |
| 444 | } |
| 445 | |
| 446 | mWindowContainerController = controller; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void removeWindowContainer() { |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 450 | mService.getLockTaskController().clearLockedTask(this); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 451 | mWindowContainerController.removeContainer(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 452 | if (!getWindowConfiguration().persistTaskBounds()) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 453 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 454 | // default configuration the next time it launches. |
| 455 | updateOverrideConfiguration(null); |
| 456 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 457 | mService.getTaskChangeNotificationController().notifyTaskRemoved(taskId); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 458 | mWindowContainerController = null; |
| 459 | } |
| 460 | |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 461 | @Override |
| 462 | public void onSnapshotChanged(TaskSnapshot snapshot) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 463 | mService.getTaskChangeNotificationController().notifyTaskSnapshotChanged(taskId, snapshot); |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 464 | } |
| 465 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 466 | void setResizeMode(int resizeMode) { |
| 467 | if (mResizeMode == resizeMode) { |
| 468 | return; |
| 469 | } |
| 470 | mResizeMode = resizeMode; |
| 471 | mWindowContainerController.setResizeable(resizeMode); |
| 472 | mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 473 | mService.mStackSupervisor.resumeFocusedStacksTopActivitiesLocked(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void setTaskDockedResizing(boolean resizing) { |
| 477 | mWindowContainerController.setTaskDockedResizing(resizing); |
| 478 | } |
| 479 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 480 | // TODO: Consolidate this with the resize() method below. |
| 481 | @Override |
| 482 | public void requestResize(Rect bounds, int resizeMode) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 483 | mService.resizeTask(taskId, bounds, resizeMode); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 486 | boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 487 | mService.mWindowManager.deferSurfaceLayout(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 488 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 489 | try { |
| 490 | if (!isResizeable()) { |
| 491 | Slog.w(TAG, "resizeTask: task " + this + " not resizeable."); |
| 492 | return true; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 493 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 494 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 495 | // If this is a forced resize, let it go through even if the bounds is not changing, |
| 496 | // as we might need a relayout due to surface size change (to/from fullscreen). |
| 497 | final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0; |
| 498 | if (equivalentOverrideBounds(bounds) && !forced) { |
| 499 | // Nothing to do here... |
| 500 | return true; |
| 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 (mWindowContainerController == null) { |
| 504 | // Task doesn't exist in window manager yet (e.g. was restored from recents). |
| 505 | // All we can do for now is update the bounds so it can be used when the task is |
| 506 | // added to window manager. |
| 507 | updateOverrideConfiguration(bounds); |
| 508 | if (!inFreeformWindowingMode()) { |
| 509 | // re-restore the task so it can have the proper stack association. |
| 510 | mService.mStackSupervisor.restoreRecentTaskLocked(this, null, !ON_TOP); |
| 511 | } |
| 512 | return true; |
| 513 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 514 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 515 | if (!canResizeToBounds(bounds)) { |
| 516 | throw new IllegalArgumentException("resizeTask: Can not resize task=" + this |
| 517 | + " to bounds=" + bounds + " resizeMode=" + mResizeMode); |
| 518 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 519 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 520 | // Do not move the task to another stack here. |
| 521 | // This method assumes that the task is already placed in the right stack. |
| 522 | // we do not mess with that decision and we only do the resize! |
| 523 | |
| 524 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId); |
| 525 | |
| 526 | final boolean updatedConfig = updateOverrideConfiguration(bounds); |
| 527 | // This variable holds information whether the configuration didn't change in a significant |
| 528 | |
| 529 | // way and the activity was kept the way it was. If it's false, it means the activity |
| 530 | // had |
| 531 | // to be relaunched due to configuration change. |
| 532 | boolean kept = true; |
| 533 | if (updatedConfig) { |
| 534 | final ActivityRecord r = topRunningActivityLocked(); |
| 535 | if (r != null && !deferResume) { |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 536 | kept = r.ensureActivityConfiguration(0 /* globalChanges */, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 537 | preserveWindow); |
Garfield Tan | b915118 | 2018-06-25 16:29:21 -0700 | [diff] [blame] | 538 | // Preserve other windows for resizing because if resizing happens when there |
| 539 | // is a dialog activity in the front, the activity that still shows some |
| 540 | // content to the user will become black and cause flickers. Note in most cases |
| 541 | // this won't cause tons of irrelevant windows being preserved because only |
| 542 | // activities in this task may experience a bounds change. Configs for other |
| 543 | // activities stay the same. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 544 | mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, |
Garfield Tan | b915118 | 2018-06-25 16:29:21 -0700 | [diff] [blame] | 545 | preserveWindow); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 546 | if (!kept) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 547 | mService.mStackSupervisor.resumeFocusedStacksTopActivitiesLocked(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 548 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 549 | } |
| 550 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 551 | mWindowContainerController.resize(kept, forced); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 552 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 553 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 554 | return kept; |
| 555 | } finally { |
| 556 | mService.mWindowManager.continueSurfaceLayout(); |
| 557 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | // TODO: Investigate combining with the resize() method above. |
| 561 | void resizeWindowContainer() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 562 | mWindowContainerController.resize(false /* relayout */, false /* forced */); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 565 | void getWindowContainerBounds(Rect bounds) { |
| 566 | mWindowContainerController.getBounds(bounds); |
| 567 | } |
| 568 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 569 | /** |
| 570 | * Convenience method to reparent a task to the top or bottom position of the stack. |
| 571 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 572 | boolean reparent(ActivityStack preferredStack, boolean toTop, |
| 573 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 574 | String reason) { |
| 575 | return reparent(preferredStack, toTop ? MAX_VALUE : 0, moveStackMode, animate, deferResume, |
| 576 | true /* schedulePictureInPictureModeChange */, reason); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Convenience method to reparent a task to the top or bottom position of the stack, with |
| 581 | * an option to skip scheduling the picture-in-picture mode change. |
| 582 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 583 | boolean reparent(ActivityStack preferredStack, boolean toTop, |
| 584 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 585 | boolean schedulePictureInPictureModeChange, String reason) { |
| 586 | return reparent(preferredStack, toTop ? MAX_VALUE : 0, moveStackMode, animate, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 587 | deferResume, schedulePictureInPictureModeChange, reason); |
| 588 | } |
| 589 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 590 | /** Convenience method to reparent a task to a specific position of the stack. */ |
| 591 | boolean reparent(ActivityStack preferredStack, int position, |
| 592 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 593 | String reason) { |
| 594 | return reparent(preferredStack, position, moveStackMode, animate, deferResume, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 595 | true /* schedulePictureInPictureModeChange */, reason); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 596 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 597 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 598 | /** |
| 599 | * Reparents the task into a preferred stack, creating it if necessary. |
| 600 | * |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 601 | * @param preferredStack the target stack to move this task |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 602 | * @param position the position to place this task in the new stack |
| 603 | * @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] | 604 | * reparenting to be drawn and animated in |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 605 | * @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] | 606 | * previously focused & in front, or never |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 607 | * @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] | 608 | * have changed as a result of this reparenting |
| 609 | * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode |
| 610 | * change. Callers may set this to false if they are explicitly scheduling PiP mode |
| 611 | * changes themselves, like during the PiP animation |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 612 | * @param reason the caller of this reparenting |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 613 | * @return whether the task was reparented |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 614 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 615 | // 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] | 616 | // 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] | 617 | boolean reparent(ActivityStack preferredStack, int position, |
| 618 | @ReparentMoveStackMode int moveStackMode, boolean animate, boolean deferResume, |
| 619 | boolean schedulePictureInPictureModeChange, String reason) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 620 | final ActivityStackSupervisor supervisor = mService.mStackSupervisor; |
| 621 | final WindowManagerService windowManager = mService.mWindowManager; |
| 622 | final ActivityStack sourceStack = getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 623 | final ActivityStack toStack = supervisor.getReparentTargetStack(this, preferredStack, |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 624 | position == MAX_VALUE); |
| 625 | if (toStack == sourceStack) { |
| 626 | return false; |
| 627 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 628 | if (!canBeLaunchedOnDisplay(toStack.mDisplayId)) { |
| 629 | return false; |
| 630 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 631 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 632 | final int toStackWindowingMode = toStack.getWindowingMode(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 633 | final ActivityRecord topActivity = getTopActivity(); |
| 634 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 635 | final boolean mightReplaceWindow = topActivity != null |
| 636 | && replaceWindowsOnTaskMove(getWindowingMode(), toStackWindowingMode); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 637 | if (mightReplaceWindow) { |
| 638 | // We are about to relaunch the activity because its configuration changed due to |
| 639 | // being maximized, i.e. size change. The activity will first remove the old window |
| 640 | // and then add a new one. This call will tell window manager about this, so it can |
| 641 | // preserve the old window until the new one is drawn. This prevents having a gap |
| 642 | // between the removal and addition, in which no window is visible. We also want the |
| 643 | // entrance of the new window to be properly animated. |
| 644 | // Note here we always set the replacing window first, as the flags might be needed |
| 645 | // during the relaunch. If we end up not doing any relaunch, we clear the flags later. |
| 646 | windowManager.setWillReplaceWindow(topActivity.appToken, animate); |
| 647 | } |
| 648 | |
| 649 | windowManager.deferSurfaceLayout(); |
| 650 | boolean kept = true; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 651 | try { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 652 | final ActivityRecord r = topRunningActivityLocked(); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 653 | final boolean wasFocused = r != null && supervisor.isTopDisplayFocusedStack(sourceStack) |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 654 | && (topRunningActivityLocked() == r); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 655 | final boolean wasResumed = r != null && sourceStack.getResumedActivity() == r; |
Winson Chung | 95f8f0e | 2017-03-24 09:20:17 -0700 | [diff] [blame] | 656 | final boolean wasPaused = r != null && sourceStack.mPausingActivity == r; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 657 | |
| 658 | // In some cases the focused stack isn't the front stack. E.g. pinned stack. |
| 659 | // Whenever we are moving the top activity from the front stack we want to make sure to |
| 660 | // move the stack to the front. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 661 | final boolean wasFront = r != null && sourceStack.isTopStackOnDisplay() |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 662 | && (sourceStack.topRunningActivityLocked() == r); |
| 663 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 664 | // Adjust the position for the new parent stack as needed. |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 665 | position = toStack.getAdjustedPositionForTask(this, position, null /* starting */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 666 | |
| 667 | // Must reparent first in window manager to avoid a situation where AM can delete the |
| 668 | // 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] | 669 | mWindowContainerController.reparent(toStack.getWindowContainerController(), position, |
| 670 | moveStackMode == REPARENT_MOVE_STACK_TO_FRONT); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 671 | |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 672 | final boolean moveStackToFront = moveStackMode == REPARENT_MOVE_STACK_TO_FRONT |
| 673 | || (moveStackMode == REPARENT_KEEP_STACK_AT_FRONT && (wasFocused || wasFront)); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 674 | // Move the task |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 675 | sourceStack.removeTask(this, reason, moveStackToFront |
| 676 | ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 677 | toStack.addTask(this, position, false /* schedulePictureInPictureModeChange */, reason); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 678 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 679 | if (schedulePictureInPictureModeChange) { |
| 680 | // Notify of picture-in-picture mode changes |
| 681 | supervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, sourceStack); |
| 682 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 683 | |
| 684 | // TODO: Ensure that this is actually necessary here |
| 685 | // Notify the voice session if required |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 686 | if (voiceSession != null) { |
| 687 | try { |
| 688 | voiceSession.taskStarted(intent, taskId); |
| 689 | } catch (RemoteException e) { |
| 690 | } |
| 691 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 692 | |
| 693 | // If the task had focus before (or we're requested to move focus), move focus to the |
| 694 | // new stack by moving the stack to the front. |
Winson Chung | 95f8f0e | 2017-03-24 09:20:17 -0700 | [diff] [blame] | 695 | if (r != null) { |
| 696 | toStack.moveToFrontAndResumeStateIfNeeded(r, moveStackToFront, wasResumed, |
| 697 | wasPaused, reason); |
| 698 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 699 | if (!animate) { |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 700 | mService.mStackSupervisor.mNoAnimActivities.add(topActivity); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // We might trigger a configuration change. Save the current task bounds for freezing. |
| 704 | // TODO: Should this call be moved inside the resize method in WM? |
| 705 | toStack.prepareFreezingTaskBounds(); |
| 706 | |
| 707 | // 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] | 708 | final boolean toStackSplitScreenPrimary = |
| 709 | toStackWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 710 | final Rect configBounds = getOverrideBounds(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 711 | if ((toStackWindowingMode == WINDOWING_MODE_FULLSCREEN |
| 712 | || toStackWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 713 | && !Objects.equals(configBounds, toStack.getOverrideBounds())) { |
| 714 | kept = resize(toStack.getOverrideBounds(), RESIZE_MODE_SYSTEM, !mightReplaceWindow, |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 715 | deferResume); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 716 | } else if (toStackWindowingMode == WINDOWING_MODE_FREEFORM) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 717 | Rect bounds = getLaunchBounds(); |
| 718 | if (bounds == null) { |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 719 | mService.mStackSupervisor.getLaunchParamsController().layoutTask(this, null); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 720 | bounds = configBounds; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 721 | } |
| 722 | kept = resize(bounds, RESIZE_MODE_FORCED, !mightReplaceWindow, deferResume); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 723 | } else if (toStackSplitScreenPrimary || toStackWindowingMode == WINDOWING_MODE_PINNED) { |
| 724 | if (toStackSplitScreenPrimary && moveStackMode == REPARENT_KEEP_STACK_AT_FRONT) { |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 725 | // Move recents to front so it is not behind home stack when going into docked |
| 726 | // mode |
| 727 | mService.mStackSupervisor.moveRecentsStackToFront(reason); |
| 728 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 729 | kept = resize(toStack.getOverrideBounds(), RESIZE_MODE_SYSTEM, !mightReplaceWindow, |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 730 | deferResume); |
| 731 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 732 | } finally { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 733 | windowManager.continueSurfaceLayout(); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 734 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 735 | |
| 736 | if (mightReplaceWindow) { |
| 737 | // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old |
| 738 | // window), we need to clear the replace window settings. Otherwise, we schedule a |
| 739 | // timeout to remove the old window if the replacing window is not coming in time. |
| 740 | windowManager.scheduleClearWillReplaceWindows(topActivity.appToken, !kept); |
| 741 | } |
| 742 | |
| 743 | if (!deferResume) { |
| 744 | // The task might have already been running and its visibility needs to be synchronized |
| 745 | // with the visibility of the stack / windows. |
| 746 | supervisor.ensureActivitiesVisibleLocked(null, 0, !mightReplaceWindow); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 747 | supervisor.resumeFocusedStacksTopActivitiesLocked(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 750 | // TODO: Handle incorrect request to move before the actual move, not after. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 751 | supervisor.handleNonResizableTaskIfNeeded(this, preferredStack.getWindowingMode(), |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 752 | DEFAULT_DISPLAY, toStack); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 753 | |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 754 | return (preferredStack == toStack); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 755 | } |
| 756 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 757 | /** |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 758 | * @return True if the windows of tasks being moved to the target stack from the source stack |
| 759 | * should be replaced, meaning that window manager will keep the old window around until the new |
| 760 | * is ready. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 761 | */ |
| 762 | private static boolean replaceWindowsOnTaskMove( |
| 763 | int sourceWindowingMode, int targetWindowingMode) { |
| 764 | return sourceWindowingMode == WINDOWING_MODE_FREEFORM |
| 765 | || targetWindowingMode == WINDOWING_MODE_FREEFORM; |
| 766 | } |
| 767 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 768 | void cancelWindowTransition() { |
| 769 | mWindowContainerController.cancelWindowTransition(); |
| 770 | } |
| 771 | |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 772 | /** |
| 773 | * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD! |
| 774 | */ |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 775 | TaskSnapshot getSnapshot(boolean reducedResolution) { |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 776 | |
| 777 | // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more |
| 778 | // synchronized between AM and WM. |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 779 | return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 780 | } |
| 781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | void touchActiveTime() { |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 783 | lastActiveTime = SystemClock.elapsedRealtime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | long getInactiveDuration() { |
Winson Chung | fb44d21 | 2017-10-04 11:39:10 -0700 | [diff] [blame] | 787 | return SystemClock.elapsedRealtime() - lastActiveTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 789 | |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 790 | /** Sets the original intent, and the calling uid and package. */ |
| 791 | void setIntent(ActivityRecord r) { |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 792 | mCallingUid = r.launchedFromUid; |
| 793 | mCallingPackage = r.launchedFromPackage; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 794 | setIntent(r.intent, r.info); |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 795 | setLockTaskAuth(r); |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /** Sets the original intent, _without_ updating the calling uid or package. */ |
| 799 | private void setIntent(Intent _intent, ActivityInfo info) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 800 | if (intent == null) { |
| 801 | mNeverRelinquishIdentity = |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 802 | (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 803 | } else if (mNeverRelinquishIdentity) { |
| 804 | return; |
| 805 | } |
| 806 | |
| 807 | affinity = info.taskAffinity; |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 808 | if (intent == null) { |
| 809 | // If this task already has an intent associated with it, don't set the root |
| 810 | // affinity -- we don't want it changing after initially set, but the initially |
| 811 | // set value may be null. |
| 812 | rootAffinity = affinity; |
| 813 | } |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 814 | effectiveUid = info.applicationInfo.uid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 815 | stringName = null; |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 816 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | if (info.targetActivity == null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 818 | if (_intent != null) { |
| 819 | // If this Intent has a selector, we want to clear it for the |
| 820 | // recent task since it is not relevant if the user later wants |
| 821 | // to re-launch the app. |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 822 | if (_intent.getSelector() != null || _intent.getSourceBounds() != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 823 | _intent = new Intent(_intent); |
| 824 | _intent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 825 | _intent.setSourceBounds(null); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 826 | } |
| 827 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 828 | 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] | 829 | intent = _intent; |
| 830 | realActivity = _intent != null ? _intent.getComponent() : null; |
| 831 | origActivity = null; |
| 832 | } else { |
| 833 | ComponentName targetComponent = new ComponentName( |
| 834 | info.packageName, info.targetActivity); |
| 835 | if (_intent != null) { |
| 836 | Intent targetIntent = new Intent(_intent); |
| 837 | targetIntent.setComponent(targetComponent); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 838 | targetIntent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 839 | targetIntent.setSourceBounds(null); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 840 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 841 | "Setting Intent of " + this + " to target " + targetIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | intent = targetIntent; |
| 843 | realActivity = targetComponent; |
| 844 | origActivity = _intent.getComponent(); |
| 845 | } else { |
| 846 | intent = null; |
| 847 | realActivity = targetComponent; |
| 848 | origActivity = new ComponentName(info.packageName, info.name); |
| 849 | } |
| 850 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 851 | |
Craig Mautner | 47b20ba | 2014-09-17 17:23:44 -0700 | [diff] [blame] | 852 | final int intentFlags = intent == null ? 0 : intent.getFlags(); |
| 853 | 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] | 854 | // Once we are set to an Intent with this flag, we count this |
| 855 | // task as having a true root activity. |
| 856 | rootWasReset = true; |
| 857 | } |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 858 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 859 | mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(), |
| 860 | USER_SETUP_COMPLETE, 0, userId) != 0; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 861 | if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) { |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 862 | // If the activity itself has requested auto-remove, then just always do it. |
| 863 | autoRemoveRecents = true; |
Wale Ogunwale | 843bfb9 | 2015-03-27 11:06:48 -0700 | [diff] [blame] | 864 | } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS)) |
| 865 | == FLAG_ACTIVITY_NEW_DOCUMENT) { |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 866 | // If the caller has not asked for the document to be retained, then we may |
| 867 | // want to turn on auto-remove, depending on whether the target has set its |
| 868 | // own document launch mode. |
| 869 | if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) { |
| 870 | autoRemoveRecents = false; |
| 871 | } else { |
| 872 | autoRemoveRecents = true; |
| 873 | } |
| 874 | } else { |
| 875 | autoRemoveRecents = false; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 876 | } |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 877 | mResizeMode = info.resizeMode; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 878 | mSupportsPictureInPicture = info.supportsPictureInPicture(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 880 | |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 881 | /** Sets the original minimal width and height. */ |
| 882 | private void setMinDimensions(ActivityInfo info) { |
| 883 | if (info != null && info.windowLayout != null) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 884 | mMinWidth = info.windowLayout.minWidth; |
| 885 | mMinHeight = info.windowLayout.minHeight; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 886 | } else { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 887 | mMinWidth = INVALID_MIN_SIZE; |
| 888 | mMinHeight = INVALID_MIN_SIZE; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
Wale Ogunwale | 715a1dc | 2016-02-29 14:27:32 -0800 | [diff] [blame] | 892 | /** |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 893 | * 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] | 894 | * record is based on (normally the root activity intent). |
| 895 | */ |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 896 | boolean isSameIntentFilter(ActivityRecord r) { |
Wale Ogunwale | 715a1dc | 2016-02-29 14:27:32 -0800 | [diff] [blame] | 897 | final Intent intent = new Intent(r.intent); |
| 898 | // Correct the activity intent for aliasing. The task record intent will always be based on |
| 899 | // the real activity that will be launched not the alias, so we need to use an intent with |
| 900 | // the component name pointing to the real activity not the alias in the activity record. |
| 901 | intent.setComponent(r.realActivity); |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 902 | return intent.filterEquals(this.intent); |
Wale Ogunwale | 715a1dc | 2016-02-29 14:27:32 -0800 | [diff] [blame] | 903 | } |
| 904 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 905 | boolean returnsToHomeStack() { |
| 906 | final int returnHomeFlags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME; |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 907 | return intent != null && (intent.getFlags() & returnHomeFlags) == returnHomeFlags; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 910 | void setPrevAffiliate(TaskRecord prevAffiliate) { |
| 911 | mPrevAffiliate = prevAffiliate; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 912 | mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | void setNextAffiliate(TaskRecord nextAffiliate) { |
| 916 | mNextAffiliate = nextAffiliate; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 917 | mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 920 | <T extends ActivityStack> T getStack() { |
| 921 | return (T) mStack; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 924 | /** |
| 925 | * Must be used for setting parent stack because it performs configuration updates. |
| 926 | * Must be called after adding task as a child to the stack. |
| 927 | */ |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 928 | void setStack(ActivityStack stack) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 929 | if (stack != null && !stack.isInStackLocked(this)) { |
| 930 | throw new IllegalStateException("Task must be added as a Stack child first."); |
| 931 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 932 | final ActivityStack oldStack = mStack; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 933 | mStack = stack; |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 934 | |
| 935 | // If the new {@link TaskRecord} is from a different {@link ActivityStack}, remove this |
| 936 | // {@link ActivityRecord} from its current {@link ActivityStack}. |
| 937 | |
| 938 | if (oldStack != mStack) { |
| 939 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 940 | final ActivityRecord activity = getChildAt(i); |
| 941 | |
| 942 | if (oldStack != null) { |
| 943 | oldStack.onActivityRemovedFromStack(activity); |
| 944 | } |
| 945 | |
| 946 | if (mStack != null) { |
| 947 | stack.onActivityAddedToStack(activity); |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 952 | onParentChanged(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | /** |
| 956 | * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set. |
| 957 | */ |
| 958 | int getStackId() { |
| 959 | return mStack != null ? mStack.mStackId : INVALID_STACK_ID; |
| 960 | } |
| 961 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 962 | @Override |
| 963 | protected int getChildCount() { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 964 | return mActivities.size(); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | @Override |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 968 | protected ActivityRecord getChildAt(int index) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 969 | return mActivities.get(index); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | @Override |
| 973 | protected ConfigurationContainer getParent() { |
| 974 | return mStack; |
| 975 | } |
| 976 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 977 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 978 | protected void onParentChanged() { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 979 | super.onParentChanged(); |
| 980 | mService.mStackSupervisor.updateUIDsPresentOnDisplay(); |
| 981 | } |
| 982 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 983 | // Close up recents linked list. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 984 | private void closeRecentsChain() { |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 985 | if (mPrevAffiliate != null) { |
| 986 | mPrevAffiliate.setNextAffiliate(mNextAffiliate); |
| 987 | } |
| 988 | if (mNextAffiliate != null) { |
| 989 | mNextAffiliate.setPrevAffiliate(mPrevAffiliate); |
| 990 | } |
| 991 | setPrevAffiliate(null); |
| 992 | setNextAffiliate(null); |
| 993 | } |
| 994 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 995 | void removedFromRecents() { |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 996 | closeRecentsChain(); |
| 997 | if (inRecents) { |
| 998 | inRecents = false; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 999 | mService.notifyTaskPersisterLocked(this, false); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1000 | } |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 1001 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1002 | clearRootProcess(); |
| 1003 | |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 1004 | // TODO: Use window container controller once tasks are better synced between AM and WM |
| 1005 | mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1008 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
| 1009 | closeRecentsChain(); |
| 1010 | mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1011 | mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1012 | // Find the end |
| 1013 | while (taskToAffiliateWith.mNextAffiliate != null) { |
| 1014 | final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate; |
| 1015 | if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) { |
| 1016 | Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId=" |
| 1017 | + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId); |
| 1018 | if (nextRecents.mPrevAffiliate == taskToAffiliateWith) { |
| 1019 | nextRecents.setPrevAffiliate(null); |
| 1020 | } |
| 1021 | taskToAffiliateWith.setNextAffiliate(null); |
| 1022 | break; |
| 1023 | } |
| 1024 | taskToAffiliateWith = nextRecents; |
| 1025 | } |
| 1026 | taskToAffiliateWith.setNextAffiliate(this); |
| 1027 | setPrevAffiliate(taskToAffiliateWith); |
| 1028 | setNextAffiliate(null); |
| 1029 | } |
| 1030 | |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1031 | /** Returns the intent for the root activity for this task */ |
| 1032 | Intent getBaseIntent() { |
| 1033 | return intent != null ? intent : affinityIntent; |
| 1034 | } |
| 1035 | |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 1036 | /** Returns the first non-finishing activity from the root. */ |
| 1037 | ActivityRecord getRootActivity() { |
| 1038 | for (int i = 0; i < mActivities.size(); i++) { |
| 1039 | final ActivityRecord r = mActivities.get(i); |
| 1040 | if (r.finishing) { |
| 1041 | continue; |
| 1042 | } |
| 1043 | return r; |
| 1044 | } |
| 1045 | return null; |
| 1046 | } |
| 1047 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1048 | ActivityRecord getTopActivity() { |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 1049 | return getTopActivity(true /* includeOverlays */); |
| 1050 | } |
| 1051 | |
| 1052 | ActivityRecord getTopActivity(boolean includeOverlays) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1053 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 1054 | final ActivityRecord r = mActivities.get(i); |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 1055 | if (r.finishing || (!includeOverlays && r.mTaskOverlay)) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1056 | continue; |
| 1057 | } |
| 1058 | return r; |
| 1059 | } |
| 1060 | return null; |
| 1061 | } |
| 1062 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1063 | ActivityRecord topRunningActivityLocked() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1064 | if (mStack != null) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1065 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1066 | ActivityRecord r = mActivities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1067 | if (!r.finishing && r.okToShowLocked()) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1068 | return r; |
| 1069 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | return null; |
| 1073 | } |
| 1074 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 1075 | boolean isVisible() { |
| 1076 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 1077 | final ActivityRecord r = mActivities.get(i); |
| 1078 | if (r.visible) { |
| 1079 | return true; |
| 1080 | } |
| 1081 | } |
| 1082 | return false; |
| 1083 | } |
| 1084 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1085 | void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) { |
| 1086 | if (mStack != null) { |
| 1087 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1088 | ActivityRecord r = mActivities.get(activityNdx); |
Jorim Jaggi | 02f1d2f | 2017-08-04 14:29:16 +0200 | [diff] [blame] | 1089 | if (!r.finishing && r.okToShowLocked() && r.visibleIgnoringKeyguard) { |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1090 | outActivities.add(r); |
| 1091 | } |
| 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1096 | ActivityRecord topRunningActivityWithStartingWindowLocked() { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1097 | if (mStack != null) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1098 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1099 | ActivityRecord r = mActivities.get(activityNdx); |
| 1100 | if (r.mStartingWindowState != STARTING_WINDOW_SHOWN |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1101 | || r.finishing || !r.okToShowLocked()) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1102 | continue; |
| 1103 | } |
| 1104 | return r; |
| 1105 | } |
| 1106 | } |
| 1107 | return null; |
| 1108 | } |
| 1109 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1110 | /** |
| 1111 | * Return the number of running activities, and the number of non-finishing/initializing |
| 1112 | * activities in the provided {@param reportOut} respectively. |
| 1113 | */ |
| 1114 | void getNumRunningActivities(TaskActivitiesReport reportOut) { |
| 1115 | reportOut.reset(); |
| 1116 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 1117 | final ActivityRecord r = mActivities.get(i); |
| 1118 | if (r.finishing) { |
| 1119 | continue; |
| 1120 | } |
| 1121 | |
| 1122 | reportOut.base = r; |
| 1123 | |
| 1124 | // Increment the total number of non-finishing activities |
| 1125 | reportOut.numActivities++; |
| 1126 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1127 | if (reportOut.top == null || (reportOut.top.isState(ActivityState.INITIALIZING))) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1128 | reportOut.top = r; |
| 1129 | // Reset the number of running activities until we hit the first non-initializing |
| 1130 | // activity |
| 1131 | reportOut.numRunning = 0; |
| 1132 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1133 | if (r.attachedToProcess()) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1134 | // Increment the number of actually running activities |
| 1135 | reportOut.numRunning++; |
| 1136 | } |
| 1137 | } |
| 1138 | } |
| 1139 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1140 | boolean okToShowLocked() { |
| 1141 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 1142 | // okay to show the activity when locked. |
| 1143 | return mService.mStackSupervisor.isCurrentProfileLocked(userId) |
| 1144 | || topRunningActivityLocked() != null; |
| 1145 | } |
| 1146 | |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1147 | /** 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] | 1148 | final void setFrontOfTask() { |
| 1149 | boolean foundFront = false; |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1150 | final int numActivities = mActivities.size(); |
Craig Mautner | 704e40b | 2013-12-18 16:43:51 -0800 | [diff] [blame] | 1151 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1152 | final ActivityRecord r = mActivities.get(activityNdx); |
| 1153 | if (foundFront || r.finishing) { |
| 1154 | r.frontOfTask = false; |
| 1155 | } else { |
| 1156 | r.frontOfTask = true; |
| 1157 | // Set frontOfTask false for every following activity. |
| 1158 | foundFront = true; |
| 1159 | } |
| 1160 | } |
Craig Mautner | 9587ee0 | 2014-06-23 15:00:10 +0000 | [diff] [blame] | 1161 | if (!foundFront && numActivities > 0) { |
| 1162 | // All activities of this task are finishing. As we ought to have a frontOfTask |
| 1163 | // activity, make the bottom activity front. |
| 1164 | mActivities.get(0).frontOfTask = true; |
| 1165 | } |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1168 | /** |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1169 | * 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] | 1170 | */ |
| 1171 | final void moveActivityToFrontLocked(ActivityRecord newTop) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1172 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 1173 | "Removing and adding activity " + newTop |
| 1174 | + " to stack at top callers=" + Debug.getCallers(4)); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1175 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1176 | mActivities.remove(newTop); |
| 1177 | mActivities.add(newTop); |
Bryce Lee | d58d7b3 | 2017-09-08 15:55:22 -0700 | [diff] [blame] | 1178 | |
| 1179 | // Make sure window manager is aware of the position change. |
| 1180 | mWindowContainerController.positionChildAtTop(newTop.mWindowContainerController); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1181 | updateEffectiveIntent(); |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1182 | |
Bryce Lee | d71317c | 2017-02-07 14:27:22 -0800 | [diff] [blame] | 1183 | setFrontOfTask(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1186 | void addActivityAtBottom(ActivityRecord r) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1187 | addActivityAtIndex(0, r); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | void addActivityToTop(ActivityRecord r) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1191 | addActivityAtIndex(mActivities.size(), r); |
| 1192 | } |
| 1193 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1194 | @Override |
Wale Ogunwale | eea34ee9 | 2017-08-31 20:07:45 -0700 | [diff] [blame] | 1195 | /*@WindowConfiguration.ActivityType*/ |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1196 | public int getActivityType() { |
| 1197 | final int applicationType = super.getActivityType(); |
| 1198 | if (applicationType != ACTIVITY_TYPE_UNDEFINED || mActivities.isEmpty()) { |
| 1199 | return applicationType; |
| 1200 | } |
| 1201 | return mActivities.get(0).getActivityType(); |
| 1202 | } |
| 1203 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1204 | /** |
| 1205 | * Adds an activity {@param r} at the given {@param index}. The activity {@param r} must either |
| 1206 | * be in the current task or unparented to any task. |
| 1207 | */ |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1208 | void addActivityAtIndex(int index, ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1209 | TaskRecord task = r.getTask(); |
| 1210 | if (task != null && task != this) { |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1211 | throw new IllegalArgumentException("Can not add r=" + " to task=" + this |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1212 | + " current parent=" + task); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1213 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1214 | |
| 1215 | r.setTask(this); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1216 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 1217 | // 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] | 1218 | if (!mActivities.remove(r) && r.fullscreen) { |
| 1219 | // Was not previously in list. |
| 1220 | numFullscreen++; |
| 1221 | } |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 1222 | // Only set this based on the first activity |
| 1223 | if (mActivities.isEmpty()) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1224 | if (r.getActivityType() == ACTIVITY_TYPE_UNDEFINED) { |
| 1225 | // Normally non-standard activity type for the activity record will be set when the |
| 1226 | // object is created, however we delay setting the standard application type until |
| 1227 | // this point so that the task can set the type for additional activities added in |
| 1228 | // the else condition below. |
| 1229 | r.setActivityType(ACTIVITY_TYPE_STANDARD); |
| 1230 | } |
| 1231 | setActivityType(r.getActivityType()); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1232 | isPersistable = r.isPersistable(); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 1233 | mCallingUid = r.launchedFromUid; |
| 1234 | mCallingPackage = r.launchedFromPackage; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1235 | // Clamp to [1, max]. |
| 1236 | maxRecents = Math.min(Math.max(r.info.maxRecents, 1), |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1237 | ActivityTaskManager.getMaxAppRecentsLimitStatic()); |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 1238 | } else { |
| 1239 | // Otherwise make all added activities match this one. |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1240 | r.setActivityType(getActivityType()); |
Craig Mautner | 7873300 | 2013-06-10 13:54:49 -0700 | [diff] [blame] | 1241 | } |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1242 | |
| 1243 | final int size = mActivities.size(); |
| 1244 | |
| 1245 | if (index == size && size > 0) { |
| 1246 | final ActivityRecord top = mActivities.get(size - 1); |
| 1247 | if (top.mTaskOverlay) { |
| 1248 | // Place below the task overlay activity since the overlay activity should always |
| 1249 | // be on top. |
| 1250 | index--; |
| 1251 | } |
| 1252 | } |
| 1253 | |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1254 | index = Math.min(size, index); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1255 | mActivities.add(index, r); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1256 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1257 | updateEffectiveIntent(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1258 | if (r.isPersistable()) { |
| 1259 | mService.notifyTaskPersisterLocked(this, false); |
| 1260 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1261 | |
| 1262 | // Sync. with window manager |
| 1263 | updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1264 | final AppWindowContainerController appController = r.getWindowContainerController(); |
| 1265 | if (appController != null) { |
| 1266 | // Only attempt to move in WM if the child has a controller. It is possible we haven't |
| 1267 | // created controller for the activity we are starting yet. |
| 1268 | mWindowContainerController.positionChildAt(appController, index); |
| 1269 | } |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1270 | |
| 1271 | // Make sure the list of display UID whitelists is updated |
| 1272 | // now that this record is in a new task. |
| 1273 | mService.mStackSupervisor.updateUIDsPresentOnDisplay(); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1276 | /** |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1277 | * Removes the specified activity from this task. |
| 1278 | * @param r The {@link ActivityRecord} to remove. |
| 1279 | * @return true if this was the last activity in the task. |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1280 | */ |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1281 | boolean removeActivity(ActivityRecord r) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1282 | return removeActivity(r, false /* reparenting */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | boolean removeActivity(ActivityRecord r, boolean reparenting) { |
| 1286 | if (r.getTask() != this) { |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1287 | throw new IllegalArgumentException( |
| 1288 | "Activity=" + r + " does not belong to task=" + this); |
| 1289 | } |
| 1290 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1291 | r.setTask(null /* task */, reparenting /* reparenting */); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 1292 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1293 | if (mActivities.remove(r) && r.fullscreen) { |
| 1294 | // Was previously in list. |
| 1295 | numFullscreen--; |
| 1296 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1297 | if (r.isPersistable()) { |
| 1298 | mService.notifyTaskPersisterLocked(this, false); |
| 1299 | } |
Wale Ogunwale | 89182d5 | 2016-03-11 10:38:36 -0800 | [diff] [blame] | 1300 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1301 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | 89182d5 | 2016-03-11 10:38:36 -0800 | [diff] [blame] | 1302 | // We normally notify listeners of task stack changes on pause, however pinned stack |
| 1303 | // activities are normally in the paused state so no notification will be sent there |
| 1304 | // before the activity is removed. We send it here so instead. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1305 | mService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Wale Ogunwale | 89182d5 | 2016-03-11 10:38:36 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 1308 | if (mActivities.isEmpty()) { |
Craig Mautner | 5afcd4d | 2014-06-21 18:11:33 -0700 | [diff] [blame] | 1309 | return !mReuseTask; |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 1310 | } |
| 1311 | updateEffectiveIntent(); |
| 1312 | return false; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1313 | } |
| 1314 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1315 | /** |
| 1316 | * @return whether or not there are ONLY task overlay activities in the stack. |
| 1317 | * If {@param excludeFinishing} is set, then ignore finishing activities in the check. |
| 1318 | * If there are no task overlay activities, this call returns false. |
| 1319 | */ |
| 1320 | boolean onlyHasTaskOverlayActivities(boolean excludeFinishing) { |
| 1321 | int count = 0; |
| 1322 | for (int i = mActivities.size() - 1; i >= 0; i--) { |
| 1323 | final ActivityRecord r = mActivities.get(i); |
| 1324 | if (excludeFinishing && r.finishing) { |
| 1325 | continue; |
| 1326 | } |
| 1327 | if (!r.mTaskOverlay) { |
| 1328 | return false; |
| 1329 | } |
| 1330 | count++; |
| 1331 | } |
| 1332 | return count > 0; |
| 1333 | } |
| 1334 | |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 1335 | boolean autoRemoveFromRecents() { |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 1336 | // We will automatically remove the task either if it has explicitly asked for |
| 1337 | // this, or it is empty and has never contained an activity that got shown to |
| 1338 | // the user. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 1339 | return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1342 | /** |
| 1343 | * Completely remove all activities associated with an existing |
| 1344 | * task starting at a specified index. |
| 1345 | */ |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1346 | final void performClearTaskAtIndexLocked(int activityNdx, boolean pauseImmediately, |
| 1347 | String reason) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1348 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1349 | for ( ; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1350 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1351 | if (r.finishing) { |
| 1352 | continue; |
| 1353 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1354 | if (mStack == null) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1355 | // Task was restored from persistent storage. |
| 1356 | r.takeFromHistory(); |
| 1357 | mActivities.remove(activityNdx); |
| 1358 | --activityNdx; |
| 1359 | --numActivities; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1360 | } else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1361 | reason, false, pauseImmediately)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1362 | --activityNdx; |
| 1363 | --numActivities; |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * Completely remove all activities associated with an existing task. |
| 1370 | */ |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 1371 | void performClearTaskLocked() { |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 1372 | mReuseTask = true; |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1373 | performClearTaskAtIndexLocked(0, !PAUSE_IMMEDIATELY, "clear-task-all"); |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 1374 | mReuseTask = false; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
Filip Gruszczynski | be9dabd | 2016-01-19 12:23:10 -0800 | [diff] [blame] | 1377 | ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) { |
| 1378 | mReuseTask = true; |
| 1379 | final ActivityRecord result = performClearTaskLocked(newR, launchFlags); |
| 1380 | mReuseTask = false; |
| 1381 | return result; |
| 1382 | } |
| 1383 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1384 | /** |
| 1385 | * Perform clear operation as requested by |
| 1386 | * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the |
| 1387 | * stack to the given task, then look for |
| 1388 | * an instance of that activity in the stack and, if found, finish all |
| 1389 | * activities on top of it and return the instance. |
| 1390 | * |
| 1391 | * @param newR Description of the new activity being started. |
| 1392 | * @return Returns the old activity that should be continued to be used, |
| 1393 | * or null if none was found. |
| 1394 | */ |
| 1395 | final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1396 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1397 | for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1398 | ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1399 | if (r.finishing) { |
| 1400 | continue; |
| 1401 | } |
| 1402 | if (r.realActivity.equals(newR.realActivity)) { |
| 1403 | // Here it is! Now finish everything in front... |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1404 | final ActivityRecord ret = r; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1405 | |
| 1406 | for (++activityNdx; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1407 | r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1408 | if (r.finishing) { |
| 1409 | continue; |
| 1410 | } |
| 1411 | ActivityOptions opts = r.takeOptionsLocked(); |
| 1412 | if (opts != null) { |
| 1413 | ret.updateOptionsLocked(opts); |
| 1414 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1415 | if (mStack != null && mStack.finishActivityLocked( |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 1416 | r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1417 | --activityNdx; |
| 1418 | --numActivities; |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | // Finally, if this is a normal launch mode (that is, not |
| 1423 | // expecting onNewIntent()), then we will finish the current |
| 1424 | // instance of the activity so a new fresh one can be started. |
| 1425 | if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE |
Daichi Hirono | 15a0299 | 2016-04-27 18:47:01 +0900 | [diff] [blame] | 1426 | && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0 |
| 1427 | && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1428 | if (!ret.finishing) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1429 | if (mStack != null) { |
| 1430 | mStack.finishActivityLocked( |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1431 | ret, Activity.RESULT_CANCELED, null, "clear-task-top", false); |
| 1432 | } |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 1433 | return null; |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | return ret; |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | return null; |
| 1442 | } |
| 1443 | |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1444 | void removeTaskActivitiesLocked(boolean pauseImmediately, String reason) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1445 | // Just remove the entire task. |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1446 | performClearTaskAtIndexLocked(0, pauseImmediately, reason); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1449 | String lockTaskAuthToString() { |
| 1450 | switch (mLockTaskAuth) { |
| 1451 | case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK"; |
| 1452 | case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE"; |
| 1453 | case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE"; |
| 1454 | case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED"; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1455 | case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV"; |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1456 | default: return "unknown=" + mLockTaskAuth; |
| 1457 | } |
| 1458 | } |
| 1459 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1460 | void setLockTaskAuth() { |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1461 | setLockTaskAuth(getRootActivity()); |
| 1462 | } |
| 1463 | |
| 1464 | private void setLockTaskAuth(@Nullable ActivityRecord r) { |
| 1465 | if (r == null) { |
| 1466 | mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE; |
| 1467 | return; |
| 1468 | } |
| 1469 | |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 1470 | final String pkg = (realActivity != null) ? realActivity.getPackageName() : null; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1471 | final LockTaskController lockTaskController = mService.getLockTaskController(); |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1472 | switch (r.lockTaskLaunchMode) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1473 | case LOCK_TASK_LAUNCH_MODE_DEFAULT: |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1474 | mLockTaskAuth = lockTaskController.isPackageWhitelisted(userId, pkg) |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 1475 | ? LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1476 | break; |
| 1477 | |
| 1478 | case LOCK_TASK_LAUNCH_MODE_NEVER: |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1479 | mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1480 | break; |
| 1481 | |
| 1482 | case LOCK_TASK_LAUNCH_MODE_ALWAYS: |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1483 | mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1484 | break; |
| 1485 | |
| 1486 | case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED: |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1487 | mLockTaskAuth = lockTaskController.isPackageWhitelisted(userId, pkg) |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 1488 | ? LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1489 | break; |
| 1490 | } |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1491 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + |
| 1492 | " mLockTaskAuth=" + lockTaskAuthToString()); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1495 | private boolean isResizeable(boolean checkSupportsPip) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1496 | return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1497 | || (checkSupportsPip && mSupportsPictureInPicture)); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1500 | boolean isResizeable() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1501 | return isResizeable(true /* checkSupportsPip */); |
| 1502 | } |
| 1503 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1504 | @Override |
| 1505 | public boolean supportsSplitScreenWindowingMode() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1506 | // A task can not be docked even if it is considered resizeable because it only supports |
| 1507 | // picture-in-picture mode but has a non-resizeable resizeMode |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1508 | return super.supportsSplitScreenWindowingMode() |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1509 | && mService.mSupportsSplitScreenMultiWindow |
| 1510 | && (mService.mForceResizableActivities |
Bryce Lee | c857a5b | 2017-08-16 10:04:52 -0700 | [diff] [blame] | 1511 | || (isResizeable(false /* checkSupportsPip */) |
| 1512 | && !ActivityInfo.isPreserveOrientationMode(mResizeMode))); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1513 | } |
| 1514 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1515 | /** |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1516 | * Check whether this task can be launched on the specified display. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1517 | * |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1518 | * @param displayId Target display id. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1519 | * @return {@code true} if either it is the default display or this activity can be put on a |
| 1520 | * secondary display. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1521 | */ |
| 1522 | boolean canBeLaunchedOnDisplay(int displayId) { |
| 1523 | return mService.mStackSupervisor.canPlaceEntityOnDisplay(displayId, |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1524 | -1 /* don't check PID */, -1 /* don't check UID */, null /* activityInfo */); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /** |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1528 | * Check that a given bounds matches the application requested orientation. |
| 1529 | * |
| 1530 | * @param bounds The bounds to be tested. |
| 1531 | * @return True if the requested bounds are okay for a resizing request. |
| 1532 | */ |
Wale Ogunwale | 069bbd3 | 2017-02-03 07:58:14 -0800 | [diff] [blame] | 1533 | private boolean canResizeToBounds(Rect bounds) { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1534 | if (bounds == null || !inFreeformWindowingMode()) { |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1535 | // Note: If not on the freeform workspace, we ignore the bounds. |
| 1536 | return true; |
| 1537 | } |
| 1538 | final boolean landscape = bounds.width() > bounds.height(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1539 | final Rect configBounds = getOverrideBounds(); |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1540 | if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1541 | return configBounds.isEmpty() |
| 1542 | || landscape == (configBounds.width() > configBounds.height()); |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 1543 | } |
| 1544 | return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape) |
| 1545 | && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape); |
| 1546 | } |
| 1547 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1548 | /** |
Yorke Lee | bdef537 | 2017-04-10 16:38:51 -0700 | [diff] [blame] | 1549 | * @return {@code true} if the task is being cleared for the purposes of being reused. |
| 1550 | */ |
| 1551 | boolean isClearingToReuseTask() { |
| 1552 | return mReuseTask; |
| 1553 | } |
| 1554 | |
| 1555 | /** |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1556 | * Find the activity in the history stack within the given task. Returns |
| 1557 | * the index within the history at which it's found, or < 0 if not found. |
| 1558 | */ |
| 1559 | final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) { |
| 1560 | final ComponentName realActivity = r.realActivity; |
| 1561 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1562 | ActivityRecord candidate = mActivities.get(activityNdx); |
| 1563 | if (candidate.finishing) { |
| 1564 | continue; |
| 1565 | } |
| 1566 | if (candidate.realActivity.equals(realActivity)) { |
| 1567 | return candidate; |
| 1568 | } |
| 1569 | } |
| 1570 | return null; |
| 1571 | } |
| 1572 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1573 | /** Updates the last task description values. */ |
| 1574 | void updateTaskDescription() { |
| 1575 | // Traverse upwards looking for any break between main task activities and |
| 1576 | // utility activities. |
| 1577 | int activityNdx; |
| 1578 | final int numActivities = mActivities.size(); |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 1579 | final boolean relinquish = numActivities != 0 && |
| 1580 | (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1581 | for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1582 | ++activityNdx) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1583 | final ActivityRecord r = mActivities.get(activityNdx); |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 1584 | if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1585 | // This will be the top activity for determining taskDescription. Pre-inc to |
| 1586 | // overcome initial decrement below. |
| 1587 | ++activityNdx; |
| 1588 | break; |
| 1589 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1590 | if (r.intent != null && |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1591 | (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1592 | break; |
| 1593 | } |
| 1594 | } |
| 1595 | if (activityNdx > 0) { |
| 1596 | // Traverse downwards starting below break looking for set label, icon. |
| 1597 | // Note that if there are activities in the task but none of them set the |
| 1598 | // recent activity values, then we do not fall back to the last set |
| 1599 | // values in the TaskRecord. |
| 1600 | String label = null; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1601 | String iconFilename = null; |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 1602 | int iconResource = -1; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1603 | int colorPrimary = 0; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1604 | int colorBackground = 0; |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1605 | int statusBarColor = 0; |
| 1606 | int navigationBarColor = 0; |
| 1607 | boolean topActivity = true; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1608 | for (--activityNdx; activityNdx >= 0; --activityNdx) { |
| 1609 | final ActivityRecord r = mActivities.get(activityNdx); |
Winson Chung | 80f80db | 2018-05-30 21:13:25 -0700 | [diff] [blame] | 1610 | if (r.mTaskOverlay) { |
| 1611 | continue; |
| 1612 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1613 | if (r.taskDescription != null) { |
| 1614 | if (label == null) { |
| 1615 | label = r.taskDescription.getLabel(); |
| 1616 | } |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 1617 | if (iconResource == -1) { |
| 1618 | iconResource = r.taskDescription.getIconResource(); |
| 1619 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1620 | if (iconFilename == null) { |
| 1621 | iconFilename = r.taskDescription.getIconFilename(); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1622 | } |
| 1623 | if (colorPrimary == 0) { |
| 1624 | colorPrimary = r.taskDescription.getPrimaryColor(); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1625 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1626 | if (topActivity) { |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1627 | colorBackground = r.taskDescription.getBackgroundColor(); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1628 | statusBarColor = r.taskDescription.getStatusBarColor(); |
| 1629 | navigationBarColor = r.taskDescription.getNavigationBarColor(); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1630 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1631 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1632 | topActivity = false; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1633 | } |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 1634 | lastTaskDescription = new TaskDescription(label, null, iconResource, iconFilename, |
| 1635 | colorPrimary, colorBackground, statusBarColor, navigationBarColor); |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 1636 | if (mWindowContainerController != null) { |
| 1637 | mWindowContainerController.setTaskDescription(lastTaskDescription); |
| 1638 | } |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1639 | // Update the task affiliation color if we are the parent of the group |
| 1640 | if (taskId == mAffiliatedTaskId) { |
| 1641 | mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor(); |
| 1642 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1643 | } |
| 1644 | } |
| 1645 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1646 | int findEffectiveRootIndex() { |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1647 | int effectiveNdx = 0; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1648 | final int topActivityNdx = mActivities.size() - 1; |
Dianne Hackborn | 39569af | 2014-09-23 10:56:58 -0700 | [diff] [blame] | 1649 | for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1650 | final ActivityRecord r = mActivities.get(activityNdx); |
| 1651 | if (r.finishing) { |
| 1652 | continue; |
| 1653 | } |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1654 | effectiveNdx = activityNdx; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 1655 | if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1656 | break; |
| 1657 | } |
| 1658 | } |
Craig Mautner | 4767f4b | 2014-09-18 15:38:33 -0700 | [diff] [blame] | 1659 | return effectiveNdx; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | void updateEffectiveIntent() { |
| 1663 | final int effectiveRootIndex = findEffectiveRootIndex(); |
| 1664 | final ActivityRecord r = mActivities.get(effectiveRootIndex); |
Winson Chung | fee2677 | 2014-08-05 12:21:52 -0700 | [diff] [blame] | 1665 | setIntent(r); |
Winson Chung | 8d9009e | 2017-11-16 15:43:05 -0800 | [diff] [blame] | 1666 | |
| 1667 | // Update the task description when the activities change |
| 1668 | updateTaskDescription(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 1671 | private void adjustForMinimalTaskDimensions(Rect bounds) { |
| 1672 | if (bounds == null) { |
| 1673 | return; |
| 1674 | } |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1675 | int minWidth = mMinWidth; |
| 1676 | int minHeight = mMinHeight; |
Robert Carr | 9c5867d | 2016-03-10 15:52:46 -0800 | [diff] [blame] | 1677 | // If the task has no requested minimal size, we'd like to enforce a minimal size |
| 1678 | // so that the user can not render the task too small to manipulate. We don't need |
| 1679 | // 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] | 1680 | if (!inPinnedWindowingMode()) { |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 1681 | final int defaultMinSizeDp = |
| 1682 | mService.mStackSupervisor.mDefaultMinSizeOfResizeableTaskDp; |
| 1683 | final ActivityDisplay display = |
| 1684 | mService.mStackSupervisor.getActivityDisplay(mStack.mDisplayId); |
| 1685 | final float density = |
| 1686 | (float) display.getConfiguration().densityDpi / DisplayMetrics.DENSITY_DEFAULT; |
| 1687 | final int defaultMinSize = (int) (defaultMinSizeDp * density); |
| 1688 | |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 1689 | if (minWidth == INVALID_MIN_SIZE) { |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 1690 | minWidth = defaultMinSize; |
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) { |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 1693 | minHeight = defaultMinSize; |
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 | } |