blob: 729d32fbfc4ffc939a36501d33c97de70d4e4d39 [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;
Winsonc809cbb2015-11-02 12:06:15 -080037import android.graphics.Point;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070038import android.graphics.Rect;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070039import android.os.Debug;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070040import android.os.ParcelFileDescriptor;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070041import android.os.RemoteException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070042import android.os.UserHandle;
Suprabh Shukla7745c142016-03-07 18:21:10 -080043import android.provider.Settings;
Dianne Hackborn91097de2014-04-04 18:02:06 -070044import android.service.voice.IVoiceInteractionSession;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070045import android.util.DisplayMetrics;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070046import android.util.Slog;
Suprabh Shukla23593142015-11-03 17:31:15 -080047
Dianne Hackborn91097de2014-04-04 18:02:06 -070048import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070049import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080050
Craig Mautner21d24a22014-04-23 11:45:37 -070051import org.xmlpull.v1.XmlPullParser;
52import org.xmlpull.v1.XmlPullParserException;
53import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
Craig Mautnerc0ffce52014-07-01 12:38:52 -070055import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070056import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080058import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070059import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060
Jorim Jaggi0a932142016-02-01 17:42:25 -080061import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
62import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
63import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
64import static android.app.ActivityManager.StackId.HOME_STACK_ID;
65import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
66import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
67import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
68import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
69import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
70import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
71import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
72import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
73import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Wale Ogunwaled829d362016-02-10 19:24:49 -080074import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080075import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Suprabh Shukla7745c142016-03-07 18:21:10 -080076import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080077import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
78import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
79import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
80import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
81import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
82import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
83import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
84import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
85import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
86import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
87import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN;
88import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
89import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
90import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -070091import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Jorim Jaggi0a932142016-02-01 17:42:25 -080092
Craig Mautnerc0ffce52014-07-01 12:38:52 -070093final class TaskRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080094 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070095 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070096 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -070097 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070098 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080099
Wale Ogunwale18795a22014-12-03 11:38:33 -0800100 static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700101 private static final String TAG_INTENT = "intent";
102 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800103 static final String ATTR_REALACTIVITY = "real_activity";
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000104 static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700105 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700106 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700107 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700108 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700109 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700110 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700111 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
112 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800113 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700114 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700115 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700116 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700117 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700118 private static final String ATTR_LASTDESCRIPTION = "last_description";
119 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700120 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800121 static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700122 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
123 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700124 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700125 private static final String ATTR_CALLING_UID = "calling_uid";
126 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800127 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700128 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700129 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulian18d75122016-03-27 20:20:28 -0700130 private static final String ATTR_MINIMAL_WIDTH = "minimal_width";
131 private static final String ATTR_MINIMAL_HEIGHT = "minimal_height";
132
Craig Mautner21d24a22014-04-23 11:45:37 -0700133
134 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
135
Wale Ogunwale18795a22014-12-03 11:38:33 -0800136 static final int INVALID_TASK_ID = -1;
Andrii Kulian18d75122016-03-27 20:20:28 -0700137 static final int INVALID_MINIMAL_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700140 String affinity; // The affinity name for this task, or null; may change identity.
141 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700142 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
143 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 Intent intent; // The original intent that started the task.
145 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700146 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 ComponentName origActivity; // The non-alias activity component of the intent.
148 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000149 boolean realActivitySuspended; // True if the actual activity component that started the
150 // task is suspended.
Winson Chungffa2ec62014-07-03 15:54:42 -0700151 long firstActiveTime; // First time this task was active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700153 boolean inRecents; // Actually in the recents list?
154 boolean isAvailable; // Is the activity available to be launched?
Chong Zhangafb776d2016-04-23 14:33:55 -0700155 boolean isLaunching; // Is an activity in this task launching?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 boolean rootWasReset; // True if the intent at the root of the task had
157 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700158 boolean autoRemoveRecents; // If true, we should automatically remove the task from
159 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700160 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700161 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 -0800162
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700163 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700164 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800165 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
166 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800167
168 int numFullscreen; // Number of fullscreen activities.
169
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800170 int mResizeMode; // The resize mode of this task and its activities.
171 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800172 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
173 // changes on a temporary basis.
Craig Mautner15df08a2015-04-01 12:17:18 -0700174 int mLockTaskMode; // Which tasklock mode to launch this task in. One of
175 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700176 private boolean mPrivileged; // The root activity application of this task holds
177 // privileged permissions.
178
Craig Mautner15df08a2015-04-01 12:17:18 -0700179 /** Can't be put in lockTask mode. */
180 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100181 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700182 final static int LOCK_TASK_AUTH_PINNABLE = 1;
183 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
184 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100185 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700186 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100187 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
188 * lockTask task. */
189 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700190 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
191
192 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800193
Winson Chung03a9bae2014-05-02 09:56:12 -0700194 // This represents the last resolved activity values for this task
195 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700196 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700197
Craig Mautnerd2328952013-03-05 12:46:26 -0800198 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700199 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800200
Craig Mautnerd2328952013-03-05 12:46:26 -0800201 /** Current stack */
202 ActivityStack stack;
203
Craig Mautner2c1faed2013-07-23 12:56:02 -0700204 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700205 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700206
Craig Mautner21d24a22014-04-23 11:45:37 -0700207 /** Takes on same value as first root activity */
208 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700209 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700210
211 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
212 * determining the order when restoring. Sign indicates whether last task movement was to front
213 * (positive) or back (negative). Absolute value indicates time. */
214 long mLastTimeMoved = System.currentTimeMillis();
215
Craig Mautner84984fa2014-06-19 11:19:20 -0700216 /** Indication of what to run next when task exits. Use ActivityRecord types.
217 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
218 * task stack. */
219 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700220
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700221 /** If original intent did not allow relinquishing task identity, save that information */
222 boolean mNeverRelinquishIdentity = true;
223
Craig Mautner362449a2014-06-20 14:04:39 -0700224 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
225 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800226 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700227
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700228 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700229 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700230 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800231 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700232 CharSequence lastDescription; // Last description captured for this item.
233
Craig Mautnera228ae92014-07-09 05:44:55 -0700234 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700235 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700236 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800237 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700238 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800239 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700240
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700241 // For relaunching the task from recents as though it was launched by the original launcher.
242 int mCallingUid;
243 String mCallingPackage;
244
Craig Mautner21d24a22014-04-23 11:45:37 -0700245 final ActivityManagerService mService;
246
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700247 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
248 boolean mFullscreen = true;
249
250 // Bounds of the Task. null for fullscreen tasks.
251 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800252 private final Rect mTmpStableBounds = new Rect();
253 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800254 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800255 private final Rect mTmpRect2 = new Rect();
256
Wale Ogunwale706ed792015-08-02 10:29:44 -0700257 // Last non-fullscreen bounds the task was launched in or resized to.
258 // The information is persisted and used to determine the appropriate stack to launch the
259 // task into on restore.
260 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700261 // Minimal width and height of this task when it's resizeable. -1 means it should use the
262 // default minimal width/height.
263 int mMinimalWidth;
264 int mMinimalHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700265
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700266 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
267 // This number will be assigned when we evaluate OOM scores for all visible tasks.
268 int mLayerRank = -1;
269
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700270 Configuration mOverrideConfig = Configuration.EMPTY;
271
Craig Mautner21d24a22014-04-23 11:45:37 -0700272 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Dianne Hackborn91097de2014-04-04 18:02:06 -0700273 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700274 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700275 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
276 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800277 userId = UserHandle.getUserId(info.applicationInfo.uid);
278 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800279 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700281 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700282 voiceSession = _voiceSession;
283 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700284 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800285 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700286 mCallingUid = info.applicationInfo.uid;
287 mCallingPackage = info.packageName;
Martijn Coenend4a69702014-06-30 11:12:17 -0700288 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700289 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700290 touchActiveTime();
Craig Mautner21d24a22014-04-23 11:45:37 -0700291 }
292
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700293 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800294 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700295 mService = service;
296 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
297 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800298 userId = UserHandle.getUserId(info.applicationInfo.uid);
299 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800300 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700301 taskId = _taskId;
302 mAffiliatedTaskId = _taskId;
303 voiceSession = null;
304 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700305 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800306 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700307 mCallingUid = info.applicationInfo.uid;
308 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700309 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700310 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700311
312 taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
313 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700314 // Clamp to [1, max].
315 maxRecents = Math.min(Math.max(info.maxRecents, 1),
316 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700317
318 taskType = APPLICATION_ACTIVITY_TYPE;
319 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700320 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700321 touchActiveTime();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700322 }
323
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800324 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
325 Intent _affinityIntent, String _affinity, String _rootAffinity,
326 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
327 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
328 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
329 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
330 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800331 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
332 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800333 int resizeMode, boolean privileged, boolean _realActivitySuspended,
Andrii Kulian18d75122016-03-27 20:20:28 -0700334 boolean userSetupComplete, int minimalWidth, int minimalHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700335 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700336 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
337 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800338 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800339 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700340 taskId = _taskId;
341 intent = _intent;
342 affinityIntent = _affinityIntent;
343 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800344 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700345 voiceSession = null;
346 voiceInteractor = null;
347 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800348 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700349 origActivity = _origActivity;
350 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700351 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700352 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700353 askedCompatMode = _askedCompatMode;
354 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700355 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700356 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800357 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700358 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700359 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700360 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700361 lastDescription = _lastDescription;
362 mActivities = activities;
363 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700364 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700365 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700366 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700367 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700368 mPrevAffiliateTaskId = prevTaskId;
369 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700370 mCallingUid = callingUid;
371 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800372 mResizeMode = resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700373 mPrivileged = privileged;
Andrii Kulian18d75122016-03-27 20:20:28 -0700374 mMinimalWidth = minimalWidth;
375 mMinimalHeight = minimalHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 }
377
378 void touchActiveTime() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700379 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700380 if (firstActiveTime == 0) {
381 firstActiveTime = lastActiveTime;
382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 long getInactiveDuration() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700386 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700388
Winson Chungfee26772014-08-05 12:21:52 -0700389 /** Sets the original intent, and the calling uid and package. */
390 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700391 mCallingUid = r.launchedFromUid;
392 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700393 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700394 }
395
396 /** Sets the original intent, _without_ updating the calling uid or package. */
397 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700398 if (intent == null) {
399 mNeverRelinquishIdentity =
400 (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0;
401 } else if (mNeverRelinquishIdentity) {
402 return;
403 }
404
405 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700406 if (intent == null) {
407 // If this task already has an intent associated with it, don't set the root
408 // affinity -- we don't want it changing after initially set, but the initially
409 // set value may be null.
410 rootAffinity = affinity;
411 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700412 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700413 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800416 if (_intent != null) {
417 // If this Intent has a selector, we want to clear it for the
418 // recent task since it is not relevant if the user later wants
419 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700420 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800421 _intent = new Intent(_intent);
422 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700423 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800424 }
425 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700426 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 intent = _intent;
428 realActivity = _intent != null ? _intent.getComponent() : null;
429 origActivity = null;
430 } else {
431 ComponentName targetComponent = new ComponentName(
432 info.packageName, info.targetActivity);
433 if (_intent != null) {
434 Intent targetIntent = new Intent(_intent);
435 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800436 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700437 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700438 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700439 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 intent = targetIntent;
441 realActivity = targetComponent;
442 origActivity = _intent.getComponent();
443 } else {
444 intent = null;
445 realActivity = targetComponent;
446 origActivity = new ComponentName(info.packageName, info.name);
447 }
448 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700449
Craig Mautner47b20ba2014-09-17 17:23:44 -0700450 final int intentFlags = intent == null ? 0 : intent.getFlags();
451 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 // Once we are set to an Intent with this flag, we count this
453 // task as having a true root activity.
454 rootWasReset = true;
455 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700456 userId = UserHandle.getUserId(info.applicationInfo.uid);
Suprabh Shukla7745c142016-03-07 18:21:10 -0800457 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
458 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700459 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700460 // If the activity itself has requested auto-remove, then just always do it.
461 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700462 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
463 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700464 // If the caller has not asked for the document to be retained, then we may
465 // want to turn on auto-remove, depending on whether the target has set its
466 // own document launch mode.
467 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
468 autoRemoveRecents = false;
469 } else {
470 autoRemoveRecents = true;
471 }
472 } else {
473 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700474 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800475 mResizeMode = info.resizeMode;
Craig Mautner15df08a2015-04-01 12:17:18 -0700476 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700477 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700478 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800480
Andrii Kulian2e751b82016-03-16 16:59:32 -0700481 /** Sets the original minimal width and height. */
482 private void setMinDimensions(ActivityInfo info) {
483 if (info != null && info.windowLayout != null) {
484 mMinimalWidth = info.windowLayout.minimalWidth;
485 mMinimalHeight = info.windowLayout.minimalHeight;
486 } else {
Andrii Kulian18d75122016-03-27 20:20:28 -0700487 mMinimalWidth = INVALID_MINIMAL_SIZE;
488 mMinimalHeight = INVALID_MINIMAL_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700489 }
490 }
491
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800492 /**
493 * Return true if the input activity has the same intent resolution as the intent this task
494 * record is based on (normally the root activity intent).
495 */
496 boolean isSameIntentResolution(ActivityRecord r) {
497 final Intent intent = new Intent(r.intent);
498 // Correct the activity intent for aliasing. The task record intent will always be based on
499 // the real activity that will be launched not the alias, so we need to use an intent with
500 // the component name pointing to the real activity not the alias in the activity record.
501 intent.setComponent(r.realActivity);
502 return this.intent.filterEquals(intent);
503 }
504
Craig Mautner84984fa2014-06-19 11:19:20 -0700505 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800506 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
507 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700508 }
509
510 int getTaskToReturnTo() {
511 return mTaskToReturnTo;
512 }
513
Craig Mautnera228ae92014-07-09 05:44:55 -0700514 void setPrevAffiliate(TaskRecord prevAffiliate) {
515 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800516 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700517 }
518
519 void setNextAffiliate(TaskRecord nextAffiliate) {
520 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800521 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700522 }
523
524 // Close up recents linked list.
525 void closeRecentsChain() {
526 if (mPrevAffiliate != null) {
527 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
528 }
529 if (mNextAffiliate != null) {
530 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
531 }
532 setPrevAffiliate(null);
533 setNextAffiliate(null);
534 }
535
Winson Chung740c3ac2014-11-12 16:14:38 -0800536 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700537 disposeThumbnail();
538 closeRecentsChain();
539 if (inRecents) {
540 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800541 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700542 }
543 }
544
Craig Mautnera228ae92014-07-09 05:44:55 -0700545 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
546 closeRecentsChain();
547 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700548 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700549 // Find the end
550 while (taskToAffiliateWith.mNextAffiliate != null) {
551 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
552 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
553 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
554 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
555 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
556 nextRecents.setPrevAffiliate(null);
557 }
558 taskToAffiliateWith.setNextAffiliate(null);
559 break;
560 }
561 taskToAffiliateWith = nextRecents;
562 }
563 taskToAffiliateWith.setNextAffiliate(this);
564 setPrevAffiliate(taskToAffiliateWith);
565 setNextAffiliate(null);
566 }
567
Winson Chung096f36b2014-08-20 15:39:01 -0700568 /**
Winsonc809cbb2015-11-02 12:06:15 -0800569 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700570 * @return whether the thumbnail was set
571 */
Winsonc809cbb2015-11-02 12:06:15 -0800572 boolean setLastThumbnailLocked(Bitmap thumbnail) {
573 final Configuration serviceConfig = mService.mConfiguration;
574 int taskWidth = 0;
575 int taskHeight = 0;
576 if (mBounds != null) {
577 // Non-fullscreen tasks
578 taskWidth = mBounds.width();
579 taskHeight = mBounds.height();
580 } else if (stack != null) {
581 // Fullscreen tasks
582 final Point displaySize = new Point();
583 stack.getDisplaySize(displaySize);
584 taskWidth = displaySize.x;
585 taskHeight = displaySize.y;
586 } else {
587 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
588 }
589 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, serviceConfig.orientation);
590 }
591
592 /**
593 * Sets the last thumbnail with the current task bounds.
594 * @return whether the thumbnail was set
595 */
596 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
597 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700598 if (mLastThumbnail != thumbnail) {
599 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800600 mLastThumbnailInfo.taskWidth = taskWidth;
601 mLastThumbnailInfo.taskHeight = taskHeight;
602 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700603 if (thumbnail == null) {
604 if (mLastThumbnailFile != null) {
605 mLastThumbnailFile.delete();
606 }
607 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800608 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700609 }
Winson Chung096f36b2014-08-20 15:39:01 -0700610 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700611 }
Winson Chung096f36b2014-08-20 15:39:01 -0700612 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700613 }
614
615 void getLastThumbnail(TaskThumbnail thumbs) {
616 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800617 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700618 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700619 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800620 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800621 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700622 }
Winson Chung096f36b2014-08-20 15:39:01 -0700623 // Only load the thumbnail file if we don't have a thumbnail
624 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700625 try {
626 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
627 ParcelFileDescriptor.MODE_READ_ONLY);
628 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700629 }
630 }
631 }
632
Winsonc809cbb2015-11-02 12:06:15 -0800633 /**
634 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
635 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700636 void freeLastThumbnail() {
637 mLastThumbnail = null;
638 }
639
Winsonc809cbb2015-11-02 12:06:15 -0800640 /**
641 * Removes all associated thumbnail data when a task is removed or pruned from recents.
642 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700643 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800644 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700645 mLastThumbnail = null;
646 lastDescription = null;
647 }
648
Winson Chung1147c402014-05-14 11:05:00 -0700649 /** Returns the intent for the root activity for this task */
650 Intent getBaseIntent() {
651 return intent != null ? intent : affinityIntent;
652 }
653
Winson Chung3b3f4642014-04-22 10:08:18 -0700654 /** Returns the first non-finishing activity from the root. */
655 ActivityRecord getRootActivity() {
656 for (int i = 0; i < mActivities.size(); i++) {
657 final ActivityRecord r = mActivities.get(i);
658 if (r.finishing) {
659 continue;
660 }
661 return r;
662 }
663 return null;
664 }
665
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800666 ActivityRecord getTopActivity() {
667 for (int i = mActivities.size() - 1; i >= 0; --i) {
668 final ActivityRecord r = mActivities.get(i);
669 if (r.finishing) {
670 continue;
671 }
672 return r;
673 }
674 return null;
675 }
676
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700677 ActivityRecord topRunningActivityLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700678 if (stack != null) {
679 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
680 ActivityRecord r = mActivities.get(activityNdx);
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700681 if (!r.finishing && stack.okToShowLocked(r)) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700682 return r;
683 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700684 }
685 }
686 return null;
687 }
688
Wale Ogunwale3b232392016-05-13 15:37:13 -0700689 ActivityRecord topRunningActivityWithStartingWindowLocked() {
690 if (stack != null) {
691 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
692 ActivityRecord r = mActivities.get(activityNdx);
693 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
694 || r.finishing || !stack.okToShowLocked(r)) {
695 continue;
696 }
697 return r;
698 }
699 }
700 return null;
701 }
702
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800703 void setFrontOfTask() {
704 setFrontOfTask(null);
705 }
706
Craig Mautner3b475fe2013-12-16 15:58:31 -0800707 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800708 void setFrontOfTask(ActivityRecord newTop) {
709 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
710 // as not front. This is needed in situations where the current front activity in the
711 // task isn't finished yet and we want to set the front to the activity moved to the front
712 // of the task.
713 boolean foundFront = newTop != null ? true : false;
714
Craig Mautner3b475fe2013-12-16 15:58:31 -0800715 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800716 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800717 final ActivityRecord r = mActivities.get(activityNdx);
718 if (foundFront || r.finishing) {
719 r.frontOfTask = false;
720 } else {
721 r.frontOfTask = true;
722 // Set frontOfTask false for every following activity.
723 foundFront = true;
724 }
725 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000726 if (!foundFront && numActivities > 0) {
727 // All activities of this task are finishing. As we ought to have a frontOfTask
728 // activity, make the bottom activity front.
729 mActivities.get(0).frontOfTask = true;
730 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800731 if (newTop != null) {
732 newTop.frontOfTask = true;
733 }
Craig Mautner3b475fe2013-12-16 15:58:31 -0800734 }
735
Craig Mautnerde4ef022013-04-07 19:01:33 -0700736 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800737 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700738 */
739 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700740 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
741 "Removing and adding activity " + newTop
742 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -0700743
Craig Mautnerde4ef022013-04-07 19:01:33 -0700744 mActivities.remove(newTop);
745 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700746 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -0800747
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800748 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700749 }
750
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800751 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800752 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800753 }
754
755 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700756 addActivityAtIndex(mActivities.size(), r);
757 }
758
759 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700760 // 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 -0800761 if (!mActivities.remove(r) && r.fullscreen) {
762 // Was not previously in list.
763 numFullscreen++;
764 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700765 // Only set this based on the first activity
766 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700767 taskType = r.mActivityType;
768 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700769 mCallingUid = r.launchedFromUid;
770 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700771 // Clamp to [1, max].
772 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
773 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -0700774 } else {
775 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -0700776 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -0700777 }
Wale Ogunwale3b232392016-05-13 15:37:13 -0700778
779 final int size = mActivities.size();
780
781 if (index == size && size > 0) {
782 final ActivityRecord top = mActivities.get(size - 1);
783 if (top.mTaskOverlay) {
784 // Place below the task overlay activity since the overlay activity should always
785 // be on top.
786 index--;
787 }
788 }
789
Craig Mautner77878772013-03-04 19:46:24 -0800790 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700791 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -0700792 if (r.isPersistable()) {
793 mService.notifyTaskPersisterLocked(this, false);
794 }
Craig Mautner77878772013-03-04 19:46:24 -0800795 }
796
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800797 /** @return true if this was the last activity in the task */
798 boolean removeActivity(ActivityRecord r) {
799 if (mActivities.remove(r) && r.fullscreen) {
800 // Was previously in list.
801 numFullscreen--;
802 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700803 if (r.isPersistable()) {
804 mService.notifyTaskPersisterLocked(this, false);
805 }
Wale Ogunwale89182d52016-03-11 10:38:36 -0800806
807 if (stack != null && stack.mStackId == PINNED_STACK_ID) {
808 // We normally notify listeners of task stack changes on pause, however pinned stack
809 // activities are normally in the paused state so no notification will be sent there
810 // before the activity is removed. We send it here so instead.
811 mService.notifyTaskStackChangedLocked();
812 }
813
Craig Mautner41326202014-06-20 14:38:21 -0700814 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -0700815 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -0700816 }
817 updateEffectiveIntent();
818 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800819 }
820
Craig Mautner41db4a72014-05-07 17:20:56 -0700821 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700822 // We will automatically remove the task either if it has explicitly asked for
823 // this, or it is empty and has never contained an activity that got shown to
824 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700825 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -0700826 }
827
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700828 /**
829 * Completely remove all activities associated with an existing
830 * task starting at a specified index.
831 */
832 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700833 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700834 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700835 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700836 if (r.finishing) {
837 continue;
838 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700839 if (stack == null) {
840 // Task was restored from persistent storage.
841 r.takeFromHistory();
842 mActivities.remove(activityNdx);
843 --activityNdx;
844 --numActivities;
Todd Kennedy539db512014-12-15 09:57:55 -0800845 } else if (stack.finishActivityLocked(
846 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700847 --activityNdx;
848 --numActivities;
849 }
850 }
851 }
852
853 /**
854 * Completely remove all activities associated with an existing task.
855 */
856 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -0700857 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700858 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -0700859 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700860 }
861
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800862 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
863 mReuseTask = true;
864 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
865 mReuseTask = false;
866 return result;
867 }
868
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700869 /**
870 * Perform clear operation as requested by
871 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
872 * stack to the given task, then look for
873 * an instance of that activity in the stack and, if found, finish all
874 * activities on top of it and return the instance.
875 *
876 * @param newR Description of the new activity being started.
877 * @return Returns the old activity that should be continued to be used,
878 * or null if none was found.
879 */
880 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700881 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700882 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700883 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700884 if (r.finishing) {
885 continue;
886 }
887 if (r.realActivity.equals(newR.realActivity)) {
888 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -0700889 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700890
891 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700892 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700893 if (r.finishing) {
894 continue;
895 }
896 ActivityOptions opts = r.takeOptionsLocked();
897 if (opts != null) {
898 ret.updateOptionsLocked(opts);
899 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700900 if (stack != null && stack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -0800901 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700902 --activityNdx;
903 --numActivities;
904 }
905 }
906
907 // Finally, if this is a normal launch mode (that is, not
908 // expecting onNewIntent()), then we will finish the current
909 // instance of the activity so a new fresh one can be started.
910 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
911 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
912 if (!ret.finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700913 if (stack != null) {
914 stack.finishActivityLocked(
915 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
916 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700917 return null;
918 }
919 }
920
921 return ret;
922 }
923 }
924
925 return null;
926 }
927
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700928 public TaskThumbnail getTaskThumbnailLocked() {
Craig Mautner21d24a22014-04-23 11:45:37 -0700929 if (stack != null) {
930 final ActivityRecord resumedActivity = stack.mResumedActivity;
931 if (resumedActivity != null && resumedActivity.task == this) {
Winson8b1871d2015-11-20 09:56:20 -0800932 final Bitmap thumbnail = stack.screenshotActivitiesLocked(resumedActivity);
Winsonc809cbb2015-11-02 12:06:15 -0800933 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -0700934 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700935 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700936 final TaskThumbnail taskThumbnail = new TaskThumbnail();
937 getLastThumbnail(taskThumbnail);
938 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700939 }
940
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700941 public void removeTaskActivitiesLocked() {
942 // Just remove the entire task.
943 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700944 }
945
Craig Mautner432f64e2015-05-20 14:59:57 -0700946 String lockTaskAuthToString() {
947 switch (mLockTaskAuth) {
948 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
949 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
950 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
951 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +0100952 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -0700953 default: return "unknown=" + mLockTaskAuth;
954 }
955 }
956
Craig Mautner15df08a2015-04-01 12:17:18 -0700957 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +0100958 if (!mPrivileged &&
959 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
960 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
961 // Non-priv apps are not allowed to use always or never, fall back to default
962 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
963 }
Craig Mautner15df08a2015-04-01 12:17:18 -0700964 switch (mLockTaskMode) {
965 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
966 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
967 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
968 break;
969
970 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +0100971 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -0700972 break;
973
974 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +0100975 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -0700976 break;
977
978 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
979 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
980 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
981 break;
982 }
Craig Mautner432f64e2015-05-20 14:59:57 -0700983 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
984 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -0700985 }
986
987 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +0100988 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
989 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -0700990 return false;
991 }
992 String[] packages = mService.mLockTaskPackages.get(userId);
993 if (packages == null) {
994 return false;
995 }
996 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +0100997 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -0700998 return true;
999 }
1000 }
1001 return false;
1002 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001003
Craig Mautnera82aa092013-09-13 15:34:08 -07001004 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001005 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001006 }
1007
Wale Ogunwale74e26592016-02-05 11:48:37 -08001008 boolean isRecentsTask() {
1009 return taskType == RECENTS_ACTIVITY_TYPE;
1010 }
1011
Craig Mautner86d67a42013-05-14 10:34:38 -07001012 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001013 return taskType == APPLICATION_ACTIVITY_TYPE;
1014 }
1015
1016 boolean isOverHomeStack() {
1017 return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001018 }
1019
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001020 boolean isResizeable() {
1021 return !isHomeTask() && (mService.mForceResizableActivities
Jorim Jaggi8202b2a2016-02-03 19:24:31 -08001022 || ActivityInfo.isResizeableMode(mResizeMode)) && !mTemporarilyUnresizable;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001023 }
1024
1025 boolean inCropWindowsResizeMode() {
1026 return !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS;
1027 }
1028
Wale Ogunwale513346d2016-01-27 10:55:01 -08001029 boolean canGoInDockedStack() {
1030 return isResizeable() || inCropWindowsResizeMode();
1031 }
1032
Craig Mautner525f3d92013-05-07 14:01:50 -07001033 /**
1034 * Find the activity in the history stack within the given task. Returns
1035 * the index within the history at which it's found, or < 0 if not found.
1036 */
1037 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1038 final ComponentName realActivity = r.realActivity;
1039 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1040 ActivityRecord candidate = mActivities.get(activityNdx);
1041 if (candidate.finishing) {
1042 continue;
1043 }
1044 if (candidate.realActivity.equals(realActivity)) {
1045 return candidate;
1046 }
1047 }
1048 return null;
1049 }
1050
Winson Chunga449dc02014-05-16 11:15:04 -07001051 /** Updates the last task description values. */
1052 void updateTaskDescription() {
1053 // Traverse upwards looking for any break between main task activities and
1054 // utility activities.
1055 int activityNdx;
1056 final int numActivities = mActivities.size();
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001057 final boolean relinquish = numActivities == 0 ? false :
1058 (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001059 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001060 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001061 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001062 if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1063 // This will be the top activity for determining taskDescription. Pre-inc to
1064 // overcome initial decrement below.
1065 ++activityNdx;
1066 break;
1067 }
Winson Chunga449dc02014-05-16 11:15:04 -07001068 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001069 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001070 break;
1071 }
1072 }
1073 if (activityNdx > 0) {
1074 // Traverse downwards starting below break looking for set label, icon.
1075 // Note that if there are activities in the task but none of them set the
1076 // recent activity values, then we do not fall back to the last set
1077 // values in the TaskRecord.
1078 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001079 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001080 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001081 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001082 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1083 final ActivityRecord r = mActivities.get(activityNdx);
1084 if (r.taskDescription != null) {
1085 if (label == null) {
1086 label = r.taskDescription.getLabel();
1087 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001088 if (iconFilename == null) {
1089 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001090 }
1091 if (colorPrimary == 0) {
1092 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001093 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001094 if (colorBackground == 0) {
1095 colorBackground = r.taskDescription.getBackgroundColor();
1096 }
Winson Chunga449dc02014-05-16 11:15:04 -07001097 }
1098 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001099 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1100 colorBackground);
Winson Chungec396d62014-08-06 17:08:00 -07001101 // Update the task affiliation color if we are the parent of the group
1102 if (taskId == mAffiliatedTaskId) {
1103 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1104 }
Winson Chunga449dc02014-05-16 11:15:04 -07001105 }
1106 }
1107
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001108 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001109 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001110 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001111 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001112 final ActivityRecord r = mActivities.get(activityNdx);
1113 if (r.finishing) {
1114 continue;
1115 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001116 effectiveNdx = activityNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001117 if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1118 break;
1119 }
1120 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001121 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001122 }
1123
1124 void updateEffectiveIntent() {
1125 final int effectiveRootIndex = findEffectiveRootIndex();
1126 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001127 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001128 }
1129
Craig Mautner21d24a22014-04-23 11:45:37 -07001130 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001131 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001132
1133 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1134 if (realActivity != null) {
1135 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1136 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001137 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001138 if (origActivity != null) {
1139 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1140 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001141 // Write affinity, and root affinity if it is different from affinity.
1142 // We use the special string "@" for a null root affinity, so we can identify
1143 // later whether we were given a root affinity or should just make it the
1144 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001145 if (affinity != null) {
1146 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001147 if (!affinity.equals(rootAffinity)) {
1148 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1149 }
1150 } else if (rootAffinity != null) {
1151 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001152 }
1153 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001154 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001155 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1156 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001157 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001158 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001159 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001160 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001161 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001162 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001163 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001164 if (lastDescription != null) {
1165 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1166 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001167 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001168 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001169 }
Winsonc809cbb2015-11-02 12:06:15 -08001170 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001171 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001172 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1173 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1174 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001175 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1176 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001177 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001178 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001179 if (mLastNonFullscreenBounds != null) {
1180 out.attribute(
1181 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001182 }
Andrii Kulian18d75122016-03-27 20:20:28 -07001183 out.attribute(null, ATTR_MINIMAL_WIDTH, String.valueOf(mMinimalWidth));
1184 out.attribute(null, ATTR_MINIMAL_HEIGHT, String.valueOf(mMinimalHeight));
Winson Chung2cb86c72014-06-25 12:03:30 -07001185
Craig Mautner21d24a22014-04-23 11:45:37 -07001186 if (affinityIntent != null) {
1187 out.startTag(null, TAG_AFFINITYINTENT);
1188 affinityIntent.saveToXml(out);
1189 out.endTag(null, TAG_AFFINITYINTENT);
1190 }
1191
1192 out.startTag(null, TAG_INTENT);
1193 intent.saveToXml(out);
1194 out.endTag(null, TAG_INTENT);
1195
1196 final ArrayList<ActivityRecord> activities = mActivities;
1197 final int numActivities = activities.size();
1198 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1199 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001200 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001201 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1202 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001203 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001204 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001205 break;
1206 }
1207 out.startTag(null, TAG_ACTIVITY);
1208 r.saveToXml(out);
1209 out.endTag(null, TAG_ACTIVITY);
1210 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001211 }
1212
1213 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1214 throws IOException, XmlPullParserException {
1215 Intent intent = null;
1216 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001217 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001218 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001219 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001220 ComponentName origActivity = null;
1221 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001222 String rootAffinity = null;
1223 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001224 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001225 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001226 boolean askedCompatMode = false;
1227 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001228 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001229 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001230 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001231 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001232 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001233 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001234 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001235 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001236 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001237 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001238 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001239 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001240 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001241 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001242 int prevTaskId = INVALID_TASK_ID;
1243 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001244 int callingUid = -1;
1245 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001246 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001247 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001248 Rect bounds = null;
Andrii Kulian18d75122016-03-27 20:20:28 -07001249 int minimalWidth = INVALID_MINIMAL_SIZE;
1250 int minimalHeight = INVALID_MINIMAL_SIZE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001251
1252 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1253 final String attrName = in.getAttributeName(attrNdx);
1254 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001255 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1256 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001257 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001258 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001259 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1260 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001261 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1262 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001263 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1264 origActivity = ComponentName.unflattenFromString(attrValue);
1265 } else if (ATTR_AFFINITY.equals(attrName)) {
1266 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001267 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1268 rootAffinity = attrValue;
1269 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001270 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
1271 rootHasReset = Boolean.valueOf(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001272 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
1273 autoRemoveRecents = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001274 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
1275 askedCompatMode = Boolean.valueOf(attrValue);
1276 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001277 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001278 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
1279 userSetupComplete = Boolean.valueOf(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001280 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001281 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001282 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001283 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001284 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
1285 firstActiveTime = Long.valueOf(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001286 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
1287 lastActiveTime = Long.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001288 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1289 lastDescription = attrValue;
1290 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
1291 lastTimeOnTop = Long.valueOf(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001292 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
1293 neverRelinquishIdentity = Boolean.valueOf(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001294 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1295 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001296 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1297 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001298 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001299 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001300 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001301 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001302 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001303 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001304 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001305 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001306 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001307 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001308 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1309 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001310 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001311 resizeMode = Integer.parseInt(attrValue);
Wale Ogunwaled829d362016-02-10 19:24:49 -08001312 resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS)
1313 ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001314 } else if (ATTR_PRIVILEGED.equals(attrName)) {
1315 privileged = Boolean.valueOf(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001316 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001317 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulian18d75122016-03-27 20:20:28 -07001318 } else if (ATTR_MINIMAL_WIDTH.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001319 minimalWidth = Integer.parseInt(attrValue);
Andrii Kulian18d75122016-03-27 20:20:28 -07001320 } else if (ATTR_MINIMAL_HEIGHT.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001321 minimalHeight = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001322 } else {
1323 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1324 }
1325 }
1326
1327 int event;
1328 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001329 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001330 if (event == XmlPullParser.START_TAG) {
1331 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001332 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1333 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001334 if (TAG_AFFINITYINTENT.equals(name)) {
1335 affinityIntent = Intent.restoreFromXml(in);
1336 } else if (TAG_INTENT.equals(name)) {
1337 intent = Intent.restoreFromXml(in);
1338 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001339 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001340 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1341 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001342 if (activity != null) {
1343 activities.add(activity);
1344 }
1345 } else {
1346 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1347 XmlUtils.skipCurrentTag(in);
1348 }
1349 }
1350 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001351 if (!hasRootAffinity) {
1352 rootAffinity = affinity;
1353 } else if ("@".equals(rootAffinity)) {
1354 rootAffinity = null;
1355 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001356 if (effectiveUid <= 0) {
1357 Intent checkIntent = intent != null ? intent : affinityIntent;
1358 effectiveUid = 0;
1359 if (checkIntent != null) {
1360 IPackageManager pm = AppGlobals.getPackageManager();
1361 try {
1362 ApplicationInfo ai = pm.getApplicationInfo(
1363 checkIntent.getComponent().getPackageName(),
1364 PackageManager.GET_UNINSTALLED_PACKAGES
1365 | PackageManager.GET_DISABLED_COMPONENTS, userId);
1366 if (ai != null) {
1367 effectiveUid = ai.uid;
1368 }
1369 } catch (RemoteException e) {
1370 }
1371 }
1372 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1373 + ": effectiveUid=" + effectiveUid);
1374 }
1375
Craig Mautner21d24a22014-04-23 11:45:37 -07001376 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001377 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001378 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1379 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001380 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001381 taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged,
Andrii Kulian18d75122016-03-27 20:20:28 -07001382 realActivitySuspended, userSetupComplete, minimalWidth, minimalHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001383 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001384
1385 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001386 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001387 }
1388
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001389 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001390 return task;
1391 }
1392
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001393 private void adjustForMinimalTaskDimensions(Rect bounds) {
1394 if (bounds == null) {
1395 return;
1396 }
Andrii Kulian2e751b82016-03-16 16:59:32 -07001397 int minimalWidth = mMinimalWidth;
1398 int minimalHeight = mMinimalHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001399 // If the task has no requested minimal size, we'd like to enforce a minimal size
1400 // so that the user can not render the task too small to manipulate. We don't need
1401 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian2e751b82016-03-16 16:59:32 -07001402 if (stack.mStackId != PINNED_STACK_ID) {
Andrii Kulian18d75122016-03-27 20:20:28 -07001403 if (minimalWidth == INVALID_MINIMAL_SIZE) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001404 minimalWidth = mService.mStackSupervisor.mDefaultMinimalSizeOfResizeableTask;
1405 }
Andrii Kulian18d75122016-03-27 20:20:28 -07001406 if (minimalHeight == INVALID_MINIMAL_SIZE) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001407 minimalHeight = mService.mStackSupervisor.mDefaultMinimalSizeOfResizeableTask;
1408 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001409 }
Andrii Kulian2e751b82016-03-16 16:59:32 -07001410 final boolean adjustWidth = minimalWidth > bounds.width();
1411 final boolean adjustHeight = minimalHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001412 if (!(adjustWidth || adjustHeight)) {
1413 return;
1414 }
1415
1416 if (adjustWidth) {
1417 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001418 bounds.left = bounds.right - minimalWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001419 } else {
1420 // Either left bounds match, or neither match, or the previous bounds were
1421 // fullscreen and we default to keeping left.
Andrii Kulian2e751b82016-03-16 16:59:32 -07001422 bounds.right = bounds.left + minimalWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001423 }
1424 }
1425 if (adjustHeight) {
1426 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001427 bounds.top = bounds.bottom - minimalHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001428 } else {
1429 // Either top bounds match, or neither match, or the previous bounds were
1430 // fullscreen and we default to keeping top.
Andrii Kulian2e751b82016-03-16 16:59:32 -07001431 bounds.bottom = bounds.top + minimalHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001432 }
1433 }
1434 }
1435
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001436 /**
1437 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001438 * @param bounds The bounds of the task.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001439 * @return Update configuration or null if there is no change.
1440 */
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001441 Configuration updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001442 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1443 }
1444
1445 /**
1446 * Update task's override configuration based on the bounds.
1447 * @param bounds The bounds of the task.
1448 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1449 * subtract the navigation bar/status bar size from the screen size reported
1450 * to the application. See {@link IActivityManager#resizeDockedStack}.
1451 * @return Update configuration or null if there is no change.
1452 */
1453 Configuration updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001454 if (Objects.equals(mBounds, bounds)) {
1455 return null;
1456 }
Wale Ogunwale5f986092015-12-04 15:35:38 -08001457 final Configuration oldConfig = mOverrideConfig;
1458 final boolean oldFullscreen = mFullscreen;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001459
1460 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001461 if (mFullscreen) {
Wale Ogunwale3797c222015-10-27 14:21:58 -07001462 if (mBounds != null && StackId.persistTaskBounds(stack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001463 mLastNonFullscreenBounds = mBounds;
1464 }
1465 mBounds = null;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001466 mOverrideConfig = Configuration.EMPTY;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001467 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001468 mTmpRect.set(bounds);
1469 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001470 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001471 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001472 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001473 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001474 }
Wale Ogunwale3797c222015-10-27 14:21:58 -07001475 if (stack == null || StackId.persistTaskBounds(stack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001476 mLastNonFullscreenBounds = mBounds;
1477 }
Andrii Kuliandaea3572016-04-08 13:20:51 -07001478 mOverrideConfig = calculateOverrideConfig(mTmpRect, insetBounds,
1479 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001480 }
Wale Ogunwale5f986092015-12-04 15:35:38 -08001481
1482 if (mFullscreen != oldFullscreen) {
Andrii Kulian933076d2016-03-29 17:04:42 -07001483 mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001484 }
1485
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001486 return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001487 }
1488
Andrii Kuliandaea3572016-04-08 13:20:51 -07001489 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds,
1490 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001491 mTmpRect2.set(inInsetBounds);
1492 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1493 int leftInset = mTmpRect2.left - inInsetBounds.left;
1494 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001495 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1496 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001497 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1498 }
1499
Andrii Kuliandaea3572016-04-08 13:20:51 -07001500 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds,
1501 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001502 mTmpRect2.set(inInsetBounds);
1503 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1504 int leftInset = mTmpRect2.left - inInsetBounds.left;
1505 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001506 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1507 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi0a932142016-02-01 17:42:25 -08001508 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1509 }
1510
Andrii Kuliandaea3572016-04-08 13:20:51 -07001511 private Configuration calculateOverrideConfig(Rect bounds, Rect insetBounds,
1512 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001513 mTmpNonDecorBounds.set(bounds);
1514 mTmpStableBounds.set(bounds);
1515 subtractNonDecorInsets(
Andrii Kuliandaea3572016-04-08 13:20:51 -07001516 mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds,
1517 overrideWidth, overrideHeight);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001518 subtractStableInsets(
Andrii Kuliandaea3572016-04-08 13:20:51 -07001519 mTmpStableBounds, insetBounds != null ? insetBounds : bounds,
1520 overrideWidth, overrideHeight);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001521
1522 // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
1523 // i.e. the screen area without the system bars.
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001524 final Configuration serviceConfig = mService.mConfiguration;
1525 final Configuration config = new Configuration(Configuration.EMPTY);
1526 // TODO(multidisplay): Update Dp to that of display stack is on.
1527 final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
1528 config.screenWidthDp =
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001529 Math.min((int)(mTmpStableBounds.width() / density), serviceConfig.screenWidthDp);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001530 config.screenHeightDp =
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001531 Math.min((int)(mTmpStableBounds.height() / density), serviceConfig.screenHeightDp);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001532
1533 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001534 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1535 ? Configuration.ORIENTATION_PORTRAIT
1536 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001537
Jorim Jaggi85639432016-05-06 17:27:55 -07001538 // For calculating screen layout, we need to use the non-decor inset screen area for the
1539 // calculation for compatibility reasons, i.e. screen area without system bars that could
1540 // never go away in Honeycomb.
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001541 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1542 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001543 final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001544 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07001545 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);;
1546 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
1547
1548 config.smallestScreenWidthDp = mService.mWindowManager.getSmallestWidthForTaskBounds(
1549 insetBounds != null ? insetBounds : bounds);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001550 return config;
1551 }
1552
1553 /**
1554 * Using the existing configuration {@param config}, creates a new task override config such
1555 * that all the fields that are usually set in an override config are set to the ones in
1556 * {@param config}.
1557 */
1558 Configuration extractOverrideConfig(Configuration config) {
1559 final Configuration extracted = new Configuration(Configuration.EMPTY);
1560 extracted.screenWidthDp = config.screenWidthDp;
1561 extracted.screenHeightDp = config.screenHeightDp;
1562 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1563 extracted.orientation = config.orientation;
1564 extracted.screenLayout = config.screenLayout;
1565 return extracted;
1566 }
1567
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001568 Rect updateOverrideConfigurationFromLaunchBounds() {
1569 final Rect bounds = validateBounds(getLaunchBounds());
1570 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07001571 if (bounds != null) {
1572 bounds.set(mBounds);
1573 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001574 return bounds;
1575 }
1576
1577 static Rect validateBounds(Rect bounds) {
1578 if (bounds != null && bounds.isEmpty()) {
1579 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1580 return null;
1581 }
1582 return bounds;
1583 }
1584
Wale Ogunwale935e5022015-11-10 12:36:10 -08001585 /** Updates the task's bounds and override configuration to match what is expected for the
1586 * input stack. */
1587 void updateOverrideConfigurationForStack(ActivityStack inStack) {
1588 if (stack != null && stack == inStack) {
1589 return;
1590 }
1591
1592 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001593 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001594 throw new IllegalArgumentException("Can not position non-resizeable task="
1595 + this + " in stack=" + inStack);
1596 }
1597 if (mBounds != null) {
1598 return;
1599 }
1600 if (mLastNonFullscreenBounds != null) {
1601 updateOverrideConfiguration(mLastNonFullscreenBounds);
1602 } else {
1603 inStack.layoutTaskInStack(this, null);
1604 }
1605 } else {
1606 updateOverrideConfiguration(inStack.mBounds);
1607 }
1608 }
1609
Chong Zhang0fa656b2015-08-31 15:17:21 -07001610 /**
1611 * Returns the correct stack to use based on task type and currently set bounds,
1612 * regardless of the focused stack and current stack association of the task.
1613 * The task will be moved (and stack focus changed) later if necessary.
1614 */
1615 int getLaunchStackId() {
1616 if (!isApplicationTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001617 return HOME_STACK_ID;
1618 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001619 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001620 return FREEFORM_WORKSPACE_STACK_ID;
1621 }
1622 return FULLSCREEN_WORKSPACE_STACK_ID;
1623 }
1624
1625 /** Returns the bounds that should be used to launch this task. */
1626 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001627 // If we're over lockscreen, forget about stack bounds and use fullscreen.
1628 if (mService.mLockScreenShown == LOCK_SCREEN_SHOWN) {
1629 return null;
1630 }
1631
Chong Zhang7d5f5102016-01-13 10:29:24 -08001632 if (stack == null) {
1633 return null;
1634 }
1635
1636 final int stackId = stack.mStackId;
1637 if (stackId == HOME_STACK_ID
1638 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001639 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
1640 return isResizeable() ? stack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07001641 } else if (!StackId.persistTaskBounds(stackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001642 return stack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001643 }
1644 return mLastNonFullscreenBounds;
1645 }
1646
Wale Ogunwale39381972015-12-17 17:15:29 -08001647 boolean canMatchRootAffinity() {
1648 // We don't allow root affinity matching on the pinned stack as no other task should
1649 // be launching in it based on affinity.
1650 return rootAffinity != null && (stack == null || stack.mStackId != PINNED_STACK_ID);
1651 }
1652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001654 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001655 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1656 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08001657 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001658 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001659 if (affinity != null || rootAffinity != null) {
1660 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
1661 if (affinity == null || !affinity.equals(rootAffinity)) {
1662 pw.print(" root="); pw.println(rootAffinity);
1663 } else {
1664 pw.println();
1665 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001666 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07001667 if (voiceSession != null || voiceInteractor != null) {
1668 pw.print(prefix); pw.print("VOICE: session=0x");
1669 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
1670 pw.print(" interactor=0x");
1671 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
1672 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001673 if (intent != null) {
1674 StringBuilder sb = new StringBuilder(128);
1675 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001676 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001677 sb.append('}');
1678 pw.println(sb.toString());
1679 }
1680 if (affinityIntent != null) {
1681 StringBuilder sb = new StringBuilder(128);
1682 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001683 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001684 sb.append('}');
1685 pw.println(sb.toString());
1686 }
1687 if (origActivity != null) {
1688 pw.print(prefix); pw.print("origActivity=");
1689 pw.println(origActivity.flattenToShortString());
1690 }
1691 if (realActivity != null) {
1692 pw.print(prefix); pw.print("realActivity=");
1693 pw.println(realActivity.flattenToShortString());
1694 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07001695 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
1696 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001697 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001698 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001699 pw.print(" numFullscreen="); pw.print(numFullscreen);
1700 pw.print(" taskType="); pw.print(taskType);
1701 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
1702 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001703 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
1704 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001705 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
1706 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07001707 pw.print(" mReuseTask="); pw.print(mReuseTask);
1708 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001709 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08001710 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
1711 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
1712 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07001713 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
1714 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
1715 pw.print(" (");
1716 if (mPrevAffiliate == null) {
1717 pw.print("null");
1718 } else {
1719 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
1720 }
1721 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
1722 pw.print(" (");
1723 if (mNextAffiliate == null) {
1724 pw.print("null");
1725 } else {
1726 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
1727 }
1728 pw.println(")");
1729 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001730 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001731 if (!askedCompatMode || !inRecents || !isAvailable) {
1732 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
1733 pw.print(" inRecents="); pw.print(inRecents);
1734 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001735 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001736 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001737 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
1738 if (lastDescription != null) {
1739 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
1740 }
Wale Ogunwale069fbe42015-07-29 11:38:01 -07001741 if (stack != null) {
1742 pw.print(prefix); pw.print("stackId="); pw.println(stack.mStackId);
1743 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001744 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
1745 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
1746 pw.print(" isResizeable=" + isResizeable());
1747 pw.print(" firstActiveTime=" + lastActiveTime);
1748 pw.print(" lastActiveTime=" + lastActiveTime);
1749 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750 }
1751
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001752 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001754 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001755 if (stringName != null) {
1756 sb.append(stringName);
1757 sb.append(" U=");
1758 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08001759 sb.append(" StackId=");
1760 sb.append(stack != null ? stack.mStackId : INVALID_STACK_ID);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001761 sb.append(" sz=");
1762 sb.append(mActivities.size());
1763 sb.append('}');
1764 return sb.toString();
1765 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001766 sb.append("TaskRecord{");
1767 sb.append(Integer.toHexString(System.identityHashCode(this)));
1768 sb.append(" #");
1769 sb.append(taskId);
1770 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001771 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001772 sb.append(affinity);
1773 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001774 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001775 sb.append(intent.getComponent().flattenToShortString());
1776 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001777 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001778 sb.append(affinityIntent.getComponent().flattenToShortString());
1779 } else {
1780 sb.append(" ??");
1781 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001782 stringName = sb.toString();
1783 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001784 }
1785}