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