blob: 2373ea8975d8b2a21d54115853eb192294a71e7f [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 Ogunwalee1fe7fa22016-12-15 18:27:00 -080054import com.android.server.wm.TaskWindowContainerController;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010055import com.android.server.wm.TaskWindowContainerListener;
56
Craig Mautner21d24a22014-04-23 11:45:37 -070057import org.xmlpull.v1.XmlPullParser;
58import org.xmlpull.v1.XmlPullParserException;
59import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060
Craig Mautnerc0ffce52014-07-01 12:38:52 -070061import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070062import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080064import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070065import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080067import static android.app.ActivityManager.RESIZE_MODE_FORCED;
Jorim Jaggi0a932142016-02-01 17:42:25 -080068import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
69import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
70import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
71import static android.app.ActivityManager.StackId.HOME_STACK_ID;
72import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
73import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080074import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080075import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
76import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070077import static android.content.pm.ActivityInfo.FLAG_ON_TOP_LAUNCHER;
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.
Winson Chungd3395382016-12-13 11:49:09 -0800193 boolean mSupportsPictureInPicture; // Whether or not this task and its activities support PiP.
194 // Based on the {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE} flag of the root
195 // 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.
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700202 private boolean mIsOnTopLauncher; // Whether this task is an on-top launcher. See
203 // android.R.attr#onTopLauncher.
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700204
Craig Mautner15df08a2015-04-01 12:17:18 -0700205 /** Can't be put in lockTask mode. */
206 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100207 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700208 final static int LOCK_TASK_AUTH_PINNABLE = 1;
209 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
210 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100211 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700212 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100213 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
214 * lockTask task. */
215 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700216 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
217
218 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800219
Winson Chung03a9bae2014-05-02 09:56:12 -0700220 // This represents the last resolved activity values for this task
221 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700222 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700223
Craig Mautnerd2328952013-03-05 12:46:26 -0800224 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700225 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800226
Andrii Kulian02b7a832016-10-06 23:11:56 -0700227 /** Current stack. Setter must always be used to update the value. */
228 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800229
Craig Mautner2c1faed2013-07-23 12:56:02 -0700230 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700231 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700232
Craig Mautner21d24a22014-04-23 11:45:37 -0700233 /** Takes on same value as first root activity */
234 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700235 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700236
237 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
238 * determining the order when restoring. Sign indicates whether last task movement was to front
239 * (positive) or back (negative). Absolute value indicates time. */
240 long mLastTimeMoved = System.currentTimeMillis();
241
Craig Mautner84984fa2014-06-19 11:19:20 -0700242 /** Indication of what to run next when task exits. Use ActivityRecord types.
243 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
244 * task stack. */
245 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700246
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700247 /** If original intent did not allow relinquishing task identity, save that information */
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700248 private boolean mNeverRelinquishIdentity = true;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700249
Craig Mautner362449a2014-06-20 14:04:39 -0700250 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
251 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800252 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700253
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700254 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700255 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700256 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800257 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700258 CharSequence lastDescription; // Last description captured for this item.
259
Craig Mautnera228ae92014-07-09 05:44:55 -0700260 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700261 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700262 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800263 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700264 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800265 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700266
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700267 // For relaunching the task from recents as though it was launched by the original launcher.
268 int mCallingUid;
269 String mCallingPackage;
270
Craig Mautner21d24a22014-04-23 11:45:37 -0700271 final ActivityManagerService mService;
272
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700273 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
274 boolean mFullscreen = true;
275
276 // Bounds of the Task. null for fullscreen tasks.
277 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800278 private final Rect mTmpStableBounds = new Rect();
279 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800280 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800281 private final Rect mTmpRect2 = new Rect();
282
Wale Ogunwale706ed792015-08-02 10:29:44 -0700283 // Last non-fullscreen bounds the task was launched in or resized to.
284 // The information is persisted and used to determine the appropriate stack to launch the
285 // task into on restore.
286 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700287 // Minimal width and height of this task when it's resizeable. -1 means it should use the
288 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700289 int mMinWidth;
290 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700291
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700292 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
293 // This number will be assigned when we evaluate OOM scores for all visible tasks.
294 int mLayerRank = -1;
295
Andrii Kulian1779e612016-10-12 21:58:25 -0700296 /** Helper object used for updating override configuration. */
297 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700298
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800299 private TaskWindowContainerController mWindowContainerController;
300
Craig Mautner21d24a22014-04-23 11:45:37 -0700301 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Wale Ogunwale72919d22016-12-08 18:58:50 -0800302 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, int type) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700303 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700304 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
305 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800306 userId = UserHandle.getUserId(info.applicationInfo.uid);
307 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800308 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700310 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700311 voiceSession = _voiceSession;
312 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700313 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800314 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700315 mCallingUid = info.applicationInfo.uid;
316 mCallingPackage = info.packageName;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800317 taskType = type;
Martijn Coenend4a69702014-06-30 11:12:17 -0700318 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700319 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700320 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700321 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Craig Mautner21d24a22014-04-23 11:45:37 -0700322 }
323
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700324 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800325 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700326 mService = service;
327 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
328 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800329 userId = UserHandle.getUserId(info.applicationInfo.uid);
330 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800331 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700332 taskId = _taskId;
333 mAffiliatedTaskId = _taskId;
334 voiceSession = null;
335 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700336 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800337 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700338 mCallingUid = info.applicationInfo.uid;
339 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700340 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700341 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700342
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700343 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700344 // Clamp to [1, max].
345 maxRecents = Math.min(Math.max(info.maxRecents, 1),
346 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700347
348 taskType = APPLICATION_ACTIVITY_TYPE;
349 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700350 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700351 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700352 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700353 }
354
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800355 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
356 Intent _affinityIntent, String _affinity, String _rootAffinity,
357 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
358 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
359 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
360 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
361 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800362 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
363 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Winson Chungd3395382016-12-13 11:49:09 -0800364 int resizeMode, boolean supportsPictureInPicture, boolean privileged,
365 boolean _realActivitySuspended, boolean userSetupComplete, int minWidth,
366 int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700367 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700368 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
369 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800370 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800371 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700372 taskId = _taskId;
373 intent = _intent;
374 affinityIntent = _affinityIntent;
375 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800376 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700377 voiceSession = null;
378 voiceInteractor = null;
379 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800380 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700381 origActivity = _origActivity;
382 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700383 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700384 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700385 askedCompatMode = _askedCompatMode;
386 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700387 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700388 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800389 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700390 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700391 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700392 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700393 lastDescription = _lastDescription;
394 mActivities = activities;
395 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700396 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700397 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700398 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700399 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700400 mPrevAffiliateTaskId = prevTaskId;
401 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700402 mCallingUid = callingUid;
403 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800404 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800405 mSupportsPictureInPicture = supportsPictureInPicture;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700406 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700407 mMinWidth = minWidth;
408 mMinHeight = minHeight;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700409 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 }
411
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800412 TaskWindowContainerController getWindowContainerController() {
413 return mWindowContainerController;
414 }
415
416 void createWindowContainer(boolean onTop, boolean showForAllUsers) {
417 if (mWindowContainerController != null) {
418 throw new IllegalArgumentException("Window container=" + mWindowContainerController
419 + " already created for task=" + this);
420 }
421
422 final Rect bounds = updateOverrideConfigurationFromLaunchBounds();
423 final Configuration overrideConfig = getOverrideConfiguration();
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100424 mWindowContainerController = new TaskWindowContainerController(taskId, this, getStackId(),
Winson Chungd3395382016-12-13 11:49:09 -0800425 userId, bounds, overrideConfig, mResizeMode, mSupportsPictureInPicture,
426 isHomeTask(), isOnTopLauncher(), onTop, showForAllUsers, lastTaskDescription);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800427 }
428
429 void removeWindowContainer() {
430 mService.mStackSupervisor.removeLockedTaskLocked(this);
431 mWindowContainerController.removeContainer();
432 if (!StackId.persistTaskBounds(getStackId())) {
433 // Reset current bounds for task whose bounds shouldn't be persisted so it uses
434 // default configuration the next time it launches.
435 updateOverrideConfiguration(null);
436 }
437 mService.mTaskChangeNotificationController.notifyTaskRemoved(taskId);
438 mWindowContainerController = null;
439 }
440
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100441 @Override
442 public void onSnapshotChanged(TaskSnapshot snapshot) {
443 mService.mTaskChangeNotificationController.notifyTaskSnapshotChanged(taskId, snapshot);
444 }
445
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800446 void setResizeMode(int resizeMode) {
447 if (mResizeMode == resizeMode) {
448 return;
449 }
450 mResizeMode = resizeMode;
451 mWindowContainerController.setResizeable(resizeMode);
452 mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
453 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
454 }
455
456 void setTaskDockedResizing(boolean resizing) {
457 mWindowContainerController.setTaskDockedResizing(resizing);
458 }
459
460 boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
461 if (!isResizeable()) {
462 Slog.w(TAG, "resizeTask: task " + this + " not resizeable.");
463 return true;
464 }
465
466 // If this is a forced resize, let it go through even if the bounds is not changing,
467 // as we might need a relayout due to surface size change (to/from fullscreen).
468 final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
469 if (Objects.equals(mBounds, bounds) && !forced) {
470 // Nothing to do here...
471 return true;
472 }
473 bounds = validateBounds(bounds);
474
475 if (mWindowContainerController == null) {
476 // Task doesn't exist in window manager yet (e.g. was restored from recents).
477 // All we can do for now is update the bounds so it can be used when the task is
478 // added to window manager.
479 updateOverrideConfiguration(bounds);
480 if (getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
481 // re-restore the task so it can have the proper stack association.
482 mService.mStackSupervisor.restoreRecentTaskLocked(this,
483 FREEFORM_WORKSPACE_STACK_ID);
484 }
485 return true;
486 }
487
488 if (!canResizeToBounds(bounds)) {
489 throw new IllegalArgumentException("resizeTask: Can not resize task=" + this
490 + " to bounds=" + bounds + " resizeMode=" + mResizeMode);
491 }
492
493 // Do not move the task to another stack here.
494 // This method assumes that the task is already placed in the right stack.
495 // we do not mess with that decision and we only do the resize!
496
497 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId);
498
499 final boolean updatedConfig = updateOverrideConfiguration(bounds);
500 // This variable holds information whether the configuration didn't change in a significant
501 // way and the activity was kept the way it was. If it's false, it means the activity had
502 // to be relaunched due to configuration change.
503 boolean kept = true;
504 if (updatedConfig) {
505 final ActivityRecord r = topRunningActivityLocked();
506 if (r != null) {
507 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
508
509 if (!deferResume) {
510 // All other activities must be made visible with their correct configuration.
511 mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
512 if (!kept) {
513 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
514 }
515 }
516 }
517 }
518 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), kept, forced);
519
520 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
521 return kept;
522 }
523
524 // TODO: Investigate combining with the resize() method above.
525 void resizeWindowContainer() {
526 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), false /* relayout */,
527 false /* forced */);
528 }
529
530 // TODO: Remove once we have a stack controller.
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800531 void positionWindowContainerAt(int position) {
532 mWindowContainerController.positionAt(position, mBounds, getOverrideConfiguration());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800533 }
534
535 // TODO: Replace with moveChildToTop?
536 void moveWindowContainerToTop(boolean includingParents) {
537 if (mWindowContainerController != null) {
538 mWindowContainerController.moveToTop(includingParents);
539 }
540 }
541
542 // TODO: Replace with moveChildToBottom?
543 void moveWindowContainerToBottom() {
544 if (mWindowContainerController != null) {
545 mWindowContainerController.moveToBottom();
546 }
547 }
548
549 void getWindowContainerBounds(Rect bounds) {
550 mWindowContainerController.getBounds(bounds);
551 }
552
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800553 // TODO: Should we be doing all the stuff in ASS.moveTaskToStackLocked?
554 void reparent(int stackId, int position, String reason) {
555 mService.mWindowManager.deferSurfaceLayout();
556
557 try {
558 final ActivityStackSupervisor supervisor = mService.mStackSupervisor;
559 final ActivityStack newStack = supervisor.getStack(stackId,
560 CREATE_IF_NEEDED, false /* toTop */);
561 // Adjust the position for the new parent stack as needed.
562 position = newStack.getAdjustedPositionForTask(this, position, null /* starting */);
563
564 // Must reparent first in window manager to avoid a situation where AM can delete the
565 // we are coming from in WM before we reparent because it became empty.
566 mWindowContainerController.reparent(stackId, position);
567
568 final ActivityStack prevStack = mStack;
569 prevStack.removeTask(this, reason, REMOVE_TASK_MODE_MOVING);
570 newStack.addTask(this, position, reason);
571
572 supervisor.scheduleReportPictureInPictureModeChangedIfNeeded(this, prevStack);
573
574 if (voiceSession != null) {
575 try {
576 voiceSession.taskStarted(intent, taskId);
577 } catch (RemoteException e) {
578 }
579 }
580 } finally {
581 mService.mWindowManager.continueSurfaceLayout();
582 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800583 }
584
585 void cancelWindowTransition() {
586 mWindowContainerController.cancelWindowTransition();
587 }
588
589 void cancelThumbnailTransition() {
590 mWindowContainerController.cancelThumbnailTransition();
591 }
592
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100593 /**
594 * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
595 */
596 TaskSnapshot getSnapshot() {
597
598 // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
599 // synchronized between AM and WM.
600 return mService.mWindowManager.getTaskSnapshot(taskId, userId);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800601 }
602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000604 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700605 if (firstActiveTime == 0) {
606 firstActiveTime = lastActiveTime;
607 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000611 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700613
Winson Chungfee26772014-08-05 12:21:52 -0700614 /** Sets the original intent, and the calling uid and package. */
615 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700616 mCallingUid = r.launchedFromUid;
617 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700618 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700619 }
620
621 /** Sets the original intent, _without_ updating the calling uid or package. */
622 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700623 if (intent == null) {
624 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700625 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700626 } else if (mNeverRelinquishIdentity) {
627 return;
628 }
629
630 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700631 if (intent == null) {
632 // If this task already has an intent associated with it, don't set the root
633 // affinity -- we don't want it changing after initially set, but the initially
634 // set value may be null.
635 rootAffinity = affinity;
636 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700637 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700638 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800641 if (_intent != null) {
642 // If this Intent has a selector, we want to clear it for the
643 // recent task since it is not relevant if the user later wants
644 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700645 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800646 _intent = new Intent(_intent);
647 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700648 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800649 }
650 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700651 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 intent = _intent;
653 realActivity = _intent != null ? _intent.getComponent() : null;
654 origActivity = null;
655 } else {
656 ComponentName targetComponent = new ComponentName(
657 info.packageName, info.targetActivity);
658 if (_intent != null) {
659 Intent targetIntent = new Intent(_intent);
660 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800661 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700662 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700663 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700664 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 intent = targetIntent;
666 realActivity = targetComponent;
667 origActivity = _intent.getComponent();
668 } else {
669 intent = null;
670 realActivity = targetComponent;
671 origActivity = new ComponentName(info.packageName, info.name);
672 }
673 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700674
Craig Mautner47b20ba2014-09-17 17:23:44 -0700675 final int intentFlags = intent == null ? 0 : intent.getFlags();
676 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 // Once we are set to an Intent with this flag, we count this
678 // task as having a true root activity.
679 rootWasReset = true;
680 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700681 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000682 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
683 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700684 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700685 // If the activity itself has requested auto-remove, then just always do it.
686 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700687 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
688 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700689 // If the caller has not asked for the document to be retained, then we may
690 // want to turn on auto-remove, depending on whether the target has set its
691 // own document launch mode.
692 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
693 autoRemoveRecents = false;
694 } else {
695 autoRemoveRecents = true;
696 }
697 } else {
698 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700699 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800700 mResizeMode = info.resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800701 mSupportsPictureInPicture = info.supportsPictureInPicture();
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700702 mIsOnTopLauncher = (info.flags & FLAG_ON_TOP_LAUNCHER) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700703 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700704 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700705 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800707
Andrii Kulian2e751b82016-03-16 16:59:32 -0700708 /** Sets the original minimal width and height. */
709 private void setMinDimensions(ActivityInfo info) {
710 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700711 mMinWidth = info.windowLayout.minWidth;
712 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700713 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700714 mMinWidth = INVALID_MIN_SIZE;
715 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700716 }
717 }
718
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800719 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700720 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800721 * record is based on (normally the root activity intent).
722 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700723 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800724 final Intent intent = new Intent(r.intent);
725 // Correct the activity intent for aliasing. The task record intent will always be based on
726 // the real activity that will be launched not the alias, so we need to use an intent with
727 // the component name pointing to the real activity not the alias in the activity record.
728 intent.setComponent(r.realActivity);
729 return this.intent.filterEquals(intent);
730 }
731
Craig Mautner84984fa2014-06-19 11:19:20 -0700732 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800733 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
734 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700735 }
736
737 int getTaskToReturnTo() {
738 return mTaskToReturnTo;
739 }
740
Craig Mautnera228ae92014-07-09 05:44:55 -0700741 void setPrevAffiliate(TaskRecord prevAffiliate) {
742 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800743 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700744 }
745
746 void setNextAffiliate(TaskRecord nextAffiliate) {
747 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800748 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700749 }
750
Andrii Kulian02b7a832016-10-06 23:11:56 -0700751 ActivityStack getStack() {
752 return mStack;
753 }
754
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800755 /**
756 * Must be used for setting parent stack because it performs configuration updates.
757 * Must be called after adding task as a child to the stack.
758 */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700759 void setStack(ActivityStack stack) {
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800760 if (stack != null && !stack.isInStackLocked(this)) {
761 throw new IllegalStateException("Task must be added as a Stack child first.");
762 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700763 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700764 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700765 }
766
767 /**
768 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
769 */
770 int getStackId() {
771 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
772 }
773
Andrii Kulian1779e612016-10-12 21:58:25 -0700774 @Override
775 protected int getChildCount() {
776 return 0;
777 }
778
779 @Override
780 protected ConfigurationContainer getChildAt(int index) {
781 return null;
782 }
783
784 @Override
785 protected ConfigurationContainer getParent() {
786 return mStack;
787 }
788
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800789 @Override
790 void onParentChanged() {
791 super.onParentChanged();
792 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
793 }
794
Craig Mautnera228ae92014-07-09 05:44:55 -0700795 // Close up recents linked list.
796 void closeRecentsChain() {
797 if (mPrevAffiliate != null) {
798 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
799 }
800 if (mNextAffiliate != null) {
801 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
802 }
803 setPrevAffiliate(null);
804 setNextAffiliate(null);
805 }
806
Winson Chung740c3ac2014-11-12 16:14:38 -0800807 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700808 disposeThumbnail();
809 closeRecentsChain();
810 if (inRecents) {
811 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800812 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700813 }
Jorim Jaggif9084ec2017-01-16 13:16:59 +0100814
815 // TODO: Use window container controller once tasks are better synced between AM and WM
816 mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700817 }
818
Craig Mautnera228ae92014-07-09 05:44:55 -0700819 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
820 closeRecentsChain();
821 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700822 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700823 // Find the end
824 while (taskToAffiliateWith.mNextAffiliate != null) {
825 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
826 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
827 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
828 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
829 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
830 nextRecents.setPrevAffiliate(null);
831 }
832 taskToAffiliateWith.setNextAffiliate(null);
833 break;
834 }
835 taskToAffiliateWith = nextRecents;
836 }
837 taskToAffiliateWith.setNextAffiliate(this);
838 setPrevAffiliate(taskToAffiliateWith);
839 setNextAffiliate(null);
840 }
841
Winson Chung096f36b2014-08-20 15:39:01 -0700842 /**
Winsonc809cbb2015-11-02 12:06:15 -0800843 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700844 * @return whether the thumbnail was set
845 */
Winsonc809cbb2015-11-02 12:06:15 -0800846 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -0800847 int taskWidth = 0;
848 int taskHeight = 0;
849 if (mBounds != null) {
850 // Non-fullscreen tasks
851 taskWidth = mBounds.width();
852 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700853 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -0800854 // Fullscreen tasks
855 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700856 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -0800857 taskWidth = displaySize.x;
858 taskHeight = displaySize.y;
859 } else {
860 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
861 }
Andrii Kulian1779e612016-10-12 21:58:25 -0700862 // We need to provide the current orientation of the display on which this task resides,
863 // not the orientation of the task.
864 final int orientation =
865 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
866 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -0800867 }
868
869 /**
870 * Sets the last thumbnail with the current task bounds.
871 * @return whether the thumbnail was set
872 */
873 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
874 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700875 if (mLastThumbnail != thumbnail) {
876 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800877 mLastThumbnailInfo.taskWidth = taskWidth;
878 mLastThumbnailInfo.taskHeight = taskHeight;
879 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700880 if (thumbnail == null) {
881 if (mLastThumbnailFile != null) {
882 mLastThumbnailFile.delete();
883 }
884 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800885 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700886 }
Winson Chung096f36b2014-08-20 15:39:01 -0700887 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700888 }
Winson Chung096f36b2014-08-20 15:39:01 -0700889 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700890 }
891
892 void getLastThumbnail(TaskThumbnail thumbs) {
893 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800894 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700895 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700896 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800897 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800898 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700899 }
Winson Chung096f36b2014-08-20 15:39:01 -0700900 // Only load the thumbnail file if we don't have a thumbnail
901 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700902 try {
903 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
904 ParcelFileDescriptor.MODE_READ_ONLY);
905 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700906 }
907 }
908 }
909
Winsonc809cbb2015-11-02 12:06:15 -0800910 /**
911 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
912 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700913 void freeLastThumbnail() {
914 mLastThumbnail = null;
915 }
916
Winsonc809cbb2015-11-02 12:06:15 -0800917 /**
918 * Removes all associated thumbnail data when a task is removed or pruned from recents.
919 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700920 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800921 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700922 mLastThumbnail = null;
923 lastDescription = null;
924 }
925
Winson Chung1147c402014-05-14 11:05:00 -0700926 /** Returns the intent for the root activity for this task */
927 Intent getBaseIntent() {
928 return intent != null ? intent : affinityIntent;
929 }
930
Winson Chung3b3f4642014-04-22 10:08:18 -0700931 /** Returns the first non-finishing activity from the root. */
932 ActivityRecord getRootActivity() {
933 for (int i = 0; i < mActivities.size(); i++) {
934 final ActivityRecord r = mActivities.get(i);
935 if (r.finishing) {
936 continue;
937 }
938 return r;
939 }
940 return null;
941 }
942
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800943 ActivityRecord getTopActivity() {
944 for (int i = mActivities.size() - 1; i >= 0; --i) {
945 final ActivityRecord r = mActivities.get(i);
946 if (r.finishing) {
947 continue;
948 }
949 return r;
950 }
951 return null;
952 }
953
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700954 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700955 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700956 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
957 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -0700958 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700959 return r;
960 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700961 }
962 }
963 return null;
964 }
965
Wale Ogunwale3b232392016-05-13 15:37:13 -0700966 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700967 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700968 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
969 ActivityRecord r = mActivities.get(activityNdx);
970 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -0700971 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700972 continue;
973 }
974 return r;
975 }
976 }
977 return null;
978 }
979
Chong Zhang87761972016-08-22 13:53:24 -0700980 boolean okToShowLocked() {
981 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
982 // okay to show the activity when locked.
983 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
984 || topRunningActivityLocked() != null;
985 }
986
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800987 void setFrontOfTask() {
988 setFrontOfTask(null);
989 }
990
Craig Mautner3b475fe2013-12-16 15:58:31 -0800991 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800992 void setFrontOfTask(ActivityRecord newTop) {
993 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
994 // as not front. This is needed in situations where the current front activity in the
995 // task isn't finished yet and we want to set the front to the activity moved to the front
996 // of the task.
997 boolean foundFront = newTop != null ? true : false;
998
Craig Mautner3b475fe2013-12-16 15:58:31 -0800999 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -08001000 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -08001001 final ActivityRecord r = mActivities.get(activityNdx);
1002 if (foundFront || r.finishing) {
1003 r.frontOfTask = false;
1004 } else {
1005 r.frontOfTask = true;
1006 // Set frontOfTask false for every following activity.
1007 foundFront = true;
1008 }
1009 }
Craig Mautner9587ee02014-06-23 15:00:10 +00001010 if (!foundFront && numActivities > 0) {
1011 // All activities of this task are finishing. As we ought to have a frontOfTask
1012 // activity, make the bottom activity front.
1013 mActivities.get(0).frontOfTask = true;
1014 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -08001015 if (newTop != null) {
1016 newTop.frontOfTask = true;
1017 }
Craig Mautner3b475fe2013-12-16 15:58:31 -08001018 }
1019
Craig Mautnerde4ef022013-04-07 19:01:33 -07001020 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -08001021 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -07001022 */
1023 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001024 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
1025 "Removing and adding activity " + newTop
1026 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -07001027
Craig Mautnerde4ef022013-04-07 19:01:33 -07001028 mActivities.remove(newTop);
1029 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001030 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -08001031
Wale Ogunwale6d42df62015-11-05 09:50:55 -08001032 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001033 }
1034
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001035 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -08001036 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001037 }
1038
1039 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001040 addActivityAtIndex(mActivities.size(), r);
1041 }
1042
Wale Ogunwalec5cc3012017-01-13 13:26:16 -08001043 // TODO: Figure-out if any of the call points expect the window container to be reparented and
1044 // correct them to use the right method.
Craig Mautner1602ec22013-05-12 10:24:27 -07001045 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -07001046 // 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 -08001047 if (!mActivities.remove(r) && r.fullscreen) {
1048 // Was not previously in list.
1049 numFullscreen++;
1050 }
Craig Mautner2c1faed2013-07-23 12:56:02 -07001051 // Only set this based on the first activity
1052 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001053 taskType = r.mActivityType;
1054 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001055 mCallingUid = r.launchedFromUid;
1056 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001057 // Clamp to [1, max].
1058 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
1059 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -07001060 } else {
1061 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -07001062 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -07001063 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001064
1065 final int size = mActivities.size();
1066
1067 if (index == size && size > 0) {
1068 final ActivityRecord top = mActivities.get(size - 1);
1069 if (top.mTaskOverlay) {
1070 // Place below the task overlay activity since the overlay activity should always
1071 // be on top.
1072 index--;
1073 }
1074 }
1075
Craig Mautner77878772013-03-04 19:46:24 -08001076 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001077 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001078 if (r.isPersistable()) {
1079 mService.notifyTaskPersisterLocked(this, false);
1080 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001081
1082 // Sync. with window manager
1083 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001084 mWindowContainerController.positionChildAt(r.getWindowContainerController(), index);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001085 r.onOverrideConfigurationSent();
Craig Mautner77878772013-03-04 19:46:24 -08001086 }
1087
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001088 /** @return true if this was the last activity in the task */
1089 boolean removeActivity(ActivityRecord r) {
1090 if (mActivities.remove(r) && r.fullscreen) {
1091 // Was previously in list.
1092 numFullscreen--;
1093 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001094 if (r.isPersistable()) {
1095 mService.notifyTaskPersisterLocked(this, false);
1096 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001097
Andrii Kulian02b7a832016-10-06 23:11:56 -07001098 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001099 // We normally notify listeners of task stack changes on pause, however pinned stack
1100 // activities are normally in the paused state so no notification will be sent there
1101 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001102 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001103 }
1104
Craig Mautner41326202014-06-20 14:38:21 -07001105 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001106 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001107 }
1108 updateEffectiveIntent();
1109 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001110 }
1111
Craig Mautner41db4a72014-05-07 17:20:56 -07001112 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001113 // We will automatically remove the task either if it has explicitly asked for
1114 // this, or it is empty and has never contained an activity that got shown to
1115 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001116 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001117 }
1118
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001119 /**
1120 * Completely remove all activities associated with an existing
1121 * task starting at a specified index.
1122 */
1123 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001124 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001125 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001126 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001127 if (r.finishing) {
1128 continue;
1129 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001130 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001131 // Task was restored from persistent storage.
1132 r.takeFromHistory();
1133 mActivities.remove(activityNdx);
1134 --activityNdx;
1135 --numActivities;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001136 } else if (mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001137 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001138 --activityNdx;
1139 --numActivities;
1140 }
1141 }
1142 }
1143
1144 /**
1145 * Completely remove all activities associated with an existing task.
1146 */
1147 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001148 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001149 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -07001150 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001151 }
1152
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001153 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1154 mReuseTask = true;
1155 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1156 mReuseTask = false;
1157 return result;
1158 }
1159
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001160 /**
1161 * Perform clear operation as requested by
1162 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1163 * stack to the given task, then look for
1164 * an instance of that activity in the stack and, if found, finish all
1165 * activities on top of it and return the instance.
1166 *
1167 * @param newR Description of the new activity being started.
1168 * @return Returns the old activity that should be continued to be used,
1169 * or null if none was found.
1170 */
1171 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001172 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001173 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001174 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001175 if (r.finishing) {
1176 continue;
1177 }
1178 if (r.realActivity.equals(newR.realActivity)) {
1179 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001180 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001181
1182 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001183 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001184 if (r.finishing) {
1185 continue;
1186 }
1187 ActivityOptions opts = r.takeOptionsLocked();
1188 if (opts != null) {
1189 ret.updateOptionsLocked(opts);
1190 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001191 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001192 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001193 --activityNdx;
1194 --numActivities;
1195 }
1196 }
1197
1198 // Finally, if this is a normal launch mode (that is, not
1199 // expecting onNewIntent()), then we will finish the current
1200 // instance of the activity so a new fresh one can be started.
1201 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001202 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1203 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001204 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001205 if (mStack != null) {
1206 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001207 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1208 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001209 return null;
1210 }
1211 }
1212
1213 return ret;
1214 }
1215 }
1216
1217 return null;
1218 }
1219
Andrii Kulian21713ac2016-10-12 22:05:05 -07001220 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001221 if (mStack != null) {
1222 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Craig Mautner21d24a22014-04-23 11:45:37 -07001223 if (resumedActivity != null && resumedActivity.task == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001224 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001225 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001226 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001227 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001228 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1229 getLastThumbnail(taskThumbnail);
1230 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001231 }
1232
Andrii Kulian21713ac2016-10-12 22:05:05 -07001233 void removeTaskActivitiesLocked() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001234 // Just remove the entire task.
1235 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001236 }
1237
Craig Mautner432f64e2015-05-20 14:59:57 -07001238 String lockTaskAuthToString() {
1239 switch (mLockTaskAuth) {
1240 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1241 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1242 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1243 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001244 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001245 default: return "unknown=" + mLockTaskAuth;
1246 }
1247 }
1248
Craig Mautner15df08a2015-04-01 12:17:18 -07001249 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001250 if (!mPrivileged &&
1251 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1252 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1253 // Non-priv apps are not allowed to use always or never, fall back to default
1254 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1255 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001256 switch (mLockTaskMode) {
1257 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1258 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1259 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1260 break;
1261
1262 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001263 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001264 break;
1265
1266 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001267 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001268 break;
1269
1270 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1271 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1272 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1273 break;
1274 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001275 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1276 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001277 }
1278
1279 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001280 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1281 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001282 return false;
1283 }
1284 String[] packages = mService.mLockTaskPackages.get(userId);
1285 if (packages == null) {
1286 return false;
1287 }
1288 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001289 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001290 return true;
1291 }
1292 }
1293 return false;
1294 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001295
Craig Mautnera82aa092013-09-13 15:34:08 -07001296 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001297 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001298 }
1299
Wale Ogunwale74e26592016-02-05 11:48:37 -08001300 boolean isRecentsTask() {
1301 return taskType == RECENTS_ACTIVITY_TYPE;
1302 }
1303
Craig Mautner86d67a42013-05-14 10:34:38 -07001304 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001305 return taskType == APPLICATION_ACTIVITY_TYPE;
1306 }
1307
1308 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001309 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001310 }
1311
Winson Chungd3395382016-12-13 11:49:09 -08001312 private boolean isResizeable(boolean checkSupportsPip) {
1313 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode)
1314 || (checkSupportsPip && mSupportsPictureInPicture)) && !mTemporarilyUnresizable;
1315 }
1316
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001317 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001318 return isResizeable(true /* checkSupportsPip */);
1319 }
1320
1321 boolean supportsSplitScreen() {
1322 // A task can not be docked even if it is considered resizeable because it only supports
1323 // picture-in-picture mode but has a non-resizeable resizeMode
1324 return mService.mSupportsSplitScreenMultiWindow
1325 && isResizeable(false /* checkSupportsPip */)
1326 && !ActivityInfo.isPreserveOrientationMode(mResizeMode);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001327 }
1328
skuhne@google.com322347b2016-12-02 12:54:03 -08001329 /**
1330 * Check that a given bounds matches the application requested orientation.
1331 *
1332 * @param bounds The bounds to be tested.
1333 * @return True if the requested bounds are okay for a resizing request.
1334 */
1335 boolean canResizeToBounds(Rect bounds) {
1336 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1337 // Note: If not on the freeform workspace, we ignore the bounds.
1338 return true;
1339 }
1340 final boolean landscape = bounds.width() > bounds.height();
1341 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1342 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1343 }
1344 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1345 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1346 }
1347
Jiaquan Hedd1e66f2016-06-15 15:15:12 -07001348 boolean isOnTopLauncher() {
1349 return isHomeTask() && mIsOnTopLauncher;
1350 }
1351
Craig Mautner525f3d92013-05-07 14:01:50 -07001352 /**
1353 * Find the activity in the history stack within the given task. Returns
1354 * the index within the history at which it's found, or < 0 if not found.
1355 */
1356 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1357 final ComponentName realActivity = r.realActivity;
1358 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1359 ActivityRecord candidate = mActivities.get(activityNdx);
1360 if (candidate.finishing) {
1361 continue;
1362 }
1363 if (candidate.realActivity.equals(realActivity)) {
1364 return candidate;
1365 }
1366 }
1367 return null;
1368 }
1369
Winson Chunga449dc02014-05-16 11:15:04 -07001370 /** Updates the last task description values. */
1371 void updateTaskDescription() {
1372 // Traverse upwards looking for any break between main task activities and
1373 // utility activities.
1374 int activityNdx;
1375 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001376 final boolean relinquish = numActivities != 0 &&
1377 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001378 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001379 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001380 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001381 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001382 // This will be the top activity for determining taskDescription. Pre-inc to
1383 // overcome initial decrement below.
1384 ++activityNdx;
1385 break;
1386 }
Winson Chunga449dc02014-05-16 11:15:04 -07001387 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001388 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001389 break;
1390 }
1391 }
1392 if (activityNdx > 0) {
1393 // Traverse downwards starting below break looking for set label, icon.
1394 // Note that if there are activities in the task but none of them set the
1395 // recent activity values, then we do not fall back to the last set
1396 // values in the TaskRecord.
1397 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001398 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001399 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001400 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001401 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1402 final ActivityRecord r = mActivities.get(activityNdx);
1403 if (r.taskDescription != null) {
1404 if (label == null) {
1405 label = r.taskDescription.getLabel();
1406 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001407 if (iconFilename == null) {
1408 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001409 }
1410 if (colorPrimary == 0) {
1411 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001412 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001413 if (colorBackground == 0) {
1414 colorBackground = r.taskDescription.getBackgroundColor();
1415 }
Winson Chunga449dc02014-05-16 11:15:04 -07001416 }
1417 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001418 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1419 colorBackground);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +01001420 if (mWindowContainerController != null) {
1421 mWindowContainerController.setTaskDescription(lastTaskDescription);
1422 }
Winson Chungec396d62014-08-06 17:08:00 -07001423 // Update the task affiliation color if we are the parent of the group
1424 if (taskId == mAffiliatedTaskId) {
1425 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1426 }
Winson Chunga449dc02014-05-16 11:15:04 -07001427 }
1428 }
1429
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001430 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001431 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001432 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001433 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001434 final ActivityRecord r = mActivities.get(activityNdx);
1435 if (r.finishing) {
1436 continue;
1437 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001438 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001439 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001440 break;
1441 }
1442 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001443 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001444 }
1445
1446 void updateEffectiveIntent() {
1447 final int effectiveRootIndex = findEffectiveRootIndex();
1448 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001449 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001450 }
1451
Craig Mautner21d24a22014-04-23 11:45:37 -07001452 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001453 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001454
1455 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1456 if (realActivity != null) {
1457 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1458 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001459 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001460 if (origActivity != null) {
1461 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1462 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001463 // Write affinity, and root affinity if it is different from affinity.
1464 // We use the special string "@" for a null root affinity, so we can identify
1465 // later whether we were given a root affinity or should just make it the
1466 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001467 if (affinity != null) {
1468 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001469 if (!affinity.equals(rootAffinity)) {
1470 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1471 }
1472 } else if (rootAffinity != null) {
1473 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001474 }
1475 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001476 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001477 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1478 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001479 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001480 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001481 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001482 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001483 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001484 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001485 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001486 if (lastDescription != null) {
1487 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1488 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001489 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001490 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001491 }
Winson Chung36f3f032016-09-08 23:29:43 +00001492 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001493 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001494 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1495 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1496 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001497 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1498 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001499 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08001500 out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE,
1501 String.valueOf(mSupportsPictureInPicture));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001502 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001503 if (mLastNonFullscreenBounds != null) {
1504 out.attribute(
1505 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001506 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001507 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1508 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001509 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001510
Craig Mautner21d24a22014-04-23 11:45:37 -07001511 if (affinityIntent != null) {
1512 out.startTag(null, TAG_AFFINITYINTENT);
1513 affinityIntent.saveToXml(out);
1514 out.endTag(null, TAG_AFFINITYINTENT);
1515 }
1516
Winson Chung36f3f032016-09-08 23:29:43 +00001517 out.startTag(null, TAG_INTENT);
1518 intent.saveToXml(out);
1519 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001520
1521 final ArrayList<ActivityRecord> activities = mActivities;
1522 final int numActivities = activities.size();
1523 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1524 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001525 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001526 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1527 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001528 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001529 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001530 break;
1531 }
1532 out.startTag(null, TAG_ACTIVITY);
1533 r.saveToXml(out);
1534 out.endTag(null, TAG_ACTIVITY);
1535 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001536 }
1537
Winson Chung36f3f032016-09-08 23:29:43 +00001538 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1539 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001540 Intent intent = null;
1541 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001542 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001543 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001544 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001545 ComponentName origActivity = null;
1546 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001547 String rootAffinity = null;
1548 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001549 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001550 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001551 boolean askedCompatMode = false;
1552 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001553 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001554 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001555 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001556 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001557 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001558 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001559 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001560 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001561 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001562 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001563 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001564 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001565 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001566 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001567 int prevTaskId = INVALID_TASK_ID;
1568 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001569 int callingUid = -1;
1570 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001571 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -08001572 boolean supportsPictureInPicture = false;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001573 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001574 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001575 int minWidth = INVALID_MIN_SIZE;
1576 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001577 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001578
1579 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1580 final String attrName = in.getAttributeName(attrNdx);
1581 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001582 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1583 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001584 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001585 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001586 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1587 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001588 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1589 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001590 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1591 origActivity = ComponentName.unflattenFromString(attrValue);
1592 } else if (ATTR_AFFINITY.equals(attrName)) {
1593 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001594 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1595 rootAffinity = attrValue;
1596 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001597 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001598 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001599 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001600 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001601 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001602 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001603 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001604 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001605 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001606 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001607 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001608 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001609 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001610 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001611 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001612 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001613 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001614 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001615 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1616 lastDescription = attrValue;
1617 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001618 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001619 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001620 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001621 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1622 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001623 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1624 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001625 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001626 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001627 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001628 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001629 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001630 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001631 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001632 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001633 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001634 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001635 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1636 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001637 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001638 resizeMode = Integer.parseInt(attrValue);
Winson Chungd3395382016-12-13 11:49:09 -08001639 } else if (ATTR_SUPPORTS_PICTURE_IN_PICTURE.equals(attrName)) {
1640 supportsPictureInPicture = Boolean.parseBoolean(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001641 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001642 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001643 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001644 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001645 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1646 minWidth = Integer.parseInt(attrValue);
1647 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1648 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001649 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1650 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001651 } else {
1652 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1653 }
1654 }
1655
1656 int event;
1657 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001658 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001659 if (event == XmlPullParser.START_TAG) {
1660 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001661 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1662 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001663 if (TAG_AFFINITYINTENT.equals(name)) {
1664 affinityIntent = Intent.restoreFromXml(in);
1665 } else if (TAG_INTENT.equals(name)) {
1666 intent = Intent.restoreFromXml(in);
1667 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001668 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001669 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1670 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001671 if (activity != null) {
1672 activities.add(activity);
1673 }
1674 } else {
1675 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1676 XmlUtils.skipCurrentTag(in);
1677 }
1678 }
1679 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001680 if (!hasRootAffinity) {
1681 rootAffinity = affinity;
1682 } else if ("@".equals(rootAffinity)) {
1683 rootAffinity = null;
1684 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001685 if (effectiveUid <= 0) {
1686 Intent checkIntent = intent != null ? intent : affinityIntent;
1687 effectiveUid = 0;
1688 if (checkIntent != null) {
1689 IPackageManager pm = AppGlobals.getPackageManager();
1690 try {
1691 ApplicationInfo ai = pm.getApplicationInfo(
1692 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001693 PackageManager.MATCH_UNINSTALLED_PACKAGES
1694 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001695 if (ai != null) {
1696 effectiveUid = ai.uid;
1697 }
1698 } catch (RemoteException e) {
1699 }
1700 }
1701 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1702 + ": effectiveUid=" + effectiveUid);
1703 }
1704
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001705 if (persistTaskVersion < 1) {
1706 // We need to convert the resize mode of home activities saved before version one if
1707 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1708 // since we didn't have that differentiation before version 1 and the system didn't
1709 // resize home activities before then.
1710 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1711 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1712 }
Winson Chungd3395382016-12-13 11:49:09 -08001713 } else {
1714 // This activity has previously marked itself explicitly as both resizeable and
1715 // supporting picture-in-picture. Since there is no longer a requirement for
1716 // picture-in-picture activities to be resizeable, we can mark this simply as
1717 // resizeable and supporting picture-in-picture separately.
1718 if (resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED) {
1719 resizeMode = RESIZE_MODE_RESIZEABLE;
1720 supportsPictureInPicture = true;
1721 }
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001722 }
1723
Winson Chung36f3f032016-09-08 23:29:43 +00001724 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001725 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001726 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1727 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001728 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Winson Chungd3395382016-12-13 11:49:09 -08001729 taskAffiliationColor, callingUid, callingPackage, resizeMode,
1730 supportsPictureInPicture, privileged, realActivitySuspended, userSetupComplete,
1731 minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001732 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001733
1734 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001735 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001736 }
1737
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001738 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001739 return task;
1740 }
1741
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001742 private void adjustForMinimalTaskDimensions(Rect bounds) {
1743 if (bounds == null) {
1744 return;
1745 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001746 int minWidth = mMinWidth;
1747 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001748 // If the task has no requested minimal size, we'd like to enforce a minimal size
1749 // so that the user can not render the task too small to manipulate. We don't need
1750 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001751 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001752 if (minWidth == INVALID_MIN_SIZE) {
1753 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001754 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001755 if (minHeight == INVALID_MIN_SIZE) {
1756 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001757 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001758 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001759 final boolean adjustWidth = minWidth > bounds.width();
1760 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001761 if (!(adjustWidth || adjustHeight)) {
1762 return;
1763 }
1764
1765 if (adjustWidth) {
1766 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001767 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001768 } else {
1769 // Either left bounds match, or neither match, or the previous bounds were
1770 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001771 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001772 }
1773 }
1774 if (adjustHeight) {
1775 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001776 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001777 } else {
1778 // Either top bounds match, or neither match, or the previous bounds were
1779 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001780 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001781 }
1782 }
1783 }
1784
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001785 /**
1786 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001787 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07001788 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001789 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001790 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001791 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1792 }
1793
1794 /**
1795 * Update task's override configuration based on the bounds.
1796 * @param bounds The bounds of the task.
1797 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1798 * subtract the navigation bar/status bar size from the screen size reported
1799 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07001800 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001801 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001802 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001803 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07001804 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001805 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001806 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08001807 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07001808 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001809
1810 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001811 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001812 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001813 mLastNonFullscreenBounds = mBounds;
1814 }
1815 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07001816 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07001817 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001818 mTmpRect.set(bounds);
1819 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001820 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001821 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001822 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001823 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001824 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001825 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001826 mLastNonFullscreenBounds = mBounds;
1827 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001828 calculateOverrideConfig(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07001829 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001830 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001831 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001832
1833 if (mFullscreen != oldFullscreen) {
Andrii Kulian933076d2016-03-29 17:04:42 -07001834 mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001835 }
1836
Andrii Kulian1779e612016-10-12 21:58:25 -07001837 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001838 }
1839
Andrii Kuliandaea3572016-04-08 13:20:51 -07001840 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds,
1841 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001842 mTmpRect2.set(inInsetBounds);
1843 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1844 int leftInset = mTmpRect2.left - inInsetBounds.left;
1845 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001846 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1847 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001848 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1849 }
1850
Andrii Kuliandaea3572016-04-08 13:20:51 -07001851 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds,
1852 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001853 mTmpRect2.set(inInsetBounds);
1854 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1855 int leftInset = mTmpRect2.left - inInsetBounds.left;
1856 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001857 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1858 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi0a932142016-02-01 17:42:25 -08001859 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1860 }
1861
Andrii Kulian1779e612016-10-12 21:58:25 -07001862 /** Clears passed config and fills it with new override values. */
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07001863 private void calculateOverrideConfig(Configuration config, Rect bounds, Rect insetBounds,
1864 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001865 mTmpNonDecorBounds.set(bounds);
1866 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001867
Andrii Kulian1779e612016-10-12 21:58:25 -07001868 final Configuration parentConfig = getParent().getConfiguration();
1869 config.unset();
1870 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Yorke Leef54f9da2017-01-10 07:58:59 -08001871 final boolean isFloatingTask = mStack != null && StackId.tasksAreFloating(mStack.mStackId);
1872 if (isFloatingTask) {
1873 // Floating tasks should not be resized to the screen's bounds.
1874 config.screenWidthDp = (int) (mTmpStableBounds.width() / density);
1875 config.screenHeightDp = (int) (mTmpStableBounds.height() / density);
1876 } else {
1877 // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
1878 // i.e. the screen area without the system bars.
1879 // Additionally task dimensions should not be bigger than its parents dimensions.
1880 subtractNonDecorInsets(mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds,
1881 overrideWidth, overrideHeight);
1882 subtractStableInsets(mTmpStableBounds, insetBounds != null ? insetBounds : bounds,
1883 overrideWidth, overrideHeight);
1884 config.screenWidthDp = Math.min(
1885 (int) (mTmpStableBounds.width() / density), parentConfig.screenWidthDp);
1886 config.screenHeightDp = Math.min(
1887 (int) (mTmpStableBounds.height() / density), parentConfig.screenHeightDp);
1888 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001889
1890 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001891 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1892 ? Configuration.ORIENTATION_PORTRAIT
1893 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001894
Jorim Jaggi85639432016-05-06 17:27:55 -07001895 // For calculating screen layout, we need to use the non-decor inset screen area for the
1896 // calculation for compatibility reasons, i.e. screen area without system bars that could
1897 // never go away in Honeycomb.
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001898 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1899 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07001900 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
1901 // calculation with partial default.
1902 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001903 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07001904 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07001905 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
1906
1907 config.smallestScreenWidthDp = mService.mWindowManager.getSmallestWidthForTaskBounds(
1908 insetBounds != null ? insetBounds : bounds);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001909 }
1910
1911 /**
1912 * Using the existing configuration {@param config}, creates a new task override config such
1913 * that all the fields that are usually set in an override config are set to the ones in
1914 * {@param config}.
1915 */
1916 Configuration extractOverrideConfig(Configuration config) {
Andrii Kulian1779e612016-10-12 21:58:25 -07001917 final Configuration extracted = new Configuration();
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001918 extracted.screenWidthDp = config.screenWidthDp;
1919 extracted.screenHeightDp = config.screenHeightDp;
1920 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1921 extracted.orientation = config.orientation;
Andrii Kulian1779e612016-10-12 21:58:25 -07001922 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout.
1923 extracted.screenLayout = config.screenLayout & (Configuration.SCREENLAYOUT_LONG_MASK
1924 | Configuration.SCREENLAYOUT_SIZE_MASK | Configuration.SCREENLAYOUT_COMPAT_NEEDED);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001925 return extracted;
1926 }
1927
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001928 Rect updateOverrideConfigurationFromLaunchBounds() {
1929 final Rect bounds = validateBounds(getLaunchBounds());
1930 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07001931 if (bounds != null) {
1932 bounds.set(mBounds);
1933 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001934 return bounds;
1935 }
1936
1937 static Rect validateBounds(Rect bounds) {
1938 if (bounds != null && bounds.isEmpty()) {
1939 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1940 return null;
1941 }
1942 return bounds;
1943 }
1944
Wale Ogunwale935e5022015-11-10 12:36:10 -08001945 /** Updates the task's bounds and override configuration to match what is expected for the
1946 * input stack. */
1947 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001948 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001949 return;
1950 }
1951
1952 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001953 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001954 throw new IllegalArgumentException("Can not position non-resizeable task="
1955 + this + " in stack=" + inStack);
1956 }
1957 if (mBounds != null) {
1958 return;
1959 }
1960 if (mLastNonFullscreenBounds != null) {
1961 updateOverrideConfiguration(mLastNonFullscreenBounds);
1962 } else {
1963 inStack.layoutTaskInStack(this, null);
1964 }
1965 } else {
1966 updateOverrideConfiguration(inStack.mBounds);
1967 }
1968 }
1969
Chong Zhang0fa656b2015-08-31 15:17:21 -07001970 /**
1971 * Returns the correct stack to use based on task type and currently set bounds,
1972 * regardless of the focused stack and current stack association of the task.
1973 * The task will be moved (and stack focus changed) later if necessary.
1974 */
1975 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001976 if (isRecentsTask()) {
1977 return RECENTS_STACK_ID;
1978 }
1979 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001980 return HOME_STACK_ID;
1981 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001982 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001983 return FREEFORM_WORKSPACE_STACK_ID;
1984 }
1985 return FULLSCREEN_WORKSPACE_STACK_ID;
1986 }
1987
1988 /** Returns the bounds that should be used to launch this task. */
1989 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001990 // If we're over lockscreen, forget about stack bounds and use fullscreen.
Jorim Jaggife762342016-10-13 14:33:27 +02001991 if (mService.mStackSupervisor.mKeyguardController.isKeyguardShowing()) {
Chong Zhang75b37202015-12-04 14:16:36 -08001992 return null;
1993 }
1994
Andrii Kulian02b7a832016-10-06 23:11:56 -07001995 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08001996 return null;
1997 }
1998
Andrii Kulian02b7a832016-10-06 23:11:56 -07001999 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08002000 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002001 || stackId == RECENTS_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08002002 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002003 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002004 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07002005 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002006 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002007 }
2008 return mLastNonFullscreenBounds;
2009 }
2010
Wale Ogunwale39381972015-12-17 17:15:29 -08002011 boolean canMatchRootAffinity() {
2012 // We don't allow root affinity matching on the pinned stack as no other task should
2013 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07002014 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08002015 }
2016
Jorim Jaggi8b702ed2017-01-20 16:59:03 +01002017 void addStartingWindowsForVisibleActivities(boolean taskSwitch) {
2018 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
2019 final ActivityRecord r = mActivities.get(activityNdx);
2020 if (r.visible) {
2021 r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch);
2022 }
2023 }
2024 }
2025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002027 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07002028 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
2029 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08002030 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002031 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07002032 if (affinity != null || rootAffinity != null) {
2033 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
2034 if (affinity == null || !affinity.equals(rootAffinity)) {
2035 pw.print(" root="); pw.println(rootAffinity);
2036 } else {
2037 pw.println();
2038 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002039 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07002040 if (voiceSession != null || voiceInteractor != null) {
2041 pw.print(prefix); pw.print("VOICE: session=0x");
2042 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
2043 pw.print(" interactor=0x");
2044 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
2045 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002046 if (intent != null) {
2047 StringBuilder sb = new StringBuilder(128);
2048 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002049 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002050 sb.append('}');
2051 pw.println(sb.toString());
2052 }
2053 if (affinityIntent != null) {
2054 StringBuilder sb = new StringBuilder(128);
2055 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002056 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002057 sb.append('}');
2058 pw.println(sb.toString());
2059 }
2060 if (origActivity != null) {
2061 pw.print(prefix); pw.print("origActivity=");
2062 pw.println(origActivity.flattenToShortString());
2063 }
2064 if (realActivity != null) {
2065 pw.print(prefix); pw.print("realActivity=");
2066 pw.println(realActivity.flattenToShortString());
2067 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07002068 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
2069 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002070 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002071 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002072 pw.print(" numFullscreen="); pw.print(numFullscreen);
2073 pw.print(" taskType="); pw.print(taskType);
2074 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
2075 }
Craig Mautner432f64e2015-05-20 14:59:57 -07002076 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
2077 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002078 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
2079 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07002080 pw.print(" mReuseTask="); pw.print(mReuseTask);
2081 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002082 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08002083 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
2084 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
2085 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07002086 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
2087 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
2088 pw.print(" (");
2089 if (mPrevAffiliate == null) {
2090 pw.print("null");
2091 } else {
2092 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
2093 }
2094 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
2095 pw.print(" (");
2096 if (mNextAffiliate == null) {
2097 pw.print("null");
2098 } else {
2099 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2100 }
2101 pw.println(")");
2102 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002103 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002104 if (!askedCompatMode || !inRecents || !isAvailable) {
2105 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2106 pw.print(" inRecents="); pw.print(inRecents);
2107 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002108 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002109 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002110 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2111 if (lastDescription != null) {
2112 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2113 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002114 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002115 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2116 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08002117 pw.print(" mSupportsPictureInPicture=" + mSupportsPictureInPicture);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002118 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00002119 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002120 pw.print(" lastActiveTime=" + lastActiveTime);
2121 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 }
2123
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002124 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002126 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002127 if (stringName != null) {
2128 sb.append(stringName);
2129 sb.append(" U=");
2130 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002131 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002132 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002133 sb.append(" sz=");
2134 sb.append(mActivities.size());
2135 sb.append('}');
2136 return sb.toString();
2137 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002138 sb.append("TaskRecord{");
2139 sb.append(Integer.toHexString(System.identityHashCode(this)));
2140 sb.append(" #");
2141 sb.append(taskId);
2142 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002143 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002144 sb.append(affinity);
2145 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002146 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002147 sb.append(intent.getComponent().flattenToShortString());
2148 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002149 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002150 sb.append(affinityIntent.getComponent().flattenToShortString());
2151 } else {
2152 sb.append(" ??");
2153 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002154 stringName = sb.toString();
2155 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002156 }
2157}