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