blob: 62275a98aba1697e896888db22f7b624b3c4c569 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.am;
18
Jorim Jaggi0a932142016-02-01 17:42:25 -080019import android.annotation.Nullable;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070020import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070021import android.app.ActivityManager;
Wale Ogunwale3797c222015-10-27 14:21:58 -070022import android.app.ActivityManager.StackId;
Craig Mautner648f69b2014-09-18 14:16:26 -070023import android.app.ActivityManager.TaskDescription;
Wale Ogunwaleff3c66c2015-11-18 19:22:49 -080024import android.app.ActivityManager.TaskThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -080025import android.app.ActivityManager.TaskThumbnailInfo;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070026import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070027import android.app.AppGlobals;
Jorim Jaggi0a932142016-02-01 17:42:25 -080028import android.app.IActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.ComponentName;
30import android.content.Intent;
31import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070032import android.content.pm.ApplicationInfo;
33import android.content.pm.IPackageManager;
34import android.content.pm.PackageManager;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070035import android.content.res.Configuration;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070036import android.graphics.Bitmap;
Winsonc809cbb2015-11-02 12:06:15 -080037import android.graphics.Point;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070038import android.graphics.Rect;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070039import android.os.Debug;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070040import android.os.ParcelFileDescriptor;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070041import android.os.RemoteException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070042import android.os.UserHandle;
Dianne Hackborn91097de2014-04-04 18:02:06 -070043import android.service.voice.IVoiceInteractionSession;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070044import android.util.DisplayMetrics;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070045import android.util.Slog;
Suprabh Shukla23593142015-11-03 17:31:15 -080046
Dianne Hackborn91097de2014-04-04 18:02:06 -070047import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070048import com.android.internal.util.XmlUtils;
Suprabh Shukla23593142015-11-03 17:31:15 -080049
Craig Mautner21d24a22014-04-23 11:45:37 -070050import org.xmlpull.v1.XmlPullParser;
51import org.xmlpull.v1.XmlPullParserException;
52import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
Craig Mautnerc0ffce52014-07-01 12:38:52 -070054import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070055import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080057import java.util.ArrayList;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070058import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
Jorim Jaggi0a932142016-02-01 17:42:25 -080060import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
61import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
62import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
63import static android.app.ActivityManager.StackId.HOME_STACK_ID;
64import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
65import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
66import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
67import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
68import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
69import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
70import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
71import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
72import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Wale Ogunwaled829d362016-02-10 19:24:49 -080073import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
Jorim Jaggi0a932142016-02-01 17:42:25 -080074import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
75import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
76import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
77import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
78import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
79import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
80import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
81import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
82import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
83import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
84import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
85import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
86import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
87import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN;
88import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
89import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
90import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
91
Craig Mautnerc0ffce52014-07-01 12:38:52 -070092final class TaskRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080093 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
Wale Ogunwale0fc365c2015-05-25 19:35:42 -070094 private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070095 private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
Craig Mautnere0570202015-05-13 13:06:11 -070096 private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
Wale Ogunwaleee006da2015-03-30 14:49:25 -070097 private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080098
Wale Ogunwale18795a22014-12-03 11:38:33 -080099 static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -0700100 private static final String TAG_INTENT = "intent";
101 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800102 static final String ATTR_REALACTIVITY = "real_activity";
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000103 static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
Craig Mautner21d24a22014-04-23 11:45:37 -0700104 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700105 private static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700106 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -0700107 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -0700108 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -0700109 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -0700110 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
111 private static final String ATTR_USERID = "user_id";
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800112 private static final String ATTR_USER_SETUP_COMPLETE = "user_setup_complete";
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700113 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -0700114 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -0700115 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -0700116 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -0700117 private static final String ATTR_LASTDESCRIPTION = "last_description";
118 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700119 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale18795a22014-12-03 11:38:33 -0800120 static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -0700121 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
122 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -0700123 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700124 private static final String ATTR_CALLING_UID = "calling_uid";
125 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800126 private static final String ATTR_RESIZE_MODE = "resize_mode";
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700127 private static final String ATTR_PRIVILEGED = "privileged";
Wale Ogunwale706ed792015-08-02 10:29:44 -0700128 private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
Craig Mautner21d24a22014-04-23 11:45:37 -0700129
130 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
131
Wale Ogunwale18795a22014-12-03 11:38:33 -0800132 static final int INVALID_TASK_ID = -1;
133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -0700135 String affinity; // The affinity name for this task, or null; may change identity.
136 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -0700137 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
138 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 Intent intent; // The original intent that started the task.
140 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700141 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 ComponentName origActivity; // The non-alias activity component of the intent.
143 ComponentName realActivity; // The actual activity component that started the task.
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +0000144 boolean realActivitySuspended; // True if the actual activity component that started the
145 // task is suspended.
Winson Chungffa2ec62014-07-03 15:54:42 -0700146 long firstActiveTime; // First time this task was active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700148 boolean inRecents; // Actually in the recents list?
149 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 boolean rootWasReset; // True if the intent at the root of the task had
151 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700152 boolean autoRemoveRecents; // If true, we should automatically remove the task from
153 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700154 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700155 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 -0800156
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700157 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700158 int userId; // user for which this task was created
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800159 boolean mUserSetupComplete; // The user set-up is complete as of the last time the task activity
160 // was changed.
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800161
162 int numFullscreen; // Number of fullscreen activities.
163
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800164 int mResizeMode; // The resize mode of this task and its activities.
165 // Based on the {@link ActivityInfo#resizeMode} of the root activity.
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800166 boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
167 // changes on a temporary basis.
Craig Mautner15df08a2015-04-01 12:17:18 -0700168 int mLockTaskMode; // Which tasklock mode to launch this task in. One of
169 // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700170 private boolean mPrivileged; // The root activity application of this task holds
171 // privileged permissions.
172
Craig Mautner15df08a2015-04-01 12:17:18 -0700173 /** Can't be put in lockTask mode. */
174 final static int LOCK_TASK_AUTH_DONT_LOCK = 0;
Benjamin Franz469dd582015-06-09 14:24:36 +0100175 /** Can enter app pinning with user approval. Can never start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700176 final static int LOCK_TASK_AUTH_PINNABLE = 1;
177 /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */
178 final static int LOCK_TASK_AUTH_LAUNCHABLE = 2;
Benjamin Franz469dd582015-06-09 14:24:36 +0100179 /** Can enter lockTask without user approval. Can start over existing lockTask task. */
Craig Mautner15df08a2015-04-01 12:17:18 -0700180 final static int LOCK_TASK_AUTH_WHITELISTED = 3;
Benjamin Franz469dd582015-06-09 14:24:36 +0100181 /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing
182 * lockTask task. */
183 final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4;
Craig Mautner15df08a2015-04-01 12:17:18 -0700184 int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE;
185
186 int mLockTaskUid = -1; // The uid of the application that called startLockTask().
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800187
Winson Chung03a9bae2014-05-02 09:56:12 -0700188 // This represents the last resolved activity values for this task
189 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700190 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700191
Craig Mautnerd2328952013-03-05 12:46:26 -0800192 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700193 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800194
Craig Mautnerd2328952013-03-05 12:46:26 -0800195 /** Current stack */
196 ActivityStack stack;
197
Craig Mautner2c1faed2013-07-23 12:56:02 -0700198 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700199 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700200
Craig Mautner21d24a22014-04-23 11:45:37 -0700201 /** Takes on same value as first root activity */
202 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700203 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700204
205 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
206 * determining the order when restoring. Sign indicates whether last task movement was to front
207 * (positive) or back (negative). Absolute value indicates time. */
208 long mLastTimeMoved = System.currentTimeMillis();
209
Craig Mautner84984fa2014-06-19 11:19:20 -0700210 /** Indication of what to run next when task exits. Use ActivityRecord types.
211 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
212 * task stack. */
213 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700214
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700215 /** If original intent did not allow relinquishing task identity, save that information */
216 boolean mNeverRelinquishIdentity = true;
217
Craig Mautner362449a2014-06-20 14:04:39 -0700218 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
219 // do not want to delete the stack when the task goes empty.
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800220 private boolean mReuseTask = false;
Craig Mautner362449a2014-06-20 14:04:39 -0700221
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700222 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700223 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700224 private final String mFilename;
Winsonc809cbb2015-11-02 12:06:15 -0800225 private TaskThumbnailInfo mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700226 CharSequence lastDescription; // Last description captured for this item.
227
Craig Mautnera228ae92014-07-09 05:44:55 -0700228 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700229 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700230 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800231 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700232 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800233 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700234
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700235 // For relaunching the task from recents as though it was launched by the original launcher.
236 int mCallingUid;
237 String mCallingPackage;
238
Craig Mautner21d24a22014-04-23 11:45:37 -0700239 final ActivityManagerService mService;
240
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700241 // Whether or not this task covers the entire screen; by default tasks are fullscreen.
242 boolean mFullscreen = true;
243
244 // Bounds of the Task. null for fullscreen tasks.
245 Rect mBounds = null;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -0800246 private final Rect mTmpStableBounds = new Rect();
247 private final Rect mTmpNonDecorBounds = new Rect();
Wale Ogunwale9a08f822016-02-17 19:03:58 -0800248 private final Rect mTmpRect = new Rect();
Jorim Jaggi0a932142016-02-01 17:42:25 -0800249 private final Rect mTmpRect2 = new Rect();
250
Wale Ogunwale706ed792015-08-02 10:29:44 -0700251 // Last non-fullscreen bounds the task was launched in or resized to.
252 // The information is persisted and used to determine the appropriate stack to launch the
253 // task into on restore.
254 Rect mLastNonFullscreenBounds = null;
Filip Gruszczynskid2f1d942015-10-14 15:10:12 -0700255 // Minimal size for width/height of this task when it's resizeable. -1 means it should use the
256 // default minimal size.
257 final int mMinimalSize;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700258
Chong Zhangfdcc4d42015-10-14 16:50:12 -0700259 // Ranking (from top) of this task among all visible tasks. (-1 means it's not visible)
260 // This number will be assigned when we evaluate OOM scores for all visible tasks.
261 int mLayerRank = -1;
262
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700263 Configuration mOverrideConfig = Configuration.EMPTY;
264
Craig Mautner21d24a22014-04-23 11:45:37 -0700265 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Dianne Hackborn91097de2014-04-04 18:02:06 -0700266 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700267 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700268 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
269 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800270 userId = UserHandle.getUserId(info.applicationInfo.uid);
271 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800272 mLastThumbnailInfo = new TaskThumbnailInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700274 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700275 voiceSession = _voiceSession;
276 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700277 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800278 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700279 mCallingUid = info.applicationInfo.uid;
280 mCallingPackage = info.packageName;
Martijn Coenend4a69702014-06-30 11:12:17 -0700281 setIntent(_intent, info);
Filip Gruszczynskid2f1d942015-10-14 15:10:12 -0700282 mMinimalSize = info != null && info.layout != null ? info.layout.minimalSize : -1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700283 }
284
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700285 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Winsonc809cbb2015-11-02 12:06:15 -0800286 TaskDescription _taskDescription, TaskThumbnailInfo thumbnailInfo) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700287 mService = service;
288 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
289 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800290 userId = UserHandle.getUserId(info.applicationInfo.uid);
291 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800292 mLastThumbnailInfo = thumbnailInfo;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700293 taskId = _taskId;
294 mAffiliatedTaskId = _taskId;
295 voiceSession = null;
296 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700297 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800298 mActivities = new ArrayList<>();
Craig Mautner15df08a2015-04-01 12:17:18 -0700299 mCallingUid = info.applicationInfo.uid;
300 mCallingPackage = info.packageName;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700301 setIntent(_intent, info);
302
303 taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
304 isPersistable = true;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700305 // Clamp to [1, max].
306 maxRecents = Math.min(Math.max(info.maxRecents, 1),
307 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700308
309 taskType = APPLICATION_ACTIVITY_TYPE;
310 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700311 lastTaskDescription = _taskDescription;
Filip Gruszczynskid2f1d942015-10-14 15:10:12 -0700312 mMinimalSize = info != null && info.layout != null ? info.layout.minimalSize : -1;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700313 }
314
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800315 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
316 Intent _affinityIntent, String _affinity, String _rootAffinity,
317 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
318 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
319 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
320 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
321 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
Winsonc809cbb2015-11-02 12:06:15 -0800322 TaskThumbnailInfo lastThumbnailInfo, int taskAffiliation, int prevTaskId,
323 int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800324 int resizeMode, boolean privileged, boolean _realActivitySuspended,
325 boolean userSetupComplete) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700326 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700327 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
328 TaskPersister.IMAGE_EXTENSION;
Suprabh Shukla23593142015-11-03 17:31:15 -0800329 mLastThumbnailFile = new File(TaskPersister.getUserImagesDir(_userId), mFilename);
Winsonc809cbb2015-11-02 12:06:15 -0800330 mLastThumbnailInfo = lastThumbnailInfo;
Craig Mautner21d24a22014-04-23 11:45:37 -0700331 taskId = _taskId;
332 intent = _intent;
333 affinityIntent = _affinityIntent;
334 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800335 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700336 voiceSession = null;
337 voiceInteractor = null;
338 realActivity = _realActivity;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800339 realActivitySuspended = _realActivitySuspended;
Craig Mautner21d24a22014-04-23 11:45:37 -0700340 origActivity = _origActivity;
341 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700342 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700343 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700344 askedCompatMode = _askedCompatMode;
345 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700346 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700347 userId = _userId;
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800348 mUserSetupComplete = userSetupComplete;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700349 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700350 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700351 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700352 lastDescription = _lastDescription;
353 mActivities = activities;
354 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700355 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700356 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700357 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700358 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700359 mPrevAffiliateTaskId = prevTaskId;
360 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700361 mCallingUid = callingUid;
362 mCallingPackage = callingPackage;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800363 mResizeMode = resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700364 mPrivileged = privileged;
Suprabh Shukla74f9f162015-11-06 15:39:42 -0800365 ActivityInfo info = (mActivities.size() > 0) ? mActivities.get(0).info : null;
Filip Gruszczynskid2f1d942015-10-14 15:10:12 -0700366 mMinimalSize = info != null && info.layout != null ? info.layout.minimalSize : -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 }
368
369 void touchActiveTime() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700370 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700371 if (firstActiveTime == 0) {
372 firstActiveTime = lastActiveTime;
373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 long getInactiveDuration() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700377 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700379
Winson Chungfee26772014-08-05 12:21:52 -0700380 /** Sets the original intent, and the calling uid and package. */
381 void setIntent(ActivityRecord r) {
Winson Chungfee26772014-08-05 12:21:52 -0700382 mCallingUid = r.launchedFromUid;
383 mCallingPackage = r.launchedFromPackage;
Craig Mautner15df08a2015-04-01 12:17:18 -0700384 setIntent(r.intent, r.info);
Winson Chungfee26772014-08-05 12:21:52 -0700385 }
386
387 /** Sets the original intent, _without_ updating the calling uid or package. */
388 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700389 if (intent == null) {
390 mNeverRelinquishIdentity =
391 (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0;
392 } else if (mNeverRelinquishIdentity) {
393 return;
394 }
395
396 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700397 if (intent == null) {
398 // If this task already has an intent associated with it, don't set the root
399 // affinity -- we don't want it changing after initially set, but the initially
400 // set value may be null.
401 rootAffinity = affinity;
402 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700403 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700404 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800407 if (_intent != null) {
408 // If this Intent has a selector, we want to clear it for the
409 // recent task since it is not relevant if the user later wants
410 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700411 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800412 _intent = new Intent(_intent);
413 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700414 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800415 }
416 }
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700417 if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 intent = _intent;
419 realActivity = _intent != null ? _intent.getComponent() : null;
420 origActivity = null;
421 } else {
422 ComponentName targetComponent = new ComponentName(
423 info.packageName, info.targetActivity);
424 if (_intent != null) {
425 Intent targetIntent = new Intent(_intent);
426 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800427 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700428 targetIntent.setSourceBounds(null);
Wale Ogunwaleee006da2015-03-30 14:49:25 -0700429 if (DEBUG_TASKS) Slog.v(TAG_TASKS,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700430 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 intent = targetIntent;
432 realActivity = targetComponent;
433 origActivity = _intent.getComponent();
434 } else {
435 intent = null;
436 realActivity = targetComponent;
437 origActivity = new ComponentName(info.packageName, info.name);
438 }
439 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700440
Craig Mautner47b20ba2014-09-17 17:23:44 -0700441 final int intentFlags = intent == null ? 0 : intent.getFlags();
442 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 // Once we are set to an Intent with this flag, we count this
444 // task as having a true root activity.
445 rootWasReset = true;
446 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700447
Dianne Hackborn09233282014-04-30 11:33:59 -0700448 userId = UserHandle.getUserId(info.applicationInfo.uid);
Wale Ogunwalef80170f2016-02-04 15:12:29 -0800449 mUserSetupComplete = mService.mUserController.isUserSetupCompleteLocked(userId);
Craig Mautner41db4a72014-05-07 17:20:56 -0700450 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700451 // If the activity itself has requested auto-remove, then just always do it.
452 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700453 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
454 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700455 // If the caller has not asked for the document to be retained, then we may
456 // want to turn on auto-remove, depending on whether the target has set its
457 // own document launch mode.
458 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
459 autoRemoveRecents = false;
460 } else {
461 autoRemoveRecents = true;
462 }
463 } else {
464 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700465 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800466 mResizeMode = info.resizeMode;
Craig Mautner15df08a2015-04-01 12:17:18 -0700467 mLockTaskMode = info.lockTaskLaunchMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -0700468 mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
Craig Mautner15df08a2015-04-01 12:17:18 -0700469 setLockTaskAuth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800471
Wale Ogunwale715a1dc2016-02-29 14:27:32 -0800472 /**
473 * Return true if the input activity has the same intent resolution as the intent this task
474 * record is based on (normally the root activity intent).
475 */
476 boolean isSameIntentResolution(ActivityRecord r) {
477 final Intent intent = new Intent(r.intent);
478 // Correct the activity intent for aliasing. The task record intent will always be based on
479 // the real activity that will be launched not the alias, so we need to use an intent with
480 // the component name pointing to the real activity not the alias in the activity record.
481 intent.setComponent(r.realActivity);
482 return this.intent.filterEquals(intent);
483 }
484
Craig Mautner84984fa2014-06-19 11:19:20 -0700485 void setTaskToReturnTo(int taskToReturnTo) {
Wale Ogunwale673cbd22016-01-30 18:30:55 -0800486 mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE)
487 ? HOME_ACTIVITY_TYPE : taskToReturnTo;
Craig Mautner84984fa2014-06-19 11:19:20 -0700488 }
489
490 int getTaskToReturnTo() {
491 return mTaskToReturnTo;
492 }
493
Craig Mautnera228ae92014-07-09 05:44:55 -0700494 void setPrevAffiliate(TaskRecord prevAffiliate) {
495 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800496 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700497 }
498
499 void setNextAffiliate(TaskRecord nextAffiliate) {
500 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800501 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700502 }
503
504 // Close up recents linked list.
505 void closeRecentsChain() {
506 if (mPrevAffiliate != null) {
507 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
508 }
509 if (mNextAffiliate != null) {
510 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
511 }
512 setPrevAffiliate(null);
513 setNextAffiliate(null);
514 }
515
Winson Chung740c3ac2014-11-12 16:14:38 -0800516 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700517 disposeThumbnail();
518 closeRecentsChain();
519 if (inRecents) {
520 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800521 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700522 }
523 }
524
Craig Mautnera228ae92014-07-09 05:44:55 -0700525 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
526 closeRecentsChain();
527 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700528 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700529 // Find the end
530 while (taskToAffiliateWith.mNextAffiliate != null) {
531 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
532 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
533 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
534 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
535 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
536 nextRecents.setPrevAffiliate(null);
537 }
538 taskToAffiliateWith.setNextAffiliate(null);
539 break;
540 }
541 taskToAffiliateWith = nextRecents;
542 }
543 taskToAffiliateWith.setNextAffiliate(this);
544 setPrevAffiliate(taskToAffiliateWith);
545 setNextAffiliate(null);
546 }
547
Winson Chung096f36b2014-08-20 15:39:01 -0700548 /**
Winsonc809cbb2015-11-02 12:06:15 -0800549 * Sets the last thumbnail with the current task bounds and the system orientation.
Winson Chung096f36b2014-08-20 15:39:01 -0700550 * @return whether the thumbnail was set
551 */
Winsonc809cbb2015-11-02 12:06:15 -0800552 boolean setLastThumbnailLocked(Bitmap thumbnail) {
553 final Configuration serviceConfig = mService.mConfiguration;
554 int taskWidth = 0;
555 int taskHeight = 0;
556 if (mBounds != null) {
557 // Non-fullscreen tasks
558 taskWidth = mBounds.width();
559 taskHeight = mBounds.height();
560 } else if (stack != null) {
561 // Fullscreen tasks
562 final Point displaySize = new Point();
563 stack.getDisplaySize(displaySize);
564 taskWidth = displaySize.x;
565 taskHeight = displaySize.y;
566 } else {
567 Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
568 }
569 return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, serviceConfig.orientation);
570 }
571
572 /**
573 * Sets the last thumbnail with the current task bounds.
574 * @return whether the thumbnail was set
575 */
576 private boolean setLastThumbnailLocked(Bitmap thumbnail, int taskWidth, int taskHeight,
577 int screenOrientation) {
Winson Chung096f36b2014-08-20 15:39:01 -0700578 if (mLastThumbnail != thumbnail) {
579 mLastThumbnail = thumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800580 mLastThumbnailInfo.taskWidth = taskWidth;
581 mLastThumbnailInfo.taskHeight = taskHeight;
582 mLastThumbnailInfo.screenOrientation = screenOrientation;
Winson Chung096f36b2014-08-20 15:39:01 -0700583 if (thumbnail == null) {
584 if (mLastThumbnailFile != null) {
585 mLastThumbnailFile.delete();
586 }
587 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800588 mService.mRecentTasks.saveImage(thumbnail, mLastThumbnailFile.getAbsolutePath());
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700589 }
Winson Chung096f36b2014-08-20 15:39:01 -0700590 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700591 }
Winson Chung096f36b2014-08-20 15:39:01 -0700592 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700593 }
594
595 void getLastThumbnail(TaskThumbnail thumbs) {
596 thumbs.mainThumbnail = mLastThumbnail;
Winsonc809cbb2015-11-02 12:06:15 -0800597 thumbs.thumbnailInfo = mLastThumbnailInfo;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700598 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700599 if (mLastThumbnail == null) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800600 thumbs.mainThumbnail = mService.mRecentTasks.getImageFromWriteQueue(
Suprabh Shukla23593142015-11-03 17:31:15 -0800601 mLastThumbnailFile.getAbsolutePath());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700602 }
Winson Chung096f36b2014-08-20 15:39:01 -0700603 // Only load the thumbnail file if we don't have a thumbnail
604 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700605 try {
606 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
607 ParcelFileDescriptor.MODE_READ_ONLY);
608 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700609 }
610 }
611 }
612
Winsonc809cbb2015-11-02 12:06:15 -0800613 /**
614 * Removes in-memory thumbnail data when the max number of in-memory task thumbnails is reached.
615 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700616 void freeLastThumbnail() {
617 mLastThumbnail = null;
618 }
619
Winsonc809cbb2015-11-02 12:06:15 -0800620 /**
621 * Removes all associated thumbnail data when a task is removed or pruned from recents.
622 */
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700623 void disposeThumbnail() {
Winsonc6a2da02015-11-11 18:11:59 -0800624 mLastThumbnailInfo.reset();
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700625 mLastThumbnail = null;
626 lastDescription = null;
627 }
628
Winson Chung1147c402014-05-14 11:05:00 -0700629 /** Returns the intent for the root activity for this task */
630 Intent getBaseIntent() {
631 return intent != null ? intent : affinityIntent;
632 }
633
Winson Chung3b3f4642014-04-22 10:08:18 -0700634 /** Returns the first non-finishing activity from the root. */
635 ActivityRecord getRootActivity() {
636 for (int i = 0; i < mActivities.size(); i++) {
637 final ActivityRecord r = mActivities.get(i);
638 if (r.finishing) {
639 continue;
640 }
641 return r;
642 }
643 return null;
644 }
645
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800646 ActivityRecord getTopActivity() {
647 for (int i = mActivities.size() - 1; i >= 0; --i) {
648 final ActivityRecord r = mActivities.get(i);
649 if (r.finishing) {
650 continue;
651 }
652 return r;
653 }
654 return null;
655 }
656
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700657 ActivityRecord topRunningActivityLocked() {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700658 if (stack != null) {
659 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
660 ActivityRecord r = mActivities.get(activityNdx);
Filip Gruszczynski3e85ba22015-10-05 22:48:30 -0700661 if (!r.finishing && stack.okToShowLocked(r)) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700662 return r;
663 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700664 }
665 }
666 return null;
667 }
668
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800669 void setFrontOfTask() {
670 setFrontOfTask(null);
671 }
672
Craig Mautner3b475fe2013-12-16 15:58:31 -0800673 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800674 void setFrontOfTask(ActivityRecord newTop) {
675 // If a top candidate is suggested by the caller, go ahead and use it and mark all others
676 // as not front. This is needed in situations where the current front activity in the
677 // task isn't finished yet and we want to set the front to the activity moved to the front
678 // of the task.
679 boolean foundFront = newTop != null ? true : false;
680
Craig Mautner3b475fe2013-12-16 15:58:31 -0800681 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800682 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800683 final ActivityRecord r = mActivities.get(activityNdx);
684 if (foundFront || r.finishing) {
685 r.frontOfTask = false;
686 } else {
687 r.frontOfTask = true;
688 // Set frontOfTask false for every following activity.
689 foundFront = true;
690 }
691 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000692 if (!foundFront && numActivities > 0) {
693 // All activities of this task are finishing. As we ought to have a frontOfTask
694 // activity, make the bottom activity front.
695 mActivities.get(0).frontOfTask = true;
696 }
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800697 if (newTop != null) {
698 newTop.frontOfTask = true;
699 }
Craig Mautner3b475fe2013-12-16 15:58:31 -0800700 }
701
Craig Mautnerde4ef022013-04-07 19:01:33 -0700702 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800703 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700704 */
705 final void moveActivityToFrontLocked(ActivityRecord newTop) {
Wale Ogunwale0fc365c2015-05-25 19:35:42 -0700706 if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
707 "Removing and adding activity " + newTop
708 + " to stack at top callers=" + Debug.getCallers(4));
Craig Mautnerde4ef022013-04-07 19:01:33 -0700709
Craig Mautnerde4ef022013-04-07 19:01:33 -0700710 mActivities.remove(newTop);
711 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700712 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -0800713
Wale Ogunwale6d42df62015-11-05 09:50:55 -0800714 setFrontOfTask(newTop);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700715 }
716
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800717 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800718 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800719 }
720
721 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700722 addActivityAtIndex(mActivities.size(), r);
723 }
724
725 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700726 // 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 -0800727 if (!mActivities.remove(r) && r.fullscreen) {
728 // Was not previously in list.
729 numFullscreen++;
730 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700731 // Only set this based on the first activity
732 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700733 taskType = r.mActivityType;
734 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700735 mCallingUid = r.launchedFromUid;
736 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700737 // Clamp to [1, max].
738 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
739 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -0700740 } else {
741 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -0700742 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -0700743 }
Craig Mautner77878772013-03-04 19:46:24 -0800744 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700745 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -0700746 if (r.isPersistable()) {
747 mService.notifyTaskPersisterLocked(this, false);
748 }
Craig Mautner77878772013-03-04 19:46:24 -0800749 }
750
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800751 /** @return true if this was the last activity in the task */
752 boolean removeActivity(ActivityRecord r) {
753 if (mActivities.remove(r) && r.fullscreen) {
754 // Was previously in list.
755 numFullscreen--;
756 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700757 if (r.isPersistable()) {
758 mService.notifyTaskPersisterLocked(this, false);
759 }
Craig Mautner41326202014-06-20 14:38:21 -0700760 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -0700761 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -0700762 }
763 updateEffectiveIntent();
764 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800765 }
766
Craig Mautner41db4a72014-05-07 17:20:56 -0700767 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700768 // We will automatically remove the task either if it has explicitly asked for
769 // this, or it is empty and has never contained an activity that got shown to
770 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700771 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -0700772 }
773
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700774 /**
775 * Completely remove all activities associated with an existing
776 * task starting at a specified index.
777 */
778 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700779 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700780 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700781 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700782 if (r.finishing) {
783 continue;
784 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700785 if (stack == null) {
786 // Task was restored from persistent storage.
787 r.takeFromHistory();
788 mActivities.remove(activityNdx);
789 --activityNdx;
790 --numActivities;
Todd Kennedy539db512014-12-15 09:57:55 -0800791 } else if (stack.finishActivityLocked(
792 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700793 --activityNdx;
794 --numActivities;
795 }
796 }
797 }
798
799 /**
800 * Completely remove all activities associated with an existing task.
801 */
802 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -0700803 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700804 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -0700805 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700806 }
807
Filip Gruszczynskibe9dabd2016-01-19 12:23:10 -0800808 ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
809 mReuseTask = true;
810 final ActivityRecord result = performClearTaskLocked(newR, launchFlags);
811 mReuseTask = false;
812 return result;
813 }
814
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700815 /**
816 * Perform clear operation as requested by
817 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
818 * stack to the given task, then look for
819 * an instance of that activity in the stack and, if found, finish all
820 * activities on top of it and return the instance.
821 *
822 * @param newR Description of the new activity being started.
823 * @return Returns the old activity that should be continued to be used,
824 * or null if none was found.
825 */
826 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700827 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700828 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700829 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700830 if (r.finishing) {
831 continue;
832 }
833 if (r.realActivity.equals(newR.realActivity)) {
834 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -0700835 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700836
837 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700838 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700839 if (r.finishing) {
840 continue;
841 }
842 ActivityOptions opts = r.takeOptionsLocked();
843 if (opts != null) {
844 ret.updateOptionsLocked(opts);
845 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700846 if (stack != null && stack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -0800847 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700848 --activityNdx;
849 --numActivities;
850 }
851 }
852
853 // Finally, if this is a normal launch mode (that is, not
854 // expecting onNewIntent()), then we will finish the current
855 // instance of the activity so a new fresh one can be started.
856 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
857 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
858 if (!ret.finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700859 if (stack != null) {
860 stack.finishActivityLocked(
861 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
862 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700863 return null;
864 }
865 }
866
867 return ret;
868 }
869 }
870
871 return null;
872 }
873
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700874 public TaskThumbnail getTaskThumbnailLocked() {
Craig Mautner21d24a22014-04-23 11:45:37 -0700875 if (stack != null) {
876 final ActivityRecord resumedActivity = stack.mResumedActivity;
877 if (resumedActivity != null && resumedActivity.task == this) {
Winson8b1871d2015-11-20 09:56:20 -0800878 final Bitmap thumbnail = stack.screenshotActivitiesLocked(resumedActivity);
Winsonc809cbb2015-11-02 12:06:15 -0800879 setLastThumbnailLocked(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -0700880 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700881 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700882 final TaskThumbnail taskThumbnail = new TaskThumbnail();
883 getLastThumbnail(taskThumbnail);
884 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700885 }
886
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700887 public void removeTaskActivitiesLocked() {
888 // Just remove the entire task.
889 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700890 }
891
Craig Mautner432f64e2015-05-20 14:59:57 -0700892 String lockTaskAuthToString() {
893 switch (mLockTaskAuth) {
894 case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK";
895 case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE";
896 case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE";
897 case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED";
Benjamin Franz469dd582015-06-09 14:24:36 +0100898 case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV";
Craig Mautner432f64e2015-05-20 14:59:57 -0700899 default: return "unknown=" + mLockTaskAuth;
900 }
901 }
902
Craig Mautner15df08a2015-04-01 12:17:18 -0700903 void setLockTaskAuth() {
Benjamin Franz469dd582015-06-09 14:24:36 +0100904 if (!mPrivileged &&
905 (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS ||
906 mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) {
907 // Non-priv apps are not allowed to use always or never, fall back to default
908 mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT;
909 }
Craig Mautner15df08a2015-04-01 12:17:18 -0700910 switch (mLockTaskMode) {
911 case LOCK_TASK_LAUNCH_MODE_DEFAULT:
912 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
913 LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE;
914 break;
915
916 case LOCK_TASK_LAUNCH_MODE_NEVER:
Benjamin Franz469dd582015-06-09 14:24:36 +0100917 mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK;
Craig Mautner15df08a2015-04-01 12:17:18 -0700918 break;
919
920 case LOCK_TASK_LAUNCH_MODE_ALWAYS:
Benjamin Franz469dd582015-06-09 14:24:36 +0100921 mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
Craig Mautner15df08a2015-04-01 12:17:18 -0700922 break;
923
924 case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED:
925 mLockTaskAuth = isLockTaskWhitelistedLocked() ?
926 LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE;
927 break;
928 }
Craig Mautner432f64e2015-05-20 14:59:57 -0700929 if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this +
930 " mLockTaskAuth=" + lockTaskAuthToString());
Craig Mautner15df08a2015-04-01 12:17:18 -0700931 }
932
933 boolean isLockTaskWhitelistedLocked() {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +0100934 String pkg = (realActivity != null) ? realActivity.getPackageName() : null;
935 if (pkg == null) {
Craig Mautner15df08a2015-04-01 12:17:18 -0700936 return false;
937 }
938 String[] packages = mService.mLockTaskPackages.get(userId);
939 if (packages == null) {
940 return false;
941 }
942 for (int i = packages.length - 1; i >= 0; --i) {
Benjamin Franz6fd84cc2015-08-06 18:09:03 +0100943 if (pkg.equals(packages[i])) {
Craig Mautner15df08a2015-04-01 12:17:18 -0700944 return true;
945 }
946 }
947 return false;
948 }
Wale Ogunwale74e26592016-02-05 11:48:37 -0800949
Craig Mautnera82aa092013-09-13 15:34:08 -0700950 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700951 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -0700952 }
953
Wale Ogunwale74e26592016-02-05 11:48:37 -0800954 boolean isRecentsTask() {
955 return taskType == RECENTS_ACTIVITY_TYPE;
956 }
957
Craig Mautner86d67a42013-05-14 10:34:38 -0700958 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700959 return taskType == APPLICATION_ACTIVITY_TYPE;
960 }
961
962 boolean isOverHomeStack() {
963 return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -0700964 }
965
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800966 boolean isResizeable() {
967 return !isHomeTask() && (mService.mForceResizableActivities
Jorim Jaggi8202b2a2016-02-03 19:24:31 -0800968 || ActivityInfo.isResizeableMode(mResizeMode)) && !mTemporarilyUnresizable;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800969 }
970
971 boolean inCropWindowsResizeMode() {
972 return !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS;
973 }
974
Wale Ogunwale513346d2016-01-27 10:55:01 -0800975 boolean canGoInDockedStack() {
976 return isResizeable() || inCropWindowsResizeMode();
977 }
978
Craig Mautner525f3d92013-05-07 14:01:50 -0700979 /**
980 * Find the activity in the history stack within the given task. Returns
981 * the index within the history at which it's found, or < 0 if not found.
982 */
983 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
984 final ComponentName realActivity = r.realActivity;
985 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
986 ActivityRecord candidate = mActivities.get(activityNdx);
987 if (candidate.finishing) {
988 continue;
989 }
990 if (candidate.realActivity.equals(realActivity)) {
991 return candidate;
992 }
993 }
994 return null;
995 }
996
Winson Chunga449dc02014-05-16 11:15:04 -0700997 /** Updates the last task description values. */
998 void updateTaskDescription() {
999 // Traverse upwards looking for any break between main task activities and
1000 // utility activities.
1001 int activityNdx;
1002 final int numActivities = mActivities.size();
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001003 final boolean relinquish = numActivities == 0 ? false :
1004 (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001005 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -07001006 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -07001007 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001008 if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1009 // This will be the top activity for determining taskDescription. Pre-inc to
1010 // overcome initial decrement below.
1011 ++activityNdx;
1012 break;
1013 }
Winson Chunga449dc02014-05-16 11:15:04 -07001014 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001015 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -07001016 break;
1017 }
1018 }
1019 if (activityNdx > 0) {
1020 // Traverse downwards starting below break looking for set label, icon.
1021 // Note that if there are activities in the task but none of them set the
1022 // recent activity values, then we do not fall back to the last set
1023 // values in the TaskRecord.
1024 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -07001025 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -07001026 int colorPrimary = 0;
Winson Chung1af8eda2016-02-05 17:55:56 +00001027 int colorBackground = 0;
Winson Chunga449dc02014-05-16 11:15:04 -07001028 for (--activityNdx; activityNdx >= 0; --activityNdx) {
1029 final ActivityRecord r = mActivities.get(activityNdx);
1030 if (r.taskDescription != null) {
1031 if (label == null) {
1032 label = r.taskDescription.getLabel();
1033 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001034 if (iconFilename == null) {
1035 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -07001036 }
1037 if (colorPrimary == 0) {
1038 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -07001039 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001040 if (colorBackground == 0) {
1041 colorBackground = r.taskDescription.getBackgroundColor();
1042 }
Winson Chunga449dc02014-05-16 11:15:04 -07001043 }
1044 }
Winson Chung1af8eda2016-02-05 17:55:56 +00001045 lastTaskDescription = new TaskDescription(label, null, iconFilename, colorPrimary,
1046 colorBackground);
Winson Chungec396d62014-08-06 17:08:00 -07001047 // Update the task affiliation color if we are the parent of the group
1048 if (taskId == mAffiliatedTaskId) {
1049 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
1050 }
Winson Chunga449dc02014-05-16 11:15:04 -07001051 }
1052 }
1053
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001054 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -07001055 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001056 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -07001057 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001058 final ActivityRecord r = mActivities.get(activityNdx);
1059 if (r.finishing) {
1060 continue;
1061 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001062 effectiveNdx = activityNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001063 if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
1064 break;
1065 }
1066 }
Craig Mautner4767f4b2014-09-18 15:38:33 -07001067 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001068 }
1069
1070 void updateEffectiveIntent() {
1071 final int effectiveRootIndex = findEffectiveRootIndex();
1072 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -07001073 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001074 }
1075
Craig Mautner21d24a22014-04-23 11:45:37 -07001076 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001077 if (DEBUG_RECENTS) Slog.i(TAG_RECENTS, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -07001078
1079 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
1080 if (realActivity != null) {
1081 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
1082 }
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001083 out.attribute(null, ATTR_REALACTIVITY_SUSPENDED, String.valueOf(realActivitySuspended));
Craig Mautner21d24a22014-04-23 11:45:37 -07001084 if (origActivity != null) {
1085 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
1086 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001087 // Write affinity, and root affinity if it is different from affinity.
1088 // We use the special string "@" for a null root affinity, so we can identify
1089 // later whether we were given a root affinity or should just make it the
1090 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -07001091 if (affinity != null) {
1092 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -07001093 if (!affinity.equals(rootAffinity)) {
1094 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
1095 }
1096 } else if (rootAffinity != null) {
1097 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -07001098 }
1099 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -07001100 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -07001101 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
1102 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001103 out.attribute(null, ATTR_USER_SETUP_COMPLETE, String.valueOf(mUserSetupComplete));
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001104 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -07001105 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -07001106 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -07001107 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -07001108 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001109 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -07001110 if (lastDescription != null) {
1111 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
1112 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001113 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001114 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -07001115 }
Winsonc809cbb2015-11-02 12:06:15 -08001116 mLastThumbnailInfo.saveToXml(out);
Winson Chungec396d62014-08-06 17:08:00 -07001117 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -07001118 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
1119 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
1120 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001121 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
1122 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001123 out.attribute(null, ATTR_RESIZE_MODE, String.valueOf(mResizeMode));
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001124 out.attribute(null, ATTR_PRIVILEGED, String.valueOf(mPrivileged));
Wale Ogunwale706ed792015-08-02 10:29:44 -07001125 if (mLastNonFullscreenBounds != null) {
1126 out.attribute(
1127 null, ATTR_NON_FULLSCREEN_BOUNDS, mLastNonFullscreenBounds.flattenToString());
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001128 }
Winson Chung2cb86c72014-06-25 12:03:30 -07001129
Craig Mautner21d24a22014-04-23 11:45:37 -07001130 if (affinityIntent != null) {
1131 out.startTag(null, TAG_AFFINITYINTENT);
1132 affinityIntent.saveToXml(out);
1133 out.endTag(null, TAG_AFFINITYINTENT);
1134 }
1135
1136 out.startTag(null, TAG_INTENT);
1137 intent.saveToXml(out);
1138 out.endTag(null, TAG_INTENT);
1139
1140 final ArrayList<ActivityRecord> activities = mActivities;
1141 final int numActivities = activities.size();
1142 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
1143 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -07001144 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -07001145 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
1146 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -07001147 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -07001148 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -07001149 break;
1150 }
1151 out.startTag(null, TAG_ACTIVITY);
1152 r.saveToXml(out);
1153 out.endTag(null, TAG_ACTIVITY);
1154 }
Craig Mautner21d24a22014-04-23 11:45:37 -07001155 }
1156
1157 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
1158 throws IOException, XmlPullParserException {
1159 Intent intent = null;
1160 Intent affinityIntent = null;
Winsonc809cbb2015-11-02 12:06:15 -08001161 ArrayList<ActivityRecord> activities = new ArrayList<>();
Craig Mautner21d24a22014-04-23 11:45:37 -07001162 ComponentName realActivity = null;
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001163 boolean realActivitySuspended = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001164 ComponentName origActivity = null;
1165 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -07001166 String rootAffinity = null;
1167 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001168 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -07001169 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -07001170 boolean askedCompatMode = false;
1171 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -07001172 int userId = 0;
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001173 boolean userSetupComplete = true;
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001174 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001175 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -07001176 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -07001177 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -07001178 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001179 boolean neverRelinquishIdentity = true;
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001180 int taskId = INVALID_TASK_ID;
Craig Mautner21d24a22014-04-23 11:45:37 -07001181 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -07001182 TaskDescription taskDescription = new TaskDescription();
Winsonc809cbb2015-11-02 12:06:15 -08001183 TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
Wale Ogunwale18795a22014-12-03 11:38:33 -08001184 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -07001185 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -08001186 int prevTaskId = INVALID_TASK_ID;
1187 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001188 int callingUid = -1;
1189 String callingPackage = "";
Wale Ogunwaled829d362016-02-10 19:24:49 -08001190 int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001191 boolean privileged = false;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001192 Rect bounds = null;
Craig Mautner21d24a22014-04-23 11:45:37 -07001193
1194 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
1195 final String attrName = in.getAttributeName(attrNdx);
1196 final String attrValue = in.getAttributeValue(attrNdx);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001197 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
1198 attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001199 if (ATTR_TASKID.equals(attrName)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001200 if (taskId == INVALID_TASK_ID) taskId = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001201 } else if (ATTR_REALACTIVITY.equals(attrName)) {
1202 realActivity = ComponentName.unflattenFromString(attrValue);
Andrei Stingaceanu4ccec532016-01-13 12:10:21 +00001203 } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
1204 realActivitySuspended = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001205 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
1206 origActivity = ComponentName.unflattenFromString(attrValue);
1207 } else if (ATTR_AFFINITY.equals(attrName)) {
1208 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -07001209 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
1210 rootAffinity = attrValue;
1211 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -07001212 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
1213 rootHasReset = Boolean.valueOf(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -07001214 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
1215 autoRemoveRecents = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001216 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
1217 askedCompatMode = Boolean.valueOf(attrValue);
1218 } else if (ATTR_USERID.equals(attrName)) {
1219 userId = Integer.valueOf(attrValue);
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001220 } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
1221 userSetupComplete = Boolean.valueOf(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001222 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
1223 effectiveUid = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001224 } else if (ATTR_TASKTYPE.equals(attrName)) {
1225 taskType = Integer.valueOf(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -07001226 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
1227 firstActiveTime = Long.valueOf(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -07001228 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
1229 lastActiveTime = Long.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001230 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
1231 lastDescription = attrValue;
1232 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
1233 lastTimeOnTop = Long.valueOf(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -07001234 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
1235 neverRelinquishIdentity = Boolean.valueOf(attrValue);
Winsonc809cbb2015-11-02 12:06:15 -08001236 } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
1237 thumbnailInfo.restoreFromXml(attrName, attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -07001238 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
1239 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -07001240 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
1241 taskAffiliation = Integer.valueOf(attrValue);
1242 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
1243 prevTaskId = Integer.valueOf(attrValue);
1244 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
1245 nextTaskId = Integer.valueOf(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -07001246 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
1247 taskAffiliationColor = Integer.valueOf(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -07001248 } else if (ATTR_CALLING_UID.equals(attrName)) {
1249 callingUid = Integer.valueOf(attrValue);
1250 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
1251 callingPackage = attrValue;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001252 } else if (ATTR_RESIZE_MODE.equals(attrName)) {
1253 resizeMode = Integer.valueOf(attrValue);
Wale Ogunwaled829d362016-02-10 19:24:49 -08001254 resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS)
1255 ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
Wale Ogunwalea7afaa22015-05-01 20:39:18 -07001256 } else if (ATTR_PRIVILEGED.equals(attrName)) {
1257 privileged = Boolean.valueOf(attrValue);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001258 } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001259 bounds = Rect.unflattenFromString(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -07001260 } else {
1261 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
1262 }
1263 }
1264
1265 int event;
1266 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
Ben Kwa8814cf42015-07-08 10:54:56 -07001267 (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
Craig Mautner21d24a22014-04-23 11:45:37 -07001268 if (event == XmlPullParser.START_TAG) {
1269 final String name = in.getName();
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001270 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" +
1271 name);
Craig Mautner21d24a22014-04-23 11:45:37 -07001272 if (TAG_AFFINITYINTENT.equals(name)) {
1273 affinityIntent = Intent.restoreFromXml(in);
1274 } else if (TAG_INTENT.equals(name)) {
1275 intent = Intent.restoreFromXml(in);
1276 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001277 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -07001278 if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" +
1279 activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001280 if (activity != null) {
1281 activities.add(activity);
1282 }
1283 } else {
1284 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1285 XmlUtils.skipCurrentTag(in);
1286 }
1287 }
1288 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001289 if (!hasRootAffinity) {
1290 rootAffinity = affinity;
1291 } else if ("@".equals(rootAffinity)) {
1292 rootAffinity = null;
1293 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001294 if (effectiveUid <= 0) {
1295 Intent checkIntent = intent != null ? intent : affinityIntent;
1296 effectiveUid = 0;
1297 if (checkIntent != null) {
1298 IPackageManager pm = AppGlobals.getPackageManager();
1299 try {
1300 ApplicationInfo ai = pm.getApplicationInfo(
1301 checkIntent.getComponent().getPackageName(),
1302 PackageManager.GET_UNINSTALLED_PACKAGES
1303 | PackageManager.GET_DISABLED_COMPONENTS, userId);
1304 if (ai != null) {
1305 effectiveUid = ai.uid;
1306 }
1307 } catch (RemoteException e) {
1308 }
1309 }
1310 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1311 + ": effectiveUid=" + effectiveUid);
1312 }
1313
Craig Mautner21d24a22014-04-23 11:45:37 -07001314 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001315 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001316 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1317 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winsonc809cbb2015-11-02 12:06:15 -08001318 taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId,
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001319 taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged,
Wale Ogunwalef80170f2016-02-04 15:12:29 -08001320 realActivitySuspended, userSetupComplete);
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001321 task.updateOverrideConfiguration(bounds);
Craig Mautner21d24a22014-04-23 11:45:37 -07001322
1323 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001324 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001325 }
1326
Wale Ogunwaleee006da2015-03-30 14:49:25 -07001327 if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001328 return task;
1329 }
1330
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001331 private void adjustForMinimalTaskDimensions(Rect bounds) {
1332 if (bounds == null) {
1333 return;
1334 }
1335 final int minimalSize = mMinimalSize == -1
1336 ? mService.mStackSupervisor.mDefaultMinimalSizeOfResizeableTask : mMinimalSize;
1337 final boolean adjustWidth = minimalSize > bounds.width();
1338 final boolean adjustHeight = minimalSize > bounds.height();
1339 if (!(adjustWidth || adjustHeight)) {
1340 return;
1341 }
1342
1343 if (adjustWidth) {
1344 if (mBounds != null && bounds.right == mBounds.right) {
1345 bounds.left = bounds.right - minimalSize;
1346 } else {
1347 // Either left bounds match, or neither match, or the previous bounds were
1348 // fullscreen and we default to keeping left.
1349 bounds.right = bounds.left + minimalSize;
1350 }
1351 }
1352 if (adjustHeight) {
1353 if (mBounds != null && bounds.bottom == mBounds.bottom) {
1354 bounds.top = bounds.bottom - minimalSize;
1355 } else {
1356 // Either top bounds match, or neither match, or the previous bounds were
1357 // fullscreen and we default to keeping top.
1358 bounds.bottom = bounds.top + minimalSize;
1359 }
1360 }
1361 }
1362
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001363 /**
1364 * Update task's override configuration based on the bounds.
Jorim Jaggi0a932142016-02-01 17:42:25 -08001365 * @param bounds The bounds of the task.
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001366 * @return Update configuration or null if there is no change.
1367 */
Filip Gruszczynskiaff7f132015-09-02 17:21:21 -07001368 Configuration updateOverrideConfiguration(Rect bounds) {
Jorim Jaggi0a932142016-02-01 17:42:25 -08001369 return updateOverrideConfiguration(bounds, null /* insetBounds */);
1370 }
1371
1372 /**
1373 * Update task's override configuration based on the bounds.
1374 * @param bounds The bounds of the task.
1375 * @param insetBounds The bounds used to calculate the system insets, which is used here to
1376 * subtract the navigation bar/status bar size from the screen size reported
1377 * to the application. See {@link IActivityManager#resizeDockedStack}.
1378 * @return Update configuration or null if there is no change.
1379 */
1380 Configuration updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001381 if (Objects.equals(mBounds, bounds)) {
1382 return null;
1383 }
Wale Ogunwale5f986092015-12-04 15:35:38 -08001384 final Configuration oldConfig = mOverrideConfig;
1385 final boolean oldFullscreen = mFullscreen;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001386
1387 mFullscreen = bounds == null;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001388 if (mFullscreen) {
Wale Ogunwale3797c222015-10-27 14:21:58 -07001389 if (mBounds != null && StackId.persistTaskBounds(stack.mStackId)) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001390 mLastNonFullscreenBounds = mBounds;
1391 }
1392 mBounds = null;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001393 mOverrideConfig = Configuration.EMPTY;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001394 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001395 mTmpRect.set(bounds);
1396 adjustForMinimalTaskDimensions(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001397 if (mBounds == null) {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001398 mBounds = new Rect(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001399 } else {
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001400 mBounds.set(mTmpRect);
Chong Zhangb15758a2015-11-17 12:12:03 -08001401 }
Wale Ogunwale3797c222015-10-27 14:21:58 -07001402 if (stack == null || StackId.persistTaskBounds(stack.mStackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001403 mLastNonFullscreenBounds = mBounds;
1404 }
Wale Ogunwale9a08f822016-02-17 19:03:58 -08001405 mOverrideConfig = calculateOverrideConfig(mTmpRect, insetBounds);
Wale Ogunwale706ed792015-08-02 10:29:44 -07001406 }
Wale Ogunwale5f986092015-12-04 15:35:38 -08001407
1408 if (mFullscreen != oldFullscreen) {
Wale Ogunwale22e25262016-02-01 10:32:02 -08001409 mService.mStackSupervisor.scheduleReportMultiWindowChanged(this);
Wale Ogunwale5f986092015-12-04 15:35:38 -08001410 }
1411
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -07001412 return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001413 }
1414
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001415 private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds) {
1416 mTmpRect2.set(inInsetBounds);
1417 mService.mWindowManager.subtractNonDecorInsets(mTmpRect2);
1418 int leftInset = mTmpRect2.left - inInsetBounds.left;
1419 int topInset = mTmpRect2.top - inInsetBounds.top;
1420 int rightInset = inInsetBounds.right - mTmpRect2.right;
1421 int bottomInset = inInsetBounds.bottom - mTmpRect2.bottom;
1422 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1423 }
1424
Jorim Jaggi0a932142016-02-01 17:42:25 -08001425 private void subtractStableInsets(Rect inOutBounds, Rect inInsetBounds) {
1426 mTmpRect2.set(inInsetBounds);
1427 mService.mWindowManager.subtractStableInsets(mTmpRect2);
1428 int leftInset = mTmpRect2.left - inInsetBounds.left;
1429 int topInset = mTmpRect2.top - inInsetBounds.top;
1430 int rightInset = inInsetBounds.right - mTmpRect2.right;
1431 int bottomInset = inInsetBounds.bottom - mTmpRect2.bottom;
1432 inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
1433 }
1434
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001435 private Configuration calculateOverrideConfig(Rect bounds, Rect insetBounds) {
1436 mTmpNonDecorBounds.set(bounds);
1437 mTmpStableBounds.set(bounds);
1438 subtractNonDecorInsets(
1439 mTmpNonDecorBounds, insetBounds != null ? insetBounds : bounds);
1440 subtractStableInsets(
1441 mTmpStableBounds, insetBounds != null ? insetBounds : bounds);
1442
1443 // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
1444 // i.e. the screen area without the system bars.
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001445 final Configuration serviceConfig = mService.mConfiguration;
1446 final Configuration config = new Configuration(Configuration.EMPTY);
1447 // TODO(multidisplay): Update Dp to that of display stack is on.
1448 final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
1449 config.screenWidthDp =
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001450 Math.min((int)(mTmpStableBounds.width() / density), serviceConfig.screenWidthDp);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001451 config.screenHeightDp =
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001452 Math.min((int)(mTmpStableBounds.height() / density), serviceConfig.screenHeightDp);
1453 config.smallestScreenWidthDp = Math.min(config.screenWidthDp, config.screenHeightDp);
1454
1455 // TODO: Orientation?
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001456 config.orientation = (config.screenWidthDp <= config.screenHeightDp)
1457 ? Configuration.ORIENTATION_PORTRAIT
1458 : Configuration.ORIENTATION_LANDSCAPE;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001459
1460 // For calculating screen layout, we need to use the non-decor inset screen area for the
1461 // calculation for compatibility reasons, i.e. screen area without system bars that could
1462 // never go away in Honeycomb.
1463 final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
1464 final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001465 final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout);
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08001466 final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
1467 final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
Jorim Jaggi0a932142016-02-01 17:42:25 -08001468 config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
Jorim Jaggia95ca8d2016-01-15 22:54:46 -08001469 return config;
1470 }
1471
1472 /**
1473 * Using the existing configuration {@param config}, creates a new task override config such
1474 * that all the fields that are usually set in an override config are set to the ones in
1475 * {@param config}.
1476 */
1477 Configuration extractOverrideConfig(Configuration config) {
1478 final Configuration extracted = new Configuration(Configuration.EMPTY);
1479 extracted.screenWidthDp = config.screenWidthDp;
1480 extracted.screenHeightDp = config.screenHeightDp;
1481 extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
1482 extracted.orientation = config.orientation;
1483 extracted.screenLayout = config.screenLayout;
1484 return extracted;
1485 }
1486
Filip Gruszczynskidce2d162016-01-12 15:40:13 -08001487 Rect updateOverrideConfigurationFromLaunchBounds() {
1488 final Rect bounds = validateBounds(getLaunchBounds());
1489 updateOverrideConfiguration(bounds);
1490 return bounds;
1491 }
1492
1493 static Rect validateBounds(Rect bounds) {
1494 if (bounds != null && bounds.isEmpty()) {
1495 Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
1496 return null;
1497 }
1498 return bounds;
1499 }
1500
Wale Ogunwale935e5022015-11-10 12:36:10 -08001501 /** Updates the task's bounds and override configuration to match what is expected for the
1502 * input stack. */
1503 void updateOverrideConfigurationForStack(ActivityStack inStack) {
1504 if (stack != null && stack == inStack) {
1505 return;
1506 }
1507
1508 if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001509 if (!isResizeable()) {
Wale Ogunwale935e5022015-11-10 12:36:10 -08001510 throw new IllegalArgumentException("Can not position non-resizeable task="
1511 + this + " in stack=" + inStack);
1512 }
1513 if (mBounds != null) {
1514 return;
1515 }
1516 if (mLastNonFullscreenBounds != null) {
1517 updateOverrideConfiguration(mLastNonFullscreenBounds);
1518 } else {
1519 inStack.layoutTaskInStack(this, null);
1520 }
1521 } else {
1522 updateOverrideConfiguration(inStack.mBounds);
1523 }
1524 }
1525
Chong Zhang0fa656b2015-08-31 15:17:21 -07001526 /**
1527 * Returns the correct stack to use based on task type and currently set bounds,
1528 * regardless of the focused stack and current stack association of the task.
1529 * The task will be moved (and stack focus changed) later if necessary.
1530 */
1531 int getLaunchStackId() {
1532 if (!isApplicationTask()) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001533 return HOME_STACK_ID;
1534 }
Chong Zhang0fa656b2015-08-31 15:17:21 -07001535 if (mBounds != null) {
Wale Ogunwale706ed792015-08-02 10:29:44 -07001536 return FREEFORM_WORKSPACE_STACK_ID;
1537 }
1538 return FULLSCREEN_WORKSPACE_STACK_ID;
1539 }
1540
1541 /** Returns the bounds that should be used to launch this task. */
1542 Rect getLaunchBounds() {
Chong Zhang75b37202015-12-04 14:16:36 -08001543 // If we're over lockscreen, forget about stack bounds and use fullscreen.
1544 if (mService.mLockScreenShown == LOCK_SCREEN_SHOWN) {
1545 return null;
1546 }
1547
Chong Zhang7d5f5102016-01-13 10:29:24 -08001548 if (stack == null) {
1549 return null;
1550 }
1551
1552 final int stackId = stack.mStackId;
1553 if (stackId == HOME_STACK_ID
1554 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001555 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
1556 return isResizeable() ? stack.mBounds : null;
Wale Ogunwale3797c222015-10-27 14:21:58 -07001557 } else if (!StackId.persistTaskBounds(stackId)) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -07001558 return stack.mBounds;
Wale Ogunwale706ed792015-08-02 10:29:44 -07001559 }
1560 return mLastNonFullscreenBounds;
1561 }
1562
Wale Ogunwale39381972015-12-17 17:15:29 -08001563 boolean canMatchRootAffinity() {
1564 // We don't allow root affinity matching on the pinned stack as no other task should
1565 // be launching in it based on affinity.
1566 return rootAffinity != null && (stack == null || stack.mStackId != PINNED_STACK_ID);
1567 }
1568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001570 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001571 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1572 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001573 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001574 if (affinity != null || rootAffinity != null) {
1575 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
1576 if (affinity == null || !affinity.equals(rootAffinity)) {
1577 pw.print(" root="); pw.println(rootAffinity);
1578 } else {
1579 pw.println();
1580 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001581 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07001582 if (voiceSession != null || voiceInteractor != null) {
1583 pw.print(prefix); pw.print("VOICE: session=0x");
1584 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
1585 pw.print(" interactor=0x");
1586 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
1587 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001588 if (intent != null) {
1589 StringBuilder sb = new StringBuilder(128);
1590 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001591 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001592 sb.append('}');
1593 pw.println(sb.toString());
1594 }
1595 if (affinityIntent != null) {
1596 StringBuilder sb = new StringBuilder(128);
1597 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001598 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001599 sb.append('}');
1600 pw.println(sb.toString());
1601 }
1602 if (origActivity != null) {
1603 pw.print(prefix); pw.print("origActivity=");
1604 pw.println(origActivity.flattenToShortString());
1605 }
1606 if (realActivity != null) {
1607 pw.print(prefix); pw.print("realActivity=");
1608 pw.println(realActivity.flattenToShortString());
1609 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07001610 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
1611 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001612 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001613 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001614 pw.print(" numFullscreen="); pw.print(numFullscreen);
1615 pw.print(" taskType="); pw.print(taskType);
1616 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
1617 }
Craig Mautner432f64e2015-05-20 14:59:57 -07001618 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask
1619 || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001620 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
1621 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
Craig Mautner432f64e2015-05-20 14:59:57 -07001622 pw.print(" mReuseTask="); pw.print(mReuseTask);
1623 pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001624 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08001625 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
1626 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
1627 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07001628 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
1629 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
1630 pw.print(" (");
1631 if (mPrevAffiliate == null) {
1632 pw.print("null");
1633 } else {
1634 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
1635 }
1636 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
1637 pw.print(" (");
1638 if (mNextAffiliate == null) {
1639 pw.print("null");
1640 } else {
1641 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
1642 }
1643 pw.println(")");
1644 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001645 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001646 if (!askedCompatMode || !inRecents || !isAvailable) {
1647 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
1648 pw.print(" inRecents="); pw.print(inRecents);
1649 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001650 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001651 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001652 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
1653 if (lastDescription != null) {
1654 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
1655 }
Wale Ogunwale069fbe42015-07-29 11:38:01 -07001656 if (stack != null) {
1657 pw.print(prefix); pw.print("stackId="); pw.println(stack.mStackId);
1658 }
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001659 pw.print(prefix + "hasBeenVisible=" + hasBeenVisible);
1660 pw.print(" mResizeMode=" + ActivityInfo.resizeModeToString(mResizeMode));
1661 pw.print(" isResizeable=" + isResizeable());
1662 pw.print(" firstActiveTime=" + lastActiveTime);
1663 pw.print(" lastActiveTime=" + lastActiveTime);
1664 pw.println(" (inactive for " + (getInactiveDuration() / 1000) + "s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 }
1666
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001667 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001669 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001670 if (stringName != null) {
1671 sb.append(stringName);
1672 sb.append(" U=");
1673 sb.append(userId);
Wale Ogunwale6c5eb1c2015-11-10 07:52:22 -08001674 sb.append(" StackId=");
1675 sb.append(stack != null ? stack.mStackId : INVALID_STACK_ID);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001676 sb.append(" sz=");
1677 sb.append(mActivities.size());
1678 sb.append('}');
1679 return sb.toString();
1680 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001681 sb.append("TaskRecord{");
1682 sb.append(Integer.toHexString(System.identityHashCode(this)));
1683 sb.append(" #");
1684 sb.append(taskId);
1685 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001686 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001687 sb.append(affinity);
1688 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001689 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001690 sb.append(intent.getComponent().flattenToShortString());
1691 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001692 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001693 sb.append(affinityIntent.getComponent().flattenToShortString());
1694 } else {
1695 sb.append(" ??");
1696 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001697 stringName = sb.toString();
1698 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 }
1700}