blob: 2d5825af716628f742b50dec3fe0e63a0a8b65bb [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
Dianne Hackborn91097de2014-04-04 18:02:06 -070051import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070052import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080053
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -080054import com.android.server.wm.AppWindowContainerController;
Winson Chungbdc646f2017-02-13 12:12:22 -080055import com.android.server.wm.StackWindowController;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080056import com.android.server.wm.TaskWindowContainerController;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010057import com.android.server.wm.TaskWindowContainerListener;
Winson Chung74666102017-02-22 17:49:24 -080058import com.android.server.wm.WindowManagerService;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010059
Craig Mautner21d24a22014-04-23 11:45:37 -070060import org.xmlpull.v1.XmlPullParser;
61import org.xmlpull.v1.XmlPullParserException;
62import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063
Craig Mautnerc0ffce52014-07-01 12:38:52 -070064import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070065import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import java.io.PrintWriter;
Winson Chung74666102017-02-22 17:49:24 -080067import java.lang.annotation.Retention;
68import java.lang.annotation.RetentionPolicy;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080069import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070070import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080072import static android.app.ActivityManager.RESIZE_MODE_FORCED;
Winson Chung74666102017-02-22 17:49:24 -080073import static android.app.ActivityManager.RESIZE_MODE_SYSTEM;
Winson Chung83471632016-12-13 11:02:12 -080074import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080075import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
76import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
77import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
78import static android.app.ActivityManager.StackId.HOME_STACK_ID;
79import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
80import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Matthew Ngae1ff4f2016-11-10 15:49:14 -080081import static android.app.ActivityManager.StackId.RECENTS_STACK_ID;
Jorim Jaggi0a932142016-02-01 17:42:25 -080082import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
83import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070084import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
Jorim Jaggi0a932142016-02-01 17:42:25 -080085import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
86import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
87import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
88import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
skuhne@google.com322347b2016-12-02 12:54:03 -080089import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
90import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
91import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Wale Ogunwaled829d362016-02-10 19:24:49 -080092import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070093import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -080094import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070095import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
Jorim Jaggi0a932142016-02-01 17:42:25 -080096import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080097import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
Suprabh Shukla7745c142016-03-07 18:21:10 -080098import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080099import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
100import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
101import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
102import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
103import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
104import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
105import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
106import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
107import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
108import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800109import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Winson Chung83471632016-12-13 11:02:12 -0800110import static com.android.server.am.ActivityRecord.ASSISTANT_ACTIVITY_TYPE;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800111import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
112import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700113import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800114import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
Winson Chung6954fc92017-03-24 16:22:12 -0700115import static com.android.server.am.ActivityStackSupervisor.PAUSE_IMMEDIATELY;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800116import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
Jorim Jaggi0a932142016-02-01 17:42:25 -0800117
Winson Chung74666102017-02-22 17:49:24 -0800118import static java.lang.Integer.MAX_VALUE;
119
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100120final class TaskRecord extends ConfigurationContainer implements TaskWindowContainerListener {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800121 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700122 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700123 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -0700124 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700125 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800126
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700127 private static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700128 private static final String TAG_INTENT = "intent";
129 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700130 private static final String ATTR_REALACTIVITY = "real_activity";
131 private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700132 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700133 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700134 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700135 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700136 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700137 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700138 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
139 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800140 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700141 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700142 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700143 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700144 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700145 private static final String ATTR_LASTDESCRIPTION = "last_description";
146 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700147 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700148 private static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700149 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
150 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700151 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700152 private static final String ATTR_CALLING_UID = "calling_uid";
153 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Winson Chungd3395382016-12-13 11:49:09 -0800154 private static final String ATTR_SUPPORTS_PICTURE_IN_PICTURE = "supports_picture_in_picture";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800155 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700156 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700157 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700158 private static final String ATTR_MIN_WIDTH = "min_width";
159 private static final String ATTR_MIN_HEIGHT = "min_height";
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700160 private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
Andrii Kulian18d75122016-03-27 20:20:28 -0700161
Wale Ogunwale625ed0c2016-10-18 08:50:31 -0700162 // Current version of the task record we persist. Used to check if we need to run any upgrade
163 // code.
164 private static final int PERSIST_TASK_VERSION = 1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700165 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
166
Wale Ogunwale18795a22014-12-03 11:38:33 -0800167 static final int INVALID_TASK_ID = -1;
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700168 private static final int INVALID_MIN_SIZE = -1;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800169
Winson Chung74666102017-02-22 17:49:24 -0800170 /**
171 * The modes to control how the stack is moved to the front when calling
172 * {@link TaskRecord#reparent}.
173 */
174 @Retention(RetentionPolicy.SOURCE)
175 @IntDef({
176 REPARENT_MOVE_STACK_TO_FRONT,
177 REPARENT_KEEP_STACK_AT_FRONT,
178 REPARENT_LEAVE_STACK_IN_PLACE
179 })
180 public @interface ReparentMoveStackMode {}
181 // Moves the stack to the front if it was not at the front
182 public static final int REPARENT_MOVE_STACK_TO_FRONT = 0;
183 // Only moves the stack to the front if it was focused or front most already
184 public static final int REPARENT_KEEP_STACK_AT_FRONT = 1;
185 // Do not move the stack as a part of reparenting
186 public static final int REPARENT_LEAVE_STACK_IN_PLACE = 2;
187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700189 String affinity; // The affinity name for this task, or null; may change identity.
190 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700191 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
192 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 Intent intent; // The original intent that started the task.
194 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700195 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 ComponentName origActivity; // The non-alias activity component of the intent.
197 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000198 boolean realActivitySuspended; // True if the actual activity component that started the
199 // task is suspended.
Winson Chung36f3f032016-09-08 23:29:43 +0000200 long firstActiveTime; // First time this task was active.
201 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700202 boolean inRecents; // Actually in the recents list?
203 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 boolean rootWasReset; // True if the intent at the root of the task had
205 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700206 boolean autoRemoveRecents; // If true, we should automatically remove the task from
207 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700208 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700209 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 -0800210
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700211 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700212 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800213 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
214 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800215
216 int numFullscreen; // Number of fullscreen activities.
217
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800218 int mResizeMode; // The resize mode of this task and its activities.
219 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800220 private boolean mSupportsPictureInPicture; // Whether or not this task and its activities
221 // support PiP. Based on the {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE} flag
222 // of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800223 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
224 // changes on a temporary basis.
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700225 private int mLockTaskMode; // Which tasklock mode to launch this task in. One of
226 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700227 private boolean mPrivileged; // The root activity application of this task holds
228 // privileged permissions.
229
Craig Mautner15df08a2015-04-01 12:17:18 -0700230 /** Can't be put in lockTask mode. */
231 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100232 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700233 final static int LOCK_TASK_AUTH_PINNABLE = 1;
234 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
235 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100236 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700237 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100238 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
239 * lockTask task. */
240 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700241 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
242
243 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800244
Winson Chung03a9bae2014-05-02 09:56:12 -0700245 // This represents the last resolved activity values for this task
246 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700247 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700248
Craig Mautnerd2328952013-03-05 12:46:26 -0800249 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700250 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800251
Andrii Kulian02b7a832016-10-06 23:11:56 -0700252 /** Current stack. Setter must always be used to update the value. */
253 private ActivityStack mStack;
Craig Mautnerd2328952013-03-05 12:46:26 -0800254
Craig Mautner2c1faed2013-07-23 12:56:02 -0700255 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700256 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700257
Craig Mautner21d24a22014-04-23 11:45:37 -0700258 /** Takes on same value as first root activity */
259 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700260 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700261
262 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
263 * determining the order when restoring. Sign indicates whether last task movement was to front
264 * (positive) or back (negative). Absolute value indicates time. */
265 long mLastTimeMoved = System.currentTimeMillis();
266
Craig Mautner84984fa2014-06-19 11:19:20 -0700267 /** Indication of what to run next when task exits. Use ActivityRecord types.
268 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
269 * task stack. */
270 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700271
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700272 /** If original intent did not allow relinquishing task identity, save that information */
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700273 private boolean mNeverRelinquishIdentity = true;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700274
Craig Mautner362449a2014-06-20 14:04:39 -0700275 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
276 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800277 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700278
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700279 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700280 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700281 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800282 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700283 CharSequence lastDescription; // Last description captured for this item.
284
Craig Mautnera228ae92014-07-09 05:44:55 -0700285 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700286 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700287 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800288 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700289 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800290 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700291
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700292 // For relaunching the task from recents as though it was launched by the original launcher.
293 int mCallingUid;
294 String mCallingPackage;
295
Craig Mautner21d24a22014-04-23 11:45:37 -0700296 final ActivityManagerService mService;
297
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700298 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
299 boolean mFullscreen = true;
300
301 // Bounds of the Task. null for fullscreen tasks.
302 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800303 private final Rect mTmpStableBounds = new Rect();
304 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800305 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800306
Wale Ogunwale706ed792015-08-02 10:29:44 -0700307 // Last non-fullscreen bounds the task was launched in or resized to.
308 // The information is persisted and used to determine the appropriate stack to launch the
309 // task into on restore.
310 Rect mLastNonFullscreenBounds = null;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700311 // Minimal width and height of this task when it's resizeable. -1 means it should use the
312 // default minimal width/height.
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700313 int mMinWidth;
314 int mMinHeight;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700315
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700316 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
317 // This number will be assigned when we evaluate OOM scores for all visible tasks.
318 int mLayerRank = -1;
319
Andrii Kulian1779e612016-10-12 21:58:25 -0700320 /** Helper object used for updating override configuration. */
321 private Configuration mTmpConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700322
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800323 private TaskWindowContainerController mWindowContainerController;
324
Craig Mautner21d24a22014-04-23 11:45:37 -0700325 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Wale Ogunwale72919d22016-12-08 18:58:50 -0800326 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor, int type) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700327 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700328 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
329 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800330 userId = UserHandle.getUserId(info.applicationInfo.uid);
331 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800332 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700334 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700335 voiceSession = _voiceSession;
336 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700337 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800338 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700339 mCallingUid = info.applicationInfo.uid;
340 mCallingPackage = info.packageName;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800341 taskType = type;
Martijn Coenend4a69702014-06-30 11:12:17 -0700342 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700343 setMinDimensions(info);
Winson730bf062016-03-31 18:04:56 -0700344 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700345 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Craig Mautner21d24a22014-04-23 11:45:37 -0700346 }
347
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700348 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800349 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700350 mService = service;
351 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
352 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800353 userId = UserHandle.getUserId(info.applicationInfo.uid);
354 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800355 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700356 taskId = _taskId;
357 mAffiliatedTaskId = _taskId;
358 voiceSession = null;
359 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700360 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800361 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700362 mCallingUid = info.applicationInfo.uid;
363 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700364 setIntent(_intent, info);
Andrii Kulian2e751b82016-03-16 16:59:32 -0700365 setMinDimensions(info);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700366
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700367 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700368 // Clamp to [1, max].
369 maxRecents = Math.min(Math.max(info.maxRecents, 1),
370 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700371
372 taskType = APPLICATION_ACTIVITY_TYPE;
373 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700374 lastTaskDescription = _taskDescription;
Winson730bf062016-03-31 18:04:56 -0700375 touchActiveTime();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700376 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700377 }
378
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800379 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
380 Intent _affinityIntent, String _affinity, String _rootAffinity,
381 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
382 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
383 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
384 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
385 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800386 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
387 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Winson Chungd3395382016-12-13 11:49:09 -0800388 int resizeMode, boolean supportsPictureInPicture, boolean privileged,
389 boolean _realActivitySuspended, boolean userSetupComplete, int minWidth,
390 int minHeight) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700391 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700392 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
393 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800394 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800395 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700396 taskId = _taskId;
397 intent = _intent;
398 affinityIntent = _affinityIntent;
399 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800400 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700401 voiceSession = null;
402 voiceInteractor = null;
403 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800404 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700405 origActivity = _origActivity;
406 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700407 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700408 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700409 askedCompatMode = _askedCompatMode;
410 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700411 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700412 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800413 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700414 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700415 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700416 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700417 lastDescription = _lastDescription;
418 mActivities = activities;
419 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700420 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700421 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700422 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700423 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700424 mPrevAffiliateTaskId = prevTaskId;
425 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700426 mCallingUid = callingUid;
427 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800428 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800429 mSupportsPictureInPicture = supportsPictureInPicture;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700430 mPrivileged = privileged;
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700431 mMinWidth = minWidth;
432 mMinHeight = minHeight;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700433 mService.mTaskChangeNotificationController.notifyTaskCreated(_taskId, realActivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 }
435
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800436 TaskWindowContainerController getWindowContainerController() {
437 return mWindowContainerController;
438 }
439
440 void createWindowContainer(boolean onTop, boolean showForAllUsers) {
441 if (mWindowContainerController != null) {
442 throw new IllegalArgumentException("Window container=" + mWindowContainerController
443 + " already created for task=" + this);
444 }
445
446 final Rect bounds = updateOverrideConfigurationFromLaunchBounds();
447 final Configuration overrideConfig = getOverrideConfiguration();
Wale Ogunwale1666e312016-12-16 11:27:18 -0800448 mWindowContainerController = new TaskWindowContainerController(taskId, this,
449 getStack().getWindowContainerController(), userId, bounds, overrideConfig,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800450 mResizeMode, mSupportsPictureInPicture, isHomeTask(), onTop, showForAllUsers,
451 lastTaskDescription);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800452 }
453
454 void removeWindowContainer() {
455 mService.mStackSupervisor.removeLockedTaskLocked(this);
456 mWindowContainerController.removeContainer();
457 if (!StackId.persistTaskBounds(getStackId())) {
458 // Reset current bounds for task whose bounds shouldn't be persisted so it uses
459 // default configuration the next time it launches.
460 updateOverrideConfiguration(null);
461 }
462 mService.mTaskChangeNotificationController.notifyTaskRemoved(taskId);
463 mWindowContainerController = null;
464 }
465
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100466 @Override
467 public void onSnapshotChanged(TaskSnapshot snapshot) {
468 mService.mTaskChangeNotificationController.notifyTaskSnapshotChanged(taskId, snapshot);
469 }
470
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800471 void setResizeMode(int resizeMode) {
472 if (mResizeMode == resizeMode) {
473 return;
474 }
475 mResizeMode = resizeMode;
476 mWindowContainerController.setResizeable(resizeMode);
477 mService.mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
478 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
479 }
480
481 void setTaskDockedResizing(boolean resizing) {
482 mWindowContainerController.setTaskDockedResizing(resizing);
483 }
484
Wale Ogunwale1666e312016-12-16 11:27:18 -0800485 // TODO: Consolidate this with the resize() method below.
486 @Override
487 public void requestResize(Rect bounds, int resizeMode) {
488 mService.resizeTask(taskId, bounds, resizeMode);
489 }
490
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800491 boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) {
492 if (!isResizeable()) {
493 Slog.w(TAG, "resizeTask: task " + this + " not resizeable.");
494 return true;
495 }
496
497 // If this is a forced resize, let it go through even if the bounds is not changing,
498 // as we might need a relayout due to surface size change (to/from fullscreen).
499 final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
500 if (Objects.equals(mBounds, bounds) && !forced) {
501 // Nothing to do here...
502 return true;
503 }
504 bounds = validateBounds(bounds);
505
506 if (mWindowContainerController == null) {
507 // Task doesn't exist in window manager yet (e.g. was restored from recents).
508 // All we can do for now is update the bounds so it can be used when the task is
509 // added to window manager.
510 updateOverrideConfiguration(bounds);
511 if (getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
512 // re-restore the task so it can have the proper stack association.
513 mService.mStackSupervisor.restoreRecentTaskLocked(this,
514 FREEFORM_WORKSPACE_STACK_ID);
515 }
516 return true;
517 }
518
519 if (!canResizeToBounds(bounds)) {
520 throw new IllegalArgumentException("resizeTask: Can not resize task=" + this
521 + " to bounds=" + bounds + " resizeMode=" + mResizeMode);
522 }
523
524 // Do not move the task to another stack here.
525 // This method assumes that the task is already placed in the right stack.
526 // we do not mess with that decision and we only do the resize!
527
528 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + taskId);
529
530 final boolean updatedConfig = updateOverrideConfiguration(bounds);
531 // This variable holds information whether the configuration didn't change in a significant
532 // way and the activity was kept the way it was. If it's false, it means the activity had
533 // to be relaunched due to configuration change.
534 boolean kept = true;
535 if (updatedConfig) {
536 final ActivityRecord r = topRunningActivityLocked();
537 if (r != null) {
538 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
539
540 if (!deferResume) {
541 // All other activities must be made visible with their correct configuration.
542 mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
543 if (!kept) {
544 mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
545 }
546 }
547 }
548 }
549 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), kept, forced);
550
551 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
552 return kept;
553 }
554
555 // TODO: Investigate combining with the resize() method above.
556 void resizeWindowContainer() {
557 mWindowContainerController.resize(mBounds, getOverrideConfiguration(), false /* relayout */,
558 false /* forced */);
559 }
560
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800561 void getWindowContainerBounds(Rect bounds) {
562 mWindowContainerController.getBounds(bounds);
563 }
564
Winson Chung74666102017-02-22 17:49:24 -0800565 /**
566 * Convenience method to reparent a task to the top or bottom position of the stack.
567 */
568 boolean reparent(int preferredStackId, boolean toTop, @ReparentMoveStackMode int moveStackMode,
569 boolean animate, boolean deferResume, String reason) {
570 return reparent(preferredStackId, toTop ? MAX_VALUE : 0, moveStackMode, animate,
Winson Chung5af42fc2017-03-24 17:11:33 -0700571 deferResume, true /* schedulePictureInPictureModeChange */, reason);
572 }
573
574 /**
575 * Convenience method to reparent a task to the top or bottom position of the stack, with
576 * an option to skip scheduling the picture-in-picture mode change.
577 */
578 boolean reparent(int preferredStackId, boolean toTop, @ReparentMoveStackMode int moveStackMode,
579 boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange,
580 String reason) {
581 return reparent(preferredStackId, toTop ? MAX_VALUE : 0, moveStackMode, animate,
582 deferResume, schedulePictureInPictureModeChange, reason);
583 }
584
585 /**
586 * Convenience method to reparent a task to a specific position of the stack.
587 */
588 boolean reparent(int preferredStackId, int position, @ReparentMoveStackMode int moveStackMode,
589 boolean animate, boolean deferResume, String reason) {
590 return reparent(preferredStackId, position, moveStackMode, animate, deferResume,
591 true /* schedulePictureInPictureModeChange */, reason);
Winson Chung74666102017-02-22 17:49:24 -0800592 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800593
Winson Chung74666102017-02-22 17:49:24 -0800594 /**
595 * Reparents the task into a preferred stack, creating it if necessary.
596 *
597 * @param preferredStackId the stack id of the target stack to move this task
598 * @param position the position to place this task in the new stack
599 * @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 -0700600 * reparenting to be drawn and animated in
Winson Chung74666102017-02-22 17:49:24 -0800601 * @param moveStackMode whether or not to move the stack to the front always, only if it was
Winson Chung5af42fc2017-03-24 17:11:33 -0700602 * previously focused & in front, or never
Winson Chung74666102017-02-22 17:49:24 -0800603 * @param deferResume whether or not to update the visibility of other tasks and stacks that may
Winson Chung5af42fc2017-03-24 17:11:33 -0700604 * have changed as a result of this reparenting
605 * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode
606 * change. Callers may set this to false if they are explicitly scheduling PiP mode
607 * changes themselves, like during the PiP animation
Winson Chung74666102017-02-22 17:49:24 -0800608 * @param reason the caller of this reparenting
Winson Chung5af42fc2017-03-24 17:11:33 -0700609 * @return whether the task was reparented
Winson Chung74666102017-02-22 17:49:24 -0800610 */
611 boolean reparent(int preferredStackId, int position, @ReparentMoveStackMode int moveStackMode,
Winson Chung5af42fc2017-03-24 17:11:33 -0700612 boolean animate, boolean deferResume, boolean schedulePictureInPictureModeChange,
613 String reason) {
Winson Chung74666102017-02-22 17:49:24 -0800614 final ActivityStackSupervisor supervisor = mService.mStackSupervisor;
615 final WindowManagerService windowManager = mService.mWindowManager;
616 final ActivityStack sourceStack = getStack();
617 final ActivityStack toStack = supervisor.getReparentTargetStack(this, preferredStackId,
618 position == MAX_VALUE);
619 if (toStack == sourceStack) {
620 return false;
621 }
622
623 final int sourceStackId = getStackId();
624 final int stackId = toStack.getStackId();
625 final ActivityRecord topActivity = getTopActivity();
626
627 final boolean mightReplaceWindow = StackId.replaceWindowsOnTaskMove(sourceStackId, stackId)
628 && topActivity != null;
629 if (mightReplaceWindow) {
630 // We are about to relaunch the activity because its configuration changed due to
631 // being maximized, i.e. size change. The activity will first remove the old window
632 // and then add a new one. This call will tell window manager about this, so it can
633 // preserve the old window until the new one is drawn. This prevents having a gap
634 // between the removal and addition, in which no window is visible. We also want the
635 // entrance of the new window to be properly animated.
636 // Note here we always set the replacing window first, as the flags might be needed
637 // during the relaunch. If we end up not doing any relaunch, we clear the flags later.
638 windowManager.setWillReplaceWindow(topActivity.appToken, animate);
639 }
640
641 windowManager.deferSurfaceLayout();
642 boolean kept = true;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800643 try {
Winson Chung74666102017-02-22 17:49:24 -0800644 final ActivityRecord r = topRunningActivityLocked();
Winson Chung95f8f0e2017-03-24 09:20:17 -0700645 final boolean wasFocused = r != null && supervisor.isFocusedStack(sourceStack)
Winson Chung74666102017-02-22 17:49:24 -0800646 && (topRunningActivityLocked() == r);
Winson Chung95f8f0e2017-03-24 09:20:17 -0700647 final boolean wasResumed = r != null && sourceStack.mResumedActivity == r;
648 final boolean wasPaused = r != null && sourceStack.mPausingActivity == r;
Winson Chung74666102017-02-22 17:49:24 -0800649
650 // In some cases the focused stack isn't the front stack. E.g. pinned stack.
651 // Whenever we are moving the top activity from the front stack we want to make sure to
652 // move the stack to the front.
Winson Chung95f8f0e2017-03-24 09:20:17 -0700653 final boolean wasFront = r != null && supervisor.isFrontStackOnDisplay(sourceStack)
Winson Chung74666102017-02-22 17:49:24 -0800654 && (sourceStack.topRunningActivityLocked() == r);
655
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800656 // Adjust the position for the new parent stack as needed.
Winson Chung74666102017-02-22 17:49:24 -0800657 position = toStack.getAdjustedPositionForTask(this, position, null /* starting */);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800658
659 // Must reparent first in window manager to avoid a situation where AM can delete the
660 // we are coming from in WM before we reparent because it became empty.
Winson Chung74666102017-02-22 17:49:24 -0800661 mWindowContainerController.reparent(toStack.getWindowContainerController(), position);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800662
Winson Chung74666102017-02-22 17:49:24 -0800663 // Reset the resumed activity on the previous stack
664 if (wasResumed) {
665 sourceStack.mResumedActivity = null;
666 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800667
Winson Chung74666102017-02-22 17:49:24 -0800668 // Reset the paused activity on the previous stack
669 if (wasPaused) {
670 sourceStack.mPausingActivity = null;
671 sourceStack.removeTimeoutsForActivityLocked(r);
672 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800673
Winson Chung74666102017-02-22 17:49:24 -0800674 // Move the task
675 sourceStack.removeTask(this, reason, REMOVE_TASK_MODE_MOVING);
Winson Chung5af42fc2017-03-24 17:11:33 -0700676 toStack.addTask(this, position, false /* schedulePictureInPictureModeChange */, reason);
Winson Chung74666102017-02-22 17:49:24 -0800677
Winson Chung5af42fc2017-03-24 17:11:33 -0700678 if (schedulePictureInPictureModeChange) {
679 // Notify of picture-in-picture mode changes
680 supervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, sourceStack);
681 }
Winson Chung74666102017-02-22 17:49:24 -0800682
683 // TODO: Ensure that this is actually necessary here
684 // Notify the voice session if required
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800685 if (voiceSession != null) {
686 try {
687 voiceSession.taskStarted(intent, taskId);
688 } catch (RemoteException e) {
689 }
690 }
Winson Chung74666102017-02-22 17:49:24 -0800691
692 // If the task had focus before (or we're requested to move focus), move focus to the
693 // new stack by moving the stack to the front.
694 final boolean moveStackToFront = moveStackMode == REPARENT_MOVE_STACK_TO_FRONT
695 || (moveStackMode == REPARENT_KEEP_STACK_AT_FRONT && (wasFocused || wasFront));
Winson Chung95f8f0e2017-03-24 09:20:17 -0700696 if (r != null) {
697 toStack.moveToFrontAndResumeStateIfNeeded(r, moveStackToFront, wasResumed,
698 wasPaused, reason);
699 }
Winson Chung74666102017-02-22 17:49:24 -0800700 if (!animate) {
701 toStack.mNoAnimActivities.add(topActivity);
702 }
703
704 // We might trigger a configuration change. Save the current task bounds for freezing.
705 // TODO: Should this call be moved inside the resize method in WM?
706 toStack.prepareFreezingTaskBounds();
707
708 // Make sure the task has the appropriate bounds/size for the stack it is in.
709 if (stackId == FULLSCREEN_WORKSPACE_STACK_ID
710 && !Objects.equals(mBounds, toStack.mBounds)) {
711 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
712 deferResume);
713 } else if (stackId == FREEFORM_WORKSPACE_STACK_ID) {
714 Rect bounds = getLaunchBounds();
715 if (bounds == null) {
716 toStack.layoutTaskInStack(this, null);
717 bounds = mBounds;
718 }
719 kept = resize(bounds, RESIZE_MODE_FORCED, !mightReplaceWindow, deferResume);
720 } else if (stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID) {
Matthew Ng330757d2017-02-28 14:19:17 -0800721 if (stackId == DOCKED_STACK_ID && moveStackMode == REPARENT_KEEP_STACK_AT_FRONT) {
722 // Move recents to front so it is not behind home stack when going into docked
723 // mode
724 mService.mStackSupervisor.moveRecentsStackToFront(reason);
725 }
Winson Chung74666102017-02-22 17:49:24 -0800726 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
727 deferResume);
728 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800729 } finally {
Winson Chung74666102017-02-22 17:49:24 -0800730 windowManager.continueSurfaceLayout();
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800731 }
Winson Chung74666102017-02-22 17:49:24 -0800732
733 if (mightReplaceWindow) {
734 // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old
735 // window), we need to clear the replace window settings. Otherwise, we schedule a
736 // timeout to remove the old window if the replacing window is not coming in time.
737 windowManager.scheduleClearWillReplaceWindows(topActivity.appToken, !kept);
738 }
739
740 if (!deferResume) {
741 // The task might have already been running and its visibility needs to be synchronized
742 // with the visibility of the stack / windows.
743 supervisor.ensureActivitiesVisibleLocked(null, 0, !mightReplaceWindow);
744 supervisor.resumeFocusedStackTopActivityLocked();
745 }
746
747 supervisor.handleNonResizableTaskIfNeeded(this, preferredStackId, stackId);
748
Matthew Ng330757d2017-02-28 14:19:17 -0800749 boolean successful = (preferredStackId == stackId);
750 if (successful && stackId == DOCKED_STACK_ID) {
751 // If task moved to docked stack - show recents if needed.
752 mService.mWindowManager.showRecentApps(false /* fromHome */);
753 }
754 return successful;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800755 }
756
757 void cancelWindowTransition() {
758 mWindowContainerController.cancelWindowTransition();
759 }
760
761 void cancelThumbnailTransition() {
762 mWindowContainerController.cancelThumbnailTransition();
763 }
764
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100765 /**
766 * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
767 */
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100768 TaskSnapshot getSnapshot(boolean reducedResolution) {
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100769
770 // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
771 // synchronized between AM and WM.
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100772 return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800773 }
774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000776 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700777 if (firstActiveTime == 0) {
778 firstActiveTime = lastActiveTime;
779 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000783 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700785
Winson Chungfee26772014-08-05 12:21:52 -0700786 /** Sets the original intent, and the calling uid and package. */
787 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700788 mCallingUid = r.launchedFromUid;
789 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700790 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700791 }
792
793 /** Sets the original intent, _without_ updating the calling uid or package. */
794 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700795 if (intent == null) {
796 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700797 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700798 } else if (mNeverRelinquishIdentity) {
799 return;
800 }
801
802 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700803 if (intent == null) {
804 // If this task already has an intent associated with it, don't set the root
805 // affinity -- we don't want it changing after initially set, but the initially
806 // set value may be null.
807 rootAffinity = affinity;
808 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700809 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700810 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800813 if (_intent != null) {
814 // If this Intent has a selector, we want to clear it for the
815 // recent task since it is not relevant if the user later wants
816 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700817 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800818 _intent = new Intent(_intent);
819 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700820 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800821 }
822 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700823 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 intent = _intent;
825 realActivity = _intent != null ? _intent.getComponent() : null;
826 origActivity = null;
827 } else {
828 ComponentName targetComponent = new ComponentName(
829 info.packageName, info.targetActivity);
830 if (_intent != null) {
831 Intent targetIntent = new Intent(_intent);
832 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800833 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700834 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700835 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700836 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 intent = targetIntent;
838 realActivity = targetComponent;
839 origActivity = _intent.getComponent();
840 } else {
841 intent = null;
842 realActivity = targetComponent;
843 origActivity = new ComponentName(info.packageName, info.name);
844 }
845 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700846
Craig Mautner47b20ba2014-09-17 17:23:44 -0700847 final int intentFlags = intent == null ? 0 : intent.getFlags();
848 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 // Once we are set to an Intent with this flag, we count this
850 // task as having a true root activity.
851 rootWasReset = true;
852 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700853 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000854 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
855 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700856 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700857 // If the activity itself has requested auto-remove, then just always do it.
858 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700859 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
860 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700861 // If the caller has not asked for the document to be retained, then we may
862 // want to turn on auto-remove, depending on whether the target has set its
863 // own document launch mode.
864 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
865 autoRemoveRecents = false;
866 } else {
867 autoRemoveRecents = true;
868 }
869 } else {
870 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700871 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800872 mResizeMode = info.resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800873 mSupportsPictureInPicture = info.supportsPictureInPicture();
Craig Mautner15df08a2015-04-01 12:17:18 -0700874 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700875 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700876 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800878
Andrii Kulian2e751b82016-03-16 16:59:32 -0700879 /** Sets the original minimal width and height. */
880 private void setMinDimensions(ActivityInfo info) {
881 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700882 mMinWidth = info.windowLayout.minWidth;
883 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700884 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700885 mMinWidth = INVALID_MIN_SIZE;
886 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700887 }
888 }
889
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800890 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700891 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800892 * record is based on (normally the root activity intent).
893 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700894 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800895 final Intent intent = new Intent(r.intent);
896 // Correct the activity intent for aliasing. The task record intent will always be based on
897 // the real activity that will be launched not the alias, so we need to use an intent with
898 // the component name pointing to the real activity not the alias in the activity record.
899 intent.setComponent(r.realActivity);
900 return this.intent.filterEquals(intent);
901 }
902
Craig Mautner84984fa2014-06-19 11:19:20 -0700903 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800904 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
905 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700906 }
907
Winson Chung83471632016-12-13 11:02:12 -0800908 void setTaskToReturnTo(ActivityRecord source) {
909 if (source.isRecentsActivity()) {
910 setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
911 } else if (source.isAssistantActivity()) {
912 setTaskToReturnTo(ASSISTANT_ACTIVITY_TYPE);
913 }
914 }
915
Craig Mautner84984fa2014-06-19 11:19:20 -0700916 int getTaskToReturnTo() {
917 return mTaskToReturnTo;
918 }
919
Craig Mautnera228ae92014-07-09 05:44:55 -0700920 void setPrevAffiliate(TaskRecord prevAffiliate) {
921 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800922 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700923 }
924
925 void setNextAffiliate(TaskRecord nextAffiliate) {
926 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800927 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700928 }
929
Andrii Kulian02b7a832016-10-06 23:11:56 -0700930 ActivityStack getStack() {
931 return mStack;
932 }
933
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800934 /**
935 * Must be used for setting parent stack because it performs configuration updates.
936 * Must be called after adding task as a child to the stack.
937 */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700938 void setStack(ActivityStack stack) {
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800939 if (stack != null && !stack.isInStackLocked(this)) {
940 throw new IllegalStateException("Task must be added as a Stack child first.");
941 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700942 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700943 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700944 }
945
946 /**
947 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
948 */
949 int getStackId() {
950 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
951 }
952
Andrii Kulian1779e612016-10-12 21:58:25 -0700953 @Override
954 protected int getChildCount() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700955 return mActivities.size();
Andrii Kulian1779e612016-10-12 21:58:25 -0700956 }
957
958 @Override
959 protected ConfigurationContainer getChildAt(int index) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700960 return mActivities.get(index);
Andrii Kulian1779e612016-10-12 21:58:25 -0700961 }
962
963 @Override
964 protected ConfigurationContainer getParent() {
965 return mStack;
966 }
967
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800968 @Override
969 void onParentChanged() {
970 super.onParentChanged();
971 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
972 }
973
Craig Mautnera228ae92014-07-09 05:44:55 -0700974 // Close up recents linked list.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700975 private void closeRecentsChain() {
Craig Mautnera228ae92014-07-09 05:44:55 -0700976 if (mPrevAffiliate != null) {
977 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
978 }
979 if (mNextAffiliate != null) {
980 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
981 }
982 setPrevAffiliate(null);
983 setNextAffiliate(null);
984 }
985
Winson Chung740c3ac2014-11-12 16:14:38 -0800986 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700987 disposeThumbnail();
988 closeRecentsChain();
989 if (inRecents) {
990 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800991 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700992 }
Jorim Jaggif9084ec2017-01-16 13:16:59 +0100993
994 // TODO: Use window container controller once tasks are better synced between AM and WM
995 mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700996 }
997
Craig Mautnera228ae92014-07-09 05:44:55 -0700998 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
999 closeRecentsChain();
1000 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -07001001 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -07001002 // Find the end
1003 while (taskToAffiliateWith.mNextAffiliate != null) {
1004 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
1005 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
1006 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
1007 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
1008 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
1009 nextRecents.setPrevAffiliate(null);
1010 }
1011 taskToAffiliateWith.setNextAffiliate(null);
1012 break;
1013 }
1014 taskToAffiliateWith = nextRecents;
1015 }
1016 taskToAffiliateWith.setNextAffiliate(this);
1017 setPrevAffiliate(taskToAffiliateWith);
1018 setNextAffiliate(null);
1019 }
1020
Winson Chung096f36b2014-08-20 15:39:01 -07001021 /**
Winsonc809cbb2015-11-02 12:06:15 -08001022 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -07001023 * @return whether the thumbnail was set
1024 */
Winsonc809cbb2015-11-02 12:06:15 -08001025 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -08001026 int taskWidth = 0;
1027 int taskHeight = 0;
1028 if (mBounds != null) {
1029 // Non-fullscreen tasks
1030 taskWidth = mBounds.width();
1031 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001032 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -08001033 // Fullscreen tasks
1034 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001035 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -08001036 taskWidth = displaySize.x;
1037 taskHeight = displaySize.y;
1038 } else {
1039 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
1040 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001041 // We need to provide the current orientation of the display on which this task resides,
1042 // not the orientation of the task.
1043 final int orientation =
1044 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
1045 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -08001046 }
1047
1048 /**
1049 * Sets the last thumbnail with the current task bounds.
1050 * @return whether the thumbnail was set
1051 */
1052 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
1053 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -07001054 if (mLastThumbnail != thumbnail) {
1055 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001056 mLastThumbnailInfo.taskWidth = taskWidth;
1057 mLastThumbnailInfo.taskHeight = taskHeight;
1058 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -07001059 if (thumbnail == null) {
1060 if (mLastThumbnailFile != null) {
1061 mLastThumbnailFile.delete();
1062 }
1063 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001064 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001065 }
Winson Chung096f36b2014-08-20 15:39:01 -07001066 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001067 }
Winson Chung096f36b2014-08-20 15:39:01 -07001068 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001069 }
1070
1071 void getLastThumbnail(TaskThumbnail thumbs) {
1072 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001073 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001074 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001075 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001076 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -08001077 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001078 }
Winson Chung096f36b2014-08-20 15:39:01 -07001079 // Only load the thumbnail file if we don't have a thumbnail
1080 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001081 try {
1082 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
1083 ParcelFileDescriptor.MODE_READ_ONLY);
1084 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -07001085 }
1086 }
1087 }
1088
Winsonc809cbb2015-11-02 12:06:15 -08001089 /**
1090 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
1091 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001092 void freeLastThumbnail() {
1093 mLastThumbnail = null;
1094 }
1095
Winsonc809cbb2015-11-02 12:06:15 -08001096 /**
1097 * Removes all associated thumbnail data when a task is removed or pruned from recents.
1098 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001099 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -08001100 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001101 mLastThumbnail = null;
1102 lastDescription = null;
1103 }
1104
Winson Chung1147c402014-05-14 11:05:00 -07001105 /** Returns the intent for the root activity for this task */
1106 Intent getBaseIntent() {
1107 return intent != null ? intent : affinityIntent;
1108 }
1109
Winson Chung3b3f4642014-04-22 10:08:18 -07001110 /** Returns the first non-finishing activity from the root. */
1111 ActivityRecord getRootActivity() {
1112 for (int i = 0; i < mActivities.size(); i++) {
1113 final ActivityRecord r = mActivities.get(i);
1114 if (r.finishing) {
1115 continue;
1116 }
1117 return r;
1118 }
1119 return null;
1120 }
1121
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001122 ActivityRecord getTopActivity() {
1123 for (int i = mActivities.size() - 1; i >= 0; --i) {
1124 final ActivityRecord r = mActivities.get(i);
1125 if (r.finishing) {
1126 continue;
1127 }
1128 return r;
1129 }
1130 return null;
1131 }
1132
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -07001133 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001134 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001135 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1136 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -07001137 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001138 return r;
1139 }
Craig Mautner6b74cb52013-09-27 17:02:21 -07001140 }
1141 }
1142 return null;
1143 }
1144
Wale Ogunwale3b232392016-05-13 15:37:13 -07001145 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001146 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001147 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1148 ActivityRecord r = mActivities.get(activityNdx);
1149 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -07001150 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001151 continue;
1152 }
1153 return r;
1154 }
1155 }
1156 return null;
1157 }
1158
Chong Zhang87761972016-08-22 13:53:24 -07001159 boolean okToShowLocked() {
1160 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
1161 // okay to show the activity when locked.
1162 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
1163 || topRunningActivityLocked() != null;
1164 }
1165
Craig Mautner3b475fe2013-12-16 15:58:31 -08001166 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Bryce Leed71317c2017-02-07 14:27:22 -08001167 final void setFrontOfTask() {
1168 boolean foundFront = false;
Craig Mautner3b475fe2013-12-16 15:58:31 -08001169 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -08001170 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -08001171 final ActivityRecord r = mActivities.get(activityNdx);
1172 if (foundFront || r.finishing) {
1173 r.frontOfTask = false;
1174 } else {
1175 r.frontOfTask = true;
1176 // Set frontOfTask false for every following activity.
1177 foundFront = true;
1178 }
1179 }
Craig Mautner9587ee02014-06-23 15:00:10 +00001180 if (!foundFront && numActivities > 0) {
1181 // All activities of this task are finishing. As we ought to have a frontOfTask
1182 // activity, make the bottom activity front.
1183 mActivities.get(0).frontOfTask = true;
1184 }
Craig Mautner3b475fe2013-12-16 15:58:31 -08001185 }
1186
Craig Mautnerde4ef022013-04-07 19:01:33 -07001187 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -08001188 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -07001189 */
1190 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001191 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
1192 "Removing and adding activity " + newTop
1193 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -07001194
Craig Mautnerde4ef022013-04-07 19:01:33 -07001195 mActivities.remove(newTop);
1196 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001197 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -08001198
Bryce Leed71317c2017-02-07 14:27:22 -08001199 setFrontOfTask();
Craig Mautnerde4ef022013-04-07 19:01:33 -07001200 }
1201
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001202 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -08001203 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001204 }
1205
1206 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001207 addActivityAtIndex(mActivities.size(), r);
1208 }
1209
Winson Chung30480042017-01-26 10:55:34 -08001210 /**
1211 * Adds an activity {@param r} at the given {@param index}. The activity {@param r} must either
1212 * be in the current task or unparented to any task.
1213 */
Craig Mautner1602ec22013-05-12 10:24:27 -07001214 void addActivityAtIndex(int index, ActivityRecord r) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001215 if (r.task != null && r.task != this) {
1216 throw new IllegalArgumentException("Can not add r=" + " to task=" + this
1217 + " current parent=" + r.task);
1218 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001219 // TODO(b/36505427): Maybe make task private to ActivityRecord so we can also do
1220 // onParentChanged() within the setter?
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001221 r.task = this;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001222 r.onParentChanged();
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001223
Craig Mautner6170f732013-04-02 13:05:23 -07001224 // 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 -08001225 if (!mActivities.remove(r) && r.fullscreen) {
1226 // Was not previously in list.
1227 numFullscreen++;
1228 }
Craig Mautner2c1faed2013-07-23 12:56:02 -07001229 // Only set this based on the first activity
1230 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001231 taskType = r.mActivityType;
1232 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001233 mCallingUid = r.launchedFromUid;
1234 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001235 // Clamp to [1, max].
1236 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
1237 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -07001238 } else {
1239 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -07001240 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -07001241 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001242
1243 final int size = mActivities.size();
1244
1245 if (index == size && size > 0) {
1246 final ActivityRecord top = mActivities.get(size - 1);
1247 if (top.mTaskOverlay) {
1248 // Place below the task overlay activity since the overlay activity should always
1249 // be on top.
1250 index--;
1251 }
1252 }
1253
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001254 index = Math.min(size, index);
Craig Mautner77878772013-03-04 19:46:24 -08001255 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001256 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001257 if (r.isPersistable()) {
1258 mService.notifyTaskPersisterLocked(this, false);
1259 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001260
1261 // Sync. with window manager
1262 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001263 final AppWindowContainerController appController = r.getWindowContainerController();
1264 if (appController != null) {
1265 // Only attempt to move in WM if the child has a controller. It is possible we haven't
1266 // created controller for the activity we are starting yet.
1267 mWindowContainerController.positionChildAt(appController, index);
1268 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001269 r.onOverrideConfigurationSent();
David Stevens82ea6cb2017-03-03 16:18:50 -08001270
1271 // Make sure the list of display UID whitelists is updated
1272 // now that this record is in a new task.
1273 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
Craig Mautner77878772013-03-04 19:46:24 -08001274 }
1275
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001276 /**
1277 * @return true if this was the last activity in the task
1278 */
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001279 boolean removeActivity(ActivityRecord r) {
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001280 if (r.task != this) {
1281 throw new IllegalArgumentException(
1282 "Activity=" + r + " does not belong to task=" + this);
1283 }
1284
1285 r.task = null;
1286
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001287 if (mActivities.remove(r) && r.fullscreen) {
1288 // Was previously in list.
1289 numFullscreen--;
1290 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001291 if (r.isPersistable()) {
1292 mService.notifyTaskPersisterLocked(this, false);
1293 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001294
Andrii Kulian02b7a832016-10-06 23:11:56 -07001295 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001296 // We normally notify listeners of task stack changes on pause, however pinned stack
1297 // activities are normally in the paused state so no notification will be sent there
1298 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001299 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001300 }
1301
Craig Mautner41326202014-06-20 14:38:21 -07001302 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001303 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001304 }
1305 updateEffectiveIntent();
1306 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001307 }
1308
Winson Chung6954fc92017-03-24 16:22:12 -07001309 /**
1310 * @return whether or not there are ONLY task overlay activities in the stack.
1311 * If {@param excludeFinishing} is set, then ignore finishing activities in the check.
1312 * If there are no task overlay activities, this call returns false.
1313 */
1314 boolean onlyHasTaskOverlayActivities(boolean excludeFinishing) {
1315 int count = 0;
1316 for (int i = mActivities.size() - 1; i >= 0; i--) {
1317 final ActivityRecord r = mActivities.get(i);
1318 if (excludeFinishing && r.finishing) {
1319 continue;
1320 }
1321 if (!r.mTaskOverlay) {
1322 return false;
1323 }
1324 count++;
1325 }
1326 return count > 0;
1327 }
1328
Craig Mautner41db4a72014-05-07 17:20:56 -07001329 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001330 // We will automatically remove the task either if it has explicitly asked for
1331 // this, or it is empty and has never contained an activity that got shown to
1332 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001333 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001334 }
1335
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001336 /**
1337 * Completely remove all activities associated with an existing
1338 * task starting at a specified index.
1339 */
Winson Chung6954fc92017-03-24 16:22:12 -07001340 final void performClearTaskAtIndexLocked(int activityNdx, boolean pauseImmediately) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001341 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001342 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001343 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001344 if (r.finishing) {
1345 continue;
1346 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001347 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001348 // Task was restored from persistent storage.
1349 r.takeFromHistory();
1350 mActivities.remove(activityNdx);
1351 --activityNdx;
1352 --numActivities;
Winson Chung6954fc92017-03-24 16:22:12 -07001353 } else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null,
1354 "clear-task-index", false, pauseImmediately)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001355 --activityNdx;
1356 --numActivities;
1357 }
1358 }
1359 }
1360
1361 /**
1362 * Completely remove all activities associated with an existing task.
1363 */
1364 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001365 mReuseTask = true;
Winson Chung6954fc92017-03-24 16:22:12 -07001366 performClearTaskAtIndexLocked(0, !PAUSE_IMMEDIATELY);
Craig Mautner362449a2014-06-20 14:04:39 -07001367 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001368 }
1369
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001370 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1371 mReuseTask = true;
1372 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1373 mReuseTask = false;
1374 return result;
1375 }
1376
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001377 /**
1378 * Perform clear operation as requested by
1379 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1380 * stack to the given task, then look for
1381 * an instance of that activity in the stack and, if found, finish all
1382 * activities on top of it and return the instance.
1383 *
1384 * @param newR Description of the new activity being started.
1385 * @return Returns the old activity that should be continued to be used,
1386 * or null if none was found.
1387 */
1388 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001389 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001390 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001391 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001392 if (r.finishing) {
1393 continue;
1394 }
1395 if (r.realActivity.equals(newR.realActivity)) {
1396 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001397 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001398
1399 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001400 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001401 if (r.finishing) {
1402 continue;
1403 }
1404 ActivityOptions opts = r.takeOptionsLocked();
1405 if (opts != null) {
1406 ret.updateOptionsLocked(opts);
1407 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001408 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001409 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001410 --activityNdx;
1411 --numActivities;
1412 }
1413 }
1414
1415 // Finally, if this is a normal launch mode (that is, not
1416 // expecting onNewIntent()), then we will finish the current
1417 // instance of the activity so a new fresh one can be started.
1418 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001419 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1420 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001421 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001422 if (mStack != null) {
1423 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001424 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1425 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001426 return null;
1427 }
1428 }
1429
1430 return ret;
1431 }
1432 }
1433
1434 return null;
1435 }
1436
Andrii Kulian21713ac2016-10-12 22:05:05 -07001437 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001438 if (mStack != null) {
1439 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Craig Mautner21d24a22014-04-23 11:45:37 -07001440 if (resumedActivity != null && resumedActivity.task == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001441 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001442 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001443 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001444 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001445 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1446 getLastThumbnail(taskThumbnail);
1447 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001448 }
1449
Winson Chung6954fc92017-03-24 16:22:12 -07001450 void removeTaskActivitiesLocked(boolean pauseImmediately) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001451 // Just remove the entire task.
Winson Chung6954fc92017-03-24 16:22:12 -07001452 performClearTaskAtIndexLocked(0, pauseImmediately);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001453 }
1454
Craig Mautner432f64e2015-05-20 14:59:57 -07001455 String lockTaskAuthToString() {
1456 switch (mLockTaskAuth) {
1457 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1458 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1459 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1460 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001461 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001462 default: return "unknown=" + mLockTaskAuth;
1463 }
1464 }
1465
Craig Mautner15df08a2015-04-01 12:17:18 -07001466 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001467 if (!mPrivileged &&
1468 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1469 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1470 // Non-priv apps are not allowed to use always or never, fall back to default
1471 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1472 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001473 switch (mLockTaskMode) {
1474 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1475 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1476 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1477 break;
1478
1479 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001480 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001481 break;
1482
1483 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001484 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001485 break;
1486
1487 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1488 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1489 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1490 break;
1491 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001492 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1493 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001494 }
1495
1496 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001497 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1498 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001499 return false;
1500 }
1501 String[] packages = mService.mLockTaskPackages.get(userId);
1502 if (packages == null) {
1503 return false;
1504 }
1505 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001506 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001507 return true;
1508 }
1509 }
1510 return false;
1511 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001512
Craig Mautnera82aa092013-09-13 15:34:08 -07001513 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001514 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001515 }
1516
Wale Ogunwale74e26592016-02-05 11:48:37 -08001517 boolean isRecentsTask() {
1518 return taskType == RECENTS_ACTIVITY_TYPE;
1519 }
1520
Winson Chung83471632016-12-13 11:02:12 -08001521 boolean isAssistantTask() {
1522 return taskType == ASSISTANT_ACTIVITY_TYPE;
1523 }
1524
Craig Mautner86d67a42013-05-14 10:34:38 -07001525 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001526 return taskType == APPLICATION_ACTIVITY_TYPE;
1527 }
1528
1529 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001530 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001531 }
1532
Winson Chung83471632016-12-13 11:02:12 -08001533 boolean isOverAssistantStack() {
1534 return mTaskToReturnTo == ASSISTANT_ACTIVITY_TYPE;
1535 }
1536
Winson Chungd3395382016-12-13 11:49:09 -08001537 private boolean isResizeable(boolean checkSupportsPip) {
1538 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode)
1539 || (checkSupportsPip && mSupportsPictureInPicture)) && !mTemporarilyUnresizable;
1540 }
1541
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001542 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001543 return isResizeable(true /* checkSupportsPip */);
1544 }
1545
1546 boolean supportsSplitScreen() {
1547 // A task can not be docked even if it is considered resizeable because it only supports
1548 // picture-in-picture mode but has a non-resizeable resizeMode
1549 return mService.mSupportsSplitScreenMultiWindow
1550 && isResizeable(false /* checkSupportsPip */)
1551 && !ActivityInfo.isPreserveOrientationMode(mResizeMode);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001552 }
1553
skuhne@google.com322347b2016-12-02 12:54:03 -08001554 /**
1555 * Check that a given bounds matches the application requested orientation.
1556 *
1557 * @param bounds The bounds to be tested.
1558 * @return True if the requested bounds are okay for a resizing request.
1559 */
Wale Ogunwale069bbd32017-02-03 07:58:14 -08001560 private boolean canResizeToBounds(Rect bounds) {
skuhne@google.com322347b2016-12-02 12:54:03 -08001561 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1562 // Note: If not on the freeform workspace, we ignore the bounds.
1563 return true;
1564 }
1565 final boolean landscape = bounds.width() > bounds.height();
1566 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1567 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1568 }
1569 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1570 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1571 }
1572
Craig Mautner525f3d92013-05-07 14:01:50 -07001573 /**
1574 * Find the activity in the history stack within the given task. Returns
1575 * the index within the history at which it's found, or < 0 if not found.
1576 */
1577 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1578 final ComponentName realActivity = r.realActivity;
1579 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1580 ActivityRecord candidate = mActivities.get(activityNdx);
1581 if (candidate.finishing) {
1582 continue;
1583 }
1584 if (candidate.realActivity.equals(realActivity)) {
1585 return candidate;
1586 }
1587 }
1588 return null;
1589 }
1590
Winson Chunga449dc02014-05-16 11:15:04 -07001591 /** Updates the last task description values. */
1592 void updateTaskDescription() {
1593 // Traverse upwards looking for any break between main task activities and
1594 // utility activities.
1595 int activityNdx;
1596 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001597 final boolean relinquish = numActivities != 0 &&
1598 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001599 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001600 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001601 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001602 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001603 // This will be the top activity for determining taskDescription. Pre-inc to
1604 // overcome initial decrement below.
1605 ++activityNdx;
1606 break;
1607 }
Winson Chunga449dc02014-05-16 11:15:04 -07001608 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001609 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001610 break;
1611 }
1612 }
1613 if (activityNdx > 0) {
1614 // Traverse downwards starting below break looking for set label, icon.
1615 // Note that if there are activities in the task but none of them set the
1616 // recent activity values, then we do not fall back to the last set
1617 // values in the TaskRecord.
1618 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001619 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001620 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001621 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001622 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1623 final ActivityRecord r = mActivities.get(activityNdx);
1624 if (r.taskDescription != null) {
1625 if (label == null) {
1626 label = r.taskDescription.getLabel();
1627 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001628 if (iconFilename == null) {
1629 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001630 }
1631 if (colorPrimary == 0) {
1632 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001633 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001634 if (colorBackground == 0) {
1635 colorBackground = r.taskDescription.getBackgroundColor();
1636 }
Winson Chunga449dc02014-05-16 11:15:04 -07001637 }
1638 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001639 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1640 colorBackground);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +01001641 if (mWindowContainerController != null) {
1642 mWindowContainerController.setTaskDescription(lastTaskDescription);
1643 }
Winson Chungec396d62014-08-06 17:08:00 -07001644 // Update the task affiliation color if we are the parent of the group
1645 if (taskId == mAffiliatedTaskId) {
1646 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1647 }
Winson Chunga449dc02014-05-16 11:15:04 -07001648 }
1649 }
1650
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001651 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001652 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001653 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001654 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001655 final ActivityRecord r = mActivities.get(activityNdx);
1656 if (r.finishing) {
1657 continue;
1658 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001659 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001660 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001661 break;
1662 }
1663 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001664 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001665 }
1666
1667 void updateEffectiveIntent() {
1668 final int effectiveRootIndex = findEffectiveRootIndex();
1669 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001670 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001671 }
1672
Craig Mautner21d24a22014-04-23 11:45:37 -07001673 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001674 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001675
1676 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1677 if (realActivity != null) {
1678 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1679 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001680 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001681 if (origActivity != null) {
1682 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1683 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001684 // Write affinity, and root affinity if it is different from affinity.
1685 // We use the special string "@" for a null root affinity, so we can identify
1686 // later whether we were given a root affinity or should just make it the
1687 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001688 if (affinity != null) {
1689 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001690 if (!affinity.equals(rootAffinity)) {
1691 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1692 }
1693 } else if (rootAffinity != null) {
1694 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001695 }
1696 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001697 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001698 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1699 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001700 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001701 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001702 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001703 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001704 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001705 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001706 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001707 if (lastDescription != null) {
1708 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1709 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001710 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001711 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001712 }
Winson Chung36f3f032016-09-08 23:29:43 +00001713 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001714 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001715 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1716 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1717 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001718 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1719 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001720 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08001721 out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE,
1722 String.valueOf(mSupportsPictureInPicture));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001723 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001724 if (mLastNonFullscreenBounds != null) {
1725 out.attribute(
1726 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001727 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001728 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1729 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001730 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001731
Craig Mautner21d24a22014-04-23 11:45:37 -07001732 if (affinityIntent != null) {
1733 out.startTag(null, TAG_AFFINITYINTENT);
1734 affinityIntent.saveToXml(out);
1735 out.endTag(null, TAG_AFFINITYINTENT);
1736 }
1737
Winson Chung36f3f032016-09-08 23:29:43 +00001738 out.startTag(null, TAG_INTENT);
1739 intent.saveToXml(out);
1740 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001741
1742 final ArrayList<ActivityRecord> activities = mActivities;
1743 final int numActivities = activities.size();
1744 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1745 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001746 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001747 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1748 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001749 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001750 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001751 break;
1752 }
1753 out.startTag(null, TAG_ACTIVITY);
1754 r.saveToXml(out);
1755 out.endTag(null, TAG_ACTIVITY);
1756 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001757 }
1758
Winson Chung36f3f032016-09-08 23:29:43 +00001759 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1760 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001761 Intent intent = null;
1762 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001763 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001764 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001765 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001766 ComponentName origActivity = null;
1767 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001768 String rootAffinity = null;
1769 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001770 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001771 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001772 boolean askedCompatMode = false;
1773 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001774 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001775 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001776 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001777 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001778 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001779 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001780 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001781 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001782 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001783 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001784 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001785 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001786 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001787 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001788 int prevTaskId = INVALID_TASK_ID;
1789 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001790 int callingUid = -1;
1791 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001792 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -08001793 boolean supportsPictureInPicture = false;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001794 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001795 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001796 int minWidth = INVALID_MIN_SIZE;
1797 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001798 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001799
1800 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1801 final String attrName = in.getAttributeName(attrNdx);
1802 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001803 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1804 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001805 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001806 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001807 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1808 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001809 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1810 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001811 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1812 origActivity = ComponentName.unflattenFromString(attrValue);
1813 } else if (ATTR_AFFINITY.equals(attrName)) {
1814 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001815 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1816 rootAffinity = attrValue;
1817 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001818 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001819 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001820 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001821 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001822 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001823 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001824 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001825 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001826 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001827 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001828 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001829 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001830 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001831 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001832 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001833 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001834 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001835 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001836 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1837 lastDescription = attrValue;
1838 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001839 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001840 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001841 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001842 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1843 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001844 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1845 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001846 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001847 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001848 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001849 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001850 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001851 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001852 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001853 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001854 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001855 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001856 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1857 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001858 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001859 resizeMode = Integer.parseInt(attrValue);
Winson Chungd3395382016-12-13 11:49:09 -08001860 } else if (ATTR_SUPPORTS_PICTURE_IN_PICTURE.equals(attrName)) {
1861 supportsPictureInPicture = Boolean.parseBoolean(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001862 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001863 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001864 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001865 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001866 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1867 minWidth = Integer.parseInt(attrValue);
1868 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1869 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001870 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1871 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001872 } else {
1873 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1874 }
1875 }
1876
1877 int event;
1878 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001879 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001880 if (event == XmlPullParser.START_TAG) {
1881 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001882 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1883 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001884 if (TAG_AFFINITYINTENT.equals(name)) {
1885 affinityIntent = Intent.restoreFromXml(in);
1886 } else if (TAG_INTENT.equals(name)) {
1887 intent = Intent.restoreFromXml(in);
1888 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001889 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001890 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1891 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001892 if (activity != null) {
1893 activities.add(activity);
1894 }
1895 } else {
1896 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1897 XmlUtils.skipCurrentTag(in);
1898 }
1899 }
1900 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001901 if (!hasRootAffinity) {
1902 rootAffinity = affinity;
1903 } else if ("@".equals(rootAffinity)) {
1904 rootAffinity = null;
1905 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001906 if (effectiveUid <= 0) {
1907 Intent checkIntent = intent != null ? intent : affinityIntent;
1908 effectiveUid = 0;
1909 if (checkIntent != null) {
1910 IPackageManager pm = AppGlobals.getPackageManager();
1911 try {
1912 ApplicationInfo ai = pm.getApplicationInfo(
1913 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001914 PackageManager.MATCH_UNINSTALLED_PACKAGES
1915 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001916 if (ai != null) {
1917 effectiveUid = ai.uid;
1918 }
1919 } catch (RemoteException e) {
1920 }
1921 }
1922 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1923 + ": effectiveUid=" + effectiveUid);
1924 }
1925
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001926 if (persistTaskVersion < 1) {
1927 // We need to convert the resize mode of home activities saved before version one if
1928 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1929 // since we didn't have that differentiation before version 1 and the system didn't
1930 // resize home activities before then.
1931 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1932 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1933 }
Winson Chungd3395382016-12-13 11:49:09 -08001934 } else {
1935 // This activity has previously marked itself explicitly as both resizeable and
1936 // supporting picture-in-picture. Since there is no longer a requirement for
1937 // picture-in-picture activities to be resizeable, we can mark this simply as
1938 // resizeable and supporting picture-in-picture separately.
1939 if (resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED) {
1940 resizeMode = RESIZE_MODE_RESIZEABLE;
1941 supportsPictureInPicture = true;
1942 }
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001943 }
1944
Winson Chung36f3f032016-09-08 23:29:43 +00001945 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001946 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001947 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1948 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001949 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Winson Chungd3395382016-12-13 11:49:09 -08001950 taskAffiliationColor, callingUid, callingPackage, resizeMode,
1951 supportsPictureInPicture, privileged, realActivitySuspended, userSetupComplete,
1952 minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001953 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001954
1955 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001956 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001957 }
1958
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001959 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001960 return task;
1961 }
1962
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001963 private void adjustForMinimalTaskDimensions(Rect bounds) {
1964 if (bounds == null) {
1965 return;
1966 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001967 int minWidth = mMinWidth;
1968 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001969 // If the task has no requested minimal size, we'd like to enforce a minimal size
1970 // so that the user can not render the task too small to manipulate. We don't need
1971 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001972 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001973 if (minWidth == INVALID_MIN_SIZE) {
1974 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001975 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001976 if (minHeight == INVALID_MIN_SIZE) {
1977 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001978 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001979 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001980 final boolean adjustWidth = minWidth > bounds.width();
1981 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001982 if (!(adjustWidth || adjustHeight)) {
1983 return;
1984 }
1985
1986 if (adjustWidth) {
1987 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001988 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001989 } else {
1990 // Either left bounds match, or neither match, or the previous bounds were
1991 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001992 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001993 }
1994 }
1995 if (adjustHeight) {
1996 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001997 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001998 } else {
1999 // Either top bounds match, or neither match, or the previous bounds were
2000 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002001 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002002 }
2003 }
2004 }
2005
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002006 /**
Winson Chung5af42fc2017-03-24 17:11:33 -07002007 * @return a new Configuration for this Task, given the provided {@param bounds} and
2008 * {@param insetBounds}.
2009 */
2010 Configuration computeNewOverrideConfigurationForBounds(Rect bounds, Rect insetBounds) {
2011 // Compute a new override configuration for the given bounds, if fullscreen bounds
2012 // (bounds == null), then leave the override config unset
2013 final Configuration newOverrideConfig = new Configuration();
2014 if (bounds != null) {
2015 newOverrideConfig.setTo(getOverrideConfiguration());
2016 mTmpRect.set(bounds);
2017 adjustForMinimalTaskDimensions(mTmpRect);
2018 computeOverrideConfiguration(newOverrideConfig, mTmpRect, insetBounds,
2019 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
2020 }
2021
2022 return newOverrideConfig;
2023 }
2024
2025 /**
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002026 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002027 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07002028 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002029 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002030 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08002031 return updateOverrideConfiguration(bounds, null /* insetBounds */);
2032 }
2033
2034 /**
2035 * Update task's override configuration based on the bounds.
2036 * @param bounds The bounds of the task.
2037 * @param insetBounds The bounds used to calculate the system insets, which is used here to
2038 * subtract the navigation bar/status bar size from the screen size reported
2039 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07002040 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002041 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002042 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002043 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07002044 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002045 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002046 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08002047 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07002048 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002049
2050 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002051 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002052 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002053 mLastNonFullscreenBounds = mBounds;
2054 }
2055 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07002056 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07002057 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002058 mTmpRect.set(bounds);
2059 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002060 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002061 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002062 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002063 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002064 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002065 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07002066 mLastNonFullscreenBounds = mBounds;
2067 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002068 computeOverrideConfiguration(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07002069 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07002070 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002071 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002072
2073 if (mFullscreen != oldFullscreen) {
Winson Chung5af42fc2017-03-24 17:11:33 -07002074 mService.mStackSupervisor.scheduleUpdateMultiWindowMode(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002075 }
2076
Andrii Kulian1779e612016-10-12 21:58:25 -07002077 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002078 }
2079
Andrii Kulian1779e612016-10-12 21:58:25 -07002080 /** Clears passed config and fills it with new override values. */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002081 // TODO(b/36505427): TaskRecord.computeOverrideConfiguration() is a utility method that doesn't
2082 // depend on task or stacks, but uses those object to get the display to base the calculation
2083 // on. Probably best to centralize calculations like this in ConfigurationContainer.
2084 void computeOverrideConfiguration(Configuration config, Rect bounds, Rect insetBounds,
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002085 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002086 mTmpNonDecorBounds.set(bounds);
2087 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002088
Andrii Kulian1779e612016-10-12 21:58:25 -07002089 config.unset();
Winson Chungbdc646f2017-02-13 12:12:22 -08002090 final Configuration parentConfig = getParent().getConfiguration();
Andrii Kulian1779e612016-10-12 21:58:25 -07002091 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002092
Winson Chungbdc646f2017-02-13 12:12:22 -08002093 if (mStack != null) {
2094 final StackWindowController stackController = mStack.getWindowContainerController();
2095 stackController.adjustConfigurationForBounds(bounds, insetBounds,
2096 mTmpNonDecorBounds, mTmpStableBounds, overrideWidth, overrideHeight, density,
2097 config, parentConfig);
2098 } else {
2099 // No stack, give some default values
2100 config.smallestScreenWidthDp =
2101 mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
2102 config.screenWidthDp = config.screenHeightDp = config.smallestScreenWidthDp;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002103 Slog.wtf(TAG, "Expected stack when calculating override config");
Winson Chungbdc646f2017-02-13 12:12:22 -08002104 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002105
Winson Chung60c1aba2017-03-14 17:47:42 -07002106 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
2107 ? Configuration.ORIENTATION_PORTRAIT
2108 : Configuration.ORIENTATION_LANDSCAPE;
2109
Jorim Jaggi85639432016-05-06 17:27:55 -07002110 // For calculating screen layout, we need to use the non-decor inset screen area for the
2111 // calculation for compatibility reasons, i.e. screen area without system bars that could
2112 // never go away in Honeycomb.
Winson Chungbdc646f2017-02-13 12:12:22 -08002113 final int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density);
2114 final int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07002115 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
2116 // calculation with partial default.
2117 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002118 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07002119 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07002120 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
2121
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08002122 }
2123
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002124 Rect updateOverrideConfigurationFromLaunchBounds() {
2125 final Rect bounds = validateBounds(getLaunchBounds());
2126 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07002127 if (bounds != null) {
2128 bounds.set(mBounds);
2129 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002130 return bounds;
2131 }
2132
2133 static Rect validateBounds(Rect bounds) {
2134 if (bounds != null && bounds.isEmpty()) {
2135 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
2136 return null;
2137 }
2138 return bounds;
2139 }
2140
Wale Ogunwale935e5022015-11-10 12:36:10 -08002141 /** Updates the task's bounds and override configuration to match what is expected for the
2142 * input stack. */
2143 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002144 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002145 return;
2146 }
2147
2148 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002149 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002150 throw new IllegalArgumentException("Can not position non-resizeable task="
2151 + this + " in stack=" + inStack);
2152 }
2153 if (mBounds != null) {
2154 return;
2155 }
2156 if (mLastNonFullscreenBounds != null) {
2157 updateOverrideConfiguration(mLastNonFullscreenBounds);
2158 } else {
2159 inStack.layoutTaskInStack(this, null);
2160 }
2161 } else {
2162 updateOverrideConfiguration(inStack.mBounds);
2163 }
2164 }
2165
Chong Zhang0fa656b2015-08-31 15:17:21 -07002166 /**
2167 * Returns the correct stack to use based on task type and currently set bounds,
2168 * regardless of the focused stack and current stack association of the task.
2169 * The task will be moved (and stack focus changed) later if necessary.
2170 */
2171 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002172 if (isRecentsTask()) {
2173 return RECENTS_STACK_ID;
2174 }
2175 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002176 return HOME_STACK_ID;
2177 }
Winson Chung83471632016-12-13 11:02:12 -08002178 if (isAssistantTask()) {
2179 return ASSISTANT_STACK_ID;
2180 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07002181 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002182 return FREEFORM_WORKSPACE_STACK_ID;
2183 }
2184 return FULLSCREEN_WORKSPACE_STACK_ID;
2185 }
2186
2187 /** Returns the bounds that should be used to launch this task. */
2188 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08002189 // If we're over lockscreen, forget about stack bounds and use fullscreen.
Jorim Jaggife762342016-10-13 14:33:27 +02002190 if (mService.mStackSupervisor.mKeyguardController.isKeyguardShowing()) {
Chong Zhang75b37202015-12-04 14:16:36 -08002191 return null;
2192 }
2193
Andrii Kulian02b7a832016-10-06 23:11:56 -07002194 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08002195 return null;
2196 }
2197
Andrii Kulian02b7a832016-10-06 23:11:56 -07002198 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08002199 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002200 || stackId == RECENTS_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -08002201 || stackId == ASSISTANT_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08002202 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002203 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002204 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07002205 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002206 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002207 }
2208 return mLastNonFullscreenBounds;
2209 }
2210
Wale Ogunwale39381972015-12-17 17:15:29 -08002211 boolean canMatchRootAffinity() {
2212 // We don't allow root affinity matching on the pinned stack as no other task should
2213 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07002214 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08002215 }
2216
Jorim Jaggi8b702ed2017-01-20 16:59:03 +01002217 void addStartingWindowsForVisibleActivities(boolean taskSwitch) {
2218 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
2219 final ActivityRecord r = mActivities.get(activityNdx);
2220 if (r.visible) {
2221 r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch);
2222 }
2223 }
2224 }
2225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002227 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07002228 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
2229 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08002230 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002231 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07002232 if (affinity != null || rootAffinity != null) {
2233 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
2234 if (affinity == null || !affinity.equals(rootAffinity)) {
2235 pw.print(" root="); pw.println(rootAffinity);
2236 } else {
2237 pw.println();
2238 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002239 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07002240 if (voiceSession != null || voiceInteractor != null) {
2241 pw.print(prefix); pw.print("VOICE: session=0x");
2242 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
2243 pw.print(" interactor=0x");
2244 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
2245 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002246 if (intent != null) {
2247 StringBuilder sb = new StringBuilder(128);
2248 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002249 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002250 sb.append('}');
2251 pw.println(sb.toString());
2252 }
2253 if (affinityIntent != null) {
2254 StringBuilder sb = new StringBuilder(128);
2255 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002256 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002257 sb.append('}');
2258 pw.println(sb.toString());
2259 }
2260 if (origActivity != null) {
2261 pw.print(prefix); pw.print("origActivity=");
2262 pw.println(origActivity.flattenToShortString());
2263 }
2264 if (realActivity != null) {
2265 pw.print(prefix); pw.print("realActivity=");
2266 pw.println(realActivity.flattenToShortString());
2267 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07002268 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
2269 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002270 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002271 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002272 pw.print(" numFullscreen="); pw.print(numFullscreen);
2273 pw.print(" taskType="); pw.print(taskType);
2274 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
2275 }
Craig Mautner432f64e2015-05-20 14:59:57 -07002276 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
2277 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002278 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
2279 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07002280 pw.print(" mReuseTask="); pw.print(mReuseTask);
2281 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002282 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08002283 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
2284 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
2285 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07002286 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
2287 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
2288 pw.print(" (");
2289 if (mPrevAffiliate == null) {
2290 pw.print("null");
2291 } else {
2292 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
2293 }
2294 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
2295 pw.print(" (");
2296 if (mNextAffiliate == null) {
2297 pw.print("null");
2298 } else {
2299 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2300 }
2301 pw.println(")");
2302 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002303 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002304 if (!askedCompatMode || !inRecents || !isAvailable) {
2305 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2306 pw.print(" inRecents="); pw.print(inRecents);
2307 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002308 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002309 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002310 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2311 if (lastDescription != null) {
2312 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2313 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002314 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002315 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2316 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08002317 pw.print(" mSupportsPictureInPicture=" + mSupportsPictureInPicture);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002318 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00002319 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002320 pw.print(" lastActiveTime=" + lastActiveTime);
2321 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 }
2323
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002324 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002326 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002327 if (stringName != null) {
2328 sb.append(stringName);
2329 sb.append(" U=");
2330 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002331 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002332 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002333 sb.append(" sz=");
2334 sb.append(mActivities.size());
2335 sb.append('}');
2336 return sb.toString();
2337 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002338 sb.append("TaskRecord{");
2339 sb.append(Integer.toHexString(System.identityHashCode(this)));
2340 sb.append(" #");
2341 sb.append(taskId);
2342 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002343 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002344 sb.append(affinity);
2345 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002346 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002347 sb.append(intent.getComponent().flattenToShortString());
2348 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002349 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002350 sb.append(affinityIntent.getComponent().flattenToShortString());
2351 } else {
2352 sb.append(" ??");
2353 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002354 stringName = sb.toString();
2355 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 }
2357}