The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 19 | import static com.android.server.am.ActivityManagerService.TAG; |
| 20 | import static com.android.server.am.ActivityStack.DEBUG_ADD_REMOVE; |
| 21 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 22 | import android.app.Activity; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 24 | import android.app.ActivityOptions; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 25 | import android.app.IThumbnailRetriever; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.ComponentName; |
| 27 | import android.content.Intent; |
| 28 | import android.content.pm.ActivityInfo; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 29 | import android.graphics.Bitmap; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 30 | import android.os.UserHandle; |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 31 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
| 33 | import java.io.PrintWriter; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 34 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 36 | class TaskRecord extends ThumbnailHolder { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | final int taskId; // Unique identifier for this task. |
| 38 | final String affinity; // The affinity name for this task, or null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | Intent intent; // The original intent that started the task. |
| 40 | Intent affinityIntent; // Intent of affinity-moved activity that started this task. |
| 41 | ComponentName origActivity; // The non-alias activity component of the intent. |
| 42 | ComponentName realActivity; // The actual activity component that started the task. |
| 43 | int numActivities; // Current number of activities in this task. |
| 44 | long lastActiveTime; // Last time this task was active, including sleep. |
| 45 | boolean rootWasReset; // True if the intent at the root of the task had |
| 46 | // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag. |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 47 | boolean askedCompatMode;// Have asked the user about compat mode for this task. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 49 | String stringName; // caching of toString() result. |
Dianne Hackborn | 9da2d40 | 2012-03-15 13:43:08 -0700 | [diff] [blame] | 50 | int userId; // user for which this task was created |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 51 | |
| 52 | int numFullscreen; // Number of fullscreen activities. |
| 53 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 54 | /** List of all activities in the task arranged in history order */ |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 55 | final ArrayList<ActivityRecord> mActivities = new ArrayList<ActivityRecord>(); |
| 56 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 57 | /** Current stack */ |
| 58 | ActivityStack stack; |
| 59 | |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 60 | private boolean mHomeTask; |
| 61 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 62 | TaskRecord(int _taskId, ActivityInfo info, Intent _intent, ActivityStack _stack) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | taskId = _taskId; |
| 64 | affinity = info.taskAffinity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | setIntent(_intent, info); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 66 | stack = _stack; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void touchActiveTime() { |
| 70 | lastActiveTime = android.os.SystemClock.elapsedRealtime(); |
| 71 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 72 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | long getInactiveDuration() { |
| 74 | return android.os.SystemClock.elapsedRealtime() - lastActiveTime; |
| 75 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | void setIntent(Intent _intent, ActivityInfo info) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 78 | stringName = null; |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | if (info.targetActivity == null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 81 | if (_intent != null) { |
| 82 | // If this Intent has a selector, we want to clear it for the |
| 83 | // recent task since it is not relevant if the user later wants |
| 84 | // to re-launch the app. |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 85 | if (_intent.getSelector() != null || _intent.getSourceBounds() != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 86 | _intent = new Intent(_intent); |
| 87 | _intent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 88 | _intent.setSourceBounds(null); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 89 | } |
| 90 | } |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 91 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 92 | "Setting Intent of " + this + " to " + _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | intent = _intent; |
| 94 | realActivity = _intent != null ? _intent.getComponent() : null; |
| 95 | origActivity = null; |
| 96 | } else { |
| 97 | ComponentName targetComponent = new ComponentName( |
| 98 | info.packageName, info.targetActivity); |
| 99 | if (_intent != null) { |
| 100 | Intent targetIntent = new Intent(_intent); |
| 101 | targetIntent.setComponent(targetComponent); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 102 | targetIntent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 103 | targetIntent.setSourceBounds(null); |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 104 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 105 | "Setting Intent of " + this + " to target " + targetIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | intent = targetIntent; |
| 107 | realActivity = targetComponent; |
| 108 | origActivity = _intent.getComponent(); |
| 109 | } else { |
| 110 | intent = null; |
| 111 | realActivity = targetComponent; |
| 112 | origActivity = new ComponentName(info.packageName, info.name); |
| 113 | } |
| 114 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | if (intent != null && |
| 117 | (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
| 118 | // Once we are set to an Intent with this flag, we count this |
| 119 | // task as having a true root activity. |
| 120 | rootWasReset = true; |
| 121 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 122 | |
| 123 | if (info.applicationInfo != null) { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 124 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 127 | |
| 128 | ActivityRecord getTopActivity() { |
| 129 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 130 | final ActivityRecord r = mActivities.get(i); |
| 131 | if (r.finishing) { |
| 132 | continue; |
| 133 | } |
| 134 | return r; |
| 135 | } |
| 136 | return null; |
| 137 | } |
| 138 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 139 | /** |
| 140 | * Reorder the history stack so that the activity at the given index is |
| 141 | * brought to the front. |
| 142 | */ |
| 143 | final void moveActivityToFrontLocked(ActivityRecord newTop) { |
| 144 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop |
| 145 | + " to stack at top", new RuntimeException("here").fillInStackTrace()); |
| 146 | |
| 147 | getTopActivity().frontOfTask = false; |
| 148 | mActivities.remove(newTop); |
| 149 | mActivities.add(newTop); |
| 150 | newTop.frontOfTask = true; |
| 151 | } |
| 152 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 153 | void addActivityAtBottom(ActivityRecord r) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 154 | addActivityAtIndex(0, r); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void addActivityToTop(ActivityRecord r) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 158 | addActivityAtIndex(mActivities.size(), r); |
| 159 | } |
| 160 | |
| 161 | void addActivityAtIndex(int index, ActivityRecord r) { |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 162 | // Remove r first, and if it wasn't already in the list and it's fullscreen, count it. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 163 | if (!mActivities.remove(r) && r.fullscreen) { |
| 164 | // Was not previously in list. |
| 165 | numFullscreen++; |
| 166 | } |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 167 | mHomeTask = r.isHomeActivity; |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 168 | mActivities.add(index, r); |
| 169 | } |
| 170 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 171 | /** @return true if this was the last activity in the task */ |
| 172 | boolean removeActivity(ActivityRecord r) { |
| 173 | if (mActivities.remove(r) && r.fullscreen) { |
| 174 | // Was previously in list. |
| 175 | numFullscreen--; |
| 176 | } |
| 177 | return mActivities.size() == 0; |
| 178 | } |
| 179 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 180 | /** |
| 181 | * Completely remove all activities associated with an existing |
| 182 | * task starting at a specified index. |
| 183 | */ |
| 184 | final void performClearTaskAtIndexLocked(int activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 185 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 186 | for ( ; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 187 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 188 | if (r.finishing) { |
| 189 | continue; |
| 190 | } |
| 191 | if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", false)) { |
| 192 | --activityNdx; |
| 193 | --numActivities; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Completely remove all activities associated with an existing task. |
| 200 | */ |
| 201 | final void performClearTaskLocked() { |
| 202 | performClearTaskAtIndexLocked(0); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Perform clear operation as requested by |
| 207 | * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the |
| 208 | * stack to the given task, then look for |
| 209 | * an instance of that activity in the stack and, if found, finish all |
| 210 | * activities on top of it and return the instance. |
| 211 | * |
| 212 | * @param newR Description of the new activity being started. |
| 213 | * @return Returns the old activity that should be continued to be used, |
| 214 | * or null if none was found. |
| 215 | */ |
| 216 | final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 217 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 218 | for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 219 | ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 220 | if (r.finishing) { |
| 221 | continue; |
| 222 | } |
| 223 | if (r.realActivity.equals(newR.realActivity)) { |
| 224 | // Here it is! Now finish everything in front... |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 225 | final ActivityRecord ret = r; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 226 | |
| 227 | for (++activityNdx; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 228 | r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 229 | if (r.finishing) { |
| 230 | continue; |
| 231 | } |
| 232 | ActivityOptions opts = r.takeOptionsLocked(); |
| 233 | if (opts != null) { |
| 234 | ret.updateOptionsLocked(opts); |
| 235 | } |
| 236 | if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", |
| 237 | false)) { |
| 238 | --activityNdx; |
| 239 | --numActivities; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // Finally, if this is a normal launch mode (that is, not |
| 244 | // expecting onNewIntent()), then we will finish the current |
| 245 | // instance of the activity so a new fresh one can be started. |
| 246 | if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE |
| 247 | && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) { |
| 248 | if (!ret.finishing) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 249 | stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null, |
| 250 | "clear", false); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 251 | return null; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | return ret; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | return null; |
| 260 | } |
| 261 | |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 262 | public ActivityManager.TaskThumbnails getTaskThumbnailsLocked() { |
| 263 | TaskAccessInfo info = getTaskAccessInfoLocked(true); |
| 264 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 265 | if (resumedActivity != null && resumedActivity.thumbHolder == this) { |
| 266 | info.mainThumbnail = stack.screenshotActivities(resumedActivity); |
| 267 | } |
| 268 | if (info.mainThumbnail == null) { |
| 269 | info.mainThumbnail = lastThumbnail; |
| 270 | } |
| 271 | return info; |
| 272 | } |
| 273 | |
| 274 | public Bitmap getTaskTopThumbnailLocked() { |
| 275 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 276 | if (resumedActivity != null && resumedActivity.task == this) { |
| 277 | // This task is the current resumed task, we just need to take |
| 278 | // a screenshot of it and return that. |
| 279 | return stack.screenshotActivities(resumedActivity); |
| 280 | } |
| 281 | // Return the information about the task, to figure out the top |
| 282 | // thumbnail to return. |
| 283 | TaskAccessInfo info = getTaskAccessInfoLocked(true); |
| 284 | if (info.numSubThumbbails <= 0) { |
| 285 | return info.mainThumbnail != null ? info.mainThumbnail : lastThumbnail; |
| 286 | } |
| 287 | return info.subtasks.get(info.numSubThumbbails-1).holder.lastThumbnail; |
| 288 | } |
| 289 | |
| 290 | public ActivityRecord removeTaskActivitiesLocked(int subTaskIndex, |
| 291 | boolean taskRequired) { |
| 292 | TaskAccessInfo info = getTaskAccessInfoLocked(false); |
| 293 | if (info.root == null) { |
| 294 | if (taskRequired) { |
| 295 | Slog.w(TAG, "removeTaskLocked: unknown taskId " + taskId); |
| 296 | } |
| 297 | return null; |
| 298 | } |
| 299 | |
| 300 | if (subTaskIndex < 0) { |
| 301 | // Just remove the entire task. |
| 302 | performClearTaskAtIndexLocked(info.rootIndex); |
| 303 | return info.root; |
| 304 | } |
| 305 | |
| 306 | if (subTaskIndex >= info.subtasks.size()) { |
| 307 | if (taskRequired) { |
| 308 | Slog.w(TAG, "removeTaskLocked: unknown subTaskIndex " + subTaskIndex); |
| 309 | } |
| 310 | return null; |
| 311 | } |
| 312 | |
| 313 | // Remove all of this task's activities starting at the sub task. |
| 314 | TaskAccessInfo.SubTask subtask = info.subtasks.get(subTaskIndex); |
| 315 | performClearTaskAtIndexLocked(subtask.index); |
| 316 | return subtask.activity; |
| 317 | } |
| 318 | |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame^] | 319 | boolean isHomeTask() { |
| 320 | return mHomeTask; |
| 321 | } |
| 322 | |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 323 | public TaskAccessInfo getTaskAccessInfoLocked(boolean inclThumbs) { |
| 324 | final TaskAccessInfo thumbs = new TaskAccessInfo(); |
| 325 | // How many different sub-thumbnails? |
| 326 | final int NA = mActivities.size(); |
| 327 | int j = 0; |
| 328 | ThumbnailHolder holder = null; |
| 329 | while (j < NA) { |
| 330 | ActivityRecord ar = mActivities.get(j); |
| 331 | if (!ar.finishing) { |
| 332 | thumbs.root = ar; |
| 333 | thumbs.rootIndex = j; |
| 334 | holder = ar.thumbHolder; |
| 335 | if (holder != null) { |
| 336 | thumbs.mainThumbnail = holder.lastThumbnail; |
| 337 | } |
| 338 | j++; |
| 339 | break; |
| 340 | } |
| 341 | j++; |
| 342 | } |
| 343 | |
| 344 | if (j >= NA) { |
| 345 | return thumbs; |
| 346 | } |
| 347 | |
| 348 | ArrayList<TaskAccessInfo.SubTask> subtasks = new ArrayList<TaskAccessInfo.SubTask>(); |
| 349 | thumbs.subtasks = subtasks; |
| 350 | while (j < NA) { |
| 351 | ActivityRecord ar = mActivities.get(j); |
| 352 | j++; |
| 353 | if (ar.finishing) { |
| 354 | continue; |
| 355 | } |
| 356 | if (ar.thumbHolder != holder && holder != null) { |
| 357 | thumbs.numSubThumbbails++; |
| 358 | holder = ar.thumbHolder; |
| 359 | TaskAccessInfo.SubTask sub = new TaskAccessInfo.SubTask(); |
| 360 | sub.holder = holder; |
| 361 | sub.activity = ar; |
| 362 | sub.index = j-1; |
| 363 | subtasks.add(sub); |
| 364 | } |
| 365 | } |
| 366 | if (thumbs.numSubThumbbails > 0) { |
| 367 | thumbs.retriever = new IThumbnailRetriever.Stub() { |
| 368 | @Override |
| 369 | public Bitmap getThumbnail(int index) { |
| 370 | if (index < 0 || index >= thumbs.subtasks.size()) { |
| 371 | return null; |
| 372 | } |
| 373 | TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index); |
| 374 | ActivityRecord resumedActivity = stack.mResumedActivity; |
| 375 | if (resumedActivity != null && resumedActivity.thumbHolder == sub.holder) { |
| 376 | return stack.screenshotActivities(resumedActivity); |
| 377 | } |
| 378 | return sub.holder.lastThumbnail; |
| 379 | } |
| 380 | }; |
| 381 | } |
| 382 | return thumbs; |
| 383 | } |
| 384 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 385 | /** |
| 386 | * Find the activity in the history stack within the given task. Returns |
| 387 | * the index within the history at which it's found, or < 0 if not found. |
| 388 | */ |
| 389 | final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) { |
| 390 | final ComponentName realActivity = r.realActivity; |
| 391 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 392 | ActivityRecord candidate = mActivities.get(activityNdx); |
| 393 | if (candidate.finishing) { |
| 394 | continue; |
| 395 | } |
| 396 | if (candidate.realActivity.equals(realActivity)) { |
| 397 | return candidate; |
| 398 | } |
| 399 | } |
| 400 | return null; |
| 401 | } |
| 402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 404 | if (numActivities != 0 || rootWasReset || userId != 0) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 405 | pw.print(prefix); pw.print("numActivities="); pw.print(numActivities); |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 406 | pw.print(" rootWasReset="); pw.print(rootWasReset); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 407 | pw.print(" userId="); pw.print(userId); |
| 408 | pw.print(" numFullscreen="); pw.println(numFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 409 | } |
| 410 | if (affinity != null) { |
| 411 | pw.print(prefix); pw.print("affinity="); pw.println(affinity); |
| 412 | } |
| 413 | if (intent != null) { |
| 414 | StringBuilder sb = new StringBuilder(128); |
| 415 | sb.append(prefix); sb.append("intent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 416 | intent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 417 | sb.append('}'); |
| 418 | pw.println(sb.toString()); |
| 419 | } |
| 420 | if (affinityIntent != null) { |
| 421 | StringBuilder sb = new StringBuilder(128); |
| 422 | sb.append(prefix); sb.append("affinityIntent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 423 | affinityIntent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 424 | sb.append('}'); |
| 425 | pw.println(sb.toString()); |
| 426 | } |
| 427 | if (origActivity != null) { |
| 428 | pw.print(prefix); pw.print("origActivity="); |
| 429 | pw.println(origActivity.flattenToShortString()); |
| 430 | } |
| 431 | if (realActivity != null) { |
| 432 | pw.print(prefix); pw.print("realActivity="); |
| 433 | pw.println(realActivity.flattenToShortString()); |
| 434 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 435 | pw.print(prefix); pw.print("Activities="); pw.println(mActivities); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 436 | if (!askedCompatMode) { |
| 437 | pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode); |
| 438 | } |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 439 | pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail); |
| 440 | pw.print(" lastDescription="); pw.println(lastDescription); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 441 | pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime); |
| 442 | pw.print(" (inactive for "); |
| 443 | pw.print((getInactiveDuration()/1000)); pw.println("s)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 446 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 448 | StringBuilder sb = new StringBuilder(128); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 449 | if (stringName != null) { |
| 450 | sb.append(stringName); |
| 451 | sb.append(" U="); |
| 452 | sb.append(userId); |
| 453 | sb.append(" sz="); |
| 454 | sb.append(mActivities.size()); |
| 455 | sb.append('}'); |
| 456 | return sb.toString(); |
| 457 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 458 | sb.append("TaskRecord{"); |
| 459 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 460 | sb.append(" #"); |
| 461 | sb.append(taskId); |
| 462 | if (affinity != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 463 | sb.append(" A="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 464 | sb.append(affinity); |
| 465 | } else if (intent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 466 | sb.append(" I="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 467 | sb.append(intent.getComponent().flattenToShortString()); |
| 468 | } else if (affinityIntent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 469 | sb.append(" aI="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 470 | sb.append(affinityIntent.getComponent().flattenToShortString()); |
| 471 | } else { |
| 472 | sb.append(" ??"); |
| 473 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 474 | stringName = sb.toString(); |
| 475 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | } |
| 477 | } |