blob: 0ae36193213b57d4c2f0708a398ddc8b9d6abafd [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 // Move the task
664 sourceStack.removeTask(this, reason, REMOVE_TASK_MODE_MOVING);
Winson Chung5af42fc2017-03-24 17:11:33 -0700665 toStack.addTask(this, position, false /* schedulePictureInPictureModeChange */, reason);
Winson Chung74666102017-02-22 17:49:24 -0800666
Winson Chung5af42fc2017-03-24 17:11:33 -0700667 if (schedulePictureInPictureModeChange) {
668 // Notify of picture-in-picture mode changes
669 supervisor.scheduleUpdatePictureInPictureModeIfNeeded(this, sourceStack);
670 }
Winson Chung74666102017-02-22 17:49:24 -0800671
672 // TODO: Ensure that this is actually necessary here
673 // Notify the voice session if required
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800674 if (voiceSession != null) {
675 try {
676 voiceSession.taskStarted(intent, taskId);
677 } catch (RemoteException e) {
678 }
679 }
Winson Chung74666102017-02-22 17:49:24 -0800680
681 // If the task had focus before (or we're requested to move focus), move focus to the
682 // new stack by moving the stack to the front.
683 final boolean moveStackToFront = moveStackMode == REPARENT_MOVE_STACK_TO_FRONT
684 || (moveStackMode == REPARENT_KEEP_STACK_AT_FRONT && (wasFocused || wasFront));
Winson Chung95f8f0e2017-03-24 09:20:17 -0700685 if (r != null) {
686 toStack.moveToFrontAndResumeStateIfNeeded(r, moveStackToFront, wasResumed,
687 wasPaused, reason);
688 }
Winson Chung74666102017-02-22 17:49:24 -0800689 if (!animate) {
690 toStack.mNoAnimActivities.add(topActivity);
691 }
692
693 // We might trigger a configuration change. Save the current task bounds for freezing.
694 // TODO: Should this call be moved inside the resize method in WM?
695 toStack.prepareFreezingTaskBounds();
696
697 // Make sure the task has the appropriate bounds/size for the stack it is in.
698 if (stackId == FULLSCREEN_WORKSPACE_STACK_ID
699 && !Objects.equals(mBounds, toStack.mBounds)) {
700 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
701 deferResume);
702 } else if (stackId == FREEFORM_WORKSPACE_STACK_ID) {
703 Rect bounds = getLaunchBounds();
704 if (bounds == null) {
705 toStack.layoutTaskInStack(this, null);
706 bounds = mBounds;
707 }
708 kept = resize(bounds, RESIZE_MODE_FORCED, !mightReplaceWindow, deferResume);
709 } else if (stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID) {
Matthew Ng330757d2017-02-28 14:19:17 -0800710 if (stackId == DOCKED_STACK_ID && moveStackMode == REPARENT_KEEP_STACK_AT_FRONT) {
711 // Move recents to front so it is not behind home stack when going into docked
712 // mode
713 mService.mStackSupervisor.moveRecentsStackToFront(reason);
714 }
Winson Chung74666102017-02-22 17:49:24 -0800715 kept = resize(toStack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow,
716 deferResume);
717 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800718 } finally {
Winson Chung74666102017-02-22 17:49:24 -0800719 windowManager.continueSurfaceLayout();
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800720 }
Winson Chung74666102017-02-22 17:49:24 -0800721
722 if (mightReplaceWindow) {
723 // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old
724 // window), we need to clear the replace window settings. Otherwise, we schedule a
725 // timeout to remove the old window if the replacing window is not coming in time.
726 windowManager.scheduleClearWillReplaceWindows(topActivity.appToken, !kept);
727 }
728
729 if (!deferResume) {
730 // The task might have already been running and its visibility needs to be synchronized
731 // with the visibility of the stack / windows.
732 supervisor.ensureActivitiesVisibleLocked(null, 0, !mightReplaceWindow);
733 supervisor.resumeFocusedStackTopActivityLocked();
734 }
735
736 supervisor.handleNonResizableTaskIfNeeded(this, preferredStackId, stackId);
737
Matthew Ng330757d2017-02-28 14:19:17 -0800738 boolean successful = (preferredStackId == stackId);
739 if (successful && stackId == DOCKED_STACK_ID) {
740 // If task moved to docked stack - show recents if needed.
741 mService.mWindowManager.showRecentApps(false /* fromHome */);
742 }
743 return successful;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800744 }
745
746 void cancelWindowTransition() {
747 mWindowContainerController.cancelWindowTransition();
748 }
749
750 void cancelThumbnailTransition() {
751 mWindowContainerController.cancelThumbnailTransition();
752 }
753
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100754 /**
755 * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
756 */
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100757 TaskSnapshot getSnapshot(boolean reducedResolution) {
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100758
759 // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
760 // synchronized between AM and WM.
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100761 return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800762 }
763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 void touchActiveTime() {
Winson Chung36f3f032016-09-08 23:29:43 +0000765 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700766 if (firstActiveTime == 0) {
767 firstActiveTime = lastActiveTime;
768 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 long getInactiveDuration() {
Winson Chung36f3f032016-09-08 23:29:43 +0000772 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700774
Winson Chungfee26772014-08-05 12:21:52 -0700775 /** Sets the original intent, and the calling uid and package. */
776 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700777 mCallingUid = r.launchedFromUid;
778 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700779 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700780 }
781
782 /** Sets the original intent, _without_ updating the calling uid or package. */
783 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700784 if (intent == null) {
785 mNeverRelinquishIdentity =
Wale Ogunwale3eadad72016-10-13 09:16:59 -0700786 (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700787 } else if (mNeverRelinquishIdentity) {
788 return;
789 }
790
791 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700792 if (intent == null) {
793 // If this task already has an intent associated with it, don't set the root
794 // affinity -- we don't want it changing after initially set, but the initially
795 // set value may be null.
796 rootAffinity = affinity;
797 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700798 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700799 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800802 if (_intent != null) {
803 // If this Intent has a selector, we want to clear it for the
804 // recent task since it is not relevant if the user later wants
805 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700806 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800807 _intent = new Intent(_intent);
808 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700809 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800810 }
811 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700812 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 intent = _intent;
814 realActivity = _intent != null ? _intent.getComponent() : null;
815 origActivity = null;
816 } else {
817 ComponentName targetComponent = new ComponentName(
818 info.packageName, info.targetActivity);
819 if (_intent != null) {
820 Intent targetIntent = new Intent(_intent);
821 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800822 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700823 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700824 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700825 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 intent = targetIntent;
827 realActivity = targetComponent;
828 origActivity = _intent.getComponent();
829 } else {
830 intent = null;
831 realActivity = targetComponent;
832 origActivity = new ComponentName(info.packageName, info.name);
833 }
834 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700835
Craig Mautner47b20ba2014-09-17 17:23:44 -0700836 final int intentFlags = intent == null ? 0 : intent.getFlags();
837 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 // Once we are set to an Intent with this flag, we count this
839 // task as having a true root activity.
840 rootWasReset = true;
841 }
Dianne Hackborn09233282014-04-30 11:33:59 -0700842 userId = UserHandle.getUserId(info.applicationInfo.uid);
Winson Chung36f3f032016-09-08 23:29:43 +0000843 mUserSetupComplete = Settings.Secure.getIntForUser(mService.mContext.getContentResolver(),
844 USER_SETUP_COMPLETE, 0, userId) != 0;
Craig Mautner41db4a72014-05-07 17:20:56 -0700845 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700846 // If the activity itself has requested auto-remove, then just always do it.
847 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700848 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
849 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700850 // If the caller has not asked for the document to be retained, then we may
851 // want to turn on auto-remove, depending on whether the target has set its
852 // own document launch mode.
853 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
854 autoRemoveRecents = false;
855 } else {
856 autoRemoveRecents = true;
857 }
858 } else {
859 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700860 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800861 mResizeMode = info.resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800862 mSupportsPictureInPicture = info.supportsPictureInPicture();
Craig Mautner15df08a2015-04-01 12:17:18 -0700863 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700864 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700865 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800867
Andrii Kulian2e751b82016-03-16 16:59:32 -0700868 /** Sets the original minimal width and height. */
869 private void setMinDimensions(ActivityInfo info) {
870 if (info != null && info.windowLayout != null) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700871 mMinWidth = info.windowLayout.minWidth;
872 mMinHeight = info.windowLayout.minHeight;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700873 } else {
Andrii Kulianf66a83d2016-05-17 12:17:44 -0700874 mMinWidth = INVALID_MIN_SIZE;
875 mMinHeight = INVALID_MIN_SIZE;
Andrii Kulian2e751b82016-03-16 16:59:32 -0700876 }
877 }
878
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800879 /**
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700880 * Return true if the input activity has the same intent filter as the intent this task
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800881 * record is based on (normally the root activity intent).
882 */
Andrii Kulian206b9fa2016-06-02 13:18:01 -0700883 boolean isSameIntentFilter(ActivityRecord r) {
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800884 final Intent intent = new Intent(r.intent);
885 // Correct the activity intent for aliasing. The task record intent will always be based on
886 // the real activity that will be launched not the alias, so we need to use an intent with
887 // the component name pointing to the real activity not the alias in the activity record.
888 intent.setComponent(r.realActivity);
889 return this.intent.filterEquals(intent);
890 }
891
Craig Mautner84984fa2014-06-19 11:19:20 -0700892 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800893 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
894 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700895 }
896
Winson Chung83471632016-12-13 11:02:12 -0800897 void setTaskToReturnTo(ActivityRecord source) {
898 if (source.isRecentsActivity()) {
899 setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
900 } else if (source.isAssistantActivity()) {
901 setTaskToReturnTo(ASSISTANT_ACTIVITY_TYPE);
902 }
903 }
904
Craig Mautner84984fa2014-06-19 11:19:20 -0700905 int getTaskToReturnTo() {
906 return mTaskToReturnTo;
907 }
908
Craig Mautnera228ae92014-07-09 05:44:55 -0700909 void setPrevAffiliate(TaskRecord prevAffiliate) {
910 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800911 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700912 }
913
914 void setNextAffiliate(TaskRecord nextAffiliate) {
915 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800916 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700917 }
918
Andrii Kulian02b7a832016-10-06 23:11:56 -0700919 ActivityStack getStack() {
920 return mStack;
921 }
922
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800923 /**
924 * Must be used for setting parent stack because it performs configuration updates.
925 * Must be called after adding task as a child to the stack.
926 */
Andrii Kulian02b7a832016-10-06 23:11:56 -0700927 void setStack(ActivityStack stack) {
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800928 if (stack != null && !stack.isInStackLocked(this)) {
929 throw new IllegalStateException("Task must be added as a Stack child first.");
930 }
Andrii Kulian02b7a832016-10-06 23:11:56 -0700931 mStack = stack;
Andrii Kulian1779e612016-10-12 21:58:25 -0700932 onParentChanged();
Andrii Kulian02b7a832016-10-06 23:11:56 -0700933 }
934
935 /**
936 * @return Id of current stack, {@link INVALID_STACK_ID} if no stack is set.
937 */
938 int getStackId() {
939 return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
940 }
941
Andrii Kulian1779e612016-10-12 21:58:25 -0700942 @Override
943 protected int getChildCount() {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700944 return mActivities.size();
Andrii Kulian1779e612016-10-12 21:58:25 -0700945 }
946
947 @Override
948 protected ConfigurationContainer getChildAt(int index) {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700949 return mActivities.get(index);
Andrii Kulian1779e612016-10-12 21:58:25 -0700950 }
951
952 @Override
953 protected ConfigurationContainer getParent() {
954 return mStack;
955 }
956
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800957 @Override
958 void onParentChanged() {
959 super.onParentChanged();
960 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
961 }
962
Craig Mautnera228ae92014-07-09 05:44:55 -0700963 // Close up recents linked list.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700964 private void closeRecentsChain() {
Craig Mautnera228ae92014-07-09 05:44:55 -0700965 if (mPrevAffiliate != null) {
966 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
967 }
968 if (mNextAffiliate != null) {
969 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
970 }
971 setPrevAffiliate(null);
972 setNextAffiliate(null);
973 }
974
Winson Chung740c3ac2014-11-12 16:14:38 -0800975 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700976 disposeThumbnail();
977 closeRecentsChain();
978 if (inRecents) {
979 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800980 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700981 }
Jorim Jaggif9084ec2017-01-16 13:16:59 +0100982
983 // TODO: Use window container controller once tasks are better synced between AM and WM
984 mService.mWindowManager.notifyTaskRemovedFromRecents(taskId, userId);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700985 }
986
Craig Mautnera228ae92014-07-09 05:44:55 -0700987 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
988 closeRecentsChain();
989 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700990 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700991 // Find the end
992 while (taskToAffiliateWith.mNextAffiliate != null) {
993 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
994 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
995 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
996 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
997 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
998 nextRecents.setPrevAffiliate(null);
999 }
1000 taskToAffiliateWith.setNextAffiliate(null);
1001 break;
1002 }
1003 taskToAffiliateWith = nextRecents;
1004 }
1005 taskToAffiliateWith.setNextAffiliate(this);
1006 setPrevAffiliate(taskToAffiliateWith);
1007 setNextAffiliate(null);
1008 }
1009
Winson Chung096f36b2014-08-20 15:39:01 -07001010 /**
Winsonc809cbb2015-11-02 12:06:15 -08001011 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -07001012 * @return whether the thumbnail was set
1013 */
Winsonc809cbb2015-11-02 12:06:15 -08001014 boolean setLastThumbnailLocked(Bitmap thumbnail) {
Winsonc809cbb2015-11-02 12:06:15 -08001015 int taskWidth = 0;
1016 int taskHeight = 0;
1017 if (mBounds != null) {
1018 // Non-fullscreen tasks
1019 taskWidth = mBounds.width();
1020 taskHeight = mBounds.height();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001021 } else if (mStack != null) {
Winsonc809cbb2015-11-02 12:06:15 -08001022 // Fullscreen tasks
1023 final Point displaySize = new Point();
Andrii Kulian02b7a832016-10-06 23:11:56 -07001024 mStack.getDisplaySize(displaySize);
Winsonc809cbb2015-11-02 12:06:15 -08001025 taskWidth = displaySize.x;
1026 taskHeight = displaySize.y;
1027 } else {
1028 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
1029 }
Andrii Kulian1779e612016-10-12 21:58:25 -07001030 // We need to provide the current orientation of the display on which this task resides,
1031 // not the orientation of the task.
1032 final int orientation =
1033 getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
1034 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
Winsonc809cbb2015-11-02 12:06:15 -08001035 }
1036
1037 /**
1038 * Sets the last thumbnail with the current task bounds.
1039 * @return whether the thumbnail was set
1040 */
1041 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
1042 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -07001043 if (mLastThumbnail != thumbnail) {
1044 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001045 mLastThumbnailInfo.taskWidth = taskWidth;
1046 mLastThumbnailInfo.taskHeight = taskHeight;
1047 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -07001048 if (thumbnail == null) {
1049 if (mLastThumbnailFile != null) {
1050 mLastThumbnailFile.delete();
1051 }
1052 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001053 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001054 }
Winson Chung096f36b2014-08-20 15:39:01 -07001055 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001056 }
Winson Chung096f36b2014-08-20 15:39:01 -07001057 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001058 }
1059
1060 void getLastThumbnail(TaskThumbnail thumbs) {
1061 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -08001062 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001063 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001064 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001065 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -08001066 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -07001067 }
Winson Chung096f36b2014-08-20 15:39:01 -07001068 // Only load the thumbnail file if we don't have a thumbnail
1069 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001070 try {
1071 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
1072 ParcelFileDescriptor.MODE_READ_ONLY);
1073 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -07001074 }
1075 }
1076 }
1077
Winsonc809cbb2015-11-02 12:06:15 -08001078 /**
1079 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
1080 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001081 void freeLastThumbnail() {
1082 mLastThumbnail = null;
1083 }
1084
Winsonc809cbb2015-11-02 12:06:15 -08001085 /**
1086 * Removes all associated thumbnail data when a task is removed or pruned from recents.
1087 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001088 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -08001089 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001090 mLastThumbnail = null;
1091 lastDescription = null;
1092 }
1093
Winson Chung1147c402014-05-14 11:05:00 -07001094 /** Returns the intent for the root activity for this task */
1095 Intent getBaseIntent() {
1096 return intent != null ? intent : affinityIntent;
1097 }
1098
Winson Chung3b3f4642014-04-22 10:08:18 -07001099 /** Returns the first non-finishing activity from the root. */
1100 ActivityRecord getRootActivity() {
1101 for (int i = 0; i < mActivities.size(); i++) {
1102 final ActivityRecord r = mActivities.get(i);
1103 if (r.finishing) {
1104 continue;
1105 }
1106 return r;
1107 }
1108 return null;
1109 }
1110
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001111 ActivityRecord getTopActivity() {
1112 for (int i = mActivities.size() - 1; i >= 0; --i) {
1113 final ActivityRecord r = mActivities.get(i);
1114 if (r.finishing) {
1115 continue;
1116 }
1117 return r;
1118 }
1119 return null;
1120 }
1121
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -07001122 ActivityRecord topRunningActivityLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001123 if (mStack != null) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001124 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1125 ActivityRecord r = mActivities.get(activityNdx);
Chong Zhang87761972016-08-22 13:53:24 -07001126 if (!r.finishing && r.okToShowLocked()) {
Wale Ogunwale7d701172015-03-11 15:36:30 -07001127 return r;
1128 }
Craig Mautner6b74cb52013-09-27 17:02:21 -07001129 }
1130 }
1131 return null;
1132 }
1133
Wale Ogunwale3b232392016-05-13 15:37:13 -07001134 ActivityRecord topRunningActivityWithStartingWindowLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001135 if (mStack != null) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001136 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1137 ActivityRecord r = mActivities.get(activityNdx);
1138 if (r.mStartingWindowState != STARTING_WINDOW_SHOWN
Chong Zhang87761972016-08-22 13:53:24 -07001139 || r.finishing || !r.okToShowLocked()) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001140 continue;
1141 }
1142 return r;
1143 }
1144 }
1145 return null;
1146 }
1147
Chong Zhang87761972016-08-22 13:53:24 -07001148 boolean okToShowLocked() {
1149 // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is
1150 // okay to show the activity when locked.
1151 return mService.mStackSupervisor.isCurrentProfileLocked(userId)
1152 || topRunningActivityLocked() != null;
1153 }
1154
Craig Mautner3b475fe2013-12-16 15:58:31 -08001155 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Bryce Leed71317c2017-02-07 14:27:22 -08001156 final void setFrontOfTask() {
1157 boolean foundFront = false;
Craig Mautner3b475fe2013-12-16 15:58:31 -08001158 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -08001159 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -08001160 final ActivityRecord r = mActivities.get(activityNdx);
1161 if (foundFront || r.finishing) {
1162 r.frontOfTask = false;
1163 } else {
1164 r.frontOfTask = true;
1165 // Set frontOfTask false for every following activity.
1166 foundFront = true;
1167 }
1168 }
Craig Mautner9587ee02014-06-23 15:00:10 +00001169 if (!foundFront && numActivities > 0) {
1170 // All activities of this task are finishing. As we ought to have a frontOfTask
1171 // activity, make the bottom activity front.
1172 mActivities.get(0).frontOfTask = true;
1173 }
Craig Mautner3b475fe2013-12-16 15:58:31 -08001174 }
1175
Craig Mautnerde4ef022013-04-07 19:01:33 -07001176 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -08001177 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -07001178 */
1179 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -07001180 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
1181 "Removing and adding activity " + newTop
1182 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -07001183
Craig Mautnerde4ef022013-04-07 19:01:33 -07001184 mActivities.remove(newTop);
1185 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001186 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -08001187
Bryce Leed71317c2017-02-07 14:27:22 -08001188 setFrontOfTask();
Craig Mautnerde4ef022013-04-07 19:01:33 -07001189 }
1190
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001191 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -08001192 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001193 }
1194
1195 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001196 addActivityAtIndex(mActivities.size(), r);
1197 }
1198
Winson Chung30480042017-01-26 10:55:34 -08001199 /**
1200 * Adds an activity {@param r} at the given {@param index}. The activity {@param r} must either
1201 * be in the current task or unparented to any task.
1202 */
Craig Mautner1602ec22013-05-12 10:24:27 -07001203 void addActivityAtIndex(int index, ActivityRecord r) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001204 TaskRecord task = r.getTask();
1205 if (task != null && task != this) {
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001206 throw new IllegalArgumentException("Can not add r=" + " to task=" + this
Bryce Leeaf691c02017-03-20 14:20:22 -07001207 + " current parent=" + task);
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001208 }
Bryce Leeaf691c02017-03-20 14:20:22 -07001209
1210 r.setTask(this);
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001211
Craig Mautner6170f732013-04-02 13:05:23 -07001212 // 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 -08001213 if (!mActivities.remove(r) && r.fullscreen) {
1214 // Was not previously in list.
1215 numFullscreen++;
1216 }
Craig Mautner2c1faed2013-07-23 12:56:02 -07001217 // Only set this based on the first activity
1218 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001219 taskType = r.mActivityType;
1220 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001221 mCallingUid = r.launchedFromUid;
1222 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001223 // Clamp to [1, max].
1224 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
1225 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -07001226 } else {
1227 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -07001228 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -07001229 }
Wale Ogunwale3b232392016-05-13 15:37:13 -07001230
1231 final int size = mActivities.size();
1232
1233 if (index == size && size > 0) {
1234 final ActivityRecord top = mActivities.get(size - 1);
1235 if (top.mTaskOverlay) {
1236 // Place below the task overlay activity since the overlay activity should always
1237 // be on top.
1238 index--;
1239 }
1240 }
1241
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001242 index = Math.min(size, index);
Craig Mautner77878772013-03-04 19:46:24 -08001243 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001244 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -07001245 if (r.isPersistable()) {
1246 mService.notifyTaskPersisterLocked(this, false);
1247 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001248
1249 // Sync. with window manager
1250 updateOverrideConfigurationFromLaunchBounds();
Wale Ogunwalea0cd15e2017-02-01 15:33:08 -08001251 final AppWindowContainerController appController = r.getWindowContainerController();
1252 if (appController != null) {
1253 // Only attempt to move in WM if the child has a controller. It is possible we haven't
1254 // created controller for the activity we are starting yet.
1255 mWindowContainerController.positionChildAt(appController, index);
1256 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -08001257 r.onOverrideConfigurationSent();
David Stevens82ea6cb2017-03-03 16:18:50 -08001258
1259 // Make sure the list of display UID whitelists is updated
1260 // now that this record is in a new task.
1261 mService.mStackSupervisor.updateUIDsPresentOnDisplay();
Craig Mautner77878772013-03-04 19:46:24 -08001262 }
1263
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001264 /**
Bryce Leeaf691c02017-03-20 14:20:22 -07001265 * Removes the specified activity from this task.
1266 * @param r The {@link ActivityRecord} to remove.
1267 * @return true if this was the last activity in the task.
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001268 */
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001269 boolean removeActivity(ActivityRecord r) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001270 return removeActivity(r, false /*reparenting*/);
1271 }
1272
1273 boolean removeActivity(ActivityRecord r, boolean reparenting) {
1274 if (r.getTask() != this) {
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001275 throw new IllegalArgumentException(
1276 "Activity=" + r + " does not belong to task=" + this);
1277 }
1278
Bryce Leeaf691c02017-03-20 14:20:22 -07001279 r.setTask(null /*task*/, reparenting);
Bryce Leeaa5e8c32017-03-01 16:01:06 -08001280
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001281 if (mActivities.remove(r) && r.fullscreen) {
1282 // Was previously in list.
1283 numFullscreen--;
1284 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001285 if (r.isPersistable()) {
1286 mService.notifyTaskPersisterLocked(this, false);
1287 }
Wale Ogunwale89182d52016-03-11 10:38:36 -08001288
Andrii Kulian02b7a832016-10-06 23:11:56 -07001289 if (getStackId() == PINNED_STACK_ID) {
Wale Ogunwale89182d52016-03-11 10:38:36 -08001290 // We normally notify listeners of task stack changes on pause, however pinned stack
1291 // activities are normally in the paused state so no notification will be sent there
1292 // before the activity is removed. We send it here so instead.
Yorke Leebd54c2a2016-10-25 13:49:23 -07001293 mService.mTaskChangeNotificationController.notifyTaskStackChanged();
Wale Ogunwale89182d52016-03-11 10:38:36 -08001294 }
1295
Craig Mautner41326202014-06-20 14:38:21 -07001296 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -07001297 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -07001298 }
1299 updateEffectiveIntent();
1300 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001301 }
1302
Winson Chung6954fc92017-03-24 16:22:12 -07001303 /**
1304 * @return whether or not there are ONLY task overlay activities in the stack.
1305 * If {@param excludeFinishing} is set, then ignore finishing activities in the check.
1306 * If there are no task overlay activities, this call returns false.
1307 */
1308 boolean onlyHasTaskOverlayActivities(boolean excludeFinishing) {
1309 int count = 0;
1310 for (int i = mActivities.size() - 1; i >= 0; i--) {
1311 final ActivityRecord r = mActivities.get(i);
1312 if (excludeFinishing && r.finishing) {
1313 continue;
1314 }
1315 if (!r.mTaskOverlay) {
1316 return false;
1317 }
1318 count++;
1319 }
1320 return count > 0;
1321 }
1322
Craig Mautner41db4a72014-05-07 17:20:56 -07001323 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001324 // We will automatically remove the task either if it has explicitly asked for
1325 // this, or it is empty and has never contained an activity that got shown to
1326 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -07001327 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -07001328 }
1329
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001330 /**
1331 * Completely remove all activities associated with an existing
1332 * task starting at a specified index.
1333 */
Winson Chung6954fc92017-03-24 16:22:12 -07001334 final void performClearTaskAtIndexLocked(int activityNdx, boolean pauseImmediately) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001335 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001336 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001337 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001338 if (r.finishing) {
1339 continue;
1340 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001341 if (mStack == null) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001342 // Task was restored from persistent storage.
1343 r.takeFromHistory();
1344 mActivities.remove(activityNdx);
1345 --activityNdx;
1346 --numActivities;
Winson Chung6954fc92017-03-24 16:22:12 -07001347 } else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null,
1348 "clear-task-index", false, pauseImmediately)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001349 --activityNdx;
1350 --numActivities;
1351 }
1352 }
1353 }
1354
1355 /**
1356 * Completely remove all activities associated with an existing task.
1357 */
1358 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -07001359 mReuseTask = true;
Winson Chung6954fc92017-03-24 16:22:12 -07001360 performClearTaskAtIndexLocked(0, !PAUSE_IMMEDIATELY);
Craig Mautner362449a2014-06-20 14:04:39 -07001361 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001362 }
1363
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -08001364 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
1365 mReuseTask = true;
1366 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
1367 mReuseTask = false;
1368 return result;
1369 }
1370
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001371 /**
1372 * Perform clear operation as requested by
1373 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
1374 * stack to the given task, then look for
1375 * an instance of that activity in the stack and, if found, finish all
1376 * activities on top of it and return the instance.
1377 *
1378 * @param newR Description of the new activity being started.
1379 * @return Returns the old activity that should be continued to be used,
1380 * or null if none was found.
1381 */
1382 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001383 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001384 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001385 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001386 if (r.finishing) {
1387 continue;
1388 }
1389 if (r.realActivity.equals(newR.realActivity)) {
1390 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -07001391 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001392
1393 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -07001394 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001395 if (r.finishing) {
1396 continue;
1397 }
1398 ActivityOptions opts = r.takeOptionsLocked();
1399 if (opts != null) {
1400 ret.updateOptionsLocked(opts);
1401 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07001402 if (mStack != null && mStack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -08001403 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001404 --activityNdx;
1405 --numActivities;
1406 }
1407 }
1408
1409 // Finally, if this is a normal launch mode (that is, not
1410 // expecting onNewIntent()), then we will finish the current
1411 // instance of the activity so a new fresh one can be started.
1412 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
Daichi Hirono15a02992016-04-27 18:47:01 +09001413 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0
1414 && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001415 if (!ret.finishing) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001416 if (mStack != null) {
1417 mStack.finishActivityLocked(
Wale Ogunwale7d701172015-03-11 15:36:30 -07001418 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
1419 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -07001420 return null;
1421 }
1422 }
1423
1424 return ret;
1425 }
1426 }
1427
1428 return null;
1429 }
1430
Andrii Kulian21713ac2016-10-12 22:05:05 -07001431 TaskThumbnail getTaskThumbnailLocked() {
Andrii Kulian02b7a832016-10-06 23:11:56 -07001432 if (mStack != null) {
1433 final ActivityRecord resumedActivity = mStack.mResumedActivity;
Bryce Leeaf691c02017-03-20 14:20:22 -07001434 if (resumedActivity != null && resumedActivity.getTask() == this) {
Andrii Kulian21713ac2016-10-12 22:05:05 -07001435 final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
Winsonc809cbb2015-11-02 12:06:15 -08001436 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -07001437 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001438 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001439 final TaskThumbnail taskThumbnail = new TaskThumbnail();
1440 getLastThumbnail(taskThumbnail);
1441 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001442 }
1443
Winson Chung6954fc92017-03-24 16:22:12 -07001444 void removeTaskActivitiesLocked(boolean pauseImmediately) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001445 // Just remove the entire task.
Winson Chung6954fc92017-03-24 16:22:12 -07001446 performClearTaskAtIndexLocked(0, pauseImmediately);
Craig Mautner9db9a0b2013-04-29 17:05:56 -07001447 }
1448
Craig Mautner432f64e2015-05-20 14:59:57 -07001449 String lockTaskAuthToString() {
1450 switch (mLockTaskAuth) {
1451 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
1452 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
1453 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
1454 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +01001455 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -07001456 default: return "unknown=" + mLockTaskAuth;
1457 }
1458 }
1459
Craig Mautner15df08a2015-04-01 12:17:18 -07001460 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +01001461 if (!mPrivileged &&
1462 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
1463 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
1464 // Non-priv apps are not allowed to use always or never, fall back to default
1465 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
1466 }
Craig Mautner15df08a2015-04-01 12:17:18 -07001467 switch (mLockTaskMode) {
1468 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
1469 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1470 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
1471 break;
1472
1473 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +01001474 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -07001475 break;
1476
1477 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +01001478 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -07001479 break;
1480
1481 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
1482 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
1483 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
1484 break;
1485 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001486 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
1487 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -07001488 }
1489
1490 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001491 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
1492 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001493 return false;
1494 }
1495 String[] packages = mService.mLockTaskPackages.get(userId);
1496 if (packages == null) {
1497 return false;
1498 }
1499 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +01001500 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -07001501 return true;
1502 }
1503 }
1504 return false;
1505 }
Wale Ogunwale74e26592016-02-05 11:48:37 -08001506
Craig Mautnera82aa092013-09-13 15:34:08 -07001507 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001508 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -07001509 }
1510
Wale Ogunwale74e26592016-02-05 11:48:37 -08001511 boolean isRecentsTask() {
1512 return taskType == RECENTS_ACTIVITY_TYPE;
1513 }
1514
Winson Chung83471632016-12-13 11:02:12 -08001515 boolean isAssistantTask() {
1516 return taskType == ASSISTANT_ACTIVITY_TYPE;
1517 }
1518
Craig Mautner86d67a42013-05-14 10:34:38 -07001519 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -07001520 return taskType == APPLICATION_ACTIVITY_TYPE;
1521 }
1522
1523 boolean isOverHomeStack() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001524 return mTaskToReturnTo == HOME_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -07001525 }
1526
Winson Chung83471632016-12-13 11:02:12 -08001527 boolean isOverAssistantStack() {
1528 return mTaskToReturnTo == ASSISTANT_ACTIVITY_TYPE;
1529 }
1530
Winson Chungd3395382016-12-13 11:49:09 -08001531 private boolean isResizeable(boolean checkSupportsPip) {
1532 return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode)
1533 || (checkSupportsPip && mSupportsPictureInPicture)) && !mTemporarilyUnresizable;
1534 }
1535
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001536 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -08001537 return isResizeable(true /* checkSupportsPip */);
1538 }
1539
1540 boolean supportsSplitScreen() {
1541 // A task can not be docked even if it is considered resizeable because it only supports
1542 // picture-in-picture mode but has a non-resizeable resizeMode
1543 return mService.mSupportsSplitScreenMultiWindow
1544 && isResizeable(false /* checkSupportsPip */)
1545 && !ActivityInfo.isPreserveOrientationMode(mResizeMode);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001546 }
1547
skuhne@google.com322347b2016-12-02 12:54:03 -08001548 /**
1549 * Check that a given bounds matches the application requested orientation.
1550 *
1551 * @param bounds The bounds to be tested.
1552 * @return True if the requested bounds are okay for a resizing request.
1553 */
Wale Ogunwale069bbd32017-02-03 07:58:14 -08001554 private boolean canResizeToBounds(Rect bounds) {
skuhne@google.com322347b2016-12-02 12:54:03 -08001555 if (bounds == null || getStackId() != FREEFORM_WORKSPACE_STACK_ID) {
1556 // Note: If not on the freeform workspace, we ignore the bounds.
1557 return true;
1558 }
1559 final boolean landscape = bounds.width() > bounds.height();
1560 if (mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION) {
1561 return mBounds == null || landscape == (mBounds.width() > mBounds.height());
1562 }
1563 return (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY || !landscape)
1564 && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape);
1565 }
1566
Craig Mautner525f3d92013-05-07 14:01:50 -07001567 /**
Yorke Leebdef5372017-04-10 16:38:51 -07001568 * @return {@code true} if the task is being cleared for the purposes of being reused.
1569 */
1570 boolean isClearingToReuseTask() {
1571 return mReuseTask;
1572 }
1573
1574 /**
Craig Mautner525f3d92013-05-07 14:01:50 -07001575 * Find the activity in the history stack within the given task. Returns
1576 * the index within the history at which it's found, or < 0 if not found.
1577 */
1578 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
1579 final ComponentName realActivity = r.realActivity;
1580 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
1581 ActivityRecord candidate = mActivities.get(activityNdx);
1582 if (candidate.finishing) {
1583 continue;
1584 }
1585 if (candidate.realActivity.equals(realActivity)) {
1586 return candidate;
1587 }
1588 }
1589 return null;
1590 }
1591
Winson Chunga449dc02014-05-16 11:15:04 -07001592 /** Updates the last task description values. */
1593 void updateTaskDescription() {
1594 // Traverse upwards looking for any break between main task activities and
1595 // utility activities.
1596 int activityNdx;
1597 final int numActivities = mActivities.size();
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001598 final boolean relinquish = numActivities != 0 &&
1599 (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001600 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001601 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001602 final ActivityRecord r = mActivities.get(activityNdx);
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001603 if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001604 // This will be the top activity for determining taskDescription. Pre-inc to
1605 // overcome initial decrement below.
1606 ++activityNdx;
1607 break;
1608 }
Winson Chunga449dc02014-05-16 11:15:04 -07001609 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001610 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001611 break;
1612 }
1613 }
1614 if (activityNdx > 0) {
1615 // Traverse downwards starting below break looking for set label, icon.
1616 // Note that if there are activities in the task but none of them set the
1617 // recent activity values, then we do not fall back to the last set
1618 // values in the TaskRecord.
1619 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001620 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001621 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001622 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001623 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1624 final ActivityRecord r = mActivities.get(activityNdx);
1625 if (r.taskDescription != null) {
1626 if (label == null) {
1627 label = r.taskDescription.getLabel();
1628 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001629 if (iconFilename == null) {
1630 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001631 }
1632 if (colorPrimary == 0) {
1633 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001634 }
Jason Monkba53d8a2017-04-06 18:28:19 +00001635 if (colorBackground == 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001636 colorBackground = r.taskDescription.getBackgroundColor();
1637 }
Winson Chunga449dc02014-05-16 11:15:04 -07001638 }
1639 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001640 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
Jason Monkba53d8a2017-04-06 18:28:19 +00001641 colorBackground);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +01001642 if (mWindowContainerController != null) {
1643 mWindowContainerController.setTaskDescription(lastTaskDescription);
1644 }
Winson Chungec396d62014-08-06 17:08:00 -07001645 // Update the task affiliation color if we are the parent of the group
1646 if (taskId == mAffiliatedTaskId) {
1647 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1648 }
Winson Chunga449dc02014-05-16 11:15:04 -07001649 }
1650 }
1651
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001652 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001653 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001654 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001655 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001656 final ActivityRecord r = mActivities.get(activityNdx);
1657 if (r.finishing) {
1658 continue;
1659 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001660 effectiveNdx = activityNdx;
Wale Ogunwale3eadad72016-10-13 09:16:59 -07001661 if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001662 break;
1663 }
1664 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001665 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001666 }
1667
1668 void updateEffectiveIntent() {
1669 final int effectiveRootIndex = findEffectiveRootIndex();
1670 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001671 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001672 }
1673
Craig Mautner21d24a22014-04-23 11:45:37 -07001674 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001675 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001676
1677 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1678 if (realActivity != null) {
1679 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1680 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001681 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001682 if (origActivity != null) {
1683 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1684 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001685 // Write affinity, and root affinity if it is different from affinity.
1686 // We use the special string "@" for a null root affinity, so we can identify
1687 // later whether we were given a root affinity or should just make it the
1688 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001689 if (affinity != null) {
1690 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001691 if (!affinity.equals(rootAffinity)) {
1692 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1693 }
1694 } else if (rootAffinity != null) {
1695 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001696 }
1697 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001698 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001699 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1700 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001701 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001702 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001703 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001704 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001705 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001706 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001707 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001708 if (lastDescription != null) {
1709 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1710 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001711 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001712 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001713 }
Winson Chung36f3f032016-09-08 23:29:43 +00001714 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001715 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001716 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1717 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1718 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001719 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1720 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001721 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08001722 out.attribute(null, ATTR_SUPPORTS_PICTURE_IN_PICTURE,
1723 String.valueOf(mSupportsPictureInPicture));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001724 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001725 if (mLastNonFullscreenBounds != null) {
1726 out.attribute(
1727 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001728 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001729 out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
1730 out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001731 out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
Winson Chung2cb86c72014-06-25 12:03:30 -07001732
Craig Mautner21d24a22014-04-23 11:45:37 -07001733 if (affinityIntent != null) {
1734 out.startTag(null, TAG_AFFINITYINTENT);
1735 affinityIntent.saveToXml(out);
1736 out.endTag(null, TAG_AFFINITYINTENT);
1737 }
1738
Winson Chung36f3f032016-09-08 23:29:43 +00001739 out.startTag(null, TAG_INTENT);
1740 intent.saveToXml(out);
1741 out.endTag(null, TAG_INTENT);
Craig Mautner21d24a22014-04-23 11:45:37 -07001742
1743 final ArrayList<ActivityRecord> activities = mActivities;
1744 final int numActivities = activities.size();
1745 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1746 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001747 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001748 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1749 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001750 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001751 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001752 break;
1753 }
1754 out.startTag(null, TAG_ACTIVITY);
1755 r.saveToXml(out);
1756 out.endTag(null, TAG_ACTIVITY);
1757 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001758 }
1759
Winson Chung36f3f032016-09-08 23:29:43 +00001760 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1761 throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -07001762 Intent intent = null;
1763 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001764 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001765 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001766 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001767 ComponentName origActivity = null;
1768 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001769 String rootAffinity = null;
1770 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001771 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001772 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001773 boolean askedCompatMode = false;
1774 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001775 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001776 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001777 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001778 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001779 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001780 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001781 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001782 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001783 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001784 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001785 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001786 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001787 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001788 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001789 int prevTaskId = INVALID_TASK_ID;
1790 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001791 int callingUid = -1;
1792 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001793 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Winson Chungd3395382016-12-13 11:49:09 -08001794 boolean supportsPictureInPicture = false;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001795 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001796 Rect bounds = null;
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001797 int minWidth = INVALID_MIN_SIZE;
1798 int minHeight = INVALID_MIN_SIZE;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001799 int persistTaskVersion = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -07001800
1801 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1802 final String attrName = in.getAttributeName(attrNdx);
1803 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001804 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1805 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001806 if (ATTR_TASKID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001807 if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001808 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1809 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001810 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1811 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001812 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1813 origActivity = ComponentName.unflattenFromString(attrValue);
1814 } else if (ATTR_AFFINITY.equals(attrName)) {
1815 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001816 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1817 rootAffinity = attrValue;
1818 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001819 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001820 rootHasReset = Boolean.parseBoolean(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001821 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001822 autoRemoveRecents = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001823 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001824 askedCompatMode = Boolean.parseBoolean(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001825 } else if (ATTR_USERID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001826 userId = Integer.parseInt(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001827 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001828 userSetupComplete = Boolean.parseBoolean(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001829 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001830 effectiveUid = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001831 } else if (ATTR_TASKTYPE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001832 taskType = Integer.parseInt(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001833 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001834 firstActiveTime = Long.parseLong(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001835 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001836 lastActiveTime = Long.parseLong(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001837 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1838 lastDescription = attrValue;
1839 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001840 lastTimeOnTop = Long.parseLong(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001841 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001842 neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001843 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1844 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001845 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1846 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001847 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001848 taskAffiliation = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001849 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001850 prevTaskId = Integer.parseInt(attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001851 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001852 nextTaskId = Integer.parseInt(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001853 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001854 taskAffiliationColor = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001855 } else if (ATTR_CALLING_UID.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001856 callingUid = Integer.parseInt(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001857 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1858 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001859 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01001860 resizeMode = Integer.parseInt(attrValue);
Winson Chungd3395382016-12-13 11:49:09 -08001861 } else if (ATTR_SUPPORTS_PICTURE_IN_PICTURE.equals(attrName)) {
1862 supportsPictureInPicture = Boolean.parseBoolean(attrValue);
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001863 } else if (ATTR_PRIVILEGED.equals(attrName)) {
Tobias Thierer28532d02016-04-21 14:52:10 +01001864 privileged = Boolean.parseBoolean(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001865 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001866 bounds = Rect.unflattenFromString(attrValue);
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001867 } else if (ATTR_MIN_WIDTH.equals(attrName)) {
1868 minWidth = Integer.parseInt(attrValue);
1869 } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
1870 minHeight = Integer.parseInt(attrValue);
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001871 } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
1872 persistTaskVersion = Integer.parseInt(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001873 } else {
1874 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1875 }
1876 }
1877
1878 int event;
1879 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001880 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001881 if (event == XmlPullParser.START_TAG) {
1882 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001883 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1884 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001885 if (TAG_AFFINITYINTENT.equals(name)) {
1886 affinityIntent = Intent.restoreFromXml(in);
1887 } else if (TAG_INTENT.equals(name)) {
1888 intent = Intent.restoreFromXml(in);
1889 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001890 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001891 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1892 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001893 if (activity != null) {
1894 activities.add(activity);
1895 }
1896 } else {
1897 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1898 XmlUtils.skipCurrentTag(in);
1899 }
1900 }
1901 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001902 if (!hasRootAffinity) {
1903 rootAffinity = affinity;
1904 } else if ("@".equals(rootAffinity)) {
1905 rootAffinity = null;
1906 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001907 if (effectiveUid <= 0) {
1908 Intent checkIntent = intent != null ? intent : affinityIntent;
1909 effectiveUid = 0;
1910 if (checkIntent != null) {
1911 IPackageManager pm = AppGlobals.getPackageManager();
1912 try {
1913 ApplicationInfo ai = pm.getApplicationInfo(
1914 checkIntent.getComponent().getPackageName(),
Amith Yamasani0d1fd8d2016-10-12 14:21:51 -07001915 PackageManager.MATCH_UNINSTALLED_PACKAGES
1916 | PackageManager.MATCH_DISABLED_COMPONENTS, userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001917 if (ai != null) {
1918 effectiveUid = ai.uid;
1919 }
1920 } catch (RemoteException e) {
1921 }
1922 }
1923 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1924 + ": effectiveUid=" + effectiveUid);
1925 }
1926
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001927 if (persistTaskVersion < 1) {
1928 // We need to convert the resize mode of home activities saved before version one if
1929 // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
1930 // since we didn't have that differentiation before version 1 and the system didn't
1931 // resize home activities before then.
1932 if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
1933 resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
1934 }
Winson Chungd3395382016-12-13 11:49:09 -08001935 } else {
1936 // This activity has previously marked itself explicitly as both resizeable and
1937 // supporting picture-in-picture. Since there is no longer a requirement for
1938 // picture-in-picture activities to be resizeable, we can mark this simply as
1939 // resizeable and supporting picture-in-picture separately.
1940 if (resizeMode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED) {
1941 resizeMode = RESIZE_MODE_RESIZEABLE;
1942 supportsPictureInPicture = true;
1943 }
Wale Ogunwale625ed0c2016-10-18 08:50:31 -07001944 }
1945
Winson Chung36f3f032016-09-08 23:29:43 +00001946 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001947 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001948 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1949 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001950 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Winson Chungd3395382016-12-13 11:49:09 -08001951 taskAffiliationColor, callingUid, callingPackage, resizeMode,
1952 supportsPictureInPicture, privileged, realActivitySuspended, userSetupComplete,
1953 minWidth, minHeight);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001954 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001955
1956 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Bryce Leeaf691c02017-03-20 14:20:22 -07001957 activities.get(activityNdx).setTask(task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001958 }
1959
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001960 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001961 return task;
1962 }
1963
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001964 private void adjustForMinimalTaskDimensions(Rect bounds) {
1965 if (bounds == null) {
1966 return;
1967 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001968 int minWidth = mMinWidth;
1969 int minHeight = mMinHeight;
Robert Carr9c5867d2016-03-10 15:52:46 -08001970 // If the task has no requested minimal size, we'd like to enforce a minimal size
1971 // so that the user can not render the task too small to manipulate. We don't need
1972 // to do this for the pinned stack as the bounds are controlled by the system.
Andrii Kulian02b7a832016-10-06 23:11:56 -07001973 if (getStackId() != PINNED_STACK_ID) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001974 if (minWidth == INVALID_MIN_SIZE) {
1975 minWidth = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001976 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001977 if (minHeight == INVALID_MIN_SIZE) {
1978 minHeight = mService.mStackSupervisor.mDefaultMinSizeOfResizeableTask;
Andrii Kulian2e751b82016-03-16 16:59:32 -07001979 }
Robert Carr9c5867d2016-03-10 15:52:46 -08001980 }
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001981 final boolean adjustWidth = minWidth > bounds.width();
1982 final boolean adjustHeight = minHeight > bounds.height();
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001983 if (!(adjustWidth || adjustHeight)) {
1984 return;
1985 }
1986
1987 if (adjustWidth) {
1988 if (mBounds != null && bounds.right == mBounds.right) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001989 bounds.left = bounds.right - minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001990 } else {
1991 // Either left bounds match, or neither match, or the previous bounds were
1992 // fullscreen and we default to keeping left.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001993 bounds.right = bounds.left + minWidth;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001994 }
1995 }
1996 if (adjustHeight) {
1997 if (mBounds != null && bounds.bottom == mBounds.bottom) {
Andrii Kulianf66a83d2016-05-17 12:17:44 -07001998 bounds.top = bounds.bottom - minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001999 } else {
2000 // Either top bounds match, or neither match, or the previous bounds were
2001 // fullscreen and we default to keeping top.
Andrii Kulianf66a83d2016-05-17 12:17:44 -07002002 bounds.bottom = bounds.top + minHeight;
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002003 }
2004 }
2005 }
2006
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002007 /**
Winson Chung5af42fc2017-03-24 17:11:33 -07002008 * @return a new Configuration for this Task, given the provided {@param bounds} and
2009 * {@param insetBounds}.
2010 */
2011 Configuration computeNewOverrideConfigurationForBounds(Rect bounds, Rect insetBounds) {
2012 // Compute a new override configuration for the given bounds, if fullscreen bounds
2013 // (bounds == null), then leave the override config unset
2014 final Configuration newOverrideConfig = new Configuration();
2015 if (bounds != null) {
2016 newOverrideConfig.setTo(getOverrideConfiguration());
2017 mTmpRect.set(bounds);
2018 adjustForMinimalTaskDimensions(mTmpRect);
2019 computeOverrideConfiguration(newOverrideConfig, mTmpRect, insetBounds,
2020 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
2021 }
2022
2023 return newOverrideConfig;
2024 }
2025
2026 /**
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002027 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002028 * @param bounds The bounds of the task.
Andrii Kulian8072d112016-09-16 11:11:01 -07002029 * @return True if the override configuration was updated.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002030 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002031 boolean updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08002032 return updateOverrideConfiguration(bounds, null /* insetBounds */);
2033 }
2034
2035 /**
2036 * Update task's override configuration based on the bounds.
2037 * @param bounds The bounds of the task.
2038 * @param insetBounds The bounds used to calculate the system insets, which is used here to
2039 * subtract the navigation bar/status bar size from the screen size reported
2040 * to the application. See {@link IActivityManager#resizeDockedStack}.
Andrii Kulian8072d112016-09-16 11:11:01 -07002041 * @return True if the override configuration was updated.
Jorim Jaggi0a932142016-02-01 17:42:25 -08002042 */
Andrii Kulian8072d112016-09-16 11:11:01 -07002043 boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002044 if (Objects.equals(mBounds, bounds)) {
Andrii Kulian8072d112016-09-16 11:11:01 -07002045 return false;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002046 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002047 mTmpConfig.setTo(getOverrideConfiguration());
Wale Ogunwale5f986092015-12-04 15:35:38 -08002048 final boolean oldFullscreen = mFullscreen;
Andrii Kulian1779e612016-10-12 21:58:25 -07002049 final Configuration newConfig = getOverrideConfiguration();
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07002050
2051 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002052 if (mFullscreen) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002053 if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002054 mLastNonFullscreenBounds = mBounds;
2055 }
2056 mBounds = null;
Andrii Kulian1779e612016-10-12 21:58:25 -07002057 newConfig.unset();
Wale Ogunwale706ed792015-08-02 10:29:44 -07002058 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002059 mTmpRect.set(bounds);
2060 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002061 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002062 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002063 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08002064 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08002065 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002066 if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07002067 mLastNonFullscreenBounds = mBounds;
2068 }
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002069 computeOverrideConfiguration(newConfig, mTmpRect, insetBounds,
Andrii Kuliandaea3572016-04-08 13:20:51 -07002070 mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
Wale Ogunwale706ed792015-08-02 10:29:44 -07002071 }
Andrii Kulian1779e612016-10-12 21:58:25 -07002072 onOverrideConfigurationChanged(newConfig);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002073
2074 if (mFullscreen != oldFullscreen) {
Winson Chung5af42fc2017-03-24 17:11:33 -07002075 mService.mStackSupervisor.scheduleUpdateMultiWindowMode(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08002076 }
2077
Andrii Kulian1779e612016-10-12 21:58:25 -07002078 return !mTmpConfig.equals(newConfig);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002079 }
2080
Andrii Kulian1779e612016-10-12 21:58:25 -07002081 /** Clears passed config and fills it with new override values. */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002082 // TODO(b/36505427): TaskRecord.computeOverrideConfiguration() is a utility method that doesn't
2083 // depend on task or stacks, but uses those object to get the display to base the calculation
2084 // on. Probably best to centralize calculations like this in ConfigurationContainer.
2085 void computeOverrideConfiguration(Configuration config, Rect bounds, Rect insetBounds,
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002086 boolean overrideWidth, boolean overrideHeight) {
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002087 mTmpNonDecorBounds.set(bounds);
2088 mTmpStableBounds.set(bounds);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002089
Andrii Kulian1779e612016-10-12 21:58:25 -07002090 config.unset();
Winson Chungbdc646f2017-02-13 12:12:22 -08002091 final Configuration parentConfig = getParent().getConfiguration();
Bryce Lee7566d762017-03-30 09:34:15 -07002092
Andrii Kulian1779e612016-10-12 21:58:25 -07002093 final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002094
Winson Chungbdc646f2017-02-13 12:12:22 -08002095 if (mStack != null) {
2096 final StackWindowController stackController = mStack.getWindowContainerController();
2097 stackController.adjustConfigurationForBounds(bounds, insetBounds,
2098 mTmpNonDecorBounds, mTmpStableBounds, overrideWidth, overrideHeight, density,
2099 config, parentConfig);
2100 } else {
Bryce Lee7566d762017-03-30 09:34:15 -07002101 throw new IllegalArgumentException("Expected stack when calculating override config");
Winson Chungbdc646f2017-02-13 12:12:22 -08002102 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002103
Winson Chung60c1aba2017-03-14 17:47:42 -07002104 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
2105 ? Configuration.ORIENTATION_PORTRAIT
2106 : Configuration.ORIENTATION_LANDSCAPE;
2107
Jorim Jaggi85639432016-05-06 17:27:55 -07002108 // For calculating screen layout, we need to use the non-decor inset screen area for the
2109 // calculation for compatibility reasons, i.e. screen area without system bars that could
2110 // never go away in Honeycomb.
Winson Chungbdc646f2017-02-13 12:12:22 -08002111 final int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density);
2112 final int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density);
Andrii Kulian1779e612016-10-12 21:58:25 -07002113 // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
2114 // calculation with partial default.
2115 final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08002116 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
Andrii Kulian1779e612016-10-12 21:58:25 -07002117 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi85639432016-05-06 17:27:55 -07002118 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
2119
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08002120 }
2121
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002122 Rect updateOverrideConfigurationFromLaunchBounds() {
2123 final Rect bounds = validateBounds(getLaunchBounds());
2124 updateOverrideConfiguration(bounds);
Andrii Kulian73336d812016-03-24 12:56:08 -07002125 if (bounds != null) {
2126 bounds.set(mBounds);
2127 }
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08002128 return bounds;
2129 }
2130
2131 static Rect validateBounds(Rect bounds) {
2132 if (bounds != null && bounds.isEmpty()) {
2133 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
2134 return null;
2135 }
2136 return bounds;
2137 }
2138
Wale Ogunwale935e5022015-11-10 12:36:10 -08002139 /** Updates the task's bounds and override configuration to match what is expected for the
2140 * input stack. */
2141 void updateOverrideConfigurationForStack(ActivityStack inStack) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002142 if (mStack != null && mStack == inStack) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002143 return;
2144 }
2145
2146 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002147 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08002148 throw new IllegalArgumentException("Can not position non-resizeable task="
2149 + this + " in stack=" + inStack);
2150 }
2151 if (mBounds != null) {
2152 return;
2153 }
2154 if (mLastNonFullscreenBounds != null) {
2155 updateOverrideConfiguration(mLastNonFullscreenBounds);
2156 } else {
2157 inStack.layoutTaskInStack(this, null);
2158 }
2159 } else {
2160 updateOverrideConfiguration(inStack.mBounds);
2161 }
2162 }
2163
Chong Zhang0fa656b2015-08-31 15:17:21 -07002164 /**
2165 * Returns the correct stack to use based on task type and currently set bounds,
2166 * regardless of the focused stack and current stack association of the task.
2167 * The task will be moved (and stack focus changed) later if necessary.
2168 */
2169 int getLaunchStackId() {
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002170 if (isRecentsTask()) {
2171 return RECENTS_STACK_ID;
2172 }
2173 if (isHomeTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002174 return HOME_STACK_ID;
2175 }
Winson Chung83471632016-12-13 11:02:12 -08002176 if (isAssistantTask()) {
2177 return ASSISTANT_STACK_ID;
2178 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07002179 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07002180 return FREEFORM_WORKSPACE_STACK_ID;
2181 }
2182 return FULLSCREEN_WORKSPACE_STACK_ID;
2183 }
2184
2185 /** Returns the bounds that should be used to launch this task. */
2186 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08002187 // If we're over lockscreen, forget about stack bounds and use fullscreen.
Jorim Jaggife762342016-10-13 14:33:27 +02002188 if (mService.mStackSupervisor.mKeyguardController.isKeyguardShowing()) {
Chong Zhang75b37202015-12-04 14:16:36 -08002189 return null;
2190 }
2191
Andrii Kulian02b7a832016-10-06 23:11:56 -07002192 if (mStack == null) {
Chong Zhang7d5f5102016-01-13 10:29:24 -08002193 return null;
2194 }
2195
Andrii Kulian02b7a832016-10-06 23:11:56 -07002196 final int stackId = mStack.mStackId;
Chong Zhang7d5f5102016-01-13 10:29:24 -08002197 if (stackId == HOME_STACK_ID
Matthew Ngae1ff4f2016-11-10 15:49:14 -08002198 || stackId == RECENTS_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -08002199 || stackId == ASSISTANT_STACK_ID
Chong Zhang7d5f5102016-01-13 10:29:24 -08002200 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002201 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002202 return isResizeable() ? mStack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07002203 } else if (!StackId.persistTaskBounds(stackId)) {
Andrii Kulian02b7a832016-10-06 23:11:56 -07002204 return mStack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07002205 }
2206 return mLastNonFullscreenBounds;
2207 }
2208
Wale Ogunwale39381972015-12-17 17:15:29 -08002209 boolean canMatchRootAffinity() {
2210 // We don't allow root affinity matching on the pinned stack as no other task should
2211 // be launching in it based on affinity.
Andrii Kulian02b7a832016-10-06 23:11:56 -07002212 return rootAffinity != null && getStackId() != PINNED_STACK_ID;
Wale Ogunwale39381972015-12-17 17:15:29 -08002213 }
2214
Jorim Jaggi8b702ed2017-01-20 16:59:03 +01002215 void addStartingWindowsForVisibleActivities(boolean taskSwitch) {
2216 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
2217 final ActivityRecord r = mActivities.get(activityNdx);
2218 if (r.visible) {
2219 r.showStartingWindow(null /* prev */, false /* newTask */, taskSwitch);
2220 }
2221 }
2222 }
2223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002224 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002225 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07002226 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
2227 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Suprabh Shukla7745c142016-03-07 18:21:10 -08002228 pw.print(" mUserSetupComplete="); pw.print(mUserSetupComplete);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002229 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07002230 if (affinity != null || rootAffinity != null) {
2231 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
2232 if (affinity == null || !affinity.equals(rootAffinity)) {
2233 pw.print(" root="); pw.println(rootAffinity);
2234 } else {
2235 pw.println();
2236 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002237 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07002238 if (voiceSession != null || voiceInteractor != null) {
2239 pw.print(prefix); pw.print("VOICE: session=0x");
2240 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
2241 pw.print(" interactor=0x");
2242 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
2243 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002244 if (intent != null) {
2245 StringBuilder sb = new StringBuilder(128);
2246 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002247 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002248 sb.append('}');
2249 pw.println(sb.toString());
2250 }
2251 if (affinityIntent != null) {
2252 StringBuilder sb = new StringBuilder(128);
2253 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08002254 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002255 sb.append('}');
2256 pw.println(sb.toString());
2257 }
2258 if (origActivity != null) {
2259 pw.print(prefix); pw.print("origActivity=");
2260 pw.println(origActivity.flattenToShortString());
2261 }
2262 if (realActivity != null) {
2263 pw.print(prefix); pw.print("realActivity=");
2264 pw.println(realActivity.flattenToShortString());
2265 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07002266 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
2267 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002268 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002269 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002270 pw.print(" numFullscreen="); pw.print(numFullscreen);
2271 pw.print(" taskType="); pw.print(taskType);
2272 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
2273 }
Craig Mautner432f64e2015-05-20 14:59:57 -07002274 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
2275 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002276 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
2277 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07002278 pw.print(" mReuseTask="); pw.print(mReuseTask);
2279 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002280 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08002281 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
2282 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
2283 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07002284 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
2285 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
2286 pw.print(" (");
2287 if (mPrevAffiliate == null) {
2288 pw.print("null");
2289 } else {
2290 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
2291 }
2292 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
2293 pw.print(" (");
2294 if (mNextAffiliate == null) {
2295 pw.print("null");
2296 } else {
2297 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
2298 }
2299 pw.println(")");
2300 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002301 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002302 if (!askedCompatMode || !inRecents || !isAvailable) {
2303 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
2304 pw.print(" inRecents="); pw.print(inRecents);
2305 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07002306 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002307 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002308 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
2309 if (lastDescription != null) {
2310 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
2311 }
Andrii Kulian02b7a832016-10-06 23:11:56 -07002312 pw.print(prefix); pw.print("stackId="); pw.println(getStackId());
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002313 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
2314 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
Winson Chungd3395382016-12-13 11:49:09 -08002315 pw.print(" mSupportsPictureInPicture=" + mSupportsPictureInPicture);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002316 pw.print(" isResizeable=" + isResizeable());
Winson Chung36f3f032016-09-08 23:29:43 +00002317 pw.print(" firstActiveTime=" + lastActiveTime);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002318 pw.print(" lastActiveTime=" + lastActiveTime);
2319 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 }
2321
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002322 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002324 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002325 if (stringName != null) {
2326 sb.append(stringName);
2327 sb.append(" U=");
2328 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08002329 sb.append(" StackId=");
Andrii Kulian02b7a832016-10-06 23:11:56 -07002330 sb.append(getStackId());
Craig Mautnerde4ef022013-04-07 19:01:33 -07002331 sb.append(" sz=");
2332 sb.append(mActivities.size());
2333 sb.append('}');
2334 return sb.toString();
2335 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002336 sb.append("TaskRecord{");
2337 sb.append(Integer.toHexString(System.identityHashCode(this)));
2338 sb.append(" #");
2339 sb.append(taskId);
2340 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002341 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002342 sb.append(affinity);
2343 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002344 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002345 sb.append(intent.getComponent().flattenToShortString());
2346 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08002347 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002348 sb.append(affinityIntent.getComponent().flattenToShortString());
2349 } else {
2350 sb.append(" ??");
2351 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002352 stringName = sb.toString();
2353 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 }
2355}