blob: 2745fe509268718e9260d8a5a7e847c6d2d781eb [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.am;
18
Jorim Jaggi0a932142016-02-01 17:42:25 -080019import android.annotation.Nullable;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070020import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070021import android.app.ActivityManager;
Wale Ogunwale3797c222015-10-27 14:21:58 -070022import android.app.ActivityManager.StackId;
Craig Mautner648f69b2014-09-18 14:16:26 -070023import android.app.ActivityManager.TaskDescription;
Jorim Jaggie2c77f92016-12-29 14:57:22 +010024import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwaleff3c66c2015-11-18 19:22:49 -080025import android.app.ActivityManager.TaskThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -080026import android.app.ActivityManager.TaskThumbnailInfo;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070027import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070028import android.app.AppGlobals;
Jorim Jaggi0a932142016-02-01 17:42:25 -080029import android.app.IActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.ComponentName;
31import android.content.Intent;
32import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070033import android.content.pm.ApplicationInfo;
34import android.content.pm.IPackageManager;
35import android.content.pm.PackageManager;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070036import android.content.res.Configuration;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070037import android.graphics.Bitmap;
Jorim Jaggi02886a82016-12-06 09:10:06 -080038import android.graphics.GraphicBuffer;
Winsonc809cbb2015-11-02 12:06:15 -080039import android.graphics.Point;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070040import android.graphics.Rect;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070041import android.os.Debug;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070042import android.os.ParcelFileDescriptor;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070043import android.os.RemoteException;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080044import android.os.Trace;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070045import android.os.UserHandle;
Suprabh Shukla7745c142016-03-07 18:21:10 -080046import android.provider.Settings;
Dianne Hackborn91097de2014-04-04 18:02:06 -070047import android.service.voice.IVoiceInteractionSession;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070048import android.util.DisplayMetrics;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070049import android.util.Slog;
Suprabh Shukla23593142015-11-03 17:31:15 -080050
Dianne Hackborn91097de2014-04-04 18:02:06 -070051import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070052import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080053
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080054import com.android.server.wm.TaskWindowContainerController;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010055import com.android.server.wm.TaskWindowContainerListener;
56
Craig Mautner21d24a22014-04-23 11:45:37 -070057import org.xmlpull.v1.XmlPullParser;
58import org.xmlpull.v1.XmlPullParserException;
59import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060
Craig Mautnerc0ffce52014-07-01 12:38:52 -070061import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070062import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080064import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070065import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080067import static android.app.ActivityManager.RESIZE_MODE_FORCED;
Jorim Jaggi0a932142016-02-01 17:42:25 -080068import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
69import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
70import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
71import static android.app.ActivityManager.StackId.HOME_STACK_ID;
72import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
73import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080074import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080075import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
76import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070077import static android.content.pm.ActivityInfo.FLAG_ON_TOP_LAUNCHER;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070078import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
Jorim Jaggi0a932142016-02-01 17:42:25 -080079import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
80import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
81import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
82import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
skuhne@google.com322347b2016-12-02 12:54:03 -080083import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
84import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
85import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Wale Ogunwaled829d362016-02-10 19:24:49 -080086import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070087import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
88import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggi0a932142016-02-01 17:42:25 -080089import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080090import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Suprabh Shukla7745c142016-03-07 18:21:10 -080091import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080092import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
93import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
94import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
95import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
96import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
97import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
98import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
99import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
100import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
101import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800102import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
103import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
104import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700105import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800106import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
107import static com.android.server.am.ActivityStackSupervisor.CREATE_IF_NEEDED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800108import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800109
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100110final class TaskRecord extends ConfigurationContainer implements TaskWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800111 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700112 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700113 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -0700114 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700115 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800116
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700117 private static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700118 private static final String TAG_INTENT = "intent";
119 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700120 private static final String ATTR_REALACTIVITY = "real_activity";
121 private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700122 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700123 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700124 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700125 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700126 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700127 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700128 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
129 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800130 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700131 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700132 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700133 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700134 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700135 private static final String ATTR_LASTDESCRIPTION = "last_description";
136 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700137 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700138 private static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700139 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
140 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700141 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700142 private static final String ATTR_CALLING_UID = "calling_uid";
143 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800144 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700145 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700146 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700147 private static final String ATTR_MIN_WIDTH = "min_width";
148 private static final String ATTR_MIN_HEIGHT = "min_height";
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700149 private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
Andrii Kulian18d75122016-03-27 20:20:28 -0700150
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700151 // Current version of the task record we persist. Used to check if we need to run any upgrade
152 // code.
153 private static final int PERSIST_TASK_VERSION = 1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700154 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
155
Wale Ogunwale18795a22014-12-03 11:38:33 -0800156 static final int INVALID_TASK_ID = -1;
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700157 private static final int INVALID_MIN_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700160 String affinity; // The affinity name for this task, or null; may change identity.
161 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700162 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
163 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 Intent intent; // The original intent that started the task.
165 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700166 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 ComponentName origActivity; // The non-alias activity component of the intent.
168 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000169 boolean realActivitySuspended; // True if the actual activity component that started the
170 // task is suspended.
Winson Chung36f3f032016-09-08 23:29:43 +0000171 long firstActiveTime; // First time this task was active.
172 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700173 boolean inRecents; // Actually in the recents list?
174 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 boolean rootWasReset; // True if the intent at the root of the task had
176 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700177 boolean autoRemoveRecents; // If true, we should automatically remove the task from
178 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700179 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700180 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 -0800181
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700182 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700183 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800184 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
185 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800186
187 int numFullscreen; // Number of fullscreen activities.
188
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800189 int mResizeMode; // The resize mode of this task and its activities.
190 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800191 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
192 // changes on a temporary basis.
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700193 private int mLockTaskMode; // Which tasklock mode to launch this task in. One of
194 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700195 private boolean mPrivileged; // The root activity application of this task holds
196 // privileged permissions.
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700197 private boolean mIsOnTopLauncher; // Whether this task is an on-top launcher. See
198 // android.R.attr#onTopLauncher.
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700199
Craig Mautner15df08a2015-04-01 12:17:18 -0700200 /** Can't be put in lockTask mode. */
201 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100202 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700203 final static int LOCK_TASK_AUTH_PINNABLE = 1;
204 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
205 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100206 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700207 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100208 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
209 * lockTask task. */
210 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700211 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
212
213 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800214
Winson Chung03a9bae2014-05-02 09:56:12 -0700215 // This represents the last resolved activity values for this task
216 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700217 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700218
Craig Mautnerd2328952013-03-05 12:46:26 -0800219 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700220 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800221
Andrii Kulian02b7a832016-10-06 23:11:56 -0700222 /** Current stack. Setter must always be used to update the value. */
223 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800224
Craig Mautner2c1faed2013-07-23 12:56:02 -0700225 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700226 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700227
Craig Mautner21d24a22014-04-23 11:45:37 -0700228 /** Takes on same value as first root activity */
229 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700230 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700231
232 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
233 * determining the order when restoring. Sign indicates whether last task movement was to front
234 * (positive) or back (negative). Absolute value indicates time. */
235 long mLastTimeMoved = System.currentTimeMillis();
236
Craig Mautner84984fa2014-06-19 11:19:20 -0700237 /** Indication of what to run next when task exits. Use ActivityRecord types.
238 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
239 * task stack. */
240 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700241
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700242 /** If original intent did not allow relinquishing task identity, save that information */
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700243 private boolean mNeverRelinquishIdentity = true;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700244
Craig Mautner362449a2014-06-20 14:04:39 -0700245 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
246 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800247 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700248
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700249 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700250 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700251 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800252 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700253 CharSequence lastDescription; // Last description captured for this item.
254
Craig Mautnera228ae92014-07-09 05:44:55 -0700255 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700256 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700257 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800258 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700259 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800260 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700261
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700262 // For relaunching the task from recents as though it was launched by the original launcher.
263 int mCallingUid;
264 String mCallingPackage;
265
Craig Mautner21d24a22014-04-23 11:45:37 -0700266 final ActivityManagerService mService;
267
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700268 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
269 boolean mFullscreen = true;
270
271 // Bounds of the Task. null for fullscreen tasks.
272 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800273 private final Rect mTmpStableBounds = new Rect();
274 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800275 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800276 private final Rect mTmpRect2 = new Rect();
277
Wale Ogunwale706ed792015-08-02 10:29:44 -0700278 // Last non-fullscreen bounds the task was launched in or resized to.
279 // The information is persisted and used to determine the appropriate stack to launch the
280 // task into on restore.
281 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700282 // Minimal width and height of this task when it's resizeable. -1 means it should use the
283 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700284 int mMinWidth;
285 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700286
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700287 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
288 // This number will be assigned when we evaluate OOM scores for all visible tasks.
289 int mLayerRank = -1;
290
Andrii Kulian1779e612016-10-12 21:58:25 -0700291 /** Helper object used for updating override configuration. */
292 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700293
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800294 private TaskWindowContainerController mWindowContainerController;
295
Craig Mautner21d24a22014-04-23 11:45:37 -0700296 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Wale Ogunwale72919d22016-12-08 18:58:50 -0800297 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, int type) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700298 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700299 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
300 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800301 userId = UserHandle.getUserId(info.applicationInfo.uid);
302 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800303 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700305 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700306 voiceSession = _voiceSession;
307 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700308 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800309 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700310 mCallingUid = info.applicationInfo.uid;
311 mCallingPackage = info.packageName;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800312 taskType = type;
Martijn Coenend4a69702014-06-30 11:12:17 -0700313 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700314 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700315 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700316 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Craig Mautner21d24a22014-04-23 11:45:37 -0700317 }
318
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700319 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800320 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700321 mService = service;
322 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
323 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800324 userId = UserHandle.getUserId(info.applicationInfo.uid);
325 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800326 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700327 taskId = _taskId;
328 mAffiliatedTaskId = _taskId;
329 voiceSession = null;
330 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700331 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800332 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700333 mCallingUid = info.applicationInfo.uid;
334 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700335 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700336 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700337
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700338 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700339 // Clamp to [1, max].
340 maxRecents = Math.min(Math.max(info.maxRecents, 1),
341 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700342
343 taskType = APPLICATION_ACTIVITY_TYPE;
344 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700345 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700346 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700347 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700348 }
349
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800350 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
351 Intent _affinityIntent, String _affinity, String _rootAffinity,
352 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
353 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
354 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
355 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
356 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800357 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
358 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800359 int resizeMode, boolean privileged, boolean _realActivitySuspended,
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700360 boolean userSetupComplete, int minWidth, int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700361 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700362 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
363 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800364 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800365 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700366 taskId = _taskId;
367 intent = _intent;
368 affinityIntent = _affinityIntent;
369 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800370 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700371 voiceSession = null;
372 voiceInteractor = null;
373 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800374 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700375 origActivity = _origActivity;
376 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700377 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700378 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700379 askedCompatMode = _askedCompatMode;
380 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700381 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700382 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800383 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700384 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700385 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700386 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700387 lastDescription = _lastDescription;
388 mActivities = activities;
389 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700390 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700391 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700392 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700393 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700394 mPrevAffiliateTaskId = prevTaskId;
395 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700396 mCallingUid = callingUid;
397 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800398 mResizeMode = resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700399 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700400 mMinWidth = minWidth;
401 mMinHeight = minHeight;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700402 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 }
404
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800405 TaskWindowContainerController getWindowContainerController() {
406 return mWindowContainerController;
407 }
408
409 void createWindowContainer(boolean onTop, boolean showForAllUsers) {
410 if (mWindowContainerController != null) {
411 throw new IllegalArgumentException("Window container=" + mWindowContainerController
412 + " already created for task=" + this);
413 }
414
415 final Rect bounds = updateOverrideConfigurationFromLaunchBounds();
416 final Configuration overrideConfig = getOverrideConfiguration();
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100417 mWindowContainerController = new TaskWindowContainerController(taskId, this, getStackId(),
418 userId, bounds, overrideConfig, mResizeMode, isHomeTask(), isOnTopLauncher(), onTop,
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800419 showForAllUsers);
420 }
421
422 void removeWindowContainer() {
423 mService.mStackSupervisor.removeLockedTaskLocked(this);
424 mWindowContainerController.removeContainer();
425 if (!StackId.persistTaskBounds(getStackId())) {
426 // Reset current bounds for task whose bounds shouldn't be persisted so it uses
427 // default configuration the next time it launches.
428 updateOverrideConfiguration(null);
429 }
430 mService.mTaskChangeNotificationController.notifyTaskRemoved(taskId);
431 mWindowContainerController = null;
432 }
433
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100434 @Override
435 public void onSnapshotChanged(TaskSnapshot snapshot) {
436 mService.mTaskChangeNotificationController.notifyTaskSnapshotChanged(taskId, snapshot);
437 }
438
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800439 void setResizeMode(int resizeMode) {
440 if (mResizeMode == resizeMode) {
441 return;
442 }
443 mResizeMode = resizeMode;
444 mWindowContainerController.setResizeable(resizeMode);
445 mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
446 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
447 }
448
449 void setTaskDockedResizing(boolean resizing) {
450 mWindowContainerController.setTaskDockedResizing(resizing);
451 }
452
453 boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
454 if (!isResizeable()) {
455 Slog.w(TAG, "resizeTask: task " + this + " not resizeable.");
456 return true;
457 }
458
459 // If this is a forced resize, let it go through even if the bounds is not changing,
460 // as we might need a relayout due to surface size change (to/from fullscreen).
461 final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
462 if (Objects.equals(mBounds, bounds) && !forced) {
463 // Nothing to do here...
464 return true;
465 }
466 bounds = validateBounds(bounds);
467
468 if (mWindowContainerController == null) {
469 // Task doesn't exist in window manager yet (e.g. was restored from recents).
470 // All we can do for now is update the bounds so it can be used when the task is
471 // added to window manager.
472 updateOverrideConfiguration(bounds);
473 if (getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
474 // re-restore the task so it can have the proper stack association.
475 mService.mStackSupervisor.restoreRecentTaskLocked(this,
476 FREEFORM_WORKSPACE_STACK_ID);
477 }
478 return true;
479 }
480
481 if (!canResizeToBounds(bounds)) {
482 throw new IllegalArgumentException("resizeTask: Can not resize task=" + this
483 + " to bounds=" + bounds + " resizeMode=" + mResizeMode);
484 }
485
486 // Do not move the task to another stack here.
487 // This method assumes that the task is already placed in the right stack.
488 // we do not mess with that decision and we only do the resize!
489
490 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId);
491
492 final boolean updatedConfig = updateOverrideConfiguration(bounds);
493 // This variable holds information whether the configuration didn't change in a significant
494 // way and the activity was kept the way it was. If it's false, it means the activity had
495 // to be relaunched due to configuration change.
496 boolean kept = true;
497 if (updatedConfig) {
498 final ActivityRecord r = topRunningActivityLocked();
499 if (r != null) {
500 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
501
502 if (!deferResume) {
503 // All other activities must be made visible with their correct configuration.
504 mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
505 if (!kept) {
506 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
507 }
508 }
509 }
510 }
511 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), kept, forced);
512
513 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
514 return kept;
515 }
516
517 // TODO: Investigate combining with the resize() method above.
518 void resizeWindowContainer() {
519 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), false /* relayout */,
520 false /* forced */);
521 }
522
523 // TODO: Remove once we have a stack controller.
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800524 void positionWindowContainerAt(int position) {
525 mWindowContainerController.positionAt(position, mBounds, getOverrideConfiguration());
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800526 }
527
528 // TODO: Replace with moveChildToTop?
529 void moveWindowContainerToTop(boolean includingParents) {
530 if (mWindowContainerController != null) {
531 mWindowContainerController.moveToTop(includingParents);
532 }
533 }
534
535 // TODO: Replace with moveChildToBottom?
536 void moveWindowContainerToBottom() {
537 if (mWindowContainerController != null) {
538 mWindowContainerController.moveToBottom();
539 }
540 }
541
542 void getWindowContainerBounds(Rect bounds) {
543 mWindowContainerController.getBounds(bounds);
544 }
545
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800546 // TODO: Should we be doing all the stuff in ASS.moveTaskToStackLocked?
547 void reparent(int stackId, int position, String reason) {
548 mService.mWindowManager.deferSurfaceLayout();
549
550 try {
551 final ActivityStackSupervisor supervisor = mService.mStackSupervisor;
552 final ActivityStack newStack = supervisor.getStack(stackId,
553 CREATE_IF_NEEDED, false /* toTop */);
554 // Adjust the position for the new parent stack as needed.
555 position = newStack.getAdjustedPositionForTask(this, position, null /* starting */);
556
557 // Must reparent first in window manager to avoid a situation where AM can delete the
558 // we are coming from in WM before we reparent because it became empty.
559 mWindowContainerController.reparent(stackId, position);
560
561 final ActivityStack prevStack = mStack;
562 prevStack.removeTask(this, reason, REMOVE_TASK_MODE_MOVING);
563 newStack.addTask(this, position, reason);
564
565 supervisor.scheduleReportPictureInPictureModeChangedIfNeeded(this, prevStack);
566
567 if (voiceSession != null) {
568 try {
569 voiceSession.taskStarted(intent, taskId);
570 } catch (RemoteException e) {
571 }
572 }
573 } finally {
574 mService.mWindowManager.continueSurfaceLayout();
575 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800576 }
577
578 void cancelWindowTransition() {
579 mWindowContainerController.cancelWindowTransition();
580 }
581
582 void cancelThumbnailTransition() {
583 mWindowContainerController.cancelThumbnailTransition();
584 }
585
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100586 /**
587 * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
588 */
589 TaskSnapshot getSnapshot() {
590
591 // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
592 // synchronized between AM and WM.
593 return mService.mWindowManager.getTaskSnapshot(taskId, userId);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800594 }
595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000597 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700598 if (firstActiveTime == 0) {
599 firstActiveTime = lastActiveTime;
600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000604 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700606
Winson Chungfee26772014-08-05 12:21:52 -0700607 /** Sets the original intent, and the calling uid and package. */
608 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700609 mCallingUid = r.launchedFromUid;
610 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700611 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700612 }
613
614 /** Sets the original intent, _without_ updating the calling uid or package. */
615 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700616 if (intent == null) {
617 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700618 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700619 } else if (mNeverRelinquishIdentity) {
620 return;
621 }
622
623 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700624 if (intent == null) {
625 // If this task already has an intent associated with it, don't set the root
626 // affinity -- we don't want it changing after initially set, but the initially
627 // set value may be null.
628 rootAffinity = affinity;
629 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700630 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700631 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800634 if (_intent != null) {
635 // If this Intent has a selector, we want to clear it for the
636 // recent task since it is not relevant if the user later wants
637 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700638 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800639 _intent = new Intent(_intent);
640 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700641 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800642 }
643 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700644 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 intent = _intent;
646 realActivity = _intent != null ? _intent.getComponent() : null;
647 origActivity = null;
648 } else {
649 ComponentName targetComponent = new ComponentName(
650 info.packageName, info.targetActivity);
651 if (_intent != null) {
652 Intent targetIntent = new Intent(_intent);
653 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800654 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700655 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700656 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700657 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 intent = targetIntent;
659 realActivity = targetComponent;
660 origActivity = _intent.getComponent();
661 } else {
662 intent = null;
663 realActivity = targetComponent;
664 origActivity = new ComponentName(info.packageName, info.name);
665 }
666 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700667
Craig Mautner47b20ba2014-09-17 17:23:44 -0700668 final int intentFlags = intent == null ? 0 : intent.getFlags();
669 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 // Once we are set to an Intent with this flag, we count this
671 // task as having a true root activity.
672 rootWasReset = true;
673 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700674 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000675 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
676 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700677 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700678 // If the activity itself has requested auto-remove, then just always do it.
679 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700680 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
681 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700682 // If the caller has not asked for the document to be retained, then we may
683 // want to turn on auto-remove, depending on whether the target has set its
684 // own document launch mode.
685 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
686 autoRemoveRecents = false;
687 } else {
688 autoRemoveRecents = true;
689 }
690 } else {
691 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700692 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800693 mResizeMode = info.resizeMode;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700694 mIsOnTopLauncher = (info.flags & FLAG_ON_TOP_LAUNCHER) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700695 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700696 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700697 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800699
Andrii Kulian2e751b82016-03-16 16:59:32 -0700700 /** Sets the original minimal width and height. */
701 private void setMinDimensions(ActivityInfo info) {
702 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700703 mMinWidth = info.windowLayout.minWidth;
704 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700705 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700706 mMinWidth = INVALID_MIN_SIZE;
707 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700708 }
709 }
710
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800711 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700712 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800713 * record is based on (normally the root activity intent).
714 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700715 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800716 final Intent intent = new Intent(r.intent);
717 // Correct the activity intent for aliasing. The task record intent will always be based on
718 // the real activity that will be launched not the alias, so we need to use an intent with
719 // the component name pointing to the real activity not the alias in the activity record.
720 intent.setComponent(r.realActivity);
721 return this.intent.filterEquals(intent);
722 }
723
Craig Mautner84984fa2014-06-19 11:19:20 -0700724 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800725 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
726 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700727 }
728
729 int getTaskToReturnTo() {
730 return mTaskToReturnTo;
731 }
732
Craig Mautnera228ae92014-07-09 05:44:55 -0700733 void setPrevAffiliate(TaskRecord prevAffiliate) {
734 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800735 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700736 }
737
738 void setNextAffiliate(TaskRecord nextAffiliate) {
739 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800740 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700741 }
742
Andrii Kulian02b7a832016-10-06 23:11:56 -0700743 ActivityStack getStack() {
744 return mStack;
745 }
746
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800747 /**
748 * Must be used for setting parent stack because it performs configuration updates.
749 * Must be called after adding task as a child to the stack.
750 */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700751 void setStack(ActivityStack stack) {
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800752 if (stack != null && !stack.isInStackLocked(this)) {
753 throw new IllegalStateException("Task must be added as a Stack child first.");
754 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700755 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700756 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700757 }
758
759 /**
760 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
761 */
762 int getStackId() {
763 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
764 }
765
Andrii Kulian1779e612016-10-12 21:58:25 -0700766 @Override
767 protected int getChildCount() {
768 return 0;
769 }
770
771 @Override
772 protected ConfigurationContainer getChildAt(int index) {
773 return null;
774 }
775
776 @Override
777 protected ConfigurationContainer getParent() {
778 return mStack;
779 }
780
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800781 @Override
782 void onParentChanged() {
783 super.onParentChanged();
784 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
785 }
786
Craig Mautnera228ae92014-07-09 05:44:55 -0700787 // Close up recents linked list.
788 void closeRecentsChain() {
789 if (mPrevAffiliate != null) {
790 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
791 }
792 if (mNextAffiliate != null) {
793 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
794 }
795 setPrevAffiliate(null);
796 setNextAffiliate(null);
797 }
798
Winson Chung740c3ac2014-11-12 16:14:38 -0800799 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700800 disposeThumbnail();
801 closeRecentsChain();
802 if (inRecents) {
803 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800804 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700805 }
Jorim Jaggif9084ec2017-01-16 13:16:59 +0100806
807 // TODO: Use window container controller once tasks are better synced between AM and WM
808 mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700809 }
810
Craig Mautnera228ae92014-07-09 05:44:55 -0700811 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
812 closeRecentsChain();
813 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700814 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700815 // Find the end
816 while (taskToAffiliateWith.mNextAffiliate != null) {
817 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
818 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
819 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
820 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
821 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
822 nextRecents.setPrevAffiliate(null);
823 }
824 taskToAffiliateWith.setNextAffiliate(null);
825 break;
826 }
827 taskToAffiliateWith = nextRecents;
828 }
829 taskToAffiliateWith.setNextAffiliate(this);
830 setPrevAffiliate(taskToAffiliateWith);
831 setNextAffiliate(null);
832 }
833
Winson Chung096f36b2014-08-20 15:39:01 -0700834 /**
Winsonc809cbb2015-11-02 12:06:15 -0800835 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700836 * @return whether the thumbnail was set
837 */
Winsonc809cbb2015-11-02 12:06:15 -0800838 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -0800839 int taskWidth = 0;
840 int taskHeight = 0;
841 if (mBounds != null) {
842 // Non-fullscreen tasks
843 taskWidth = mBounds.width();
844 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700845 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -0800846 // Fullscreen tasks
847 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700848 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -0800849 taskWidth = displaySize.x;
850 taskHeight = displaySize.y;
851 } else {
852 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
853 }
Andrii Kulian1779e612016-10-12 21:58:25 -0700854 // We need to provide the current orientation of the display on which this task resides,
855 // not the orientation of the task.
856 final int orientation =
857 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
858 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -0800859 }
860
861 /**
862 * Sets the last thumbnail with the current task bounds.
863 * @return whether the thumbnail was set
864 */
865 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
866 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700867 if (mLastThumbnail != thumbnail) {
868 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800869 mLastThumbnailInfo.taskWidth = taskWidth;
870 mLastThumbnailInfo.taskHeight = taskHeight;
871 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700872 if (thumbnail == null) {
873 if (mLastThumbnailFile != null) {
874 mLastThumbnailFile.delete();
875 }
876 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800877 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700878 }
Winson Chung096f36b2014-08-20 15:39:01 -0700879 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700880 }
Winson Chung096f36b2014-08-20 15:39:01 -0700881 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700882 }
883
884 void getLastThumbnail(TaskThumbnail thumbs) {
885 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800886 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700887 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700888 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800889 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800890 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700891 }
Winson Chung096f36b2014-08-20 15:39:01 -0700892 // Only load the thumbnail file if we don't have a thumbnail
893 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700894 try {
895 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
896 ParcelFileDescriptor.MODE_READ_ONLY);
897 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700898 }
899 }
900 }
901
Winsonc809cbb2015-11-02 12:06:15 -0800902 /**
903 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
904 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700905 void freeLastThumbnail() {
906 mLastThumbnail = null;
907 }
908
Winsonc809cbb2015-11-02 12:06:15 -0800909 /**
910 * Removes all associated thumbnail data when a task is removed or pruned from recents.
911 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700912 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800913 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700914 mLastThumbnail = null;
915 lastDescription = null;
916 }
917
Winson Chung1147c402014-05-14 11:05:00 -0700918 /** Returns the intent for the root activity for this task */
919 Intent getBaseIntent() {
920 return intent != null ? intent : affinityIntent;
921 }
922
Winson Chung3b3f4642014-04-22 10:08:18 -0700923 /** Returns the first non-finishing activity from the root. */
924 ActivityRecord getRootActivity() {
925 for (int i = 0; i < mActivities.size(); i++) {
926 final ActivityRecord r = mActivities.get(i);
927 if (r.finishing) {
928 continue;
929 }
930 return r;
931 }
932 return null;
933 }
934
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800935 ActivityRecord getTopActivity() {
936 for (int i = mActivities.size() - 1; i >= 0; --i) {
937 final ActivityRecord r = mActivities.get(i);
938 if (r.finishing) {
939 continue;
940 }
941 return r;
942 }
943 return null;
944 }
945
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700946 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700947 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700948 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
949 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -0700950 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700951 return r;
952 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700953 }
954 }
955 return null;
956 }
957
Wale Ogunwale3b232392016-05-13 15:37:13 -0700958 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -0700959 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700960 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
961 ActivityRecord r = mActivities.get(activityNdx);
962 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -0700963 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -0700964 continue;
965 }
966 return r;
967 }
968 }
969 return null;
970 }
971
Chong Zhang87761972016-08-22 13:53:24 -0700972 boolean okToShowLocked() {
973 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
974 // okay to show the activity when locked.
975 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
976 || topRunningActivityLocked() != null;
977 }
978
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800979 void setFrontOfTask() {
980 setFrontOfTask(null);
981 }
982
Craig Mautner3b475fe2013-12-16 15:58:31 -0800983 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800984 void setFrontOfTask(ActivityRecord newTop) {
985 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
986 // as not front. This is needed in situations where the current front activity in the
987 // task isn't finished yet and we want to set the front to the activity moved to the front
988 // of the task.
989 boolean foundFront = newTop != null ? true : false;
990
Craig Mautner3b475fe2013-12-16 15:58:31 -0800991 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800992 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800993 final ActivityRecord r = mActivities.get(activityNdx);
994 if (foundFront || r.finishing) {
995 r.frontOfTask = false;
996 } else {
997 r.frontOfTask = true;
998 // Set frontOfTask false for every following activity.
999 foundFront = true;
1000 }
1001 }
Craig Mautner9587ee02014-06-23 15:00:10 +00001002 if (!foundFront && numActivities > 0) {
1003 // All activities of this task are finishing. As we ought to have a frontOfTask
1004 // activity, make the bottom activity front.
1005 mActivities.get(0).frontOfTask = true;
1006 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -08001007 if (newTop != null) {
1008 newTop.frontOfTask = true;
1009 }
Craig Mautner3b475fe2013-12-16 15:58:31 -08001010 }
1011
Craig Mautnerde4ef022013-04-07 19:01:33 -07001012 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -08001013 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -07001014 */
1015 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001016 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
1017 "Removing and adding activity " + newTop
1018 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -07001019
Craig Mautnerde4ef022013-04-07 19:01:33 -07001020 mActivities.remove(newTop);
1021 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001022 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -08001023
Wale Ogunwale6d42df62015-11-05 09:50:55 -08001024 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001025 }
1026
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001027 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -08001028 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001029 }
1030
1031 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001032 addActivityAtIndex(mActivities.size(), r);
1033 }
1034
Wale Ogunwalec5cc3012017-01-13 13:26:16 -08001035 // TODO: Figure-out if any of the call points expect the window container to be reparented and
1036 // correct them to use the right method.
Craig Mautner1602ec22013-05-12 10:24:27 -07001037 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -07001038 // 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 -08001039 if (!mActivities.remove(r) && r.fullscreen) {
1040 // Was not previously in list.
1041 numFullscreen++;
1042 }
Craig Mautner2c1faed2013-07-23 12:56:02 -07001043 // Only set this based on the first activity
1044 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001045 taskType = r.mActivityType;
1046 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001047 mCallingUid = r.launchedFromUid;
1048 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001049 // Clamp to [1, max].
1050 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
1051 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -07001052 } else {
1053 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -07001054 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -07001055 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001056
1057 final int size = mActivities.size();
1058
1059 if (index == size && size > 0) {
1060 final ActivityRecord top = mActivities.get(size - 1);
1061 if (top.mTaskOverlay) {
1062 // Place below the task overlay activity since the overlay activity should always
1063 // be on top.
1064 index--;
1065 }
1066 }
1067
Craig Mautner77878772013-03-04 19:46:24 -08001068 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001069 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001070 if (r.isPersistable()) {
1071 mService.notifyTaskPersisterLocked(this, false);
1072 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001073
1074 // Sync. with window manager
1075 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -08001076 mWindowContainerController.positionChildAt(r.getWindowContainerController(), index);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001077 r.onOverrideConfigurationSent();
Craig Mautner77878772013-03-04 19:46:24 -08001078 }
1079
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001080 /** @return true if this was the last activity in the task */
1081 boolean removeActivity(ActivityRecord r) {
1082 if (mActivities.remove(r) && r.fullscreen) {
1083 // Was previously in list.
1084 numFullscreen--;
1085 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001086 if (r.isPersistable()) {
1087 mService.notifyTaskPersisterLocked(this, false);
1088 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001089
Andrii Kulian02b7a832016-10-06 23:11:56 -07001090 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001091 // We normally notify listeners of task stack changes on pause, however pinned stack
1092 // activities are normally in the paused state so no notification will be sent there
1093 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001094 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001095 }
1096
Craig Mautner41326202014-06-20 14:38:21 -07001097 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001098 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001099 }
1100 updateEffectiveIntent();
1101 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001102 }
1103
Craig Mautner41db4a72014-05-07 17:20:56 -07001104 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001105 // We will automatically remove the task either if it has explicitly asked for
1106 // this, or it is empty and has never contained an activity that got shown to
1107 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001108 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001109 }
1110
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001111 /**
1112 * Completely remove all activities associated with an existing
1113 * task starting at a specified index.
1114 */
1115 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001116 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001117 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001118 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001119 if (r.finishing) {
1120 continue;
1121 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001122 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001123 // Task was restored from persistent storage.
1124 r.takeFromHistory();
1125 mActivities.remove(activityNdx);
1126 --activityNdx;
1127 --numActivities;
Andrii Kulian02b7a832016-10-06 23:11:56 -07001128 } else if (mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001129 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001130 --activityNdx;
1131 --numActivities;
1132 }
1133 }
1134 }
1135
1136 /**
1137 * Completely remove all activities associated with an existing task.
1138 */
1139 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001140 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001141 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -07001142 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001143 }
1144
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001145 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1146 mReuseTask = true;
1147 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1148 mReuseTask = false;
1149 return result;
1150 }
1151
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001152 /**
1153 * Perform clear operation as requested by
1154 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1155 * stack to the given task, then look for
1156 * an instance of that activity in the stack and, if found, finish all
1157 * activities on top of it and return the instance.
1158 *
1159 * @param newR Description of the new activity being started.
1160 * @return Returns the old activity that should be continued to be used,
1161 * or null if none was found.
1162 */
1163 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001164 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001165 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001166 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001167 if (r.finishing) {
1168 continue;
1169 }
1170 if (r.realActivity.equals(newR.realActivity)) {
1171 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001172 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001173
1174 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001175 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001176 if (r.finishing) {
1177 continue;
1178 }
1179 ActivityOptions opts = r.takeOptionsLocked();
1180 if (opts != null) {
1181 ret.updateOptionsLocked(opts);
1182 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001183 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001184 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001185 --activityNdx;
1186 --numActivities;
1187 }
1188 }
1189
1190 // Finally, if this is a normal launch mode (that is, not
1191 // expecting onNewIntent()), then we will finish the current
1192 // instance of the activity so a new fresh one can be started.
1193 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001194 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1195 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001196 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001197 if (mStack != null) {
1198 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001199 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1200 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001201 return null;
1202 }
1203 }
1204
1205 return ret;
1206 }
1207 }
1208
1209 return null;
1210 }
1211
Andrii Kulian21713ac2016-10-12 22:05:05 -07001212 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001213 if (mStack != null) {
1214 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Craig Mautner21d24a22014-04-23 11:45:37 -07001215 if (resumedActivity != null && resumedActivity.task == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001216 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001217 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001218 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001219 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001220 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1221 getLastThumbnail(taskThumbnail);
1222 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001223 }
1224
Andrii Kulian21713ac2016-10-12 22:05:05 -07001225 void removeTaskActivitiesLocked() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001226 // Just remove the entire task.
1227 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001228 }
1229
Craig Mautner432f64e2015-05-20 14:59:57 -07001230 String lockTaskAuthToString() {
1231 switch (mLockTaskAuth) {
1232 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1233 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1234 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1235 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001236 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001237 default: return "unknown=" + mLockTaskAuth;
1238 }
1239 }
1240
Craig Mautner15df08a2015-04-01 12:17:18 -07001241 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001242 if (!mPrivileged &&
1243 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1244 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1245 // Non-priv apps are not allowed to use always or never, fall back to default
1246 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1247 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001248 switch (mLockTaskMode) {
1249 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1250 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1251 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1252 break;
1253
1254 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001255 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001256 break;
1257
1258 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001259 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001260 break;
1261
1262 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1263 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1264 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1265 break;
1266 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001267 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1268 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001269 }
1270
1271 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001272 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1273 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001274 return false;
1275 }
1276 String[] packages = mService.mLockTaskPackages.get(userId);
1277 if (packages == null) {
1278 return false;
1279 }
1280 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001281 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001282 return true;
1283 }
1284 }
1285 return false;
1286 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001287
Craig Mautnera82aa092013-09-13 15:34:08 -07001288 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001289 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001290 }
1291
Wale Ogunwale74e26592016-02-05 11:48:37 -08001292 boolean isRecentsTask() {
1293 return taskType == RECENTS_ACTIVITY_TYPE;
1294 }
1295
Craig Mautner86d67a42013-05-14 10:34:38 -07001296 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001297 return taskType == APPLICATION_ACTIVITY_TYPE;
1298 }
1299
1300 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001301 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001302 }
1303
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001304 boolean isResizeable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -07001305 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode))
1306 && !mTemporarilyUnresizable;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001307 }
1308
skuhne@google.com322347b2016-12-02 12:54:03 -08001309 /**
1310 * Check that a given bounds matches the application requested orientation.
1311 *
1312 * @param bounds The bounds to be tested.
1313 * @return True if the requested bounds are okay for a resizing request.
1314 */
1315 boolean canResizeToBounds(Rect bounds) {
1316 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1317 // Note: If not on the freeform workspace, we ignore the bounds.
1318 return true;
1319 }
1320 final boolean landscape = bounds.width() > bounds.height();
1321 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1322 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1323 }
1324 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1325 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1326 }
1327
Jiaquan Hedd1e66f2016-06-15 15:15:12 -07001328 boolean isOnTopLauncher() {
1329 return isHomeTask() && mIsOnTopLauncher;
1330 }
1331
Wale Ogunwale513346d2016-01-27 10:55:01 -08001332 boolean canGoInDockedStack() {
Matthew Ng626e0cc2016-12-07 17:25:53 -08001333 return isResizeable() && mService.mSupportsSplitScreenMultiWindow &&
skuhne@google.com322347b2016-12-02 12:54:03 -08001334 !ActivityInfo.isPreserveOrientationMode(mResizeMode);
Wale Ogunwale513346d2016-01-27 10:55:01 -08001335 }
1336
Craig Mautner525f3d92013-05-07 14:01:50 -07001337 /**
1338 * Find the activity in the history stack within the given task. Returns
1339 * the index within the history at which it's found, or < 0 if not found.
1340 */
1341 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1342 final ComponentName realActivity = r.realActivity;
1343 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1344 ActivityRecord candidate = mActivities.get(activityNdx);
1345 if (candidate.finishing) {
1346 continue;
1347 }
1348 if (candidate.realActivity.equals(realActivity)) {
1349 return candidate;
1350 }
1351 }
1352 return null;
1353 }
1354
Winson Chunga449dc02014-05-16 11:15:04 -07001355 /** Updates the last task description values. */
1356 void updateTaskDescription() {
1357 // Traverse upwards looking for any break between main task activities and
1358 // utility activities.
1359 int activityNdx;
1360 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001361 final boolean relinquish = numActivities != 0 &&
1362 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001363 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001364 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001365 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001366 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001367 // This will be the top activity for determining taskDescription. Pre-inc to
1368 // overcome initial decrement below.
1369 ++activityNdx;
1370 break;
1371 }
Winson Chunga449dc02014-05-16 11:15:04 -07001372 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001373 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001374 break;
1375 }
1376 }
1377 if (activityNdx > 0) {
1378 // Traverse downwards starting below break looking for set label, icon.
1379 // Note that if there are activities in the task but none of them set the
1380 // recent activity values, then we do not fall back to the last set
1381 // values in the TaskRecord.
1382 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001383 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001384 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001385 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001386 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1387 final ActivityRecord r = mActivities.get(activityNdx);
1388 if (r.taskDescription != null) {
1389 if (label == null) {
1390 label = r.taskDescription.getLabel();
1391 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001392 if (iconFilename == null) {
1393 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001394 }
1395 if (colorPrimary == 0) {
1396 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001397 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001398 if (colorBackground == 0) {
1399 colorBackground = r.taskDescription.getBackgroundColor();
1400 }
Winson Chunga449dc02014-05-16 11:15:04 -07001401 }
1402 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001403 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1404 colorBackground);
Winson Chungec396d62014-08-06 17:08:00 -07001405 // Update the task affiliation color if we are the parent of the group
1406 if (taskId == mAffiliatedTaskId) {
1407 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1408 }
Winson Chunga449dc02014-05-16 11:15:04 -07001409 }
1410 }
1411
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001412 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001413 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001414 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001415 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001416 final ActivityRecord r = mActivities.get(activityNdx);
1417 if (r.finishing) {
1418 continue;
1419 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001420 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001421 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001422 break;
1423 }
1424 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001425 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001426 }
1427
1428 void updateEffectiveIntent() {
1429 final int effectiveRootIndex = findEffectiveRootIndex();
1430 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001431 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001432 }
1433
Craig Mautner21d24a22014-04-23 11:45:37 -07001434 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001435 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001436
1437 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1438 if (realActivity != null) {
1439 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1440 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001441 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001442 if (origActivity != null) {
1443 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1444 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001445 // Write affinity, and root affinity if it is different from affinity.
1446 // We use the special string "@" for a null root affinity, so we can identify
1447 // later whether we were given a root affinity or should just make it the
1448 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001449 if (affinity != null) {
1450 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001451 if (!affinity.equals(rootAffinity)) {
1452 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1453 }
1454 } else if (rootAffinity != null) {
1455 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001456 }
1457 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001458 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001459 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1460 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001461 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001462 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001463 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001464 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001465 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001466 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001467 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001468 if (lastDescription != null) {
1469 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1470 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001471 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001472 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001473 }
Winson Chung36f3f032016-09-08 23:29:43 +00001474 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001475 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001476 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1477 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1478 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001479 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1480 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001481 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001482 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001483 if (mLastNonFullscreenBounds != null) {
1484 out.attribute(
1485 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001486 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001487 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1488 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001489 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001490
Craig Mautner21d24a22014-04-23 11:45:37 -07001491 if (affinityIntent != null) {
1492 out.startTag(null, TAG_AFFINITYINTENT);
1493 affinityIntent.saveToXml(out);
1494 out.endTag(null, TAG_AFFINITYINTENT);
1495 }
1496
Winson Chung36f3f032016-09-08 23:29:43 +00001497 out.startTag(null, TAG_INTENT);
1498 intent.saveToXml(out);
1499 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001500
1501 final ArrayList<ActivityRecord> activities = mActivities;
1502 final int numActivities = activities.size();
1503 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1504 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001505 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001506 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1507 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001508 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001509 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001510 break;
1511 }
1512 out.startTag(null, TAG_ACTIVITY);
1513 r.saveToXml(out);
1514 out.endTag(null, TAG_ACTIVITY);
1515 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001516 }
1517
Winson Chung36f3f032016-09-08 23:29:43 +00001518 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1519 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001520 Intent intent = null;
1521 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001522 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001523 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001524 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001525 ComponentName origActivity = null;
1526 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001527 String rootAffinity = null;
1528 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001529 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001530 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001531 boolean askedCompatMode = false;
1532 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001533 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001534 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001535 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001536 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001537 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001538 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001539 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001540 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001541 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001542 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001543 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001544 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001545 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001546 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001547 int prevTaskId = INVALID_TASK_ID;
1548 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001549 int callingUid = -1;
1550 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001551 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001552 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001553 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001554 int minWidth = INVALID_MIN_SIZE;
1555 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001556 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001557
1558 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1559 final String attrName = in.getAttributeName(attrNdx);
1560 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001561 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1562 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001563 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001564 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001565 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1566 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001567 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1568 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001569 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1570 origActivity = ComponentName.unflattenFromString(attrValue);
1571 } else if (ATTR_AFFINITY.equals(attrName)) {
1572 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001573 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1574 rootAffinity = attrValue;
1575 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001576 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001577 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001578 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001579 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001580 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001581 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001582 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001583 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001584 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001585 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001586 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001587 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001588 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001589 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001590 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001591 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001592 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001593 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001594 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1595 lastDescription = attrValue;
1596 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001597 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001598 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001599 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001600 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1601 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001602 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1603 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001604 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001605 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001606 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001607 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001608 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001609 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001610 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001611 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001612 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001613 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001614 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1615 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001616 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001617 resizeMode = Integer.parseInt(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001618 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001619 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001620 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001621 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001622 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1623 minWidth = Integer.parseInt(attrValue);
1624 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1625 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001626 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1627 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001628 } else {
1629 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1630 }
1631 }
1632
1633 int event;
1634 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001635 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001636 if (event == XmlPullParser.START_TAG) {
1637 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001638 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1639 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001640 if (TAG_AFFINITYINTENT.equals(name)) {
1641 affinityIntent = Intent.restoreFromXml(in);
1642 } else if (TAG_INTENT.equals(name)) {
1643 intent = Intent.restoreFromXml(in);
1644 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001645 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001646 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1647 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001648 if (activity != null) {
1649 activities.add(activity);
1650 }
1651 } else {
1652 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1653 XmlUtils.skipCurrentTag(in);
1654 }
1655 }
1656 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001657 if (!hasRootAffinity) {
1658 rootAffinity = affinity;
1659 } else if ("@".equals(rootAffinity)) {
1660 rootAffinity = null;
1661 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001662 if (effectiveUid <= 0) {
1663 Intent checkIntent = intent != null ? intent : affinityIntent;
1664 effectiveUid = 0;
1665 if (checkIntent != null) {
1666 IPackageManager pm = AppGlobals.getPackageManager();
1667 try {
1668 ApplicationInfo ai = pm.getApplicationInfo(
1669 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001670 PackageManager.MATCH_UNINSTALLED_PACKAGES
1671 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001672 if (ai != null) {
1673 effectiveUid = ai.uid;
1674 }
1675 } catch (RemoteException e) {
1676 }
1677 }
1678 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1679 + ": effectiveUid=" + effectiveUid);
1680 }
1681
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001682 if (persistTaskVersion < 1) {
1683 // We need to convert the resize mode of home activities saved before version one if
1684 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1685 // since we didn't have that differentiation before version 1 and the system didn't
1686 // resize home activities before then.
1687 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1688 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1689 }
1690 }
1691
Winson Chung36f3f032016-09-08 23:29:43 +00001692 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001693 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001694 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1695 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001696 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001697 taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged,
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001698 realActivitySuspended, userSetupComplete, minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001699 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001700
1701 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001702 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001703 }
1704
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001705 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001706 return task;
1707 }
1708
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001709 private void adjustForMinimalTaskDimensions(Rect bounds) {
1710 if (bounds == null) {
1711 return;
1712 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001713 int minWidth = mMinWidth;
1714 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001715 // If the task has no requested minimal size, we'd like to enforce a minimal size
1716 // so that the user can not render the task too small to manipulate. We don't need
1717 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001718 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001719 if (minWidth == INVALID_MIN_SIZE) {
1720 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001721 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001722 if (minHeight == INVALID_MIN_SIZE) {
1723 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001724 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001725 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001726 final boolean adjustWidth = minWidth > bounds.width();
1727 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001728 if (!(adjustWidth || adjustHeight)) {
1729 return;
1730 }
1731
1732 if (adjustWidth) {
1733 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001734 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001735 } else {
1736 // Either left bounds match, or neither match, or the previous bounds were
1737 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001738 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001739 }
1740 }
1741 if (adjustHeight) {
1742 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001743 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001744 } else {
1745 // Either top bounds match, or neither match, or the previous bounds were
1746 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001747 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001748 }
1749 }
1750 }
1751
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001752 /**
1753 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001754 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07001755 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001756 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001757 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001758 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1759 }
1760
1761 /**
1762 * Update task's override configuration based on the bounds.
1763 * @param bounds The bounds of the task.
1764 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1765 * subtract the navigation bar/status bar size from the screen size reported
1766 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07001767 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001768 */
Andrii Kulian8072d112016-09-16 11:11:01 -07001769 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001770 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07001771 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001772 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001773 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08001774 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07001775 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001776
1777 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001778 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001779 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001780 mLastNonFullscreenBounds = mBounds;
1781 }
1782 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07001783 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07001784 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001785 mTmpRect.set(bounds);
1786 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001787 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001788 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001789 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001790 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001791 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001792 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001793 mLastNonFullscreenBounds = mBounds;
1794 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001795 calculateOverrideConfig(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07001796 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001797 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001798 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001799
1800 if (mFullscreen != oldFullscreen) {
Andrii Kulian933076d2016-03-29 17:04:42 -07001801 mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001802 }
1803
Andrii Kulian1779e612016-10-12 21:58:25 -07001804 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001805 }
1806
Andrii Kuliandaea3572016-04-08 13:20:51 -07001807 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds,
1808 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001809 mTmpRect2.set(inInsetBounds);
1810 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1811 int leftInset = mTmpRect2.left - inInsetBounds.left;
1812 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001813 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1814 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001815 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1816 }
1817
Andrii Kuliandaea3572016-04-08 13:20:51 -07001818 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds,
1819 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001820 mTmpRect2.set(inInsetBounds);
1821 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1822 int leftInset = mTmpRect2.left - inInsetBounds.left;
1823 int topInset = mTmpRect2.top - inInsetBounds.top;
Andrii Kuliandaea3572016-04-08 13:20:51 -07001824 int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect2.right;
1825 int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect2.bottom;
Jorim Jaggi0a932142016-02-01 17:42:25 -08001826 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1827 }
1828
Andrii Kulian1779e612016-10-12 21:58:25 -07001829 /** Clears passed config and fills it with new override values. */
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07001830 private void calculateOverrideConfig(Configuration config, Rect bounds, Rect insetBounds,
1831 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001832 mTmpNonDecorBounds.set(bounds);
1833 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001834
Andrii Kulian1779e612016-10-12 21:58:25 -07001835 final Configuration parentConfig = getParent().getConfiguration();
1836 config.unset();
1837 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Yorke Leef54f9da2017-01-10 07:58:59 -08001838 final boolean isFloatingTask = mStack != null && StackId.tasksAreFloating(mStack.mStackId);
1839 if (isFloatingTask) {
1840 // Floating tasks should not be resized to the screen's bounds.
1841 config.screenWidthDp = (int) (mTmpStableBounds.width() / density);
1842 config.screenHeightDp = (int) (mTmpStableBounds.height() / density);
1843 } else {
1844 // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
1845 // i.e. the screen area without the system bars.
1846 // Additionally task dimensions should not be bigger than its parents dimensions.
1847 subtractNonDecorInsets(mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds,
1848 overrideWidth, overrideHeight);
1849 subtractStableInsets(mTmpStableBounds, insetBounds != null ? insetBounds : bounds,
1850 overrideWidth, overrideHeight);
1851 config.screenWidthDp = Math.min(
1852 (int) (mTmpStableBounds.width() / density), parentConfig.screenWidthDp);
1853 config.screenHeightDp = Math.min(
1854 (int) (mTmpStableBounds.height() / density), parentConfig.screenHeightDp);
1855 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001856
1857 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001858 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1859 ? Configuration.ORIENTATION_PORTRAIT
1860 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001861
Jorim Jaggi85639432016-05-06 17:27:55 -07001862 // For calculating screen layout, we need to use the non-decor inset screen area for the
1863 // calculation for compatibility reasons, i.e. screen area without system bars that could
1864 // never go away in Honeycomb.
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001865 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1866 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07001867 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
1868 // calculation with partial default.
1869 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001870 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07001871 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07001872 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
1873
1874 config.smallestScreenWidthDp = mService.mWindowManager.getSmallestWidthForTaskBounds(
1875 insetBounds != null ? insetBounds : bounds);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001876 }
1877
1878 /**
1879 * Using the existing configuration {@param config}, creates a new task override config such
1880 * that all the fields that are usually set in an override config are set to the ones in
1881 * {@param config}.
1882 */
1883 Configuration extractOverrideConfig(Configuration config) {
Andrii Kulian1779e612016-10-12 21:58:25 -07001884 final Configuration extracted = new Configuration();
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001885 extracted.screenWidthDp = config.screenWidthDp;
1886 extracted.screenHeightDp = config.screenHeightDp;
1887 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1888 extracted.orientation = config.orientation;
Andrii Kulian1779e612016-10-12 21:58:25 -07001889 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout.
1890 extracted.screenLayout = config.screenLayout & (Configuration.SCREENLAYOUT_LONG_MASK
1891 | Configuration.SCREENLAYOUT_SIZE_MASK | Configuration.SCREENLAYOUT_COMPAT_NEEDED);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001892 return extracted;
1893 }
1894
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001895 Rect updateOverrideConfigurationFromLaunchBounds() {
1896 final Rect bounds = validateBounds(getLaunchBounds());
1897 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07001898 if (bounds != null) {
1899 bounds.set(mBounds);
1900 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001901 return bounds;
1902 }
1903
1904 static Rect validateBounds(Rect bounds) {
1905 if (bounds != null && bounds.isEmpty()) {
1906 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1907 return null;
1908 }
1909 return bounds;
1910 }
1911
Wale Ogunwale935e5022015-11-10 12:36:10 -08001912 /** Updates the task's bounds and override configuration to match what is expected for the
1913 * input stack. */
1914 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001915 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001916 return;
1917 }
1918
1919 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001920 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001921 throw new IllegalArgumentException("Can not position non-resizeable task="
1922 + this + " in stack=" + inStack);
1923 }
1924 if (mBounds != null) {
1925 return;
1926 }
1927 if (mLastNonFullscreenBounds != null) {
1928 updateOverrideConfiguration(mLastNonFullscreenBounds);
1929 } else {
1930 inStack.layoutTaskInStack(this, null);
1931 }
1932 } else {
1933 updateOverrideConfiguration(inStack.mBounds);
1934 }
1935 }
1936
Chong Zhang0fa656b2015-08-31 15:17:21 -07001937 /**
1938 * Returns the correct stack to use based on task type and currently set bounds,
1939 * regardless of the focused stack and current stack association of the task.
1940 * The task will be moved (and stack focus changed) later if necessary.
1941 */
1942 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001943 if (isRecentsTask()) {
1944 return RECENTS_STACK_ID;
1945 }
1946 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001947 return HOME_STACK_ID;
1948 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001949 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001950 return FREEFORM_WORKSPACE_STACK_ID;
1951 }
1952 return FULLSCREEN_WORKSPACE_STACK_ID;
1953 }
1954
1955 /** Returns the bounds that should be used to launch this task. */
1956 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001957 // If we're over lockscreen, forget about stack bounds and use fullscreen.
Jorim Jaggife762342016-10-13 14:33:27 +02001958 if (mService.mStackSupervisor.mKeyguardController.isKeyguardShowing()) {
Chong Zhang75b37202015-12-04 14:16:36 -08001959 return null;
1960 }
1961
Andrii Kulian02b7a832016-10-06 23:11:56 -07001962 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08001963 return null;
1964 }
1965
Andrii Kulian02b7a832016-10-06 23:11:56 -07001966 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08001967 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001968 || stackId == RECENTS_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08001969 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001970 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001971 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07001972 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001973 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001974 }
1975 return mLastNonFullscreenBounds;
1976 }
1977
Wale Ogunwale39381972015-12-17 17:15:29 -08001978 boolean canMatchRootAffinity() {
1979 // We don't allow root affinity matching on the pinned stack as no other task should
1980 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001981 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08001982 }
1983
Jorim Jaggi8b702ed2017-01-20 16:59:03 +01001984 void addStartingWindowsForVisibleActivities(boolean taskSwitch) {
1985 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1986 final ActivityRecord r = mActivities.get(activityNdx);
1987 if (r.visible) {
1988 r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch);
1989 }
1990 }
1991 }
1992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001994 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001995 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1996 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08001997 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001998 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001999 if (affinity != null || rootAffinity != null) {
2000 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
2001 if (affinity == null || !affinity.equals(rootAffinity)) {
2002 pw.print(" root="); pw.println(rootAffinity);
2003 } else {
2004 pw.println();
2005 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002006 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07002007 if (voiceSession != null || voiceInteractor != null) {
2008 pw.print(prefix); pw.print("VOICE: session=0x");
2009 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
2010 pw.print(" interactor=0x");
2011 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
2012 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002013 if (intent != null) {
2014 StringBuilder sb = new StringBuilder(128);
2015 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002016 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002017 sb.append('}');
2018 pw.println(sb.toString());
2019 }
2020 if (affinityIntent != null) {
2021 StringBuilder sb = new StringBuilder(128);
2022 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002023 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002024 sb.append('}');
2025 pw.println(sb.toString());
2026 }
2027 if (origActivity != null) {
2028 pw.print(prefix); pw.print("origActivity=");
2029 pw.println(origActivity.flattenToShortString());
2030 }
2031 if (realActivity != null) {
2032 pw.print(prefix); pw.print("realActivity=");
2033 pw.println(realActivity.flattenToShortString());
2034 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07002035 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
2036 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002037 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002038 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002039 pw.print(" numFullscreen="); pw.print(numFullscreen);
2040 pw.print(" taskType="); pw.print(taskType);
2041 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
2042 }
Craig Mautner432f64e2015-05-20 14:59:57 -07002043 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
2044 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002045 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
2046 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07002047 pw.print(" mReuseTask="); pw.print(mReuseTask);
2048 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002049 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08002050 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
2051 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
2052 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07002053 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
2054 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
2055 pw.print(" (");
2056 if (mPrevAffiliate == null) {
2057 pw.print("null");
2058 } else {
2059 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
2060 }
2061 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
2062 pw.print(" (");
2063 if (mNextAffiliate == null) {
2064 pw.print("null");
2065 } else {
2066 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2067 }
2068 pw.println(")");
2069 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002070 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002071 if (!askedCompatMode || !inRecents || !isAvailable) {
2072 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2073 pw.print(" inRecents="); pw.print(inRecents);
2074 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002075 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002076 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002077 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2078 if (lastDescription != null) {
2079 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2080 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002081 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002082 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2083 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
2084 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00002085 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002086 pw.print(" lastActiveTime=" + lastActiveTime);
2087 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 }
2089
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002090 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002092 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002093 if (stringName != null) {
2094 sb.append(stringName);
2095 sb.append(" U=");
2096 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002097 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002098 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002099 sb.append(" sz=");
2100 sb.append(mActivities.size());
2101 sb.append('}');
2102 return sb.toString();
2103 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002104 sb.append("TaskRecord{");
2105 sb.append(Integer.toHexString(System.identityHashCode(this)));
2106 sb.append(" #");
2107 sb.append(taskId);
2108 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002109 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002110 sb.append(affinity);
2111 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002112 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002113 sb.append(intent.getComponent().flattenToShortString());
2114 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002115 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002116 sb.append(affinityIntent.getComponent().flattenToShortString());
2117 } else {
2118 sb.append(" ??");
2119 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002120 stringName = sb.toString();
2121 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 }
2123}