blob: e32d1d1fa19e94af5bdfb3a246fedddb213ee6e9 [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;
91
Craig Mautnerc0ffce52014-07-01 12:38:52 -070092final class TaskRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080093 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070094 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070095 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -070096 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070097 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080098
Wale Ogunwale18795a22014-12-03 11:38:33 -080099 static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700100 private static final String TAG_INTENT = "intent";
101 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800102 static final String ATTR_REALACTIVITY = "real_activity";
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000103 static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700104 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700105 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700106 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700107 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700108 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700109 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700110 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
111 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800112 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700113 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700114 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700115 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700116 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700117 private static final String ATTR_LASTDESCRIPTION = "last_description";
118 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700119 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800120 static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700121 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
122 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700123 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700124 private static final String ATTR_CALLING_UID = "calling_uid";
125 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800126 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700127 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700128 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulian18d75122016-03-27 20:20:28 -0700129 private static final String ATTR_MINIMAL_WIDTH = "minimal_width";
130 private static final String ATTR_MINIMAL_HEIGHT = "minimal_height";
131
Craig Mautner21d24a22014-04-23 11:45:37 -0700132
133 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
134
Wale Ogunwale18795a22014-12-03 11:38:33 -0800135 static final int INVALID_TASK_ID = -1;
Andrii Kulian18d75122016-03-27 20:20:28 -0700136 static final int INVALID_MINIMAL_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700139 String affinity; // The affinity name for this task, or null; may change identity.
140 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700141 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
142 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 Intent intent; // The original intent that started the task.
144 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700145 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 ComponentName origActivity; // The non-alias activity component of the intent.
147 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000148 boolean realActivitySuspended; // True if the actual activity component that started the
149 // task is suspended.
Winson Chungffa2ec62014-07-03 15:54:42 -0700150 long firstActiveTime; // First time this task was active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700152 boolean inRecents; // Actually in the recents list?
153 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 boolean rootWasReset; // True if the intent at the root of the task had
155 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700156 boolean autoRemoveRecents; // If true, we should automatically remove the task from
157 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700158 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700159 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 -0800160
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700161 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700162 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800163 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
164 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800165
166 int numFullscreen; // Number of fullscreen activities.
167
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800168 int mResizeMode; // The resize mode of this task and its activities.
169 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800170 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
171 // changes on a temporary basis.
Craig Mautner15df08a2015-04-01 12:17:18 -0700172 int mLockTaskMode; // Which tasklock mode to launch this task in. One of
173 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700174 private boolean mPrivileged; // The root activity application of this task holds
175 // privileged permissions.
176
Craig Mautner15df08a2015-04-01 12:17:18 -0700177 /** Can't be put in lockTask mode. */
178 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100179 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700180 final static int LOCK_TASK_AUTH_PINNABLE = 1;
181 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
182 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100183 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700184 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100185 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
186 * lockTask task. */
187 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700188 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
189
190 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800191
Winson Chung03a9bae2014-05-02 09:56:12 -0700192 // This represents the last resolved activity values for this task
193 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700194 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700195
Craig Mautnerd2328952013-03-05 12:46:26 -0800196 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700197 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800198
Craig Mautnerd2328952013-03-05 12:46:26 -0800199 /** Current stack */
200 ActivityStack stack;
201
Craig Mautner2c1faed2013-07-23 12:56:02 -0700202 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700203 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700204
Craig Mautner21d24a22014-04-23 11:45:37 -0700205 /** Takes on same value as first root activity */
206 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700207 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700208
209 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
210 * determining the order when restoring. Sign indicates whether last task movement was to front
211 * (positive) or back (negative). Absolute value indicates time. */
212 long mLastTimeMoved = System.currentTimeMillis();
213
Craig Mautner84984fa2014-06-19 11:19:20 -0700214 /** Indication of what to run next when task exits. Use ActivityRecord types.
215 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
216 * task stack. */
217 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700218
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700219 /** If original intent did not allow relinquishing task identity, save that information */
220 boolean mNeverRelinquishIdentity = true;
221
Craig Mautner362449a2014-06-20 14:04:39 -0700222 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
223 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800224 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700225
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700226 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700227 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700228 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800229 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700230 CharSequence lastDescription; // Last description captured for this item.
231
Craig Mautnera228ae92014-07-09 05:44:55 -0700232 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700233 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700234 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800235 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700236 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800237 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700238
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700239 // For relaunching the task from recents as though it was launched by the original launcher.
240 int mCallingUid;
241 String mCallingPackage;
242
Craig Mautner21d24a22014-04-23 11:45:37 -0700243 final ActivityManagerService mService;
244
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700245 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
246 boolean mFullscreen = true;
247
248 // Bounds of the Task. null for fullscreen tasks.
249 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800250 private final Rect mTmpStableBounds = new Rect();
251 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800252 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800253 private final Rect mTmpRect2 = new Rect();
254
Wale Ogunwale706ed792015-08-02 10:29:44 -0700255 // Last non-fullscreen bounds the task was launched in or resized to.
256 // The information is persisted and used to determine the appropriate stack to launch the
257 // task into on restore.
258 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700259 // Minimal width and height of this task when it's resizeable. -1 means it should use the
260 // default minimal width/height.
261 int mMinimalWidth;
262 int mMinimalHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700263
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700264 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
265 // This number will be assigned when we evaluate OOM scores for all visible tasks.
266 int mLayerRank = -1;
267
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700268 Configuration mOverrideConfig = Configuration.EMPTY;
269
Craig Mautner21d24a22014-04-23 11:45:37 -0700270 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Dianne Hackborn91097de2014-04-04 18:02:06 -0700271 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700272 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700273 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
274 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800275 userId = UserHandle.getUserId(info.applicationInfo.uid);
276 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800277 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700279 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700280 voiceSession = _voiceSession;
281 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700282 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800283 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700284 mCallingUid = info.applicationInfo.uid;
285 mCallingPackage = info.packageName;
Martijn Coenend4a69702014-06-30 11:12:17 -0700286 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700287 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700288 touchActiveTime();
Craig Mautner21d24a22014-04-23 11:45:37 -0700289 }
290
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700291 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800292 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700293 mService = service;
294 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
295 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800296 userId = UserHandle.getUserId(info.applicationInfo.uid);
297 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800298 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700299 taskId = _taskId;
300 mAffiliatedTaskId = _taskId;
301 voiceSession = null;
302 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700303 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800304 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700305 mCallingUid = info.applicationInfo.uid;
306 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700307 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700308 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700309
310 taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
311 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700312 // Clamp to [1, max].
313 maxRecents = Math.min(Math.max(info.maxRecents, 1),
314 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700315
316 taskType = APPLICATION_ACTIVITY_TYPE;
317 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700318 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700319 touchActiveTime();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700320 }
321
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800322 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
323 Intent _affinityIntent, String _affinity, String _rootAffinity,
324 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
325 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
326 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
327 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
328 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800329 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
330 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800331 int resizeMode, boolean privileged, boolean _realActivitySuspended,
Andrii Kulian18d75122016-03-27 20:20:28 -0700332 boolean userSetupComplete, int minimalWidth, int minimalHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700333 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700334 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
335 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800336 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800337 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700338 taskId = _taskId;
339 intent = _intent;
340 affinityIntent = _affinityIntent;
341 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800342 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700343 voiceSession = null;
344 voiceInteractor = null;
345 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800346 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700347 origActivity = _origActivity;
348 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700349 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700350 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700351 askedCompatMode = _askedCompatMode;
352 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700353 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700354 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800355 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700356 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700357 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700358 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700359 lastDescription = _lastDescription;
360 mActivities = activities;
361 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700362 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700363 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700364 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700365 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700366 mPrevAffiliateTaskId = prevTaskId;
367 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700368 mCallingUid = callingUid;
369 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800370 mResizeMode = resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700371 mPrivileged = privileged;
Andrii Kulian18d75122016-03-27 20:20:28 -0700372 mMinimalWidth = minimalWidth;
373 mMinimalHeight = minimalHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 }
375
376 void touchActiveTime() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700377 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700378 if (firstActiveTime == 0) {
379 firstActiveTime = lastActiveTime;
380 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 long getInactiveDuration() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700384 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700386
Winson Chungfee26772014-08-05 12:21:52 -0700387 /** Sets the original intent, and the calling uid and package. */
388 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700389 mCallingUid = r.launchedFromUid;
390 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700391 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700392 }
393
394 /** Sets the original intent, _without_ updating the calling uid or package. */
395 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700396 if (intent == null) {
397 mNeverRelinquishIdentity =
398 (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0;
399 } else if (mNeverRelinquishIdentity) {
400 return;
401 }
402
403 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700404 if (intent == null) {
405 // If this task already has an intent associated with it, don't set the root
406 // affinity -- we don't want it changing after initially set, but the initially
407 // set value may be null.
408 rootAffinity = affinity;
409 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700410 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700411 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800414 if (_intent != null) {
415 // If this Intent has a selector, we want to clear it for the
416 // recent task since it is not relevant if the user later wants
417 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700418 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800419 _intent = new Intent(_intent);
420 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700421 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800422 }
423 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700424 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 intent = _intent;
426 realActivity = _intent != null ? _intent.getComponent() : null;
427 origActivity = null;
428 } else {
429 ComponentName targetComponent = new ComponentName(
430 info.packageName, info.targetActivity);
431 if (_intent != null) {
432 Intent targetIntent = new Intent(_intent);
433 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800434 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700435 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700436 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700437 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 intent = targetIntent;
439 realActivity = targetComponent;
440 origActivity = _intent.getComponent();
441 } else {
442 intent = null;
443 realActivity = targetComponent;
444 origActivity = new ComponentName(info.packageName, info.name);
445 }
446 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700447
Craig Mautner47b20ba2014-09-17 17:23:44 -0700448 final int intentFlags = intent == null ? 0 : intent.getFlags();
449 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 // Once we are set to an Intent with this flag, we count this
451 // task as having a true root activity.
452 rootWasReset = true;
453 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700454 userId = UserHandle.getUserId(info.applicationInfo.uid);
Suprabh Shukla7745c142016-03-07 18:21:10 -0800455 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
456 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700457 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700458 // If the activity itself has requested auto-remove, then just always do it.
459 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700460 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
461 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700462 // If the caller has not asked for the document to be retained, then we may
463 // want to turn on auto-remove, depending on whether the target has set its
464 // own document launch mode.
465 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
466 autoRemoveRecents = false;
467 } else {
468 autoRemoveRecents = true;
469 }
470 } else {
471 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700472 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800473 mResizeMode = info.resizeMode;
Craig Mautner15df08a2015-04-01 12:17:18 -0700474 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700475 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700476 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800478
Andrii Kulian2e751b82016-03-16 16:59:32 -0700479 /** Sets the original minimal width and height. */
480 private void setMinDimensions(ActivityInfo info) {
481 if (info != null && info.windowLayout != null) {
482 mMinimalWidth = info.windowLayout.minimalWidth;
483 mMinimalHeight = info.windowLayout.minimalHeight;
484 } else {
Andrii Kulian18d75122016-03-27 20:20:28 -0700485 mMinimalWidth = INVALID_MINIMAL_SIZE;
486 mMinimalHeight = INVALID_MINIMAL_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700487 }
488 }
489
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800490 /**
491 * Return true if the input activity has the same intent resolution as the intent this task
492 * record is based on (normally the root activity intent).
493 */
494 boolean isSameIntentResolution(ActivityRecord r) {
495 final Intent intent = new Intent(r.intent);
496 // Correct the activity intent for aliasing. The task record intent will always be based on
497 // the real activity that will be launched not the alias, so we need to use an intent with
498 // the component name pointing to the real activity not the alias in the activity record.
499 intent.setComponent(r.realActivity);
500 return this.intent.filterEquals(intent);
501 }
502
Craig Mautner84984fa2014-06-19 11:19:20 -0700503 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800504 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
505 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700506 }
507
508 int getTaskToReturnTo() {
509 return mTaskToReturnTo;
510 }
511
Craig Mautnera228ae92014-07-09 05:44:55 -0700512 void setPrevAffiliate(TaskRecord prevAffiliate) {
513 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800514 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700515 }
516
517 void setNextAffiliate(TaskRecord nextAffiliate) {
518 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800519 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700520 }
521
522 // Close up recents linked list.
523 void closeRecentsChain() {
524 if (mPrevAffiliate != null) {
525 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
526 }
527 if (mNextAffiliate != null) {
528 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
529 }
530 setPrevAffiliate(null);
531 setNextAffiliate(null);
532 }
533
Winson Chung740c3ac2014-11-12 16:14:38 -0800534 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700535 disposeThumbnail();
536 closeRecentsChain();
537 if (inRecents) {
538 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800539 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700540 }
541 }
542
Craig Mautnera228ae92014-07-09 05:44:55 -0700543 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
544 closeRecentsChain();
545 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700546 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700547 // Find the end
548 while (taskToAffiliateWith.mNextAffiliate != null) {
549 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
550 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
551 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
552 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
553 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
554 nextRecents.setPrevAffiliate(null);
555 }
556 taskToAffiliateWith.setNextAffiliate(null);
557 break;
558 }
559 taskToAffiliateWith = nextRecents;
560 }
561 taskToAffiliateWith.setNextAffiliate(this);
562 setPrevAffiliate(taskToAffiliateWith);
563 setNextAffiliate(null);
564 }
565
Winson Chung096f36b2014-08-20 15:39:01 -0700566 /**
Winsonc809cbb2015-11-02 12:06:15 -0800567 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700568 * @return whether the thumbnail was set
569 */
Winsonc809cbb2015-11-02 12:06:15 -0800570 boolean setLastThumbnailLocked(Bitmap thumbnail) {
571 final Configuration serviceConfig = mService.mConfiguration;
572 int taskWidth = 0;
573 int taskHeight = 0;
574 if (mBounds != null) {
575 // Non-fullscreen tasks
576 taskWidth = mBounds.width();
577 taskHeight = mBounds.height();
578 } else if (stack != null) {
579 // Fullscreen tasks
580 final Point displaySize = new Point();
581 stack.getDisplaySize(displaySize);
582 taskWidth = displaySize.x;
583 taskHeight = displaySize.y;
584 } else {
585 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
586 }
587 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, serviceConfig.orientation);
588 }
589
590 /**
591 * Sets the last thumbnail with the current task bounds.
592 * @return whether the thumbnail was set
593 */
594 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
595 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700596 if (mLastThumbnail != thumbnail) {
597 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800598 mLastThumbnailInfo.taskWidth = taskWidth;
599 mLastThumbnailInfo.taskHeight = taskHeight;
600 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700601 if (thumbnail == null) {
602 if (mLastThumbnailFile != null) {
603 mLastThumbnailFile.delete();
604 }
605 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800606 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700607 }
Winson Chung096f36b2014-08-20 15:39:01 -0700608 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700609 }
Winson Chung096f36b2014-08-20 15:39:01 -0700610 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700611 }
612
613 void getLastThumbnail(TaskThumbnail thumbs) {
614 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800615 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700616 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700617 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800618 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800619 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700620 }
Winson Chung096f36b2014-08-20 15:39:01 -0700621 // Only load the thumbnail file if we don't have a thumbnail
622 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700623 try {
624 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
625 ParcelFileDescriptor.MODE_READ_ONLY);
626 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700627 }
628 }
629 }
630
Winsonc809cbb2015-11-02 12:06:15 -0800631 /**
632 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
633 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700634 void freeLastThumbnail() {
635 mLastThumbnail = null;
636 }
637
Winsonc809cbb2015-11-02 12:06:15 -0800638 /**
639 * Removes all associated thumbnail data when a task is removed or pruned from recents.
640 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700641 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800642 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700643 mLastThumbnail = null;
644 lastDescription = null;
645 }
646
Winson Chung1147c402014-05-14 11:05:00 -0700647 /** Returns the intent for the root activity for this task */
648 Intent getBaseIntent() {
649 return intent != null ? intent : affinityIntent;
650 }
651
Winson Chung3b3f4642014-04-22 10:08:18 -0700652 /** Returns the first non-finishing activity from the root. */
653 ActivityRecord getRootActivity() {
654 for (int i = 0; i < mActivities.size(); i++) {
655 final ActivityRecord r = mActivities.get(i);
656 if (r.finishing) {
657 continue;
658 }
659 return r;
660 }
661 return null;
662 }
663
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800664 ActivityRecord getTopActivity() {
665 for (int i = mActivities.size() - 1; i >= 0; --i) {
666 final ActivityRecord r = mActivities.get(i);
667 if (r.finishing) {
668 continue;
669 }
670 return r;
671 }
672 return null;
673 }
674
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700675 ActivityRecord topRunningActivityLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700676 if (stack != null) {
677 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
678 ActivityRecord r = mActivities.get(activityNdx);
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700679 if (!r.finishing && stack.okToShowLocked(r)) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700680 return r;
681 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700682 }
683 }
684 return null;
685 }
686
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800687 void setFrontOfTask() {
688 setFrontOfTask(null);
689 }
690
Craig Mautner3b475fe2013-12-16 15:58:31 -0800691 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800692 void setFrontOfTask(ActivityRecord newTop) {
693 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
694 // as not front. This is needed in situations where the current front activity in the
695 // task isn't finished yet and we want to set the front to the activity moved to the front
696 // of the task.
697 boolean foundFront = newTop != null ? true : false;
698
Craig Mautner3b475fe2013-12-16 15:58:31 -0800699 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800700 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800701 final ActivityRecord r = mActivities.get(activityNdx);
702 if (foundFront || r.finishing) {
703 r.frontOfTask = false;
704 } else {
705 r.frontOfTask = true;
706 // Set frontOfTask false for every following activity.
707 foundFront = true;
708 }
709 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000710 if (!foundFront && numActivities > 0) {
711 // All activities of this task are finishing. As we ought to have a frontOfTask
712 // activity, make the bottom activity front.
713 mActivities.get(0).frontOfTask = true;
714 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800715 if (newTop != null) {
716 newTop.frontOfTask = true;
717 }
Craig Mautner3b475fe2013-12-16 15:58:31 -0800718 }
719
Craig Mautnerde4ef022013-04-07 19:01:33 -0700720 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800721 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700722 */
723 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700724 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
725 "Removing and adding activity " + newTop
726 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -0700727
Craig Mautnerde4ef022013-04-07 19:01:33 -0700728 mActivities.remove(newTop);
729 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700730 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -0800731
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800732 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700733 }
734
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800735 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800736 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800737 }
738
739 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700740 addActivityAtIndex(mActivities.size(), r);
741 }
742
743 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700744 // 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 -0800745 if (!mActivities.remove(r) && r.fullscreen) {
746 // Was not previously in list.
747 numFullscreen++;
748 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700749 // Only set this based on the first activity
750 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700751 taskType = r.mActivityType;
752 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700753 mCallingUid = r.launchedFromUid;
754 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700755 // Clamp to [1, max].
756 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
757 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -0700758 } else {
759 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -0700760 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -0700761 }
Craig Mautner77878772013-03-04 19:46:24 -0800762 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700763 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -0700764 if (r.isPersistable()) {
765 mService.notifyTaskPersisterLocked(this, false);
766 }
Craig Mautner77878772013-03-04 19:46:24 -0800767 }
768
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800769 /** @return true if this was the last activity in the task */
770 boolean removeActivity(ActivityRecord r) {
771 if (mActivities.remove(r) && r.fullscreen) {
772 // Was previously in list.
773 numFullscreen--;
774 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700775 if (r.isPersistable()) {
776 mService.notifyTaskPersisterLocked(this, false);
777 }
Wale Ogunwale89182d52016-03-11 10:38:36 -0800778
779 if (stack != null && stack.mStackId == PINNED_STACK_ID) {
780 // We normally notify listeners of task stack changes on pause, however pinned stack
781 // activities are normally in the paused state so no notification will be sent there
782 // before the activity is removed. We send it here so instead.
783 mService.notifyTaskStackChangedLocked();
784 }
785
Craig Mautner41326202014-06-20 14:38:21 -0700786 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -0700787 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -0700788 }
789 updateEffectiveIntent();
790 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800791 }
792
Craig Mautner41db4a72014-05-07 17:20:56 -0700793 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700794 // We will automatically remove the task either if it has explicitly asked for
795 // this, or it is empty and has never contained an activity that got shown to
796 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700797 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -0700798 }
799
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700800 /**
801 * Completely remove all activities associated with an existing
802 * task starting at a specified index.
803 */
804 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700805 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700806 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700807 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700808 if (r.finishing) {
809 continue;
810 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700811 if (stack == null) {
812 // Task was restored from persistent storage.
813 r.takeFromHistory();
814 mActivities.remove(activityNdx);
815 --activityNdx;
816 --numActivities;
Todd Kennedy539db512014-12-15 09:57:55 -0800817 } else if (stack.finishActivityLocked(
818 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700819 --activityNdx;
820 --numActivities;
821 }
822 }
823 }
824
825 /**
826 * Completely remove all activities associated with an existing task.
827 */
828 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -0700829 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700830 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -0700831 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700832 }
833
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800834 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
835 mReuseTask = true;
836 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
837 mReuseTask = false;
838 return result;
839 }
840
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700841 /**
842 * Perform clear operation as requested by
843 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
844 * stack to the given task, then look for
845 * an instance of that activity in the stack and, if found, finish all
846 * activities on top of it and return the instance.
847 *
848 * @param newR Description of the new activity being started.
849 * @return Returns the old activity that should be continued to be used,
850 * or null if none was found.
851 */
852 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700853 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700854 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700855 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700856 if (r.finishing) {
857 continue;
858 }
859 if (r.realActivity.equals(newR.realActivity)) {
860 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -0700861 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700862
863 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700864 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700865 if (r.finishing) {
866 continue;
867 }
868 ActivityOptions opts = r.takeOptionsLocked();
869 if (opts != null) {
870 ret.updateOptionsLocked(opts);
871 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700872 if (stack != null && stack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -0800873 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700874 --activityNdx;
875 --numActivities;
876 }
877 }
878
879 // Finally, if this is a normal launch mode (that is, not
880 // expecting onNewIntent()), then we will finish the current
881 // instance of the activity so a new fresh one can be started.
882 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
883 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
884 if (!ret.finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700885 if (stack != null) {
886 stack.finishActivityLocked(
887 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
888 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700889 return null;
890 }
891 }
892
893 return ret;
894 }
895 }
896
897 return null;
898 }
899
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700900 public TaskThumbnail getTaskThumbnailLocked() {
Craig Mautner21d24a22014-04-23 11:45:37 -0700901 if (stack != null) {
902 final ActivityRecord resumedActivity = stack.mResumedActivity;
903 if (resumedActivity != null && resumedActivity.task == this) {
Winson8b1871d2015-11-20 09:56:20 -0800904 final Bitmap thumbnail = stack.screenshotActivitiesLocked(resumedActivity);
Winsonc809cbb2015-11-02 12:06:15 -0800905 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -0700906 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700907 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700908 final TaskThumbnail taskThumbnail = new TaskThumbnail();
909 getLastThumbnail(taskThumbnail);
910 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700911 }
912
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700913 public void removeTaskActivitiesLocked() {
914 // Just remove the entire task.
915 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700916 }
917
Craig Mautner432f64e2015-05-20 14:59:57 -0700918 String lockTaskAuthToString() {
919 switch (mLockTaskAuth) {
920 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
921 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
922 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
923 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +0100924 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -0700925 default: return "unknown=" + mLockTaskAuth;
926 }
927 }
928
Craig Mautner15df08a2015-04-01 12:17:18 -0700929 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +0100930 if (!mPrivileged &&
931 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
932 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
933 // Non-priv apps are not allowed to use always or never, fall back to default
934 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
935 }
Craig Mautner15df08a2015-04-01 12:17:18 -0700936 switch (mLockTaskMode) {
937 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
938 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
939 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
940 break;
941
942 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +0100943 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -0700944 break;
945
946 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +0100947 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -0700948 break;
949
950 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
951 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
952 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
953 break;
954 }
Craig Mautner432f64e2015-05-20 14:59:57 -0700955 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
956 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -0700957 }
958
959 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +0100960 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
961 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -0700962 return false;
963 }
964 String[] packages = mService.mLockTaskPackages.get(userId);
965 if (packages == null) {
966 return false;
967 }
968 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +0100969 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -0700970 return true;
971 }
972 }
973 return false;
974 }
Wale Ogunwale74e26592016-02-05 11:48:37 -0800975
Craig Mautnera82aa092013-09-13 15:34:08 -0700976 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700977 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -0700978 }
979
Wale Ogunwale74e26592016-02-05 11:48:37 -0800980 boolean isRecentsTask() {
981 return taskType == RECENTS_ACTIVITY_TYPE;
982 }
983
Craig Mautner86d67a42013-05-14 10:34:38 -0700984 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700985 return taskType == APPLICATION_ACTIVITY_TYPE;
986 }
987
988 boolean isOverHomeStack() {
989 return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -0700990 }
991
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800992 boolean isResizeable() {
993 return !isHomeTask() && (mService.mForceResizableActivities
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800994 || ActivityInfo.isResizeableMode(mResizeMode)) && !mTemporarilyUnresizable;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800995 }
996
997 boolean inCropWindowsResizeMode() {
998 return !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS;
999 }
1000
Wale Ogunwale513346d2016-01-27 10:55:01 -08001001 boolean canGoInDockedStack() {
1002 return isResizeable() || inCropWindowsResizeMode();
1003 }
1004
Craig Mautner525f3d92013-05-07 14:01:50 -07001005 /**
1006 * Find the activity in the history stack within the given task. Returns
1007 * the index within the history at which it's found, or < 0 if not found.
1008 */
1009 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1010 final ComponentName realActivity = r.realActivity;
1011 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1012 ActivityRecord candidate = mActivities.get(activityNdx);
1013 if (candidate.finishing) {
1014 continue;
1015 }
1016 if (candidate.realActivity.equals(realActivity)) {
1017 return candidate;
1018 }
1019 }
1020 return null;
1021 }
1022
Winson Chunga449dc02014-05-16 11:15:04 -07001023 /** Updates the last task description values. */
1024 void updateTaskDescription() {
1025 // Traverse upwards looking for any break between main task activities and
1026 // utility activities.
1027 int activityNdx;
1028 final int numActivities = mActivities.size();
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001029 final boolean relinquish = numActivities == 0 ? false :
1030 (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001031 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001032 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001033 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001034 if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1035 // This will be the top activity for determining taskDescription. Pre-inc to
1036 // overcome initial decrement below.
1037 ++activityNdx;
1038 break;
1039 }
Winson Chunga449dc02014-05-16 11:15:04 -07001040 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001041 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001042 break;
1043 }
1044 }
1045 if (activityNdx > 0) {
1046 // Traverse downwards starting below break looking for set label, icon.
1047 // Note that if there are activities in the task but none of them set the
1048 // recent activity values, then we do not fall back to the last set
1049 // values in the TaskRecord.
1050 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001051 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001052 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001053 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001054 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1055 final ActivityRecord r = mActivities.get(activityNdx);
1056 if (r.taskDescription != null) {
1057 if (label == null) {
1058 label = r.taskDescription.getLabel();
1059 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001060 if (iconFilename == null) {
1061 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001062 }
1063 if (colorPrimary == 0) {
1064 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001065 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001066 if (colorBackground == 0) {
1067 colorBackground = r.taskDescription.getBackgroundColor();
1068 }
Winson Chunga449dc02014-05-16 11:15:04 -07001069 }
1070 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001071 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1072 colorBackground);
Winson Chungec396d62014-08-06 17:08:00 -07001073 // Update the task affiliation color if we are the parent of the group
1074 if (taskId == mAffiliatedTaskId) {
1075 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1076 }
Winson Chunga449dc02014-05-16 11:15:04 -07001077 }
1078 }
1079
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001080 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001081 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001082 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001083 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001084 final ActivityRecord r = mActivities.get(activityNdx);
1085 if (r.finishing) {
1086 continue;
1087 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001088 effectiveNdx = activityNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001089 if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1090 break;
1091 }
1092 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001093 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001094 }
1095
1096 void updateEffectiveIntent() {
1097 final int effectiveRootIndex = findEffectiveRootIndex();
1098 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001099 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001100 }
1101
Craig Mautner21d24a22014-04-23 11:45:37 -07001102 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001103 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001104
1105 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1106 if (realActivity != null) {
1107 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1108 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001109 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001110 if (origActivity != null) {
1111 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1112 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001113 // Write affinity, and root affinity if it is different from affinity.
1114 // We use the special string "@" for a null root affinity, so we can identify
1115 // later whether we were given a root affinity or should just make it the
1116 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001117 if (affinity != null) {
1118 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001119 if (!affinity.equals(rootAffinity)) {
1120 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1121 }
1122 } else if (rootAffinity != null) {
1123 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001124 }
1125 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001126 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001127 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1128 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001129 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001130 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001131 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001132 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001133 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001134 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001135 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001136 if (lastDescription != null) {
1137 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1138 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001139 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001140 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001141 }
Winsonc809cbb2015-11-02 12:06:15 -08001142 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001143 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001144 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1145 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1146 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001147 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1148 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001149 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001150 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001151 if (mLastNonFullscreenBounds != null) {
1152 out.attribute(
1153 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001154 }
Andrii Kulian18d75122016-03-27 20:20:28 -07001155 out.attribute(null, ATTR_MINIMAL_WIDTH, String.valueOf(mMinimalWidth));
1156 out.attribute(null, ATTR_MINIMAL_HEIGHT, String.valueOf(mMinimalHeight));
Winson Chung2cb86c72014-06-25 12:03:30 -07001157
Craig Mautner21d24a22014-04-23 11:45:37 -07001158 if (affinityIntent != null) {
1159 out.startTag(null, TAG_AFFINITYINTENT);
1160 affinityIntent.saveToXml(out);
1161 out.endTag(null, TAG_AFFINITYINTENT);
1162 }
1163
1164 out.startTag(null, TAG_INTENT);
1165 intent.saveToXml(out);
1166 out.endTag(null, TAG_INTENT);
1167
1168 final ArrayList<ActivityRecord> activities = mActivities;
1169 final int numActivities = activities.size();
1170 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1171 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001172 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001173 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1174 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001175 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001176 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001177 break;
1178 }
1179 out.startTag(null, TAG_ACTIVITY);
1180 r.saveToXml(out);
1181 out.endTag(null, TAG_ACTIVITY);
1182 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001183 }
1184
1185 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1186 throws IOException, XmlPullParserException {
1187 Intent intent = null;
1188 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001189 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001190 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001191 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001192 ComponentName origActivity = null;
1193 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001194 String rootAffinity = null;
1195 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001196 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001197 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001198 boolean askedCompatMode = false;
1199 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001200 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001201 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001202 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001203 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001204 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001205 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001206 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001207 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001208 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001209 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001210 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001211 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001212 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001213 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001214 int prevTaskId = INVALID_TASK_ID;
1215 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001216 int callingUid = -1;
1217 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001218 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001219 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001220 Rect bounds = null;
Andrii Kulian18d75122016-03-27 20:20:28 -07001221 int minimalWidth = INVALID_MINIMAL_SIZE;
1222 int minimalHeight = INVALID_MINIMAL_SIZE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001223
1224 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1225 final String attrName = in.getAttributeName(attrNdx);
1226 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001227 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1228 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001229 if (ATTR_TASKID.equals(attrName)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001230 if (taskId == INVALID_TASK_ID) taskId = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001231 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1232 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001233 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1234 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001235 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1236 origActivity = ComponentName.unflattenFromString(attrValue);
1237 } else if (ATTR_AFFINITY.equals(attrName)) {
1238 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001239 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1240 rootAffinity = attrValue;
1241 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001242 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
1243 rootHasReset = Boolean.valueOf(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001244 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
1245 autoRemoveRecents = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001246 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
1247 askedCompatMode = Boolean.valueOf(attrValue);
1248 } else if (ATTR_USERID.equals(attrName)) {
1249 userId = Integer.valueOf(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001250 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
1251 userSetupComplete = Boolean.valueOf(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001252 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
1253 effectiveUid = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001254 } else if (ATTR_TASKTYPE.equals(attrName)) {
1255 taskType = Integer.valueOf(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001256 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
1257 firstActiveTime = Long.valueOf(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001258 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
1259 lastActiveTime = Long.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001260 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1261 lastDescription = attrValue;
1262 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
1263 lastTimeOnTop = Long.valueOf(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001264 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
1265 neverRelinquishIdentity = Boolean.valueOf(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001266 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1267 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001268 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1269 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001270 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
1271 taskAffiliation = Integer.valueOf(attrValue);
1272 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
1273 prevTaskId = Integer.valueOf(attrValue);
1274 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
1275 nextTaskId = Integer.valueOf(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001276 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
1277 taskAffiliationColor = Integer.valueOf(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001278 } else if (ATTR_CALLING_UID.equals(attrName)) {
1279 callingUid = Integer.valueOf(attrValue);
1280 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1281 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001282 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
1283 resizeMode = Integer.valueOf(attrValue);
Wale Ogunwaled829d362016-02-10 19:24:49 -08001284 resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS)
1285 ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001286 } else if (ATTR_PRIVILEGED.equals(attrName)) {
1287 privileged = Boolean.valueOf(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001288 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001289 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulian18d75122016-03-27 20:20:28 -07001290 } else if (ATTR_MINIMAL_WIDTH.equals(attrName)) {
1291 minimalWidth = Integer.valueOf(attrValue);
1292 } else if (ATTR_MINIMAL_HEIGHT.equals(attrName)) {
1293 minimalHeight = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001294 } else {
1295 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1296 }
1297 }
1298
1299 int event;
1300 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001301 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001302 if (event == XmlPullParser.START_TAG) {
1303 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001304 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1305 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001306 if (TAG_AFFINITYINTENT.equals(name)) {
1307 affinityIntent = Intent.restoreFromXml(in);
1308 } else if (TAG_INTENT.equals(name)) {
1309 intent = Intent.restoreFromXml(in);
1310 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001311 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001312 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1313 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001314 if (activity != null) {
1315 activities.add(activity);
1316 }
1317 } else {
1318 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1319 XmlUtils.skipCurrentTag(in);
1320 }
1321 }
1322 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001323 if (!hasRootAffinity) {
1324 rootAffinity = affinity;
1325 } else if ("@".equals(rootAffinity)) {
1326 rootAffinity = null;
1327 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001328 if (effectiveUid <= 0) {
1329 Intent checkIntent = intent != null ? intent : affinityIntent;
1330 effectiveUid = 0;
1331 if (checkIntent != null) {
1332 IPackageManager pm = AppGlobals.getPackageManager();
1333 try {
1334 ApplicationInfo ai = pm.getApplicationInfo(
1335 checkIntent.getComponent().getPackageName(),
1336 PackageManager.GET_UNINSTALLED_PACKAGES
1337 | PackageManager.GET_DISABLED_COMPONENTS, userId);
1338 if (ai != null) {
1339 effectiveUid = ai.uid;
1340 }
1341 } catch (RemoteException e) {
1342 }
1343 }
1344 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1345 + ": effectiveUid=" + effectiveUid);
1346 }
1347
Craig Mautner21d24a22014-04-23 11:45:37 -07001348 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001349 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001350 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1351 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001352 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001353 taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged,
Andrii Kulian18d75122016-03-27 20:20:28 -07001354 realActivitySuspended, userSetupComplete, minimalWidth, minimalHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001355 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001356
1357 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001358 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001359 }
1360
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001361 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001362 return task;
1363 }
1364
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001365 private void adjustForMinimalTaskDimensions(Rect bounds) {
1366 if (bounds == null) {
1367 return;
1368 }
Andrii Kulian2e751b82016-03-16 16:59:32 -07001369 int minimalWidth = mMinimalWidth;
1370 int minimalHeight = mMinimalHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001371 // If the task has no requested minimal size, we'd like to enforce a minimal size
1372 // so that the user can not render the task too small to manipulate. We don't need
1373 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian2e751b82016-03-16 16:59:32 -07001374 if (stack.mStackId != PINNED_STACK_ID) {
Andrii Kulian18d75122016-03-27 20:20:28 -07001375 if (minimalWidth == INVALID_MINIMAL_SIZE) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001376 minimalWidth = mService.mStackSupervisor.mDefaultMinimalSizeOfResizeableTask;
1377 }
Andrii Kulian18d75122016-03-27 20:20:28 -07001378 if (minimalHeight == INVALID_MINIMAL_SIZE) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001379 minimalHeight = mService.mStackSupervisor.mDefaultMinimalSizeOfResizeableTask;
1380 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001381 }
Andrii Kulian2e751b82016-03-16 16:59:32 -07001382 final boolean adjustWidth = minimalWidth > bounds.width();
1383 final boolean adjustHeight = minimalHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001384 if (!(adjustWidth || adjustHeight)) {
1385 return;
1386 }
1387
1388 if (adjustWidth) {
1389 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001390 bounds.left = bounds.right - minimalWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001391 } else {
1392 // Either left bounds match, or neither match, or the previous bounds were
1393 // fullscreen and we default to keeping left.
Andrii Kulian2e751b82016-03-16 16:59:32 -07001394 bounds.right = bounds.left + minimalWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001395 }
1396 }
1397 if (adjustHeight) {
1398 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulian2e751b82016-03-16 16:59:32 -07001399 bounds.top = bounds.bottom - minimalHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001400 } else {
1401 // Either top bounds match, or neither match, or the previous bounds were
1402 // fullscreen and we default to keeping top.
Andrii Kulian2e751b82016-03-16 16:59:32 -07001403 bounds.bottom = bounds.top + minimalHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001404 }
1405 }
1406 }
1407
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001408 /**
1409 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001410 * @param bounds The bounds of the task.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001411 * @return Update configuration or null if there is no change.
1412 */
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001413 Configuration updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001414 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1415 }
1416
1417 /**
1418 * Update task's override configuration based on the bounds.
1419 * @param bounds The bounds of the task.
1420 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1421 * subtract the navigation bar/status bar size from the screen size reported
1422 * to the application. See {@link IActivityManager#resizeDockedStack}.
1423 * @return Update configuration or null if there is no change.
1424 */
1425 Configuration updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001426 if (Objects.equals(mBounds, bounds)) {
1427 return null;
1428 }
Wale Ogunwale5f986092015-12-04 15:35:38 -08001429 final Configuration oldConfig = mOverrideConfig;
1430 final boolean oldFullscreen = mFullscreen;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001431
1432 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001433 if (mFullscreen) {
Wale Ogunwale3797c222015-10-27 14:21:58 -07001434 if (mBounds != null && StackId.persistTaskBounds(stack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001435 mLastNonFullscreenBounds = mBounds;
1436 }
1437 mBounds = null;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001438 mOverrideConfig = Configuration.EMPTY;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001439 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001440 mTmpRect.set(bounds);
1441 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001442 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001443 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001444 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001445 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001446 }
Wale Ogunwale3797c222015-10-27 14:21:58 -07001447 if (stack == null || StackId.persistTaskBounds(stack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001448 mLastNonFullscreenBounds = mBounds;
1449 }
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001450 mOverrideConfig = calculateOverrideConfig(mTmpRect, insetBounds);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001451 }
Wale Ogunwale5f986092015-12-04 15:35:38 -08001452
1453 if (mFullscreen != oldFullscreen) {
Andrii Kulian933076d2016-03-29 17:04:42 -07001454 mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001455 }
1456
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001457 return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001458 }
1459
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001460 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds) {
1461 mTmpRect2.set(inInsetBounds);
1462 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1463 int leftInset = mTmpRect2.left - inInsetBounds.left;
1464 int topInset = mTmpRect2.top - inInsetBounds.top;
1465 int rightInset = inInsetBounds.right - mTmpRect2.right;
1466 int bottomInset = inInsetBounds.bottom - mTmpRect2.bottom;
1467 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1468 }
1469
Jorim Jaggi0a932142016-02-01 17:42:25 -08001470 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds) {
1471 mTmpRect2.set(inInsetBounds);
1472 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1473 int leftInset = mTmpRect2.left - inInsetBounds.left;
1474 int topInset = mTmpRect2.top - inInsetBounds.top;
1475 int rightInset = inInsetBounds.right - mTmpRect2.right;
1476 int bottomInset = inInsetBounds.bottom - mTmpRect2.bottom;
1477 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1478 }
1479
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001480 private Configuration calculateOverrideConfig(Rect bounds, Rect insetBounds) {
1481 mTmpNonDecorBounds.set(bounds);
1482 mTmpStableBounds.set(bounds);
1483 subtractNonDecorInsets(
1484 mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds);
1485 subtractStableInsets(
1486 mTmpStableBounds, insetBounds != null ? insetBounds : bounds);
1487
1488 // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
1489 // i.e. the screen area without the system bars.
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001490 final Configuration serviceConfig = mService.mConfiguration;
1491 final Configuration config = new Configuration(Configuration.EMPTY);
1492 // TODO(multidisplay): Update Dp to that of display stack is on.
1493 final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
1494 config.screenWidthDp =
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001495 Math.min((int)(mTmpStableBounds.width() / density), serviceConfig.screenWidthDp);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001496 config.screenHeightDp =
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001497 Math.min((int)(mTmpStableBounds.height() / density), serviceConfig.screenHeightDp);
1498 config.smallestScreenWidthDp = Math.min(config.screenWidthDp, config.screenHeightDp);
1499
1500 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001501 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1502 ? Configuration.ORIENTATION_PORTRAIT
1503 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001504
1505 // For calculating screen layout, we need to use the non-decor inset screen area for the
1506 // calculation for compatibility reasons, i.e. screen area without system bars that could
1507 // never go away in Honeycomb.
1508 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1509 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001510 final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001511 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
1512 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi0a932142016-02-01 17:42:25 -08001513 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001514 return config;
1515 }
1516
1517 /**
1518 * Using the existing configuration {@param config}, creates a new task override config such
1519 * that all the fields that are usually set in an override config are set to the ones in
1520 * {@param config}.
1521 */
1522 Configuration extractOverrideConfig(Configuration config) {
1523 final Configuration extracted = new Configuration(Configuration.EMPTY);
1524 extracted.screenWidthDp = config.screenWidthDp;
1525 extracted.screenHeightDp = config.screenHeightDp;
1526 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1527 extracted.orientation = config.orientation;
1528 extracted.screenLayout = config.screenLayout;
1529 return extracted;
1530 }
1531
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001532 Rect updateOverrideConfigurationFromLaunchBounds() {
1533 final Rect bounds = validateBounds(getLaunchBounds());
1534 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07001535 if (bounds != null) {
1536 bounds.set(mBounds);
1537 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001538 return bounds;
1539 }
1540
1541 static Rect validateBounds(Rect bounds) {
1542 if (bounds != null && bounds.isEmpty()) {
1543 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1544 return null;
1545 }
1546 return bounds;
1547 }
1548
Wale Ogunwale935e5022015-11-10 12:36:10 -08001549 /** Updates the task's bounds and override configuration to match what is expected for the
1550 * input stack. */
1551 void updateOverrideConfigurationForStack(ActivityStack inStack) {
1552 if (stack != null && stack == inStack) {
1553 return;
1554 }
1555
1556 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001557 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001558 throw new IllegalArgumentException("Can not position non-resizeable task="
1559 + this + " in stack=" + inStack);
1560 }
1561 if (mBounds != null) {
1562 return;
1563 }
1564 if (mLastNonFullscreenBounds != null) {
1565 updateOverrideConfiguration(mLastNonFullscreenBounds);
1566 } else {
1567 inStack.layoutTaskInStack(this, null);
1568 }
1569 } else {
1570 updateOverrideConfiguration(inStack.mBounds);
1571 }
1572 }
1573
Chong Zhang0fa656b2015-08-31 15:17:21 -07001574 /**
1575 * Returns the correct stack to use based on task type and currently set bounds,
1576 * regardless of the focused stack and current stack association of the task.
1577 * The task will be moved (and stack focus changed) later if necessary.
1578 */
1579 int getLaunchStackId() {
1580 if (!isApplicationTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001581 return HOME_STACK_ID;
1582 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001583 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001584 return FREEFORM_WORKSPACE_STACK_ID;
1585 }
1586 return FULLSCREEN_WORKSPACE_STACK_ID;
1587 }
1588
1589 /** Returns the bounds that should be used to launch this task. */
1590 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001591 // If we're over lockscreen, forget about stack bounds and use fullscreen.
1592 if (mService.mLockScreenShown == LOCK_SCREEN_SHOWN) {
1593 return null;
1594 }
1595
Chong Zhang7d5f5102016-01-13 10:29:24 -08001596 if (stack == null) {
1597 return null;
1598 }
1599
1600 final int stackId = stack.mStackId;
1601 if (stackId == HOME_STACK_ID
1602 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001603 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
1604 return isResizeable() ? stack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07001605 } else if (!StackId.persistTaskBounds(stackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001606 return stack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001607 }
1608 return mLastNonFullscreenBounds;
1609 }
1610
Wale Ogunwale39381972015-12-17 17:15:29 -08001611 boolean canMatchRootAffinity() {
1612 // We don't allow root affinity matching on the pinned stack as no other task should
1613 // be launching in it based on affinity.
1614 return rootAffinity != null && (stack == null || stack.mStackId != PINNED_STACK_ID);
1615 }
1616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001618 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001619 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1620 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08001621 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001622 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001623 if (affinity != null || rootAffinity != null) {
1624 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
1625 if (affinity == null || !affinity.equals(rootAffinity)) {
1626 pw.print(" root="); pw.println(rootAffinity);
1627 } else {
1628 pw.println();
1629 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001630 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07001631 if (voiceSession != null || voiceInteractor != null) {
1632 pw.print(prefix); pw.print("VOICE: session=0x");
1633 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
1634 pw.print(" interactor=0x");
1635 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
1636 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001637 if (intent != null) {
1638 StringBuilder sb = new StringBuilder(128);
1639 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001640 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001641 sb.append('}');
1642 pw.println(sb.toString());
1643 }
1644 if (affinityIntent != null) {
1645 StringBuilder sb = new StringBuilder(128);
1646 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001647 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001648 sb.append('}');
1649 pw.println(sb.toString());
1650 }
1651 if (origActivity != null) {
1652 pw.print(prefix); pw.print("origActivity=");
1653 pw.println(origActivity.flattenToShortString());
1654 }
1655 if (realActivity != null) {
1656 pw.print(prefix); pw.print("realActivity=");
1657 pw.println(realActivity.flattenToShortString());
1658 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07001659 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
1660 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001661 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001662 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001663 pw.print(" numFullscreen="); pw.print(numFullscreen);
1664 pw.print(" taskType="); pw.print(taskType);
1665 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
1666 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001667 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
1668 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001669 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
1670 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07001671 pw.print(" mReuseTask="); pw.print(mReuseTask);
1672 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001673 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08001674 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
1675 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
1676 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07001677 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
1678 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
1679 pw.print(" (");
1680 if (mPrevAffiliate == null) {
1681 pw.print("null");
1682 } else {
1683 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
1684 }
1685 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
1686 pw.print(" (");
1687 if (mNextAffiliate == null) {
1688 pw.print("null");
1689 } else {
1690 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
1691 }
1692 pw.println(")");
1693 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001694 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001695 if (!askedCompatMode || !inRecents || !isAvailable) {
1696 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
1697 pw.print(" inRecents="); pw.print(inRecents);
1698 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001699 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001700 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001701 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
1702 if (lastDescription != null) {
1703 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
1704 }
Wale Ogunwale069fbe42015-07-29 11:38:01 -07001705 if (stack != null) {
1706 pw.print(prefix); pw.print("stackId="); pw.println(stack.mStackId);
1707 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001708 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
1709 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
1710 pw.print(" isResizeable=" + isResizeable());
1711 pw.print(" firstActiveTime=" + lastActiveTime);
1712 pw.print(" lastActiveTime=" + lastActiveTime);
1713 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 }
1715
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001716 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001718 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001719 if (stringName != null) {
1720 sb.append(stringName);
1721 sb.append(" U=");
1722 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08001723 sb.append(" StackId=");
1724 sb.append(stack != null ? stack.mStackId : INVALID_STACK_ID);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001725 sb.append(" sz=");
1726 sb.append(mActivities.size());
1727 sb.append('}');
1728 return sb.toString();
1729 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001730 sb.append("TaskRecord{");
1731 sb.append(Integer.toHexString(System.identityHashCode(this)));
1732 sb.append(" #");
1733 sb.append(taskId);
1734 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001735 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001736 sb.append(affinity);
1737 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001738 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001739 sb.append(intent.getComponent().flattenToShortString());
1740 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001741 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001742 sb.append(affinityIntent.getComponent().flattenToShortString());
1743 } else {
1744 sb.append(" ??");
1745 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001746 stringName = sb.toString();
1747 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 }
1749}