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