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; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 20 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 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 | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 31 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 32 | import android.util.Slog; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 33 | import com.android.internal.app.IVoiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
| 35 | import java.io.PrintWriter; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 36 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 38 | final class TaskRecord extends ThumbnailHolder { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | final int taskId; // Unique identifier for this task. |
| 40 | final String affinity; // The affinity name for this task, or null. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 41 | final IVoiceInteractionSession voiceSession; // Voice interaction session driving task |
| 42 | final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | 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 Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 51 | 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] | 52 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 53 | String stringName; // caching of toString() result. |
Dianne Hackborn | 9da2d40 | 2012-03-15 13:43:08 -0700 | [diff] [blame] | 54 | int userId; // user for which this task was created |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 55 | int creatorUid; // The app uid that originally created the task |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 56 | |
| 57 | int numFullscreen; // Number of fullscreen activities. |
| 58 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 59 | // 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 Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 64 | /** List of all activities in the task arranged in history order */ |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 65 | final ArrayList<ActivityRecord> mActivities = new ArrayList<ActivityRecord>(); |
| 66 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 67 | /** Current stack */ |
| 68 | ActivityStack stack; |
| 69 | |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 70 | /** Takes on same set of values as ActivityRecord.mActivityType */ |
| 71 | private int mTaskType; |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 72 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 73 | /** Launch the home activity when leaving this task. Will be false for tasks that are not on |
| 74 | * Display.DEFAULT_DISPLAY. */ |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 75 | boolean mOnTopOfHome = false; |
| 76 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 77 | TaskRecord(int _taskId, ActivityInfo info, Intent _intent, |
| 78 | IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | taskId = _taskId; |
| 80 | affinity = info.taskAffinity; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 81 | voiceSession = _voiceSession; |
| 82 | voiceInteractor = _voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | setIntent(_intent, info); |
| 84 | } |
| 85 | |
| 86 | void touchActiveTime() { |
| 87 | lastActiveTime = android.os.SystemClock.elapsedRealtime(); |
| 88 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | long getInactiveDuration() { |
| 91 | return android.os.SystemClock.elapsedRealtime() - lastActiveTime; |
| 92 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | void setIntent(Intent _intent, ActivityInfo info) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 95 | stringName = null; |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 96 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | if (info.targetActivity == null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 98 | 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 Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 102 | if (_intent.getSelector() != null || _intent.getSourceBounds() != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 103 | _intent = new Intent(_intent); |
| 104 | _intent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 105 | _intent.setSourceBounds(null); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 106 | } |
| 107 | } |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 108 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 109 | "Setting Intent of " + this + " to " + _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | 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 Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 119 | targetIntent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 120 | targetIntent.setSourceBounds(null); |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 121 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 122 | "Setting Intent of " + this + " to target " + targetIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | 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 Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | 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 Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 139 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 140 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
| 141 | creatorUid = info.applicationInfo.uid; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 142 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 146 | |
Dianne Hackborn | 9844d29 | 2013-10-04 16:44:22 -0700 | [diff] [blame] | 147 | 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 Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame^] | 157 | /** Returns the intent for the root activity for this task */ |
| 158 | Intent getBaseIntent() { |
| 159 | return intent != null ? intent : affinityIntent; |
| 160 | } |
| 161 | |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 162 | /** Returns the first non-finishing activity from the root. */ |
| 163 | ActivityRecord getRootActivity() { |
| 164 | for (int i = 0; i < mActivities.size(); i++) { |
| 165 | final ActivityRecord r = mActivities.get(i); |
| 166 | if (r.finishing) { |
| 167 | continue; |
| 168 | } |
| 169 | return r; |
| 170 | } |
| 171 | return null; |
| 172 | } |
| 173 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 174 | ActivityRecord getTopActivity() { |
| 175 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 176 | final ActivityRecord r = mActivities.get(i); |
| 177 | if (r.finishing) { |
| 178 | continue; |
| 179 | } |
| 180 | return r; |
| 181 | } |
| 182 | return null; |
| 183 | } |
| 184 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 185 | ActivityRecord topRunningActivityLocked(ActivityRecord notTop) { |
| 186 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 187 | ActivityRecord r = mActivities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 188 | if (!r.finishing && r != notTop && stack.okToShowLocked(r)) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 189 | return r; |
| 190 | } |
| 191 | } |
| 192 | return null; |
| 193 | } |
| 194 | |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 195 | /** Call after activity movement or finish to make sure that frontOfTask is set correctly */ |
| 196 | final void setFrontOfTask() { |
| 197 | boolean foundFront = false; |
| 198 | final int numActivities = mActivities.size(); |
Craig Mautner | 704e40b | 2013-12-18 16:43:51 -0800 | [diff] [blame] | 199 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 200 | final ActivityRecord r = mActivities.get(activityNdx); |
| 201 | if (foundFront || r.finishing) { |
| 202 | r.frontOfTask = false; |
| 203 | } else { |
| 204 | r.frontOfTask = true; |
| 205 | // Set frontOfTask false for every following activity. |
| 206 | foundFront = true; |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 211 | /** |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 212 | * Reorder the history stack so that the passed activity is brought to the front. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 213 | */ |
| 214 | final void moveActivityToFrontLocked(ActivityRecord newTop) { |
| 215 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop |
| 216 | + " to stack at top", new RuntimeException("here").fillInStackTrace()); |
| 217 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 218 | mActivities.remove(newTop); |
| 219 | mActivities.add(newTop); |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 220 | |
| 221 | setFrontOfTask(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 224 | void addActivityAtBottom(ActivityRecord r) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 225 | addActivityAtIndex(0, r); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void addActivityToTop(ActivityRecord r) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 229 | addActivityAtIndex(mActivities.size(), r); |
| 230 | } |
| 231 | |
| 232 | void addActivityAtIndex(int index, ActivityRecord r) { |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 233 | // 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] | 234 | if (!mActivities.remove(r) && r.fullscreen) { |
| 235 | // Was not previously in list. |
| 236 | numFullscreen++; |
| 237 | } |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 238 | // Only set this based on the first activity |
| 239 | if (mActivities.isEmpty()) { |
| 240 | mTaskType = r.mActivityType; |
| 241 | } else { |
| 242 | // Otherwise make all added activities match this one. |
| 243 | r.mActivityType = mTaskType; |
Craig Mautner | 7873300 | 2013-06-10 13:54:49 -0700 | [diff] [blame] | 244 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 245 | mActivities.add(index, r); |
| 246 | } |
| 247 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 248 | /** @return true if this was the last activity in the task */ |
| 249 | boolean removeActivity(ActivityRecord r) { |
| 250 | if (mActivities.remove(r) && r.fullscreen) { |
| 251 | // Was previously in list. |
| 252 | numFullscreen--; |
| 253 | } |
| 254 | return mActivities.size() == 0; |
| 255 | } |
| 256 | |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 257 | boolean autoRemoveFromRecents() { |
| 258 | return intent != null && |
| 259 | (intent.getFlags() & Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS) != 0; |
| 260 | } |
| 261 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 262 | /** |
| 263 | * Completely remove all activities associated with an existing |
| 264 | * task starting at a specified index. |
| 265 | */ |
| 266 | final void performClearTaskAtIndexLocked(int activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 267 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 268 | for ( ; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 269 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 270 | if (r.finishing) { |
| 271 | continue; |
| 272 | } |
| 273 | if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", false)) { |
| 274 | --activityNdx; |
| 275 | --numActivities; |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Completely remove all activities associated with an existing task. |
| 282 | */ |
| 283 | final void performClearTaskLocked() { |
| 284 | performClearTaskAtIndexLocked(0); |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Perform clear operation as requested by |
| 289 | * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the |
| 290 | * stack to the given task, then look for |
| 291 | * an instance of that activity in the stack and, if found, finish all |
| 292 | * activities on top of it and return the instance. |
| 293 | * |
| 294 | * @param newR Description of the new activity being started. |
| 295 | * @return Returns the old activity that should be continued to be used, |
| 296 | * or null if none was found. |
| 297 | */ |
| 298 | final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 299 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 300 | for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 301 | ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 302 | if (r.finishing) { |
| 303 | continue; |
| 304 | } |
| 305 | if (r.realActivity.equals(newR.realActivity)) { |
| 306 | // Here it is! Now finish everything in front... |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 307 | final ActivityRecord ret = r; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 308 | |
| 309 | for (++activityNdx; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 310 | r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 311 | if (r.finishing) { |
| 312 | continue; |
| 313 | } |
| 314 | ActivityOptions opts = r.takeOptionsLocked(); |
| 315 | if (opts != null) { |
| 316 | ret.updateOptionsLocked(opts); |
| 317 | } |
| 318 | if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", |
| 319 | false)) { |
| 320 | --activityNdx; |
| 321 | --numActivities; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // Finally, if this is a normal launch mode (that is, not |
| 326 | // expecting onNewIntent()), then we will finish the current |
| 327 | // instance of the activity so a new fresh one can be started. |
| 328 | if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE |
| 329 | && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) { |
| 330 | if (!ret.finishing) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 331 | stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null, |
| 332 | "clear", false); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 333 | return null; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | return ret; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | return null; |
| 342 | } |
| 343 | |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 344 | public ActivityManager.TaskThumbnails getTaskThumbnailsLocked() { |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 345 | TaskAccessInfo info = getTaskAccessInfoLocked(); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 346 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 347 | if (resumedActivity != null && resumedActivity.thumbHolder == this) { |
| 348 | info.mainThumbnail = stack.screenshotActivities(resumedActivity); |
| 349 | } |
| 350 | if (info.mainThumbnail == null) { |
| 351 | info.mainThumbnail = lastThumbnail; |
| 352 | } |
| 353 | return info; |
| 354 | } |
| 355 | |
| 356 | public Bitmap getTaskTopThumbnailLocked() { |
| 357 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 358 | if (resumedActivity != null && resumedActivity.task == this) { |
| 359 | // This task is the current resumed task, we just need to take |
| 360 | // a screenshot of it and return that. |
| 361 | return stack.screenshotActivities(resumedActivity); |
| 362 | } |
| 363 | // Return the information about the task, to figure out the top |
| 364 | // thumbnail to return. |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 365 | TaskAccessInfo info = getTaskAccessInfoLocked(); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 366 | if (info.numSubThumbbails <= 0) { |
| 367 | return info.mainThumbnail != null ? info.mainThumbnail : lastThumbnail; |
| 368 | } |
| 369 | return info.subtasks.get(info.numSubThumbbails-1).holder.lastThumbnail; |
| 370 | } |
| 371 | |
| 372 | public ActivityRecord removeTaskActivitiesLocked(int subTaskIndex, |
| 373 | boolean taskRequired) { |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 374 | TaskAccessInfo info = getTaskAccessInfoLocked(); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 375 | if (info.root == null) { |
| 376 | if (taskRequired) { |
| 377 | Slog.w(TAG, "removeTaskLocked: unknown taskId " + taskId); |
| 378 | } |
| 379 | return null; |
| 380 | } |
| 381 | |
| 382 | if (subTaskIndex < 0) { |
| 383 | // Just remove the entire task. |
| 384 | performClearTaskAtIndexLocked(info.rootIndex); |
| 385 | return info.root; |
| 386 | } |
| 387 | |
| 388 | if (subTaskIndex >= info.subtasks.size()) { |
| 389 | if (taskRequired) { |
| 390 | Slog.w(TAG, "removeTaskLocked: unknown subTaskIndex " + subTaskIndex); |
| 391 | } |
| 392 | return null; |
| 393 | } |
| 394 | |
| 395 | // Remove all of this task's activities starting at the sub task. |
| 396 | TaskAccessInfo.SubTask subtask = info.subtasks.get(subTaskIndex); |
| 397 | performClearTaskAtIndexLocked(subtask.index); |
| 398 | return subtask.activity; |
| 399 | } |
| 400 | |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 401 | boolean isHomeTask() { |
| 402 | return mTaskType == ActivityRecord.HOME_ACTIVITY_TYPE; |
| 403 | } |
| 404 | |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 405 | boolean isApplicationTask() { |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 406 | return mTaskType == ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 409 | public TaskAccessInfo getTaskAccessInfoLocked() { |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 410 | final TaskAccessInfo thumbs = new TaskAccessInfo(); |
| 411 | // How many different sub-thumbnails? |
| 412 | final int NA = mActivities.size(); |
| 413 | int j = 0; |
| 414 | ThumbnailHolder holder = null; |
| 415 | while (j < NA) { |
| 416 | ActivityRecord ar = mActivities.get(j); |
| 417 | if (!ar.finishing) { |
| 418 | thumbs.root = ar; |
| 419 | thumbs.rootIndex = j; |
| 420 | holder = ar.thumbHolder; |
| 421 | if (holder != null) { |
| 422 | thumbs.mainThumbnail = holder.lastThumbnail; |
| 423 | } |
| 424 | j++; |
| 425 | break; |
| 426 | } |
| 427 | j++; |
| 428 | } |
| 429 | |
| 430 | if (j >= NA) { |
| 431 | return thumbs; |
| 432 | } |
| 433 | |
| 434 | ArrayList<TaskAccessInfo.SubTask> subtasks = new ArrayList<TaskAccessInfo.SubTask>(); |
| 435 | thumbs.subtasks = subtasks; |
| 436 | while (j < NA) { |
| 437 | ActivityRecord ar = mActivities.get(j); |
| 438 | j++; |
| 439 | if (ar.finishing) { |
| 440 | continue; |
| 441 | } |
| 442 | if (ar.thumbHolder != holder && holder != null) { |
| 443 | thumbs.numSubThumbbails++; |
| 444 | holder = ar.thumbHolder; |
| 445 | TaskAccessInfo.SubTask sub = new TaskAccessInfo.SubTask(); |
| 446 | sub.holder = holder; |
| 447 | sub.activity = ar; |
| 448 | sub.index = j-1; |
| 449 | subtasks.add(sub); |
| 450 | } |
| 451 | } |
| 452 | if (thumbs.numSubThumbbails > 0) { |
| 453 | thumbs.retriever = new IThumbnailRetriever.Stub() { |
| 454 | @Override |
| 455 | public Bitmap getThumbnail(int index) { |
| 456 | if (index < 0 || index >= thumbs.subtasks.size()) { |
| 457 | return null; |
| 458 | } |
| 459 | TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index); |
| 460 | ActivityRecord resumedActivity = stack.mResumedActivity; |
| 461 | if (resumedActivity != null && resumedActivity.thumbHolder == sub.holder) { |
| 462 | return stack.screenshotActivities(resumedActivity); |
| 463 | } |
| 464 | return sub.holder.lastThumbnail; |
| 465 | } |
| 466 | }; |
| 467 | } |
| 468 | return thumbs; |
| 469 | } |
| 470 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 471 | /** |
| 472 | * Find the activity in the history stack within the given task. Returns |
| 473 | * the index within the history at which it's found, or < 0 if not found. |
| 474 | */ |
| 475 | final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) { |
| 476 | final ComponentName realActivity = r.realActivity; |
| 477 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 478 | ActivityRecord candidate = mActivities.get(activityNdx); |
| 479 | if (candidate.finishing) { |
| 480 | continue; |
| 481 | } |
| 482 | if (candidate.realActivity.equals(realActivity)) { |
| 483 | return candidate; |
| 484 | } |
| 485 | } |
| 486 | return null; |
| 487 | } |
| 488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | void dump(PrintWriter pw, String prefix) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 490 | if (numActivities != 0 || rootWasReset || userId != 0 || numFullscreen != 0) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 491 | pw.print(prefix); pw.print("numActivities="); pw.print(numActivities); |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 492 | pw.print(" rootWasReset="); pw.print(rootWasReset); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 493 | pw.print(" userId="); pw.print(userId); |
Craig Mautner | 8025935 | 2013-09-28 12:35:25 -0700 | [diff] [blame] | 494 | pw.print(" mTaskType="); pw.print(mTaskType); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 495 | pw.print(" numFullscreen="); pw.print(numFullscreen); |
| 496 | pw.print(" mOnTopOfHome="); pw.println(mOnTopOfHome); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 497 | } |
| 498 | if (affinity != null) { |
| 499 | pw.print(prefix); pw.print("affinity="); pw.println(affinity); |
| 500 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 501 | if (voiceSession != null || voiceInteractor != null) { |
| 502 | pw.print(prefix); pw.print("VOICE: session=0x"); |
| 503 | pw.print(Integer.toHexString(System.identityHashCode(voiceSession))); |
| 504 | pw.print(" interactor=0x"); |
| 505 | pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor))); |
| 506 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 507 | if (intent != null) { |
| 508 | StringBuilder sb = new StringBuilder(128); |
| 509 | sb.append(prefix); sb.append("intent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 510 | intent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 511 | sb.append('}'); |
| 512 | pw.println(sb.toString()); |
| 513 | } |
| 514 | if (affinityIntent != null) { |
| 515 | StringBuilder sb = new StringBuilder(128); |
| 516 | sb.append(prefix); sb.append("affinityIntent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 517 | affinityIntent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 518 | sb.append('}'); |
| 519 | pw.println(sb.toString()); |
| 520 | } |
| 521 | if (origActivity != null) { |
| 522 | pw.print(prefix); pw.print("origActivity="); |
| 523 | pw.println(origActivity.flattenToShortString()); |
| 524 | } |
| 525 | if (realActivity != null) { |
| 526 | pw.print(prefix); pw.print("realActivity="); |
| 527 | pw.println(realActivity.flattenToShortString()); |
| 528 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 529 | pw.print(prefix); pw.print("Activities="); pw.println(mActivities); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 530 | if (!askedCompatMode) { |
| 531 | pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode); |
| 532 | } |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 533 | pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail); |
| 534 | pw.print(" lastDescription="); pw.println(lastDescription); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 535 | pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime); |
| 536 | pw.print(" (inactive for "); |
| 537 | pw.print((getInactiveDuration()/1000)); pw.println("s)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 540 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 542 | StringBuilder sb = new StringBuilder(128); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 543 | if (stringName != null) { |
| 544 | sb.append(stringName); |
| 545 | sb.append(" U="); |
| 546 | sb.append(userId); |
| 547 | sb.append(" sz="); |
| 548 | sb.append(mActivities.size()); |
| 549 | sb.append('}'); |
| 550 | return sb.toString(); |
| 551 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 552 | sb.append("TaskRecord{"); |
| 553 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 554 | sb.append(" #"); |
| 555 | sb.append(taskId); |
| 556 | if (affinity != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 557 | sb.append(" A="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 558 | sb.append(affinity); |
| 559 | } else if (intent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 560 | sb.append(" I="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 561 | sb.append(intent.getComponent().flattenToShortString()); |
| 562 | } else if (affinityIntent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 563 | sb.append(" aI="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 564 | sb.append(affinityIntent.getComponent().flattenToShortString()); |
| 565 | } else { |
| 566 | sb.append(" ??"); |
| 567 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 568 | stringName = sb.toString(); |
| 569 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | } |
| 571 | } |