blob: 4e44c5f042f10ed2abcd199f2537f20f43e08bf5 [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;
Wale Ogunwaleff3c66c2015-11-18 19:22:49 -080024import android.app.ActivityManager.TaskThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -080025import android.app.ActivityManager.TaskThumbnailInfo;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070026import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070027import android.app.AppGlobals;
Jorim Jaggi0a932142016-02-01 17:42:25 -080028import android.app.IActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.ComponentName;
30import android.content.Intent;
31import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070032import android.content.pm.ApplicationInfo;
33import android.content.pm.IPackageManager;
34import android.content.pm.PackageManager;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070035import android.content.res.Configuration;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070036import android.graphics.Bitmap;
Jorim Jaggi02886a82016-12-06 09:10:06 -080037import android.graphics.GraphicBuffer;
Winsonc809cbb2015-11-02 12:06:15 -080038import android.graphics.Point;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070039import android.graphics.Rect;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070040import android.os.Debug;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070041import android.os.ParcelFileDescriptor;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070042import android.os.RemoteException;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080043import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070044import android.os.UserHandle;
Suprabh Shukla7745c142016-03-07 18:21:10 -080045import android.provider.Settings;
Dianne Hackborn91097de2014-04-04 18:02:06 -070046import android.service.voice.IVoiceInteractionSession;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070047import android.util.DisplayMetrics;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070048import android.util.Slog;
Suprabh Shukla23593142015-11-03 17:31:15 -080049
Dianne Hackborn91097de2014-04-04 18:02:06 -070050import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070051import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080052
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080053import com.android.server.wm.TaskWindowContainerController;
Craig Mautner21d24a22014-04-23 11:45:37 -070054import org.xmlpull.v1.XmlPullParser;
55import org.xmlpull.v1.XmlPullParserException;
56import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Craig Mautnerc0ffce52014-07-01 12:38:52 -070058import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070059import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080061import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070062import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080064import static android.app.ActivityManager.RESIZE_MODE_FORCED;
Jorim Jaggi0a932142016-02-01 17:42:25 -080065import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
66import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
67import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
68import static android.app.ActivityManager.StackId.HOME_STACK_ID;
69import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
70import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080071import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080072import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
73import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070074import static android.content.pm.ActivityInfo.FLAG_ON_TOP_LAUNCHER;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070075import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
Jorim Jaggi0a932142016-02-01 17:42:25 -080076import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
77import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
78import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
79import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
skuhne@google.com322347b2016-12-02 12:54:03 -080080import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
81import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
82import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Wale Ogunwaled829d362016-02-10 19:24:49 -080083import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070084import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
85import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggi0a932142016-02-01 17:42:25 -080086import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080087import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Suprabh Shukla7745c142016-03-07 18:21:10 -080088import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080089import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
90import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
91import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
92import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
93import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
94import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
95import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
96import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
97import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
98import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Jorim Jaggi0a932142016-02-01 17:42:25 -080099import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
100import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
101import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700102import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800103import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800104
Andrii Kulian1779e612016-10-12 21:58:25 -0700105final class TaskRecord extends ConfigurationContainer {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800106 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700107 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700108 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -0700109 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700110 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800111
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700112 private static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700113 private static final String TAG_INTENT = "intent";
114 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700115 private static final String ATTR_REALACTIVITY = "real_activity";
116 private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700117 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700118 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700119 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700120 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700121 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700122 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700123 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
124 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800125 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700126 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700127 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700128 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700129 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700130 private static final String ATTR_LASTDESCRIPTION = "last_description";
131 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700132 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700133 private static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700134 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
135 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700136 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700137 private static final String ATTR_CALLING_UID = "calling_uid";
138 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800139 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700140 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700141 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700142 private static final String ATTR_MIN_WIDTH = "min_width";
143 private static final String ATTR_MIN_HEIGHT = "min_height";
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700144 private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
Andrii Kulian18d75122016-03-27 20:20:28 -0700145
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700146 // Current version of the task record we persist. Used to check if we need to run any upgrade
147 // code.
148 private static final int PERSIST_TASK_VERSION = 1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700149 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
150
Wale Ogunwale18795a22014-12-03 11:38:33 -0800151 static final int INVALID_TASK_ID = -1;
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700152 private static final int INVALID_MIN_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700155 String affinity; // The affinity name for this task, or null; may change identity.
156 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700157 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
158 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 Intent intent; // The original intent that started the task.
160 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700161 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 ComponentName origActivity; // The non-alias activity component of the intent.
163 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000164 boolean realActivitySuspended; // True if the actual activity component that started the
165 // task is suspended.
Winson Chung36f3f032016-09-08 23:29:43 +0000166 long firstActiveTime; // First time this task was active.
167 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700168 boolean inRecents; // Actually in the recents list?
169 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 boolean rootWasReset; // True if the intent at the root of the task had
171 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700172 boolean autoRemoveRecents; // If true, we should automatically remove the task from
173 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700174 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700175 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 -0800176
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700177 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700178 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800179 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
180 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800181
182 int numFullscreen; // Number of fullscreen activities.
183
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800184 int mResizeMode; // The resize mode of this task and its activities.
185 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800186 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
187 // changes on a temporary basis.
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700188 private int mLockTaskMode; // Which tasklock mode to launch this task in. One of
189 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700190 private boolean mPrivileged; // The root activity application of this task holds
191 // privileged permissions.
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700192 private boolean mIsOnTopLauncher; // Whether this task is an on-top launcher. See
193 // android.R.attr#onTopLauncher.
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700194
Craig Mautner15df08a2015-04-01 12:17:18 -0700195 /** Can't be put in lockTask mode. */
196 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100197 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700198 final static int LOCK_TASK_AUTH_PINNABLE = 1;
199 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
200 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100201 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700202 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100203 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
204 * lockTask task. */
205 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700206 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
207
208 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800209
Winson Chung03a9bae2014-05-02 09:56:12 -0700210 // This represents the last resolved activity values for this task
211 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700212 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700213
Craig Mautnerd2328952013-03-05 12:46:26 -0800214 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700215 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800216
Andrii Kulian02b7a832016-10-06 23:11:56 -0700217 /** Current stack. Setter must always be used to update the value. */
218 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800219
Craig Mautner2c1faed2013-07-23 12:56:02 -0700220 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700221 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700222
Craig Mautner21d24a22014-04-23 11:45:37 -0700223 /** Takes on same value as first root activity */
224 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700225 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700226
227 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
228 * determining the order when restoring. Sign indicates whether last task movement was to front
229 * (positive) or back (negative). Absolute value indicates time. */
230 long mLastTimeMoved = System.currentTimeMillis();
231
Craig Mautner84984fa2014-06-19 11:19:20 -0700232 /** Indication of what to run next when task exits. Use ActivityRecord types.
233 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
234 * task stack. */
235 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700236
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700237 /** If original intent did not allow relinquishing task identity, save that information */
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700238 private boolean mNeverRelinquishIdentity = true;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700239
Craig Mautner362449a2014-06-20 14:04:39 -0700240 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
241 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800242 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700243
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700244 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700245 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700246 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800247 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700248 CharSequence lastDescription; // Last description captured for this item.
249
Craig Mautnera228ae92014-07-09 05:44:55 -0700250 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700251 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700252 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800253 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700254 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800255 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700256
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700257 // For relaunching the task from recents as though it was launched by the original launcher.
258 int mCallingUid;
259 String mCallingPackage;
260
Craig Mautner21d24a22014-04-23 11:45:37 -0700261 final ActivityManagerService mService;
262
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700263 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
264 boolean mFullscreen = true;
265
266 // Bounds of the Task. null for fullscreen tasks.
267 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800268 private final Rect mTmpStableBounds = new Rect();
269 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800270 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800271 private final Rect mTmpRect2 = new Rect();
272
Wale Ogunwale706ed792015-08-02 10:29:44 -0700273 // Last non-fullscreen bounds the task was launched in or resized to.
274 // The information is persisted and used to determine the appropriate stack to launch the
275 // task into on restore.
276 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700277 // Minimal width and height of this task when it's resizeable. -1 means it should use the
278 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700279 int mMinWidth;
280 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700281
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700282 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
283 // This number will be assigned when we evaluate OOM scores for all visible tasks.
284 int mLayerRank = -1;
285
Andrii Kulian1779e612016-10-12 21:58:25 -0700286 /** Helper object used for updating override configuration. */
287 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700288
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800289 private TaskWindowContainerController mWindowContainerController;
290
Craig Mautner21d24a22014-04-23 11:45:37 -0700291 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Wale Ogunwale72919d22016-12-08 18:58:50 -0800292 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, int type) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700293 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700294 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
295 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800296 userId = UserHandle.getUserId(info.applicationInfo.uid);
297 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800298 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700300 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700301 voiceSession = _voiceSession;
302 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700303 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800304 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700305 mCallingUid = info.applicationInfo.uid;
306 mCallingPackage = info.packageName;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800307 taskType = type;
Martijn Coenend4a69702014-06-30 11:12:17 -0700308 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700309 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700310 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700311 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Craig Mautner21d24a22014-04-23 11:45:37 -0700312 }
313
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700314 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800315 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700316 mService = service;
317 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
318 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800319 userId = UserHandle.getUserId(info.applicationInfo.uid);
320 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800321 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700322 taskId = _taskId;
323 mAffiliatedTaskId = _taskId;
324 voiceSession = null;
325 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700326 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800327 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700328 mCallingUid = info.applicationInfo.uid;
329 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700330 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700331 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700332
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700333 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700334 // Clamp to [1, max].
335 maxRecents = Math.min(Math.max(info.maxRecents, 1),
336 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700337
338 taskType = APPLICATION_ACTIVITY_TYPE;
339 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700340 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700341 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700342 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700343 }
344
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800345 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
346 Intent _affinityIntent, String _affinity, String _rootAffinity,
347 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
348 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
349 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
350 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
351 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800352 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
353 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800354 int resizeMode, boolean privileged, boolean _realActivitySuspended,
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700355 boolean userSetupComplete, int minWidth, int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700356 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700357 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
358 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800359 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800360 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700361 taskId = _taskId;
362 intent = _intent;
363 affinityIntent = _affinityIntent;
364 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800365 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700366 voiceSession = null;
367 voiceInteractor = null;
368 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800369 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700370 origActivity = _origActivity;
371 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700372 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700373 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700374 askedCompatMode = _askedCompatMode;
375 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700376 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700377 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800378 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700379 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700380 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700381 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700382 lastDescription = _lastDescription;
383 mActivities = activities;
384 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700385 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700386 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700387 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700388 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700389 mPrevAffiliateTaskId = prevTaskId;
390 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700391 mCallingUid = callingUid;
392 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800393 mResizeMode = resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700394 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700395 mMinWidth = minWidth;
396 mMinHeight = minHeight;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700397 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 }
399
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800400 TaskWindowContainerController getWindowContainerController() {
401 return mWindowContainerController;
402 }
403
404 void createWindowContainer(boolean onTop, boolean showForAllUsers) {
405 if (mWindowContainerController != null) {
406 throw new IllegalArgumentException("Window container=" + mWindowContainerController
407 + " already created for task=" + this);
408 }
409
410 final Rect bounds = updateOverrideConfigurationFromLaunchBounds();
411 final Configuration overrideConfig = getOverrideConfiguration();
412 mWindowContainerController = new TaskWindowContainerController(taskId, getStackId(), userId,
413 bounds, overrideConfig, mResizeMode, isHomeTask(), isOnTopLauncher(), onTop,
414 showForAllUsers);
415 }
416
417 void removeWindowContainer() {
418 mService.mStackSupervisor.removeLockedTaskLocked(this);
419 mWindowContainerController.removeContainer();
420 if (!StackId.persistTaskBounds(getStackId())) {
421 // Reset current bounds for task whose bounds shouldn't be persisted so it uses
422 // default configuration the next time it launches.
423 updateOverrideConfiguration(null);
424 }
425 mService.mTaskChangeNotificationController.notifyTaskRemoved(taskId);
426 mWindowContainerController = null;
427 }
428
429 void setResizeMode(int resizeMode) {
430 if (mResizeMode == resizeMode) {
431 return;
432 }
433 mResizeMode = resizeMode;
434 mWindowContainerController.setResizeable(resizeMode);
435 mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
436 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
437 }
438
439 void setTaskDockedResizing(boolean resizing) {
440 mWindowContainerController.setTaskDockedResizing(resizing);
441 }
442
443 boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
444 if (!isResizeable()) {
445 Slog.w(TAG, "resizeTask: task " + this + " not resizeable.");
446 return true;
447 }
448
449 // If this is a forced resize, let it go through even if the bounds is not changing,
450 // as we might need a relayout due to surface size change (to/from fullscreen).
451 final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
452 if (Objects.equals(mBounds, bounds) && !forced) {
453 // Nothing to do here...
454 return true;
455 }
456 bounds = validateBounds(bounds);
457
458 if (mWindowContainerController == null) {
459 // Task doesn't exist in window manager yet (e.g. was restored from recents).
460 // All we can do for now is update the bounds so it can be used when the task is
461 // added to window manager.
462 updateOverrideConfiguration(bounds);
463 if (getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
464 // re-restore the task so it can have the proper stack association.
465 mService.mStackSupervisor.restoreRecentTaskLocked(this,
466 FREEFORM_WORKSPACE_STACK_ID);
467 }
468 return true;
469 }
470
471 if (!canResizeToBounds(bounds)) {
472 throw new IllegalArgumentException("resizeTask: Can not resize task=" + this
473 + " to bounds=" + bounds + " resizeMode=" + mResizeMode);
474 }
475
476 // Do not move the task to another stack here.
477 // This method assumes that the task is already placed in the right stack.
478 // we do not mess with that decision and we only do the resize!
479
480 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId);
481
482 final boolean updatedConfig = updateOverrideConfiguration(bounds);
483 // This variable holds information whether the configuration didn't change in a significant
484 // way and the activity was kept the way it was. If it's false, it means the activity had
485 // to be relaunched due to configuration change.
486 boolean kept = true;
487 if (updatedConfig) {
488 final ActivityRecord r = topRunningActivityLocked();
489 if (r != null) {
490 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
491
492 if (!deferResume) {
493 // All other activities must be made visible with their correct configuration.
494 mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
495 if (!kept) {
496 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
497 }
498 }
499 }
500 }
501 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), kept, forced);
502
503 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
504 return kept;
505 }
506
507 // TODO: Investigate combining with the resize() method above.
508 void resizeWindowContainer() {
509 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), false /* relayout */,
510 false /* forced */);
511 }
512
513 // TODO: Remove once we have a stack controller.
514 void positionWindowContainerAt(int stackId, int index) {
515 mWindowContainerController.positionAt(stackId, index, mBounds, getOverrideConfiguration());
516 }
517
518 // TODO: Replace with moveChildToTop?
519 void moveWindowContainerToTop(boolean includingParents) {
520 if (mWindowContainerController != null) {
521 mWindowContainerController.moveToTop(includingParents);
522 }
523 }
524
525 // TODO: Replace with moveChildToBottom?
526 void moveWindowContainerToBottom() {
527 if (mWindowContainerController != null) {
528 mWindowContainerController.moveToBottom();
529 }
530 }
531
532 void getWindowContainerBounds(Rect bounds) {
533 mWindowContainerController.getBounds(bounds);
534 }
535
536 // TODO: make this part of adding it to the stack?
537 void reparentWindowContainer(int stackId, int position) {
538 mWindowContainerController.reparent(stackId, position);
539 }
540
541 void cancelWindowTransition() {
542 mWindowContainerController.cancelWindowTransition();
543 }
544
545 void cancelThumbnailTransition() {
546 mWindowContainerController.cancelThumbnailTransition();
547 }
548
Jorim Jaggi02886a82016-12-06 09:10:06 -0800549 public GraphicBuffer getSnapshot() {
550 if (mWindowContainerController == null) {
551 return null;
552 }
553 return mWindowContainerController.getSnapshot();
554 }
555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000557 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700558 if (firstActiveTime == 0) {
559 firstActiveTime = lastActiveTime;
560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000564 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700566
Winson Chungfee26772014-08-05 12:21:52 -0700567 /** Sets the original intent, and the calling uid and package. */
568 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700569 mCallingUid = r.launchedFromUid;
570 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700571 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700572 }
573
574 /** Sets the original intent, _without_ updating the calling uid or package. */
575 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700576 if (intent == null) {
577 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700578 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700579 } else if (mNeverRelinquishIdentity) {
580 return;
581 }
582
583 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700584 if (intent == null) {
585 // If this task already has an intent associated with it, don't set the root
586 // affinity -- we don't want it changing after initially set, but the initially
587 // set value may be null.
588 rootAffinity = affinity;
589 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700590 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700591 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800594 if (_intent != null) {
595 // If this Intent has a selector, we want to clear it for the
596 // recent task since it is not relevant if the user later wants
597 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700598 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800599 _intent = new Intent(_intent);
600 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700601 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800602 }
603 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700604 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 intent = _intent;
606 realActivity = _intent != null ? _intent.getComponent() : null;
607 origActivity = null;
608 } else {
609 ComponentName targetComponent = new ComponentName(
610 info.packageName, info.targetActivity);
611 if (_intent != null) {
612 Intent targetIntent = new Intent(_intent);
613 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800614 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700615 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700616 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700617 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 intent = targetIntent;
619 realActivity = targetComponent;
620 origActivity = _intent.getComponent();
621 } else {
622 intent = null;
623 realActivity = targetComponent;
624 origActivity = new ComponentName(info.packageName, info.name);
625 }
626 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700627
Craig Mautner47b20ba2014-09-17 17:23:44 -0700628 final int intentFlags = intent == null ? 0 : intent.getFlags();
629 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 // Once we are set to an Intent with this flag, we count this
631 // task as having a true root activity.
632 rootWasReset = true;
633 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700634 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000635 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
636 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700637 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700638 // If the activity itself has requested auto-remove, then just always do it.
639 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700640 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
641 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700642 // If the caller has not asked for the document to be retained, then we may
643 // want to turn on auto-remove, depending on whether the target has set its
644 // own document launch mode.
645 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
646 autoRemoveRecents = false;
647 } else {
648 autoRemoveRecents = true;
649 }
650 } else {
651 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700652 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800653 mResizeMode = info.resizeMode;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700654 mIsOnTopLauncher = (info.flags & FLAG_ON_TOP_LAUNCHER) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700655 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700656 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700657 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800659
Andrii Kulian2e751b82016-03-16 16:59:32 -0700660 /** Sets the original minimal width and height. */
661 private void setMinDimensions(ActivityInfo info) {
662 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700663 mMinWidth = info.windowLayout.minWidth;
664 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700665 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700666 mMinWidth = INVALID_MIN_SIZE;
667 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700668 }
669 }
670
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800671 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700672 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800673 * record is based on (normally the root activity intent).
674 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700675 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800676 final Intent intent = new Intent(r.intent);
677 // Correct the activity intent for aliasing. The task record intent will always be based on
678 // the real activity that will be launched not the alias, so we need to use an intent with
679 // the component name pointing to the real activity not the alias in the activity record.
680 intent.setComponent(r.realActivity);
681 return this.intent.filterEquals(intent);
682 }
683
Craig Mautner84984fa2014-06-19 11:19:20 -0700684 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800685 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
686 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700687 }
688
689 int getTaskToReturnTo() {
690 return mTaskToReturnTo;
691 }
692
Craig Mautnera228ae92014-07-09 05:44:55 -0700693 void setPrevAffiliate(TaskRecord prevAffiliate) {
694 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800695 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700696 }
697
698 void setNextAffiliate(TaskRecord nextAffiliate) {
699 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800700 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700701 }
702
Andrii Kulian02b7a832016-10-06 23:11:56 -0700703 ActivityStack getStack() {
704 return mStack;
705 }
706
Andrii Kulian1779e612016-10-12 21:58:25 -0700707 /** Must be used for setting parent stack because it performs configuration updates. */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700708 void setStack(ActivityStack stack) {
709 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700710 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700711 }
712
713 /**
714 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
715 */
716 int getStackId() {
717 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
718 }
719
Andrii Kulian1779e612016-10-12 21:58:25 -0700720 @Override
721 protected int getChildCount() {
722 return 0;
723 }
724
725 @Override
726 protected ConfigurationContainer getChildAt(int index) {
727 return null;
728 }
729
730 @Override
731 protected ConfigurationContainer getParent() {
732 return mStack;
733 }
734
Craig Mautnera228ae92014-07-09 05:44:55 -0700735 // Close up recents linked list.
736 void closeRecentsChain() {
737 if (mPrevAffiliate != null) {
738 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
739 }
740 if (mNextAffiliate != null) {
741 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
742 }
743 setPrevAffiliate(null);
744 setNextAffiliate(null);
745 }
746
Winson Chung740c3ac2014-11-12 16:14:38 -0800747 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700748 disposeThumbnail();
749 closeRecentsChain();
750 if (inRecents) {
751 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800752 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700753 }
754 }
755
Craig Mautnera228ae92014-07-09 05:44:55 -0700756 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
757 closeRecentsChain();
758 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700759 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700760 // Find the end
761 while (taskToAffiliateWith.mNextAffiliate != null) {
762 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
763 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
764 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
765 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
766 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
767 nextRecents.setPrevAffiliate(null);
768 }
769 taskToAffiliateWith.setNextAffiliate(null);
770 break;
771 }
772 taskToAffiliateWith = nextRecents;
773 }
774 taskToAffiliateWith.setNextAffiliate(this);
775 setPrevAffiliate(taskToAffiliateWith);
776 setNextAffiliate(null);
777 }
778
Winson Chung096f36b2014-08-20 15:39:01 -0700779 /**
Winsonc809cbb2015-11-02 12:06:15 -0800780 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700781 * @return whether the thumbnail was set
782 */
Winsonc809cbb2015-11-02 12:06:15 -0800783 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -0800784 int taskWidth = 0;
785 int taskHeight = 0;
786 if (mBounds != null) {
787 // Non-fullscreen tasks
788 taskWidth = mBounds.width();
789 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700790 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -0800791 // Fullscreen tasks
792 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700793 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -0800794 taskWidth = displaySize.x;
795 taskHeight = displaySize.y;
796 } else {
797 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
798 }
Andrii Kulian1779e612016-10-12 21:58:25 -0700799 // We need to provide the current orientation of the display on which this task resides,
800 // not the orientation of the task.
801 final int orientation =
802 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
803 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -0800804 }
805
806 /**
807 * Sets the last thumbnail with the current task bounds.
808 * @return whether the thumbnail was set
809 */
810 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
811 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700812 if (mLastThumbnail != thumbnail) {
813 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800814 mLastThumbnailInfo.taskWidth = taskWidth;
815 mLastThumbnailInfo.taskHeight = taskHeight;
816 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700817 if (thumbnail == null) {
818 if (mLastThumbnailFile != null) {
819 mLastThumbnailFile.delete();
820 }
821 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800822 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700823 }
Winson Chung096f36b2014-08-20 15:39:01 -0700824 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700825 }
Winson Chung096f36b2014-08-20 15:39:01 -0700826 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700827 }
828
829 void getLastThumbnail(TaskThumbnail thumbs) {
830 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800831 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700832 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700833 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800834 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800835 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700836 }
Winson Chung096f36b2014-08-20 15:39:01 -0700837 // Only load the thumbnail file if we don't have a thumbnail
838 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700839 try {
840 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
841 ParcelFileDescriptor.MODE_READ_ONLY);
842 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700843 }
844 }
845 }
846
Winsonc809cbb2015-11-02 12:06:15 -0800847 /**
848 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
849 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700850 void freeLastThumbnail() {
851 mLastThumbnail = null;
852 }
853
Winsonc809cbb2015-11-02 12:06:15 -0800854 /**
855 * Removes all associated thumbnail data when a task is removed or pruned from recents.
856 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700857 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800858 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700859 mLastThumbnail = null;
860 lastDescription = null;
861 }
862
Winson Chung1147c402014-05-14 11:05:00 -0700863 /** Returns the intent for the root activity for this task */
864 Intent getBaseIntent() {
865 return intent != null ? intent : affinityIntent;
866 }
867
Winson Chung3b3f4642014-04-22 10:08:18 -0700868 /** Returns the first non-finishing activity from the root. */
869 ActivityRecord getRootActivity() {
870 for (int i = 0; i < mActivities.size(); i++) {
871 final ActivityRecord r = mActivities.get(i);
872 if (r.finishing) {
873 continue;
874 }
875 return r;
876 }
877 return null;
878 }
879
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800880 ActivityRecord getTopActivity() {
881 for (int i = mActivities.size() - 1; i >= 0; --i) {
882 final ActivityRecord r = mActivities.get(i);
883 if (r.finishing) {
884 continue;
885 }
886 return r;
887 }
888 return null;
889 }
890
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700891 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700892 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700893 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
894 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -0700895 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700896 return r;
897 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700898 }
899 }
900 return null;
901 }
902
Wale Ogunwale3b232392016-05-13 15:37:13 -0700903 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700904 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700905 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
906 ActivityRecord r = mActivities.get(activityNdx);
907 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -0700908 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700909 continue;
910 }
911 return r;
912 }
913 }
914 return null;
915 }
916
Chong Zhang87761972016-08-22 13:53:24 -0700917 boolean okToShowLocked() {
918 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
919 // okay to show the activity when locked.
920 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
921 || topRunningActivityLocked() != null;
922 }
923
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800924 void setFrontOfTask() {
925 setFrontOfTask(null);
926 }
927
Craig Mautner3b475fe2013-12-16 15:58:31 -0800928 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800929 void setFrontOfTask(ActivityRecord newTop) {
930 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
931 // as not front. This is needed in situations where the current front activity in the
932 // task isn't finished yet and we want to set the front to the activity moved to the front
933 // of the task.
934 boolean foundFront = newTop != null ? true : false;
935
Craig Mautner3b475fe2013-12-16 15:58:31 -0800936 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800937 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800938 final ActivityRecord r = mActivities.get(activityNdx);
939 if (foundFront || r.finishing) {
940 r.frontOfTask = false;
941 } else {
942 r.frontOfTask = true;
943 // Set frontOfTask false for every following activity.
944 foundFront = true;
945 }
946 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000947 if (!foundFront && numActivities > 0) {
948 // All activities of this task are finishing. As we ought to have a frontOfTask
949 // activity, make the bottom activity front.
950 mActivities.get(0).frontOfTask = true;
951 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800952 if (newTop != null) {
953 newTop.frontOfTask = true;
954 }
Craig Mautner3b475fe2013-12-16 15:58:31 -0800955 }
956
Craig Mautnerde4ef022013-04-07 19:01:33 -0700957 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800958 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700959 */
960 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700961 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
962 "Removing and adding activity " + newTop
963 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -0700964
Craig Mautnerde4ef022013-04-07 19:01:33 -0700965 mActivities.remove(newTop);
966 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700967 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -0800968
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800969 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700970 }
971
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800972 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800973 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800974 }
975
976 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700977 addActivityAtIndex(mActivities.size(), r);
978 }
979
980 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700981 // 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 -0800982 if (!mActivities.remove(r) && r.fullscreen) {
983 // Was not previously in list.
984 numFullscreen++;
985 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700986 // Only set this based on the first activity
987 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700988 taskType = r.mActivityType;
989 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700990 mCallingUid = r.launchedFromUid;
991 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700992 // Clamp to [1, max].
993 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
994 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -0700995 } else {
996 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -0700997 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -0700998 }
Wale Ogunwale3b232392016-05-13 15:37:13 -0700999
1000 final int size = mActivities.size();
1001
1002 if (index == size && size > 0) {
1003 final ActivityRecord top = mActivities.get(size - 1);
1004 if (top.mTaskOverlay) {
1005 // Place below the task overlay activity since the overlay activity should always
1006 // be on top.
1007 index--;
1008 }
1009 }
1010
Craig Mautner77878772013-03-04 19:46:24 -08001011 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001012 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001013 if (r.isPersistable()) {
1014 mService.notifyTaskPersisterLocked(this, false);
1015 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001016
1017 // Sync. with window manager
1018 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001019 mWindowContainerController.positionChildAt(r.getWindowContainerController(), index);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001020 r.onOverrideConfigurationSent();
Craig Mautner77878772013-03-04 19:46:24 -08001021 }
1022
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001023 /** @return true if this was the last activity in the task */
1024 boolean removeActivity(ActivityRecord r) {
1025 if (mActivities.remove(r) && r.fullscreen) {
1026 // Was previously in list.
1027 numFullscreen--;
1028 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001029 if (r.isPersistable()) {
1030 mService.notifyTaskPersisterLocked(this, false);
1031 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001032
Andrii Kulian02b7a832016-10-06 23:11:56 -07001033 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001034 // We normally notify listeners of task stack changes on pause, however pinned stack
1035 // activities are normally in the paused state so no notification will be sent there
1036 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001037 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001038 }
1039
Craig Mautner41326202014-06-20 14:38:21 -07001040 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001041 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001042 }
1043 updateEffectiveIntent();
1044 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001045 }
1046
Craig Mautner41db4a72014-05-07 17:20:56 -07001047 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001048 // We will automatically remove the task either if it has explicitly asked for
1049 // this, or it is empty and has never contained an activity that got shown to
1050 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001051 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001052 }
1053
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001054 /**
1055 * Completely remove all activities associated with an existing
1056 * task starting at a specified index.
1057 */
1058 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001059 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001060 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001061 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001062 if (r.finishing) {
1063 continue;
1064 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001065 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001066 // Task was restored from persistent storage.
1067 r.takeFromHistory();
1068 mActivities.remove(activityNdx);
1069 --activityNdx;
1070 --numActivities;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001071 } else if (mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001072 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001073 --activityNdx;
1074 --numActivities;
1075 }
1076 }
1077 }
1078
1079 /**
1080 * Completely remove all activities associated with an existing task.
1081 */
1082 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001083 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001084 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -07001085 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001086 }
1087
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001088 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1089 mReuseTask = true;
1090 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1091 mReuseTask = false;
1092 return result;
1093 }
1094
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001095 /**
1096 * Perform clear operation as requested by
1097 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1098 * stack to the given task, then look for
1099 * an instance of that activity in the stack and, if found, finish all
1100 * activities on top of it and return the instance.
1101 *
1102 * @param newR Description of the new activity being started.
1103 * @return Returns the old activity that should be continued to be used,
1104 * or null if none was found.
1105 */
1106 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001107 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001108 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001109 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001110 if (r.finishing) {
1111 continue;
1112 }
1113 if (r.realActivity.equals(newR.realActivity)) {
1114 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001115 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001116
1117 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001118 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001119 if (r.finishing) {
1120 continue;
1121 }
1122 ActivityOptions opts = r.takeOptionsLocked();
1123 if (opts != null) {
1124 ret.updateOptionsLocked(opts);
1125 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001126 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001127 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001128 --activityNdx;
1129 --numActivities;
1130 }
1131 }
1132
1133 // Finally, if this is a normal launch mode (that is, not
1134 // expecting onNewIntent()), then we will finish the current
1135 // instance of the activity so a new fresh one can be started.
1136 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001137 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1138 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001139 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001140 if (mStack != null) {
1141 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001142 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1143 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001144 return null;
1145 }
1146 }
1147
1148 return ret;
1149 }
1150 }
1151
1152 return null;
1153 }
1154
Andrii Kulian21713ac2016-10-12 22:05:05 -07001155 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001156 if (mStack != null) {
1157 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Craig Mautner21d24a22014-04-23 11:45:37 -07001158 if (resumedActivity != null && resumedActivity.task == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001159 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001160 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001161 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001162 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001163 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1164 getLastThumbnail(taskThumbnail);
1165 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001166 }
1167
Andrii Kulian21713ac2016-10-12 22:05:05 -07001168 void removeTaskActivitiesLocked() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001169 // Just remove the entire task.
1170 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001171 }
1172
Craig Mautner432f64e2015-05-20 14:59:57 -07001173 String lockTaskAuthToString() {
1174 switch (mLockTaskAuth) {
1175 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1176 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1177 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1178 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001179 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001180 default: return "unknown=" + mLockTaskAuth;
1181 }
1182 }
1183
Craig Mautner15df08a2015-04-01 12:17:18 -07001184 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001185 if (!mPrivileged &&
1186 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1187 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1188 // Non-priv apps are not allowed to use always or never, fall back to default
1189 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1190 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001191 switch (mLockTaskMode) {
1192 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1193 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1194 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1195 break;
1196
1197 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001198 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001199 break;
1200
1201 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001202 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001203 break;
1204
1205 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1206 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1207 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1208 break;
1209 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001210 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1211 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001212 }
1213
1214 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001215 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1216 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001217 return false;
1218 }
1219 String[] packages = mService.mLockTaskPackages.get(userId);
1220 if (packages == null) {
1221 return false;
1222 }
1223 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001224 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001225 return true;
1226 }
1227 }
1228 return false;
1229 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001230
Craig Mautnera82aa092013-09-13 15:34:08 -07001231 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001232 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001233 }
1234
Wale Ogunwale74e26592016-02-05 11:48:37 -08001235 boolean isRecentsTask() {
1236 return taskType == RECENTS_ACTIVITY_TYPE;
1237 }
1238
Craig Mautner86d67a42013-05-14 10:34:38 -07001239 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001240 return taskType == APPLICATION_ACTIVITY_TYPE;
1241 }
1242
1243 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001244 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001245 }
1246
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001247 boolean isResizeable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001248 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode))
1249 && !mTemporarilyUnresizable;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001250 }
1251
skuhne@google.com322347b2016-12-02 12:54:03 -08001252 /**
1253 * Check that a given bounds matches the application requested orientation.
1254 *
1255 * @param bounds The bounds to be tested.
1256 * @return True if the requested bounds are okay for a resizing request.
1257 */
1258 boolean canResizeToBounds(Rect bounds) {
1259 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1260 // Note: If not on the freeform workspace, we ignore the bounds.
1261 return true;
1262 }
1263 final boolean landscape = bounds.width() > bounds.height();
1264 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1265 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1266 }
1267 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1268 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1269 }
1270
Jiaquan Hedd1e66f2016-06-15 15:15:12 -07001271 boolean isOnTopLauncher() {
1272 return isHomeTask() && mIsOnTopLauncher;
1273 }
1274
Wale Ogunwale513346d2016-01-27 10:55:01 -08001275 boolean canGoInDockedStack() {
Matthew Ng626e0cc2016-12-07 17:25:53 -08001276 return isResizeable() && mService.mSupportsSplitScreenMultiWindow &&
skuhne@google.com322347b2016-12-02 12:54:03 -08001277 !ActivityInfo.isPreserveOrientationMode(mResizeMode);
Wale Ogunwale513346d2016-01-27 10:55:01 -08001278 }
1279
Craig Mautner525f3d92013-05-07 14:01:50 -07001280 /**
1281 * Find the activity in the history stack within the given task. Returns
1282 * the index within the history at which it's found, or < 0 if not found.
1283 */
1284 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1285 final ComponentName realActivity = r.realActivity;
1286 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1287 ActivityRecord candidate = mActivities.get(activityNdx);
1288 if (candidate.finishing) {
1289 continue;
1290 }
1291 if (candidate.realActivity.equals(realActivity)) {
1292 return candidate;
1293 }
1294 }
1295 return null;
1296 }
1297
Winson Chunga449dc02014-05-16 11:15:04 -07001298 /** Updates the last task description values. */
1299 void updateTaskDescription() {
1300 // Traverse upwards looking for any break between main task activities and
1301 // utility activities.
1302 int activityNdx;
1303 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001304 final boolean relinquish = numActivities != 0 &&
1305 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001306 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001307 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001308 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001309 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001310 // This will be the top activity for determining taskDescription. Pre-inc to
1311 // overcome initial decrement below.
1312 ++activityNdx;
1313 break;
1314 }
Winson Chunga449dc02014-05-16 11:15:04 -07001315 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001316 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001317 break;
1318 }
1319 }
1320 if (activityNdx > 0) {
1321 // Traverse downwards starting below break looking for set label, icon.
1322 // Note that if there are activities in the task but none of them set the
1323 // recent activity values, then we do not fall back to the last set
1324 // values in the TaskRecord.
1325 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001326 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001327 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001328 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001329 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1330 final ActivityRecord r = mActivities.get(activityNdx);
1331 if (r.taskDescription != null) {
1332 if (label == null) {
1333 label = r.taskDescription.getLabel();
1334 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001335 if (iconFilename == null) {
1336 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001337 }
1338 if (colorPrimary == 0) {
1339 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001340 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001341 if (colorBackground == 0) {
1342 colorBackground = r.taskDescription.getBackgroundColor();
1343 }
Winson Chunga449dc02014-05-16 11:15:04 -07001344 }
1345 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001346 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1347 colorBackground);
Winson Chungec396d62014-08-06 17:08:00 -07001348 // Update the task affiliation color if we are the parent of the group
1349 if (taskId == mAffiliatedTaskId) {
1350 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1351 }
Winson Chunga449dc02014-05-16 11:15:04 -07001352 }
1353 }
1354
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001355 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001356 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001357 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001358 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001359 final ActivityRecord r = mActivities.get(activityNdx);
1360 if (r.finishing) {
1361 continue;
1362 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001363 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001364 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001365 break;
1366 }
1367 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001368 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001369 }
1370
1371 void updateEffectiveIntent() {
1372 final int effectiveRootIndex = findEffectiveRootIndex();
1373 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001374 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001375 }
1376
Craig Mautner21d24a22014-04-23 11:45:37 -07001377 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001378 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001379
1380 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1381 if (realActivity != null) {
1382 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1383 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001384 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001385 if (origActivity != null) {
1386 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1387 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001388 // Write affinity, and root affinity if it is different from affinity.
1389 // We use the special string "@" for a null root affinity, so we can identify
1390 // later whether we were given a root affinity or should just make it the
1391 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001392 if (affinity != null) {
1393 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001394 if (!affinity.equals(rootAffinity)) {
1395 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1396 }
1397 } else if (rootAffinity != null) {
1398 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001399 }
1400 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001401 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001402 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1403 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001404 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001405 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001406 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001407 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001408 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001409 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001410 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001411 if (lastDescription != null) {
1412 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1413 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001414 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001415 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001416 }
Winson Chung36f3f032016-09-08 23:29:43 +00001417 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001418 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001419 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1420 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1421 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001422 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1423 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001424 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001425 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001426 if (mLastNonFullscreenBounds != null) {
1427 out.attribute(
1428 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001429 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001430 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1431 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001432 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001433
Craig Mautner21d24a22014-04-23 11:45:37 -07001434 if (affinityIntent != null) {
1435 out.startTag(null, TAG_AFFINITYINTENT);
1436 affinityIntent.saveToXml(out);
1437 out.endTag(null, TAG_AFFINITYINTENT);
1438 }
1439
Winson Chung36f3f032016-09-08 23:29:43 +00001440 out.startTag(null, TAG_INTENT);
1441 intent.saveToXml(out);
1442 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001443
1444 final ArrayList<ActivityRecord> activities = mActivities;
1445 final int numActivities = activities.size();
1446 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1447 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001448 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001449 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1450 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001451 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001452 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001453 break;
1454 }
1455 out.startTag(null, TAG_ACTIVITY);
1456 r.saveToXml(out);
1457 out.endTag(null, TAG_ACTIVITY);
1458 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001459 }
1460
Winson Chung36f3f032016-09-08 23:29:43 +00001461 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1462 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001463 Intent intent = null;
1464 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001465 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001466 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001467 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001468 ComponentName origActivity = null;
1469 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001470 String rootAffinity = null;
1471 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001472 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001473 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001474 boolean askedCompatMode = false;
1475 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001476 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001477 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001478 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001479 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001480 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001481 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001482 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001483 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001484 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001485 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001486 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001487 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001488 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001489 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001490 int prevTaskId = INVALID_TASK_ID;
1491 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001492 int callingUid = -1;
1493 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001494 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001495 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001496 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001497 int minWidth = INVALID_MIN_SIZE;
1498 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001499 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001500
1501 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1502 final String attrName = in.getAttributeName(attrNdx);
1503 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001504 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1505 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001506 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001507 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001508 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1509 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001510 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1511 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001512 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1513 origActivity = ComponentName.unflattenFromString(attrValue);
1514 } else if (ATTR_AFFINITY.equals(attrName)) {
1515 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001516 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1517 rootAffinity = attrValue;
1518 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001519 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001520 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001521 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001522 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001523 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001524 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001525 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001526 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001527 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001528 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001529 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001530 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001531 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001532 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001533 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001534 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001535 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001536 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001537 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1538 lastDescription = attrValue;
1539 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001540 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001541 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001542 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001543 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1544 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001545 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1546 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001547 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001548 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001549 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001550 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001551 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001552 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001553 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001554 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001555 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001556 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001557 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1558 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001559 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001560 resizeMode = Integer.parseInt(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001561 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001562 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001563 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001564 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001565 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1566 minWidth = Integer.parseInt(attrValue);
1567 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1568 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001569 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1570 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001571 } else {
1572 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1573 }
1574 }
1575
1576 int event;
1577 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001578 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001579 if (event == XmlPullParser.START_TAG) {
1580 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001581 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1582 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001583 if (TAG_AFFINITYINTENT.equals(name)) {
1584 affinityIntent = Intent.restoreFromXml(in);
1585 } else if (TAG_INTENT.equals(name)) {
1586 intent = Intent.restoreFromXml(in);
1587 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001588 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001589 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1590 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001591 if (activity != null) {
1592 activities.add(activity);
1593 }
1594 } else {
1595 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1596 XmlUtils.skipCurrentTag(in);
1597 }
1598 }
1599 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001600 if (!hasRootAffinity) {
1601 rootAffinity = affinity;
1602 } else if ("@".equals(rootAffinity)) {
1603 rootAffinity = null;
1604 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001605 if (effectiveUid <= 0) {
1606 Intent checkIntent = intent != null ? intent : affinityIntent;
1607 effectiveUid = 0;
1608 if (checkIntent != null) {
1609 IPackageManager pm = AppGlobals.getPackageManager();
1610 try {
1611 ApplicationInfo ai = pm.getApplicationInfo(
1612 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001613 PackageManager.MATCH_UNINSTALLED_PACKAGES
1614 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001615 if (ai != null) {
1616 effectiveUid = ai.uid;
1617 }
1618 } catch (RemoteException e) {
1619 }
1620 }
1621 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1622 + ": effectiveUid=" + effectiveUid);
1623 }
1624
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001625 if (persistTaskVersion < 1) {
1626 // We need to convert the resize mode of home activities saved before version one if
1627 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1628 // since we didn't have that differentiation before version 1 and the system didn't
1629 // resize home activities before then.
1630 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1631 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1632 }
1633 }
1634
Winson Chung36f3f032016-09-08 23:29:43 +00001635 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001636 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001637 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1638 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001639 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001640 taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged,
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001641 realActivitySuspended, userSetupComplete, minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001642 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001643
1644 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001645 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001646 }
1647
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001648 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001649 return task;
1650 }
1651
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001652 private void adjustForMinimalTaskDimensions(Rect bounds) {
1653 if (bounds == null) {
1654 return;
1655 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001656 int minWidth = mMinWidth;
1657 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001658 // If the task has no requested minimal size, we'd like to enforce a minimal size
1659 // so that the user can not render the task too small to manipulate. We don't need
1660 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001661 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001662 if (minWidth == INVALID_MIN_SIZE) {
1663 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001664 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001665 if (minHeight == INVALID_MIN_SIZE) {
1666 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001667 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001668 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001669 final boolean adjustWidth = minWidth > bounds.width();
1670 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001671 if (!(adjustWidth || adjustHeight)) {
1672 return;
1673 }
1674
1675 if (adjustWidth) {
1676 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001677 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001678 } else {
1679 // Either left bounds match, or neither match, or the previous bounds were
1680 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001681 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001682 }
1683 }
1684 if (adjustHeight) {
1685 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001686 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001687 } else {
1688 // Either top bounds match, or neither match, or the previous bounds were
1689 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001690 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001691 }
1692 }
1693 }
1694
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001695 /**
1696 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001697 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07001698 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001699 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001700 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001701 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1702 }
1703
1704 /**
1705 * Update task's override configuration based on the bounds.
1706 * @param bounds The bounds of the task.
1707 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1708 * subtract the navigation bar/status bar size from the screen size reported
1709 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07001710 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001711 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001712 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001713 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07001714 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001715 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001716 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08001717 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07001718 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001719
1720 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001721 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001722 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001723 mLastNonFullscreenBounds = mBounds;
1724 }
1725 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07001726 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07001727 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001728 mTmpRect.set(bounds);
1729 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001730 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001731 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001732 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001733 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001734 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001735 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001736 mLastNonFullscreenBounds = mBounds;
1737 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001738 calculateOverrideConfig(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07001739 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001740 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001741 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001742
1743 if (mFullscreen != oldFullscreen) {
Andrii Kulian933076d2016-03-29 17:04:42 -07001744 mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001745 }
1746
Andrii Kulian1779e612016-10-12 21:58:25 -07001747 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001748 }
1749
Andrii Kuliandaea3572016-04-08 13:20:51 -07001750 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds,
1751 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001752 mTmpRect2.set(inInsetBounds);
1753 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1754 int leftInset = mTmpRect2.left - inInsetBounds.left;
1755 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001756 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1757 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001758 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1759 }
1760
Andrii Kuliandaea3572016-04-08 13:20:51 -07001761 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds,
1762 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001763 mTmpRect2.set(inInsetBounds);
1764 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1765 int leftInset = mTmpRect2.left - inInsetBounds.left;
1766 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001767 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1768 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi0a932142016-02-01 17:42:25 -08001769 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1770 }
1771
Andrii Kulian1779e612016-10-12 21:58:25 -07001772 /** Clears passed config and fills it with new override values. */
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07001773 private void calculateOverrideConfig(Configuration config, Rect bounds, Rect insetBounds,
1774 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001775 mTmpNonDecorBounds.set(bounds);
1776 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001777
Andrii Kulian1779e612016-10-12 21:58:25 -07001778 final Configuration parentConfig = getParent().getConfiguration();
1779 config.unset();
1780 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Yorke Leef54f9da2017-01-10 07:58:59 -08001781 final boolean isFloatingTask = mStack != null && StackId.tasksAreFloating(mStack.mStackId);
1782 if (isFloatingTask) {
1783 // Floating tasks should not be resized to the screen's bounds.
1784 config.screenWidthDp = (int) (mTmpStableBounds.width() / density);
1785 config.screenHeightDp = (int) (mTmpStableBounds.height() / density);
1786 } else {
1787 // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
1788 // i.e. the screen area without the system bars.
1789 // Additionally task dimensions should not be bigger than its parents dimensions.
1790 subtractNonDecorInsets(mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds,
1791 overrideWidth, overrideHeight);
1792 subtractStableInsets(mTmpStableBounds, insetBounds != null ? insetBounds : bounds,
1793 overrideWidth, overrideHeight);
1794 config.screenWidthDp = Math.min(
1795 (int) (mTmpStableBounds.width() / density), parentConfig.screenWidthDp);
1796 config.screenHeightDp = Math.min(
1797 (int) (mTmpStableBounds.height() / density), parentConfig.screenHeightDp);
1798 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001799
1800 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001801 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1802 ? Configuration.ORIENTATION_PORTRAIT
1803 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001804
Jorim Jaggi85639432016-05-06 17:27:55 -07001805 // For calculating screen layout, we need to use the non-decor inset screen area for the
1806 // calculation for compatibility reasons, i.e. screen area without system bars that could
1807 // never go away in Honeycomb.
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001808 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1809 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07001810 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
1811 // calculation with partial default.
1812 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001813 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07001814 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07001815 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
1816
1817 config.smallestScreenWidthDp = mService.mWindowManager.getSmallestWidthForTaskBounds(
1818 insetBounds != null ? insetBounds : bounds);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001819 }
1820
1821 /**
1822 * Using the existing configuration {@param config}, creates a new task override config such
1823 * that all the fields that are usually set in an override config are set to the ones in
1824 * {@param config}.
1825 */
1826 Configuration extractOverrideConfig(Configuration config) {
Andrii Kulian1779e612016-10-12 21:58:25 -07001827 final Configuration extracted = new Configuration();
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001828 extracted.screenWidthDp = config.screenWidthDp;
1829 extracted.screenHeightDp = config.screenHeightDp;
1830 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1831 extracted.orientation = config.orientation;
Andrii Kulian1779e612016-10-12 21:58:25 -07001832 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout.
1833 extracted.screenLayout = config.screenLayout & (Configuration.SCREENLAYOUT_LONG_MASK
1834 | Configuration.SCREENLAYOUT_SIZE_MASK | Configuration.SCREENLAYOUT_COMPAT_NEEDED);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001835 return extracted;
1836 }
1837
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001838 Rect updateOverrideConfigurationFromLaunchBounds() {
1839 final Rect bounds = validateBounds(getLaunchBounds());
1840 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07001841 if (bounds != null) {
1842 bounds.set(mBounds);
1843 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001844 return bounds;
1845 }
1846
1847 static Rect validateBounds(Rect bounds) {
1848 if (bounds != null && bounds.isEmpty()) {
1849 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1850 return null;
1851 }
1852 return bounds;
1853 }
1854
Wale Ogunwale935e5022015-11-10 12:36:10 -08001855 /** Updates the task's bounds and override configuration to match what is expected for the
1856 * input stack. */
1857 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001858 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001859 return;
1860 }
1861
1862 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001863 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001864 throw new IllegalArgumentException("Can not position non-resizeable task="
1865 + this + " in stack=" + inStack);
1866 }
1867 if (mBounds != null) {
1868 return;
1869 }
1870 if (mLastNonFullscreenBounds != null) {
1871 updateOverrideConfiguration(mLastNonFullscreenBounds);
1872 } else {
1873 inStack.layoutTaskInStack(this, null);
1874 }
1875 } else {
1876 updateOverrideConfiguration(inStack.mBounds);
1877 }
1878 }
1879
Chong Zhang0fa656b2015-08-31 15:17:21 -07001880 /**
1881 * Returns the correct stack to use based on task type and currently set bounds,
1882 * regardless of the focused stack and current stack association of the task.
1883 * The task will be moved (and stack focus changed) later if necessary.
1884 */
1885 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001886 if (isRecentsTask()) {
1887 return RECENTS_STACK_ID;
1888 }
1889 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001890 return HOME_STACK_ID;
1891 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001892 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001893 return FREEFORM_WORKSPACE_STACK_ID;
1894 }
1895 return FULLSCREEN_WORKSPACE_STACK_ID;
1896 }
1897
1898 /** Returns the bounds that should be used to launch this task. */
1899 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001900 // If we're over lockscreen, forget about stack bounds and use fullscreen.
Jorim Jaggife762342016-10-13 14:33:27 +02001901 if (mService.mStackSupervisor.mKeyguardController.isKeyguardShowing()) {
Chong Zhang75b37202015-12-04 14:16:36 -08001902 return null;
1903 }
1904
Andrii Kulian02b7a832016-10-06 23:11:56 -07001905 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08001906 return null;
1907 }
1908
Andrii Kulian02b7a832016-10-06 23:11:56 -07001909 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08001910 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001911 || stackId == RECENTS_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08001912 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001913 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001914 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07001915 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001916 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001917 }
1918 return mLastNonFullscreenBounds;
1919 }
1920
Wale Ogunwale39381972015-12-17 17:15:29 -08001921 boolean canMatchRootAffinity() {
1922 // We don't allow root affinity matching on the pinned stack as no other task should
1923 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001924 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08001925 }
1926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001928 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001929 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1930 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08001931 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001932 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001933 if (affinity != null || rootAffinity != null) {
1934 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
1935 if (affinity == null || !affinity.equals(rootAffinity)) {
1936 pw.print(" root="); pw.println(rootAffinity);
1937 } else {
1938 pw.println();
1939 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001940 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07001941 if (voiceSession != null || voiceInteractor != null) {
1942 pw.print(prefix); pw.print("VOICE: session=0x");
1943 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
1944 pw.print(" interactor=0x");
1945 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
1946 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001947 if (intent != null) {
1948 StringBuilder sb = new StringBuilder(128);
1949 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001950 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001951 sb.append('}');
1952 pw.println(sb.toString());
1953 }
1954 if (affinityIntent != null) {
1955 StringBuilder sb = new StringBuilder(128);
1956 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001957 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001958 sb.append('}');
1959 pw.println(sb.toString());
1960 }
1961 if (origActivity != null) {
1962 pw.print(prefix); pw.print("origActivity=");
1963 pw.println(origActivity.flattenToShortString());
1964 }
1965 if (realActivity != null) {
1966 pw.print(prefix); pw.print("realActivity=");
1967 pw.println(realActivity.flattenToShortString());
1968 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07001969 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
1970 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001971 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001972 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001973 pw.print(" numFullscreen="); pw.print(numFullscreen);
1974 pw.print(" taskType="); pw.print(taskType);
1975 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
1976 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001977 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
1978 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001979 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
1980 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07001981 pw.print(" mReuseTask="); pw.print(mReuseTask);
1982 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001983 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08001984 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
1985 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
1986 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07001987 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
1988 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
1989 pw.print(" (");
1990 if (mPrevAffiliate == null) {
1991 pw.print("null");
1992 } else {
1993 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
1994 }
1995 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
1996 pw.print(" (");
1997 if (mNextAffiliate == null) {
1998 pw.print("null");
1999 } else {
2000 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2001 }
2002 pw.println(")");
2003 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002004 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002005 if (!askedCompatMode || !inRecents || !isAvailable) {
2006 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2007 pw.print(" inRecents="); pw.print(inRecents);
2008 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002009 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002010 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002011 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2012 if (lastDescription != null) {
2013 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2014 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002015 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002016 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2017 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
2018 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00002019 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002020 pw.print(" lastActiveTime=" + lastActiveTime);
2021 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022 }
2023
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002024 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002026 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002027 if (stringName != null) {
2028 sb.append(stringName);
2029 sb.append(" U=");
2030 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002031 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002032 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002033 sb.append(" sz=");
2034 sb.append(mActivities.size());
2035 sb.append('}');
2036 return sb.toString();
2037 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002038 sb.append("TaskRecord{");
2039 sb.append(Integer.toHexString(System.identityHashCode(this)));
2040 sb.append(" #");
2041 sb.append(taskId);
2042 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002043 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002044 sb.append(affinity);
2045 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002046 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002047 sb.append(intent.getComponent().flattenToShortString());
2048 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002049 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002050 sb.append(affinityIntent.getComponent().flattenToShortString());
2051 } else {
2052 sb.append(" ??");
2053 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002054 stringName = sb.toString();
2055 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 }
2057}