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