blob: af0e92695f95239f97c3e402aaac34b1dd5b0ac0 [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;
Andrii Kulian1779e612016-10-12 21:58:25 -070059import java.util.Collections;
60import java.util.List;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070061import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Jorim Jaggi0a932142016-02-01 17:42:25 -080063import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
64import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
65import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
66import static android.app.ActivityManager.StackId.HOME_STACK_ID;
67import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
68import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
69import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
70import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070071import static android.content.pm.ActivityInfo.FLAG_ON_TOP_LAUNCHER;
Jorim Jaggi0a932142016-02-01 17:42:25 -080072import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
73import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
74import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
75import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
76import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Wale Ogunwaled829d362016-02-10 19:24:49 -080077import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080078import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Suprabh Shukla7745c142016-03-07 18:21:10 -080079import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080080import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
81import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
82import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
83import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
84import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
85import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
86import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
87import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
88import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
89import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
90import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN;
91import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
92import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
93import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -070094import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Jorim Jaggi0a932142016-02-01 17:42:25 -080095
Andrii Kulian1779e612016-10-12 21:58:25 -070096final class TaskRecord extends ConfigurationContainer {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080097 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070098 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070099 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -0700100 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700101 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800102
Wale Ogunwale18795a22014-12-03 11:38:33 -0800103 static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700104 private static final String TAG_INTENT = "intent";
105 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800106 static final String ATTR_REALACTIVITY = "real_activity";
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000107 static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700108 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700109 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700110 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700111 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700112 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700113 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700114 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
115 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800116 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700117 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700118 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700119 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700120 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700121 private static final String ATTR_LASTDESCRIPTION = "last_description";
122 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700123 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800124 static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700125 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
126 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700127 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700128 private static final String ATTR_CALLING_UID = "calling_uid";
129 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800130 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700131 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700132 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700133 private static final String ATTR_MIN_WIDTH = "min_width";
134 private static final String ATTR_MIN_HEIGHT = "min_height";
Andrii Kulian18d75122016-03-27 20:20:28 -0700135
Craig Mautner21d24a22014-04-23 11:45:37 -0700136
137 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
138
Wale Ogunwale18795a22014-12-03 11:38:33 -0800139 static final int INVALID_TASK_ID = -1;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700140 static final int INVALID_MIN_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700143 String affinity; // The affinity name for this task, or null; may change identity.
144 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700145 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
146 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 Intent intent; // The original intent that started the task.
148 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700149 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 ComponentName origActivity; // The non-alias activity component of the intent.
151 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000152 boolean realActivitySuspended; // True if the actual activity component that started the
153 // task is suspended.
Winson Chung36f3f032016-09-08 23:29:43 +0000154 long firstActiveTime; // First time this task was active.
155 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700156 boolean inRecents; // Actually in the recents list?
157 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 boolean rootWasReset; // True if the intent at the root of the task had
159 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700160 boolean autoRemoveRecents; // If true, we should automatically remove the task from
161 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700162 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700163 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 -0800164
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700165 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700166 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800167 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
168 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800169
170 int numFullscreen; // Number of fullscreen activities.
171
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800172 int mResizeMode; // The resize mode of this task and its activities.
173 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800174 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
175 // changes on a temporary basis.
Craig Mautner15df08a2015-04-01 12:17:18 -0700176 int mLockTaskMode; // Which tasklock mode to launch this task in. One of
177 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700178 private boolean mPrivileged; // The root activity application of this task holds
179 // privileged permissions.
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700180 private boolean mIsOnTopLauncher; // Whether this task is an on-top launcher. See
181 // android.R.attr#onTopLauncher.
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700182
Craig Mautner15df08a2015-04-01 12:17:18 -0700183 /** Can't be put in lockTask mode. */
184 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100185 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700186 final static int LOCK_TASK_AUTH_PINNABLE = 1;
187 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
188 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100189 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700190 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100191 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
192 * lockTask task. */
193 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700194 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
195
196 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800197
Winson Chung03a9bae2014-05-02 09:56:12 -0700198 // This represents the last resolved activity values for this task
199 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700200 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700201
Craig Mautnerd2328952013-03-05 12:46:26 -0800202 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700203 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800204
Andrii Kulian02b7a832016-10-06 23:11:56 -0700205 /** Current stack. Setter must always be used to update the value. */
206 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800207
Craig Mautner2c1faed2013-07-23 12:56:02 -0700208 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700209 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700210
Craig Mautner21d24a22014-04-23 11:45:37 -0700211 /** Takes on same value as first root activity */
212 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700213 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700214
215 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
216 * determining the order when restoring. Sign indicates whether last task movement was to front
217 * (positive) or back (negative). Absolute value indicates time. */
218 long mLastTimeMoved = System.currentTimeMillis();
219
Craig Mautner84984fa2014-06-19 11:19:20 -0700220 /** Indication of what to run next when task exits. Use ActivityRecord types.
221 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
222 * task stack. */
223 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700224
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700225 /** If original intent did not allow relinquishing task identity, save that information */
226 boolean mNeverRelinquishIdentity = true;
227
Craig Mautner362449a2014-06-20 14:04:39 -0700228 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
229 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800230 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700231
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700232 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700233 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700234 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800235 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700236 CharSequence lastDescription; // Last description captured for this item.
237
Craig Mautnera228ae92014-07-09 05:44:55 -0700238 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700239 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700240 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800241 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700242 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800243 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700244
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700245 // For relaunching the task from recents as though it was launched by the original launcher.
246 int mCallingUid;
247 String mCallingPackage;
248
Craig Mautner21d24a22014-04-23 11:45:37 -0700249 final ActivityManagerService mService;
250
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700251 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
252 boolean mFullscreen = true;
253
254 // Bounds of the Task. null for fullscreen tasks.
255 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800256 private final Rect mTmpStableBounds = new Rect();
257 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800258 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800259 private final Rect mTmpRect2 = new Rect();
260
Wale Ogunwale706ed792015-08-02 10:29:44 -0700261 // Last non-fullscreen bounds the task was launched in or resized to.
262 // The information is persisted and used to determine the appropriate stack to launch the
263 // task into on restore.
264 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700265 // Minimal width and height of this task when it's resizeable. -1 means it should use the
266 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700267 int mMinWidth;
268 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700269
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700270 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
271 // This number will be assigned when we evaluate OOM scores for all visible tasks.
272 int mLayerRank = -1;
273
Andrii Kulian1779e612016-10-12 21:58:25 -0700274 /** Helper object used for updating override configuration. */
275 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700276
Craig Mautner21d24a22014-04-23 11:45:37 -0700277 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Dianne Hackborn91097de2014-04-04 18:02:06 -0700278 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700279 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700280 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
281 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800282 userId = UserHandle.getUserId(info.applicationInfo.uid);
283 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800284 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700286 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700287 voiceSession = _voiceSession;
288 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700289 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800290 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700291 mCallingUid = info.applicationInfo.uid;
292 mCallingPackage = info.packageName;
Martijn Coenend4a69702014-06-30 11:12:17 -0700293 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700294 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700295 touchActiveTime();
Craig Mautner21d24a22014-04-23 11:45:37 -0700296 }
297
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700298 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800299 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700300 mService = service;
301 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
302 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800303 userId = UserHandle.getUserId(info.applicationInfo.uid);
304 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800305 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700306 taskId = _taskId;
307 mAffiliatedTaskId = _taskId;
308 voiceSession = null;
309 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700310 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800311 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700312 mCallingUid = info.applicationInfo.uid;
313 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700314 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700315 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700316
317 taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
318 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700319 // Clamp to [1, max].
320 maxRecents = Math.min(Math.max(info.maxRecents, 1),
321 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700322
323 taskType = APPLICATION_ACTIVITY_TYPE;
324 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700325 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700326 touchActiveTime();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700327 }
328
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800329 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
330 Intent _affinityIntent, String _affinity, String _rootAffinity,
331 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
332 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
333 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
334 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
335 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800336 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
337 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800338 int resizeMode, boolean privileged, boolean _realActivitySuspended,
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700339 boolean userSetupComplete, int minWidth, int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700340 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700341 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
342 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800343 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800344 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700345 taskId = _taskId;
346 intent = _intent;
347 affinityIntent = _affinityIntent;
348 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800349 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700350 voiceSession = null;
351 voiceInteractor = null;
352 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800353 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700354 origActivity = _origActivity;
355 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700356 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700357 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700358 askedCompatMode = _askedCompatMode;
359 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700360 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700361 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800362 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700363 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700364 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700365 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700366 lastDescription = _lastDescription;
367 mActivities = activities;
368 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700369 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700370 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700371 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700372 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700373 mPrevAffiliateTaskId = prevTaskId;
374 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700375 mCallingUid = callingUid;
376 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800377 mResizeMode = resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700378 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700379 mMinWidth = minWidth;
380 mMinHeight = minHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
382
383 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000384 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700385 if (firstActiveTime == 0) {
386 firstActiveTime = lastActiveTime;
387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000391 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700393
Winson Chungfee26772014-08-05 12:21:52 -0700394 /** Sets the original intent, and the calling uid and package. */
395 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700396 mCallingUid = r.launchedFromUid;
397 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700398 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700399 }
400
401 /** Sets the original intent, _without_ updating the calling uid or package. */
402 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700403 if (intent == null) {
404 mNeverRelinquishIdentity =
405 (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0;
406 } else if (mNeverRelinquishIdentity) {
407 return;
408 }
409
410 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700411 if (intent == null) {
412 // If this task already has an intent associated with it, don't set the root
413 // affinity -- we don't want it changing after initially set, but the initially
414 // set value may be null.
415 rootAffinity = affinity;
416 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700417 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700418 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800421 if (_intent != null) {
422 // If this Intent has a selector, we want to clear it for the
423 // recent task since it is not relevant if the user later wants
424 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700425 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800426 _intent = new Intent(_intent);
427 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700428 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800429 }
430 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700431 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 intent = _intent;
433 realActivity = _intent != null ? _intent.getComponent() : null;
434 origActivity = null;
435 } else {
436 ComponentName targetComponent = new ComponentName(
437 info.packageName, info.targetActivity);
438 if (_intent != null) {
439 Intent targetIntent = new Intent(_intent);
440 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800441 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700442 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700443 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700444 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 intent = targetIntent;
446 realActivity = targetComponent;
447 origActivity = _intent.getComponent();
448 } else {
449 intent = null;
450 realActivity = targetComponent;
451 origActivity = new ComponentName(info.packageName, info.name);
452 }
453 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700454
Craig Mautner47b20ba2014-09-17 17:23:44 -0700455 final int intentFlags = intent == null ? 0 : intent.getFlags();
456 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 // Once we are set to an Intent with this flag, we count this
458 // task as having a true root activity.
459 rootWasReset = true;
460 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700461 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000462 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
463 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700464 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700465 // If the activity itself has requested auto-remove, then just always do it.
466 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700467 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
468 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700469 // If the caller has not asked for the document to be retained, then we may
470 // want to turn on auto-remove, depending on whether the target has set its
471 // own document launch mode.
472 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
473 autoRemoveRecents = false;
474 } else {
475 autoRemoveRecents = true;
476 }
477 } else {
478 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700479 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800480 mResizeMode = info.resizeMode;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700481 mIsOnTopLauncher = (info.flags & FLAG_ON_TOP_LAUNCHER) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700482 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700483 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700484 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800486
Andrii Kulian2e751b82016-03-16 16:59:32 -0700487 /** Sets the original minimal width and height. */
488 private void setMinDimensions(ActivityInfo info) {
489 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700490 mMinWidth = info.windowLayout.minWidth;
491 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700492 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700493 mMinWidth = INVALID_MIN_SIZE;
494 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700495 }
496 }
497
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800498 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700499 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800500 * record is based on (normally the root activity intent).
501 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700502 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800503 final Intent intent = new Intent(r.intent);
504 // Correct the activity intent for aliasing. The task record intent will always be based on
505 // the real activity that will be launched not the alias, so we need to use an intent with
506 // the component name pointing to the real activity not the alias in the activity record.
507 intent.setComponent(r.realActivity);
508 return this.intent.filterEquals(intent);
509 }
510
Craig Mautner84984fa2014-06-19 11:19:20 -0700511 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800512 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
513 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700514 }
515
516 int getTaskToReturnTo() {
517 return mTaskToReturnTo;
518 }
519
Craig Mautnera228ae92014-07-09 05:44:55 -0700520 void setPrevAffiliate(TaskRecord prevAffiliate) {
521 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800522 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700523 }
524
525 void setNextAffiliate(TaskRecord nextAffiliate) {
526 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800527 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700528 }
529
Andrii Kulian02b7a832016-10-06 23:11:56 -0700530 ActivityStack getStack() {
531 return mStack;
532 }
533
Andrii Kulian1779e612016-10-12 21:58:25 -0700534 /** Must be used for setting parent stack because it performs configuration updates. */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700535 void setStack(ActivityStack stack) {
536 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700537 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700538 }
539
540 /**
541 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
542 */
543 int getStackId() {
544 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
545 }
546
Andrii Kulian1779e612016-10-12 21:58:25 -0700547 @Override
548 protected int getChildCount() {
549 return 0;
550 }
551
552 @Override
553 protected ConfigurationContainer getChildAt(int index) {
554 return null;
555 }
556
557 @Override
558 protected ConfigurationContainer getParent() {
559 return mStack;
560 }
561
Craig Mautnera228ae92014-07-09 05:44:55 -0700562 // Close up recents linked list.
563 void closeRecentsChain() {
564 if (mPrevAffiliate != null) {
565 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
566 }
567 if (mNextAffiliate != null) {
568 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
569 }
570 setPrevAffiliate(null);
571 setNextAffiliate(null);
572 }
573
Winson Chung740c3ac2014-11-12 16:14:38 -0800574 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700575 disposeThumbnail();
576 closeRecentsChain();
577 if (inRecents) {
578 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800579 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700580 }
581 }
582
Craig Mautnera228ae92014-07-09 05:44:55 -0700583 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
584 closeRecentsChain();
585 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700586 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700587 // Find the end
588 while (taskToAffiliateWith.mNextAffiliate != null) {
589 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
590 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
591 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
592 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
593 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
594 nextRecents.setPrevAffiliate(null);
595 }
596 taskToAffiliateWith.setNextAffiliate(null);
597 break;
598 }
599 taskToAffiliateWith = nextRecents;
600 }
601 taskToAffiliateWith.setNextAffiliate(this);
602 setPrevAffiliate(taskToAffiliateWith);
603 setNextAffiliate(null);
604 }
605
Winson Chung096f36b2014-08-20 15:39:01 -0700606 /**
Winsonc809cbb2015-11-02 12:06:15 -0800607 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700608 * @return whether the thumbnail was set
609 */
Winsonc809cbb2015-11-02 12:06:15 -0800610 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -0800611 int taskWidth = 0;
612 int taskHeight = 0;
613 if (mBounds != null) {
614 // Non-fullscreen tasks
615 taskWidth = mBounds.width();
616 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700617 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -0800618 // Fullscreen tasks
619 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700620 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -0800621 taskWidth = displaySize.x;
622 taskHeight = displaySize.y;
623 } else {
624 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
625 }
Andrii Kulian1779e612016-10-12 21:58:25 -0700626 // We need to provide the current orientation of the display on which this task resides,
627 // not the orientation of the task.
628 final int orientation =
629 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
630 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -0800631 }
632
633 /**
634 * Sets the last thumbnail with the current task bounds.
635 * @return whether the thumbnail was set
636 */
637 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
638 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700639 if (mLastThumbnail != thumbnail) {
640 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800641 mLastThumbnailInfo.taskWidth = taskWidth;
642 mLastThumbnailInfo.taskHeight = taskHeight;
643 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700644 if (thumbnail == null) {
645 if (mLastThumbnailFile != null) {
646 mLastThumbnailFile.delete();
647 }
648 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800649 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700650 }
Winson Chung096f36b2014-08-20 15:39:01 -0700651 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700652 }
Winson Chung096f36b2014-08-20 15:39:01 -0700653 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700654 }
655
656 void getLastThumbnail(TaskThumbnail thumbs) {
657 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800658 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700659 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700660 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800661 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800662 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700663 }
Winson Chung096f36b2014-08-20 15:39:01 -0700664 // Only load the thumbnail file if we don't have a thumbnail
665 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700666 try {
667 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
668 ParcelFileDescriptor.MODE_READ_ONLY);
669 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700670 }
671 }
672 }
673
Winsonc809cbb2015-11-02 12:06:15 -0800674 /**
675 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
676 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700677 void freeLastThumbnail() {
678 mLastThumbnail = null;
679 }
680
Winsonc809cbb2015-11-02 12:06:15 -0800681 /**
682 * Removes all associated thumbnail data when a task is removed or pruned from recents.
683 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700684 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800685 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700686 mLastThumbnail = null;
687 lastDescription = null;
688 }
689
Winson Chung1147c402014-05-14 11:05:00 -0700690 /** Returns the intent for the root activity for this task */
691 Intent getBaseIntent() {
692 return intent != null ? intent : affinityIntent;
693 }
694
Winson Chung3b3f4642014-04-22 10:08:18 -0700695 /** Returns the first non-finishing activity from the root. */
696 ActivityRecord getRootActivity() {
697 for (int i = 0; i < mActivities.size(); i++) {
698 final ActivityRecord r = mActivities.get(i);
699 if (r.finishing) {
700 continue;
701 }
702 return r;
703 }
704 return null;
705 }
706
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800707 ActivityRecord getTopActivity() {
708 for (int i = mActivities.size() - 1; i >= 0; --i) {
709 final ActivityRecord r = mActivities.get(i);
710 if (r.finishing) {
711 continue;
712 }
713 return r;
714 }
715 return null;
716 }
717
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700718 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700719 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700720 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
721 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -0700722 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700723 return r;
724 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700725 }
726 }
727 return null;
728 }
729
Wale Ogunwale3b232392016-05-13 15:37:13 -0700730 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700731 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700732 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
733 ActivityRecord r = mActivities.get(activityNdx);
734 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -0700735 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700736 continue;
737 }
738 return r;
739 }
740 }
741 return null;
742 }
743
Chong Zhang87761972016-08-22 13:53:24 -0700744 boolean okToShowLocked() {
745 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
746 // okay to show the activity when locked.
747 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
748 || topRunningActivityLocked() != null;
749 }
750
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800751 void setFrontOfTask() {
752 setFrontOfTask(null);
753 }
754
Craig Mautner3b475fe2013-12-16 15:58:31 -0800755 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800756 void setFrontOfTask(ActivityRecord newTop) {
757 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
758 // as not front. This is needed in situations where the current front activity in the
759 // task isn't finished yet and we want to set the front to the activity moved to the front
760 // of the task.
761 boolean foundFront = newTop != null ? true : false;
762
Craig Mautner3b475fe2013-12-16 15:58:31 -0800763 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800764 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800765 final ActivityRecord r = mActivities.get(activityNdx);
766 if (foundFront || r.finishing) {
767 r.frontOfTask = false;
768 } else {
769 r.frontOfTask = true;
770 // Set frontOfTask false for every following activity.
771 foundFront = true;
772 }
773 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000774 if (!foundFront && numActivities > 0) {
775 // All activities of this task are finishing. As we ought to have a frontOfTask
776 // activity, make the bottom activity front.
777 mActivities.get(0).frontOfTask = true;
778 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800779 if (newTop != null) {
780 newTop.frontOfTask = true;
781 }
Craig Mautner3b475fe2013-12-16 15:58:31 -0800782 }
783
Craig Mautnerde4ef022013-04-07 19:01:33 -0700784 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800785 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700786 */
787 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700788 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
789 "Removing and adding activity " + newTop
790 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -0700791
Craig Mautnerde4ef022013-04-07 19:01:33 -0700792 mActivities.remove(newTop);
793 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700794 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -0800795
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800796 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700797 }
798
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800799 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800800 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800801 }
802
803 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700804 addActivityAtIndex(mActivities.size(), r);
805 }
806
807 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700808 // 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 -0800809 if (!mActivities.remove(r) && r.fullscreen) {
810 // Was not previously in list.
811 numFullscreen++;
812 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700813 // Only set this based on the first activity
814 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700815 taskType = r.mActivityType;
816 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700817 mCallingUid = r.launchedFromUid;
818 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700819 // Clamp to [1, max].
820 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
821 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -0700822 } else {
823 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -0700824 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -0700825 }
Wale Ogunwale3b232392016-05-13 15:37:13 -0700826
827 final int size = mActivities.size();
828
829 if (index == size && size > 0) {
830 final ActivityRecord top = mActivities.get(size - 1);
831 if (top.mTaskOverlay) {
832 // Place below the task overlay activity since the overlay activity should always
833 // be on top.
834 index--;
835 }
836 }
837
Craig Mautner77878772013-03-04 19:46:24 -0800838 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700839 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -0700840 if (r.isPersistable()) {
841 mService.notifyTaskPersisterLocked(this, false);
842 }
Craig Mautner77878772013-03-04 19:46:24 -0800843 }
844
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800845 /** @return true if this was the last activity in the task */
846 boolean removeActivity(ActivityRecord r) {
847 if (mActivities.remove(r) && r.fullscreen) {
848 // Was previously in list.
849 numFullscreen--;
850 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700851 if (r.isPersistable()) {
852 mService.notifyTaskPersisterLocked(this, false);
853 }
Wale Ogunwale89182d52016-03-11 10:38:36 -0800854
Andrii Kulian02b7a832016-10-06 23:11:56 -0700855 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -0800856 // We normally notify listeners of task stack changes on pause, however pinned stack
857 // activities are normally in the paused state so no notification will be sent there
858 // before the activity is removed. We send it here so instead.
859 mService.notifyTaskStackChangedLocked();
860 }
861
Craig Mautner41326202014-06-20 14:38:21 -0700862 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -0700863 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -0700864 }
865 updateEffectiveIntent();
866 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800867 }
868
Craig Mautner41db4a72014-05-07 17:20:56 -0700869 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700870 // We will automatically remove the task either if it has explicitly asked for
871 // this, or it is empty and has never contained an activity that got shown to
872 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700873 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -0700874 }
875
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700876 /**
877 * Completely remove all activities associated with an existing
878 * task starting at a specified index.
879 */
880 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700881 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700882 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700883 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700884 if (r.finishing) {
885 continue;
886 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700887 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700888 // Task was restored from persistent storage.
889 r.takeFromHistory();
890 mActivities.remove(activityNdx);
891 --activityNdx;
892 --numActivities;
Andrii Kulian02b7a832016-10-06 23:11:56 -0700893 } else if (mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -0800894 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700895 --activityNdx;
896 --numActivities;
897 }
898 }
899 }
900
901 /**
902 * Completely remove all activities associated with an existing task.
903 */
904 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -0700905 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700906 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -0700907 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700908 }
909
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800910 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
911 mReuseTask = true;
912 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
913 mReuseTask = false;
914 return result;
915 }
916
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700917 /**
918 * Perform clear operation as requested by
919 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
920 * stack to the given task, then look for
921 * an instance of that activity in the stack and, if found, finish all
922 * activities on top of it and return the instance.
923 *
924 * @param newR Description of the new activity being started.
925 * @return Returns the old activity that should be continued to be used,
926 * or null if none was found.
927 */
928 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700929 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700930 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700931 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700932 if (r.finishing) {
933 continue;
934 }
935 if (r.realActivity.equals(newR.realActivity)) {
936 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -0700937 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700938
939 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700940 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700941 if (r.finishing) {
942 continue;
943 }
944 ActivityOptions opts = r.takeOptionsLocked();
945 if (opts != null) {
946 ret.updateOptionsLocked(opts);
947 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700948 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -0800949 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700950 --activityNdx;
951 --numActivities;
952 }
953 }
954
955 // Finally, if this is a normal launch mode (that is, not
956 // expecting onNewIntent()), then we will finish the current
957 // instance of the activity so a new fresh one can be started.
958 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +0900959 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
960 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700961 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700962 if (mStack != null) {
963 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -0700964 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
965 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700966 return null;
967 }
968 }
969
970 return ret;
971 }
972 }
973
974 return null;
975 }
976
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700977 public TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700978 if (mStack != null) {
979 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700980 if (resumedActivity != null && resumedActivity.task == this) {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700981 final Bitmap thumbnail = mStack.screenshotActivitiesLocked(resumedActivity);
Winsonc809cbb2015-11-02 12:06:15 -0800982 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -0700983 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700984 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700985 final TaskThumbnail taskThumbnail = new TaskThumbnail();
986 getLastThumbnail(taskThumbnail);
987 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700988 }
989
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700990 public void removeTaskActivitiesLocked() {
991 // Just remove the entire task.
992 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700993 }
994
Craig Mautner432f64e2015-05-20 14:59:57 -0700995 String lockTaskAuthToString() {
996 switch (mLockTaskAuth) {
997 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
998 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
999 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1000 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001001 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001002 default: return "unknown=" + mLockTaskAuth;
1003 }
1004 }
1005
Craig Mautner15df08a2015-04-01 12:17:18 -07001006 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001007 if (!mPrivileged &&
1008 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1009 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1010 // Non-priv apps are not allowed to use always or never, fall back to default
1011 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1012 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001013 switch (mLockTaskMode) {
1014 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1015 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1016 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1017 break;
1018
1019 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001020 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001021 break;
1022
1023 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001024 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001025 break;
1026
1027 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1028 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1029 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1030 break;
1031 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001032 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1033 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001034 }
1035
1036 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001037 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1038 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001039 return false;
1040 }
1041 String[] packages = mService.mLockTaskPackages.get(userId);
1042 if (packages == null) {
1043 return false;
1044 }
1045 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001046 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001047 return true;
1048 }
1049 }
1050 return false;
1051 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001052
Craig Mautnera82aa092013-09-13 15:34:08 -07001053 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001054 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001055 }
1056
Wale Ogunwale74e26592016-02-05 11:48:37 -08001057 boolean isRecentsTask() {
1058 return taskType == RECENTS_ACTIVITY_TYPE;
1059 }
1060
Craig Mautner86d67a42013-05-14 10:34:38 -07001061 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001062 return taskType == APPLICATION_ACTIVITY_TYPE;
1063 }
1064
1065 boolean isOverHomeStack() {
1066 return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001067 }
1068
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001069 boolean isResizeable() {
1070 return !isHomeTask() && (mService.mForceResizableActivities
Jorim Jaggi8202b2a2016-02-03 19:24:31 -08001071 || ActivityInfo.isResizeableMode(mResizeMode)) && !mTemporarilyUnresizable;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001072 }
1073
Jiaquan Hedd1e66f2016-06-15 15:15:12 -07001074 boolean isOnTopLauncher() {
1075 return isHomeTask() && mIsOnTopLauncher;
1076 }
1077
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001078 boolean inCropWindowsResizeMode() {
1079 return !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS;
1080 }
1081
Wale Ogunwale513346d2016-01-27 10:55:01 -08001082 boolean canGoInDockedStack() {
1083 return isResizeable() || inCropWindowsResizeMode();
1084 }
1085
Craig Mautner525f3d92013-05-07 14:01:50 -07001086 /**
1087 * Find the activity in the history stack within the given task. Returns
1088 * the index within the history at which it's found, or < 0 if not found.
1089 */
1090 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1091 final ComponentName realActivity = r.realActivity;
1092 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1093 ActivityRecord candidate = mActivities.get(activityNdx);
1094 if (candidate.finishing) {
1095 continue;
1096 }
1097 if (candidate.realActivity.equals(realActivity)) {
1098 return candidate;
1099 }
1100 }
1101 return null;
1102 }
1103
Winson Chunga449dc02014-05-16 11:15:04 -07001104 /** Updates the last task description values. */
1105 void updateTaskDescription() {
1106 // Traverse upwards looking for any break between main task activities and
1107 // utility activities.
1108 int activityNdx;
1109 final int numActivities = mActivities.size();
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001110 final boolean relinquish = numActivities == 0 ? false :
1111 (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001112 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001113 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001114 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001115 if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1116 // This will be the top activity for determining taskDescription. Pre-inc to
1117 // overcome initial decrement below.
1118 ++activityNdx;
1119 break;
1120 }
Winson Chunga449dc02014-05-16 11:15:04 -07001121 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001122 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001123 break;
1124 }
1125 }
1126 if (activityNdx > 0) {
1127 // Traverse downwards starting below break looking for set label, icon.
1128 // Note that if there are activities in the task but none of them set the
1129 // recent activity values, then we do not fall back to the last set
1130 // values in the TaskRecord.
1131 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001132 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001133 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001134 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001135 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1136 final ActivityRecord r = mActivities.get(activityNdx);
1137 if (r.taskDescription != null) {
1138 if (label == null) {
1139 label = r.taskDescription.getLabel();
1140 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001141 if (iconFilename == null) {
1142 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001143 }
1144 if (colorPrimary == 0) {
1145 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001146 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001147 if (colorBackground == 0) {
1148 colorBackground = r.taskDescription.getBackgroundColor();
1149 }
Winson Chunga449dc02014-05-16 11:15:04 -07001150 }
1151 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001152 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1153 colorBackground);
Winson Chungec396d62014-08-06 17:08:00 -07001154 // Update the task affiliation color if we are the parent of the group
1155 if (taskId == mAffiliatedTaskId) {
1156 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1157 }
Winson Chunga449dc02014-05-16 11:15:04 -07001158 }
1159 }
1160
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001161 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001162 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001163 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001164 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001165 final ActivityRecord r = mActivities.get(activityNdx);
1166 if (r.finishing) {
1167 continue;
1168 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001169 effectiveNdx = activityNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001170 if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1171 break;
1172 }
1173 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001174 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001175 }
1176
1177 void updateEffectiveIntent() {
1178 final int effectiveRootIndex = findEffectiveRootIndex();
1179 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001180 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001181 }
1182
Craig Mautner21d24a22014-04-23 11:45:37 -07001183 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001184 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001185
1186 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1187 if (realActivity != null) {
1188 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1189 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001190 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001191 if (origActivity != null) {
1192 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1193 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001194 // Write affinity, and root affinity if it is different from affinity.
1195 // We use the special string "@" for a null root affinity, so we can identify
1196 // later whether we were given a root affinity or should just make it the
1197 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001198 if (affinity != null) {
1199 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001200 if (!affinity.equals(rootAffinity)) {
1201 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1202 }
1203 } else if (rootAffinity != null) {
1204 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001205 }
1206 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001207 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001208 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1209 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001210 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001211 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001212 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001213 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001214 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001215 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001216 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001217 if (lastDescription != null) {
1218 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1219 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001220 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001221 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001222 }
Winson Chung36f3f032016-09-08 23:29:43 +00001223 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001224 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001225 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1226 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1227 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001228 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1229 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001230 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001231 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001232 if (mLastNonFullscreenBounds != null) {
1233 out.attribute(
1234 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001235 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001236 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1237 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Winson Chung2cb86c72014-06-25 12:03:30 -07001238
Craig Mautner21d24a22014-04-23 11:45:37 -07001239 if (affinityIntent != null) {
1240 out.startTag(null, TAG_AFFINITYINTENT);
1241 affinityIntent.saveToXml(out);
1242 out.endTag(null, TAG_AFFINITYINTENT);
1243 }
1244
Winson Chung36f3f032016-09-08 23:29:43 +00001245 out.startTag(null, TAG_INTENT);
1246 intent.saveToXml(out);
1247 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001248
1249 final ArrayList<ActivityRecord> activities = mActivities;
1250 final int numActivities = activities.size();
1251 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1252 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001253 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001254 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1255 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001256 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001257 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001258 break;
1259 }
1260 out.startTag(null, TAG_ACTIVITY);
1261 r.saveToXml(out);
1262 out.endTag(null, TAG_ACTIVITY);
1263 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001264 }
1265
Winson Chung36f3f032016-09-08 23:29:43 +00001266 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1267 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001268 Intent intent = null;
1269 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001270 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001271 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001272 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001273 ComponentName origActivity = null;
1274 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001275 String rootAffinity = null;
1276 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001277 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001278 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001279 boolean askedCompatMode = false;
1280 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001281 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001282 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001283 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001284 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001285 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001286 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001287 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001288 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001289 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001290 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001291 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001292 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001293 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001294 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001295 int prevTaskId = INVALID_TASK_ID;
1296 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001297 int callingUid = -1;
1298 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001299 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001300 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001301 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001302 int minWidth = INVALID_MIN_SIZE;
1303 int minHeight = INVALID_MIN_SIZE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001304
1305 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1306 final String attrName = in.getAttributeName(attrNdx);
1307 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001308 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1309 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001310 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001311 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001312 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1313 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001314 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1315 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001316 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1317 origActivity = ComponentName.unflattenFromString(attrValue);
1318 } else if (ATTR_AFFINITY.equals(attrName)) {
1319 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001320 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1321 rootAffinity = attrValue;
1322 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001323 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001324 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001325 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001326 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001327 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001328 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001329 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001330 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001331 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001332 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001333 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001334 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001335 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001336 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001337 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001338 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001339 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001340 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001341 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1342 lastDescription = attrValue;
1343 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001344 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001345 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001346 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001347 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1348 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001349 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1350 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001351 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001352 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001353 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001354 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001355 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001356 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001357 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001358 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001359 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001360 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001361 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1362 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001363 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001364 resizeMode = Integer.parseInt(attrValue);
Wale Ogunwaled829d362016-02-10 19:24:49 -08001365 resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS)
1366 ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001367 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001368 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001369 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001370 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001371 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1372 minWidth = Integer.parseInt(attrValue);
1373 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1374 minHeight = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001375 } else {
1376 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1377 }
1378 }
1379
1380 int event;
1381 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001382 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001383 if (event == XmlPullParser.START_TAG) {
1384 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001385 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1386 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001387 if (TAG_AFFINITYINTENT.equals(name)) {
1388 affinityIntent = Intent.restoreFromXml(in);
1389 } else if (TAG_INTENT.equals(name)) {
1390 intent = Intent.restoreFromXml(in);
1391 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001392 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001393 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1394 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001395 if (activity != null) {
1396 activities.add(activity);
1397 }
1398 } else {
1399 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1400 XmlUtils.skipCurrentTag(in);
1401 }
1402 }
1403 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001404 if (!hasRootAffinity) {
1405 rootAffinity = affinity;
1406 } else if ("@".equals(rootAffinity)) {
1407 rootAffinity = null;
1408 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001409 if (effectiveUid <= 0) {
1410 Intent checkIntent = intent != null ? intent : affinityIntent;
1411 effectiveUid = 0;
1412 if (checkIntent != null) {
1413 IPackageManager pm = AppGlobals.getPackageManager();
1414 try {
1415 ApplicationInfo ai = pm.getApplicationInfo(
1416 checkIntent.getComponent().getPackageName(),
1417 PackageManager.GET_UNINSTALLED_PACKAGES
1418 | PackageManager.GET_DISABLED_COMPONENTS, userId);
1419 if (ai != null) {
1420 effectiveUid = ai.uid;
1421 }
1422 } catch (RemoteException e) {
1423 }
1424 }
1425 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1426 + ": effectiveUid=" + effectiveUid);
1427 }
1428
Winson Chung36f3f032016-09-08 23:29:43 +00001429 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001430 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001431 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1432 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001433 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001434 taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged,
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001435 realActivitySuspended, userSetupComplete, minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001436 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001437
1438 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001439 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001440 }
1441
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001442 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001443 return task;
1444 }
1445
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001446 private void adjustForMinimalTaskDimensions(Rect bounds) {
1447 if (bounds == null) {
1448 return;
1449 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001450 int minWidth = mMinWidth;
1451 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001452 // If the task has no requested minimal size, we'd like to enforce a minimal size
1453 // so that the user can not render the task too small to manipulate. We don't need
1454 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001455 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001456 if (minWidth == INVALID_MIN_SIZE) {
1457 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001458 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001459 if (minHeight == INVALID_MIN_SIZE) {
1460 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001461 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001462 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001463 final boolean adjustWidth = minWidth > bounds.width();
1464 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001465 if (!(adjustWidth || adjustHeight)) {
1466 return;
1467 }
1468
1469 if (adjustWidth) {
1470 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001471 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001472 } else {
1473 // Either left bounds match, or neither match, or the previous bounds were
1474 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001475 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001476 }
1477 }
1478 if (adjustHeight) {
1479 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001480 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001481 } else {
1482 // Either top bounds match, or neither match, or the previous bounds were
1483 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001484 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001485 }
1486 }
1487 }
1488
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001489 /**
1490 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001491 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07001492 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001493 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001494 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001495 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1496 }
1497
1498 /**
1499 * Update task's override configuration based on the bounds.
1500 * @param bounds The bounds of the task.
1501 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1502 * subtract the navigation bar/status bar size from the screen size reported
1503 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07001504 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001505 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001506 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001507 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07001508 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001509 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001510 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08001511 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07001512 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001513
1514 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001515 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001516 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001517 mLastNonFullscreenBounds = mBounds;
1518 }
1519 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07001520 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07001521 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001522 mTmpRect.set(bounds);
1523 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001524 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001525 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001526 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001527 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001528 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001529 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001530 mLastNonFullscreenBounds = mBounds;
1531 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001532 calculateOverrideConfig(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07001533 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001534 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001535 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001536
1537 if (mFullscreen != oldFullscreen) {
Andrii Kulian933076d2016-03-29 17:04:42 -07001538 mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001539 }
1540
Andrii Kulian1779e612016-10-12 21:58:25 -07001541 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001542 }
1543
Andrii Kuliandaea3572016-04-08 13:20:51 -07001544 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds,
1545 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001546 mTmpRect2.set(inInsetBounds);
1547 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1548 int leftInset = mTmpRect2.left - inInsetBounds.left;
1549 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001550 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1551 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001552 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1553 }
1554
Andrii Kuliandaea3572016-04-08 13:20:51 -07001555 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds,
1556 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001557 mTmpRect2.set(inInsetBounds);
1558 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1559 int leftInset = mTmpRect2.left - inInsetBounds.left;
1560 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001561 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1562 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi0a932142016-02-01 17:42:25 -08001563 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1564 }
1565
Andrii Kulian1779e612016-10-12 21:58:25 -07001566 /** Clears passed config and fills it with new override values. */
1567 private Configuration calculateOverrideConfig(Configuration config, Rect bounds,
1568 Rect insetBounds, boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001569 mTmpNonDecorBounds.set(bounds);
1570 mTmpStableBounds.set(bounds);
1571 subtractNonDecorInsets(
Andrii Kuliandaea3572016-04-08 13:20:51 -07001572 mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds,
1573 overrideWidth, overrideHeight);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001574 subtractStableInsets(
Andrii Kuliandaea3572016-04-08 13:20:51 -07001575 mTmpStableBounds, insetBounds != null ? insetBounds : bounds,
1576 overrideWidth, overrideHeight);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001577
Andrii Kulian1779e612016-10-12 21:58:25 -07001578 // For calculating screenWidthDp, screenHeightDp, we use the stable inset screen area,
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001579 // i.e. the screen area without the system bars.
Andrii Kulian1779e612016-10-12 21:58:25 -07001580 // Additionally task dimensions should not be bigger than its parents dimensions.
1581 final Configuration parentConfig = getParent().getConfiguration();
1582 config.unset();
1583 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001584 config.screenWidthDp =
Andrii Kulian1779e612016-10-12 21:58:25 -07001585 Math.min((int)(mTmpStableBounds.width() / density), parentConfig.screenWidthDp);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001586 config.screenHeightDp =
Andrii Kulian1779e612016-10-12 21:58:25 -07001587 Math.min((int)(mTmpStableBounds.height() / density), parentConfig.screenHeightDp);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001588
1589 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001590 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1591 ? Configuration.ORIENTATION_PORTRAIT
1592 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001593
Jorim Jaggi85639432016-05-06 17:27:55 -07001594 // For calculating screen layout, we need to use the non-decor inset screen area for the
1595 // calculation for compatibility reasons, i.e. screen area without system bars that could
1596 // never go away in Honeycomb.
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001597 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1598 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07001599 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
1600 // calculation with partial default.
1601 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001602 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07001603 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07001604 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
1605
1606 config.smallestScreenWidthDp = mService.mWindowManager.getSmallestWidthForTaskBounds(
1607 insetBounds != null ? insetBounds : bounds);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001608 return config;
1609 }
1610
1611 /**
1612 * Using the existing configuration {@param config}, creates a new task override config such
1613 * that all the fields that are usually set in an override config are set to the ones in
1614 * {@param config}.
1615 */
1616 Configuration extractOverrideConfig(Configuration config) {
Andrii Kulian1779e612016-10-12 21:58:25 -07001617 final Configuration extracted = new Configuration();
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001618 extracted.screenWidthDp = config.screenWidthDp;
1619 extracted.screenHeightDp = config.screenHeightDp;
1620 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1621 extracted.orientation = config.orientation;
Andrii Kulian1779e612016-10-12 21:58:25 -07001622 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout.
1623 extracted.screenLayout = config.screenLayout & (Configuration.SCREENLAYOUT_LONG_MASK
1624 | Configuration.SCREENLAYOUT_SIZE_MASK | Configuration.SCREENLAYOUT_COMPAT_NEEDED);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001625 return extracted;
1626 }
1627
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001628 Rect updateOverrideConfigurationFromLaunchBounds() {
1629 final Rect bounds = validateBounds(getLaunchBounds());
1630 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07001631 if (bounds != null) {
1632 bounds.set(mBounds);
1633 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001634 return bounds;
1635 }
1636
1637 static Rect validateBounds(Rect bounds) {
1638 if (bounds != null && bounds.isEmpty()) {
1639 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1640 return null;
1641 }
1642 return bounds;
1643 }
1644
Wale Ogunwale935e5022015-11-10 12:36:10 -08001645 /** Updates the task's bounds and override configuration to match what is expected for the
1646 * input stack. */
1647 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001648 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001649 return;
1650 }
1651
1652 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001653 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001654 throw new IllegalArgumentException("Can not position non-resizeable task="
1655 + this + " in stack=" + inStack);
1656 }
1657 if (mBounds != null) {
1658 return;
1659 }
1660 if (mLastNonFullscreenBounds != null) {
1661 updateOverrideConfiguration(mLastNonFullscreenBounds);
1662 } else {
1663 inStack.layoutTaskInStack(this, null);
1664 }
1665 } else {
1666 updateOverrideConfiguration(inStack.mBounds);
1667 }
1668 }
1669
Chong Zhang0fa656b2015-08-31 15:17:21 -07001670 /**
1671 * Returns the correct stack to use based on task type and currently set bounds,
1672 * regardless of the focused stack and current stack association of the task.
1673 * The task will be moved (and stack focus changed) later if necessary.
1674 */
1675 int getLaunchStackId() {
1676 if (!isApplicationTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001677 return HOME_STACK_ID;
1678 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001679 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001680 return FREEFORM_WORKSPACE_STACK_ID;
1681 }
1682 return FULLSCREEN_WORKSPACE_STACK_ID;
1683 }
1684
1685 /** Returns the bounds that should be used to launch this task. */
1686 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001687 // If we're over lockscreen, forget about stack bounds and use fullscreen.
1688 if (mService.mLockScreenShown == LOCK_SCREEN_SHOWN) {
1689 return null;
1690 }
1691
Andrii Kulian02b7a832016-10-06 23:11:56 -07001692 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08001693 return null;
1694 }
1695
Andrii Kulian02b7a832016-10-06 23:11:56 -07001696 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08001697 if (stackId == HOME_STACK_ID
1698 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001699 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001700 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07001701 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001702 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001703 }
1704 return mLastNonFullscreenBounds;
1705 }
1706
Wale Ogunwale39381972015-12-17 17:15:29 -08001707 boolean canMatchRootAffinity() {
1708 // We don't allow root affinity matching on the pinned stack as no other task should
1709 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001710 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08001711 }
1712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001714 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001715 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1716 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08001717 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001718 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001719 if (affinity != null || rootAffinity != null) {
1720 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
1721 if (affinity == null || !affinity.equals(rootAffinity)) {
1722 pw.print(" root="); pw.println(rootAffinity);
1723 } else {
1724 pw.println();
1725 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001726 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07001727 if (voiceSession != null || voiceInteractor != null) {
1728 pw.print(prefix); pw.print("VOICE: session=0x");
1729 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
1730 pw.print(" interactor=0x");
1731 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
1732 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001733 if (intent != null) {
1734 StringBuilder sb = new StringBuilder(128);
1735 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001736 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001737 sb.append('}');
1738 pw.println(sb.toString());
1739 }
1740 if (affinityIntent != null) {
1741 StringBuilder sb = new StringBuilder(128);
1742 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001743 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001744 sb.append('}');
1745 pw.println(sb.toString());
1746 }
1747 if (origActivity != null) {
1748 pw.print(prefix); pw.print("origActivity=");
1749 pw.println(origActivity.flattenToShortString());
1750 }
1751 if (realActivity != null) {
1752 pw.print(prefix); pw.print("realActivity=");
1753 pw.println(realActivity.flattenToShortString());
1754 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07001755 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
1756 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001757 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001758 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001759 pw.print(" numFullscreen="); pw.print(numFullscreen);
1760 pw.print(" taskType="); pw.print(taskType);
1761 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
1762 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001763 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
1764 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001765 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
1766 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07001767 pw.print(" mReuseTask="); pw.print(mReuseTask);
1768 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001769 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08001770 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
1771 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
1772 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07001773 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
1774 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
1775 pw.print(" (");
1776 if (mPrevAffiliate == null) {
1777 pw.print("null");
1778 } else {
1779 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
1780 }
1781 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
1782 pw.print(" (");
1783 if (mNextAffiliate == null) {
1784 pw.print("null");
1785 } else {
1786 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
1787 }
1788 pw.println(")");
1789 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001790 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001791 if (!askedCompatMode || !inRecents || !isAvailable) {
1792 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
1793 pw.print(" inRecents="); pw.print(inRecents);
1794 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001795 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001796 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001797 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
1798 if (lastDescription != null) {
1799 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
1800 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001801 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001802 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
1803 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
1804 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00001805 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001806 pw.print(" lastActiveTime=" + lastActiveTime);
1807 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 }
1809
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001810 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001812 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001813 if (stringName != null) {
1814 sb.append(stringName);
1815 sb.append(" U=");
1816 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08001817 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07001818 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07001819 sb.append(" sz=");
1820 sb.append(mActivities.size());
1821 sb.append('}');
1822 return sb.toString();
1823 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001824 sb.append("TaskRecord{");
1825 sb.append(Integer.toHexString(System.identityHashCode(this)));
1826 sb.append(" #");
1827 sb.append(taskId);
1828 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001829 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001830 sb.append(affinity);
1831 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001832 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001833 sb.append(intent.getComponent().flattenToShortString());
1834 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001835 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001836 sb.append(affinityIntent.getComponent().flattenToShortString());
1837 } else {
1838 sb.append(" ??");
1839 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001840 stringName = sb.toString();
1841 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 }
1843}