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