blob: e237e41a3d52be2e5d5e7894549a7a3d3ead0d1e [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
Jorim Jaggi0a932142016-02-01 17:42:25 -080019import android.annotation.Nullable;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070020import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070021import android.app.ActivityManager;
Wale Ogunwale3797c222015-10-27 14:21:58 -070022import android.app.ActivityManager.StackId;
Craig Mautner648f69b2014-09-18 14:16:26 -070023import android.app.ActivityManager.TaskDescription;
Jorim Jaggie2c77f92016-12-29 14:57:22 +010024import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwaleff3c66c2015-11-18 19:22:49 -080025import android.app.ActivityManager.TaskThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -080026import android.app.ActivityManager.TaskThumbnailInfo;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070027import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070028import android.app.AppGlobals;
Jorim Jaggi0a932142016-02-01 17:42:25 -080029import android.app.IActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.ComponentName;
31import android.content.Intent;
32import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070033import android.content.pm.ApplicationInfo;
34import android.content.pm.IPackageManager;
35import android.content.pm.PackageManager;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070036import android.content.res.Configuration;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070037import android.graphics.Bitmap;
Jorim Jaggi02886a82016-12-06 09:10:06 -080038import android.graphics.GraphicBuffer;
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
Dianne Hackborn91097de2014-04-04 18:02:06 -070051import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070052import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080053
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -080054import com.android.server.wm.AppWindowContainerController;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080055import com.android.server.wm.TaskWindowContainerController;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010056import com.android.server.wm.TaskWindowContainerListener;
57
Craig Mautner21d24a22014-04-23 11:45:37 -070058import org.xmlpull.v1.XmlPullParser;
59import org.xmlpull.v1.XmlPullParserException;
60import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Craig Mautnerc0ffce52014-07-01 12:38:52 -070062import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070063import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080065import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070066import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080068import static android.app.ActivityManager.RESIZE_MODE_FORCED;
Jorim Jaggi0a932142016-02-01 17:42:25 -080069import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
70import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
71import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
72import static android.app.ActivityManager.StackId.HOME_STACK_ID;
73import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
74import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080075import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080076import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
77import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070078import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
Jorim Jaggi0a932142016-02-01 17:42:25 -080079import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
80import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
81import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
82import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
skuhne@google.com322347b2016-12-02 12:54:03 -080083import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
84import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
85import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Wale Ogunwaled829d362016-02-10 19:24:49 -080086import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070087import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -080088import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070089import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggi0a932142016-02-01 17:42:25 -080090import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080091import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Suprabh Shukla7745c142016-03-07 18:21:10 -080092import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080093import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
94import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
95import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
96import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
97import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
98import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
99import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
100import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
101import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
102import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800103import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
104import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
105import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700106import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800107import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
108import static com.android.server.am.ActivityStackSupervisor.CREATE_IF_NEEDED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800109import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800110
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100111final class TaskRecord extends ConfigurationContainer implements TaskWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800112 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700113 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700114 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -0700115 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700116 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800117
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700118 private static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700119 private static final String TAG_INTENT = "intent";
120 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700121 private static final String ATTR_REALACTIVITY = "real_activity";
122 private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700123 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700124 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700125 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700126 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700127 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700128 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700129 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
130 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800131 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700132 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700133 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700134 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700135 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700136 private static final String ATTR_LASTDESCRIPTION = "last_description";
137 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700138 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700139 private static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700140 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
141 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700142 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700143 private static final String ATTR_CALLING_UID = "calling_uid";
144 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Winson Chungd3395382016-12-13 11:49:09 -0800145 private static final String ATTR_SUPPORTS_PICTURE_IN_PICTURE = "supports_picture_in_picture";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800146 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700147 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700148 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700149 private static final String ATTR_MIN_WIDTH = "min_width";
150 private static final String ATTR_MIN_HEIGHT = "min_height";
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700151 private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
Andrii Kulian18d75122016-03-27 20:20:28 -0700152
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700153 // Current version of the task record we persist. Used to check if we need to run any upgrade
154 // code.
155 private static final int PERSIST_TASK_VERSION = 1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700156 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
157
Wale Ogunwale18795a22014-12-03 11:38:33 -0800158 static final int INVALID_TASK_ID = -1;
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700159 private static final int INVALID_MIN_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700162 String affinity; // The affinity name for this task, or null; may change identity.
163 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700164 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
165 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 Intent intent; // The original intent that started the task.
167 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700168 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 ComponentName origActivity; // The non-alias activity component of the intent.
170 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000171 boolean realActivitySuspended; // True if the actual activity component that started the
172 // task is suspended.
Winson Chung36f3f032016-09-08 23:29:43 +0000173 long firstActiveTime; // First time this task was active.
174 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700175 boolean inRecents; // Actually in the recents list?
176 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 boolean rootWasReset; // True if the intent at the root of the task had
178 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700179 boolean autoRemoveRecents; // If true, we should automatically remove the task from
180 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700181 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700182 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 -0800183
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700184 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700185 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800186 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
187 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800188
189 int numFullscreen; // Number of fullscreen activities.
190
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800191 int mResizeMode; // The resize mode of this task and its activities.
192 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800193 private boolean mSupportsPictureInPicture; // Whether or not this task and its activities
194 // support PiP. Based on the {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE} flag
195 // of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800196 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
197 // changes on a temporary basis.
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700198 private int mLockTaskMode; // Which tasklock mode to launch this task in. One of
199 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700200 private boolean mPrivileged; // The root activity application of this task holds
201 // privileged permissions.
202
Craig Mautner15df08a2015-04-01 12:17:18 -0700203 /** Can't be put in lockTask mode. */
204 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100205 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700206 final static int LOCK_TASK_AUTH_PINNABLE = 1;
207 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
208 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100209 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700210 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100211 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
212 * lockTask task. */
213 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700214 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
215
216 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800217
Winson Chung03a9bae2014-05-02 09:56:12 -0700218 // This represents the last resolved activity values for this task
219 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700220 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700221
Craig Mautnerd2328952013-03-05 12:46:26 -0800222 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700223 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800224
Andrii Kulian02b7a832016-10-06 23:11:56 -0700225 /** Current stack. Setter must always be used to update the value. */
226 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800227
Craig Mautner2c1faed2013-07-23 12:56:02 -0700228 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700229 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700230
Craig Mautner21d24a22014-04-23 11:45:37 -0700231 /** Takes on same value as first root activity */
232 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700233 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700234
235 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
236 * determining the order when restoring. Sign indicates whether last task movement was to front
237 * (positive) or back (negative). Absolute value indicates time. */
238 long mLastTimeMoved = System.currentTimeMillis();
239
Craig Mautner84984fa2014-06-19 11:19:20 -0700240 /** Indication of what to run next when task exits. Use ActivityRecord types.
241 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
242 * task stack. */
243 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700244
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700245 /** If original intent did not allow relinquishing task identity, save that information */
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700246 private boolean mNeverRelinquishIdentity = true;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700247
Craig Mautner362449a2014-06-20 14:04:39 -0700248 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
249 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800250 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700251
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700252 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700253 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700254 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800255 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700256 CharSequence lastDescription; // Last description captured for this item.
257
Craig Mautnera228ae92014-07-09 05:44:55 -0700258 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700259 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700260 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800261 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700262 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800263 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700264
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700265 // For relaunching the task from recents as though it was launched by the original launcher.
266 int mCallingUid;
267 String mCallingPackage;
268
Craig Mautner21d24a22014-04-23 11:45:37 -0700269 final ActivityManagerService mService;
270
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700271 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
272 boolean mFullscreen = true;
273
274 // Bounds of the Task. null for fullscreen tasks.
275 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800276 private final Rect mTmpStableBounds = new Rect();
277 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800278 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800279 private final Rect mTmpRect2 = new Rect();
280
Wale Ogunwale706ed792015-08-02 10:29:44 -0700281 // Last non-fullscreen bounds the task was launched in or resized to.
282 // The information is persisted and used to determine the appropriate stack to launch the
283 // task into on restore.
284 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700285 // Minimal width and height of this task when it's resizeable. -1 means it should use the
286 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700287 int mMinWidth;
288 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700289
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700290 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
291 // This number will be assigned when we evaluate OOM scores for all visible tasks.
292 int mLayerRank = -1;
293
Andrii Kulian1779e612016-10-12 21:58:25 -0700294 /** Helper object used for updating override configuration. */
295 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700296
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800297 private TaskWindowContainerController mWindowContainerController;
298
Craig Mautner21d24a22014-04-23 11:45:37 -0700299 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Wale Ogunwale72919d22016-12-08 18:58:50 -0800300 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, int type) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700301 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700302 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
303 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800304 userId = UserHandle.getUserId(info.applicationInfo.uid);
305 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800306 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700308 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700309 voiceSession = _voiceSession;
310 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700311 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800312 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700313 mCallingUid = info.applicationInfo.uid;
314 mCallingPackage = info.packageName;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800315 taskType = type;
Martijn Coenend4a69702014-06-30 11:12:17 -0700316 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700317 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700318 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700319 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Craig Mautner21d24a22014-04-23 11:45:37 -0700320 }
321
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700322 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800323 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700324 mService = service;
325 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
326 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800327 userId = UserHandle.getUserId(info.applicationInfo.uid);
328 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800329 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700330 taskId = _taskId;
331 mAffiliatedTaskId = _taskId;
332 voiceSession = null;
333 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700334 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800335 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700336 mCallingUid = info.applicationInfo.uid;
337 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700338 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700339 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700340
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700341 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700342 // Clamp to [1, max].
343 maxRecents = Math.min(Math.max(info.maxRecents, 1),
344 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700345
346 taskType = APPLICATION_ACTIVITY_TYPE;
347 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700348 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700349 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700350 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700351 }
352
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800353 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
354 Intent _affinityIntent, String _affinity, String _rootAffinity,
355 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
356 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
357 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
358 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
359 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800360 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
361 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Winson Chungd3395382016-12-13 11:49:09 -0800362 int resizeMode, boolean supportsPictureInPicture, boolean privileged,
363 boolean _realActivitySuspended, boolean userSetupComplete, int minWidth,
364 int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700365 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700366 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
367 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800368 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800369 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700370 taskId = _taskId;
371 intent = _intent;
372 affinityIntent = _affinityIntent;
373 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800374 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700375 voiceSession = null;
376 voiceInteractor = null;
377 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800378 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700379 origActivity = _origActivity;
380 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700381 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700382 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700383 askedCompatMode = _askedCompatMode;
384 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700385 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700386 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800387 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700388 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700389 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700390 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700391 lastDescription = _lastDescription;
392 mActivities = activities;
393 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700394 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700395 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700396 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700397 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700398 mPrevAffiliateTaskId = prevTaskId;
399 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700400 mCallingUid = callingUid;
401 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800402 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800403 mSupportsPictureInPicture = supportsPictureInPicture;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700404 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700405 mMinWidth = minWidth;
406 mMinHeight = minHeight;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700407 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 }
409
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800410 TaskWindowContainerController getWindowContainerController() {
411 return mWindowContainerController;
412 }
413
414 void createWindowContainer(boolean onTop, boolean showForAllUsers) {
415 if (mWindowContainerController != null) {
416 throw new IllegalArgumentException("Window container=" + mWindowContainerController
417 + " already created for task=" + this);
418 }
419
420 final Rect bounds = updateOverrideConfigurationFromLaunchBounds();
421 final Configuration overrideConfig = getOverrideConfiguration();
Wale Ogunwale1666e312016-12-16 11:27:18 -0800422 mWindowContainerController = new TaskWindowContainerController(taskId, this,
423 getStack().getWindowContainerController(), userId, bounds, overrideConfig,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800424 mResizeMode, mSupportsPictureInPicture, isHomeTask(), onTop, showForAllUsers,
425 lastTaskDescription);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800426 }
427
428 void removeWindowContainer() {
429 mService.mStackSupervisor.removeLockedTaskLocked(this);
430 mWindowContainerController.removeContainer();
431 if (!StackId.persistTaskBounds(getStackId())) {
432 // Reset current bounds for task whose bounds shouldn't be persisted so it uses
433 // default configuration the next time it launches.
434 updateOverrideConfiguration(null);
435 }
436 mService.mTaskChangeNotificationController.notifyTaskRemoved(taskId);
437 mWindowContainerController = null;
438 }
439
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100440 @Override
441 public void onSnapshotChanged(TaskSnapshot snapshot) {
442 mService.mTaskChangeNotificationController.notifyTaskSnapshotChanged(taskId, snapshot);
443 }
444
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800445 void setResizeMode(int resizeMode) {
446 if (mResizeMode == resizeMode) {
447 return;
448 }
449 mResizeMode = resizeMode;
450 mWindowContainerController.setResizeable(resizeMode);
451 mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
452 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
453 }
454
455 void setTaskDockedResizing(boolean resizing) {
456 mWindowContainerController.setTaskDockedResizing(resizing);
457 }
458
Wale Ogunwale1666e312016-12-16 11:27:18 -0800459 // TODO: Consolidate this with the resize() method below.
460 @Override
461 public void requestResize(Rect bounds, int resizeMode) {
462 mService.resizeTask(taskId, bounds, resizeMode);
463 }
464
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800465 boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
466 if (!isResizeable()) {
467 Slog.w(TAG, "resizeTask: task " + this + " not resizeable.");
468 return true;
469 }
470
471 // If this is a forced resize, let it go through even if the bounds is not changing,
472 // as we might need a relayout due to surface size change (to/from fullscreen).
473 final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
474 if (Objects.equals(mBounds, bounds) && !forced) {
475 // Nothing to do here...
476 return true;
477 }
478 bounds = validateBounds(bounds);
479
480 if (mWindowContainerController == null) {
481 // Task doesn't exist in window manager yet (e.g. was restored from recents).
482 // All we can do for now is update the bounds so it can be used when the task is
483 // added to window manager.
484 updateOverrideConfiguration(bounds);
485 if (getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
486 // re-restore the task so it can have the proper stack association.
487 mService.mStackSupervisor.restoreRecentTaskLocked(this,
488 FREEFORM_WORKSPACE_STACK_ID);
489 }
490 return true;
491 }
492
493 if (!canResizeToBounds(bounds)) {
494 throw new IllegalArgumentException("resizeTask: Can not resize task=" + this
495 + " to bounds=" + bounds + " resizeMode=" + mResizeMode);
496 }
497
498 // Do not move the task to another stack here.
499 // This method assumes that the task is already placed in the right stack.
500 // we do not mess with that decision and we only do the resize!
501
502 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId);
503
504 final boolean updatedConfig = updateOverrideConfiguration(bounds);
505 // This variable holds information whether the configuration didn't change in a significant
506 // way and the activity was kept the way it was. If it's false, it means the activity had
507 // to be relaunched due to configuration change.
508 boolean kept = true;
509 if (updatedConfig) {
510 final ActivityRecord r = topRunningActivityLocked();
511 if (r != null) {
512 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
513
514 if (!deferResume) {
515 // All other activities must be made visible with their correct configuration.
516 mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
517 if (!kept) {
518 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
519 }
520 }
521 }
522 }
523 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), kept, forced);
524
525 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
526 return kept;
527 }
528
529 // TODO: Investigate combining with the resize() method above.
530 void resizeWindowContainer() {
531 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), false /* relayout */,
532 false /* forced */);
533 }
534
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800535 void getWindowContainerBounds(Rect bounds) {
536 mWindowContainerController.getBounds(bounds);
537 }
538
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800539 // TODO: Should we be doing all the stuff in ASS.moveTaskToStackLocked?
540 void reparent(int stackId, int position, String reason) {
541 mService.mWindowManager.deferSurfaceLayout();
542
543 try {
544 final ActivityStackSupervisor supervisor = mService.mStackSupervisor;
545 final ActivityStack newStack = supervisor.getStack(stackId,
546 CREATE_IF_NEEDED, false /* toTop */);
547 // Adjust the position for the new parent stack as needed.
548 position = newStack.getAdjustedPositionForTask(this, position, null /* starting */);
549
550 // Must reparent first in window manager to avoid a situation where AM can delete the
551 // we are coming from in WM before we reparent because it became empty.
Wale Ogunwale1666e312016-12-16 11:27:18 -0800552 mWindowContainerController.reparent(newStack.getWindowContainerController(), position);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800553
554 final ActivityStack prevStack = mStack;
555 prevStack.removeTask(this, reason, REMOVE_TASK_MODE_MOVING);
556 newStack.addTask(this, position, reason);
557
558 supervisor.scheduleReportPictureInPictureModeChangedIfNeeded(this, prevStack);
559
560 if (voiceSession != null) {
561 try {
562 voiceSession.taskStarted(intent, taskId);
563 } catch (RemoteException e) {
564 }
565 }
566 } finally {
567 mService.mWindowManager.continueSurfaceLayout();
568 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800569 }
570
571 void cancelWindowTransition() {
572 mWindowContainerController.cancelWindowTransition();
573 }
574
575 void cancelThumbnailTransition() {
576 mWindowContainerController.cancelThumbnailTransition();
577 }
578
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100579 /**
580 * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
581 */
582 TaskSnapshot getSnapshot() {
583
584 // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
585 // synchronized between AM and WM.
586 return mService.mWindowManager.getTaskSnapshot(taskId, userId);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800587 }
588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000590 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700591 if (firstActiveTime == 0) {
592 firstActiveTime = lastActiveTime;
593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000597 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700599
Winson Chungfee26772014-08-05 12:21:52 -0700600 /** Sets the original intent, and the calling uid and package. */
601 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700602 mCallingUid = r.launchedFromUid;
603 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700604 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700605 }
606
607 /** Sets the original intent, _without_ updating the calling uid or package. */
608 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700609 if (intent == null) {
610 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700611 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700612 } else if (mNeverRelinquishIdentity) {
613 return;
614 }
615
616 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700617 if (intent == null) {
618 // If this task already has an intent associated with it, don't set the root
619 // affinity -- we don't want it changing after initially set, but the initially
620 // set value may be null.
621 rootAffinity = affinity;
622 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700623 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700624 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800627 if (_intent != null) {
628 // If this Intent has a selector, we want to clear it for the
629 // recent task since it is not relevant if the user later wants
630 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700631 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800632 _intent = new Intent(_intent);
633 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700634 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800635 }
636 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700637 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 intent = _intent;
639 realActivity = _intent != null ? _intent.getComponent() : null;
640 origActivity = null;
641 } else {
642 ComponentName targetComponent = new ComponentName(
643 info.packageName, info.targetActivity);
644 if (_intent != null) {
645 Intent targetIntent = new Intent(_intent);
646 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800647 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700648 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700649 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700650 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 intent = targetIntent;
652 realActivity = targetComponent;
653 origActivity = _intent.getComponent();
654 } else {
655 intent = null;
656 realActivity = targetComponent;
657 origActivity = new ComponentName(info.packageName, info.name);
658 }
659 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700660
Craig Mautner47b20ba2014-09-17 17:23:44 -0700661 final int intentFlags = intent == null ? 0 : intent.getFlags();
662 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 // Once we are set to an Intent with this flag, we count this
664 // task as having a true root activity.
665 rootWasReset = true;
666 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700667 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000668 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
669 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700670 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700671 // If the activity itself has requested auto-remove, then just always do it.
672 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700673 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
674 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700675 // If the caller has not asked for the document to be retained, then we may
676 // want to turn on auto-remove, depending on whether the target has set its
677 // own document launch mode.
678 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
679 autoRemoveRecents = false;
680 } else {
681 autoRemoveRecents = true;
682 }
683 } else {
684 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700685 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800686 mResizeMode = info.resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800687 mSupportsPictureInPicture = info.supportsPictureInPicture();
Craig Mautner15df08a2015-04-01 12:17:18 -0700688 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700689 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700690 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800692
Andrii Kulian2e751b82016-03-16 16:59:32 -0700693 /** Sets the original minimal width and height. */
694 private void setMinDimensions(ActivityInfo info) {
695 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700696 mMinWidth = info.windowLayout.minWidth;
697 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700698 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700699 mMinWidth = INVALID_MIN_SIZE;
700 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700701 }
702 }
703
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800704 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700705 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800706 * record is based on (normally the root activity intent).
707 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700708 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800709 final Intent intent = new Intent(r.intent);
710 // Correct the activity intent for aliasing. The task record intent will always be based on
711 // the real activity that will be launched not the alias, so we need to use an intent with
712 // the component name pointing to the real activity not the alias in the activity record.
713 intent.setComponent(r.realActivity);
714 return this.intent.filterEquals(intent);
715 }
716
Craig Mautner84984fa2014-06-19 11:19:20 -0700717 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800718 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
719 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700720 }
721
722 int getTaskToReturnTo() {
723 return mTaskToReturnTo;
724 }
725
Craig Mautnera228ae92014-07-09 05:44:55 -0700726 void setPrevAffiliate(TaskRecord prevAffiliate) {
727 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800728 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700729 }
730
731 void setNextAffiliate(TaskRecord nextAffiliate) {
732 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800733 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700734 }
735
Andrii Kulian02b7a832016-10-06 23:11:56 -0700736 ActivityStack getStack() {
737 return mStack;
738 }
739
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800740 /**
741 * Must be used for setting parent stack because it performs configuration updates.
742 * Must be called after adding task as a child to the stack.
743 */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700744 void setStack(ActivityStack stack) {
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800745 if (stack != null && !stack.isInStackLocked(this)) {
746 throw new IllegalStateException("Task must be added as a Stack child first.");
747 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700748 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700749 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700750 }
751
752 /**
753 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
754 */
755 int getStackId() {
756 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
757 }
758
Andrii Kulian1779e612016-10-12 21:58:25 -0700759 @Override
760 protected int getChildCount() {
761 return 0;
762 }
763
764 @Override
765 protected ConfigurationContainer getChildAt(int index) {
766 return null;
767 }
768
769 @Override
770 protected ConfigurationContainer getParent() {
771 return mStack;
772 }
773
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800774 @Override
775 void onParentChanged() {
776 super.onParentChanged();
777 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
778 }
779
Craig Mautnera228ae92014-07-09 05:44:55 -0700780 // Close up recents linked list.
781 void closeRecentsChain() {
782 if (mPrevAffiliate != null) {
783 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
784 }
785 if (mNextAffiliate != null) {
786 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
787 }
788 setPrevAffiliate(null);
789 setNextAffiliate(null);
790 }
791
Winson Chung740c3ac2014-11-12 16:14:38 -0800792 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700793 disposeThumbnail();
794 closeRecentsChain();
795 if (inRecents) {
796 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800797 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700798 }
Jorim Jaggif9084ec2017-01-16 13:16:59 +0100799
800 // TODO: Use window container controller once tasks are better synced between AM and WM
801 mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700802 }
803
Craig Mautnera228ae92014-07-09 05:44:55 -0700804 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
805 closeRecentsChain();
806 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700807 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700808 // Find the end
809 while (taskToAffiliateWith.mNextAffiliate != null) {
810 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
811 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
812 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
813 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
814 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
815 nextRecents.setPrevAffiliate(null);
816 }
817 taskToAffiliateWith.setNextAffiliate(null);
818 break;
819 }
820 taskToAffiliateWith = nextRecents;
821 }
822 taskToAffiliateWith.setNextAffiliate(this);
823 setPrevAffiliate(taskToAffiliateWith);
824 setNextAffiliate(null);
825 }
826
Winson Chung096f36b2014-08-20 15:39:01 -0700827 /**
Winsonc809cbb2015-11-02 12:06:15 -0800828 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700829 * @return whether the thumbnail was set
830 */
Winsonc809cbb2015-11-02 12:06:15 -0800831 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -0800832 int taskWidth = 0;
833 int taskHeight = 0;
834 if (mBounds != null) {
835 // Non-fullscreen tasks
836 taskWidth = mBounds.width();
837 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700838 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -0800839 // Fullscreen tasks
840 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700841 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -0800842 taskWidth = displaySize.x;
843 taskHeight = displaySize.y;
844 } else {
845 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
846 }
Andrii Kulian1779e612016-10-12 21:58:25 -0700847 // We need to provide the current orientation of the display on which this task resides,
848 // not the orientation of the task.
849 final int orientation =
850 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
851 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -0800852 }
853
854 /**
855 * Sets the last thumbnail with the current task bounds.
856 * @return whether the thumbnail was set
857 */
858 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
859 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700860 if (mLastThumbnail != thumbnail) {
861 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800862 mLastThumbnailInfo.taskWidth = taskWidth;
863 mLastThumbnailInfo.taskHeight = taskHeight;
864 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700865 if (thumbnail == null) {
866 if (mLastThumbnailFile != null) {
867 mLastThumbnailFile.delete();
868 }
869 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800870 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700871 }
Winson Chung096f36b2014-08-20 15:39:01 -0700872 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700873 }
Winson Chung096f36b2014-08-20 15:39:01 -0700874 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700875 }
876
877 void getLastThumbnail(TaskThumbnail thumbs) {
878 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800879 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700880 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700881 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800882 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800883 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700884 }
Winson Chung096f36b2014-08-20 15:39:01 -0700885 // Only load the thumbnail file if we don't have a thumbnail
886 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700887 try {
888 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
889 ParcelFileDescriptor.MODE_READ_ONLY);
890 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700891 }
892 }
893 }
894
Winsonc809cbb2015-11-02 12:06:15 -0800895 /**
896 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
897 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700898 void freeLastThumbnail() {
899 mLastThumbnail = null;
900 }
901
Winsonc809cbb2015-11-02 12:06:15 -0800902 /**
903 * Removes all associated thumbnail data when a task is removed or pruned from recents.
904 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700905 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800906 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700907 mLastThumbnail = null;
908 lastDescription = null;
909 }
910
Winson Chung1147c402014-05-14 11:05:00 -0700911 /** Returns the intent for the root activity for this task */
912 Intent getBaseIntent() {
913 return intent != null ? intent : affinityIntent;
914 }
915
Winson Chung3b3f4642014-04-22 10:08:18 -0700916 /** Returns the first non-finishing activity from the root. */
917 ActivityRecord getRootActivity() {
918 for (int i = 0; i < mActivities.size(); i++) {
919 final ActivityRecord r = mActivities.get(i);
920 if (r.finishing) {
921 continue;
922 }
923 return r;
924 }
925 return null;
926 }
927
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800928 ActivityRecord getTopActivity() {
929 for (int i = mActivities.size() - 1; i >= 0; --i) {
930 final ActivityRecord r = mActivities.get(i);
931 if (r.finishing) {
932 continue;
933 }
934 return r;
935 }
936 return null;
937 }
938
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700939 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700940 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700941 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
942 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -0700943 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700944 return r;
945 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700946 }
947 }
948 return null;
949 }
950
Wale Ogunwale3b232392016-05-13 15:37:13 -0700951 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700952 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700953 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
954 ActivityRecord r = mActivities.get(activityNdx);
955 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -0700956 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700957 continue;
958 }
959 return r;
960 }
961 }
962 return null;
963 }
964
Chong Zhang87761972016-08-22 13:53:24 -0700965 boolean okToShowLocked() {
966 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
967 // okay to show the activity when locked.
968 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
969 || topRunningActivityLocked() != null;
970 }
971
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800972 void setFrontOfTask() {
973 setFrontOfTask(null);
974 }
975
Craig Mautner3b475fe2013-12-16 15:58:31 -0800976 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800977 void setFrontOfTask(ActivityRecord newTop) {
978 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
979 // as not front. This is needed in situations where the current front activity in the
980 // task isn't finished yet and we want to set the front to the activity moved to the front
981 // of the task.
982 boolean foundFront = newTop != null ? true : false;
983
Craig Mautner3b475fe2013-12-16 15:58:31 -0800984 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800985 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800986 final ActivityRecord r = mActivities.get(activityNdx);
987 if (foundFront || r.finishing) {
988 r.frontOfTask = false;
989 } else {
990 r.frontOfTask = true;
991 // Set frontOfTask false for every following activity.
992 foundFront = true;
993 }
994 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000995 if (!foundFront && numActivities > 0) {
996 // All activities of this task are finishing. As we ought to have a frontOfTask
997 // activity, make the bottom activity front.
998 mActivities.get(0).frontOfTask = true;
999 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -08001000 if (newTop != null) {
1001 newTop.frontOfTask = true;
1002 }
Craig Mautner3b475fe2013-12-16 15:58:31 -08001003 }
1004
Craig Mautnerde4ef022013-04-07 19:01:33 -07001005 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -08001006 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -07001007 */
1008 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001009 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
1010 "Removing and adding activity " + newTop
1011 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -07001012
Craig Mautnerde4ef022013-04-07 19:01:33 -07001013 mActivities.remove(newTop);
1014 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001015 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -08001016
Wale Ogunwale6d42df62015-11-05 09:50:55 -08001017 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001018 }
1019
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001020 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -08001021 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001022 }
1023
1024 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001025 addActivityAtIndex(mActivities.size(), r);
1026 }
1027
Winson Chung30480042017-01-26 10:55:34 -08001028 /**
1029 * Adds an activity {@param r} at the given {@param index}. The activity {@param r} must either
1030 * be in the current task or unparented to any task.
1031 */
Craig Mautner1602ec22013-05-12 10:24:27 -07001032 void addActivityAtIndex(int index, ActivityRecord r) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001033 if (r.task != null && r.task != this) {
1034 throw new IllegalArgumentException("Can not add r=" + " to task=" + this
1035 + " current parent=" + r.task);
1036 }
1037 r.task = this;
1038
Craig Mautner6170f732013-04-02 13:05:23 -07001039 // 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 -08001040 if (!mActivities.remove(r) && r.fullscreen) {
1041 // Was not previously in list.
1042 numFullscreen++;
1043 }
Craig Mautner2c1faed2013-07-23 12:56:02 -07001044 // Only set this based on the first activity
1045 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001046 taskType = r.mActivityType;
1047 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001048 mCallingUid = r.launchedFromUid;
1049 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001050 // Clamp to [1, max].
1051 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
1052 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -07001053 } else {
1054 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -07001055 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -07001056 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001057
1058 final int size = mActivities.size();
1059
1060 if (index == size && size > 0) {
1061 final ActivityRecord top = mActivities.get(size - 1);
1062 if (top.mTaskOverlay) {
1063 // Place below the task overlay activity since the overlay activity should always
1064 // be on top.
1065 index--;
1066 }
1067 }
1068
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001069 index = Math.min(size, index);
Craig Mautner77878772013-03-04 19:46:24 -08001070 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001071 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001072 if (r.isPersistable()) {
1073 mService.notifyTaskPersisterLocked(this, false);
1074 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001075
1076 // Sync. with window manager
1077 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001078 final AppWindowContainerController appController = r.getWindowContainerController();
1079 if (appController != null) {
1080 // Only attempt to move in WM if the child has a controller. It is possible we haven't
1081 // created controller for the activity we are starting yet.
1082 mWindowContainerController.positionChildAt(appController, index);
1083 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001084 r.onOverrideConfigurationSent();
Craig Mautner77878772013-03-04 19:46:24 -08001085 }
1086
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001087 /** @return true if this was the last activity in the task */
1088 boolean removeActivity(ActivityRecord r) {
1089 if (mActivities.remove(r) && r.fullscreen) {
1090 // Was previously in list.
1091 numFullscreen--;
1092 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001093 if (r.isPersistable()) {
1094 mService.notifyTaskPersisterLocked(this, false);
1095 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001096
Andrii Kulian02b7a832016-10-06 23:11:56 -07001097 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001098 // We normally notify listeners of task stack changes on pause, however pinned stack
1099 // activities are normally in the paused state so no notification will be sent there
1100 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001101 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001102 }
1103
Craig Mautner41326202014-06-20 14:38:21 -07001104 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001105 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001106 }
1107 updateEffectiveIntent();
1108 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001109 }
1110
Craig Mautner41db4a72014-05-07 17:20:56 -07001111 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001112 // We will automatically remove the task either if it has explicitly asked for
1113 // this, or it is empty and has never contained an activity that got shown to
1114 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001115 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001116 }
1117
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001118 /**
1119 * Completely remove all activities associated with an existing
1120 * task starting at a specified index.
1121 */
1122 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001123 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001124 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001125 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001126 if (r.finishing) {
1127 continue;
1128 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001129 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001130 // Task was restored from persistent storage.
1131 r.takeFromHistory();
1132 mActivities.remove(activityNdx);
1133 --activityNdx;
1134 --numActivities;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001135 } else if (mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001136 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001137 --activityNdx;
1138 --numActivities;
1139 }
1140 }
1141 }
1142
1143 /**
1144 * Completely remove all activities associated with an existing task.
1145 */
1146 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001147 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001148 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -07001149 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001150 }
1151
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001152 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1153 mReuseTask = true;
1154 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1155 mReuseTask = false;
1156 return result;
1157 }
1158
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001159 /**
1160 * Perform clear operation as requested by
1161 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1162 * stack to the given task, then look for
1163 * an instance of that activity in the stack and, if found, finish all
1164 * activities on top of it and return the instance.
1165 *
1166 * @param newR Description of the new activity being started.
1167 * @return Returns the old activity that should be continued to be used,
1168 * or null if none was found.
1169 */
1170 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001171 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001172 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001173 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001174 if (r.finishing) {
1175 continue;
1176 }
1177 if (r.realActivity.equals(newR.realActivity)) {
1178 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001179 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001180
1181 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001182 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001183 if (r.finishing) {
1184 continue;
1185 }
1186 ActivityOptions opts = r.takeOptionsLocked();
1187 if (opts != null) {
1188 ret.updateOptionsLocked(opts);
1189 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001190 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001191 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001192 --activityNdx;
1193 --numActivities;
1194 }
1195 }
1196
1197 // Finally, if this is a normal launch mode (that is, not
1198 // expecting onNewIntent()), then we will finish the current
1199 // instance of the activity so a new fresh one can be started.
1200 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001201 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1202 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001203 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001204 if (mStack != null) {
1205 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001206 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1207 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001208 return null;
1209 }
1210 }
1211
1212 return ret;
1213 }
1214 }
1215
1216 return null;
1217 }
1218
Andrii Kulian21713ac2016-10-12 22:05:05 -07001219 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001220 if (mStack != null) {
1221 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Craig Mautner21d24a22014-04-23 11:45:37 -07001222 if (resumedActivity != null && resumedActivity.task == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001223 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001224 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001225 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001226 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001227 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1228 getLastThumbnail(taskThumbnail);
1229 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001230 }
1231
Andrii Kulian21713ac2016-10-12 22:05:05 -07001232 void removeTaskActivitiesLocked() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001233 // Just remove the entire task.
1234 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001235 }
1236
Craig Mautner432f64e2015-05-20 14:59:57 -07001237 String lockTaskAuthToString() {
1238 switch (mLockTaskAuth) {
1239 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1240 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1241 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1242 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001243 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001244 default: return "unknown=" + mLockTaskAuth;
1245 }
1246 }
1247
Craig Mautner15df08a2015-04-01 12:17:18 -07001248 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001249 if (!mPrivileged &&
1250 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1251 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1252 // Non-priv apps are not allowed to use always or never, fall back to default
1253 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1254 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001255 switch (mLockTaskMode) {
1256 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1257 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1258 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1259 break;
1260
1261 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001262 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001263 break;
1264
1265 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001266 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001267 break;
1268
1269 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1270 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1271 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1272 break;
1273 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001274 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1275 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001276 }
1277
1278 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001279 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1280 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001281 return false;
1282 }
1283 String[] packages = mService.mLockTaskPackages.get(userId);
1284 if (packages == null) {
1285 return false;
1286 }
1287 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001288 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001289 return true;
1290 }
1291 }
1292 return false;
1293 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001294
Craig Mautnera82aa092013-09-13 15:34:08 -07001295 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001296 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001297 }
1298
Wale Ogunwale74e26592016-02-05 11:48:37 -08001299 boolean isRecentsTask() {
1300 return taskType == RECENTS_ACTIVITY_TYPE;
1301 }
1302
Craig Mautner86d67a42013-05-14 10:34:38 -07001303 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001304 return taskType == APPLICATION_ACTIVITY_TYPE;
1305 }
1306
1307 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001308 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001309 }
1310
Winson Chungd3395382016-12-13 11:49:09 -08001311 private boolean isResizeable(boolean checkSupportsPip) {
1312 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode)
1313 || (checkSupportsPip && mSupportsPictureInPicture)) && !mTemporarilyUnresizable;
1314 }
1315
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001316 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001317 return isResizeable(true /* checkSupportsPip */);
1318 }
1319
1320 boolean supportsSplitScreen() {
1321 // A task can not be docked even if it is considered resizeable because it only supports
1322 // picture-in-picture mode but has a non-resizeable resizeMode
1323 return mService.mSupportsSplitScreenMultiWindow
1324 && isResizeable(false /* checkSupportsPip */)
1325 && !ActivityInfo.isPreserveOrientationMode(mResizeMode);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001326 }
1327
skuhne@google.com322347b2016-12-02 12:54:03 -08001328 /**
1329 * Check that a given bounds matches the application requested orientation.
1330 *
1331 * @param bounds The bounds to be tested.
1332 * @return True if the requested bounds are okay for a resizing request.
1333 */
Wale Ogunwale069bbd32017-02-03 07:58:14 -08001334 private boolean canResizeToBounds(Rect bounds) {
skuhne@google.com322347b2016-12-02 12:54:03 -08001335 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1336 // Note: If not on the freeform workspace, we ignore the bounds.
1337 return true;
1338 }
1339 final boolean landscape = bounds.width() > bounds.height();
1340 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1341 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1342 }
1343 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1344 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1345 }
1346
Craig Mautner525f3d92013-05-07 14:01:50 -07001347 /**
1348 * Find the activity in the history stack within the given task. Returns
1349 * the index within the history at which it's found, or < 0 if not found.
1350 */
1351 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1352 final ComponentName realActivity = r.realActivity;
1353 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1354 ActivityRecord candidate = mActivities.get(activityNdx);
1355 if (candidate.finishing) {
1356 continue;
1357 }
1358 if (candidate.realActivity.equals(realActivity)) {
1359 return candidate;
1360 }
1361 }
1362 return null;
1363 }
1364
Winson Chunga449dc02014-05-16 11:15:04 -07001365 /** Updates the last task description values. */
1366 void updateTaskDescription() {
1367 // Traverse upwards looking for any break between main task activities and
1368 // utility activities.
1369 int activityNdx;
1370 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001371 final boolean relinquish = numActivities != 0 &&
1372 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001373 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001374 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001375 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001376 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001377 // This will be the top activity for determining taskDescription. Pre-inc to
1378 // overcome initial decrement below.
1379 ++activityNdx;
1380 break;
1381 }
Winson Chunga449dc02014-05-16 11:15:04 -07001382 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001383 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001384 break;
1385 }
1386 }
1387 if (activityNdx > 0) {
1388 // Traverse downwards starting below break looking for set label, icon.
1389 // Note that if there are activities in the task but none of them set the
1390 // recent activity values, then we do not fall back to the last set
1391 // values in the TaskRecord.
1392 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001393 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001394 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001395 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001396 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1397 final ActivityRecord r = mActivities.get(activityNdx);
1398 if (r.taskDescription != null) {
1399 if (label == null) {
1400 label = r.taskDescription.getLabel();
1401 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001402 if (iconFilename == null) {
1403 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001404 }
1405 if (colorPrimary == 0) {
1406 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001407 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001408 if (colorBackground == 0) {
1409 colorBackground = r.taskDescription.getBackgroundColor();
1410 }
Winson Chunga449dc02014-05-16 11:15:04 -07001411 }
1412 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001413 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1414 colorBackground);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +01001415 if (mWindowContainerController != null) {
1416 mWindowContainerController.setTaskDescription(lastTaskDescription);
1417 }
Winson Chungec396d62014-08-06 17:08:00 -07001418 // Update the task affiliation color if we are the parent of the group
1419 if (taskId == mAffiliatedTaskId) {
1420 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1421 }
Winson Chunga449dc02014-05-16 11:15:04 -07001422 }
1423 }
1424
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001425 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001426 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001427 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001428 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001429 final ActivityRecord r = mActivities.get(activityNdx);
1430 if (r.finishing) {
1431 continue;
1432 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001433 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001434 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001435 break;
1436 }
1437 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001438 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001439 }
1440
1441 void updateEffectiveIntent() {
1442 final int effectiveRootIndex = findEffectiveRootIndex();
1443 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001444 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001445 }
1446
Craig Mautner21d24a22014-04-23 11:45:37 -07001447 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001448 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001449
1450 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1451 if (realActivity != null) {
1452 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1453 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001454 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001455 if (origActivity != null) {
1456 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1457 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001458 // Write affinity, and root affinity if it is different from affinity.
1459 // We use the special string "@" for a null root affinity, so we can identify
1460 // later whether we were given a root affinity or should just make it the
1461 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001462 if (affinity != null) {
1463 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001464 if (!affinity.equals(rootAffinity)) {
1465 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1466 }
1467 } else if (rootAffinity != null) {
1468 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001469 }
1470 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001471 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001472 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1473 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001474 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001475 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001476 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001477 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001478 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001479 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001480 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001481 if (lastDescription != null) {
1482 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1483 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001484 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001485 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001486 }
Winson Chung36f3f032016-09-08 23:29:43 +00001487 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001488 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001489 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1490 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1491 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001492 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1493 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001494 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08001495 out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE,
1496 String.valueOf(mSupportsPictureInPicture));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001497 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001498 if (mLastNonFullscreenBounds != null) {
1499 out.attribute(
1500 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001501 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001502 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1503 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001504 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001505
Craig Mautner21d24a22014-04-23 11:45:37 -07001506 if (affinityIntent != null) {
1507 out.startTag(null, TAG_AFFINITYINTENT);
1508 affinityIntent.saveToXml(out);
1509 out.endTag(null, TAG_AFFINITYINTENT);
1510 }
1511
Winson Chung36f3f032016-09-08 23:29:43 +00001512 out.startTag(null, TAG_INTENT);
1513 intent.saveToXml(out);
1514 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001515
1516 final ArrayList<ActivityRecord> activities = mActivities;
1517 final int numActivities = activities.size();
1518 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1519 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001520 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001521 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1522 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001523 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001524 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001525 break;
1526 }
1527 out.startTag(null, TAG_ACTIVITY);
1528 r.saveToXml(out);
1529 out.endTag(null, TAG_ACTIVITY);
1530 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001531 }
1532
Winson Chung36f3f032016-09-08 23:29:43 +00001533 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1534 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001535 Intent intent = null;
1536 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001537 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001538 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001539 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001540 ComponentName origActivity = null;
1541 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001542 String rootAffinity = null;
1543 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001544 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001545 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001546 boolean askedCompatMode = false;
1547 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001548 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001549 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001550 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001551 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001552 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001553 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001554 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001555 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001556 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001557 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001558 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001559 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001560 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001561 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001562 int prevTaskId = INVALID_TASK_ID;
1563 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001564 int callingUid = -1;
1565 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001566 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -08001567 boolean supportsPictureInPicture = false;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001568 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001569 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001570 int minWidth = INVALID_MIN_SIZE;
1571 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001572 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001573
1574 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1575 final String attrName = in.getAttributeName(attrNdx);
1576 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001577 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1578 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001579 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001580 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001581 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1582 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001583 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1584 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001585 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1586 origActivity = ComponentName.unflattenFromString(attrValue);
1587 } else if (ATTR_AFFINITY.equals(attrName)) {
1588 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001589 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1590 rootAffinity = attrValue;
1591 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001592 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001593 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001594 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001595 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001596 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001597 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001598 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001599 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001600 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001601 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001602 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001603 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001604 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001605 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001606 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001607 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001608 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001609 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001610 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1611 lastDescription = attrValue;
1612 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001613 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001614 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001615 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001616 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1617 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001618 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1619 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001620 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001621 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001622 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001623 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001624 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001625 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001626 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001627 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001628 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001629 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001630 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1631 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001632 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001633 resizeMode = Integer.parseInt(attrValue);
Winson Chungd3395382016-12-13 11:49:09 -08001634 } else if (ATTR_SUPPORTS_PICTURE_IN_PICTURE.equals(attrName)) {
1635 supportsPictureInPicture = Boolean.parseBoolean(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001636 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001637 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001638 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001639 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001640 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1641 minWidth = Integer.parseInt(attrValue);
1642 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1643 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001644 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1645 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001646 } else {
1647 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1648 }
1649 }
1650
1651 int event;
1652 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001653 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001654 if (event == XmlPullParser.START_TAG) {
1655 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001656 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1657 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001658 if (TAG_AFFINITYINTENT.equals(name)) {
1659 affinityIntent = Intent.restoreFromXml(in);
1660 } else if (TAG_INTENT.equals(name)) {
1661 intent = Intent.restoreFromXml(in);
1662 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001663 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001664 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1665 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001666 if (activity != null) {
1667 activities.add(activity);
1668 }
1669 } else {
1670 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1671 XmlUtils.skipCurrentTag(in);
1672 }
1673 }
1674 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001675 if (!hasRootAffinity) {
1676 rootAffinity = affinity;
1677 } else if ("@".equals(rootAffinity)) {
1678 rootAffinity = null;
1679 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001680 if (effectiveUid <= 0) {
1681 Intent checkIntent = intent != null ? intent : affinityIntent;
1682 effectiveUid = 0;
1683 if (checkIntent != null) {
1684 IPackageManager pm = AppGlobals.getPackageManager();
1685 try {
1686 ApplicationInfo ai = pm.getApplicationInfo(
1687 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001688 PackageManager.MATCH_UNINSTALLED_PACKAGES
1689 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001690 if (ai != null) {
1691 effectiveUid = ai.uid;
1692 }
1693 } catch (RemoteException e) {
1694 }
1695 }
1696 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1697 + ": effectiveUid=" + effectiveUid);
1698 }
1699
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001700 if (persistTaskVersion < 1) {
1701 // We need to convert the resize mode of home activities saved before version one if
1702 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1703 // since we didn't have that differentiation before version 1 and the system didn't
1704 // resize home activities before then.
1705 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1706 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1707 }
Winson Chungd3395382016-12-13 11:49:09 -08001708 } else {
1709 // This activity has previously marked itself explicitly as both resizeable and
1710 // supporting picture-in-picture. Since there is no longer a requirement for
1711 // picture-in-picture activities to be resizeable, we can mark this simply as
1712 // resizeable and supporting picture-in-picture separately.
1713 if (resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED) {
1714 resizeMode = RESIZE_MODE_RESIZEABLE;
1715 supportsPictureInPicture = true;
1716 }
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001717 }
1718
Winson Chung36f3f032016-09-08 23:29:43 +00001719 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001720 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001721 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1722 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001723 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Winson Chungd3395382016-12-13 11:49:09 -08001724 taskAffiliationColor, callingUid, callingPackage, resizeMode,
1725 supportsPictureInPicture, privileged, realActivitySuspended, userSetupComplete,
1726 minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001727 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001728
1729 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001730 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001731 }
1732
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001733 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001734 return task;
1735 }
1736
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001737 private void adjustForMinimalTaskDimensions(Rect bounds) {
1738 if (bounds == null) {
1739 return;
1740 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001741 int minWidth = mMinWidth;
1742 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001743 // If the task has no requested minimal size, we'd like to enforce a minimal size
1744 // so that the user can not render the task too small to manipulate. We don't need
1745 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001746 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001747 if (minWidth == INVALID_MIN_SIZE) {
1748 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001749 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001750 if (minHeight == INVALID_MIN_SIZE) {
1751 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001752 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001753 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001754 final boolean adjustWidth = minWidth > bounds.width();
1755 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001756 if (!(adjustWidth || adjustHeight)) {
1757 return;
1758 }
1759
1760 if (adjustWidth) {
1761 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001762 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001763 } else {
1764 // Either left bounds match, or neither match, or the previous bounds were
1765 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001766 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001767 }
1768 }
1769 if (adjustHeight) {
1770 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001771 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001772 } else {
1773 // Either top bounds match, or neither match, or the previous bounds were
1774 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001775 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001776 }
1777 }
1778 }
1779
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001780 /**
1781 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001782 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07001783 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001784 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001785 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001786 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1787 }
1788
1789 /**
1790 * Update task's override configuration based on the bounds.
1791 * @param bounds The bounds of the task.
1792 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1793 * subtract the navigation bar/status bar size from the screen size reported
1794 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07001795 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001796 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001797 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001798 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07001799 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001800 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001801 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08001802 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07001803 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001804
1805 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001806 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001807 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001808 mLastNonFullscreenBounds = mBounds;
1809 }
1810 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07001811 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07001812 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001813 mTmpRect.set(bounds);
1814 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001815 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001816 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001817 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001818 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001819 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001820 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001821 mLastNonFullscreenBounds = mBounds;
1822 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001823 calculateOverrideConfig(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07001824 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001825 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001826 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001827
1828 if (mFullscreen != oldFullscreen) {
Andrii Kulian933076d2016-03-29 17:04:42 -07001829 mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001830 }
1831
Andrii Kulian1779e612016-10-12 21:58:25 -07001832 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001833 }
1834
Andrii Kuliandaea3572016-04-08 13:20:51 -07001835 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds,
1836 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001837 mTmpRect2.set(inInsetBounds);
1838 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1839 int leftInset = mTmpRect2.left - inInsetBounds.left;
1840 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001841 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1842 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001843 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1844 }
1845
Andrii Kuliandaea3572016-04-08 13:20:51 -07001846 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds,
1847 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001848 mTmpRect2.set(inInsetBounds);
1849 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1850 int leftInset = mTmpRect2.left - inInsetBounds.left;
1851 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001852 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1853 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi0a932142016-02-01 17:42:25 -08001854 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1855 }
1856
Andrii Kulian1779e612016-10-12 21:58:25 -07001857 /** Clears passed config and fills it with new override values. */
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07001858 private void calculateOverrideConfig(Configuration config, Rect bounds, Rect insetBounds,
1859 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001860 mTmpNonDecorBounds.set(bounds);
1861 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001862
Andrii Kulian1779e612016-10-12 21:58:25 -07001863 final Configuration parentConfig = getParent().getConfiguration();
1864 config.unset();
1865 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Yorke Leef54f9da2017-01-10 07:58:59 -08001866 final boolean isFloatingTask = mStack != null && StackId.tasksAreFloating(mStack.mStackId);
1867 if (isFloatingTask) {
1868 // Floating tasks should not be resized to the screen's bounds.
1869 config.screenWidthDp = (int) (mTmpStableBounds.width() / density);
1870 config.screenHeightDp = (int) (mTmpStableBounds.height() / density);
1871 } else {
1872 // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
1873 // i.e. the screen area without the system bars.
1874 // Additionally task dimensions should not be bigger than its parents dimensions.
1875 subtractNonDecorInsets(mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds,
1876 overrideWidth, overrideHeight);
1877 subtractStableInsets(mTmpStableBounds, insetBounds != null ? insetBounds : bounds,
1878 overrideWidth, overrideHeight);
1879 config.screenWidthDp = Math.min(
1880 (int) (mTmpStableBounds.width() / density), parentConfig.screenWidthDp);
1881 config.screenHeightDp = Math.min(
1882 (int) (mTmpStableBounds.height() / density), parentConfig.screenHeightDp);
1883 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001884
1885 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001886 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1887 ? Configuration.ORIENTATION_PORTRAIT
1888 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001889
Jorim Jaggi85639432016-05-06 17:27:55 -07001890 // For calculating screen layout, we need to use the non-decor inset screen area for the
1891 // calculation for compatibility reasons, i.e. screen area without system bars that could
1892 // never go away in Honeycomb.
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001893 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1894 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07001895 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
1896 // calculation with partial default.
1897 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001898 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07001899 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07001900 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
1901
1902 config.smallestScreenWidthDp = mService.mWindowManager.getSmallestWidthForTaskBounds(
1903 insetBounds != null ? insetBounds : bounds);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001904 }
1905
1906 /**
1907 * Using the existing configuration {@param config}, creates a new task override config such
1908 * that all the fields that are usually set in an override config are set to the ones in
1909 * {@param config}.
1910 */
1911 Configuration extractOverrideConfig(Configuration config) {
Andrii Kulian1779e612016-10-12 21:58:25 -07001912 final Configuration extracted = new Configuration();
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001913 extracted.screenWidthDp = config.screenWidthDp;
1914 extracted.screenHeightDp = config.screenHeightDp;
1915 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1916 extracted.orientation = config.orientation;
Andrii Kulian1779e612016-10-12 21:58:25 -07001917 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout.
1918 extracted.screenLayout = config.screenLayout & (Configuration.SCREENLAYOUT_LONG_MASK
1919 | Configuration.SCREENLAYOUT_SIZE_MASK | Configuration.SCREENLAYOUT_COMPAT_NEEDED);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001920 return extracted;
1921 }
1922
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001923 Rect updateOverrideConfigurationFromLaunchBounds() {
1924 final Rect bounds = validateBounds(getLaunchBounds());
1925 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07001926 if (bounds != null) {
1927 bounds.set(mBounds);
1928 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001929 return bounds;
1930 }
1931
1932 static Rect validateBounds(Rect bounds) {
1933 if (bounds != null && bounds.isEmpty()) {
1934 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1935 return null;
1936 }
1937 return bounds;
1938 }
1939
Wale Ogunwale935e5022015-11-10 12:36:10 -08001940 /** Updates the task's bounds and override configuration to match what is expected for the
1941 * input stack. */
1942 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001943 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001944 return;
1945 }
1946
1947 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001948 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001949 throw new IllegalArgumentException("Can not position non-resizeable task="
1950 + this + " in stack=" + inStack);
1951 }
1952 if (mBounds != null) {
1953 return;
1954 }
1955 if (mLastNonFullscreenBounds != null) {
1956 updateOverrideConfiguration(mLastNonFullscreenBounds);
1957 } else {
1958 inStack.layoutTaskInStack(this, null);
1959 }
1960 } else {
1961 updateOverrideConfiguration(inStack.mBounds);
1962 }
1963 }
1964
Chong Zhang0fa656b2015-08-31 15:17:21 -07001965 /**
1966 * Returns the correct stack to use based on task type and currently set bounds,
1967 * regardless of the focused stack and current stack association of the task.
1968 * The task will be moved (and stack focus changed) later if necessary.
1969 */
1970 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001971 if (isRecentsTask()) {
1972 return RECENTS_STACK_ID;
1973 }
1974 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001975 return HOME_STACK_ID;
1976 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001977 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001978 return FREEFORM_WORKSPACE_STACK_ID;
1979 }
1980 return FULLSCREEN_WORKSPACE_STACK_ID;
1981 }
1982
1983 /** Returns the bounds that should be used to launch this task. */
1984 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001985 // If we're over lockscreen, forget about stack bounds and use fullscreen.
Jorim Jaggife762342016-10-13 14:33:27 +02001986 if (mService.mStackSupervisor.mKeyguardController.isKeyguardShowing()) {
Chong Zhang75b37202015-12-04 14:16:36 -08001987 return null;
1988 }
1989
Andrii Kulian02b7a832016-10-06 23:11:56 -07001990 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08001991 return null;
1992 }
1993
Andrii Kulian02b7a832016-10-06 23:11:56 -07001994 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08001995 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001996 || stackId == RECENTS_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08001997 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001998 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001999 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07002000 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002001 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002002 }
2003 return mLastNonFullscreenBounds;
2004 }
2005
Wale Ogunwale39381972015-12-17 17:15:29 -08002006 boolean canMatchRootAffinity() {
2007 // We don't allow root affinity matching on the pinned stack as no other task should
2008 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07002009 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08002010 }
2011
Jorim Jaggi8b702ed2017-01-20 16:59:03 +01002012 void addStartingWindowsForVisibleActivities(boolean taskSwitch) {
2013 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
2014 final ActivityRecord r = mActivities.get(activityNdx);
2015 if (r.visible) {
2016 r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch);
2017 }
2018 }
2019 }
2020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002022 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07002023 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
2024 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08002025 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002026 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07002027 if (affinity != null || rootAffinity != null) {
2028 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
2029 if (affinity == null || !affinity.equals(rootAffinity)) {
2030 pw.print(" root="); pw.println(rootAffinity);
2031 } else {
2032 pw.println();
2033 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002034 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07002035 if (voiceSession != null || voiceInteractor != null) {
2036 pw.print(prefix); pw.print("VOICE: session=0x");
2037 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
2038 pw.print(" interactor=0x");
2039 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
2040 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002041 if (intent != null) {
2042 StringBuilder sb = new StringBuilder(128);
2043 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002044 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002045 sb.append('}');
2046 pw.println(sb.toString());
2047 }
2048 if (affinityIntent != null) {
2049 StringBuilder sb = new StringBuilder(128);
2050 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002051 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002052 sb.append('}');
2053 pw.println(sb.toString());
2054 }
2055 if (origActivity != null) {
2056 pw.print(prefix); pw.print("origActivity=");
2057 pw.println(origActivity.flattenToShortString());
2058 }
2059 if (realActivity != null) {
2060 pw.print(prefix); pw.print("realActivity=");
2061 pw.println(realActivity.flattenToShortString());
2062 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07002063 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
2064 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002065 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002066 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002067 pw.print(" numFullscreen="); pw.print(numFullscreen);
2068 pw.print(" taskType="); pw.print(taskType);
2069 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
2070 }
Craig Mautner432f64e2015-05-20 14:59:57 -07002071 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
2072 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002073 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
2074 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07002075 pw.print(" mReuseTask="); pw.print(mReuseTask);
2076 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002077 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08002078 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
2079 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
2080 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07002081 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
2082 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
2083 pw.print(" (");
2084 if (mPrevAffiliate == null) {
2085 pw.print("null");
2086 } else {
2087 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
2088 }
2089 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
2090 pw.print(" (");
2091 if (mNextAffiliate == null) {
2092 pw.print("null");
2093 } else {
2094 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2095 }
2096 pw.println(")");
2097 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002098 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002099 if (!askedCompatMode || !inRecents || !isAvailable) {
2100 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2101 pw.print(" inRecents="); pw.print(inRecents);
2102 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002103 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002104 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002105 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2106 if (lastDescription != null) {
2107 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2108 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002109 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002110 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2111 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08002112 pw.print(" mSupportsPictureInPicture=" + mSupportsPictureInPicture);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002113 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00002114 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002115 pw.print(" lastActiveTime=" + lastActiveTime);
2116 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 }
2118
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002119 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002121 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002122 if (stringName != null) {
2123 sb.append(stringName);
2124 sb.append(" U=");
2125 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002126 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002127 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002128 sb.append(" sz=");
2129 sb.append(mActivities.size());
2130 sb.append('}');
2131 return sb.toString();
2132 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002133 sb.append("TaskRecord{");
2134 sb.append(Integer.toHexString(System.identityHashCode(this)));
2135 sb.append(" #");
2136 sb.append(taskId);
2137 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002138 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002139 sb.append(affinity);
2140 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002141 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002142 sb.append(intent.getComponent().flattenToShortString());
2143 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002144 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002145 sb.append(affinityIntent.getComponent().flattenToShortString());
2146 } else {
2147 sb.append(" ??");
2148 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002149 stringName = sb.toString();
2150 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002151 }
2152}