blob: dc636e53b18cc4fb67e039f79c0bf5bae2fd27e8 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server.am;
18
Winson Chung74666102017-02-22 17:49:24 -080019import android.annotation.IntDef;
Jorim Jaggi0a932142016-02-01 17:42:25 -080020import android.annotation.Nullable;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070021import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070022import android.app.ActivityManager;
Wale Ogunwale3797c222015-10-27 14:21:58 -070023import android.app.ActivityManager.StackId;
Craig Mautner648f69b2014-09-18 14:16:26 -070024import android.app.ActivityManager.TaskDescription;
Jorim Jaggie2c77f92016-12-29 14:57:22 +010025import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwaleff3c66c2015-11-18 19:22:49 -080026import android.app.ActivityManager.TaskThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -080027import android.app.ActivityManager.TaskThumbnailInfo;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070028import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070029import android.app.AppGlobals;
Jorim Jaggi0a932142016-02-01 17:42:25 -080030import android.app.IActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.ComponentName;
32import android.content.Intent;
33import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070034import android.content.pm.ApplicationInfo;
35import android.content.pm.IPackageManager;
36import android.content.pm.PackageManager;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070037import android.content.res.Configuration;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070038import android.graphics.Bitmap;
Winsonc809cbb2015-11-02 12:06:15 -080039import android.graphics.Point;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070040import android.graphics.Rect;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070041import android.os.Debug;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070042import android.os.ParcelFileDescriptor;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070043import android.os.RemoteException;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080044import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070045import android.os.UserHandle;
Suprabh Shukla7745c142016-03-07 18:21:10 -080046import android.provider.Settings;
Dianne Hackborn91097de2014-04-04 18:02:06 -070047import android.service.voice.IVoiceInteractionSession;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070048import android.util.DisplayMetrics;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070049import android.util.Slog;
Suprabh Shukla23593142015-11-03 17:31:15 -080050
Bryce Lee04ab3462017-04-10 15:06:33 -070051import com.android.internal.annotations.VisibleForTesting;
Dianne Hackborn91097de2014-04-04 18:02:06 -070052import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070053import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080054
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -080055import com.android.server.wm.AppWindowContainerController;
Winson Chungbdc646f2017-02-13 12:12:22 -080056import com.android.server.wm.StackWindowController;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080057import com.android.server.wm.TaskWindowContainerController;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010058import com.android.server.wm.TaskWindowContainerListener;
Winson Chung74666102017-02-22 17:49:24 -080059import com.android.server.wm.WindowManagerService;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010060
Craig Mautner21d24a22014-04-23 11:45:37 -070061import org.xmlpull.v1.XmlPullParser;
62import org.xmlpull.v1.XmlPullParserException;
63import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
Craig Mautnerc0ffce52014-07-01 12:38:52 -070065import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070066import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import java.io.PrintWriter;
Winson Chung74666102017-02-22 17:49:24 -080068import java.lang.annotation.Retention;
69import java.lang.annotation.RetentionPolicy;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080070import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070071import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080073import static android.app.ActivityManager.RESIZE_MODE_FORCED;
Winson Chung74666102017-02-22 17:49:24 -080074import static android.app.ActivityManager.RESIZE_MODE_SYSTEM;
Winson Chung83471632016-12-13 11:02:12 -080075import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080076import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
77import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
78import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
79import static android.app.ActivityManager.StackId.HOME_STACK_ID;
80import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
81import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080082import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080083import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
84import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070085import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
Jorim Jaggi0a932142016-02-01 17:42:25 -080086import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
87import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
88import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
89import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
skuhne@google.com322347b2016-12-02 12:54:03 -080090import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
91import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
92import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Wale Ogunwaled829d362016-02-10 19:24:49 -080093import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070094import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -080095import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070096import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggi0a932142016-02-01 17:42:25 -080097import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080098import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Suprabh Shukla7745c142016-03-07 18:21:10 -080099import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700100import static android.view.Display.DEFAULT_DISPLAY;
101
Jorim Jaggi0a932142016-02-01 17:42:25 -0800102import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
103import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
104import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
105import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
106import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
107import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
108import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
109import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
110import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
111import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800112import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Winson Chung83471632016-12-13 11:02:12 -0800113import static com.android.server.am.ActivityRecord.ASSISTANT_ACTIVITY_TYPE;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800114import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
115import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700116import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800117import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
Winson Chung6954fc92017-03-24 16:22:12 -0700118import static com.android.server.am.ActivityStackSupervisor.PAUSE_IMMEDIATELY;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800119import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800120
Winson Chung74666102017-02-22 17:49:24 -0800121import static java.lang.Integer.MAX_VALUE;
122
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100123final class TaskRecord extends ConfigurationContainer implements TaskWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800124 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700125 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700126 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -0700127 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700128 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800129
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700130 private static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700131 private static final String TAG_INTENT = "intent";
132 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700133 private static final String ATTR_REALACTIVITY = "real_activity";
134 private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700135 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700136 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700137 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700138 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700139 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700140 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700141 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
142 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800143 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700144 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700145 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700146 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700147 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700148 private static final String ATTR_LASTDESCRIPTION = "last_description";
149 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700150 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700151 private static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700152 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
153 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700154 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700155 private static final String ATTR_CALLING_UID = "calling_uid";
156 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Winson Chungd3395382016-12-13 11:49:09 -0800157 private static final String ATTR_SUPPORTS_PICTURE_IN_PICTURE = "supports_picture_in_picture";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800158 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700159 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700160 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700161 private static final String ATTR_MIN_WIDTH = "min_width";
162 private static final String ATTR_MIN_HEIGHT = "min_height";
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700163 private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
Andrii Kulian18d75122016-03-27 20:20:28 -0700164
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700165 // Current version of the task record we persist. Used to check if we need to run any upgrade
166 // code.
167 private static final int PERSIST_TASK_VERSION = 1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700168 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
169
Wale Ogunwale18795a22014-12-03 11:38:33 -0800170 static final int INVALID_TASK_ID = -1;
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700171 private static final int INVALID_MIN_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800172
Winson Chung74666102017-02-22 17:49:24 -0800173 /**
174 * The modes to control how the stack is moved to the front when calling
175 * {@link TaskRecord#reparent}.
176 */
177 @Retention(RetentionPolicy.SOURCE)
178 @IntDef({
179 REPARENT_MOVE_STACK_TO_FRONT,
180 REPARENT_KEEP_STACK_AT_FRONT,
181 REPARENT_LEAVE_STACK_IN_PLACE
182 })
183 public @interface ReparentMoveStackMode {}
184 // Moves the stack to the front if it was not at the front
185 public static final int REPARENT_MOVE_STACK_TO_FRONT = 0;
186 // Only moves the stack to the front if it was focused or front most already
187 public static final int REPARENT_KEEP_STACK_AT_FRONT = 1;
188 // Do not move the stack as a part of reparenting
189 public static final int REPARENT_LEAVE_STACK_IN_PLACE = 2;
190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700192 String affinity; // The affinity name for this task, or null; may change identity.
193 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700194 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
195 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 Intent intent; // The original intent that started the task.
197 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700198 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 ComponentName origActivity; // The non-alias activity component of the intent.
200 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000201 boolean realActivitySuspended; // True if the actual activity component that started the
202 // task is suspended.
Winson Chung36f3f032016-09-08 23:29:43 +0000203 long firstActiveTime; // First time this task was active.
204 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700205 boolean inRecents; // Actually in the recents list?
206 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 boolean rootWasReset; // True if the intent at the root of the task had
208 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700209 boolean autoRemoveRecents; // If true, we should automatically remove the task from
210 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700211 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700212 boolean hasBeenVisible; // Set if any activities in the task have been visible to the user.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700214 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700215 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800216 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
217 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800218
219 int numFullscreen; // Number of fullscreen activities.
220
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800221 int mResizeMode; // The resize mode of this task and its activities.
222 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800223 private boolean mSupportsPictureInPicture; // Whether or not this task and its activities
224 // support PiP. Based on the {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE} flag
225 // of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800226 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
227 // changes on a temporary basis.
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700228 private int mLockTaskMode; // Which tasklock mode to launch this task in. One of
229 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700230 private boolean mPrivileged; // The root activity application of this task holds
231 // privileged permissions.
232
Craig Mautner15df08a2015-04-01 12:17:18 -0700233 /** Can't be put in lockTask mode. */
234 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100235 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700236 final static int LOCK_TASK_AUTH_PINNABLE = 1;
237 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
238 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100239 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700240 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100241 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
242 * lockTask task. */
243 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700244 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
245
246 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800247
Winson Chung03a9bae2014-05-02 09:56:12 -0700248 // This represents the last resolved activity values for this task
249 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700250 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700251
Craig Mautnerd2328952013-03-05 12:46:26 -0800252 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700253 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800254
Andrii Kulian02b7a832016-10-06 23:11:56 -0700255 /** Current stack. Setter must always be used to update the value. */
256 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800257
Craig Mautner2c1faed2013-07-23 12:56:02 -0700258 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700259 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700260
Craig Mautner21d24a22014-04-23 11:45:37 -0700261 /** Takes on same value as first root activity */
262 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700263 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700264
265 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
266 * determining the order when restoring. Sign indicates whether last task movement was to front
267 * (positive) or back (negative). Absolute value indicates time. */
268 long mLastTimeMoved = System.currentTimeMillis();
269
Craig Mautner84984fa2014-06-19 11:19:20 -0700270 /** Indication of what to run next when task exits. Use ActivityRecord types.
271 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
272 * task stack. */
273 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700274
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700275 /** If original intent did not allow relinquishing task identity, save that information */
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700276 private boolean mNeverRelinquishIdentity = true;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700277
Craig Mautner362449a2014-06-20 14:04:39 -0700278 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
279 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800280 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700281
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700282 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700283 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700284 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800285 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700286 CharSequence lastDescription; // Last description captured for this item.
287
Craig Mautnera228ae92014-07-09 05:44:55 -0700288 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700289 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700290 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800291 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700292 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800293 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700294
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700295 // For relaunching the task from recents as though it was launched by the original launcher.
296 int mCallingUid;
297 String mCallingPackage;
298
Craig Mautner21d24a22014-04-23 11:45:37 -0700299 final ActivityManagerService mService;
300
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700301 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
302 boolean mFullscreen = true;
303
304 // Bounds of the Task. null for fullscreen tasks.
305 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800306 private final Rect mTmpStableBounds = new Rect();
307 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800308 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800309
Wale Ogunwale706ed792015-08-02 10:29:44 -0700310 // Last non-fullscreen bounds the task was launched in or resized to.
311 // The information is persisted and used to determine the appropriate stack to launch the
312 // task into on restore.
313 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700314 // Minimal width and height of this task when it's resizeable. -1 means it should use the
315 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700316 int mMinWidth;
317 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700318
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700319 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
320 // This number will be assigned when we evaluate OOM scores for all visible tasks.
321 int mLayerRank = -1;
322
Andrii Kulian1779e612016-10-12 21:58:25 -0700323 /** Helper object used for updating override configuration. */
324 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700325
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800326 private TaskWindowContainerController mWindowContainerController;
327
Craig Mautner21d24a22014-04-23 11:45:37 -0700328 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Wale Ogunwale72919d22016-12-08 18:58:50 -0800329 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, int type) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700330 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700331 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
332 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800333 userId = UserHandle.getUserId(info.applicationInfo.uid);
334 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800335 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700337 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700338 voiceSession = _voiceSession;
339 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700340 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800341 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700342 mCallingUid = info.applicationInfo.uid;
343 mCallingPackage = info.packageName;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800344 taskType = type;
Martijn Coenend4a69702014-06-30 11:12:17 -0700345 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700346 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700347 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700348 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Craig Mautner21d24a22014-04-23 11:45:37 -0700349 }
350
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700351 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800352 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700353 mService = service;
354 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
355 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800356 userId = UserHandle.getUserId(info.applicationInfo.uid);
357 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800358 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700359 taskId = _taskId;
360 mAffiliatedTaskId = _taskId;
361 voiceSession = null;
362 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700363 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800364 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700365 mCallingUid = info.applicationInfo.uid;
366 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700367 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700368 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700369
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700370 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700371 // Clamp to [1, max].
372 maxRecents = Math.min(Math.max(info.maxRecents, 1),
373 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700374
375 taskType = APPLICATION_ACTIVITY_TYPE;
376 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700377 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700378 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700379 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700380 }
381
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800382 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
383 Intent _affinityIntent, String _affinity, String _rootAffinity,
384 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
385 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
386 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
387 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
388 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800389 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
390 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Winson Chungd3395382016-12-13 11:49:09 -0800391 int resizeMode, boolean supportsPictureInPicture, boolean privileged,
392 boolean _realActivitySuspended, boolean userSetupComplete, int minWidth,
393 int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700394 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700395 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
396 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800397 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800398 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700399 taskId = _taskId;
400 intent = _intent;
401 affinityIntent = _affinityIntent;
402 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800403 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700404 voiceSession = null;
405 voiceInteractor = null;
406 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800407 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700408 origActivity = _origActivity;
409 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700410 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700411 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700412 askedCompatMode = _askedCompatMode;
413 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700414 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700415 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800416 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700417 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700418 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700419 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700420 lastDescription = _lastDescription;
421 mActivities = activities;
422 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700423 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700424 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700425 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700426 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700427 mPrevAffiliateTaskId = prevTaskId;
428 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700429 mCallingUid = callingUid;
430 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800431 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800432 mSupportsPictureInPicture = supportsPictureInPicture;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700433 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700434 mMinWidth = minWidth;
435 mMinHeight = minHeight;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700436 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 }
438
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800439 TaskWindowContainerController getWindowContainerController() {
440 return mWindowContainerController;
441 }
442
443 void createWindowContainer(boolean onTop, boolean showForAllUsers) {
444 if (mWindowContainerController != null) {
445 throw new IllegalArgumentException("Window container=" + mWindowContainerController
446 + " already created for task=" + this);
447 }
448
449 final Rect bounds = updateOverrideConfigurationFromLaunchBounds();
450 final Configuration overrideConfig = getOverrideConfiguration();
Bryce Lee04ab3462017-04-10 15:06:33 -0700451 setWindowContainerController(new TaskWindowContainerController(taskId, this,
Wale Ogunwale1666e312016-12-16 11:27:18 -0800452 getStack().getWindowContainerController(), userId, bounds, overrideConfig,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800453 mResizeMode, mSupportsPictureInPicture, isHomeTask(), onTop, showForAllUsers,
Bryce Lee04ab3462017-04-10 15:06:33 -0700454 lastTaskDescription));
455 }
456
457 /**
458 * Should only be invoked from {@link #createWindowContainer(boolean, boolean)}.
459 */
460 @VisibleForTesting
461 protected void setWindowContainerController(TaskWindowContainerController controller) {
462 if (mWindowContainerController != null) {
463 throw new IllegalArgumentException("Window container=" + mWindowContainerController
464 + " already created for task=" + this);
465 }
466
467 mWindowContainerController = controller;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800468 }
469
470 void removeWindowContainer() {
471 mService.mStackSupervisor.removeLockedTaskLocked(this);
472 mWindowContainerController.removeContainer();
473 if (!StackId.persistTaskBounds(getStackId())) {
474 // Reset current bounds for task whose bounds shouldn't be persisted so it uses
475 // default configuration the next time it launches.
476 updateOverrideConfiguration(null);
477 }
478 mService.mTaskChangeNotificationController.notifyTaskRemoved(taskId);
479 mWindowContainerController = null;
480 }
481
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100482 @Override
483 public void onSnapshotChanged(TaskSnapshot snapshot) {
484 mService.mTaskChangeNotificationController.notifyTaskSnapshotChanged(taskId, snapshot);
485 }
486
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800487 void setResizeMode(int resizeMode) {
488 if (mResizeMode == resizeMode) {
489 return;
490 }
491 mResizeMode = resizeMode;
492 mWindowContainerController.setResizeable(resizeMode);
493 mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
494 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
495 }
496
497 void setTaskDockedResizing(boolean resizing) {
498 mWindowContainerController.setTaskDockedResizing(resizing);
499 }
500
Wale Ogunwale1666e312016-12-16 11:27:18 -0800501 // TODO: Consolidate this with the resize() method below.
502 @Override
503 public void requestResize(Rect bounds, int resizeMode) {
504 mService.resizeTask(taskId, bounds, resizeMode);
505 }
506
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800507 boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
508 if (!isResizeable()) {
509 Slog.w(TAG, "resizeTask: task " + this + " not resizeable.");
510 return true;
511 }
512
513 // If this is a forced resize, let it go through even if the bounds is not changing,
514 // as we might need a relayout due to surface size change (to/from fullscreen).
515 final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
516 if (Objects.equals(mBounds, bounds) && !forced) {
517 // Nothing to do here...
518 return true;
519 }
520 bounds = validateBounds(bounds);
521
522 if (mWindowContainerController == null) {
523 // Task doesn't exist in window manager yet (e.g. was restored from recents).
524 // All we can do for now is update the bounds so it can be used when the task is
525 // added to window manager.
526 updateOverrideConfiguration(bounds);
527 if (getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
528 // re-restore the task so it can have the proper stack association.
529 mService.mStackSupervisor.restoreRecentTaskLocked(this,
530 FREEFORM_WORKSPACE_STACK_ID);
531 }
532 return true;
533 }
534
535 if (!canResizeToBounds(bounds)) {
536 throw new IllegalArgumentException("resizeTask: Can not resize task=" + this
537 + " to bounds=" + bounds + " resizeMode=" + mResizeMode);
538 }
539
540 // Do not move the task to another stack here.
541 // This method assumes that the task is already placed in the right stack.
542 // we do not mess with that decision and we only do the resize!
543
544 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId);
545
546 final boolean updatedConfig = updateOverrideConfiguration(bounds);
547 // This variable holds information whether the configuration didn't change in a significant
548 // way and the activity was kept the way it was. If it's false, it means the activity had
549 // to be relaunched due to configuration change.
550 boolean kept = true;
551 if (updatedConfig) {
552 final ActivityRecord r = topRunningActivityLocked();
553 if (r != null) {
554 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
555
556 if (!deferResume) {
557 // All other activities must be made visible with their correct configuration.
558 mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
559 if (!kept) {
560 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
561 }
562 }
563 }
564 }
565 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), kept, forced);
566
567 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
568 return kept;
569 }
570
571 // TODO: Investigate combining with the resize() method above.
572 void resizeWindowContainer() {
573 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), false /* relayout */,
574 false /* forced */);
575 }
576
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800577 void getWindowContainerBounds(Rect bounds) {
578 mWindowContainerController.getBounds(bounds);
579 }
580
Winson Chung74666102017-02-22 17:49:24 -0800581 /**
582 * Convenience method to reparent a task to the top or bottom position of the stack.
583 */
584 boolean reparent(int preferredStackId, boolean toTop, @ReparentMoveStackMode int moveStackMode,
585 boolean animate, boolean deferResume, String reason) {
586 return reparent(preferredStackId, toTop ? MAX_VALUE : 0, moveStackMode, animate,
Winson Chung5af42fc2017-03-24 17:11:33 -0700587 deferResume, true /* schedulePictureInPictureModeChange */, reason);
588 }
589
590 /**
591 * Convenience method to reparent a task to the top or bottom position of the stack, with
592 * an option to skip scheduling the picture-in-picture mode change.
593 */
594 boolean reparent(int preferredStackId, boolean toTop, @ReparentMoveStackMode int moveStackMode,
595 boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange,
596 String reason) {
597 return reparent(preferredStackId, toTop ? MAX_VALUE : 0, moveStackMode, animate,
598 deferResume, schedulePictureInPictureModeChange, reason);
599 }
600
601 /**
602 * Convenience method to reparent a task to a specific position of the stack.
603 */
604 boolean reparent(int preferredStackId, int position, @ReparentMoveStackMode int moveStackMode,
605 boolean animate, boolean deferResume, String reason) {
606 return reparent(preferredStackId, position, moveStackMode, animate, deferResume,
607 true /* schedulePictureInPictureModeChange */, reason);
Winson Chung74666102017-02-22 17:49:24 -0800608 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800609
Winson Chung74666102017-02-22 17:49:24 -0800610 /**
611 * Reparents the task into a preferred stack, creating it if necessary.
612 *
613 * @param preferredStackId the stack id of the target stack to move this task
614 * @param position the position to place this task in the new stack
615 * @param animate whether or not we should wait for the new window created as a part of the
Winson Chung5af42fc2017-03-24 17:11:33 -0700616 * reparenting to be drawn and animated in
Winson Chung74666102017-02-22 17:49:24 -0800617 * @param moveStackMode whether or not to move the stack to the front always, only if it was
Winson Chung5af42fc2017-03-24 17:11:33 -0700618 * previously focused & in front, or never
Winson Chung74666102017-02-22 17:49:24 -0800619 * @param deferResume whether or not to update the visibility of other tasks and stacks that may
Winson Chung5af42fc2017-03-24 17:11:33 -0700620 * have changed as a result of this reparenting
621 * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode
622 * change. Callers may set this to false if they are explicitly scheduling PiP mode
623 * changes themselves, like during the PiP animation
Winson Chung74666102017-02-22 17:49:24 -0800624 * @param reason the caller of this reparenting
Winson Chung5af42fc2017-03-24 17:11:33 -0700625 * @return whether the task was reparented
Winson Chung74666102017-02-22 17:49:24 -0800626 */
627 boolean reparent(int preferredStackId, int position, @ReparentMoveStackMode int moveStackMode,
Winson Chung5af42fc2017-03-24 17:11:33 -0700628 boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange,
629 String reason) {
Winson Chung74666102017-02-22 17:49:24 -0800630 final ActivityStackSupervisor supervisor = mService.mStackSupervisor;
631 final WindowManagerService windowManager = mService.mWindowManager;
632 final ActivityStack sourceStack = getStack();
633 final ActivityStack toStack = supervisor.getReparentTargetStack(this, preferredStackId,
634 position == MAX_VALUE);
635 if (toStack == sourceStack) {
636 return false;
637 }
638
639 final int sourceStackId = getStackId();
640 final int stackId = toStack.getStackId();
641 final ActivityRecord topActivity = getTopActivity();
642
643 final boolean mightReplaceWindow = StackId.replaceWindowsOnTaskMove(sourceStackId, stackId)
644 && topActivity != null;
645 if (mightReplaceWindow) {
646 // We are about to relaunch the activity because its configuration changed due to
647 // being maximized, i.e. size change. The activity will first remove the old window
648 // and then add a new one. This call will tell window manager about this, so it can
649 // preserve the old window until the new one is drawn. This prevents having a gap
650 // between the removal and addition, in which no window is visible. We also want the
651 // entrance of the new window to be properly animated.
652 // Note here we always set the replacing window first, as the flags might be needed
653 // during the relaunch. If we end up not doing any relaunch, we clear the flags later.
654 windowManager.setWillReplaceWindow(topActivity.appToken, animate);
655 }
656
657 windowManager.deferSurfaceLayout();
658 boolean kept = true;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800659 try {
Winson Chung74666102017-02-22 17:49:24 -0800660 final ActivityRecord r = topRunningActivityLocked();
Winson Chung95f8f0e2017-03-24 09:20:17 -0700661 final boolean wasFocused = r != null && supervisor.isFocusedStack(sourceStack)
Winson Chung74666102017-02-22 17:49:24 -0800662 && (topRunningActivityLocked() == r);
Winson Chung95f8f0e2017-03-24 09:20:17 -0700663 final boolean wasResumed = r != null && sourceStack.mResumedActivity == r;
664 final boolean wasPaused = r != null && sourceStack.mPausingActivity == r;
Winson Chung74666102017-02-22 17:49:24 -0800665
666 // In some cases the focused stack isn't the front stack. E.g. pinned stack.
667 // Whenever we are moving the top activity from the front stack we want to make sure to
668 // move the stack to the front.
Winson Chung95f8f0e2017-03-24 09:20:17 -0700669 final boolean wasFront = r != null && supervisor.isFrontStackOnDisplay(sourceStack)
Winson Chung74666102017-02-22 17:49:24 -0800670 && (sourceStack.topRunningActivityLocked() == r);
671
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800672 // Adjust the position for the new parent stack as needed.
Winson Chung74666102017-02-22 17:49:24 -0800673 position = toStack.getAdjustedPositionForTask(this, position, null /* starting */);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800674
675 // Must reparent first in window manager to avoid a situation where AM can delete the
676 // we are coming from in WM before we reparent because it became empty.
Wale Ogunwale2719cc12017-04-14 09:45:27 -0700677 mWindowContainerController.reparent(toStack.getWindowContainerController(), position,
678 moveStackMode == REPARENT_MOVE_STACK_TO_FRONT);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800679
Winson Chung74666102017-02-22 17:49:24 -0800680 // Move the task
681 sourceStack.removeTask(this, reason, REMOVE_TASK_MODE_MOVING);
Winson Chung5af42fc2017-03-24 17:11:33 -0700682 toStack.addTask(this, position, false /* schedulePictureInPictureModeChange */, reason);
Winson Chung74666102017-02-22 17:49:24 -0800683
Winson Chung5af42fc2017-03-24 17:11:33 -0700684 if (schedulePictureInPictureModeChange) {
685 // Notify of picture-in-picture mode changes
686 supervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, sourceStack);
687 }
Winson Chung74666102017-02-22 17:49:24 -0800688
689 // TODO: Ensure that this is actually necessary here
690 // Notify the voice session if required
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800691 if (voiceSession != null) {
692 try {
693 voiceSession.taskStarted(intent, taskId);
694 } catch (RemoteException e) {
695 }
696 }
Winson Chung74666102017-02-22 17:49:24 -0800697
698 // If the task had focus before (or we're requested to move focus), move focus to the
699 // new stack by moving the stack to the front.
700 final boolean moveStackToFront = moveStackMode == REPARENT_MOVE_STACK_TO_FRONT
701 || (moveStackMode == REPARENT_KEEP_STACK_AT_FRONT && (wasFocused || wasFront));
Winson Chung95f8f0e2017-03-24 09:20:17 -0700702 if (r != null) {
703 toStack.moveToFrontAndResumeStateIfNeeded(r, moveStackToFront, wasResumed,
704 wasPaused, reason);
705 }
Winson Chung74666102017-02-22 17:49:24 -0800706 if (!animate) {
707 toStack.mNoAnimActivities.add(topActivity);
708 }
709
710 // We might trigger a configuration change. Save the current task bounds for freezing.
711 // TODO: Should this call be moved inside the resize method in WM?
712 toStack.prepareFreezingTaskBounds();
713
714 // Make sure the task has the appropriate bounds/size for the stack it is in.
715 if (stackId == FULLSCREEN_WORKSPACE_STACK_ID
716 && !Objects.equals(mBounds, toStack.mBounds)) {
717 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
718 deferResume);
719 } else if (stackId == FREEFORM_WORKSPACE_STACK_ID) {
720 Rect bounds = getLaunchBounds();
721 if (bounds == null) {
722 toStack.layoutTaskInStack(this, null);
723 bounds = mBounds;
724 }
725 kept = resize(bounds, RESIZE_MODE_FORCED, !mightReplaceWindow, deferResume);
726 } else if (stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID) {
Matthew Ng330757d2017-02-28 14:19:17 -0800727 if (stackId == DOCKED_STACK_ID && moveStackMode == REPARENT_KEEP_STACK_AT_FRONT) {
728 // Move recents to front so it is not behind home stack when going into docked
729 // mode
730 mService.mStackSupervisor.moveRecentsStackToFront(reason);
731 }
Winson Chung74666102017-02-22 17:49:24 -0800732 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
733 deferResume);
734 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800735 } finally {
Winson Chung74666102017-02-22 17:49:24 -0800736 windowManager.continueSurfaceLayout();
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800737 }
Winson Chung74666102017-02-22 17:49:24 -0800738
739 if (mightReplaceWindow) {
740 // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old
741 // window), we need to clear the replace window settings. Otherwise, we schedule a
742 // timeout to remove the old window if the replacing window is not coming in time.
743 windowManager.scheduleClearWillReplaceWindows(topActivity.appToken, !kept);
744 }
745
746 if (!deferResume) {
747 // The task might have already been running and its visibility needs to be synchronized
748 // with the visibility of the stack / windows.
749 supervisor.ensureActivitiesVisibleLocked(null, 0, !mightReplaceWindow);
750 supervisor.resumeFocusedStackTopActivityLocked();
751 }
752
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700753 // TODO: Handle incorrect request to move before the actual move, not after.
754 supervisor.handleNonResizableTaskIfNeeded(this, preferredStackId, DEFAULT_DISPLAY, stackId);
Winson Chung74666102017-02-22 17:49:24 -0800755
Matthew Ng330757d2017-02-28 14:19:17 -0800756 boolean successful = (preferredStackId == stackId);
757 if (successful && stackId == DOCKED_STACK_ID) {
758 // If task moved to docked stack - show recents if needed.
759 mService.mWindowManager.showRecentApps(false /* fromHome */);
760 }
761 return successful;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800762 }
763
764 void cancelWindowTransition() {
765 mWindowContainerController.cancelWindowTransition();
766 }
767
768 void cancelThumbnailTransition() {
769 mWindowContainerController.cancelThumbnailTransition();
770 }
771
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100772 /**
773 * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
774 */
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100775 TaskSnapshot getSnapshot(boolean reducedResolution) {
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100776
777 // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
778 // synchronized between AM and WM.
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100779 return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800780 }
781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000783 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700784 if (firstActiveTime == 0) {
785 firstActiveTime = lastActiveTime;
786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000790 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700792
Winson Chungfee26772014-08-05 12:21:52 -0700793 /** Sets the original intent, and the calling uid and package. */
794 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700795 mCallingUid = r.launchedFromUid;
796 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700797 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700798 }
799
800 /** Sets the original intent, _without_ updating the calling uid or package. */
801 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700802 if (intent == null) {
803 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700804 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700805 } else if (mNeverRelinquishIdentity) {
806 return;
807 }
808
809 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700810 if (intent == null) {
811 // If this task already has an intent associated with it, don't set the root
812 // affinity -- we don't want it changing after initially set, but the initially
813 // set value may be null.
814 rootAffinity = affinity;
815 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700816 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700817 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800820 if (_intent != null) {
821 // If this Intent has a selector, we want to clear it for the
822 // recent task since it is not relevant if the user later wants
823 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700824 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800825 _intent = new Intent(_intent);
826 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700827 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800828 }
829 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700830 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 intent = _intent;
832 realActivity = _intent != null ? _intent.getComponent() : null;
833 origActivity = null;
834 } else {
835 ComponentName targetComponent = new ComponentName(
836 info.packageName, info.targetActivity);
837 if (_intent != null) {
838 Intent targetIntent = new Intent(_intent);
839 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800840 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700841 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700842 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700843 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 intent = targetIntent;
845 realActivity = targetComponent;
846 origActivity = _intent.getComponent();
847 } else {
848 intent = null;
849 realActivity = targetComponent;
850 origActivity = new ComponentName(info.packageName, info.name);
851 }
852 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700853
Craig Mautner47b20ba2014-09-17 17:23:44 -0700854 final int intentFlags = intent == null ? 0 : intent.getFlags();
855 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 // Once we are set to an Intent with this flag, we count this
857 // task as having a true root activity.
858 rootWasReset = true;
859 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700860 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000861 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
862 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700863 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700864 // If the activity itself has requested auto-remove, then just always do it.
865 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700866 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
867 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700868 // If the caller has not asked for the document to be retained, then we may
869 // want to turn on auto-remove, depending on whether the target has set its
870 // own document launch mode.
871 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
872 autoRemoveRecents = false;
873 } else {
874 autoRemoveRecents = true;
875 }
876 } else {
877 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700878 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800879 mResizeMode = info.resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800880 mSupportsPictureInPicture = info.supportsPictureInPicture();
Craig Mautner15df08a2015-04-01 12:17:18 -0700881 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700882 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700883 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800885
Andrii Kulian2e751b82016-03-16 16:59:32 -0700886 /** Sets the original minimal width and height. */
887 private void setMinDimensions(ActivityInfo info) {
888 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700889 mMinWidth = info.windowLayout.minWidth;
890 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700891 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700892 mMinWidth = INVALID_MIN_SIZE;
893 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700894 }
895 }
896
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800897 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700898 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800899 * record is based on (normally the root activity intent).
900 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700901 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800902 final Intent intent = new Intent(r.intent);
903 // Correct the activity intent for aliasing. The task record intent will always be based on
904 // the real activity that will be launched not the alias, so we need to use an intent with
905 // the component name pointing to the real activity not the alias in the activity record.
906 intent.setComponent(r.realActivity);
907 return this.intent.filterEquals(intent);
908 }
909
Craig Mautner84984fa2014-06-19 11:19:20 -0700910 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800911 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
912 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700913 }
914
Winson Chung83471632016-12-13 11:02:12 -0800915 void setTaskToReturnTo(ActivityRecord source) {
916 if (source.isRecentsActivity()) {
917 setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
918 } else if (source.isAssistantActivity()) {
919 setTaskToReturnTo(ASSISTANT_ACTIVITY_TYPE);
920 }
921 }
922
Craig Mautner84984fa2014-06-19 11:19:20 -0700923 int getTaskToReturnTo() {
924 return mTaskToReturnTo;
925 }
926
Craig Mautnera228ae92014-07-09 05:44:55 -0700927 void setPrevAffiliate(TaskRecord prevAffiliate) {
928 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800929 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700930 }
931
932 void setNextAffiliate(TaskRecord nextAffiliate) {
933 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800934 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700935 }
936
Andrii Kulian02b7a832016-10-06 23:11:56 -0700937 ActivityStack getStack() {
938 return mStack;
939 }
940
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800941 /**
942 * Must be used for setting parent stack because it performs configuration updates.
943 * Must be called after adding task as a child to the stack.
944 */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700945 void setStack(ActivityStack stack) {
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800946 if (stack != null && !stack.isInStackLocked(this)) {
947 throw new IllegalStateException("Task must be added as a Stack child first.");
948 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700949 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700950 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700951 }
952
953 /**
954 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
955 */
956 int getStackId() {
957 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
958 }
959
Andrii Kulian1779e612016-10-12 21:58:25 -0700960 @Override
961 protected int getChildCount() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700962 return mActivities.size();
Andrii Kulian1779e612016-10-12 21:58:25 -0700963 }
964
965 @Override
966 protected ConfigurationContainer getChildAt(int index) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700967 return mActivities.get(index);
Andrii Kulian1779e612016-10-12 21:58:25 -0700968 }
969
970 @Override
971 protected ConfigurationContainer getParent() {
972 return mStack;
973 }
974
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800975 @Override
976 void onParentChanged() {
977 super.onParentChanged();
978 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
979 }
980
Craig Mautnera228ae92014-07-09 05:44:55 -0700981 // Close up recents linked list.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700982 private void closeRecentsChain() {
Craig Mautnera228ae92014-07-09 05:44:55 -0700983 if (mPrevAffiliate != null) {
984 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
985 }
986 if (mNextAffiliate != null) {
987 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
988 }
989 setPrevAffiliate(null);
990 setNextAffiliate(null);
991 }
992
Winson Chung740c3ac2014-11-12 16:14:38 -0800993 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700994 disposeThumbnail();
995 closeRecentsChain();
996 if (inRecents) {
997 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800998 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700999 }
Jorim Jaggif9084ec2017-01-16 13:16:59 +01001000
1001 // TODO: Use window container controller once tasks are better synced between AM and WM
1002 mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001003 }
1004
Craig Mautnera228ae92014-07-09 05:44:55 -07001005 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
1006 closeRecentsChain();
1007 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -07001008 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -07001009 // Find the end
1010 while (taskToAffiliateWith.mNextAffiliate != null) {
1011 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
1012 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
1013 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
1014 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
1015 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
1016 nextRecents.setPrevAffiliate(null);
1017 }
1018 taskToAffiliateWith.setNextAffiliate(null);
1019 break;
1020 }
1021 taskToAffiliateWith = nextRecents;
1022 }
1023 taskToAffiliateWith.setNextAffiliate(this);
1024 setPrevAffiliate(taskToAffiliateWith);
1025 setNextAffiliate(null);
1026 }
1027
Winson Chung096f36b2014-08-20 15:39:01 -07001028 /**
Winsonc809cbb2015-11-02 12:06:15 -08001029 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -07001030 * @return whether the thumbnail was set
1031 */
Winsonc809cbb2015-11-02 12:06:15 -08001032 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -08001033 int taskWidth = 0;
1034 int taskHeight = 0;
1035 if (mBounds != null) {
1036 // Non-fullscreen tasks
1037 taskWidth = mBounds.width();
1038 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001039 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -08001040 // Fullscreen tasks
1041 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001042 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -08001043 taskWidth = displaySize.x;
1044 taskHeight = displaySize.y;
1045 } else {
1046 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
1047 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001048 // We need to provide the current orientation of the display on which this task resides,
1049 // not the orientation of the task.
1050 final int orientation =
1051 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
1052 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -08001053 }
1054
1055 /**
1056 * Sets the last thumbnail with the current task bounds.
1057 * @return whether the thumbnail was set
1058 */
1059 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
1060 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -07001061 if (mLastThumbnail != thumbnail) {
1062 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001063 mLastThumbnailInfo.taskWidth = taskWidth;
1064 mLastThumbnailInfo.taskHeight = taskHeight;
1065 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -07001066 if (thumbnail == null) {
1067 if (mLastThumbnailFile != null) {
1068 mLastThumbnailFile.delete();
1069 }
1070 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001071 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001072 }
Winson Chung096f36b2014-08-20 15:39:01 -07001073 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001074 }
Winson Chung096f36b2014-08-20 15:39:01 -07001075 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001076 }
1077
1078 void getLastThumbnail(TaskThumbnail thumbs) {
1079 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001080 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001081 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001082 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001083 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -08001084 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001085 }
Winson Chung096f36b2014-08-20 15:39:01 -07001086 // Only load the thumbnail file if we don't have a thumbnail
1087 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001088 try {
1089 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
1090 ParcelFileDescriptor.MODE_READ_ONLY);
1091 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -07001092 }
1093 }
1094 }
1095
Winsonc809cbb2015-11-02 12:06:15 -08001096 /**
1097 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
1098 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001099 void freeLastThumbnail() {
1100 mLastThumbnail = null;
1101 }
1102
Winsonc809cbb2015-11-02 12:06:15 -08001103 /**
1104 * Removes all associated thumbnail data when a task is removed or pruned from recents.
1105 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001106 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -08001107 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001108 mLastThumbnail = null;
1109 lastDescription = null;
1110 }
1111
Winson Chung1147c402014-05-14 11:05:00 -07001112 /** Returns the intent for the root activity for this task */
1113 Intent getBaseIntent() {
1114 return intent != null ? intent : affinityIntent;
1115 }
1116
Winson Chung3b3f4642014-04-22 10:08:18 -07001117 /** Returns the first non-finishing activity from the root. */
1118 ActivityRecord getRootActivity() {
1119 for (int i = 0; i < mActivities.size(); i++) {
1120 final ActivityRecord r = mActivities.get(i);
1121 if (r.finishing) {
1122 continue;
1123 }
1124 return r;
1125 }
1126 return null;
1127 }
1128
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001129 ActivityRecord getTopActivity() {
1130 for (int i = mActivities.size() - 1; i >= 0; --i) {
1131 final ActivityRecord r = mActivities.get(i);
1132 if (r.finishing) {
1133 continue;
1134 }
1135 return r;
1136 }
1137 return null;
1138 }
1139
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -07001140 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001141 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001142 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1143 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -07001144 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001145 return r;
1146 }
Craig Mautner6b74cb52013-09-27 17:02:21 -07001147 }
1148 }
1149 return null;
1150 }
1151
Wale Ogunwale3b232392016-05-13 15:37:13 -07001152 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001153 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001154 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1155 ActivityRecord r = mActivities.get(activityNdx);
1156 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -07001157 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001158 continue;
1159 }
1160 return r;
1161 }
1162 }
1163 return null;
1164 }
1165
Chong Zhang87761972016-08-22 13:53:24 -07001166 boolean okToShowLocked() {
1167 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
1168 // okay to show the activity when locked.
1169 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
1170 || topRunningActivityLocked() != null;
1171 }
1172
Craig Mautner3b475fe2013-12-16 15:58:31 -08001173 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Bryce Leed71317c2017-02-07 14:27:22 -08001174 final void setFrontOfTask() {
1175 boolean foundFront = false;
Craig Mautner3b475fe2013-12-16 15:58:31 -08001176 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -08001177 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -08001178 final ActivityRecord r = mActivities.get(activityNdx);
1179 if (foundFront || r.finishing) {
1180 r.frontOfTask = false;
1181 } else {
1182 r.frontOfTask = true;
1183 // Set frontOfTask false for every following activity.
1184 foundFront = true;
1185 }
1186 }
Craig Mautner9587ee02014-06-23 15:00:10 +00001187 if (!foundFront && numActivities > 0) {
1188 // All activities of this task are finishing. As we ought to have a frontOfTask
1189 // activity, make the bottom activity front.
1190 mActivities.get(0).frontOfTask = true;
1191 }
Craig Mautner3b475fe2013-12-16 15:58:31 -08001192 }
1193
Craig Mautnerde4ef022013-04-07 19:01:33 -07001194 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -08001195 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -07001196 */
1197 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001198 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
1199 "Removing and adding activity " + newTop
1200 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -07001201
Craig Mautnerde4ef022013-04-07 19:01:33 -07001202 mActivities.remove(newTop);
1203 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001204 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -08001205
Bryce Leed71317c2017-02-07 14:27:22 -08001206 setFrontOfTask();
Craig Mautnerde4ef022013-04-07 19:01:33 -07001207 }
1208
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001209 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -08001210 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001211 }
1212
1213 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001214 addActivityAtIndex(mActivities.size(), r);
1215 }
1216
Winson Chung30480042017-01-26 10:55:34 -08001217 /**
1218 * Adds an activity {@param r} at the given {@param index}. The activity {@param r} must either
1219 * be in the current task or unparented to any task.
1220 */
Craig Mautner1602ec22013-05-12 10:24:27 -07001221 void addActivityAtIndex(int index, ActivityRecord r) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001222 TaskRecord task = r.getTask();
1223 if (task != null && task != this) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001224 throw new IllegalArgumentException("Can not add r=" + " to task=" + this
Bryce Leeaf691c02017-03-20 14:20:22 -07001225 + " current parent=" + task);
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001226 }
Bryce Leeaf691c02017-03-20 14:20:22 -07001227
1228 r.setTask(this);
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001229
Craig Mautner6170f732013-04-02 13:05:23 -07001230 // Remove r first, and if it wasn't already in the list and it's fullscreen, count it.
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001231 if (!mActivities.remove(r) && r.fullscreen) {
1232 // Was not previously in list.
1233 numFullscreen++;
1234 }
Craig Mautner2c1faed2013-07-23 12:56:02 -07001235 // Only set this based on the first activity
1236 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001237 taskType = r.mActivityType;
1238 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001239 mCallingUid = r.launchedFromUid;
1240 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001241 // Clamp to [1, max].
1242 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
1243 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -07001244 } else {
1245 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -07001246 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -07001247 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001248
1249 final int size = mActivities.size();
1250
1251 if (index == size && size > 0) {
1252 final ActivityRecord top = mActivities.get(size - 1);
1253 if (top.mTaskOverlay) {
1254 // Place below the task overlay activity since the overlay activity should always
1255 // be on top.
1256 index--;
1257 }
1258 }
1259
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001260 index = Math.min(size, index);
Craig Mautner77878772013-03-04 19:46:24 -08001261 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001262 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001263 if (r.isPersistable()) {
1264 mService.notifyTaskPersisterLocked(this, false);
1265 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001266
1267 // Sync. with window manager
1268 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001269 final AppWindowContainerController appController = r.getWindowContainerController();
1270 if (appController != null) {
1271 // Only attempt to move in WM if the child has a controller. It is possible we haven't
1272 // created controller for the activity we are starting yet.
1273 mWindowContainerController.positionChildAt(appController, index);
1274 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001275 r.onOverrideConfigurationSent();
David Stevens82ea6cb2017-03-03 16:18:50 -08001276
1277 // Make sure the list of display UID whitelists is updated
1278 // now that this record is in a new task.
1279 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
Craig Mautner77878772013-03-04 19:46:24 -08001280 }
1281
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001282 /**
Bryce Leeaf691c02017-03-20 14:20:22 -07001283 * Removes the specified activity from this task.
1284 * @param r The {@link ActivityRecord} to remove.
1285 * @return true if this was the last activity in the task.
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001286 */
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001287 boolean removeActivity(ActivityRecord r) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001288 return removeActivity(r, false /*reparenting*/);
1289 }
1290
1291 boolean removeActivity(ActivityRecord r, boolean reparenting) {
1292 if (r.getTask() != this) {
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001293 throw new IllegalArgumentException(
1294 "Activity=" + r + " does not belong to task=" + this);
1295 }
1296
Bryce Leeaf691c02017-03-20 14:20:22 -07001297 r.setTask(null /*task*/, reparenting);
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001298
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001299 if (mActivities.remove(r) && r.fullscreen) {
1300 // Was previously in list.
1301 numFullscreen--;
1302 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001303 if (r.isPersistable()) {
1304 mService.notifyTaskPersisterLocked(this, false);
1305 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001306
Andrii Kulian02b7a832016-10-06 23:11:56 -07001307 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001308 // We normally notify listeners of task stack changes on pause, however pinned stack
1309 // activities are normally in the paused state so no notification will be sent there
1310 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001311 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001312 }
1313
Craig Mautner41326202014-06-20 14:38:21 -07001314 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001315 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001316 }
1317 updateEffectiveIntent();
1318 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001319 }
1320
Winson Chung6954fc92017-03-24 16:22:12 -07001321 /**
1322 * @return whether or not there are ONLY task overlay activities in the stack.
1323 * If {@param excludeFinishing} is set, then ignore finishing activities in the check.
1324 * If there are no task overlay activities, this call returns false.
1325 */
1326 boolean onlyHasTaskOverlayActivities(boolean excludeFinishing) {
1327 int count = 0;
1328 for (int i = mActivities.size() - 1; i >= 0; i--) {
1329 final ActivityRecord r = mActivities.get(i);
1330 if (excludeFinishing && r.finishing) {
1331 continue;
1332 }
1333 if (!r.mTaskOverlay) {
1334 return false;
1335 }
1336 count++;
1337 }
1338 return count > 0;
1339 }
1340
Craig Mautner41db4a72014-05-07 17:20:56 -07001341 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001342 // We will automatically remove the task either if it has explicitly asked for
1343 // this, or it is empty and has never contained an activity that got shown to
1344 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001345 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001346 }
1347
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001348 /**
1349 * Completely remove all activities associated with an existing
1350 * task starting at a specified index.
1351 */
Winson Chung6954fc92017-03-24 16:22:12 -07001352 final void performClearTaskAtIndexLocked(int activityNdx, boolean pauseImmediately) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001353 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001354 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001355 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001356 if (r.finishing) {
1357 continue;
1358 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001359 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001360 // Task was restored from persistent storage.
1361 r.takeFromHistory();
1362 mActivities.remove(activityNdx);
1363 --activityNdx;
1364 --numActivities;
Winson Chung6954fc92017-03-24 16:22:12 -07001365 } else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null,
1366 "clear-task-index", false, pauseImmediately)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001367 --activityNdx;
1368 --numActivities;
1369 }
1370 }
1371 }
1372
1373 /**
1374 * Completely remove all activities associated with an existing task.
1375 */
1376 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001377 mReuseTask = true;
Winson Chung6954fc92017-03-24 16:22:12 -07001378 performClearTaskAtIndexLocked(0, !PAUSE_IMMEDIATELY);
Craig Mautner362449a2014-06-20 14:04:39 -07001379 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001380 }
1381
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001382 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1383 mReuseTask = true;
1384 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1385 mReuseTask = false;
1386 return result;
1387 }
1388
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001389 /**
1390 * Perform clear operation as requested by
1391 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1392 * stack to the given task, then look for
1393 * an instance of that activity in the stack and, if found, finish all
1394 * activities on top of it and return the instance.
1395 *
1396 * @param newR Description of the new activity being started.
1397 * @return Returns the old activity that should be continued to be used,
1398 * or null if none was found.
1399 */
1400 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001401 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001402 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001403 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001404 if (r.finishing) {
1405 continue;
1406 }
1407 if (r.realActivity.equals(newR.realActivity)) {
1408 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001409 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001410
1411 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001412 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001413 if (r.finishing) {
1414 continue;
1415 }
1416 ActivityOptions opts = r.takeOptionsLocked();
1417 if (opts != null) {
1418 ret.updateOptionsLocked(opts);
1419 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001420 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001421 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001422 --activityNdx;
1423 --numActivities;
1424 }
1425 }
1426
1427 // Finally, if this is a normal launch mode (that is, not
1428 // expecting onNewIntent()), then we will finish the current
1429 // instance of the activity so a new fresh one can be started.
1430 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001431 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1432 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001433 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001434 if (mStack != null) {
1435 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001436 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1437 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001438 return null;
1439 }
1440 }
1441
1442 return ret;
1443 }
1444 }
1445
1446 return null;
1447 }
1448
Andrii Kulian21713ac2016-10-12 22:05:05 -07001449 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001450 if (mStack != null) {
1451 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Bryce Leeaf691c02017-03-20 14:20:22 -07001452 if (resumedActivity != null && resumedActivity.getTask() == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001453 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001454 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001455 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001456 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001457 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1458 getLastThumbnail(taskThumbnail);
1459 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001460 }
1461
Winson Chung6954fc92017-03-24 16:22:12 -07001462 void removeTaskActivitiesLocked(boolean pauseImmediately) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001463 // Just remove the entire task.
Winson Chung6954fc92017-03-24 16:22:12 -07001464 performClearTaskAtIndexLocked(0, pauseImmediately);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001465 }
1466
Craig Mautner432f64e2015-05-20 14:59:57 -07001467 String lockTaskAuthToString() {
1468 switch (mLockTaskAuth) {
1469 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1470 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1471 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1472 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001473 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001474 default: return "unknown=" + mLockTaskAuth;
1475 }
1476 }
1477
Craig Mautner15df08a2015-04-01 12:17:18 -07001478 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001479 if (!mPrivileged &&
1480 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1481 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1482 // Non-priv apps are not allowed to use always or never, fall back to default
1483 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1484 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001485 switch (mLockTaskMode) {
1486 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1487 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1488 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1489 break;
1490
1491 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001492 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001493 break;
1494
1495 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001496 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001497 break;
1498
1499 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1500 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1501 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1502 break;
1503 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001504 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1505 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001506 }
1507
1508 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001509 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1510 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001511 return false;
1512 }
1513 String[] packages = mService.mLockTaskPackages.get(userId);
1514 if (packages == null) {
1515 return false;
1516 }
1517 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001518 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001519 return true;
1520 }
1521 }
1522 return false;
1523 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001524
Craig Mautnera82aa092013-09-13 15:34:08 -07001525 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001526 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001527 }
1528
Wale Ogunwale74e26592016-02-05 11:48:37 -08001529 boolean isRecentsTask() {
1530 return taskType == RECENTS_ACTIVITY_TYPE;
1531 }
1532
Winson Chung83471632016-12-13 11:02:12 -08001533 boolean isAssistantTask() {
1534 return taskType == ASSISTANT_ACTIVITY_TYPE;
1535 }
1536
Craig Mautner86d67a42013-05-14 10:34:38 -07001537 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001538 return taskType == APPLICATION_ACTIVITY_TYPE;
1539 }
1540
1541 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001542 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001543 }
1544
Winson Chung83471632016-12-13 11:02:12 -08001545 boolean isOverAssistantStack() {
1546 return mTaskToReturnTo == ASSISTANT_ACTIVITY_TYPE;
1547 }
1548
Winson Chungd3395382016-12-13 11:49:09 -08001549 private boolean isResizeable(boolean checkSupportsPip) {
1550 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode)
1551 || (checkSupportsPip && mSupportsPictureInPicture)) && !mTemporarilyUnresizable;
1552 }
1553
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001554 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001555 return isResizeable(true /* checkSupportsPip */);
1556 }
1557
1558 boolean supportsSplitScreen() {
1559 // A task can not be docked even if it is considered resizeable because it only supports
1560 // picture-in-picture mode but has a non-resizeable resizeMode
1561 return mService.mSupportsSplitScreenMultiWindow
1562 && isResizeable(false /* checkSupportsPip */)
1563 && !ActivityInfo.isPreserveOrientationMode(mResizeMode);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001564 }
1565
skuhne@google.com322347b2016-12-02 12:54:03 -08001566 /**
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001567 * Check whether this task can be launched on the specified display.
1568 * @param displayId Target display id.
1569 * @return {@code true} if either it is the default display or this activity is resizeable and
1570 * can be put a secondary screen.
1571 */
1572 boolean canBeLaunchedOnDisplay(int displayId) {
1573 return mService.mStackSupervisor.canPlaceEntityOnDisplay(displayId,
1574 isResizeable(false /* checkSupportsPip */));
1575 }
1576
1577 /**
skuhne@google.com322347b2016-12-02 12:54:03 -08001578 * Check that a given bounds matches the application requested orientation.
1579 *
1580 * @param bounds The bounds to be tested.
1581 * @return True if the requested bounds are okay for a resizing request.
1582 */
Wale Ogunwale069bbd32017-02-03 07:58:14 -08001583 private boolean canResizeToBounds(Rect bounds) {
skuhne@google.com322347b2016-12-02 12:54:03 -08001584 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1585 // Note: If not on the freeform workspace, we ignore the bounds.
1586 return true;
1587 }
1588 final boolean landscape = bounds.width() > bounds.height();
1589 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1590 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1591 }
1592 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1593 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1594 }
1595
Craig Mautner525f3d92013-05-07 14:01:50 -07001596 /**
1597 * Find the activity in the history stack within the given task. Returns
1598 * the index within the history at which it's found, or < 0 if not found.
1599 */
1600 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1601 final ComponentName realActivity = r.realActivity;
1602 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1603 ActivityRecord candidate = mActivities.get(activityNdx);
1604 if (candidate.finishing) {
1605 continue;
1606 }
1607 if (candidate.realActivity.equals(realActivity)) {
1608 return candidate;
1609 }
1610 }
1611 return null;
1612 }
1613
Winson Chunga449dc02014-05-16 11:15:04 -07001614 /** Updates the last task description values. */
1615 void updateTaskDescription() {
1616 // Traverse upwards looking for any break between main task activities and
1617 // utility activities.
1618 int activityNdx;
1619 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001620 final boolean relinquish = numActivities != 0 &&
1621 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001622 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001623 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001624 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001625 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001626 // This will be the top activity for determining taskDescription. Pre-inc to
1627 // overcome initial decrement below.
1628 ++activityNdx;
1629 break;
1630 }
Winson Chunga449dc02014-05-16 11:15:04 -07001631 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001632 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001633 break;
1634 }
1635 }
1636 if (activityNdx > 0) {
1637 // Traverse downwards starting below break looking for set label, icon.
1638 // Note that if there are activities in the task but none of them set the
1639 // recent activity values, then we do not fall back to the last set
1640 // values in the TaskRecord.
1641 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001642 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001643 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001644 int colorBackground = 0;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001645 int statusBarColor = 0;
1646 int navigationBarColor = 0;
1647 boolean topActivity = true;
Winson Chunga449dc02014-05-16 11:15:04 -07001648 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1649 final ActivityRecord r = mActivities.get(activityNdx);
1650 if (r.taskDescription != null) {
1651 if (label == null) {
1652 label = r.taskDescription.getLabel();
1653 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001654 if (iconFilename == null) {
1655 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001656 }
1657 if (colorPrimary == 0) {
1658 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001659 }
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001660 if (topActivity) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001661 colorBackground = r.taskDescription.getBackgroundColor();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001662 statusBarColor = r.taskDescription.getStatusBarColor();
1663 navigationBarColor = r.taskDescription.getNavigationBarColor();
Winson Chung1af8eda2016-02-05 17:55:56 +00001664 }
Winson Chunga449dc02014-05-16 11:15:04 -07001665 }
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001666 topActivity = false;
Winson Chunga449dc02014-05-16 11:15:04 -07001667 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001668 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001669 colorBackground, statusBarColor, navigationBarColor);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +01001670 if (mWindowContainerController != null) {
1671 mWindowContainerController.setTaskDescription(lastTaskDescription);
1672 }
Winson Chungec396d62014-08-06 17:08:00 -07001673 // Update the task affiliation color if we are the parent of the group
1674 if (taskId == mAffiliatedTaskId) {
1675 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1676 }
Winson Chunga449dc02014-05-16 11:15:04 -07001677 }
1678 }
1679
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001680 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001681 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001682 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001683 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001684 final ActivityRecord r = mActivities.get(activityNdx);
1685 if (r.finishing) {
1686 continue;
1687 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001688 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001689 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001690 break;
1691 }
1692 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001693 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001694 }
1695
1696 void updateEffectiveIntent() {
1697 final int effectiveRootIndex = findEffectiveRootIndex();
1698 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001699 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001700 }
1701
Craig Mautner21d24a22014-04-23 11:45:37 -07001702 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001703 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001704
1705 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1706 if (realActivity != null) {
1707 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1708 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001709 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001710 if (origActivity != null) {
1711 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1712 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001713 // Write affinity, and root affinity if it is different from affinity.
1714 // We use the special string "@" for a null root affinity, so we can identify
1715 // later whether we were given a root affinity or should just make it the
1716 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001717 if (affinity != null) {
1718 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001719 if (!affinity.equals(rootAffinity)) {
1720 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1721 }
1722 } else if (rootAffinity != null) {
1723 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001724 }
1725 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001726 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001727 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1728 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001729 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001730 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001731 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001732 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001733 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001734 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001735 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001736 if (lastDescription != null) {
1737 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1738 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001739 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001740 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001741 }
Winson Chung36f3f032016-09-08 23:29:43 +00001742 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001743 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001744 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1745 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1746 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001747 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1748 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001749 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08001750 out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE,
1751 String.valueOf(mSupportsPictureInPicture));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001752 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001753 if (mLastNonFullscreenBounds != null) {
1754 out.attribute(
1755 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001756 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001757 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1758 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001759 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001760
Craig Mautner21d24a22014-04-23 11:45:37 -07001761 if (affinityIntent != null) {
1762 out.startTag(null, TAG_AFFINITYINTENT);
1763 affinityIntent.saveToXml(out);
1764 out.endTag(null, TAG_AFFINITYINTENT);
1765 }
1766
Winson Chung36f3f032016-09-08 23:29:43 +00001767 out.startTag(null, TAG_INTENT);
1768 intent.saveToXml(out);
1769 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001770
1771 final ArrayList<ActivityRecord> activities = mActivities;
1772 final int numActivities = activities.size();
1773 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1774 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001775 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001776 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1777 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001778 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001779 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001780 break;
1781 }
1782 out.startTag(null, TAG_ACTIVITY);
1783 r.saveToXml(out);
1784 out.endTag(null, TAG_ACTIVITY);
1785 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001786 }
1787
Winson Chung36f3f032016-09-08 23:29:43 +00001788 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1789 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001790 Intent intent = null;
1791 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001792 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001793 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001794 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001795 ComponentName origActivity = null;
1796 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001797 String rootAffinity = null;
1798 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001799 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001800 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001801 boolean askedCompatMode = false;
1802 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001803 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001804 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001805 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001806 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001807 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001808 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001809 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001810 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001811 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001812 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001813 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001814 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001815 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001816 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001817 int prevTaskId = INVALID_TASK_ID;
1818 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001819 int callingUid = -1;
1820 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001821 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -08001822 boolean supportsPictureInPicture = false;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001823 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001824 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001825 int minWidth = INVALID_MIN_SIZE;
1826 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001827 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001828
1829 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1830 final String attrName = in.getAttributeName(attrNdx);
1831 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001832 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1833 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001834 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001835 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001836 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1837 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001838 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1839 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001840 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1841 origActivity = ComponentName.unflattenFromString(attrValue);
1842 } else if (ATTR_AFFINITY.equals(attrName)) {
1843 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001844 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1845 rootAffinity = attrValue;
1846 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001847 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001848 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001849 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001850 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001851 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001852 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001853 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001854 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001855 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001856 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001857 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001858 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001859 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001860 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001861 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001862 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001863 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001864 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001865 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1866 lastDescription = attrValue;
1867 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001868 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001869 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001870 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001871 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1872 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001873 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1874 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001875 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001876 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001877 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001878 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001879 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001880 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001881 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001882 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001883 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001884 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001885 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1886 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001887 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001888 resizeMode = Integer.parseInt(attrValue);
Winson Chungd3395382016-12-13 11:49:09 -08001889 } else if (ATTR_SUPPORTS_PICTURE_IN_PICTURE.equals(attrName)) {
1890 supportsPictureInPicture = Boolean.parseBoolean(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001891 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001892 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001893 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001894 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001895 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1896 minWidth = Integer.parseInt(attrValue);
1897 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1898 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001899 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1900 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001901 } else {
1902 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1903 }
1904 }
1905
1906 int event;
1907 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001908 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001909 if (event == XmlPullParser.START_TAG) {
1910 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001911 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1912 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001913 if (TAG_AFFINITYINTENT.equals(name)) {
1914 affinityIntent = Intent.restoreFromXml(in);
1915 } else if (TAG_INTENT.equals(name)) {
1916 intent = Intent.restoreFromXml(in);
1917 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001918 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001919 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1920 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001921 if (activity != null) {
1922 activities.add(activity);
1923 }
1924 } else {
1925 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1926 XmlUtils.skipCurrentTag(in);
1927 }
1928 }
1929 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001930 if (!hasRootAffinity) {
1931 rootAffinity = affinity;
1932 } else if ("@".equals(rootAffinity)) {
1933 rootAffinity = null;
1934 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001935 if (effectiveUid <= 0) {
1936 Intent checkIntent = intent != null ? intent : affinityIntent;
1937 effectiveUid = 0;
1938 if (checkIntent != null) {
1939 IPackageManager pm = AppGlobals.getPackageManager();
1940 try {
1941 ApplicationInfo ai = pm.getApplicationInfo(
1942 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001943 PackageManager.MATCH_UNINSTALLED_PACKAGES
1944 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001945 if (ai != null) {
1946 effectiveUid = ai.uid;
1947 }
1948 } catch (RemoteException e) {
1949 }
1950 }
1951 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1952 + ": effectiveUid=" + effectiveUid);
1953 }
1954
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001955 if (persistTaskVersion < 1) {
1956 // We need to convert the resize mode of home activities saved before version one if
1957 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1958 // since we didn't have that differentiation before version 1 and the system didn't
1959 // resize home activities before then.
1960 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1961 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1962 }
Winson Chungd3395382016-12-13 11:49:09 -08001963 } else {
1964 // This activity has previously marked itself explicitly as both resizeable and
1965 // supporting picture-in-picture. Since there is no longer a requirement for
1966 // picture-in-picture activities to be resizeable, we can mark this simply as
1967 // resizeable and supporting picture-in-picture separately.
1968 if (resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED) {
1969 resizeMode = RESIZE_MODE_RESIZEABLE;
1970 supportsPictureInPicture = true;
1971 }
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001972 }
1973
Winson Chung36f3f032016-09-08 23:29:43 +00001974 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001975 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001976 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1977 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001978 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Winson Chungd3395382016-12-13 11:49:09 -08001979 taskAffiliationColor, callingUid, callingPackage, resizeMode,
1980 supportsPictureInPicture, privileged, realActivitySuspended, userSetupComplete,
1981 minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001982 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001983
1984 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001985 activities.get(activityNdx).setTask(task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001986 }
1987
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001988 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001989 return task;
1990 }
1991
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001992 private void adjustForMinimalTaskDimensions(Rect bounds) {
1993 if (bounds == null) {
1994 return;
1995 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001996 int minWidth = mMinWidth;
1997 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001998 // If the task has no requested minimal size, we'd like to enforce a minimal size
1999 // so that the user can not render the task too small to manipulate. We don't need
2000 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07002001 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002002 if (minWidth == INVALID_MIN_SIZE) {
2003 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07002004 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002005 if (minHeight == INVALID_MIN_SIZE) {
2006 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07002007 }
Robert Carr9c5867d2016-03-10 15:52:46 -08002008 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002009 final boolean adjustWidth = minWidth > bounds.width();
2010 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002011 if (!(adjustWidth || adjustHeight)) {
2012 return;
2013 }
2014
2015 if (adjustWidth) {
2016 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002017 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002018 } else {
2019 // Either left bounds match, or neither match, or the previous bounds were
2020 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002021 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002022 }
2023 }
2024 if (adjustHeight) {
2025 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002026 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002027 } else {
2028 // Either top bounds match, or neither match, or the previous bounds were
2029 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002030 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002031 }
2032 }
2033 }
2034
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002035 /**
Winson Chung5af42fc2017-03-24 17:11:33 -07002036 * @return a new Configuration for this Task, given the provided {@param bounds} and
2037 * {@param insetBounds}.
2038 */
2039 Configuration computeNewOverrideConfigurationForBounds(Rect bounds, Rect insetBounds) {
2040 // Compute a new override configuration for the given bounds, if fullscreen bounds
2041 // (bounds == null), then leave the override config unset
2042 final Configuration newOverrideConfig = new Configuration();
2043 if (bounds != null) {
2044 newOverrideConfig.setTo(getOverrideConfiguration());
2045 mTmpRect.set(bounds);
2046 adjustForMinimalTaskDimensions(mTmpRect);
2047 computeOverrideConfiguration(newOverrideConfig, mTmpRect, insetBounds,
2048 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
2049 }
2050
2051 return newOverrideConfig;
2052 }
2053
2054 /**
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002055 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002056 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07002057 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002058 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002059 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08002060 return updateOverrideConfiguration(bounds, null /* insetBounds */);
2061 }
2062
2063 /**
2064 * Update task's override configuration based on the bounds.
2065 * @param bounds The bounds of the task.
2066 * @param insetBounds The bounds used to calculate the system insets, which is used here to
2067 * subtract the navigation bar/status bar size from the screen size reported
2068 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07002069 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002070 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002071 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002072 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07002073 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002074 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002075 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08002076 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07002077 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002078
2079 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002080 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002081 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002082 mLastNonFullscreenBounds = mBounds;
2083 }
2084 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07002085 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07002086 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002087 mTmpRect.set(bounds);
2088 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002089 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002090 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002091 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002092 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002093 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002094 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07002095 mLastNonFullscreenBounds = mBounds;
2096 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002097 computeOverrideConfiguration(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07002098 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07002099 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002100 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002101
2102 if (mFullscreen != oldFullscreen) {
Winson Chung5af42fc2017-03-24 17:11:33 -07002103 mService.mStackSupervisor.scheduleUpdateMultiWindowMode(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002104 }
2105
Andrii Kulian1779e612016-10-12 21:58:25 -07002106 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002107 }
2108
Andrii Kulian1779e612016-10-12 21:58:25 -07002109 /** Clears passed config and fills it with new override values. */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002110 // TODO(b/36505427): TaskRecord.computeOverrideConfiguration() is a utility method that doesn't
2111 // depend on task or stacks, but uses those object to get the display to base the calculation
2112 // on. Probably best to centralize calculations like this in ConfigurationContainer.
2113 void computeOverrideConfiguration(Configuration config, Rect bounds, Rect insetBounds,
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002114 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002115 mTmpNonDecorBounds.set(bounds);
2116 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002117
Andrii Kulian1779e612016-10-12 21:58:25 -07002118 config.unset();
Winson Chungbdc646f2017-02-13 12:12:22 -08002119 final Configuration parentConfig = getParent().getConfiguration();
Bryce Lee7566d762017-03-30 09:34:15 -07002120
Andrii Kulian1779e612016-10-12 21:58:25 -07002121 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002122
Winson Chungbdc646f2017-02-13 12:12:22 -08002123 if (mStack != null) {
2124 final StackWindowController stackController = mStack.getWindowContainerController();
2125 stackController.adjustConfigurationForBounds(bounds, insetBounds,
2126 mTmpNonDecorBounds, mTmpStableBounds, overrideWidth, overrideHeight, density,
2127 config, parentConfig);
2128 } else {
Bryce Lee7566d762017-03-30 09:34:15 -07002129 throw new IllegalArgumentException("Expected stack when calculating override config");
Winson Chungbdc646f2017-02-13 12:12:22 -08002130 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002131
Winson Chung60c1aba2017-03-14 17:47:42 -07002132 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
2133 ? Configuration.ORIENTATION_PORTRAIT
2134 : Configuration.ORIENTATION_LANDSCAPE;
2135
Jorim Jaggi85639432016-05-06 17:27:55 -07002136 // For calculating screen layout, we need to use the non-decor inset screen area for the
2137 // calculation for compatibility reasons, i.e. screen area without system bars that could
2138 // never go away in Honeycomb.
Winson Chungbdc646f2017-02-13 12:12:22 -08002139 final int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density);
2140 final int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07002141 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
2142 // calculation with partial default.
2143 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002144 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07002145 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07002146 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
2147
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08002148 }
2149
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002150 Rect updateOverrideConfigurationFromLaunchBounds() {
2151 final Rect bounds = validateBounds(getLaunchBounds());
2152 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07002153 if (bounds != null) {
2154 bounds.set(mBounds);
2155 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002156 return bounds;
2157 }
2158
2159 static Rect validateBounds(Rect bounds) {
2160 if (bounds != null && bounds.isEmpty()) {
2161 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
2162 return null;
2163 }
2164 return bounds;
2165 }
2166
Wale Ogunwale935e5022015-11-10 12:36:10 -08002167 /** Updates the task's bounds and override configuration to match what is expected for the
2168 * input stack. */
2169 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002170 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002171 return;
2172 }
2173
2174 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002175 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002176 throw new IllegalArgumentException("Can not position non-resizeable task="
2177 + this + " in stack=" + inStack);
2178 }
2179 if (mBounds != null) {
2180 return;
2181 }
2182 if (mLastNonFullscreenBounds != null) {
2183 updateOverrideConfiguration(mLastNonFullscreenBounds);
2184 } else {
2185 inStack.layoutTaskInStack(this, null);
2186 }
2187 } else {
2188 updateOverrideConfiguration(inStack.mBounds);
2189 }
2190 }
2191
Chong Zhang0fa656b2015-08-31 15:17:21 -07002192 /**
2193 * Returns the correct stack to use based on task type and currently set bounds,
2194 * regardless of the focused stack and current stack association of the task.
2195 * The task will be moved (and stack focus changed) later if necessary.
2196 */
2197 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002198 if (isRecentsTask()) {
2199 return RECENTS_STACK_ID;
2200 }
2201 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002202 return HOME_STACK_ID;
2203 }
Winson Chung83471632016-12-13 11:02:12 -08002204 if (isAssistantTask()) {
2205 return ASSISTANT_STACK_ID;
2206 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07002207 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002208 return FREEFORM_WORKSPACE_STACK_ID;
2209 }
2210 return FULLSCREEN_WORKSPACE_STACK_ID;
2211 }
2212
2213 /** Returns the bounds that should be used to launch this task. */
2214 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08002215 // If we're over lockscreen, forget about stack bounds and use fullscreen.
Jorim Jaggife762342016-10-13 14:33:27 +02002216 if (mService.mStackSupervisor.mKeyguardController.isKeyguardShowing()) {
Chong Zhang75b37202015-12-04 14:16:36 -08002217 return null;
2218 }
2219
Andrii Kulian02b7a832016-10-06 23:11:56 -07002220 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08002221 return null;
2222 }
2223
Andrii Kulian02b7a832016-10-06 23:11:56 -07002224 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08002225 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002226 || stackId == RECENTS_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -08002227 || stackId == ASSISTANT_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08002228 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002229 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002230 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07002231 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002232 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002233 }
2234 return mLastNonFullscreenBounds;
2235 }
2236
Wale Ogunwale39381972015-12-17 17:15:29 -08002237 boolean canMatchRootAffinity() {
2238 // We don't allow root affinity matching on the pinned stack as no other task should
2239 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07002240 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08002241 }
2242
Jorim Jaggi8b702ed2017-01-20 16:59:03 +01002243 void addStartingWindowsForVisibleActivities(boolean taskSwitch) {
2244 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
2245 final ActivityRecord r = mActivities.get(activityNdx);
2246 if (r.visible) {
2247 r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch);
2248 }
2249 }
2250 }
2251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002253 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07002254 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
2255 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08002256 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002257 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07002258 if (affinity != null || rootAffinity != null) {
2259 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
2260 if (affinity == null || !affinity.equals(rootAffinity)) {
2261 pw.print(" root="); pw.println(rootAffinity);
2262 } else {
2263 pw.println();
2264 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002265 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07002266 if (voiceSession != null || voiceInteractor != null) {
2267 pw.print(prefix); pw.print("VOICE: session=0x");
2268 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
2269 pw.print(" interactor=0x");
2270 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
2271 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002272 if (intent != null) {
2273 StringBuilder sb = new StringBuilder(128);
2274 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002275 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002276 sb.append('}');
2277 pw.println(sb.toString());
2278 }
2279 if (affinityIntent != null) {
2280 StringBuilder sb = new StringBuilder(128);
2281 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002282 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002283 sb.append('}');
2284 pw.println(sb.toString());
2285 }
2286 if (origActivity != null) {
2287 pw.print(prefix); pw.print("origActivity=");
2288 pw.println(origActivity.flattenToShortString());
2289 }
2290 if (realActivity != null) {
2291 pw.print(prefix); pw.print("realActivity=");
2292 pw.println(realActivity.flattenToShortString());
2293 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07002294 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
2295 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002296 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002297 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002298 pw.print(" numFullscreen="); pw.print(numFullscreen);
2299 pw.print(" taskType="); pw.print(taskType);
2300 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
2301 }
Craig Mautner432f64e2015-05-20 14:59:57 -07002302 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
2303 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002304 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
2305 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07002306 pw.print(" mReuseTask="); pw.print(mReuseTask);
2307 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002308 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08002309 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
2310 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
2311 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07002312 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
2313 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
2314 pw.print(" (");
2315 if (mPrevAffiliate == null) {
2316 pw.print("null");
2317 } else {
2318 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
2319 }
2320 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
2321 pw.print(" (");
2322 if (mNextAffiliate == null) {
2323 pw.print("null");
2324 } else {
2325 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2326 }
2327 pw.println(")");
2328 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002329 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002330 if (!askedCompatMode || !inRecents || !isAvailable) {
2331 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2332 pw.print(" inRecents="); pw.print(inRecents);
2333 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002334 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002335 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002336 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2337 if (lastDescription != null) {
2338 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2339 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002340 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002341 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2342 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08002343 pw.print(" mSupportsPictureInPicture=" + mSupportsPictureInPicture);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002344 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00002345 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002346 pw.print(" lastActiveTime=" + lastActiveTime);
2347 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 }
2349
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002350 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002351 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002352 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002353 if (stringName != null) {
2354 sb.append(stringName);
2355 sb.append(" U=");
2356 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002357 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002358 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002359 sb.append(" sz=");
2360 sb.append(mActivities.size());
2361 sb.append('}');
2362 return sb.toString();
2363 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002364 sb.append("TaskRecord{");
2365 sb.append(Integer.toHexString(System.identityHashCode(this)));
2366 sb.append(" #");
2367 sb.append(taskId);
2368 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002369 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002370 sb.append(affinity);
2371 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002372 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002373 sb.append(intent.getComponent().flattenToShortString());
2374 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002375 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002376 sb.append(affinityIntent.getComponent().flattenToShortString());
2377 } else {
2378 sb.append(" ??");
2379 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002380 stringName = sb.toString();
2381 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 }
2383}