blob: 3b345413ca5f8d4282a116728d10255082a2f760 [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
Wale Ogunwale843bfb92015-03-27 11:06:48 -070019import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
20import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080021import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
22import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Craig Mautner84984fa2014-06-19 11:19:20 -070023import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
24import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
25import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Craig Mautner0eea92c2013-05-16 13:35:39 -070026import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE;
Wale Ogunwale18795a22014-12-03 11:38:33 -080027import static com.android.server.am.TaskPersister.DEBUG_PERSISTER;
28import static com.android.server.am.TaskPersister.DEBUG_RESTORER;
Craig Mautnerde4ef022013-04-07 19:01:33 -070029
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070030import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070031import android.app.ActivityManager;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070032import android.app.ActivityManager.TaskThumbnail;
Craig Mautner648f69b2014-09-18 14:16:26 -070033import android.app.ActivityManager.TaskDescription;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070034import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070035import android.app.AppGlobals;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.ComponentName;
37import android.content.Intent;
38import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070039import android.content.pm.ApplicationInfo;
40import android.content.pm.IPackageManager;
41import android.content.pm.PackageManager;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070042import android.graphics.Bitmap;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070043import android.os.ParcelFileDescriptor;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070044import android.os.RemoteException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070045import android.os.UserHandle;
Dianne Hackborn91097de2014-04-04 18:02:06 -070046import android.service.voice.IVoiceInteractionSession;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070047import android.util.Slog;
Dianne Hackborn91097de2014-04-04 18:02:06 -070048import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070049import com.android.internal.util.XmlUtils;
50import 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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058
Craig Mautnerc0ffce52014-07-01 12:38:52 -070059final class TaskRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080060 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
61
Wale Ogunwale18795a22014-12-03 11:38:33 -080062 static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -070063 private static final String TAG_INTENT = "intent";
64 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale18795a22014-12-03 11:38:33 -080065 static final String ATTR_REALACTIVITY = "real_activity";
Craig Mautner21d24a22014-04-23 11:45:37 -070066 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Wale Ogunwale92dd1ab2015-01-15 15:36:48 -080067 static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -070068 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -070069 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -070070 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -070071 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -070072 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
73 private static final String ATTR_USERID = "user_id";
Dianne Hackborn885fbe52014-08-23 15:23:58 -070074 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -070075 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -070076 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -070077 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -070078 private static final String ATTR_LASTDESCRIPTION = "last_description";
79 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -070080 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale18795a22014-12-03 11:38:33 -080081 static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -070082 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
83 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -070084 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -070085 private static final String ATTR_CALLING_UID = "calling_uid";
86 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -080087 private static final String ATTR_RESIZEABLE = "resizeable";
Craig Mautner21d24a22014-04-23 11:45:37 -070088
89 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
90
Craig Mautner0b633fc2014-07-23 10:42:18 -070091 static final boolean IGNORE_RETURN_TO_RECENTS = true;
92
Wale Ogunwale18795a22014-12-03 11:38:33 -080093 static final int INVALID_TASK_ID = -1;
94
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -070096 String affinity; // The affinity name for this task, or null; may change identity.
97 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -070098 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
99 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 Intent intent; // The original intent that started the task.
101 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700102 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 ComponentName origActivity; // The non-alias activity component of the intent.
104 ComponentName realActivity; // The actual activity component that started the task.
Winson Chungffa2ec62014-07-03 15:54:42 -0700105 long firstActiveTime; // First time this task was active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700107 boolean inRecents; // Actually in the recents list?
108 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 boolean rootWasReset; // True if the intent at the root of the task had
110 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700111 boolean autoRemoveRecents; // If true, we should automatically remove the task from
112 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700113 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700114 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 -0800115
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700116 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700117 int userId; // user for which this task was created
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800118
119 int numFullscreen; // Number of fullscreen activities.
120
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800121 boolean mResizeable; // Activities in the task resizeable. Based on the resizable setting of
122 // the root activity.
123
Winson Chung03a9bae2014-05-02 09:56:12 -0700124 // This represents the last resolved activity values for this task
125 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700126 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700127
Craig Mautnerd2328952013-03-05 12:46:26 -0800128 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700129 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800130
Craig Mautnerd2328952013-03-05 12:46:26 -0800131 /** Current stack */
132 ActivityStack stack;
133
Craig Mautner2c1faed2013-07-23 12:56:02 -0700134 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700135 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700136
Craig Mautner21d24a22014-04-23 11:45:37 -0700137 /** Takes on same value as first root activity */
138 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700139 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700140
141 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
142 * determining the order when restoring. Sign indicates whether last task movement was to front
143 * (positive) or back (negative). Absolute value indicates time. */
144 long mLastTimeMoved = System.currentTimeMillis();
145
Craig Mautner84984fa2014-06-19 11:19:20 -0700146 /** Indication of what to run next when task exits. Use ActivityRecord types.
147 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
148 * task stack. */
149 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700150
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700151 /** If original intent did not allow relinquishing task identity, save that information */
152 boolean mNeverRelinquishIdentity = true;
153
Craig Mautner362449a2014-06-20 14:04:39 -0700154 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
155 // do not want to delete the stack when the task goes empty.
156 boolean mReuseTask = false;
157
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700158 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700159 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700160 private final String mFilename;
161 CharSequence lastDescription; // Last description captured for this item.
162
Craig Mautnera228ae92014-07-09 05:44:55 -0700163 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700164 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700165 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800166 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700167 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800168 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700169
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700170 // For relaunching the task from recents as though it was launched by the original launcher.
171 int mCallingUid;
172 String mCallingPackage;
173
Craig Mautner21d24a22014-04-23 11:45:37 -0700174 final ActivityManagerService mService;
175
176 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Dianne Hackborn91097de2014-04-04 18:02:06 -0700177 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700178 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700179 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
180 TaskPersister.IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700181 mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700183 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700184 voiceSession = _voiceSession;
185 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700186 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800187 mActivities = new ArrayList<>();
Martijn Coenend4a69702014-06-30 11:12:17 -0700188 setIntent(_intent, info);
Craig Mautner21d24a22014-04-23 11:45:37 -0700189 }
190
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700191 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Craig Mautner648f69b2014-09-18 14:16:26 -0700192 TaskDescription _taskDescription) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700193 mService = service;
194 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
195 TaskPersister.IMAGE_EXTENSION;
196 mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename);
197 taskId = _taskId;
198 mAffiliatedTaskId = _taskId;
199 voiceSession = null;
200 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700201 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800202 mActivities = new ArrayList<>();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700203 setIntent(_intent, info);
204
205 taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
206 isPersistable = true;
207 mCallingUid = info.applicationInfo.uid;
208 mCallingPackage = info.packageName;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700209 // Clamp to [1, max].
210 maxRecents = Math.min(Math.max(info.maxRecents, 1),
211 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700212
213 taskType = APPLICATION_ACTIVITY_TYPE;
214 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
215 userId = UserHandle.getUserId(info.applicationInfo.uid);
216 lastTaskDescription = _taskDescription;
217 mCallingUid = info.applicationInfo.uid;
218 mCallingPackage = info.packageName;
219 }
220
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800221 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
222 Intent _affinityIntent, String _affinity, String _rootAffinity,
223 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
224 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
225 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
226 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
227 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
228 int taskAffiliation, int prevTaskId, int nextTaskId, int taskAffiliationColor,
229 int callingUid, String callingPackage, boolean resizeable) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700230 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700231 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
232 TaskPersister.IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700233 mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename);
Craig Mautner21d24a22014-04-23 11:45:37 -0700234 taskId = _taskId;
235 intent = _intent;
236 affinityIntent = _affinityIntent;
237 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800238 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700239 voiceSession = null;
240 voiceInteractor = null;
241 realActivity = _realActivity;
242 origActivity = _origActivity;
243 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700244 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700245 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700246 askedCompatMode = _askedCompatMode;
247 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700248 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700249 userId = _userId;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700250 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700251 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700252 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700253 lastDescription = _lastDescription;
254 mActivities = activities;
255 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700256 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700257 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700258 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700259 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700260 mPrevAffiliateTaskId = prevTaskId;
261 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700262 mCallingUid = callingUid;
263 mCallingPackage = callingPackage;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800264 mResizeable = resizeable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 }
266
267 void touchActiveTime() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700268 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700269 if (firstActiveTime == 0) {
270 firstActiveTime = lastActiveTime;
271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 long getInactiveDuration() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700275 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700277
Winson Chungfee26772014-08-05 12:21:52 -0700278 /** Sets the original intent, and the calling uid and package. */
279 void setIntent(ActivityRecord r) {
280 setIntent(r.intent, r.info);
281 mCallingUid = r.launchedFromUid;
282 mCallingPackage = r.launchedFromPackage;
283 }
284
285 /** Sets the original intent, _without_ updating the calling uid or package. */
286 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700287 if (intent == null) {
288 mNeverRelinquishIdentity =
289 (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0;
290 } else if (mNeverRelinquishIdentity) {
291 return;
292 }
293
294 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700295 if (intent == null) {
296 // If this task already has an intent associated with it, don't set the root
297 // affinity -- we don't want it changing after initially set, but the initially
298 // set value may be null.
299 rootAffinity = affinity;
300 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700301 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700302 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800305 if (_intent != null) {
306 // If this Intent has a selector, we want to clear it for the
307 // recent task since it is not relevant if the user later wants
308 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700309 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800310 _intent = new Intent(_intent);
311 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700312 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800313 }
314 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800315 if (ActivityManagerService.DEBUG_TASKS) Slog.v(TAG,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700316 "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 intent = _intent;
318 realActivity = _intent != null ? _intent.getComponent() : null;
319 origActivity = null;
320 } else {
321 ComponentName targetComponent = new ComponentName(
322 info.packageName, info.targetActivity);
323 if (_intent != null) {
324 Intent targetIntent = new Intent(_intent);
325 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800326 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700327 targetIntent.setSourceBounds(null);
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800328 if (ActivityManagerService.DEBUG_TASKS) Slog.v(TAG,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700329 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 intent = targetIntent;
331 realActivity = targetComponent;
332 origActivity = _intent.getComponent();
333 } else {
334 intent = null;
335 realActivity = targetComponent;
336 origActivity = new ComponentName(info.packageName, info.name);
337 }
338 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700339
Craig Mautner47b20ba2014-09-17 17:23:44 -0700340 final int intentFlags = intent == null ? 0 : intent.getFlags();
341 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 // Once we are set to an Intent with this flag, we count this
343 // task as having a true root activity.
344 rootWasReset = true;
345 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700346
Dianne Hackborn09233282014-04-30 11:33:59 -0700347 userId = UserHandle.getUserId(info.applicationInfo.uid);
Craig Mautner41db4a72014-05-07 17:20:56 -0700348 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700349 // If the activity itself has requested auto-remove, then just always do it.
350 autoRemoveRecents = true;
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700351 } else if ((intentFlags & (FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS))
352 == FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700353 // If the caller has not asked for the document to be retained, then we may
354 // want to turn on auto-remove, depending on whether the target has set its
355 // own document launch mode.
356 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
357 autoRemoveRecents = false;
358 } else {
359 autoRemoveRecents = true;
360 }
361 } else {
362 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700363 }
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800364 mResizeable = info.resizeable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800366
Craig Mautner84984fa2014-06-19 11:19:20 -0700367 void setTaskToReturnTo(int taskToReturnTo) {
Craig Mautner0b633fc2014-07-23 10:42:18 -0700368 if (IGNORE_RETURN_TO_RECENTS && taskToReturnTo == RECENTS_ACTIVITY_TYPE) {
369 taskToReturnTo = HOME_ACTIVITY_TYPE;
370 }
Craig Mautner84984fa2014-06-19 11:19:20 -0700371 mTaskToReturnTo = taskToReturnTo;
372 }
373
374 int getTaskToReturnTo() {
375 return mTaskToReturnTo;
376 }
377
Craig Mautnera228ae92014-07-09 05:44:55 -0700378 void setPrevAffiliate(TaskRecord prevAffiliate) {
379 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800380 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700381 }
382
383 void setNextAffiliate(TaskRecord nextAffiliate) {
384 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800385 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700386 }
387
388 // Close up recents linked list.
389 void closeRecentsChain() {
390 if (mPrevAffiliate != null) {
391 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
392 }
393 if (mNextAffiliate != null) {
394 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
395 }
396 setPrevAffiliate(null);
397 setNextAffiliate(null);
398 }
399
Winson Chung740c3ac2014-11-12 16:14:38 -0800400 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700401 disposeThumbnail();
402 closeRecentsChain();
403 if (inRecents) {
404 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800405 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700406 }
407 }
408
Craig Mautnera228ae92014-07-09 05:44:55 -0700409 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
410 closeRecentsChain();
411 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700412 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700413 // Find the end
414 while (taskToAffiliateWith.mNextAffiliate != null) {
415 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
416 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
417 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
418 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
419 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
420 nextRecents.setPrevAffiliate(null);
421 }
422 taskToAffiliateWith.setNextAffiliate(null);
423 break;
424 }
425 taskToAffiliateWith = nextRecents;
426 }
427 taskToAffiliateWith.setNextAffiliate(this);
428 setPrevAffiliate(taskToAffiliateWith);
429 setNextAffiliate(null);
430 }
431
Winson Chung096f36b2014-08-20 15:39:01 -0700432 /**
433 * Sets the last thumbnail.
434 * @return whether the thumbnail was set
435 */
436 boolean setLastThumbnail(Bitmap thumbnail) {
437 if (mLastThumbnail != thumbnail) {
438 mLastThumbnail = thumbnail;
439 if (thumbnail == null) {
440 if (mLastThumbnailFile != null) {
441 mLastThumbnailFile.delete();
442 }
443 } else {
444 mService.mTaskPersister.saveImage(thumbnail, mFilename);
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700445 }
Winson Chung096f36b2014-08-20 15:39:01 -0700446 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700447 }
Winson Chung096f36b2014-08-20 15:39:01 -0700448 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700449 }
450
451 void getLastThumbnail(TaskThumbnail thumbs) {
452 thumbs.mainThumbnail = mLastThumbnail;
453 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700454 if (mLastThumbnail == null) {
Craig Mautner648f69b2014-09-18 14:16:26 -0700455 thumbs.mainThumbnail = mService.mTaskPersister.getImageFromWriteQueue(mFilename);
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700456 }
Winson Chung096f36b2014-08-20 15:39:01 -0700457 // Only load the thumbnail file if we don't have a thumbnail
458 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700459 try {
460 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
461 ParcelFileDescriptor.MODE_READ_ONLY);
462 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700463 }
464 }
465 }
466
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700467 void freeLastThumbnail() {
468 mLastThumbnail = null;
469 }
470
471 void disposeThumbnail() {
472 mLastThumbnail = null;
473 lastDescription = null;
474 }
475
Winson Chung1147c402014-05-14 11:05:00 -0700476 /** Returns the intent for the root activity for this task */
477 Intent getBaseIntent() {
478 return intent != null ? intent : affinityIntent;
479 }
480
Winson Chung3b3f4642014-04-22 10:08:18 -0700481 /** Returns the first non-finishing activity from the root. */
482 ActivityRecord getRootActivity() {
483 for (int i = 0; i < mActivities.size(); i++) {
484 final ActivityRecord r = mActivities.get(i);
485 if (r.finishing) {
486 continue;
487 }
488 return r;
489 }
490 return null;
491 }
492
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800493 ActivityRecord getTopActivity() {
494 for (int i = mActivities.size() - 1; i >= 0; --i) {
495 final ActivityRecord r = mActivities.get(i);
496 if (r.finishing) {
497 continue;
498 }
499 return r;
500 }
501 return null;
502 }
503
Craig Mautner6b74cb52013-09-27 17:02:21 -0700504 ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700505 if (stack != null) {
506 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
507 ActivityRecord r = mActivities.get(activityNdx);
508 if (!r.finishing && r != notTop && stack.okToShowLocked(r)) {
509 return r;
510 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700511 }
512 }
513 return null;
514 }
515
Craig Mautner3b475fe2013-12-16 15:58:31 -0800516 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
517 final void setFrontOfTask() {
518 boolean foundFront = false;
519 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800520 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800521 final ActivityRecord r = mActivities.get(activityNdx);
522 if (foundFront || r.finishing) {
523 r.frontOfTask = false;
524 } else {
525 r.frontOfTask = true;
526 // Set frontOfTask false for every following activity.
527 foundFront = true;
528 }
529 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000530 if (!foundFront && numActivities > 0) {
531 // All activities of this task are finishing. As we ought to have a frontOfTask
532 // activity, make the bottom activity front.
533 mActivities.get(0).frontOfTask = true;
534 }
Craig Mautner3b475fe2013-12-16 15:58:31 -0800535 }
536
Craig Mautnerde4ef022013-04-07 19:01:33 -0700537 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800538 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700539 */
540 final void moveActivityToFrontLocked(ActivityRecord newTop) {
541 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop
542 + " to stack at top", new RuntimeException("here").fillInStackTrace());
543
Craig Mautnerde4ef022013-04-07 19:01:33 -0700544 mActivities.remove(newTop);
545 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700546 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -0800547
548 setFrontOfTask();
Craig Mautnerde4ef022013-04-07 19:01:33 -0700549 }
550
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800551 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800552 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800553 }
554
555 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700556 addActivityAtIndex(mActivities.size(), r);
557 }
558
559 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700560 // 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 -0800561 if (!mActivities.remove(r) && r.fullscreen) {
562 // Was not previously in list.
563 numFullscreen++;
564 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700565 // Only set this based on the first activity
566 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700567 taskType = r.mActivityType;
568 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700569 mCallingUid = r.launchedFromUid;
570 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700571 // Clamp to [1, max].
572 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
573 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -0700574 } else {
575 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -0700576 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -0700577 }
Craig Mautner77878772013-03-04 19:46:24 -0800578 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700579 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -0700580 if (r.isPersistable()) {
581 mService.notifyTaskPersisterLocked(this, false);
582 }
Craig Mautner77878772013-03-04 19:46:24 -0800583 }
584
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800585 /** @return true if this was the last activity in the task */
586 boolean removeActivity(ActivityRecord r) {
587 if (mActivities.remove(r) && r.fullscreen) {
588 // Was previously in list.
589 numFullscreen--;
590 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700591 if (r.isPersistable()) {
592 mService.notifyTaskPersisterLocked(this, false);
593 }
Craig Mautner41326202014-06-20 14:38:21 -0700594 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -0700595 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -0700596 }
597 updateEffectiveIntent();
598 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800599 }
600
Craig Mautner41db4a72014-05-07 17:20:56 -0700601 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700602 // We will automatically remove the task either if it has explicitly asked for
603 // this, or it is empty and has never contained an activity that got shown to
604 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700605 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -0700606 }
607
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700608 /**
609 * Completely remove all activities associated with an existing
610 * task starting at a specified index.
611 */
612 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700613 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700614 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700615 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700616 if (r.finishing) {
617 continue;
618 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700619 if (stack == null) {
620 // Task was restored from persistent storage.
621 r.takeFromHistory();
622 mActivities.remove(activityNdx);
623 --activityNdx;
624 --numActivities;
Todd Kennedy539db512014-12-15 09:57:55 -0800625 } else if (stack.finishActivityLocked(
626 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700627 --activityNdx;
628 --numActivities;
629 }
630 }
631 }
632
633 /**
634 * Completely remove all activities associated with an existing task.
635 */
636 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -0700637 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700638 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -0700639 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700640 }
641
642 /**
643 * Perform clear operation as requested by
644 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
645 * stack to the given task, then look for
646 * an instance of that activity in the stack and, if found, finish all
647 * activities on top of it and return the instance.
648 *
649 * @param newR Description of the new activity being started.
650 * @return Returns the old activity that should be continued to be used,
651 * or null if none was found.
652 */
653 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700654 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700655 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700656 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700657 if (r.finishing) {
658 continue;
659 }
660 if (r.realActivity.equals(newR.realActivity)) {
661 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -0700662 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700663
664 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700665 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700666 if (r.finishing) {
667 continue;
668 }
669 ActivityOptions opts = r.takeOptionsLocked();
670 if (opts != null) {
671 ret.updateOptionsLocked(opts);
672 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700673 if (stack != null && stack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -0800674 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700675 --activityNdx;
676 --numActivities;
677 }
678 }
679
680 // Finally, if this is a normal launch mode (that is, not
681 // expecting onNewIntent()), then we will finish the current
682 // instance of the activity so a new fresh one can be started.
683 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
684 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
685 if (!ret.finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700686 if (stack != null) {
687 stack.finishActivityLocked(
688 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
689 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700690 return null;
691 }
692 }
693
694 return ret;
695 }
696 }
697
698 return null;
699 }
700
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700701 public TaskThumbnail getTaskThumbnailLocked() {
Craig Mautner21d24a22014-04-23 11:45:37 -0700702 if (stack != null) {
703 final ActivityRecord resumedActivity = stack.mResumedActivity;
704 if (resumedActivity != null && resumedActivity.task == this) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700705 final Bitmap thumbnail = stack.screenshotActivities(resumedActivity);
706 setLastThumbnail(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -0700707 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700708 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700709 final TaskThumbnail taskThumbnail = new TaskThumbnail();
710 getLastThumbnail(taskThumbnail);
711 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700712 }
713
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700714 public void removeTaskActivitiesLocked() {
715 // Just remove the entire task.
716 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700717 }
718
Craig Mautnera82aa092013-09-13 15:34:08 -0700719 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700720 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -0700721 }
722
Craig Mautner86d67a42013-05-14 10:34:38 -0700723 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700724 return taskType == APPLICATION_ACTIVITY_TYPE;
725 }
726
727 boolean isOverHomeStack() {
728 return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -0700729 }
730
Craig Mautner525f3d92013-05-07 14:01:50 -0700731 /**
732 * Find the activity in the history stack within the given task. Returns
733 * the index within the history at which it's found, or < 0 if not found.
734 */
735 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
736 final ComponentName realActivity = r.realActivity;
737 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
738 ActivityRecord candidate = mActivities.get(activityNdx);
739 if (candidate.finishing) {
740 continue;
741 }
742 if (candidate.realActivity.equals(realActivity)) {
743 return candidate;
744 }
745 }
746 return null;
747 }
748
Winson Chunga449dc02014-05-16 11:15:04 -0700749 /** Updates the last task description values. */
750 void updateTaskDescription() {
751 // Traverse upwards looking for any break between main task activities and
752 // utility activities.
753 int activityNdx;
754 final int numActivities = mActivities.size();
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700755 final boolean relinquish = numActivities == 0 ? false :
756 (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -0700757 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -0700758 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -0700759 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700760 if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
761 // This will be the top activity for determining taskDescription. Pre-inc to
762 // overcome initial decrement below.
763 ++activityNdx;
764 break;
765 }
Winson Chunga449dc02014-05-16 11:15:04 -0700766 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700767 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -0700768 break;
769 }
770 }
771 if (activityNdx > 0) {
772 // Traverse downwards starting below break looking for set label, icon.
773 // Note that if there are activities in the task but none of them set the
774 // recent activity values, then we do not fall back to the last set
775 // values in the TaskRecord.
776 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -0700777 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -0700778 int colorPrimary = 0;
779 for (--activityNdx; activityNdx >= 0; --activityNdx) {
780 final ActivityRecord r = mActivities.get(activityNdx);
781 if (r.taskDescription != null) {
782 if (label == null) {
783 label = r.taskDescription.getLabel();
784 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700785 if (iconFilename == null) {
786 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -0700787 }
788 if (colorPrimary == 0) {
789 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -0700790 }
791 }
792 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700793 lastTaskDescription = new TaskDescription(label, colorPrimary, iconFilename);
Winson Chungec396d62014-08-06 17:08:00 -0700794 // Update the task affiliation color if we are the parent of the group
795 if (taskId == mAffiliatedTaskId) {
796 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
797 }
Winson Chunga449dc02014-05-16 11:15:04 -0700798 }
799 }
800
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700801 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -0700802 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700803 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -0700804 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700805 final ActivityRecord r = mActivities.get(activityNdx);
806 if (r.finishing) {
807 continue;
808 }
Craig Mautner4767f4b2014-09-18 15:38:33 -0700809 effectiveNdx = activityNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700810 if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
811 break;
812 }
813 }
Craig Mautner4767f4b2014-09-18 15:38:33 -0700814 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700815 }
816
817 void updateEffectiveIntent() {
818 final int effectiveRootIndex = findEffectiveRootIndex();
819 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -0700820 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700821 }
822
Craig Mautner21d24a22014-04-23 11:45:37 -0700823 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700824 if (ActivityManagerService.DEBUG_RECENTS) Slog.i(TAG, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -0700825
826 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
827 if (realActivity != null) {
828 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
829 }
830 if (origActivity != null) {
831 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
832 }
Dianne Hackborn79228822014-09-16 11:11:23 -0700833 // Write affinity, and root affinity if it is different from affinity.
834 // We use the special string "@" for a null root affinity, so we can identify
835 // later whether we were given a root affinity or should just make it the
836 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -0700837 if (affinity != null) {
838 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -0700839 if (!affinity.equals(rootAffinity)) {
840 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
841 }
842 } else if (rootAffinity != null) {
843 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -0700844 }
845 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -0700846 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -0700847 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
848 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700849 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -0700850 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -0700851 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -0700852 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -0700853 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700854 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -0700855 if (lastDescription != null) {
856 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
857 }
Winson Chung2cb86c72014-06-25 12:03:30 -0700858 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -0700859 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -0700860 }
Winson Chungec396d62014-08-06 17:08:00 -0700861 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -0700862 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
863 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
864 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700865 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
866 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800867 out.attribute(null, ATTR_RESIZEABLE, String.valueOf(mResizeable));
Winson Chung2cb86c72014-06-25 12:03:30 -0700868
Craig Mautner21d24a22014-04-23 11:45:37 -0700869 if (affinityIntent != null) {
870 out.startTag(null, TAG_AFFINITYINTENT);
871 affinityIntent.saveToXml(out);
872 out.endTag(null, TAG_AFFINITYINTENT);
873 }
874
875 out.startTag(null, TAG_INTENT);
876 intent.saveToXml(out);
877 out.endTag(null, TAG_INTENT);
878
879 final ArrayList<ActivityRecord> activities = mActivities;
880 final int numActivities = activities.size();
881 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
882 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -0700883 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
Wale Ogunwale843bfb92015-03-27 11:06:48 -0700884 ((r.intent.getFlags() & FLAG_ACTIVITY_NEW_DOCUMENT
885 | FLAG_ACTIVITY_RETAIN_IN_RECENTS) == FLAG_ACTIVITY_NEW_DOCUMENT) &&
Craig Mautner43e52ed2014-06-16 17:18:52 -0700886 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -0700887 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -0700888 break;
889 }
890 out.startTag(null, TAG_ACTIVITY);
891 r.saveToXml(out);
892 out.endTag(null, TAG_ACTIVITY);
893 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700894 }
895
896 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
897 throws IOException, XmlPullParserException {
Wale Ogunwale18795a22014-12-03 11:38:33 -0800898 return restoreFromXml(in, stackSupervisor, INVALID_TASK_ID);
899 }
900 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor,
901 int inTaskId) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -0700902 Intent intent = null;
903 Intent affinityIntent = null;
904 ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>();
905 ComponentName realActivity = null;
906 ComponentName origActivity = null;
907 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -0700908 String rootAffinity = null;
909 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -0700910 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700911 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -0700912 boolean askedCompatMode = false;
913 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700914 int userId = 0;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700915 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700916 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -0700917 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -0700918 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700919 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700920 boolean neverRelinquishIdentity = true;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800921 int taskId = inTaskId;
Craig Mautner21d24a22014-04-23 11:45:37 -0700922 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -0700923 TaskDescription taskDescription = new TaskDescription();
Wale Ogunwale18795a22014-12-03 11:38:33 -0800924 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -0700925 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800926 int prevTaskId = INVALID_TASK_ID;
927 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700928 int callingUid = -1;
929 String callingPackage = "";
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800930 boolean resizeable = false;
Craig Mautner21d24a22014-04-23 11:45:37 -0700931
932 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
933 final String attrName = in.getAttributeName(attrNdx);
934 final String attrValue = in.getAttributeValue(attrNdx);
Wale Ogunwale18795a22014-12-03 11:38:33 -0800935 if (DEBUG_PERSISTER || DEBUG_RESTORER) Slog.d(TaskPersister.TAG,
936 "TaskRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700937 if (ATTR_TASKID.equals(attrName)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -0800938 if (taskId == INVALID_TASK_ID) taskId = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700939 } else if (ATTR_REALACTIVITY.equals(attrName)) {
940 realActivity = ComponentName.unflattenFromString(attrValue);
941 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
942 origActivity = ComponentName.unflattenFromString(attrValue);
943 } else if (ATTR_AFFINITY.equals(attrName)) {
944 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -0700945 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
946 rootAffinity = attrValue;
947 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -0700948 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
949 rootHasReset = Boolean.valueOf(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -0700950 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
951 autoRemoveRecents = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700952 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
953 askedCompatMode = Boolean.valueOf(attrValue);
954 } else if (ATTR_USERID.equals(attrName)) {
955 userId = Integer.valueOf(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700956 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
957 effectiveUid = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700958 } else if (ATTR_TASKTYPE.equals(attrName)) {
959 taskType = Integer.valueOf(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -0700960 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
961 firstActiveTime = Long.valueOf(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -0700962 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
963 lastActiveTime = Long.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700964 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
965 lastDescription = attrValue;
966 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
967 lastTimeOnTop = Long.valueOf(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700968 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
969 neverRelinquishIdentity = Boolean.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -0700970 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
971 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -0700972 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
973 taskAffiliation = Integer.valueOf(attrValue);
974 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
975 prevTaskId = Integer.valueOf(attrValue);
976 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
977 nextTaskId = Integer.valueOf(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -0700978 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
979 taskAffiliationColor = Integer.valueOf(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700980 } else if (ATTR_CALLING_UID.equals(attrName)) {
981 callingUid = Integer.valueOf(attrValue);
982 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
983 callingPackage = attrValue;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800984 } else if (ATTR_RESIZEABLE.equals(attrName)) {
985 resizeable = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700986 } else {
987 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
988 }
989 }
990
991 int event;
992 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
993 (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
994 if (event == XmlPullParser.START_TAG) {
995 final String name = in.getName();
Wale Ogunwale18795a22014-12-03 11:38:33 -0800996 if (DEBUG_PERSISTER || DEBUG_RESTORER)
997 Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -0700998 if (TAG_AFFINITYINTENT.equals(name)) {
999 affinityIntent = Intent.restoreFromXml(in);
1000 } else if (TAG_INTENT.equals(name)) {
1001 intent = Intent.restoreFromXml(in);
1002 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001003 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
1004 if (DEBUG_PERSISTER || DEBUG_RESTORER)
1005 Slog.d(TaskPersister.TAG, "TaskRecord: activity=" + activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001006 if (activity != null) {
1007 activities.add(activity);
1008 }
1009 } else {
1010 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1011 XmlUtils.skipCurrentTag(in);
1012 }
1013 }
1014 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001015 if (!hasRootAffinity) {
1016 rootAffinity = affinity;
1017 } else if ("@".equals(rootAffinity)) {
1018 rootAffinity = null;
1019 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001020 if (effectiveUid <= 0) {
1021 Intent checkIntent = intent != null ? intent : affinityIntent;
1022 effectiveUid = 0;
1023 if (checkIntent != null) {
1024 IPackageManager pm = AppGlobals.getPackageManager();
1025 try {
1026 ApplicationInfo ai = pm.getApplicationInfo(
1027 checkIntent.getComponent().getPackageName(),
1028 PackageManager.GET_UNINSTALLED_PACKAGES
1029 | PackageManager.GET_DISABLED_COMPONENTS, userId);
1030 if (ai != null) {
1031 effectiveUid = ai.uid;
1032 }
1033 } catch (RemoteException e) {
1034 }
1035 }
1036 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1037 + ": effectiveUid=" + effectiveUid);
1038 }
1039
Craig Mautner21d24a22014-04-23 11:45:37 -07001040 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001041 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001042 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1043 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winson Chungec396d62014-08-06 17:08:00 -07001044 taskDescription, taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor,
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -08001045 callingUid, callingPackage, resizeable);
Craig Mautner21d24a22014-04-23 11:45:37 -07001046
1047 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001048 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001049 }
1050
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001051 if (ActivityManagerService.DEBUG_RECENTS) Slog.d(TAG, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001052 return task;
1053 }
1054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001056 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001057 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1058 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001059 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001060 if (affinity != null || rootAffinity != null) {
1061 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
1062 if (affinity == null || !affinity.equals(rootAffinity)) {
1063 pw.print(" root="); pw.println(rootAffinity);
1064 } else {
1065 pw.println();
1066 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001067 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07001068 if (voiceSession != null || voiceInteractor != null) {
1069 pw.print(prefix); pw.print("VOICE: session=0x");
1070 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
1071 pw.print(" interactor=0x");
1072 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
1073 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001074 if (intent != null) {
1075 StringBuilder sb = new StringBuilder(128);
1076 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001077 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001078 sb.append('}');
1079 pw.println(sb.toString());
1080 }
1081 if (affinityIntent != null) {
1082 StringBuilder sb = new StringBuilder(128);
1083 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001084 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001085 sb.append('}');
1086 pw.println(sb.toString());
1087 }
1088 if (origActivity != null) {
1089 pw.print(prefix); pw.print("origActivity=");
1090 pw.println(origActivity.flattenToShortString());
1091 }
1092 if (realActivity != null) {
1093 pw.print(prefix); pw.print("realActivity=");
1094 pw.println(realActivity.flattenToShortString());
1095 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07001096 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
1097 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001098 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001099 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001100 pw.print(" numFullscreen="); pw.print(numFullscreen);
1101 pw.print(" taskType="); pw.print(taskType);
1102 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
1103 }
1104 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask) {
1105 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
1106 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
1107 pw.print(" mReuseTask="); pw.println(mReuseTask);
1108 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08001109 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
1110 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
1111 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07001112 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
1113 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
1114 pw.print(" (");
1115 if (mPrevAffiliate == null) {
1116 pw.print("null");
1117 } else {
1118 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
1119 }
1120 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
1121 pw.print(" (");
1122 if (mNextAffiliate == null) {
1123 pw.print("null");
1124 } else {
1125 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
1126 }
1127 pw.println(")");
1128 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001129 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001130 if (!askedCompatMode || !inRecents || !isAvailable) {
1131 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
1132 pw.print(" inRecents="); pw.print(inRecents);
1133 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001134 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001135 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001136 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
1137 if (lastDescription != null) {
1138 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
1139 }
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001140 pw.print(prefix); pw.print("hasBeenVisible="); pw.print(hasBeenVisible);
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -08001141 pw.print(" mResizeable="); pw.print(mResizeable);
Winson Chungffa2ec62014-07-03 15:54:42 -07001142 pw.print(" firstActiveTime="); pw.print(lastActiveTime);
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001143 pw.print(" lastActiveTime="); pw.print(lastActiveTime);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001144 pw.print(" (inactive for ");
1145 pw.print((getInactiveDuration()/1000)); pw.println("s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 }
1147
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001148 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001150 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001151 if (stringName != null) {
1152 sb.append(stringName);
1153 sb.append(" U=");
1154 sb.append(userId);
1155 sb.append(" sz=");
1156 sb.append(mActivities.size());
1157 sb.append('}');
1158 return sb.toString();
1159 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001160 sb.append("TaskRecord{");
1161 sb.append(Integer.toHexString(System.identityHashCode(this)));
1162 sb.append(" #");
1163 sb.append(taskId);
1164 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001165 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001166 sb.append(affinity);
1167 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001168 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001169 sb.append(intent.getComponent().flattenToShortString());
1170 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001171 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001172 sb.append(affinityIntent.getComponent().flattenToShortString());
1173 } else {
1174 sb.append(" ??");
1175 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001176 stringName = sb.toString();
1177 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 }
1179}