blob: 862932cb2a0b1802f5f615e7f4baf5bef0403d20 [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
Craig Mautnerde4ef022013-04-07 19:01:33 -070019import static com.android.server.am.ActivityManagerService.TAG;
Craig Mautner0eea92c2013-05-16 13:35:39 -070020import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE;
Craig Mautnerde4ef022013-04-07 19:01:33 -070021
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070022import android.app.Activity;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070023import android.app.ActivityManager;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -070024import android.app.ActivityOptions;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070025import android.app.IThumbnailRetriever;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.ComponentName;
27import android.content.Intent;
28import android.content.pm.ActivityInfo;
Craig Mautner9db9a0b2013-04-29 17:05:56 -070029import android.graphics.Bitmap;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070030import android.os.UserHandle;
Dianne Hackborn91097de2014-04-04 18:02:06 -070031import android.service.voice.IVoiceInteractionSession;
Dianne Hackborn7f96b792012-05-29 18:46:45 -070032import android.util.Slog;
Dianne Hackborn91097de2014-04-04 18:02:06 -070033import com.android.internal.app.IVoiceInteractor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
35import java.io.PrintWriter;
Craig Mautner5d9c7be2013-02-15 14:02:56 -080036import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -070038final class TaskRecord extends ThumbnailHolder {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 final int taskId; // Unique identifier for this task.
40 final String affinity; // The affinity name for this task, or null.
Dianne Hackborn91097de2014-04-04 18:02:06 -070041 final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
42 final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 Intent intent; // The original intent that started the task.
44 Intent affinityIntent; // Intent of affinity-moved activity that started this task.
45 ComponentName origActivity; // The non-alias activity component of the intent.
46 ComponentName realActivity; // The actual activity component that started the task.
47 int numActivities; // Current number of activities in this task.
48 long lastActiveTime; // Last time this task was active, including sleep.
49 boolean rootWasReset; // True if the intent at the root of the task had
50 // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
Dianne Hackborn36cd41f2011-05-25 21:00:46 -070051 boolean askedCompatMode;// Have asked the user about compat mode for this task.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
Dianne Hackborn1d442e02009-04-20 18:14:05 -070053 String stringName; // caching of toString() result.
Dianne Hackborn9da2d402012-03-15 13:43:08 -070054 int userId; // user for which this task was created
Dianne Hackborn09233282014-04-30 11:33:59 -070055 int creatorUid; // The app uid that originally created the task
Craig Mautner5d9c7be2013-02-15 14:02:56 -080056
57 int numFullscreen; // Number of fullscreen activities.
58
Winson Chung03a9bae2014-05-02 09:56:12 -070059 // This represents the last resolved activity values for this task
60 // NOTE: This value needs to be persisted with each task
61 ActivityManager.RecentsActivityValues lastActivityValues =
62 new ActivityManager.RecentsActivityValues();
63
Craig Mautnerd2328952013-03-05 12:46:26 -080064 /** List of all activities in the task arranged in history order */
Craig Mautner5d9c7be2013-02-15 14:02:56 -080065 final ArrayList<ActivityRecord> mActivities = new ArrayList<ActivityRecord>();
66
Craig Mautnerd2328952013-03-05 12:46:26 -080067 /** Current stack */
68 ActivityStack stack;
69
Craig Mautner2c1faed2013-07-23 12:56:02 -070070 /** Takes on same set of values as ActivityRecord.mActivityType */
71 private int mTaskType;
Craig Mautner1602ec22013-05-12 10:24:27 -070072
Craig Mautnere0a38842013-12-16 16:14:02 -080073 /** Launch the home activity when leaving this task. Will be false for tasks that are not on
74 * Display.DEFAULT_DISPLAY. */
Craig Mautnerae7ecab2013-09-18 11:48:14 -070075 boolean mOnTopOfHome = false;
76
Dianne Hackborn91097de2014-04-04 18:02:06 -070077 TaskRecord(int _taskId, ActivityInfo info, Intent _intent,
78 IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 taskId = _taskId;
80 affinity = info.taskAffinity;
Dianne Hackborn91097de2014-04-04 18:02:06 -070081 voiceSession = _voiceSession;
82 voiceInteractor = _voiceInteractor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 setIntent(_intent, info);
84 }
85
86 void touchActiveTime() {
87 lastActiveTime = android.os.SystemClock.elapsedRealtime();
88 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 long getInactiveDuration() {
91 return android.os.SystemClock.elapsedRealtime() - lastActiveTime;
92 }
Craig Mautner9db9a0b2013-04-29 17:05:56 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 void setIntent(Intent _intent, ActivityInfo info) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070095 stringName = null;
Dianne Hackbornf5b86712011-12-05 17:42:41 -080096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 if (info.targetActivity == null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -080098 if (_intent != null) {
99 // If this Intent has a selector, we want to clear it for the
100 // recent task since it is not relevant if the user later wants
101 // to re-launch the app.
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700102 if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800103 _intent = new Intent(_intent);
104 _intent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700105 _intent.setSourceBounds(null);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800106 }
107 }
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700108 if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
109 "Setting Intent of " + this + " to " + _intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 intent = _intent;
111 realActivity = _intent != null ? _intent.getComponent() : null;
112 origActivity = null;
113 } else {
114 ComponentName targetComponent = new ComponentName(
115 info.packageName, info.targetActivity);
116 if (_intent != null) {
117 Intent targetIntent = new Intent(_intent);
118 targetIntent.setComponent(targetComponent);
Dianne Hackbornf5b86712011-12-05 17:42:41 -0800119 targetIntent.setSelector(null);
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700120 targetIntent.setSourceBounds(null);
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700121 if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
122 "Setting Intent of " + this + " to target " + targetIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 intent = targetIntent;
124 realActivity = targetComponent;
125 origActivity = _intent.getComponent();
126 } else {
127 intent = null;
128 realActivity = targetComponent;
129 origActivity = new ComponentName(info.packageName, info.name);
130 }
131 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 if (intent != null &&
134 (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
135 // Once we are set to an Intent with this flag, we count this
136 // task as having a true root activity.
137 rootWasReset = true;
138 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700139
Dianne Hackborn09233282014-04-30 11:33:59 -0700140 userId = UserHandle.getUserId(info.applicationInfo.uid);
141 creatorUid = info.applicationInfo.uid;
Craig Mautner41db4a72014-05-07 17:20:56 -0700142 if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) {
143 intent.addFlags(Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS);
144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800146
Dianne Hackborn9844d292013-10-04 16:44:22 -0700147 void disposeThumbnail() {
148 super.disposeThumbnail();
149 for (int i=mActivities.size()-1; i>=0; i--) {
150 ThumbnailHolder thumb = mActivities.get(i).thumbHolder;
151 if (thumb != this) {
152 thumb.disposeThumbnail();
153 }
154 }
155 }
156
Winson Chung3b3f4642014-04-22 10:08:18 -0700157 /** Returns the first non-finishing activity from the root. */
158 ActivityRecord getRootActivity() {
159 for (int i = 0; i < mActivities.size(); i++) {
160 final ActivityRecord r = mActivities.get(i);
161 if (r.finishing) {
162 continue;
163 }
164 return r;
165 }
166 return null;
167 }
168
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800169 ActivityRecord getTopActivity() {
170 for (int i = mActivities.size() - 1; i >= 0; --i) {
171 final ActivityRecord r = mActivities.get(i);
172 if (r.finishing) {
173 continue;
174 }
175 return r;
176 }
177 return null;
178 }
179
Craig Mautner6b74cb52013-09-27 17:02:21 -0700180 ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
181 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
182 ActivityRecord r = mActivities.get(activityNdx);
Amith Yamasani734983f2014-03-04 16:48:05 -0800183 if (!r.finishing && r != notTop && stack.okToShowLocked(r)) {
Craig Mautner6b74cb52013-09-27 17:02:21 -0700184 return r;
185 }
186 }
187 return null;
188 }
189
Craig Mautner3b475fe2013-12-16 15:58:31 -0800190 /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
191 final void setFrontOfTask() {
192 boolean foundFront = false;
193 final int numActivities = mActivities.size();
Craig Mautner704e40b2013-12-18 16:43:51 -0800194 for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
Craig Mautner3b475fe2013-12-16 15:58:31 -0800195 final ActivityRecord r = mActivities.get(activityNdx);
196 if (foundFront || r.finishing) {
197 r.frontOfTask = false;
198 } else {
199 r.frontOfTask = true;
200 // Set frontOfTask false for every following activity.
201 foundFront = true;
202 }
203 }
204 }
205
Craig Mautnerde4ef022013-04-07 19:01:33 -0700206 /**
Craig Mautner3b475fe2013-12-16 15:58:31 -0800207 * Reorder the history stack so that the passed activity is brought to the front.
Craig Mautnerde4ef022013-04-07 19:01:33 -0700208 */
209 final void moveActivityToFrontLocked(ActivityRecord newTop) {
210 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop
211 + " to stack at top", new RuntimeException("here").fillInStackTrace());
212
Craig Mautnerde4ef022013-04-07 19:01:33 -0700213 mActivities.remove(newTop);
214 mActivities.add(newTop);
Craig Mautner3b475fe2013-12-16 15:58:31 -0800215
216 setFrontOfTask();
Craig Mautnerde4ef022013-04-07 19:01:33 -0700217 }
218
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800219 void addActivityAtBottom(ActivityRecord r) {
Craig Mautner77878772013-03-04 19:46:24 -0800220 addActivityAtIndex(0, r);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800221 }
222
223 void addActivityToTop(ActivityRecord r) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700224 addActivityAtIndex(mActivities.size(), r);
225 }
226
227 void addActivityAtIndex(int index, ActivityRecord r) {
Craig Mautner6170f732013-04-02 13:05:23 -0700228 // 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 -0800229 if (!mActivities.remove(r) && r.fullscreen) {
230 // Was not previously in list.
231 numFullscreen++;
232 }
Craig Mautner2c1faed2013-07-23 12:56:02 -0700233 // Only set this based on the first activity
234 if (mActivities.isEmpty()) {
235 mTaskType = r.mActivityType;
236 } else {
237 // Otherwise make all added activities match this one.
238 r.mActivityType = mTaskType;
Craig Mautner78733002013-06-10 13:54:49 -0700239 }
Craig Mautner77878772013-03-04 19:46:24 -0800240 mActivities.add(index, r);
241 }
242
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800243 /** @return true if this was the last activity in the task */
244 boolean removeActivity(ActivityRecord r) {
245 if (mActivities.remove(r) && r.fullscreen) {
246 // Was previously in list.
247 numFullscreen--;
248 }
249 return mActivities.size() == 0;
250 }
251
Craig Mautner41db4a72014-05-07 17:20:56 -0700252 boolean autoRemoveFromRecents() {
253 return intent != null &&
254 (intent.getFlags() & Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS) != 0;
255 }
256
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700257 /**
258 * Completely remove all activities associated with an existing
259 * task starting at a specified index.
260 */
261 final void performClearTaskAtIndexLocked(int activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700262 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700263 for ( ; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700264 final ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700265 if (r.finishing) {
266 continue;
267 }
268 if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", false)) {
269 --activityNdx;
270 --numActivities;
271 }
272 }
273 }
274
275 /**
276 * Completely remove all activities associated with an existing task.
277 */
278 final void performClearTaskLocked() {
279 performClearTaskAtIndexLocked(0);
280 }
281
282 /**
283 * Perform clear operation as requested by
284 * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
285 * stack to the given task, then look for
286 * an instance of that activity in the stack and, if found, finish all
287 * activities on top of it and return the instance.
288 *
289 * @param newR Description of the new activity being started.
290 * @return Returns the old activity that should be continued to be used,
291 * or null if none was found.
292 */
293 final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700294 int numActivities = mActivities.size();
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700295 for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700296 ActivityRecord r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700297 if (r.finishing) {
298 continue;
299 }
300 if (r.realActivity.equals(newR.realActivity)) {
301 // Here it is! Now finish everything in front...
Craig Mautner1602ec22013-05-12 10:24:27 -0700302 final ActivityRecord ret = r;
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700303
304 for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700305 r = mActivities.get(activityNdx);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700306 if (r.finishing) {
307 continue;
308 }
309 ActivityOptions opts = r.takeOptionsLocked();
310 if (opts != null) {
311 ret.updateOptionsLocked(opts);
312 }
313 if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear",
314 false)) {
315 --activityNdx;
316 --numActivities;
317 }
318 }
319
320 // Finally, if this is a normal launch mode (that is, not
321 // expecting onNewIntent()), then we will finish the current
322 // instance of the activity so a new fresh one can be started.
323 if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
324 && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
325 if (!ret.finishing) {
Craig Mautner1602ec22013-05-12 10:24:27 -0700326 stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null,
327 "clear", false);
Craig Mautnerb0f7dc72013-04-01 16:34:45 -0700328 return null;
329 }
330 }
331
332 return ret;
333 }
334 }
335
336 return null;
337 }
338
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700339 public ActivityManager.TaskThumbnails getTaskThumbnailsLocked() {
Winson Chung3b3f4642014-04-22 10:08:18 -0700340 TaskAccessInfo info = getTaskAccessInfoLocked();
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700341 final ActivityRecord resumedActivity = stack.mResumedActivity;
342 if (resumedActivity != null && resumedActivity.thumbHolder == this) {
343 info.mainThumbnail = stack.screenshotActivities(resumedActivity);
344 }
345 if (info.mainThumbnail == null) {
346 info.mainThumbnail = lastThumbnail;
347 }
348 return info;
349 }
350
351 public Bitmap getTaskTopThumbnailLocked() {
352 final ActivityRecord resumedActivity = stack.mResumedActivity;
353 if (resumedActivity != null && resumedActivity.task == this) {
354 // This task is the current resumed task, we just need to take
355 // a screenshot of it and return that.
356 return stack.screenshotActivities(resumedActivity);
357 }
358 // Return the information about the task, to figure out the top
359 // thumbnail to return.
Winson Chung3b3f4642014-04-22 10:08:18 -0700360 TaskAccessInfo info = getTaskAccessInfoLocked();
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700361 if (info.numSubThumbbails <= 0) {
362 return info.mainThumbnail != null ? info.mainThumbnail : lastThumbnail;
363 }
364 return info.subtasks.get(info.numSubThumbbails-1).holder.lastThumbnail;
365 }
366
367 public ActivityRecord removeTaskActivitiesLocked(int subTaskIndex,
368 boolean taskRequired) {
Winson Chung3b3f4642014-04-22 10:08:18 -0700369 TaskAccessInfo info = getTaskAccessInfoLocked();
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700370 if (info.root == null) {
371 if (taskRequired) {
372 Slog.w(TAG, "removeTaskLocked: unknown taskId " + taskId);
373 }
374 return null;
375 }
376
377 if (subTaskIndex < 0) {
378 // Just remove the entire task.
379 performClearTaskAtIndexLocked(info.rootIndex);
380 return info.root;
381 }
382
383 if (subTaskIndex >= info.subtasks.size()) {
384 if (taskRequired) {
385 Slog.w(TAG, "removeTaskLocked: unknown subTaskIndex " + subTaskIndex);
386 }
387 return null;
388 }
389
390 // Remove all of this task's activities starting at the sub task.
391 TaskAccessInfo.SubTask subtask = info.subtasks.get(subTaskIndex);
392 performClearTaskAtIndexLocked(subtask.index);
393 return subtask.activity;
394 }
395
Craig Mautnera82aa092013-09-13 15:34:08 -0700396 boolean isHomeTask() {
397 return mTaskType == ActivityRecord.HOME_ACTIVITY_TYPE;
398 }
399
Craig Mautner86d67a42013-05-14 10:34:38 -0700400 boolean isApplicationTask() {
Craig Mautner2c1faed2013-07-23 12:56:02 -0700401 return mTaskType == ActivityRecord.APPLICATION_ACTIVITY_TYPE;
Craig Mautner1602ec22013-05-12 10:24:27 -0700402 }
403
Winson Chung3b3f4642014-04-22 10:08:18 -0700404 public TaskAccessInfo getTaskAccessInfoLocked() {
Craig Mautner9db9a0b2013-04-29 17:05:56 -0700405 final TaskAccessInfo thumbs = new TaskAccessInfo();
406 // How many different sub-thumbnails?
407 final int NA = mActivities.size();
408 int j = 0;
409 ThumbnailHolder holder = null;
410 while (j < NA) {
411 ActivityRecord ar = mActivities.get(j);
412 if (!ar.finishing) {
413 thumbs.root = ar;
414 thumbs.rootIndex = j;
415 holder = ar.thumbHolder;
416 if (holder != null) {
417 thumbs.mainThumbnail = holder.lastThumbnail;
418 }
419 j++;
420 break;
421 }
422 j++;
423 }
424
425 if (j >= NA) {
426 return thumbs;
427 }
428
429 ArrayList<TaskAccessInfo.SubTask> subtasks = new ArrayList<TaskAccessInfo.SubTask>();
430 thumbs.subtasks = subtasks;
431 while (j < NA) {
432 ActivityRecord ar = mActivities.get(j);
433 j++;
434 if (ar.finishing) {
435 continue;
436 }
437 if (ar.thumbHolder != holder && holder != null) {
438 thumbs.numSubThumbbails++;
439 holder = ar.thumbHolder;
440 TaskAccessInfo.SubTask sub = new TaskAccessInfo.SubTask();
441 sub.holder = holder;
442 sub.activity = ar;
443 sub.index = j-1;
444 subtasks.add(sub);
445 }
446 }
447 if (thumbs.numSubThumbbails > 0) {
448 thumbs.retriever = new IThumbnailRetriever.Stub() {
449 @Override
450 public Bitmap getThumbnail(int index) {
451 if (index < 0 || index >= thumbs.subtasks.size()) {
452 return null;
453 }
454 TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index);
455 ActivityRecord resumedActivity = stack.mResumedActivity;
456 if (resumedActivity != null && resumedActivity.thumbHolder == sub.holder) {
457 return stack.screenshotActivities(resumedActivity);
458 }
459 return sub.holder.lastThumbnail;
460 }
461 };
462 }
463 return thumbs;
464 }
465
Craig Mautner525f3d92013-05-07 14:01:50 -0700466 /**
467 * Find the activity in the history stack within the given task. Returns
468 * the index within the history at which it's found, or < 0 if not found.
469 */
470 final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
471 final ComponentName realActivity = r.realActivity;
472 for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
473 ActivityRecord candidate = mActivities.get(activityNdx);
474 if (candidate.finishing) {
475 continue;
476 }
477 if (candidate.realActivity.equals(realActivity)) {
478 return candidate;
479 }
480 }
481 return null;
482 }
483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 void dump(PrintWriter pw, String prefix) {
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700485 if (numActivities != 0 || rootWasReset || userId != 0 || numFullscreen != 0) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800486 pw.print(prefix); pw.print("numActivities="); pw.print(numActivities);
Dianne Hackborn7f96b792012-05-29 18:46:45 -0700487 pw.print(" rootWasReset="); pw.print(rootWasReset);
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800488 pw.print(" userId="); pw.print(userId);
Craig Mautner80259352013-09-28 12:35:25 -0700489 pw.print(" mTaskType="); pw.print(mTaskType);
Craig Mautnerae7ecab2013-09-18 11:48:14 -0700490 pw.print(" numFullscreen="); pw.print(numFullscreen);
491 pw.print(" mOnTopOfHome="); pw.println(mOnTopOfHome);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700492 }
493 if (affinity != null) {
494 pw.print(prefix); pw.print("affinity="); pw.println(affinity);
495 }
Dianne Hackborn91097de2014-04-04 18:02:06 -0700496 if (voiceSession != null || voiceInteractor != null) {
497 pw.print(prefix); pw.print("VOICE: session=0x");
498 pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
499 pw.print(" interactor=0x");
500 pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor)));
501 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700502 if (intent != null) {
503 StringBuilder sb = new StringBuilder(128);
504 sb.append(prefix); sb.append("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800505 intent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700506 sb.append('}');
507 pw.println(sb.toString());
508 }
509 if (affinityIntent != null) {
510 StringBuilder sb = new StringBuilder(128);
511 sb.append(prefix); sb.append("affinityIntent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800512 affinityIntent.toShortString(sb, false, true, false, true);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700513 sb.append('}');
514 pw.println(sb.toString());
515 }
516 if (origActivity != null) {
517 pw.print(prefix); pw.print("origActivity=");
518 pw.println(origActivity.flattenToShortString());
519 }
520 if (realActivity != null) {
521 pw.print(prefix); pw.print("realActivity=");
522 pw.println(realActivity.flattenToShortString());
523 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800524 pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700525 if (!askedCompatMode) {
526 pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode);
527 }
Dianne Hackborncfb9f2b2011-08-24 10:51:49 -0700528 pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail);
529 pw.print(" lastDescription="); pw.println(lastDescription);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700530 pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime);
531 pw.print(" (inactive for ");
532 pw.print((getInactiveDuration()/1000)); pw.println("s)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 }
534
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800535 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700537 StringBuilder sb = new StringBuilder(128);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700538 if (stringName != null) {
539 sb.append(stringName);
540 sb.append(" U=");
541 sb.append(userId);
542 sb.append(" sz=");
543 sb.append(mActivities.size());
544 sb.append('}');
545 return sb.toString();
546 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700547 sb.append("TaskRecord{");
548 sb.append(Integer.toHexString(System.identityHashCode(this)));
549 sb.append(" #");
550 sb.append(taskId);
551 if (affinity != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800552 sb.append(" A=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700553 sb.append(affinity);
554 } else if (intent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800555 sb.append(" I=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700556 sb.append(intent.getComponent().flattenToShortString());
557 } else if (affinityIntent != null) {
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800558 sb.append(" aI=");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700559 sb.append(affinityIntent.getComponent().flattenToShortString());
560 } else {
561 sb.append(" ??");
562 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700563 stringName = sb.toString();
564 return toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 }
566}