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