blob: d8d361b0d045ec1015a8d1d207cc5c10317063fb [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 Ogunwalee23149f2015-03-06 15:39:44 -080019import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
20import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Craig Mautner84984fa2014-06-19 11:19:20 -070021import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
22import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
23import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
Craig Mautner0eea92c2013-05-16 13:35:39 -070024import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE;
Wale Ogunwale18795a22014-12-03 11:38:33 -080025import static com.android.server.am.TaskPersister.DEBUG_PERSISTER;
26import static com.android.server.am.TaskPersister.DEBUG_RESTORER;
Craig Mautnerde4ef022013-04-07 19:01:33 -070027
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070028import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070029import android.app.ActivityManager;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070030import android.app.ActivityManager.TaskThumbnail;
Craig Mautner648f69b2014-09-18 14:16:26 -070031import android.app.ActivityManager.TaskDescription;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070032import android.app.ActivityOptions;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070033import android.app.AppGlobals;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.content.ComponentName;
35import android.content.Intent;
36import android.content.pm.ActivityInfo;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070037import android.content.pm.ApplicationInfo;
38import android.content.pm.IPackageManager;
39import android.content.pm.PackageManager;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070040import android.graphics.Bitmap;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070041import android.os.ParcelFileDescriptor;
Dianne Hackborn885fbe52014-08-23 15:23:58 -070042import android.os.RemoteException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070043import android.os.UserHandle;
Dianne Hackborn91097de2014-04-04 18:02:06 -070044import android.service.voice.IVoiceInteractionSession;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070045import android.util.Slog;
Dianne Hackborn91097de2014-04-04 18:02:06 -070046import com.android.internal.app.IVoiceInteractor;
Craig Mautner21d24a22014-04-23 11:45:37 -070047import com.android.internal.util.XmlUtils;
48import org.xmlpull.v1.XmlPullParser;
49import org.xmlpull.v1.XmlPullParserException;
50import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
Craig Mautnerc0ffce52014-07-01 12:38:52 -070052import java.io.File;
Craig Mautner21d24a22014-04-23 11:45:37 -070053import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080055import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
Craig Mautnerc0ffce52014-07-01 12:38:52 -070057final class TaskRecord {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080058 private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
59
Wale Ogunwale18795a22014-12-03 11:38:33 -080060 static final String ATTR_TASKID = "task_id";
Craig Mautner21d24a22014-04-23 11:45:37 -070061 private static final String TAG_INTENT = "intent";
62 private static final String TAG_AFFINITYINTENT = "affinity_intent";
Wale Ogunwale18795a22014-12-03 11:38:33 -080063 static final String ATTR_REALACTIVITY = "real_activity";
Craig Mautner21d24a22014-04-23 11:45:37 -070064 private static final String ATTR_ORIGACTIVITY = "orig_activity";
Wale Ogunwale92dd1ab2015-01-15 15:36:48 -080065 static final String TAG_ACTIVITY = "activity";
Craig Mautner21d24a22014-04-23 11:45:37 -070066 private static final String ATTR_AFFINITY = "affinity";
Dianne Hackborn79228822014-09-16 11:11:23 -070067 private static final String ATTR_ROOT_AFFINITY = "root_affinity";
Craig Mautner21d24a22014-04-23 11:45:37 -070068 private static final String ATTR_ROOTHASRESET = "root_has_reset";
Dianne Hackborn13420f22014-07-18 15:43:56 -070069 private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents";
Craig Mautner21d24a22014-04-23 11:45:37 -070070 private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode";
71 private static final String ATTR_USERID = "user_id";
Dianne Hackborn885fbe52014-08-23 15:23:58 -070072 private static final String ATTR_EFFECTIVE_UID = "effective_uid";
Craig Mautner21d24a22014-04-23 11:45:37 -070073 private static final String ATTR_TASKTYPE = "task_type";
Winson Chungffa2ec62014-07-03 15:54:42 -070074 private static final String ATTR_FIRSTACTIVETIME = "first_active_time";
Winson Chungf1fbd772014-06-24 18:06:58 -070075 private static final String ATTR_LASTACTIVETIME = "last_active_time";
Craig Mautner21d24a22014-04-23 11:45:37 -070076 private static final String ATTR_LASTDESCRIPTION = "last_description";
77 private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
Craig Mautner9d4e9bc2014-06-18 18:34:56 -070078 private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
Wale Ogunwale18795a22014-12-03 11:38:33 -080079 static final String ATTR_TASK_AFFILIATION = "task_affiliation";
Craig Mautnera228ae92014-07-09 05:44:55 -070080 private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
81 private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
Winson Chungec396d62014-08-06 17:08:00 -070082 private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
Craig Mautnerdc00cbe2014-07-20 17:48:47 -070083 private static final String ATTR_CALLING_UID = "calling_uid";
84 private static final String ATTR_CALLING_PACKAGE = "calling_package";
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -080085 private static final String ATTR_RESIZEABLE = "resizeable";
Craig Mautner21d24a22014-04-23 11:45:37 -070086
87 private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
88
Craig Mautner0b633fc2014-07-23 10:42:18 -070089 static final boolean IGNORE_RETURN_TO_RECENTS = true;
90
Wale Ogunwale18795a22014-12-03 11:38:33 -080091 static final int INVALID_TASK_ID = -1;
92
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 final int taskId; // Unique identifier for this task.
Dianne Hackborn79228822014-09-16 11:11:23 -070094 String affinity; // The affinity name for this task, or null; may change identity.
95 String rootAffinity; // Initial base affinity, or null; does not change from initial root.
Dianne Hackborn91097de2014-04-04 18:02:06 -070096 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
97 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 Intent intent; // The original intent that started the task.
99 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700100 int effectiveUid; // The current effective uid of the identity of this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 ComponentName origActivity; // The non-alias activity component of the intent.
102 ComponentName realActivity; // The actual activity component that started the task.
Winson Chungffa2ec62014-07-03 15:54:42 -0700103 long firstActiveTime; // First time this task was active.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 long lastActiveTime; // Last time this task was active, including sleep.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700105 boolean inRecents; // Actually in the recents list?
106 boolean isAvailable; // Is the activity available to be launched?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 boolean rootWasReset; // True if the intent at the root of the task had
108 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700109 boolean autoRemoveRecents; // If true, we should automatically remove the task from
110 // recents when activity finishes
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700111 boolean askedCompatMode;// Have asked the user about compat mode for this task.
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700112 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 -0800113
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700114 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -0700115 int userId; // user for which this task was created
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800116
117 int numFullscreen; // Number of fullscreen activities.
118
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800119 boolean mResizeable; // Activities in the task resizeable. Based on the resizable setting of
120 // the root activity.
121
Winson Chung03a9bae2014-05-02 09:56:12 -0700122 // This represents the last resolved activity values for this task
123 // NOTE: This value needs to be persisted with each task
Craig Mautner648f69b2014-09-18 14:16:26 -0700124 TaskDescription lastTaskDescription = new TaskDescription();
Winson Chung03a9bae2014-05-02 09:56:12 -0700125
Craig Mautnerd2328952013-03-05 12:46:26 -0800126 /** List of all activities in the task arranged in history order */
Craig Mautner21d24a22014-04-23 11:45:37 -0700127 final ArrayList<ActivityRecord> mActivities;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800128
Craig Mautnerd2328952013-03-05 12:46:26 -0800129 /** Current stack */
130 ActivityStack stack;
131
Craig Mautner2c1faed2013-07-23 12:56:02 -0700132 /** Takes on same set of values as ActivityRecord.mActivityType */
Craig Mautner21d24a22014-04-23 11:45:37 -0700133 int taskType;
Craig Mautner1602ec22013-05-12 10:24:27 -0700134
Craig Mautner21d24a22014-04-23 11:45:37 -0700135 /** Takes on same value as first root activity */
136 boolean isPersistable = false;
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700137 int maxRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700138
139 /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for
140 * determining the order when restoring. Sign indicates whether last task movement was to front
141 * (positive) or back (negative). Absolute value indicates time. */
142 long mLastTimeMoved = System.currentTimeMillis();
143
Craig Mautner84984fa2014-06-19 11:19:20 -0700144 /** Indication of what to run next when task exits. Use ActivityRecord types.
145 * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the
146 * task stack. */
147 private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700148
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700149 /** If original intent did not allow relinquishing task identity, save that information */
150 boolean mNeverRelinquishIdentity = true;
151
Craig Mautner362449a2014-06-20 14:04:39 -0700152 // Used in the unique case where we are clearing the task in order to reuse it. In that case we
153 // do not want to delete the stack when the task goes empty.
154 boolean mReuseTask = false;
155
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700156 private Bitmap mLastThumbnail; // Last thumbnail captured for this item.
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700157 private final File mLastThumbnailFile; // File containing last thumbnail.
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700158 private final String mFilename;
159 CharSequence lastDescription; // Last description captured for this item.
160
Craig Mautnera228ae92014-07-09 05:44:55 -0700161 int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent.
Winson Chungec396d62014-08-06 17:08:00 -0700162 int mAffiliatedTaskColor; // color of the parent task affiliation.
Craig Mautnera228ae92014-07-09 05:44:55 -0700163 TaskRecord mPrevAffiliate; // previous task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800164 int mPrevAffiliateTaskId = INVALID_TASK_ID; // previous id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700165 TaskRecord mNextAffiliate; // next task in affiliated chain.
Wale Ogunwale18795a22014-12-03 11:38:33 -0800166 int mNextAffiliateTaskId = INVALID_TASK_ID; // next id for persistence.
Craig Mautnera228ae92014-07-09 05:44:55 -0700167
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700168 // For relaunching the task from recents as though it was launched by the original launcher.
169 int mCallingUid;
170 String mCallingPackage;
171
Craig Mautner21d24a22014-04-23 11:45:37 -0700172 final ActivityManagerService mService;
173
174 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Dianne Hackborn91097de2014-04-04 18:02:06 -0700175 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700176 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700177 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
178 TaskPersister.IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700179 mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 taskId = _taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700181 mAffiliatedTaskId = _taskId;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700182 voiceSession = _voiceSession;
183 voiceInteractor = _voiceInteractor;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700184 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800185 mActivities = new ArrayList<>();
Martijn Coenend4a69702014-06-30 11:12:17 -0700186 setIntent(_intent, info);
Craig Mautner21d24a22014-04-23 11:45:37 -0700187 }
188
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700189 TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
Craig Mautner648f69b2014-09-18 14:16:26 -0700190 TaskDescription _taskDescription) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700191 mService = service;
192 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
193 TaskPersister.IMAGE_EXTENSION;
194 mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename);
195 taskId = _taskId;
196 mAffiliatedTaskId = _taskId;
197 voiceSession = null;
198 voiceInteractor = null;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700199 isAvailable = true;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800200 mActivities = new ArrayList<>();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700201 setIntent(_intent, info);
202
203 taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
204 isPersistable = true;
205 mCallingUid = info.applicationInfo.uid;
206 mCallingPackage = info.packageName;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700207 // Clamp to [1, max].
208 maxRecents = Math.min(Math.max(info.maxRecents, 1),
209 ActivityManager.getMaxAppRecentsLimitStatic());
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700210
211 taskType = APPLICATION_ACTIVITY_TYPE;
212 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
213 userId = UserHandle.getUserId(info.applicationInfo.uid);
214 lastTaskDescription = _taskDescription;
215 mCallingUid = info.applicationInfo.uid;
216 mCallingPackage = info.packageName;
217 }
218
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800219 private TaskRecord(ActivityManagerService service, int _taskId, Intent _intent,
220 Intent _affinityIntent, String _affinity, String _rootAffinity,
221 ComponentName _realActivity, ComponentName _origActivity, boolean _rootWasReset,
222 boolean _autoRemoveRecents, boolean _askedCompatMode, int _taskType, int _userId,
223 int _effectiveUid, String _lastDescription, ArrayList<ActivityRecord> activities,
224 long _firstActiveTime, long _lastActiveTime, long lastTimeMoved,
225 boolean neverRelinquishIdentity, TaskDescription _lastTaskDescription,
226 int taskAffiliation, int prevTaskId, int nextTaskId, int taskAffiliationColor,
227 int callingUid, String callingPackage, boolean resizeable) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700228 mService = service;
Craig Mautnera228ae92014-07-09 05:44:55 -0700229 mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX +
230 TaskPersister.IMAGE_EXTENSION;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700231 mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename);
Craig Mautner21d24a22014-04-23 11:45:37 -0700232 taskId = _taskId;
233 intent = _intent;
234 affinityIntent = _affinityIntent;
235 affinity = _affinity;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800236 rootAffinity = _rootAffinity;
Craig Mautner21d24a22014-04-23 11:45:37 -0700237 voiceSession = null;
238 voiceInteractor = null;
239 realActivity = _realActivity;
240 origActivity = _origActivity;
241 rootWasReset = _rootWasReset;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700242 isAvailable = true;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700243 autoRemoveRecents = _autoRemoveRecents;
Craig Mautner21d24a22014-04-23 11:45:37 -0700244 askedCompatMode = _askedCompatMode;
245 taskType = _taskType;
Craig Mautner84984fa2014-06-19 11:19:20 -0700246 mTaskToReturnTo = HOME_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700247 userId = _userId;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700248 effectiveUid = _effectiveUid;
Winson Chungffa2ec62014-07-03 15:54:42 -0700249 firstActiveTime = _firstActiveTime;
Winson Chungf1fbd772014-06-24 18:06:58 -0700250 lastActiveTime = _lastActiveTime;
Craig Mautner21d24a22014-04-23 11:45:37 -0700251 lastDescription = _lastDescription;
252 mActivities = activities;
253 mLastTimeMoved = lastTimeMoved;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700254 mNeverRelinquishIdentity = neverRelinquishIdentity;
Winson Chung2cb86c72014-06-25 12:03:30 -0700255 lastTaskDescription = _lastTaskDescription;
Craig Mautnera228ae92014-07-09 05:44:55 -0700256 mAffiliatedTaskId = taskAffiliation;
Winson Chungec396d62014-08-06 17:08:00 -0700257 mAffiliatedTaskColor = taskAffiliationColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700258 mPrevAffiliateTaskId = prevTaskId;
259 mNextAffiliateTaskId = nextTaskId;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700260 mCallingUid = callingUid;
261 mCallingPackage = callingPackage;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800262 mResizeable = resizeable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 }
264
265 void touchActiveTime() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700266 lastActiveTime = System.currentTimeMillis();
Winson Chungffa2ec62014-07-03 15:54:42 -0700267 if (firstActiveTime == 0) {
268 firstActiveTime = lastActiveTime;
269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 long getInactiveDuration() {
Craig Mautner494f6bdd2014-07-21 11:17:46 -0700273 return System.currentTimeMillis() - lastActiveTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700275
Winson Chungfee26772014-08-05 12:21:52 -0700276 /** Sets the original intent, and the calling uid and package. */
277 void setIntent(ActivityRecord r) {
278 setIntent(r.intent, r.info);
279 mCallingUid = r.launchedFromUid;
280 mCallingPackage = r.launchedFromPackage;
281 }
282
283 /** Sets the original intent, _without_ updating the calling uid or package. */
284 private void setIntent(Intent _intent, ActivityInfo info) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700285 if (intent == null) {
286 mNeverRelinquishIdentity =
287 (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0;
288 } else if (mNeverRelinquishIdentity) {
289 return;
290 }
291
292 affinity = info.taskAffinity;
Dianne Hackborn79228822014-09-16 11:11:23 -0700293 if (intent == null) {
294 // If this task already has an intent associated with it, don't set the root
295 // affinity -- we don't want it changing after initially set, but the initially
296 // set value may be null.
297 rootAffinity = affinity;
298 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700299 effectiveUid = info.applicationInfo.uid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700300 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800303 if (_intent != null) {
304 // If this Intent has a selector, we want to clear it for the
305 // recent task since it is not relevant if the user later wants
306 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700307 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800308 _intent = new Intent(_intent);
309 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700310 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800311 }
312 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800313 if (ActivityManagerService.DEBUG_TASKS) Slog.v(TAG,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700314 "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 intent = _intent;
316 realActivity = _intent != null ? _intent.getComponent() : null;
317 origActivity = null;
318 } else {
319 ComponentName targetComponent = new ComponentName(
320 info.packageName, info.targetActivity);
321 if (_intent != null) {
322 Intent targetIntent = new Intent(_intent);
323 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800324 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700325 targetIntent.setSourceBounds(null);
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800326 if (ActivityManagerService.DEBUG_TASKS) Slog.v(TAG,
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700327 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 intent = targetIntent;
329 realActivity = targetComponent;
330 origActivity = _intent.getComponent();
331 } else {
332 intent = null;
333 realActivity = targetComponent;
334 origActivity = new ComponentName(info.packageName, info.name);
335 }
336 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700337
Craig Mautner47b20ba2014-09-17 17:23:44 -0700338 final int intentFlags = intent == null ? 0 : intent.getFlags();
339 if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 // Once we are set to an Intent with this flag, we count this
341 // task as having a true root activity.
342 rootWasReset = true;
343 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700344
Dianne Hackborn09233282014-04-30 11:33:59 -0700345 userId = UserHandle.getUserId(info.applicationInfo.uid);
Craig Mautner41db4a72014-05-07 17:20:56 -0700346 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700347 // If the activity itself has requested auto-remove, then just always do it.
348 autoRemoveRecents = true;
Craig Mautner47b20ba2014-09-17 17:23:44 -0700349 } else if ((intentFlags & (Intent.FLAG_ACTIVITY_NEW_DOCUMENT
350 | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS)) == Intent.FLAG_ACTIVITY_NEW_DOCUMENT) {
Dianne Hackborn13420f22014-07-18 15:43:56 -0700351 // If the caller has not asked for the document to be retained, then we may
352 // want to turn on auto-remove, depending on whether the target has set its
353 // own document launch mode.
354 if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) {
355 autoRemoveRecents = false;
356 } else {
357 autoRemoveRecents = true;
358 }
359 } else {
360 autoRemoveRecents = false;
Craig Mautner41db4a72014-05-07 17:20:56 -0700361 }
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800362 mResizeable = info.resizeable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800364
Craig Mautner84984fa2014-06-19 11:19:20 -0700365 void setTaskToReturnTo(int taskToReturnTo) {
Craig Mautner0b633fc2014-07-23 10:42:18 -0700366 if (IGNORE_RETURN_TO_RECENTS && taskToReturnTo == RECENTS_ACTIVITY_TYPE) {
367 taskToReturnTo = HOME_ACTIVITY_TYPE;
368 }
Craig Mautner84984fa2014-06-19 11:19:20 -0700369 mTaskToReturnTo = taskToReturnTo;
370 }
371
372 int getTaskToReturnTo() {
373 return mTaskToReturnTo;
374 }
375
Craig Mautnera228ae92014-07-09 05:44:55 -0700376 void setPrevAffiliate(TaskRecord prevAffiliate) {
377 mPrevAffiliate = prevAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800378 mPrevAffiliateTaskId = prevAffiliate == null ? INVALID_TASK_ID : prevAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700379 }
380
381 void setNextAffiliate(TaskRecord nextAffiliate) {
382 mNextAffiliate = nextAffiliate;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800383 mNextAffiliateTaskId = nextAffiliate == null ? INVALID_TASK_ID : nextAffiliate.taskId;
Craig Mautnera228ae92014-07-09 05:44:55 -0700384 }
385
386 // Close up recents linked list.
387 void closeRecentsChain() {
388 if (mPrevAffiliate != null) {
389 mPrevAffiliate.setNextAffiliate(mNextAffiliate);
390 }
391 if (mNextAffiliate != null) {
392 mNextAffiliate.setPrevAffiliate(mPrevAffiliate);
393 }
394 setPrevAffiliate(null);
395 setNextAffiliate(null);
396 }
397
Winson Chung740c3ac2014-11-12 16:14:38 -0800398 void removedFromRecents() {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700399 disposeThumbnail();
400 closeRecentsChain();
401 if (inRecents) {
402 inRecents = false;
Winson Chung740c3ac2014-11-12 16:14:38 -0800403 mService.notifyTaskPersisterLocked(this, false);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700404 }
405 }
406
Craig Mautnera228ae92014-07-09 05:44:55 -0700407 void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
408 closeRecentsChain();
409 mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId;
Winson Chungec396d62014-08-06 17:08:00 -0700410 mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor;
Craig Mautnera228ae92014-07-09 05:44:55 -0700411 // Find the end
412 while (taskToAffiliateWith.mNextAffiliate != null) {
413 final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate;
414 if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) {
415 Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId="
416 + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId);
417 if (nextRecents.mPrevAffiliate == taskToAffiliateWith) {
418 nextRecents.setPrevAffiliate(null);
419 }
420 taskToAffiliateWith.setNextAffiliate(null);
421 break;
422 }
423 taskToAffiliateWith = nextRecents;
424 }
425 taskToAffiliateWith.setNextAffiliate(this);
426 setPrevAffiliate(taskToAffiliateWith);
427 setNextAffiliate(null);
428 }
429
Winson Chung096f36b2014-08-20 15:39:01 -0700430 /**
431 * Sets the last thumbnail.
432 * @return whether the thumbnail was set
433 */
434 boolean setLastThumbnail(Bitmap thumbnail) {
435 if (mLastThumbnail != thumbnail) {
436 mLastThumbnail = thumbnail;
437 if (thumbnail == null) {
438 if (mLastThumbnailFile != null) {
439 mLastThumbnailFile.delete();
440 }
441 } else {
442 mService.mTaskPersister.saveImage(thumbnail, mFilename);
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700443 }
Winson Chung096f36b2014-08-20 15:39:01 -0700444 return true;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700445 }
Winson Chung096f36b2014-08-20 15:39:01 -0700446 return false;
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700447 }
448
449 void getLastThumbnail(TaskThumbnail thumbs) {
450 thumbs.mainThumbnail = mLastThumbnail;
451 thumbs.thumbnailFileDescriptor = null;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700452 if (mLastThumbnail == null) {
Craig Mautner648f69b2014-09-18 14:16:26 -0700453 thumbs.mainThumbnail = mService.mTaskPersister.getImageFromWriteQueue(mFilename);
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700454 }
Winson Chung096f36b2014-08-20 15:39:01 -0700455 // Only load the thumbnail file if we don't have a thumbnail
456 if (thumbs.mainThumbnail == null && mLastThumbnailFile.exists()) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700457 try {
458 thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile,
459 ParcelFileDescriptor.MODE_READ_ONLY);
460 } catch (IOException e) {
Dianne Hackborn9844d292013-10-04 16:44:22 -0700461 }
462 }
463 }
464
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700465 void freeLastThumbnail() {
466 mLastThumbnail = null;
467 }
468
469 void disposeThumbnail() {
470 mLastThumbnail = null;
471 lastDescription = null;
472 }
473
Winson Chung1147c402014-05-14 11:05:00 -0700474 /** Returns the intent for the root activity for this task */
475 Intent getBaseIntent() {
476 return intent != null ? intent : affinityIntent;
477 }
478
Winson Chung3b3f4642014-04-22 10:08:18 -0700479 /** Returns the first non-finishing activity from the root. */
480 ActivityRecord getRootActivity() {
481 for (int i = 0; i < mActivities.size(); i++) {
482 final ActivityRecord r = mActivities.get(i);
483 if (r.finishing) {
484 continue;
485 }
486 return r;
487 }
488 return null;
489 }
490
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800491 ActivityRecord getTopActivity() {
492 for (int i = mActivities.size() - 1; i >= 0; --i) {
493 final ActivityRecord r = mActivities.get(i);
494 if (r.finishing) {
495 continue;
496 }
497 return r;
498 }
499 return null;
500 }
501
Craig Mautner6b74cb52013-09-27 17:02:21 -0700502 ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700503 if (stack != null) {
504 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
505 ActivityRecord r = mActivities.get(activityNdx);
506 if (!r.finishing && r != notTop && stack.okToShowLocked(r)) {
507 return r;
508 }
Craig Mautner6b74cb52013-09-27 17:02:21 -0700509 }
510 }
511 return null;
512 }
513
Craig Mautner3b475fe2013-12-16 15:58:31 -0800514 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
515 final void setFrontOfTask() {
516 boolean foundFront = false;
517 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800518 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800519 final ActivityRecord r = mActivities.get(activityNdx);
520 if (foundFront || r.finishing) {
521 r.frontOfTask = false;
522 } else {
523 r.frontOfTask = true;
524 // Set frontOfTask false for every following activity.
525 foundFront = true;
526 }
527 }
Craig Mautner9587ee02014-06-23 15:00:10 +0000528 if (!foundFront && numActivities > 0) {
529 // All activities of this task are finishing. As we ought to have a frontOfTask
530 // activity, make the bottom activity front.
531 mActivities.get(0).frontOfTask = true;
532 }
Craig Mautner3b475fe2013-12-16 15:58:31 -0800533 }
534
Craig Mautnerde4ef022013-04-07 19:01:33 -0700535 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800536 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700537 */
538 final void moveActivityToFrontLocked(ActivityRecord newTop) {
539 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop
540 + " to stack at top", new RuntimeException("here").fillInStackTrace());
541
Craig Mautnerde4ef022013-04-07 19:01:33 -0700542 mActivities.remove(newTop);
543 mActivities.add(newTop);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700544 updateEffectiveIntent();
Craig Mautner3b475fe2013-12-16 15:58:31 -0800545
546 setFrontOfTask();
Craig Mautnerde4ef022013-04-07 19:01:33 -0700547 }
548
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800549 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800550 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800551 }
552
553 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700554 addActivityAtIndex(mActivities.size(), r);
555 }
556
557 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700558 // 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 -0800559 if (!mActivities.remove(r) && r.fullscreen) {
560 // Was not previously in list.
561 numFullscreen++;
562 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700563 // Only set this based on the first activity
564 if (mActivities.isEmpty()) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700565 taskType = r.mActivityType;
566 isPersistable = r.isPersistable();
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700567 mCallingUid = r.launchedFromUid;
568 mCallingPackage = r.launchedFromPackage;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700569 // Clamp to [1, max].
570 maxRecents = Math.min(Math.max(r.info.maxRecents, 1),
571 ActivityManager.getMaxAppRecentsLimitStatic());
Craig Mautner2c1faed2013-07-23 12:56:02 -0700572 } else {
573 // Otherwise make all added activities match this one.
Craig Mautner21d24a22014-04-23 11:45:37 -0700574 r.mActivityType = taskType;
Craig Mautner78733002013-06-10 13:54:49 -0700575 }
Craig Mautner77878772013-03-04 19:46:24 -0800576 mActivities.add(index, r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700577 updateEffectiveIntent();
Craig Mautner21d24a22014-04-23 11:45:37 -0700578 if (r.isPersistable()) {
579 mService.notifyTaskPersisterLocked(this, false);
580 }
Craig Mautner77878772013-03-04 19:46:24 -0800581 }
582
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800583 /** @return true if this was the last activity in the task */
584 boolean removeActivity(ActivityRecord r) {
585 if (mActivities.remove(r) && r.fullscreen) {
586 // Was previously in list.
587 numFullscreen--;
588 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700589 if (r.isPersistable()) {
590 mService.notifyTaskPersisterLocked(this, false);
591 }
Craig Mautner41326202014-06-20 14:38:21 -0700592 if (mActivities.isEmpty()) {
Craig Mautner5afcd4d2014-06-21 18:11:33 -0700593 return !mReuseTask;
Craig Mautner41326202014-06-20 14:38:21 -0700594 }
595 updateEffectiveIntent();
596 return false;
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800597 }
598
Craig Mautner41db4a72014-05-07 17:20:56 -0700599 boolean autoRemoveFromRecents() {
Dianne Hackbornd38aed82014-06-10 21:36:35 -0700600 // We will automatically remove the task either if it has explicitly asked for
601 // this, or it is empty and has never contained an activity that got shown to
602 // the user.
Dianne Hackborn13420f22014-07-18 15:43:56 -0700603 return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible);
Craig Mautner41db4a72014-05-07 17:20:56 -0700604 }
605
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700606 /**
607 * Completely remove all activities associated with an existing
608 * task starting at a specified index.
609 */
610 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700611 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700612 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700613 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700614 if (r.finishing) {
615 continue;
616 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700617 if (stack == null) {
618 // Task was restored from persistent storage.
619 r.takeFromHistory();
620 mActivities.remove(activityNdx);
621 --activityNdx;
622 --numActivities;
Todd Kennedy539db512014-12-15 09:57:55 -0800623 } else if (stack.finishActivityLocked(
624 r, Activity.RESULT_CANCELED, null, "clear-task-index", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700625 --activityNdx;
626 --numActivities;
627 }
628 }
629 }
630
631 /**
632 * Completely remove all activities associated with an existing task.
633 */
634 final void performClearTaskLocked() {
Craig Mautner362449a2014-06-20 14:04:39 -0700635 mReuseTask = true;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700636 performClearTaskAtIndexLocked(0);
Craig Mautner362449a2014-06-20 14:04:39 -0700637 mReuseTask = false;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700638 }
639
640 /**
641 * Perform clear operation as requested by
642 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
643 * stack to the given task, then look for
644 * an instance of that activity in the stack and, if found, finish all
645 * activities on top of it and return the instance.
646 *
647 * @param newR Description of the new activity being started.
648 * @return Returns the old activity that should be continued to be used,
649 * or null if none was found.
650 */
651 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700652 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700653 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700654 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700655 if (r.finishing) {
656 continue;
657 }
658 if (r.realActivity.equals(newR.realActivity)) {
659 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -0700660 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700661
662 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700663 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700664 if (r.finishing) {
665 continue;
666 }
667 ActivityOptions opts = r.takeOptionsLocked();
668 if (opts != null) {
669 ret.updateOptionsLocked(opts);
670 }
Wale Ogunwale7d701172015-03-11 15:36:30 -0700671 if (stack != null && stack.finishActivityLocked(
Todd Kennedy539db512014-12-15 09:57:55 -0800672 r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700673 --activityNdx;
674 --numActivities;
675 }
676 }
677
678 // Finally, if this is a normal launch mode (that is, not
679 // expecting onNewIntent()), then we will finish the current
680 // instance of the activity so a new fresh one can be started.
681 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
682 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
683 if (!ret.finishing) {
Wale Ogunwale7d701172015-03-11 15:36:30 -0700684 if (stack != null) {
685 stack.finishActivityLocked(
686 ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
687 }
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700688 return null;
689 }
690 }
691
692 return ret;
693 }
694 }
695
696 return null;
697 }
698
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700699 public TaskThumbnail getTaskThumbnailLocked() {
Craig Mautner21d24a22014-04-23 11:45:37 -0700700 if (stack != null) {
701 final ActivityRecord resumedActivity = stack.mResumedActivity;
702 if (resumedActivity != null && resumedActivity.task == this) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700703 final Bitmap thumbnail = stack.screenshotActivities(resumedActivity);
704 setLastThumbnail(thumbnail);
Craig Mautner21d24a22014-04-23 11:45:37 -0700705 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700706 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700707 final TaskThumbnail taskThumbnail = new TaskThumbnail();
708 getLastThumbnail(taskThumbnail);
709 return taskThumbnail;
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700710 }
711
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700712 public void removeTaskActivitiesLocked() {
713 // Just remove the entire task.
714 performClearTaskAtIndexLocked(0);
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700715 }
716
Craig Mautnera82aa092013-09-13 15:34:08 -0700717 boolean isHomeTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700718 return taskType == HOME_ACTIVITY_TYPE;
Craig Mautnera82aa092013-09-13 15:34:08 -0700719 }
720
Craig Mautner86d67a42013-05-14 10:34:38 -0700721 boolean isApplicationTask() {
Craig Mautner84984fa2014-06-19 11:19:20 -0700722 return taskType == APPLICATION_ACTIVITY_TYPE;
723 }
724
725 boolean isOverHomeStack() {
726 return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -0700727 }
728
Craig Mautner525f3d92013-05-07 14:01:50 -0700729 /**
730 * Find the activity in the history stack within the given task. Returns
731 * the index within the history at which it's found, or < 0 if not found.
732 */
733 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
734 final ComponentName realActivity = r.realActivity;
735 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
736 ActivityRecord candidate = mActivities.get(activityNdx);
737 if (candidate.finishing) {
738 continue;
739 }
740 if (candidate.realActivity.equals(realActivity)) {
741 return candidate;
742 }
743 }
744 return null;
745 }
746
Winson Chunga449dc02014-05-16 11:15:04 -0700747 /** Updates the last task description values. */
748 void updateTaskDescription() {
749 // Traverse upwards looking for any break between main task activities and
750 // utility activities.
751 int activityNdx;
752 final int numActivities = mActivities.size();
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700753 final boolean relinquish = numActivities == 0 ? false :
754 (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0;
Winson Chunga449dc02014-05-16 11:15:04 -0700755 for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
Craig Mautner21d24a22014-04-23 11:45:37 -0700756 ++activityNdx) {
Winson Chunga449dc02014-05-16 11:15:04 -0700757 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700758 if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
759 // This will be the top activity for determining taskDescription. Pre-inc to
760 // overcome initial decrement below.
761 ++activityNdx;
762 break;
763 }
Winson Chunga449dc02014-05-16 11:15:04 -0700764 if (r.intent != null &&
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700765 (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
Winson Chunga449dc02014-05-16 11:15:04 -0700766 break;
767 }
768 }
769 if (activityNdx > 0) {
770 // Traverse downwards starting below break looking for set label, icon.
771 // Note that if there are activities in the task but none of them set the
772 // recent activity values, then we do not fall back to the last set
773 // values in the TaskRecord.
774 String label = null;
Craig Mautner648f69b2014-09-18 14:16:26 -0700775 String iconFilename = null;
Winson Chunga449dc02014-05-16 11:15:04 -0700776 int colorPrimary = 0;
777 for (--activityNdx; activityNdx >= 0; --activityNdx) {
778 final ActivityRecord r = mActivities.get(activityNdx);
779 if (r.taskDescription != null) {
780 if (label == null) {
781 label = r.taskDescription.getLabel();
782 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700783 if (iconFilename == null) {
784 iconFilename = r.taskDescription.getIconFilename();
Winson Chunga449dc02014-05-16 11:15:04 -0700785 }
786 if (colorPrimary == 0) {
787 colorPrimary = r.taskDescription.getPrimaryColor();
Winson Chunga449dc02014-05-16 11:15:04 -0700788 }
789 }
790 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700791 lastTaskDescription = new TaskDescription(label, colorPrimary, iconFilename);
Winson Chungec396d62014-08-06 17:08:00 -0700792 // Update the task affiliation color if we are the parent of the group
793 if (taskId == mAffiliatedTaskId) {
794 mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor();
795 }
Winson Chunga449dc02014-05-16 11:15:04 -0700796 }
797 }
798
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700799 int findEffectiveRootIndex() {
Craig Mautner4767f4b2014-09-18 15:38:33 -0700800 int effectiveNdx = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700801 final int topActivityNdx = mActivities.size() - 1;
Dianne Hackborn39569af2014-09-23 10:56:58 -0700802 for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700803 final ActivityRecord r = mActivities.get(activityNdx);
804 if (r.finishing) {
805 continue;
806 }
Craig Mautner4767f4b2014-09-18 15:38:33 -0700807 effectiveNdx = activityNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700808 if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
809 break;
810 }
811 }
Craig Mautner4767f4b2014-09-18 15:38:33 -0700812 return effectiveNdx;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700813 }
814
815 void updateEffectiveIntent() {
816 final int effectiveRootIndex = findEffectiveRootIndex();
817 final ActivityRecord r = mActivities.get(effectiveRootIndex);
Winson Chungfee26772014-08-05 12:21:52 -0700818 setIntent(r);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700819 }
820
Craig Mautner21d24a22014-04-23 11:45:37 -0700821 void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700822 if (ActivityManagerService.DEBUG_RECENTS) Slog.i(TAG, "Saving task=" + this);
Craig Mautner21d24a22014-04-23 11:45:37 -0700823
824 out.attribute(null, ATTR_TASKID, String.valueOf(taskId));
825 if (realActivity != null) {
826 out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString());
827 }
828 if (origActivity != null) {
829 out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString());
830 }
Dianne Hackborn79228822014-09-16 11:11:23 -0700831 // Write affinity, and root affinity if it is different from affinity.
832 // We use the special string "@" for a null root affinity, so we can identify
833 // later whether we were given a root affinity or should just make it the
834 // same as the affinity.
Craig Mautner21d24a22014-04-23 11:45:37 -0700835 if (affinity != null) {
836 out.attribute(null, ATTR_AFFINITY, affinity);
Dianne Hackborn79228822014-09-16 11:11:23 -0700837 if (!affinity.equals(rootAffinity)) {
838 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
839 }
840 } else if (rootAffinity != null) {
841 out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
Craig Mautner21d24a22014-04-23 11:45:37 -0700842 }
843 out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
Dianne Hackborn13420f22014-07-18 15:43:56 -0700844 out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
Craig Mautner21d24a22014-04-23 11:45:37 -0700845 out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
846 out.attribute(null, ATTR_USERID, String.valueOf(userId));
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700847 out.attribute(null, ATTR_EFFECTIVE_UID, String.valueOf(effectiveUid));
Craig Mautner21d24a22014-04-23 11:45:37 -0700848 out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType));
Winson Chungffa2ec62014-07-03 15:54:42 -0700849 out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime));
Winson Chungf1fbd772014-06-24 18:06:58 -0700850 out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime));
Craig Mautner21d24a22014-04-23 11:45:37 -0700851 out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved));
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700852 out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity));
Craig Mautner21d24a22014-04-23 11:45:37 -0700853 if (lastDescription != null) {
854 out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString());
855 }
Winson Chung2cb86c72014-06-25 12:03:30 -0700856 if (lastTaskDescription != null) {
Craig Mautner648f69b2014-09-18 14:16:26 -0700857 lastTaskDescription.saveToXml(out);
Winson Chung2cb86c72014-06-25 12:03:30 -0700858 }
Winson Chungec396d62014-08-06 17:08:00 -0700859 out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor));
Craig Mautnera228ae92014-07-09 05:44:55 -0700860 out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId));
861 out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId));
862 out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId));
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700863 out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid));
864 out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage);
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800865 out.attribute(null, ATTR_RESIZEABLE, String.valueOf(mResizeable));
Winson Chung2cb86c72014-06-25 12:03:30 -0700866
Craig Mautner21d24a22014-04-23 11:45:37 -0700867 if (affinityIntent != null) {
868 out.startTag(null, TAG_AFFINITYINTENT);
869 affinityIntent.saveToXml(out);
870 out.endTag(null, TAG_AFFINITYINTENT);
871 }
872
873 out.startTag(null, TAG_INTENT);
874 intent.saveToXml(out);
875 out.endTag(null, TAG_INTENT);
876
877 final ArrayList<ActivityRecord> activities = mActivities;
878 final int numActivities = activities.size();
879 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
880 final ActivityRecord r = activities.get(activityNdx);
Craig Mautner43e52ed2014-06-16 17:18:52 -0700881 if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() ||
882 ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) &&
883 activityNdx > 0) {
Craig Mautnerf357c0c2014-06-09 09:23:27 -0700884 // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET).
Craig Mautner21d24a22014-04-23 11:45:37 -0700885 break;
886 }
887 out.startTag(null, TAG_ACTIVITY);
888 r.saveToXml(out);
889 out.endTag(null, TAG_ACTIVITY);
890 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700891 }
892
893 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
894 throws IOException, XmlPullParserException {
Wale Ogunwale18795a22014-12-03 11:38:33 -0800895 return restoreFromXml(in, stackSupervisor, INVALID_TASK_ID);
896 }
897 static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor,
898 int inTaskId) throws IOException, XmlPullParserException {
Craig Mautner21d24a22014-04-23 11:45:37 -0700899 Intent intent = null;
900 Intent affinityIntent = null;
901 ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>();
902 ComponentName realActivity = null;
903 ComponentName origActivity = null;
904 String affinity = null;
Dianne Hackborn79228822014-09-16 11:11:23 -0700905 String rootAffinity = null;
906 boolean hasRootAffinity = false;
Craig Mautner21d24a22014-04-23 11:45:37 -0700907 boolean rootHasReset = false;
Dianne Hackborn13420f22014-07-18 15:43:56 -0700908 boolean autoRemoveRecents = false;
Craig Mautner21d24a22014-04-23 11:45:37 -0700909 boolean askedCompatMode = false;
910 int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner21d24a22014-04-23 11:45:37 -0700911 int userId = 0;
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700912 int effectiveUid = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700913 String lastDescription = null;
Winson Chungffa2ec62014-07-03 15:54:42 -0700914 long firstActiveTime = -1;
Winson Chung2cb86c72014-06-25 12:03:30 -0700915 long lastActiveTime = -1;
Craig Mautner21d24a22014-04-23 11:45:37 -0700916 long lastTimeOnTop = 0;
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700917 boolean neverRelinquishIdentity = true;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800918 int taskId = inTaskId;
Craig Mautner21d24a22014-04-23 11:45:37 -0700919 final int outerDepth = in.getDepth();
Craig Mautner648f69b2014-09-18 14:16:26 -0700920 TaskDescription taskDescription = new TaskDescription();
Wale Ogunwale18795a22014-12-03 11:38:33 -0800921 int taskAffiliation = INVALID_TASK_ID;
Winson Chungec396d62014-08-06 17:08:00 -0700922 int taskAffiliationColor = 0;
Wale Ogunwale18795a22014-12-03 11:38:33 -0800923 int prevTaskId = INVALID_TASK_ID;
924 int nextTaskId = INVALID_TASK_ID;
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700925 int callingUid = -1;
926 String callingPackage = "";
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800927 boolean resizeable = false;
Craig Mautner21d24a22014-04-23 11:45:37 -0700928
929 for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
930 final String attrName = in.getAttributeName(attrNdx);
931 final String attrValue = in.getAttributeValue(attrNdx);
Wale Ogunwale18795a22014-12-03 11:38:33 -0800932 if (DEBUG_PERSISTER || DEBUG_RESTORER) Slog.d(TaskPersister.TAG,
933 "TaskRecord: attribute name=" + attrName + " value=" + attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700934 if (ATTR_TASKID.equals(attrName)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -0800935 if (taskId == INVALID_TASK_ID) taskId = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700936 } else if (ATTR_REALACTIVITY.equals(attrName)) {
937 realActivity = ComponentName.unflattenFromString(attrValue);
938 } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
939 origActivity = ComponentName.unflattenFromString(attrValue);
940 } else if (ATTR_AFFINITY.equals(attrName)) {
941 affinity = attrValue;
Dianne Hackborn79228822014-09-16 11:11:23 -0700942 } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
943 rootAffinity = attrValue;
944 hasRootAffinity = true;
Craig Mautner21d24a22014-04-23 11:45:37 -0700945 } else if (ATTR_ROOTHASRESET.equals(attrName)) {
946 rootHasReset = Boolean.valueOf(attrValue);
Dianne Hackborn13420f22014-07-18 15:43:56 -0700947 } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
948 autoRemoveRecents = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700949 } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
950 askedCompatMode = Boolean.valueOf(attrValue);
951 } else if (ATTR_USERID.equals(attrName)) {
952 userId = Integer.valueOf(attrValue);
Dianne Hackborn885fbe52014-08-23 15:23:58 -0700953 } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
954 effectiveUid = Integer.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700955 } else if (ATTR_TASKTYPE.equals(attrName)) {
956 taskType = Integer.valueOf(attrValue);
Winson Chungffa2ec62014-07-03 15:54:42 -0700957 } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
958 firstActiveTime = Long.valueOf(attrValue);
Winson Chungf1fbd772014-06-24 18:06:58 -0700959 } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
960 lastActiveTime = Long.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700961 } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
962 lastDescription = attrValue;
963 } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
964 lastTimeOnTop = Long.valueOf(attrValue);
Craig Mautner9d4e9bc2014-06-18 18:34:56 -0700965 } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
966 neverRelinquishIdentity = Boolean.valueOf(attrValue);
Craig Mautner648f69b2014-09-18 14:16:26 -0700967 } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
968 taskDescription.restoreFromXml(attrName, attrValue);
Craig Mautnera228ae92014-07-09 05:44:55 -0700969 } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
970 taskAffiliation = Integer.valueOf(attrValue);
971 } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
972 prevTaskId = Integer.valueOf(attrValue);
973 } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
974 nextTaskId = Integer.valueOf(attrValue);
Winson Chungec396d62014-08-06 17:08:00 -0700975 } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
976 taskAffiliationColor = Integer.valueOf(attrValue);
Craig Mautnerdc00cbe2014-07-20 17:48:47 -0700977 } else if (ATTR_CALLING_UID.equals(attrName)) {
978 callingUid = Integer.valueOf(attrValue);
979 } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
980 callingPackage = attrValue;
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -0800981 } else if (ATTR_RESIZEABLE.equals(attrName)) {
982 resizeable = Boolean.valueOf(attrValue);
Craig Mautner21d24a22014-04-23 11:45:37 -0700983 } else {
984 Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
985 }
986 }
987
988 int event;
989 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
990 (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
991 if (event == XmlPullParser.START_TAG) {
992 final String name = in.getName();
Wale Ogunwale18795a22014-12-03 11:38:33 -0800993 if (DEBUG_PERSISTER || DEBUG_RESTORER)
994 Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -0700995 if (TAG_AFFINITYINTENT.equals(name)) {
996 affinityIntent = Intent.restoreFromXml(in);
997 } else if (TAG_INTENT.equals(name)) {
998 intent = Intent.restoreFromXml(in);
999 } else if (TAG_ACTIVITY.equals(name)) {
Wale Ogunwale18795a22014-12-03 11:38:33 -08001000 ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
1001 if (DEBUG_PERSISTER || DEBUG_RESTORER)
1002 Slog.d(TaskPersister.TAG, "TaskRecord: activity=" + activity);
Craig Mautner21d24a22014-04-23 11:45:37 -07001003 if (activity != null) {
1004 activities.add(activity);
1005 }
1006 } else {
1007 Slog.e(TAG, "restoreTask: Unexpected name=" + name);
1008 XmlUtils.skipCurrentTag(in);
1009 }
1010 }
1011 }
Dianne Hackborn79228822014-09-16 11:11:23 -07001012 if (!hasRootAffinity) {
1013 rootAffinity = affinity;
1014 } else if ("@".equals(rootAffinity)) {
1015 rootAffinity = null;
1016 }
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001017 if (effectiveUid <= 0) {
1018 Intent checkIntent = intent != null ? intent : affinityIntent;
1019 effectiveUid = 0;
1020 if (checkIntent != null) {
1021 IPackageManager pm = AppGlobals.getPackageManager();
1022 try {
1023 ApplicationInfo ai = pm.getApplicationInfo(
1024 checkIntent.getComponent().getPackageName(),
1025 PackageManager.GET_UNINSTALLED_PACKAGES
1026 | PackageManager.GET_DISABLED_COMPONENTS, userId);
1027 if (ai != null) {
1028 effectiveUid = ai.uid;
1029 }
1030 } catch (RemoteException e) {
1031 }
1032 }
1033 Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent
1034 + ": effectiveUid=" + effectiveUid);
1035 }
1036
Craig Mautner21d24a22014-04-23 11:45:37 -07001037 final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
Dianne Hackborn79228822014-09-16 11:11:23 -07001038 affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001039 autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,
1040 activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
Winson Chungec396d62014-08-06 17:08:00 -07001041 taskDescription, taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor,
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -08001042 callingUid, callingPackage, resizeable);
Craig Mautner21d24a22014-04-23 11:45:37 -07001043
1044 for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001045 activities.get(activityNdx).task = task;
Craig Mautner21d24a22014-04-23 11:45:37 -07001046 }
1047
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001048 if (ActivityManagerService.DEBUG_RECENTS) Slog.d(TAG, "Restored task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -07001049 return task;
1050 }
1051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 void dump(PrintWriter pw, String prefix) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001053 pw.print(prefix); pw.print("userId="); pw.print(userId);
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001054 pw.print(" effectiveUid="); UserHandle.formatUid(pw, effectiveUid);
1055 pw.print(" mCallingUid="); UserHandle.formatUid(pw, mCallingUid);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001056 pw.print(" mCallingPackage="); pw.println(mCallingPackage);
Dianne Hackborn79228822014-09-16 11:11:23 -07001057 if (affinity != null || rootAffinity != null) {
1058 pw.print(prefix); pw.print("affinity="); pw.print(affinity);
1059 if (affinity == null || !affinity.equals(rootAffinity)) {
1060 pw.print(" root="); pw.println(rootAffinity);
1061 } else {
1062 pw.println();
1063 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001064 }
Dianne Hackborn91097de2014-04-04 18:02:06 -07001065 if (voiceSession != null || voiceInteractor != null) {
1066 pw.print(prefix); pw.print("VOICE: session=0x");
1067 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
1068 pw.print(" interactor=0x");
1069 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
1070 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001071 if (intent != null) {
1072 StringBuilder sb = new StringBuilder(128);
1073 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001074 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001075 sb.append('}');
1076 pw.println(sb.toString());
1077 }
1078 if (affinityIntent != null) {
1079 StringBuilder sb = new StringBuilder(128);
1080 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -08001081 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001082 sb.append('}');
1083 pw.println(sb.toString());
1084 }
1085 if (origActivity != null) {
1086 pw.print(prefix); pw.print("origActivity=");
1087 pw.println(origActivity.flattenToShortString());
1088 }
1089 if (realActivity != null) {
1090 pw.print(prefix); pw.print("realActivity=");
1091 pw.println(realActivity.flattenToShortString());
1092 }
Dianne Hackborn852975d2014-08-22 17:42:43 -07001093 if (autoRemoveRecents || isPersistable || taskType != 0 || mTaskToReturnTo != 0
1094 || numFullscreen != 0) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001095 pw.print(prefix); pw.print("autoRemoveRecents="); pw.print(autoRemoveRecents);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001096 pw.print(" isPersistable="); pw.print(isPersistable);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001097 pw.print(" numFullscreen="); pw.print(numFullscreen);
1098 pw.print(" taskType="); pw.print(taskType);
1099 pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo);
1100 }
1101 if (rootWasReset || mNeverRelinquishIdentity || mReuseTask) {
1102 pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset);
1103 pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity);
1104 pw.print(" mReuseTask="); pw.println(mReuseTask);
1105 }
Wale Ogunwale18795a22014-12-03 11:38:33 -08001106 if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID
1107 || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID
1108 || mNextAffiliate != null) {
Dianne Hackborn852975d2014-08-22 17:42:43 -07001109 pw.print(prefix); pw.print("affiliation="); pw.print(mAffiliatedTaskId);
1110 pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId);
1111 pw.print(" (");
1112 if (mPrevAffiliate == null) {
1113 pw.print("null");
1114 } else {
1115 pw.print(Integer.toHexString(System.identityHashCode(mPrevAffiliate)));
1116 }
1117 pw.print(") nextAffiliation="); pw.print(mNextAffiliateTaskId);
1118 pw.print(" (");
1119 if (mNextAffiliate == null) {
1120 pw.print("null");
1121 } else {
1122 pw.print(Integer.toHexString(System.identityHashCode(mNextAffiliate)));
1123 }
1124 pw.println(")");
1125 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001126 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001127 if (!askedCompatMode || !inRecents || !isAvailable) {
1128 pw.print(prefix); pw.print("askedCompatMode="); pw.print(askedCompatMode);
1129 pw.print(" inRecents="); pw.print(inRecents);
1130 pw.print(" isAvailable="); pw.println(isAvailable);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001131 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001132 pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001133 pw.print(" lastThumbnailFile="); pw.println(mLastThumbnailFile);
1134 if (lastDescription != null) {
1135 pw.print(prefix); pw.print("lastDescription="); pw.println(lastDescription);
1136 }
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001137 pw.print(prefix); pw.print("hasBeenVisible="); pw.print(hasBeenVisible);
Wale Ogunwale9d3de4c2015-02-01 16:49:44 -08001138 pw.print(" mResizeable="); pw.print(mResizeable);
Winson Chungffa2ec62014-07-03 15:54:42 -07001139 pw.print(" firstActiveTime="); pw.print(lastActiveTime);
Dianne Hackbornd38aed82014-06-10 21:36:35 -07001140 pw.print(" lastActiveTime="); pw.print(lastActiveTime);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001141 pw.print(" (inactive for ");
1142 pw.print((getInactiveDuration()/1000)); pw.println("s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 }
1144
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001145 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001147 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -07001148 if (stringName != null) {
1149 sb.append(stringName);
1150 sb.append(" U=");
1151 sb.append(userId);
1152 sb.append(" sz=");
1153 sb.append(mActivities.size());
1154 sb.append('}');
1155 return sb.toString();
1156 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001157 sb.append("TaskRecord{");
1158 sb.append(Integer.toHexString(System.identityHashCode(this)));
1159 sb.append(" #");
1160 sb.append(taskId);
1161 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001162 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001163 sb.append(affinity);
1164 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001165 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001166 sb.append(intent.getComponent().flattenToShortString());
1167 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -08001168 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001169 sb.append(affinityIntent.getComponent().flattenToShortString());
1170 } else {
1171 sb.append(" ??");
1172 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07001173 stringName = sb.toString();
1174 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176}