blob: 261797e3113ce42331dc561325dd52e472f043e7 [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
Winson Chung74666102017-02-22 17:49:24 -080019import android.annotation.IntDef;
Jorim Jaggi0a932142016-02-01 17:42:25 -080020import android.annotation.Nullable;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070021import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070022import android.app.ActivityManager;
Wale Ogunwale3797c222015-10-27 14:21:58 -070023import android.app.ActivityManager.StackId;
Craig Mautner648f69b2014-09-18 14:16:26 -070024import android.app.ActivityManager.TaskDescription;
Jorim Jaggie2c77f92016-12-29 14:57:22 +010025import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwaleff3c66c2015-11-18 19:22:49 -080026import android.app.ActivityManager.TaskThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -080027import android.app.ActivityManager.TaskThumbnailInfo;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070028import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070029import android.app.AppGlobals;
Jorim Jaggi0a932142016-02-01 17:42:25 -080030import android.app.IActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.ComponentName;
32import android.content.Intent;
33import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070034import android.content.pm.ApplicationInfo;
35import android.content.pm.IPackageManager;
36import android.content.pm.PackageManager;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070037import android.content.res.Configuration;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070038import android.graphics.Bitmap;
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
Bryce Lee04ab3462017-04-10 15:06:33 -070051import com.android.internal.annotations.VisibleForTesting;
Dianne Hackborn91097de2014-04-04 18:02:06 -070052import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070053import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080054
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -080055import com.android.server.wm.AppWindowContainerController;
Winson Chungbdc646f2017-02-13 12:12:22 -080056import com.android.server.wm.StackWindowController;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080057import com.android.server.wm.TaskWindowContainerController;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010058import com.android.server.wm.TaskWindowContainerListener;
Winson Chung74666102017-02-22 17:49:24 -080059import com.android.server.wm.WindowManagerService;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010060
Craig Mautner21d24a22014-04-23 11:45:37 -070061import org.xmlpull.v1.XmlPullParser;
62import org.xmlpull.v1.XmlPullParserException;
63import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
Craig Mautnerc0ffce52014-07-01 12:38:52 -070065import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070066import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import java.io.PrintWriter;
Winson Chung74666102017-02-22 17:49:24 -080068import java.lang.annotation.Retention;
69import java.lang.annotation.RetentionPolicy;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080070import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070071import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080073import static android.app.ActivityManager.RESIZE_MODE_FORCED;
Winson Chung74666102017-02-22 17:49:24 -080074import static android.app.ActivityManager.RESIZE_MODE_SYSTEM;
Winson Chung83471632016-12-13 11:02:12 -080075import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080076import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
77import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
78import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
79import static android.app.ActivityManager.StackId.HOME_STACK_ID;
80import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
81import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080082import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080083import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
84import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070085import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
Jorim Jaggi0a932142016-02-01 17:42:25 -080086import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
87import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
88import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
89import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
skuhne@google.com322347b2016-12-02 12:54:03 -080090import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
91import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
92import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Wale Ogunwaled829d362016-02-10 19:24:49 -080093import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070094import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -080095import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070096import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggi0a932142016-02-01 17:42:25 -080097import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080098import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Bryce Leec857a5b2017-08-16 10:04:52 -070099import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES;
Suprabh Shukla7745c142016-03-07 18:21:10 -0800100import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700101import static android.view.Display.DEFAULT_DISPLAY;
102
Jorim Jaggi0a932142016-02-01 17:42:25 -0800103import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
104import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
105import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
106import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
107import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
108import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
109import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
110import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
111import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
112import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800113import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Winson Chung83471632016-12-13 11:02:12 -0800114import static com.android.server.am.ActivityRecord.ASSISTANT_ACTIVITY_TYPE;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800115import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
116import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700117import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800118import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
Wale Ogunwale56d8d162017-05-30 11:12:20 -0700119import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING_TO_TOP;
Winson Chung6954fc92017-03-24 16:22:12 -0700120import static com.android.server.am.ActivityStackSupervisor.PAUSE_IMMEDIATELY;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800121import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800122
Winson Chung74666102017-02-22 17:49:24 -0800123import static java.lang.Integer.MAX_VALUE;
124
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100125final class TaskRecord extends ConfigurationContainer implements TaskWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800126 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700127 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700128 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -0700129 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700130 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800131
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700132 private static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700133 private static final String TAG_INTENT = "intent";
134 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700135 private static final String ATTR_REALACTIVITY = "real_activity";
136 private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700137 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700138 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700139 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700140 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700141 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700142 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700143 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
144 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800145 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700146 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700147 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700148 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700149 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700150 private static final String ATTR_LASTDESCRIPTION = "last_description";
151 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700152 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700153 private static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700154 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
155 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700156 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700157 private static final String ATTR_CALLING_UID = "calling_uid";
158 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Winson Chungd3395382016-12-13 11:49:09 -0800159 private static final String ATTR_SUPPORTS_PICTURE_IN_PICTURE = "supports_picture_in_picture";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800160 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700161 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700162 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700163 private static final String ATTR_MIN_WIDTH = "min_width";
164 private static final String ATTR_MIN_HEIGHT = "min_height";
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700165 private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
Andrii Kulian18d75122016-03-27 20:20:28 -0700166
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700167 // Current version of the task record we persist. Used to check if we need to run any upgrade
168 // code.
169 private static final int PERSIST_TASK_VERSION = 1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700170 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
171
Wale Ogunwale18795a22014-12-03 11:38:33 -0800172 static final int INVALID_TASK_ID = -1;
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700173 private static final int INVALID_MIN_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800174
Winson Chung74666102017-02-22 17:49:24 -0800175 /**
176 * The modes to control how the stack is moved to the front when calling
177 * {@link TaskRecord#reparent}.
178 */
179 @Retention(RetentionPolicy.SOURCE)
180 @IntDef({
181 REPARENT_MOVE_STACK_TO_FRONT,
182 REPARENT_KEEP_STACK_AT_FRONT,
183 REPARENT_LEAVE_STACK_IN_PLACE
184 })
185 public @interface ReparentMoveStackMode {}
186 // Moves the stack to the front if it was not at the front
187 public static final int REPARENT_MOVE_STACK_TO_FRONT = 0;
188 // Only moves the stack to the front if it was focused or front most already
189 public static final int REPARENT_KEEP_STACK_AT_FRONT = 1;
190 // Do not move the stack as a part of reparenting
191 public static final int REPARENT_LEAVE_STACK_IN_PLACE = 2;
192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700194 String affinity; // The affinity name for this task, or null; may change identity.
195 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700196 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
197 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 Intent intent; // The original intent that started the task.
199 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700200 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 ComponentName origActivity; // The non-alias activity component of the intent.
202 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000203 boolean realActivitySuspended; // True if the actual activity component that started the
204 // task is suspended.
Winson Chung36f3f032016-09-08 23:29:43 +0000205 long firstActiveTime; // First time this task was active.
206 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700207 boolean inRecents; // Actually in the recents list?
208 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 boolean rootWasReset; // True if the intent at the root of the task had
210 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700211 boolean autoRemoveRecents; // If true, we should automatically remove the task from
212 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700213 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700214 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 -0800215
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700216 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700217 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800218 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
219 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800220
221 int numFullscreen; // Number of fullscreen activities.
222
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800223 int mResizeMode; // The resize mode of this task and its activities.
224 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800225 private boolean mSupportsPictureInPicture; // Whether or not this task and its activities
226 // support PiP. Based on the {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE} flag
227 // of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800228 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
229 // changes on a temporary basis.
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700230 private int mLockTaskMode; // Which tasklock mode to launch this task in. One of
231 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700232 private boolean mPrivileged; // The root activity application of this task holds
233 // privileged permissions.
234
Craig Mautner15df08a2015-04-01 12:17:18 -0700235 /** Can't be put in lockTask mode. */
236 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100237 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700238 final static int LOCK_TASK_AUTH_PINNABLE = 1;
239 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
240 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100241 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700242 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100243 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
244 * lockTask task. */
245 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700246 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
247
248 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800249
Winson Chung03a9bae2014-05-02 09:56:12 -0700250 // This represents the last resolved activity values for this task
251 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700252 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700253
Craig Mautnerd2328952013-03-05 12:46:26 -0800254 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700255 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800256
Andrii Kulian02b7a832016-10-06 23:11:56 -0700257 /** Current stack. Setter must always be used to update the value. */
258 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800259
Craig Mautner2c1faed2013-07-23 12:56:02 -0700260 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700261 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700262
Craig Mautner21d24a22014-04-23 11:45:37 -0700263 /** Takes on same value as first root activity */
264 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700265 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700266
267 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
268 * determining the order when restoring. Sign indicates whether last task movement was to front
269 * (positive) or back (negative). Absolute value indicates time. */
270 long mLastTimeMoved = System.currentTimeMillis();
271
Craig Mautner84984fa2014-06-19 11:19:20 -0700272 /** Indication of what to run next when task exits. Use ActivityRecord types.
273 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
274 * task stack. */
275 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700276
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700277 /** If original intent did not allow relinquishing task identity, save that information */
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700278 private boolean mNeverRelinquishIdentity = true;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700279
Craig Mautner362449a2014-06-20 14:04:39 -0700280 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
281 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800282 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700283
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700284 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700285 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700286 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800287 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700288 CharSequence lastDescription; // Last description captured for this item.
289
Craig Mautnera228ae92014-07-09 05:44:55 -0700290 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700291 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700292 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800293 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700294 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800295 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700296
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700297 // For relaunching the task from recents as though it was launched by the original launcher.
298 int mCallingUid;
299 String mCallingPackage;
300
Craig Mautner21d24a22014-04-23 11:45:37 -0700301 final ActivityManagerService mService;
302
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700303 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
304 boolean mFullscreen = true;
305
306 // Bounds of the Task. null for fullscreen tasks.
307 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800308 private final Rect mTmpStableBounds = new Rect();
309 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800310 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800311
Wale Ogunwale706ed792015-08-02 10:29:44 -0700312 // Last non-fullscreen bounds the task was launched in or resized to.
313 // The information is persisted and used to determine the appropriate stack to launch the
314 // task into on restore.
315 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700316 // Minimal width and height of this task when it's resizeable. -1 means it should use the
317 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700318 int mMinWidth;
319 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700320
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700321 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
322 // This number will be assigned when we evaluate OOM scores for all visible tasks.
323 int mLayerRank = -1;
324
Andrii Kulian1779e612016-10-12 21:58:25 -0700325 /** Helper object used for updating override configuration. */
326 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700327
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800328 private TaskWindowContainerController mWindowContainerController;
329
Craig Mautner21d24a22014-04-23 11:45:37 -0700330 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Wale Ogunwale72919d22016-12-08 18:58:50 -0800331 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, int type) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700332 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700333 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
334 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800335 userId = UserHandle.getUserId(info.applicationInfo.uid);
336 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800337 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700339 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700340 voiceSession = _voiceSession;
341 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700342 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800343 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700344 mCallingUid = info.applicationInfo.uid;
345 mCallingPackage = info.packageName;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800346 taskType = type;
Martijn Coenend4a69702014-06-30 11:12:17 -0700347 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700348 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700349 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700350 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Craig Mautner21d24a22014-04-23 11:45:37 -0700351 }
352
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700353 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800354 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700355 mService = service;
356 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
357 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800358 userId = UserHandle.getUserId(info.applicationInfo.uid);
359 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800360 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700361 taskId = _taskId;
362 mAffiliatedTaskId = _taskId;
363 voiceSession = null;
364 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700365 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800366 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700367 mCallingUid = info.applicationInfo.uid;
368 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700369 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700370 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700371
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700372 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700373 // Clamp to [1, max].
374 maxRecents = Math.min(Math.max(info.maxRecents, 1),
375 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700376
377 taskType = APPLICATION_ACTIVITY_TYPE;
378 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700379 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700380 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700381 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700382 }
383
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800384 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
385 Intent _affinityIntent, String _affinity, String _rootAffinity,
386 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
387 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
388 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
389 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
390 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800391 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
392 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Winson Chungd3395382016-12-13 11:49:09 -0800393 int resizeMode, boolean supportsPictureInPicture, boolean privileged,
394 boolean _realActivitySuspended, boolean userSetupComplete, int minWidth,
395 int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700396 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700397 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
398 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800399 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800400 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700401 taskId = _taskId;
402 intent = _intent;
403 affinityIntent = _affinityIntent;
404 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800405 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700406 voiceSession = null;
407 voiceInteractor = null;
408 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800409 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700410 origActivity = _origActivity;
411 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700412 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700413 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700414 askedCompatMode = _askedCompatMode;
415 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700416 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700417 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800418 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700419 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700420 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700421 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700422 lastDescription = _lastDescription;
423 mActivities = activities;
424 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700425 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700426 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700427 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700428 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700429 mPrevAffiliateTaskId = prevTaskId;
430 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700431 mCallingUid = callingUid;
432 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800433 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800434 mSupportsPictureInPicture = supportsPictureInPicture;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700435 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700436 mMinWidth = minWidth;
437 mMinHeight = minHeight;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700438 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 }
440
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800441 TaskWindowContainerController getWindowContainerController() {
442 return mWindowContainerController;
443 }
444
445 void createWindowContainer(boolean onTop, boolean showForAllUsers) {
446 if (mWindowContainerController != null) {
447 throw new IllegalArgumentException("Window container=" + mWindowContainerController
448 + " already created for task=" + this);
449 }
450
451 final Rect bounds = updateOverrideConfigurationFromLaunchBounds();
452 final Configuration overrideConfig = getOverrideConfiguration();
Bryce Lee04ab3462017-04-10 15:06:33 -0700453 setWindowContainerController(new TaskWindowContainerController(taskId, this,
Wale Ogunwale1666e312016-12-16 11:27:18 -0800454 getStack().getWindowContainerController(), userId, bounds, overrideConfig,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800455 mResizeMode, mSupportsPictureInPicture, isHomeTask(), onTop, showForAllUsers,
Bryce Lee04ab3462017-04-10 15:06:33 -0700456 lastTaskDescription));
457 }
458
459 /**
460 * Should only be invoked from {@link #createWindowContainer(boolean, boolean)}.
461 */
462 @VisibleForTesting
463 protected void setWindowContainerController(TaskWindowContainerController controller) {
464 if (mWindowContainerController != null) {
465 throw new IllegalArgumentException("Window container=" + mWindowContainerController
466 + " already created for task=" + this);
467 }
468
469 mWindowContainerController = controller;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800470 }
471
472 void removeWindowContainer() {
473 mService.mStackSupervisor.removeLockedTaskLocked(this);
474 mWindowContainerController.removeContainer();
475 if (!StackId.persistTaskBounds(getStackId())) {
476 // Reset current bounds for task whose bounds shouldn't be persisted so it uses
477 // default configuration the next time it launches.
478 updateOverrideConfiguration(null);
479 }
480 mService.mTaskChangeNotificationController.notifyTaskRemoved(taskId);
481 mWindowContainerController = null;
482 }
483
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100484 @Override
485 public void onSnapshotChanged(TaskSnapshot snapshot) {
486 mService.mTaskChangeNotificationController.notifyTaskSnapshotChanged(taskId, snapshot);
487 }
488
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800489 void setResizeMode(int resizeMode) {
490 if (mResizeMode == resizeMode) {
491 return;
492 }
493 mResizeMode = resizeMode;
494 mWindowContainerController.setResizeable(resizeMode);
495 mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
496 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
497 }
498
499 void setTaskDockedResizing(boolean resizing) {
500 mWindowContainerController.setTaskDockedResizing(resizing);
501 }
502
Wale Ogunwale1666e312016-12-16 11:27:18 -0800503 // TODO: Consolidate this with the resize() method below.
504 @Override
505 public void requestResize(Rect bounds, int resizeMode) {
506 mService.resizeTask(taskId, bounds, resizeMode);
507 }
508
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800509 boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
510 if (!isResizeable()) {
511 Slog.w(TAG, "resizeTask: task " + this + " not resizeable.");
512 return true;
513 }
514
515 // If this is a forced resize, let it go through even if the bounds is not changing,
516 // as we might need a relayout due to surface size change (to/from fullscreen).
517 final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
518 if (Objects.equals(mBounds, bounds) && !forced) {
519 // Nothing to do here...
520 return true;
521 }
522 bounds = validateBounds(bounds);
523
524 if (mWindowContainerController == null) {
525 // Task doesn't exist in window manager yet (e.g. was restored from recents).
526 // All we can do for now is update the bounds so it can be used when the task is
527 // added to window manager.
528 updateOverrideConfiguration(bounds);
529 if (getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
530 // re-restore the task so it can have the proper stack association.
531 mService.mStackSupervisor.restoreRecentTaskLocked(this,
532 FREEFORM_WORKSPACE_STACK_ID);
533 }
534 return true;
535 }
536
537 if (!canResizeToBounds(bounds)) {
538 throw new IllegalArgumentException("resizeTask: Can not resize task=" + this
539 + " to bounds=" + bounds + " resizeMode=" + mResizeMode);
540 }
541
542 // Do not move the task to another stack here.
543 // This method assumes that the task is already placed in the right stack.
544 // we do not mess with that decision and we only do the resize!
545
546 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId);
547
548 final boolean updatedConfig = updateOverrideConfiguration(bounds);
549 // This variable holds information whether the configuration didn't change in a significant
550 // way and the activity was kept the way it was. If it's false, it means the activity had
551 // to be relaunched due to configuration change.
552 boolean kept = true;
553 if (updatedConfig) {
554 final ActivityRecord r = topRunningActivityLocked();
Wale Ogunwaleea3d3fd2017-05-01 07:41:08 -0700555 if (r != null && !deferResume) {
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800556 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
Wale Ogunwaleea3d3fd2017-05-01 07:41:08 -0700557 mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
558 if (!kept) {
559 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800560 }
561 }
562 }
563 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), kept, forced);
564
565 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
566 return kept;
567 }
568
569 // TODO: Investigate combining with the resize() method above.
570 void resizeWindowContainer() {
571 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), false /* relayout */,
572 false /* forced */);
573 }
574
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800575 void getWindowContainerBounds(Rect bounds) {
576 mWindowContainerController.getBounds(bounds);
577 }
578
Winson Chung74666102017-02-22 17:49:24 -0800579 /**
580 * Convenience method to reparent a task to the top or bottom position of the stack.
581 */
582 boolean reparent(int preferredStackId, boolean toTop, @ReparentMoveStackMode int moveStackMode,
583 boolean animate, boolean deferResume, String reason) {
584 return reparent(preferredStackId, toTop ? MAX_VALUE : 0, moveStackMode, animate,
Winson Chung5af42fc2017-03-24 17:11:33 -0700585 deferResume, true /* schedulePictureInPictureModeChange */, reason);
586 }
587
588 /**
589 * Convenience method to reparent a task to the top or bottom position of the stack, with
590 * an option to skip scheduling the picture-in-picture mode change.
591 */
592 boolean reparent(int preferredStackId, boolean toTop, @ReparentMoveStackMode int moveStackMode,
593 boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange,
594 String reason) {
595 return reparent(preferredStackId, toTop ? MAX_VALUE : 0, moveStackMode, animate,
596 deferResume, schedulePictureInPictureModeChange, reason);
597 }
598
599 /**
600 * Convenience method to reparent a task to a specific position of the stack.
601 */
602 boolean reparent(int preferredStackId, int position, @ReparentMoveStackMode int moveStackMode,
603 boolean animate, boolean deferResume, String reason) {
604 return reparent(preferredStackId, position, moveStackMode, animate, deferResume,
605 true /* schedulePictureInPictureModeChange */, reason);
Winson Chung74666102017-02-22 17:49:24 -0800606 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800607
Winson Chung74666102017-02-22 17:49:24 -0800608 /**
609 * Reparents the task into a preferred stack, creating it if necessary.
610 *
611 * @param preferredStackId the stack id of the target stack to move this task
612 * @param position the position to place this task in the new stack
613 * @param animate whether or not we should wait for the new window created as a part of the
Winson Chung5af42fc2017-03-24 17:11:33 -0700614 * reparenting to be drawn and animated in
Winson Chung74666102017-02-22 17:49:24 -0800615 * @param moveStackMode whether or not to move the stack to the front always, only if it was
Winson Chung5af42fc2017-03-24 17:11:33 -0700616 * previously focused & in front, or never
Winson Chung74666102017-02-22 17:49:24 -0800617 * @param deferResume whether or not to update the visibility of other tasks and stacks that may
Winson Chung5af42fc2017-03-24 17:11:33 -0700618 * have changed as a result of this reparenting
619 * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode
620 * change. Callers may set this to false if they are explicitly scheduling PiP mode
621 * changes themselves, like during the PiP animation
Winson Chung74666102017-02-22 17:49:24 -0800622 * @param reason the caller of this reparenting
Winson Chung5af42fc2017-03-24 17:11:33 -0700623 * @return whether the task was reparented
Winson Chung74666102017-02-22 17:49:24 -0800624 */
625 boolean reparent(int preferredStackId, int position, @ReparentMoveStackMode int moveStackMode,
Winson Chung5af42fc2017-03-24 17:11:33 -0700626 boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange,
627 String reason) {
Winson Chung74666102017-02-22 17:49:24 -0800628 final ActivityStackSupervisor supervisor = mService.mStackSupervisor;
629 final WindowManagerService windowManager = mService.mWindowManager;
630 final ActivityStack sourceStack = getStack();
631 final ActivityStack toStack = supervisor.getReparentTargetStack(this, preferredStackId,
632 position == MAX_VALUE);
633 if (toStack == sourceStack) {
634 return false;
635 }
636
637 final int sourceStackId = getStackId();
638 final int stackId = toStack.getStackId();
639 final ActivityRecord topActivity = getTopActivity();
640
641 final boolean mightReplaceWindow = StackId.replaceWindowsOnTaskMove(sourceStackId, stackId)
642 && topActivity != null;
643 if (mightReplaceWindow) {
644 // We are about to relaunch the activity because its configuration changed due to
645 // being maximized, i.e. size change. The activity will first remove the old window
646 // and then add a new one. This call will tell window manager about this, so it can
647 // preserve the old window until the new one is drawn. This prevents having a gap
648 // between the removal and addition, in which no window is visible. We also want the
649 // entrance of the new window to be properly animated.
650 // Note here we always set the replacing window first, as the flags might be needed
651 // during the relaunch. If we end up not doing any relaunch, we clear the flags later.
652 windowManager.setWillReplaceWindow(topActivity.appToken, animate);
653 }
654
655 windowManager.deferSurfaceLayout();
656 boolean kept = true;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800657 try {
Winson Chung74666102017-02-22 17:49:24 -0800658 final ActivityRecord r = topRunningActivityLocked();
Winson Chung95f8f0e2017-03-24 09:20:17 -0700659 final boolean wasFocused = r != null && supervisor.isFocusedStack(sourceStack)
Winson Chung74666102017-02-22 17:49:24 -0800660 && (topRunningActivityLocked() == r);
Winson Chung95f8f0e2017-03-24 09:20:17 -0700661 final boolean wasResumed = r != null && sourceStack.mResumedActivity == r;
662 final boolean wasPaused = r != null && sourceStack.mPausingActivity == r;
Winson Chung74666102017-02-22 17:49:24 -0800663
664 // In some cases the focused stack isn't the front stack. E.g. pinned stack.
665 // Whenever we are moving the top activity from the front stack we want to make sure to
666 // move the stack to the front.
Winson Chung95f8f0e2017-03-24 09:20:17 -0700667 final boolean wasFront = r != null && supervisor.isFrontStackOnDisplay(sourceStack)
Winson Chung74666102017-02-22 17:49:24 -0800668 && (sourceStack.topRunningActivityLocked() == r);
669
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800670 // Adjust the position for the new parent stack as needed.
Winson Chung74666102017-02-22 17:49:24 -0800671 position = toStack.getAdjustedPositionForTask(this, position, null /* starting */);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800672
673 // Must reparent first in window manager to avoid a situation where AM can delete the
674 // we are coming from in WM before we reparent because it became empty.
Wale Ogunwale2719cc12017-04-14 09:45:27 -0700675 mWindowContainerController.reparent(toStack.getWindowContainerController(), position,
676 moveStackMode == REPARENT_MOVE_STACK_TO_FRONT);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800677
Wale Ogunwale56d8d162017-05-30 11:12:20 -0700678 final boolean moveStackToFront = moveStackMode == REPARENT_MOVE_STACK_TO_FRONT
679 || (moveStackMode == REPARENT_KEEP_STACK_AT_FRONT && (wasFocused || wasFront));
Winson Chung74666102017-02-22 17:49:24 -0800680 // Move the task
Wale Ogunwale56d8d162017-05-30 11:12:20 -0700681 sourceStack.removeTask(this, reason, moveStackToFront
682 ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING);
Winson Chung5af42fc2017-03-24 17:11:33 -0700683 toStack.addTask(this, position, false /* schedulePictureInPictureModeChange */, reason);
Winson Chung74666102017-02-22 17:49:24 -0800684
Winson Chung5af42fc2017-03-24 17:11:33 -0700685 if (schedulePictureInPictureModeChange) {
686 // Notify of picture-in-picture mode changes
687 supervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, sourceStack);
688 }
Winson Chung74666102017-02-22 17:49:24 -0800689
690 // TODO: Ensure that this is actually necessary here
691 // Notify the voice session if required
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800692 if (voiceSession != null) {
693 try {
694 voiceSession.taskStarted(intent, taskId);
695 } catch (RemoteException e) {
696 }
697 }
Winson Chung74666102017-02-22 17:49:24 -0800698
699 // If the task had focus before (or we're requested to move focus), move focus to the
700 // new stack by moving the stack to the front.
Winson Chung95f8f0e2017-03-24 09:20:17 -0700701 if (r != null) {
702 toStack.moveToFrontAndResumeStateIfNeeded(r, moveStackToFront, wasResumed,
703 wasPaused, reason);
704 }
Winson Chung74666102017-02-22 17:49:24 -0800705 if (!animate) {
706 toStack.mNoAnimActivities.add(topActivity);
707 }
708
709 // We might trigger a configuration change. Save the current task bounds for freezing.
710 // TODO: Should this call be moved inside the resize method in WM?
711 toStack.prepareFreezingTaskBounds();
712
713 // Make sure the task has the appropriate bounds/size for the stack it is in.
714 if (stackId == FULLSCREEN_WORKSPACE_STACK_ID
715 && !Objects.equals(mBounds, toStack.mBounds)) {
716 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
717 deferResume);
718 } else if (stackId == FREEFORM_WORKSPACE_STACK_ID) {
719 Rect bounds = getLaunchBounds();
720 if (bounds == null) {
721 toStack.layoutTaskInStack(this, null);
722 bounds = mBounds;
723 }
724 kept = resize(bounds, RESIZE_MODE_FORCED, !mightReplaceWindow, deferResume);
725 } else if (stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID) {
Matthew Ng330757d2017-02-28 14:19:17 -0800726 if (stackId == DOCKED_STACK_ID && moveStackMode == REPARENT_KEEP_STACK_AT_FRONT) {
727 // Move recents to front so it is not behind home stack when going into docked
728 // mode
729 mService.mStackSupervisor.moveRecentsStackToFront(reason);
730 }
Winson Chung74666102017-02-22 17:49:24 -0800731 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
732 deferResume);
733 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800734 } finally {
Winson Chung74666102017-02-22 17:49:24 -0800735 windowManager.continueSurfaceLayout();
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800736 }
Winson Chung74666102017-02-22 17:49:24 -0800737
738 if (mightReplaceWindow) {
739 // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old
740 // window), we need to clear the replace window settings. Otherwise, we schedule a
741 // timeout to remove the old window if the replacing window is not coming in time.
742 windowManager.scheduleClearWillReplaceWindows(topActivity.appToken, !kept);
743 }
744
745 if (!deferResume) {
746 // The task might have already been running and its visibility needs to be synchronized
747 // with the visibility of the stack / windows.
748 supervisor.ensureActivitiesVisibleLocked(null, 0, !mightReplaceWindow);
749 supervisor.resumeFocusedStackTopActivityLocked();
750 }
751
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700752 // TODO: Handle incorrect request to move before the actual move, not after.
753 supervisor.handleNonResizableTaskIfNeeded(this, preferredStackId, DEFAULT_DISPLAY, stackId);
Winson Chung74666102017-02-22 17:49:24 -0800754
Matthew Ng330757d2017-02-28 14:19:17 -0800755 boolean successful = (preferredStackId == stackId);
756 if (successful && stackId == DOCKED_STACK_ID) {
757 // If task moved to docked stack - show recents if needed.
758 mService.mWindowManager.showRecentApps(false /* fromHome */);
759 }
760 return successful;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800761 }
762
763 void cancelWindowTransition() {
764 mWindowContainerController.cancelWindowTransition();
765 }
766
767 void cancelThumbnailTransition() {
768 mWindowContainerController.cancelThumbnailTransition();
769 }
770
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100771 /**
772 * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
773 */
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100774 TaskSnapshot getSnapshot(boolean reducedResolution) {
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100775
776 // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
777 // synchronized between AM and WM.
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100778 return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800779 }
780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000782 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700783 if (firstActiveTime == 0) {
784 firstActiveTime = lastActiveTime;
785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000789 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700791
Winson Chungfee26772014-08-05 12:21:52 -0700792 /** Sets the original intent, and the calling uid and package. */
793 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700794 mCallingUid = r.launchedFromUid;
795 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700796 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700797 }
798
799 /** Sets the original intent, _without_ updating the calling uid or package. */
800 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700801 if (intent == null) {
802 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700803 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700804 } else if (mNeverRelinquishIdentity) {
805 return;
806 }
807
808 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700809 if (intent == null) {
810 // If this task already has an intent associated with it, don't set the root
811 // affinity -- we don't want it changing after initially set, but the initially
812 // set value may be null.
813 rootAffinity = affinity;
814 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700815 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700816 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800819 if (_intent != null) {
820 // If this Intent has a selector, we want to clear it for the
821 // recent task since it is not relevant if the user later wants
822 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700823 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800824 _intent = new Intent(_intent);
825 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700826 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800827 }
828 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700829 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 intent = _intent;
831 realActivity = _intent != null ? _intent.getComponent() : null;
832 origActivity = null;
833 } else {
834 ComponentName targetComponent = new ComponentName(
835 info.packageName, info.targetActivity);
836 if (_intent != null) {
837 Intent targetIntent = new Intent(_intent);
838 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800839 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700840 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700841 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700842 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 intent = targetIntent;
844 realActivity = targetComponent;
845 origActivity = _intent.getComponent();
846 } else {
847 intent = null;
848 realActivity = targetComponent;
849 origActivity = new ComponentName(info.packageName, info.name);
850 }
851 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700852
Craig Mautner47b20ba2014-09-17 17:23:44 -0700853 final int intentFlags = intent == null ? 0 : intent.getFlags();
854 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 // Once we are set to an Intent with this flag, we count this
856 // task as having a true root activity.
857 rootWasReset = true;
858 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700859 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000860 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
861 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700862 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700863 // If the activity itself has requested auto-remove, then just always do it.
864 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700865 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
866 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700867 // If the caller has not asked for the document to be retained, then we may
868 // want to turn on auto-remove, depending on whether the target has set its
869 // own document launch mode.
870 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
871 autoRemoveRecents = false;
872 } else {
873 autoRemoveRecents = true;
874 }
875 } else {
876 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700877 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800878 mResizeMode = info.resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800879 mSupportsPictureInPicture = info.supportsPictureInPicture();
Craig Mautner15df08a2015-04-01 12:17:18 -0700880 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700881 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700882 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800884
Andrii Kulian2e751b82016-03-16 16:59:32 -0700885 /** Sets the original minimal width and height. */
886 private void setMinDimensions(ActivityInfo info) {
887 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700888 mMinWidth = info.windowLayout.minWidth;
889 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700890 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700891 mMinWidth = INVALID_MIN_SIZE;
892 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700893 }
894 }
895
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800896 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700897 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800898 * record is based on (normally the root activity intent).
899 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700900 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800901 final Intent intent = new Intent(r.intent);
902 // Correct the activity intent for aliasing. The task record intent will always be based on
903 // the real activity that will be launched not the alias, so we need to use an intent with
904 // the component name pointing to the real activity not the alias in the activity record.
905 intent.setComponent(r.realActivity);
906 return this.intent.filterEquals(intent);
907 }
908
Craig Mautner84984fa2014-06-19 11:19:20 -0700909 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800910 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
911 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700912 }
913
Winson Chung83471632016-12-13 11:02:12 -0800914 void setTaskToReturnTo(ActivityRecord source) {
915 if (source.isRecentsActivity()) {
916 setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
917 } else if (source.isAssistantActivity()) {
918 setTaskToReturnTo(ASSISTANT_ACTIVITY_TYPE);
919 }
920 }
921
Craig Mautner84984fa2014-06-19 11:19:20 -0700922 int getTaskToReturnTo() {
923 return mTaskToReturnTo;
924 }
925
Craig Mautnera228ae92014-07-09 05:44:55 -0700926 void setPrevAffiliate(TaskRecord prevAffiliate) {
927 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800928 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700929 }
930
931 void setNextAffiliate(TaskRecord nextAffiliate) {
932 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800933 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700934 }
935
Andrii Kulian02b7a832016-10-06 23:11:56 -0700936 ActivityStack getStack() {
937 return mStack;
938 }
939
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800940 /**
941 * Must be used for setting parent stack because it performs configuration updates.
942 * Must be called after adding task as a child to the stack.
943 */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700944 void setStack(ActivityStack stack) {
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800945 if (stack != null && !stack.isInStackLocked(this)) {
946 throw new IllegalStateException("Task must be added as a Stack child first.");
947 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700948 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700949 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700950 }
951
952 /**
953 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
954 */
955 int getStackId() {
956 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
957 }
958
Andrii Kulian1779e612016-10-12 21:58:25 -0700959 @Override
960 protected int getChildCount() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700961 return mActivities.size();
Andrii Kulian1779e612016-10-12 21:58:25 -0700962 }
963
964 @Override
965 protected ConfigurationContainer getChildAt(int index) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700966 return mActivities.get(index);
Andrii Kulian1779e612016-10-12 21:58:25 -0700967 }
968
969 @Override
970 protected ConfigurationContainer getParent() {
971 return mStack;
972 }
973
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800974 @Override
975 void onParentChanged() {
976 super.onParentChanged();
977 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
978 }
979
Craig Mautnera228ae92014-07-09 05:44:55 -0700980 // Close up recents linked list.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700981 private void closeRecentsChain() {
Craig Mautnera228ae92014-07-09 05:44:55 -0700982 if (mPrevAffiliate != null) {
983 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
984 }
985 if (mNextAffiliate != null) {
986 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
987 }
988 setPrevAffiliate(null);
989 setNextAffiliate(null);
990 }
991
Winson Chung740c3ac2014-11-12 16:14:38 -0800992 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700993 disposeThumbnail();
994 closeRecentsChain();
995 if (inRecents) {
996 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800997 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700998 }
Jorim Jaggif9084ec2017-01-16 13:16:59 +0100999
1000 // TODO: Use window container controller once tasks are better synced between AM and WM
1001 mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001002 }
1003
Craig Mautnera228ae92014-07-09 05:44:55 -07001004 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
1005 closeRecentsChain();
1006 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -07001007 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -07001008 // Find the end
1009 while (taskToAffiliateWith.mNextAffiliate != null) {
1010 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
1011 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
1012 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
1013 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
1014 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
1015 nextRecents.setPrevAffiliate(null);
1016 }
1017 taskToAffiliateWith.setNextAffiliate(null);
1018 break;
1019 }
1020 taskToAffiliateWith = nextRecents;
1021 }
1022 taskToAffiliateWith.setNextAffiliate(this);
1023 setPrevAffiliate(taskToAffiliateWith);
1024 setNextAffiliate(null);
1025 }
1026
Winson Chung096f36b2014-08-20 15:39:01 -07001027 /**
Winsonc809cbb2015-11-02 12:06:15 -08001028 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -07001029 * @return whether the thumbnail was set
1030 */
Winsonc809cbb2015-11-02 12:06:15 -08001031 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -08001032 int taskWidth = 0;
1033 int taskHeight = 0;
1034 if (mBounds != null) {
1035 // Non-fullscreen tasks
1036 taskWidth = mBounds.width();
1037 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001038 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -08001039 // Fullscreen tasks
1040 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001041 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -08001042 taskWidth = displaySize.x;
1043 taskHeight = displaySize.y;
1044 } else {
1045 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
1046 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001047 // We need to provide the current orientation of the display on which this task resides,
1048 // not the orientation of the task.
Andrii Kulian94e82d9b02017-07-13 15:33:06 -07001049 final int orientation = getStack().getDisplay().getConfiguration().orientation;
Andrii Kulian1779e612016-10-12 21:58:25 -07001050 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -08001051 }
1052
1053 /**
1054 * Sets the last thumbnail with the current task bounds.
1055 * @return whether the thumbnail was set
1056 */
1057 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
1058 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -07001059 if (mLastThumbnail != thumbnail) {
1060 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001061 mLastThumbnailInfo.taskWidth = taskWidth;
1062 mLastThumbnailInfo.taskHeight = taskHeight;
1063 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -07001064 if (thumbnail == null) {
1065 if (mLastThumbnailFile != null) {
1066 mLastThumbnailFile.delete();
1067 }
1068 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001069 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001070 }
Winson Chung096f36b2014-08-20 15:39:01 -07001071 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001072 }
Winson Chung096f36b2014-08-20 15:39:01 -07001073 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001074 }
1075
1076 void getLastThumbnail(TaskThumbnail thumbs) {
1077 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001078 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001079 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001080 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001081 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -08001082 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001083 }
Winson Chung096f36b2014-08-20 15:39:01 -07001084 // Only load the thumbnail file if we don't have a thumbnail
1085 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001086 try {
1087 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
1088 ParcelFileDescriptor.MODE_READ_ONLY);
1089 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -07001090 }
1091 }
1092 }
1093
Winsonc809cbb2015-11-02 12:06:15 -08001094 /**
1095 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
1096 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001097 void freeLastThumbnail() {
1098 mLastThumbnail = null;
1099 }
1100
Winsonc809cbb2015-11-02 12:06:15 -08001101 /**
1102 * Removes all associated thumbnail data when a task is removed or pruned from recents.
1103 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001104 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -08001105 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001106 mLastThumbnail = null;
1107 lastDescription = null;
1108 }
1109
Winson Chung1147c402014-05-14 11:05:00 -07001110 /** Returns the intent for the root activity for this task */
1111 Intent getBaseIntent() {
1112 return intent != null ? intent : affinityIntent;
1113 }
1114
Winson Chung942a85c2017-07-11 15:07:45 -07001115 /**
1116 * @return Whether there are only fullscreen activities in this task.
1117 */
1118 boolean containsOnlyFullscreenActivities() {
1119 for (int i = 0; i < mActivities.size(); i++) {
1120 final ActivityRecord r = mActivities.get(i);
1121 if (!r.finishing && !r.fullscreen) {
1122 return false;
1123 }
1124 }
1125 return true;
1126 }
1127
Winson Chung3b3f4642014-04-22 10:08:18 -07001128 /** Returns the first non-finishing activity from the root. */
1129 ActivityRecord getRootActivity() {
1130 for (int i = 0; i < mActivities.size(); i++) {
1131 final ActivityRecord r = mActivities.get(i);
1132 if (r.finishing) {
1133 continue;
1134 }
1135 return r;
1136 }
1137 return null;
1138 }
1139
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001140 ActivityRecord getTopActivity() {
1141 for (int i = mActivities.size() - 1; i >= 0; --i) {
1142 final ActivityRecord r = mActivities.get(i);
1143 if (r.finishing) {
1144 continue;
1145 }
1146 return r;
1147 }
1148 return null;
1149 }
1150
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -07001151 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001152 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001153 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1154 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -07001155 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001156 return r;
1157 }
Craig Mautner6b74cb52013-09-27 17:02:21 -07001158 }
1159 }
1160 return null;
1161 }
1162
Jorim Jaggiea039a82017-08-02 14:37:49 +02001163 void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) {
1164 if (mStack != null) {
1165 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1166 ActivityRecord r = mActivities.get(activityNdx);
Jorim Jaggi02f1d2f2017-08-04 14:29:16 +02001167 if (!r.finishing && r.okToShowLocked() && r.visibleIgnoringKeyguard) {
Jorim Jaggiea039a82017-08-02 14:37:49 +02001168 outActivities.add(r);
1169 }
1170 }
1171 }
1172 }
1173
Wale Ogunwale3b232392016-05-13 15:37:13 -07001174 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001175 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001176 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1177 ActivityRecord r = mActivities.get(activityNdx);
1178 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -07001179 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001180 continue;
1181 }
1182 return r;
1183 }
1184 }
1185 return null;
1186 }
1187
Chong Zhang87761972016-08-22 13:53:24 -07001188 boolean okToShowLocked() {
1189 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
1190 // okay to show the activity when locked.
1191 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
1192 || topRunningActivityLocked() != null;
1193 }
1194
Craig Mautner3b475fe2013-12-16 15:58:31 -08001195 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Bryce Leed71317c2017-02-07 14:27:22 -08001196 final void setFrontOfTask() {
1197 boolean foundFront = false;
Craig Mautner3b475fe2013-12-16 15:58:31 -08001198 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -08001199 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -08001200 final ActivityRecord r = mActivities.get(activityNdx);
1201 if (foundFront || r.finishing) {
1202 r.frontOfTask = false;
1203 } else {
1204 r.frontOfTask = true;
1205 // Set frontOfTask false for every following activity.
1206 foundFront = true;
1207 }
1208 }
Craig Mautner9587ee02014-06-23 15:00:10 +00001209 if (!foundFront && numActivities > 0) {
1210 // All activities of this task are finishing. As we ought to have a frontOfTask
1211 // activity, make the bottom activity front.
1212 mActivities.get(0).frontOfTask = true;
1213 }
Craig Mautner3b475fe2013-12-16 15:58:31 -08001214 }
1215
Craig Mautnerde4ef022013-04-07 19:01:33 -07001216 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -08001217 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -07001218 */
1219 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001220 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
1221 "Removing and adding activity " + newTop
1222 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -07001223
Craig Mautnerde4ef022013-04-07 19:01:33 -07001224 mActivities.remove(newTop);
1225 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001226 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -08001227
Bryce Leed71317c2017-02-07 14:27:22 -08001228 setFrontOfTask();
Craig Mautnerde4ef022013-04-07 19:01:33 -07001229 }
1230
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001231 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -08001232 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001233 }
1234
1235 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001236 addActivityAtIndex(mActivities.size(), r);
1237 }
1238
Winson Chung30480042017-01-26 10:55:34 -08001239 /**
1240 * Adds an activity {@param r} at the given {@param index}. The activity {@param r} must either
1241 * be in the current task or unparented to any task.
1242 */
Craig Mautner1602ec22013-05-12 10:24:27 -07001243 void addActivityAtIndex(int index, ActivityRecord r) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001244 TaskRecord task = r.getTask();
1245 if (task != null && task != this) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001246 throw new IllegalArgumentException("Can not add r=" + " to task=" + this
Bryce Leeaf691c02017-03-20 14:20:22 -07001247 + " current parent=" + task);
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001248 }
Bryce Leeaf691c02017-03-20 14:20:22 -07001249
1250 r.setTask(this);
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001251
Craig Mautner6170f732013-04-02 13:05:23 -07001252 // 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 -08001253 if (!mActivities.remove(r) && r.fullscreen) {
1254 // Was not previously in list.
1255 numFullscreen++;
1256 }
Craig Mautner2c1faed2013-07-23 12:56:02 -07001257 // Only set this based on the first activity
1258 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001259 taskType = r.mActivityType;
1260 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001261 mCallingUid = r.launchedFromUid;
1262 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001263 // Clamp to [1, max].
1264 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
1265 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -07001266 } else {
1267 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -07001268 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -07001269 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001270
1271 final int size = mActivities.size();
1272
1273 if (index == size && size > 0) {
1274 final ActivityRecord top = mActivities.get(size - 1);
1275 if (top.mTaskOverlay) {
1276 // Place below the task overlay activity since the overlay activity should always
1277 // be on top.
1278 index--;
1279 }
1280 }
1281
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001282 index = Math.min(size, index);
Craig Mautner77878772013-03-04 19:46:24 -08001283 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001284 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001285 if (r.isPersistable()) {
1286 mService.notifyTaskPersisterLocked(this, false);
1287 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001288
1289 // Sync. with window manager
1290 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001291 final AppWindowContainerController appController = r.getWindowContainerController();
1292 if (appController != null) {
1293 // Only attempt to move in WM if the child has a controller. It is possible we haven't
1294 // created controller for the activity we are starting yet.
1295 mWindowContainerController.positionChildAt(appController, index);
1296 }
David Stevens82ea6cb2017-03-03 16:18:50 -08001297
1298 // Make sure the list of display UID whitelists is updated
1299 // now that this record is in a new task.
1300 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
Craig Mautner77878772013-03-04 19:46:24 -08001301 }
1302
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001303 /**
Bryce Leeaf691c02017-03-20 14:20:22 -07001304 * Removes the specified activity from this task.
1305 * @param r The {@link ActivityRecord} to remove.
1306 * @return true if this was the last activity in the task.
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001307 */
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001308 boolean removeActivity(ActivityRecord r) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001309 return removeActivity(r, false /*reparenting*/);
1310 }
1311
1312 boolean removeActivity(ActivityRecord r, boolean reparenting) {
1313 if (r.getTask() != this) {
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001314 throw new IllegalArgumentException(
1315 "Activity=" + r + " does not belong to task=" + this);
1316 }
1317
Bryce Leeaf691c02017-03-20 14:20:22 -07001318 r.setTask(null /*task*/, reparenting);
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001319
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001320 if (mActivities.remove(r) && r.fullscreen) {
1321 // Was previously in list.
1322 numFullscreen--;
1323 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001324 if (r.isPersistable()) {
1325 mService.notifyTaskPersisterLocked(this, false);
1326 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001327
Andrii Kulian02b7a832016-10-06 23:11:56 -07001328 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001329 // We normally notify listeners of task stack changes on pause, however pinned stack
1330 // activities are normally in the paused state so no notification will be sent there
1331 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001332 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001333 }
1334
Craig Mautner41326202014-06-20 14:38:21 -07001335 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001336 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001337 }
1338 updateEffectiveIntent();
1339 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001340 }
1341
Winson Chung6954fc92017-03-24 16:22:12 -07001342 /**
1343 * @return whether or not there are ONLY task overlay activities in the stack.
1344 * If {@param excludeFinishing} is set, then ignore finishing activities in the check.
1345 * If there are no task overlay activities, this call returns false.
1346 */
1347 boolean onlyHasTaskOverlayActivities(boolean excludeFinishing) {
1348 int count = 0;
1349 for (int i = mActivities.size() - 1; i >= 0; i--) {
1350 final ActivityRecord r = mActivities.get(i);
1351 if (excludeFinishing && r.finishing) {
1352 continue;
1353 }
1354 if (!r.mTaskOverlay) {
1355 return false;
1356 }
1357 count++;
1358 }
1359 return count > 0;
1360 }
1361
Craig Mautner41db4a72014-05-07 17:20:56 -07001362 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001363 // We will automatically remove the task either if it has explicitly asked for
1364 // this, or it is empty and has never contained an activity that got shown to
1365 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001366 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001367 }
1368
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001369 /**
1370 * Completely remove all activities associated with an existing
1371 * task starting at a specified index.
1372 */
Winson Chung6954fc92017-03-24 16:22:12 -07001373 final void performClearTaskAtIndexLocked(int activityNdx, boolean pauseImmediately) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001374 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001375 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001376 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001377 if (r.finishing) {
1378 continue;
1379 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001380 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001381 // Task was restored from persistent storage.
1382 r.takeFromHistory();
1383 mActivities.remove(activityNdx);
1384 --activityNdx;
1385 --numActivities;
Winson Chung6954fc92017-03-24 16:22:12 -07001386 } else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null,
1387 "clear-task-index", false, pauseImmediately)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001388 --activityNdx;
1389 --numActivities;
1390 }
1391 }
1392 }
1393
1394 /**
1395 * Completely remove all activities associated with an existing task.
1396 */
1397 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001398 mReuseTask = true;
Winson Chung6954fc92017-03-24 16:22:12 -07001399 performClearTaskAtIndexLocked(0, !PAUSE_IMMEDIATELY);
Craig Mautner362449a2014-06-20 14:04:39 -07001400 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001401 }
1402
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001403 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1404 mReuseTask = true;
1405 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1406 mReuseTask = false;
1407 return result;
1408 }
1409
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001410 /**
1411 * Perform clear operation as requested by
1412 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1413 * stack to the given task, then look for
1414 * an instance of that activity in the stack and, if found, finish all
1415 * activities on top of it and return the instance.
1416 *
1417 * @param newR Description of the new activity being started.
1418 * @return Returns the old activity that should be continued to be used,
1419 * or null if none was found.
1420 */
1421 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001422 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001423 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001424 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001425 if (r.finishing) {
1426 continue;
1427 }
1428 if (r.realActivity.equals(newR.realActivity)) {
1429 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001430 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001431
1432 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001433 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001434 if (r.finishing) {
1435 continue;
1436 }
1437 ActivityOptions opts = r.takeOptionsLocked();
1438 if (opts != null) {
1439 ret.updateOptionsLocked(opts);
1440 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001441 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001442 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001443 --activityNdx;
1444 --numActivities;
1445 }
1446 }
1447
1448 // Finally, if this is a normal launch mode (that is, not
1449 // expecting onNewIntent()), then we will finish the current
1450 // instance of the activity so a new fresh one can be started.
1451 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001452 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1453 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001454 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001455 if (mStack != null) {
1456 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001457 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1458 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001459 return null;
1460 }
1461 }
1462
1463 return ret;
1464 }
1465 }
1466
1467 return null;
1468 }
1469
Andrii Kulian21713ac2016-10-12 22:05:05 -07001470 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001471 if (mStack != null) {
1472 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Bryce Leeaf691c02017-03-20 14:20:22 -07001473 if (resumedActivity != null && resumedActivity.getTask() == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001474 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001475 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001476 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001477 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001478 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1479 getLastThumbnail(taskThumbnail);
1480 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001481 }
1482
Winson Chung6954fc92017-03-24 16:22:12 -07001483 void removeTaskActivitiesLocked(boolean pauseImmediately) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001484 // Just remove the entire task.
Winson Chung6954fc92017-03-24 16:22:12 -07001485 performClearTaskAtIndexLocked(0, pauseImmediately);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001486 }
1487
Craig Mautner432f64e2015-05-20 14:59:57 -07001488 String lockTaskAuthToString() {
1489 switch (mLockTaskAuth) {
1490 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1491 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1492 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1493 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001494 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001495 default: return "unknown=" + mLockTaskAuth;
1496 }
1497 }
1498
Craig Mautner15df08a2015-04-01 12:17:18 -07001499 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001500 if (!mPrivileged &&
1501 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1502 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1503 // Non-priv apps are not allowed to use always or never, fall back to default
1504 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1505 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001506 switch (mLockTaskMode) {
1507 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1508 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1509 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1510 break;
1511
1512 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001513 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001514 break;
1515
1516 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001517 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001518 break;
1519
1520 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1521 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1522 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1523 break;
1524 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001525 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1526 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001527 }
1528
1529 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001530 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1531 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001532 return false;
1533 }
1534 String[] packages = mService.mLockTaskPackages.get(userId);
1535 if (packages == null) {
1536 return false;
1537 }
1538 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001539 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001540 return true;
1541 }
1542 }
1543 return false;
1544 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001545
Craig Mautnera82aa092013-09-13 15:34:08 -07001546 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001547 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001548 }
1549
Wale Ogunwale74e26592016-02-05 11:48:37 -08001550 boolean isRecentsTask() {
1551 return taskType == RECENTS_ACTIVITY_TYPE;
1552 }
1553
Winson Chung83471632016-12-13 11:02:12 -08001554 boolean isAssistantTask() {
1555 return taskType == ASSISTANT_ACTIVITY_TYPE;
1556 }
1557
Craig Mautner86d67a42013-05-14 10:34:38 -07001558 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001559 return taskType == APPLICATION_ACTIVITY_TYPE;
1560 }
1561
1562 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001563 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001564 }
1565
Winson Chung83471632016-12-13 11:02:12 -08001566 boolean isOverAssistantStack() {
1567 return mTaskToReturnTo == ASSISTANT_ACTIVITY_TYPE;
1568 }
1569
Winson Chungd3395382016-12-13 11:49:09 -08001570 private boolean isResizeable(boolean checkSupportsPip) {
1571 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode)
1572 || (checkSupportsPip && mSupportsPictureInPicture)) && !mTemporarilyUnresizable;
1573 }
1574
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001575 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001576 return isResizeable(true /* checkSupportsPip */);
1577 }
1578
1579 boolean supportsSplitScreen() {
1580 // A task can not be docked even if it is considered resizeable because it only supports
1581 // picture-in-picture mode but has a non-resizeable resizeMode
1582 return mService.mSupportsSplitScreenMultiWindow
Bryce Leec857a5b2017-08-16 10:04:52 -07001583 && (mService.mForceResizableActivities
1584 || (isResizeable(false /* checkSupportsPip */)
1585 && !ActivityInfo.isPreserveOrientationMode(mResizeMode)));
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001586 }
1587
skuhne@google.com322347b2016-12-02 12:54:03 -08001588 /**
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001589 * Check whether this task can be launched on the specified display.
1590 * @param displayId Target display id.
1591 * @return {@code true} if either it is the default display or this activity is resizeable and
1592 * can be put a secondary screen.
1593 */
1594 boolean canBeLaunchedOnDisplay(int displayId) {
1595 return mService.mStackSupervisor.canPlaceEntityOnDisplay(displayId,
Andrii Kulian02689a72017-07-06 14:28:59 -07001596 isResizeable(false /* checkSupportsPip */), -1 /* don't check PID */,
1597 -1 /* don't check UID */, null /* activityInfo */);
Andrii Kulian036e3ad2017-04-19 10:55:10 -07001598 }
1599
1600 /**
skuhne@google.com322347b2016-12-02 12:54:03 -08001601 * Check that a given bounds matches the application requested orientation.
1602 *
1603 * @param bounds The bounds to be tested.
1604 * @return True if the requested bounds are okay for a resizing request.
1605 */
Wale Ogunwale069bbd32017-02-03 07:58:14 -08001606 private boolean canResizeToBounds(Rect bounds) {
skuhne@google.com322347b2016-12-02 12:54:03 -08001607 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1608 // Note: If not on the freeform workspace, we ignore the bounds.
1609 return true;
1610 }
1611 final boolean landscape = bounds.width() > bounds.height();
1612 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1613 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1614 }
1615 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1616 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1617 }
1618
Craig Mautner525f3d92013-05-07 14:01:50 -07001619 /**
Yorke Leebdef5372017-04-10 16:38:51 -07001620 * @return {@code true} if the task is being cleared for the purposes of being reused.
1621 */
1622 boolean isClearingToReuseTask() {
1623 return mReuseTask;
1624 }
1625
1626 /**
Craig Mautner525f3d92013-05-07 14:01:50 -07001627 * Find the activity in the history stack within the given task. Returns
1628 * the index within the history at which it's found, or < 0 if not found.
1629 */
1630 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1631 final ComponentName realActivity = r.realActivity;
1632 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1633 ActivityRecord candidate = mActivities.get(activityNdx);
1634 if (candidate.finishing) {
1635 continue;
1636 }
1637 if (candidate.realActivity.equals(realActivity)) {
1638 return candidate;
1639 }
1640 }
1641 return null;
1642 }
1643
Winson Chunga449dc02014-05-16 11:15:04 -07001644 /** Updates the last task description values. */
1645 void updateTaskDescription() {
1646 // Traverse upwards looking for any break between main task activities and
1647 // utility activities.
1648 int activityNdx;
1649 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001650 final boolean relinquish = numActivities != 0 &&
1651 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001652 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001653 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001654 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001655 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001656 // This will be the top activity for determining taskDescription. Pre-inc to
1657 // overcome initial decrement below.
1658 ++activityNdx;
1659 break;
1660 }
Winson Chunga449dc02014-05-16 11:15:04 -07001661 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001662 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001663 break;
1664 }
1665 }
1666 if (activityNdx > 0) {
1667 // Traverse downwards starting below break looking for set label, icon.
1668 // Note that if there are activities in the task but none of them set the
1669 // recent activity values, then we do not fall back to the last set
1670 // values in the TaskRecord.
1671 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001672 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001673 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001674 int colorBackground = 0;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001675 int statusBarColor = 0;
1676 int navigationBarColor = 0;
1677 boolean topActivity = true;
Winson Chunga449dc02014-05-16 11:15:04 -07001678 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1679 final ActivityRecord r = mActivities.get(activityNdx);
1680 if (r.taskDescription != null) {
1681 if (label == null) {
1682 label = r.taskDescription.getLabel();
1683 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001684 if (iconFilename == null) {
1685 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001686 }
1687 if (colorPrimary == 0) {
1688 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001689 }
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001690 if (topActivity) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001691 colorBackground = r.taskDescription.getBackgroundColor();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001692 statusBarColor = r.taskDescription.getStatusBarColor();
1693 navigationBarColor = r.taskDescription.getNavigationBarColor();
Winson Chung1af8eda2016-02-05 17:55:56 +00001694 }
Winson Chunga449dc02014-05-16 11:15:04 -07001695 }
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001696 topActivity = false;
Winson Chunga449dc02014-05-16 11:15:04 -07001697 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001698 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001699 colorBackground, statusBarColor, navigationBarColor);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +01001700 if (mWindowContainerController != null) {
1701 mWindowContainerController.setTaskDescription(lastTaskDescription);
1702 }
Winson Chungec396d62014-08-06 17:08:00 -07001703 // Update the task affiliation color if we are the parent of the group
1704 if (taskId == mAffiliatedTaskId) {
1705 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1706 }
Winson Chunga449dc02014-05-16 11:15:04 -07001707 }
1708 }
1709
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001710 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001711 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001712 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001713 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001714 final ActivityRecord r = mActivities.get(activityNdx);
1715 if (r.finishing) {
1716 continue;
1717 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001718 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001719 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001720 break;
1721 }
1722 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001723 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001724 }
1725
1726 void updateEffectiveIntent() {
1727 final int effectiveRootIndex = findEffectiveRootIndex();
1728 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001729 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001730 }
1731
Craig Mautner21d24a22014-04-23 11:45:37 -07001732 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001733 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001734
1735 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1736 if (realActivity != null) {
1737 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1738 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001739 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001740 if (origActivity != null) {
1741 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1742 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001743 // Write affinity, and root affinity if it is different from affinity.
1744 // We use the special string "@" for a null root affinity, so we can identify
1745 // later whether we were given a root affinity or should just make it the
1746 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001747 if (affinity != null) {
1748 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001749 if (!affinity.equals(rootAffinity)) {
1750 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1751 }
1752 } else if (rootAffinity != null) {
1753 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001754 }
1755 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001756 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001757 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1758 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001759 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001760 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001761 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001762 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001763 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001764 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001765 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001766 if (lastDescription != null) {
1767 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1768 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001769 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001770 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001771 }
Winson Chung36f3f032016-09-08 23:29:43 +00001772 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001773 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001774 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1775 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1776 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001777 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1778 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001779 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08001780 out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE,
1781 String.valueOf(mSupportsPictureInPicture));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001782 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001783 if (mLastNonFullscreenBounds != null) {
1784 out.attribute(
1785 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001786 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001787 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1788 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001789 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001790
Craig Mautner21d24a22014-04-23 11:45:37 -07001791 if (affinityIntent != null) {
1792 out.startTag(null, TAG_AFFINITYINTENT);
1793 affinityIntent.saveToXml(out);
1794 out.endTag(null, TAG_AFFINITYINTENT);
1795 }
1796
Winson Chung36f3f032016-09-08 23:29:43 +00001797 out.startTag(null, TAG_INTENT);
1798 intent.saveToXml(out);
1799 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001800
1801 final ArrayList<ActivityRecord> activities = mActivities;
1802 final int numActivities = activities.size();
1803 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1804 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001805 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001806 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1807 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001808 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001809 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001810 break;
1811 }
1812 out.startTag(null, TAG_ACTIVITY);
1813 r.saveToXml(out);
1814 out.endTag(null, TAG_ACTIVITY);
1815 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001816 }
1817
Winson Chung36f3f032016-09-08 23:29:43 +00001818 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1819 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001820 Intent intent = null;
1821 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001822 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001823 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001824 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001825 ComponentName origActivity = null;
1826 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001827 String rootAffinity = null;
1828 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001829 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001830 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001831 boolean askedCompatMode = false;
1832 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001833 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001834 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001835 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001836 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001837 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001838 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001839 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001840 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001841 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001842 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001843 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001844 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001845 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001846 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001847 int prevTaskId = INVALID_TASK_ID;
1848 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001849 int callingUid = -1;
1850 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001851 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -08001852 boolean supportsPictureInPicture = false;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001853 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001854 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001855 int minWidth = INVALID_MIN_SIZE;
1856 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001857 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001858
1859 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1860 final String attrName = in.getAttributeName(attrNdx);
1861 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001862 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1863 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001864 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001865 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001866 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1867 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001868 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1869 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001870 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1871 origActivity = ComponentName.unflattenFromString(attrValue);
1872 } else if (ATTR_AFFINITY.equals(attrName)) {
1873 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001874 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1875 rootAffinity = attrValue;
1876 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001877 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001878 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001879 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001880 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001881 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001882 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001883 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001884 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001885 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001886 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001887 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001888 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001889 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001890 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001891 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001892 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001893 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001894 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001895 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1896 lastDescription = attrValue;
1897 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001898 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001899 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001900 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001901 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1902 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001903 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1904 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001905 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001906 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001907 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001908 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001909 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001910 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001911 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001912 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001913 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001914 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001915 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1916 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001917 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001918 resizeMode = Integer.parseInt(attrValue);
Winson Chungd3395382016-12-13 11:49:09 -08001919 } else if (ATTR_SUPPORTS_PICTURE_IN_PICTURE.equals(attrName)) {
1920 supportsPictureInPicture = Boolean.parseBoolean(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001921 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001922 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001923 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001924 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001925 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1926 minWidth = Integer.parseInt(attrValue);
1927 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1928 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001929 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1930 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001931 } else {
1932 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1933 }
1934 }
1935
1936 int event;
1937 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001938 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001939 if (event == XmlPullParser.START_TAG) {
1940 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001941 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1942 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001943 if (TAG_AFFINITYINTENT.equals(name)) {
1944 affinityIntent = Intent.restoreFromXml(in);
1945 } else if (TAG_INTENT.equals(name)) {
1946 intent = Intent.restoreFromXml(in);
1947 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001948 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001949 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1950 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001951 if (activity != null) {
1952 activities.add(activity);
1953 }
1954 } else {
1955 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1956 XmlUtils.skipCurrentTag(in);
1957 }
1958 }
1959 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001960 if (!hasRootAffinity) {
1961 rootAffinity = affinity;
1962 } else if ("@".equals(rootAffinity)) {
1963 rootAffinity = null;
1964 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001965 if (effectiveUid <= 0) {
1966 Intent checkIntent = intent != null ? intent : affinityIntent;
1967 effectiveUid = 0;
1968 if (checkIntent != null) {
1969 IPackageManager pm = AppGlobals.getPackageManager();
1970 try {
1971 ApplicationInfo ai = pm.getApplicationInfo(
1972 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001973 PackageManager.MATCH_UNINSTALLED_PACKAGES
1974 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001975 if (ai != null) {
1976 effectiveUid = ai.uid;
1977 }
1978 } catch (RemoteException e) {
1979 }
1980 }
1981 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1982 + ": effectiveUid=" + effectiveUid);
1983 }
1984
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001985 if (persistTaskVersion < 1) {
1986 // We need to convert the resize mode of home activities saved before version one if
1987 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1988 // since we didn't have that differentiation before version 1 and the system didn't
1989 // resize home activities before then.
1990 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1991 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1992 }
Winson Chungd3395382016-12-13 11:49:09 -08001993 } else {
1994 // This activity has previously marked itself explicitly as both resizeable and
1995 // supporting picture-in-picture. Since there is no longer a requirement for
1996 // picture-in-picture activities to be resizeable, we can mark this simply as
1997 // resizeable and supporting picture-in-picture separately.
1998 if (resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED) {
1999 resizeMode = RESIZE_MODE_RESIZEABLE;
2000 supportsPictureInPicture = true;
2001 }
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07002002 }
2003
Winson Chung36f3f032016-09-08 23:29:43 +00002004 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07002005 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07002006 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
2007 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08002008 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Winson Chungd3395382016-12-13 11:49:09 -08002009 taskAffiliationColor, callingUid, callingPackage, resizeMode,
2010 supportsPictureInPicture, privileged, realActivitySuspended, userSetupComplete,
2011 minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07002012 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07002013
2014 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Bryce Leeaf691c02017-03-20 14:20:22 -07002015 activities.get(activityNdx).setTask(task);
Craig Mautner21d24a22014-04-23 11:45:37 -07002016 }
2017
Wale Ogunwaleee006da2015-03-30 14:49:25 -07002018 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07002019 return task;
2020 }
2021
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002022 private void adjustForMinimalTaskDimensions(Rect bounds) {
2023 if (bounds == null) {
2024 return;
2025 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002026 int minWidth = mMinWidth;
2027 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08002028 // If the task has no requested minimal size, we'd like to enforce a minimal size
2029 // so that the user can not render the task too small to manipulate. We don't need
2030 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07002031 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002032 if (minWidth == INVALID_MIN_SIZE) {
2033 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07002034 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002035 if (minHeight == INVALID_MIN_SIZE) {
2036 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07002037 }
Robert Carr9c5867d2016-03-10 15:52:46 -08002038 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002039 final boolean adjustWidth = minWidth > bounds.width();
2040 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002041 if (!(adjustWidth || adjustHeight)) {
2042 return;
2043 }
2044
2045 if (adjustWidth) {
2046 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002047 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002048 } else {
2049 // Either left bounds match, or neither match, or the previous bounds were
2050 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002051 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002052 }
2053 }
2054 if (adjustHeight) {
2055 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002056 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002057 } else {
2058 // Either top bounds match, or neither match, or the previous bounds were
2059 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002060 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002061 }
2062 }
2063 }
2064
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002065 /**
Winson Chung5af42fc2017-03-24 17:11:33 -07002066 * @return a new Configuration for this Task, given the provided {@param bounds} and
2067 * {@param insetBounds}.
2068 */
2069 Configuration computeNewOverrideConfigurationForBounds(Rect bounds, Rect insetBounds) {
2070 // Compute a new override configuration for the given bounds, if fullscreen bounds
2071 // (bounds == null), then leave the override config unset
2072 final Configuration newOverrideConfig = new Configuration();
2073 if (bounds != null) {
2074 newOverrideConfig.setTo(getOverrideConfiguration());
2075 mTmpRect.set(bounds);
2076 adjustForMinimalTaskDimensions(mTmpRect);
2077 computeOverrideConfiguration(newOverrideConfig, mTmpRect, insetBounds,
2078 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
2079 }
2080
2081 return newOverrideConfig;
2082 }
2083
2084 /**
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002085 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002086 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07002087 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002088 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002089 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08002090 return updateOverrideConfiguration(bounds, null /* insetBounds */);
2091 }
2092
2093 /**
2094 * Update task's override configuration based on the bounds.
2095 * @param bounds The bounds of the task.
2096 * @param insetBounds The bounds used to calculate the system insets, which is used here to
2097 * subtract the navigation bar/status bar size from the screen size reported
2098 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07002099 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002100 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002101 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002102 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07002103 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002104 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002105 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08002106 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07002107 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002108
2109 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002110 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002111 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002112 mLastNonFullscreenBounds = mBounds;
2113 }
2114 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07002115 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07002116 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002117 mTmpRect.set(bounds);
2118 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002119 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002120 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002121 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002122 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002123 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002124 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07002125 mLastNonFullscreenBounds = mBounds;
2126 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002127 computeOverrideConfiguration(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07002128 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07002129 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002130 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002131
2132 if (mFullscreen != oldFullscreen) {
Winson Chung5af42fc2017-03-24 17:11:33 -07002133 mService.mStackSupervisor.scheduleUpdateMultiWindowMode(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002134 }
2135
Andrii Kulian1779e612016-10-12 21:58:25 -07002136 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002137 }
2138
Andrii Kulian1779e612016-10-12 21:58:25 -07002139 /** Clears passed config and fills it with new override values. */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002140 // TODO(b/36505427): TaskRecord.computeOverrideConfiguration() is a utility method that doesn't
2141 // depend on task or stacks, but uses those object to get the display to base the calculation
2142 // on. Probably best to centralize calculations like this in ConfigurationContainer.
2143 void computeOverrideConfiguration(Configuration config, Rect bounds, Rect insetBounds,
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002144 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002145 mTmpNonDecorBounds.set(bounds);
2146 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002147
Andrii Kulian1779e612016-10-12 21:58:25 -07002148 config.unset();
Winson Chungbdc646f2017-02-13 12:12:22 -08002149 final Configuration parentConfig = getParent().getConfiguration();
Bryce Lee7566d762017-03-30 09:34:15 -07002150
Andrii Kulian1779e612016-10-12 21:58:25 -07002151 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002152
Winson Chungbdc646f2017-02-13 12:12:22 -08002153 if (mStack != null) {
2154 final StackWindowController stackController = mStack.getWindowContainerController();
2155 stackController.adjustConfigurationForBounds(bounds, insetBounds,
2156 mTmpNonDecorBounds, mTmpStableBounds, overrideWidth, overrideHeight, density,
2157 config, parentConfig);
2158 } else {
Bryce Lee7566d762017-03-30 09:34:15 -07002159 throw new IllegalArgumentException("Expected stack when calculating override config");
Winson Chungbdc646f2017-02-13 12:12:22 -08002160 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002161
Winson Chung60c1aba2017-03-14 17:47:42 -07002162 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
2163 ? Configuration.ORIENTATION_PORTRAIT
2164 : Configuration.ORIENTATION_LANDSCAPE;
2165
Jorim Jaggi85639432016-05-06 17:27:55 -07002166 // For calculating screen layout, we need to use the non-decor inset screen area for the
2167 // calculation for compatibility reasons, i.e. screen area without system bars that could
2168 // never go away in Honeycomb.
Winson Chungbdc646f2017-02-13 12:12:22 -08002169 final int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density);
2170 final int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07002171 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
2172 // calculation with partial default.
2173 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002174 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07002175 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07002176 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
2177
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08002178 }
2179
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002180 Rect updateOverrideConfigurationFromLaunchBounds() {
2181 final Rect bounds = validateBounds(getLaunchBounds());
2182 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07002183 if (bounds != null) {
2184 bounds.set(mBounds);
2185 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002186 return bounds;
2187 }
2188
2189 static Rect validateBounds(Rect bounds) {
2190 if (bounds != null && bounds.isEmpty()) {
2191 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
2192 return null;
2193 }
2194 return bounds;
2195 }
2196
Wale Ogunwale935e5022015-11-10 12:36:10 -08002197 /** Updates the task's bounds and override configuration to match what is expected for the
2198 * input stack. */
2199 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002200 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002201 return;
2202 }
2203
2204 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002205 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002206 throw new IllegalArgumentException("Can not position non-resizeable task="
2207 + this + " in stack=" + inStack);
2208 }
2209 if (mBounds != null) {
2210 return;
2211 }
2212 if (mLastNonFullscreenBounds != null) {
2213 updateOverrideConfiguration(mLastNonFullscreenBounds);
2214 } else {
2215 inStack.layoutTaskInStack(this, null);
2216 }
2217 } else {
2218 updateOverrideConfiguration(inStack.mBounds);
2219 }
2220 }
2221
Chong Zhang0fa656b2015-08-31 15:17:21 -07002222 /**
2223 * Returns the correct stack to use based on task type and currently set bounds,
2224 * regardless of the focused stack and current stack association of the task.
2225 * The task will be moved (and stack focus changed) later if necessary.
2226 */
2227 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002228 if (isRecentsTask()) {
2229 return RECENTS_STACK_ID;
2230 }
2231 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002232 return HOME_STACK_ID;
2233 }
Winson Chung83471632016-12-13 11:02:12 -08002234 if (isAssistantTask()) {
2235 return ASSISTANT_STACK_ID;
2236 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07002237 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002238 return FREEFORM_WORKSPACE_STACK_ID;
2239 }
2240 return FULLSCREEN_WORKSPACE_STACK_ID;
2241 }
2242
2243 /** Returns the bounds that should be used to launch this task. */
2244 Rect getLaunchBounds() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002245 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08002246 return null;
2247 }
2248
Andrii Kulian02b7a832016-10-06 23:11:56 -07002249 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08002250 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002251 || stackId == RECENTS_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -08002252 || stackId == ASSISTANT_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08002253 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002254 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002255 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07002256 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002257 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002258 }
2259 return mLastNonFullscreenBounds;
2260 }
2261
Jorim Jaggi8b702ed2017-01-20 16:59:03 +01002262 void addStartingWindowsForVisibleActivities(boolean taskSwitch) {
2263 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
2264 final ActivityRecord r = mActivities.get(activityNdx);
2265 if (r.visible) {
2266 r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch);
2267 }
2268 }
2269 }
2270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002272 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07002273 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
2274 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08002275 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002276 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07002277 if (affinity != null || rootAffinity != null) {
2278 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
2279 if (affinity == null || !affinity.equals(rootAffinity)) {
2280 pw.print(" root="); pw.println(rootAffinity);
2281 } else {
2282 pw.println();
2283 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002284 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07002285 if (voiceSession != null || voiceInteractor != null) {
2286 pw.print(prefix); pw.print("VOICE: session=0x");
2287 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
2288 pw.print(" interactor=0x");
2289 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
2290 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002291 if (intent != null) {
2292 StringBuilder sb = new StringBuilder(128);
2293 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002294 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002295 sb.append('}');
2296 pw.println(sb.toString());
2297 }
2298 if (affinityIntent != null) {
2299 StringBuilder sb = new StringBuilder(128);
2300 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002301 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002302 sb.append('}');
2303 pw.println(sb.toString());
2304 }
2305 if (origActivity != null) {
2306 pw.print(prefix); pw.print("origActivity=");
2307 pw.println(origActivity.flattenToShortString());
2308 }
2309 if (realActivity != null) {
2310 pw.print(prefix); pw.print("realActivity=");
2311 pw.println(realActivity.flattenToShortString());
2312 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07002313 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
2314 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002315 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002316 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002317 pw.print(" numFullscreen="); pw.print(numFullscreen);
2318 pw.print(" taskType="); pw.print(taskType);
2319 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
2320 }
Craig Mautner432f64e2015-05-20 14:59:57 -07002321 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
2322 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002323 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
2324 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07002325 pw.print(" mReuseTask="); pw.print(mReuseTask);
2326 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002327 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08002328 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
2329 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
2330 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07002331 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
2332 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
2333 pw.print(" (");
2334 if (mPrevAffiliate == null) {
2335 pw.print("null");
2336 } else {
2337 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
2338 }
2339 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
2340 pw.print(" (");
2341 if (mNextAffiliate == null) {
2342 pw.print("null");
2343 } else {
2344 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2345 }
2346 pw.println(")");
2347 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002348 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002349 if (!askedCompatMode || !inRecents || !isAvailable) {
2350 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2351 pw.print(" inRecents="); pw.print(inRecents);
2352 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002353 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002354 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002355 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2356 if (lastDescription != null) {
2357 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2358 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002359 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002360 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2361 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08002362 pw.print(" mSupportsPictureInPicture=" + mSupportsPictureInPicture);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002363 pw.print(" isResizeable=" + isResizeable());
daqi961e50e2017-05-30 15:37:23 +08002364 pw.print(" firstActiveTime=" + firstActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002365 pw.print(" lastActiveTime=" + lastActiveTime);
2366 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 }
2368
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002369 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002371 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002372 if (stringName != null) {
2373 sb.append(stringName);
2374 sb.append(" U=");
2375 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002376 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002377 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002378 sb.append(" sz=");
2379 sb.append(mActivities.size());
2380 sb.append('}');
2381 return sb.toString();
2382 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002383 sb.append("TaskRecord{");
2384 sb.append(Integer.toHexString(System.identityHashCode(this)));
2385 sb.append(" #");
2386 sb.append(taskId);
2387 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002388 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002389 sb.append(affinity);
2390 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002391 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002392 sb.append(intent.getComponent().flattenToShortString());
2393 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002394 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002395 sb.append(affinityIntent.getComponent().flattenToShortString());
2396 } else {
2397 sb.append(" ??");
2398 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002399 stringName = sb.toString();
2400 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 }
2402}