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