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 | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 20 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
| 21 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
| 22 | import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 23 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 24 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 25 | import android.app.Activity; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 27 | import android.app.ActivityManager.TaskThumbnail; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 28 | import android.app.ActivityOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.ComponentName; |
| 30 | import android.content.Intent; |
| 31 | import android.content.pm.ActivityInfo; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 32 | import android.graphics.Bitmap; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 33 | import android.os.ParcelFileDescriptor; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 34 | import android.os.UserHandle; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 35 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 36 | import android.util.Slog; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 37 | import com.android.internal.app.IVoiceInteractor; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 38 | import com.android.internal.util.XmlUtils; |
| 39 | import org.xmlpull.v1.XmlPullParser; |
| 40 | import org.xmlpull.v1.XmlPullParserException; |
| 41 | import org.xmlpull.v1.XmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 43 | import java.io.File; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 44 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import java.io.PrintWriter; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 46 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 48 | final class TaskRecord { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 49 | private static final String ATTR_TASKID = "task_id"; |
| 50 | private static final String TAG_INTENT = "intent"; |
| 51 | private static final String TAG_AFFINITYINTENT = "affinity_intent"; |
| 52 | private static final String ATTR_REALACTIVITY = "real_activity"; |
| 53 | private static final String ATTR_ORIGACTIVITY = "orig_activity"; |
| 54 | private static final String TAG_ACTIVITY = "activity"; |
| 55 | private static final String ATTR_AFFINITY = "affinity"; |
| 56 | private static final String ATTR_ROOTHASRESET = "root_has_reset"; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 57 | private static final String ATTR_AUTOREMOVERECENTS = "auto_remove_recents"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 58 | private static final String ATTR_ASKEDCOMPATMODE = "asked_compat_mode"; |
| 59 | private static final String ATTR_USERID = "user_id"; |
| 60 | private static final String ATTR_TASKTYPE = "task_type"; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 61 | private static final String ATTR_FIRSTACTIVETIME = "first_active_time"; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 62 | private static final String ATTR_LASTACTIVETIME = "last_active_time"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 63 | private static final String ATTR_LASTDESCRIPTION = "last_description"; |
| 64 | private static final String ATTR_LASTTIMEMOVED = "last_time_moved"; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 65 | private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity"; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 66 | private static final String ATTR_TASKDESCRIPTIONLABEL = "task_description_label"; |
| 67 | private static final String ATTR_TASKDESCRIPTIONCOLOR = "task_description_color"; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 68 | private static final String ATTR_TASK_AFFILIATION = "task_affiliation"; |
| 69 | private static final String ATTR_PREV_AFFILIATION = "prev_affiliation"; |
| 70 | private static final String ATTR_NEXT_AFFILIATION = "next_affiliation"; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 71 | private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color"; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 72 | private static final String ATTR_CALLING_UID = "calling_uid"; |
| 73 | private static final String ATTR_CALLING_PACKAGE = "calling_package"; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 74 | private static final String LAST_ACTIVITY_ICON_SUFFIX = "_last_activity_icon_"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 75 | |
| 76 | private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail"; |
| 77 | |
Craig Mautner | 0b633fc | 2014-07-23 10:42:18 -0700 | [diff] [blame] | 78 | static final boolean IGNORE_RETURN_TO_RECENTS = true; |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | final int taskId; // Unique identifier for this task. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 81 | String affinity; // The affinity name for this task, or null. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 82 | final IVoiceInteractionSession voiceSession; // Voice interaction session driving task |
| 83 | final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | Intent intent; // The original intent that started the task. |
| 85 | Intent affinityIntent; // Intent of affinity-moved activity that started this task. |
| 86 | ComponentName origActivity; // The non-alias activity component of the intent. |
| 87 | ComponentName realActivity; // The actual activity component that started the task. |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 88 | long firstActiveTime; // First time this task was active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | long lastActiveTime; // Last time this task was active, including sleep. |
| 90 | boolean rootWasReset; // True if the intent at the root of the task had |
| 91 | // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 92 | boolean autoRemoveRecents; // If true, we should automatically remove the task from |
| 93 | // recents when activity finishes |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 94 | boolean askedCompatMode;// Have asked the user about compat mode for this task. |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 95 | boolean hasBeenVisible; // Set if any activities in the task have been visible to the user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 97 | String stringName; // caching of toString() result. |
Dianne Hackborn | 9da2d40 | 2012-03-15 13:43:08 -0700 | [diff] [blame] | 98 | int userId; // user for which this task was created |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 99 | int creatorUid; // The app uid that originally created the task |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 100 | |
| 101 | int numFullscreen; // Number of fullscreen activities. |
| 102 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 103 | // This represents the last resolved activity values for this task |
| 104 | // NOTE: This value needs to be persisted with each task |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 105 | ActivityManager.TaskDescription lastTaskDescription = |
| 106 | new ActivityManager.TaskDescription(); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 107 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 108 | /** List of all activities in the task arranged in history order */ |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 109 | final ArrayList<ActivityRecord> mActivities; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 110 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 111 | /** Current stack */ |
| 112 | ActivityStack stack; |
| 113 | |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 114 | /** Takes on same set of values as ActivityRecord.mActivityType */ |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 115 | int taskType; |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 116 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 117 | /** Takes on same value as first root activity */ |
| 118 | boolean isPersistable = false; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 119 | int maxRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 120 | |
| 121 | /** Only used for persistable tasks, otherwise 0. The last time this task was moved. Used for |
| 122 | * determining the order when restoring. Sign indicates whether last task movement was to front |
| 123 | * (positive) or back (negative). Absolute value indicates time. */ |
| 124 | long mLastTimeMoved = System.currentTimeMillis(); |
| 125 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 126 | /** Indication of what to run next when task exits. Use ActivityRecord types. |
| 127 | * ActivityRecord.APPLICATION_ACTIVITY_TYPE indicates to resume the task below this one in the |
| 128 | * task stack. */ |
| 129 | private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 130 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 131 | /** If original intent did not allow relinquishing task identity, save that information */ |
| 132 | boolean mNeverRelinquishIdentity = true; |
| 133 | |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 134 | // Used in the unique case where we are clearing the task in order to reuse it. In that case we |
| 135 | // do not want to delete the stack when the task goes empty. |
| 136 | boolean mReuseTask = false; |
| 137 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 138 | private Bitmap mLastThumbnail; // Last thumbnail captured for this item. |
| 139 | private final File mLastThumbnailFile; // File containing last thubmnail. |
| 140 | private final String mFilename; |
| 141 | CharSequence lastDescription; // Last description captured for this item. |
| 142 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 143 | int mAffiliatedTaskId; // taskId of parent affiliation or self if no parent. |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 144 | int mAffiliatedTaskColor; // color of the parent task affiliation. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 145 | TaskRecord mPrevAffiliate; // previous task in affiliated chain. |
| 146 | int mPrevAffiliateTaskId = -1; // previous id for persistence. |
| 147 | TaskRecord mNextAffiliate; // next task in affiliated chain. |
| 148 | int mNextAffiliateTaskId = -1; // next id for persistence. |
| 149 | |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 150 | // For relaunching the task from recents as though it was launched by the original launcher. |
| 151 | int mCallingUid; |
| 152 | String mCallingPackage; |
| 153 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 154 | final ActivityManagerService mService; |
| 155 | |
| 156 | TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 157 | IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 158 | mService = service; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 159 | mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX + |
| 160 | TaskPersister.IMAGE_EXTENSION; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 161 | mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | taskId = _taskId; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 163 | mAffiliatedTaskId = _taskId; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 164 | voiceSession = _voiceSession; |
| 165 | voiceInteractor = _voiceInteractor; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 166 | mActivities = new ArrayList<ActivityRecord>(); |
Martijn Coenen | d4a6970 | 2014-06-30 11:12:17 -0700 | [diff] [blame] | 167 | setIntent(_intent, info); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | TaskRecord(ActivityManagerService service, int _taskId, Intent _intent, Intent _affinityIntent, |
| 171 | String _affinity, ComponentName _realActivity, ComponentName _origActivity, |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 172 | boolean _rootWasReset, boolean _autoRemoveRecents, boolean _askedCompatMode, |
| 173 | int _taskType, int _userId, |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 174 | String _lastDescription, ArrayList<ActivityRecord> activities, long _firstActiveTime, |
| 175 | long _lastActiveTime, long lastTimeMoved, boolean neverRelinquishIdentity, |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 176 | ActivityManager.TaskDescription _lastTaskDescription, int taskAffiliation, |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 177 | int prevTaskId, int nextTaskId, int taskAffiliationColor, int callingUid, |
| 178 | String callingPackage) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 179 | mService = service; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 180 | mFilename = String.valueOf(_taskId) + TASK_THUMBNAIL_SUFFIX + |
| 181 | TaskPersister.IMAGE_EXTENSION; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 182 | mLastThumbnailFile = new File(TaskPersister.sImagesDir, mFilename); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 183 | taskId = _taskId; |
| 184 | intent = _intent; |
| 185 | affinityIntent = _affinityIntent; |
| 186 | affinity = _affinity; |
| 187 | voiceSession = null; |
| 188 | voiceInteractor = null; |
| 189 | realActivity = _realActivity; |
| 190 | origActivity = _origActivity; |
| 191 | rootWasReset = _rootWasReset; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 192 | autoRemoveRecents = _autoRemoveRecents; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 193 | askedCompatMode = _askedCompatMode; |
| 194 | taskType = _taskType; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 195 | mTaskToReturnTo = HOME_ACTIVITY_TYPE; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 196 | userId = _userId; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 197 | firstActiveTime = _firstActiveTime; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 198 | lastActiveTime = _lastActiveTime; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 199 | lastDescription = _lastDescription; |
| 200 | mActivities = activities; |
| 201 | mLastTimeMoved = lastTimeMoved; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 202 | mNeverRelinquishIdentity = neverRelinquishIdentity; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 203 | lastTaskDescription = _lastTaskDescription; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 204 | mAffiliatedTaskId = taskAffiliation; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 205 | mAffiliatedTaskColor = taskAffiliationColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 206 | mPrevAffiliateTaskId = prevTaskId; |
| 207 | mNextAffiliateTaskId = nextTaskId; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 208 | mCallingUid = callingUid; |
| 209 | mCallingPackage = callingPackage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void touchActiveTime() { |
Craig Mautner | 494f6bdd | 2014-07-21 11:17:46 -0700 | [diff] [blame] | 213 | lastActiveTime = System.currentTimeMillis(); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 214 | if (firstActiveTime == 0) { |
| 215 | firstActiveTime = lastActiveTime; |
| 216 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | long getInactiveDuration() { |
Craig Mautner | 494f6bdd | 2014-07-21 11:17:46 -0700 | [diff] [blame] | 220 | return System.currentTimeMillis() - lastActiveTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | void setIntent(Intent _intent, ActivityInfo info) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 224 | if (intent == null) { |
| 225 | mNeverRelinquishIdentity = |
| 226 | (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0; |
| 227 | } else if (mNeverRelinquishIdentity) { |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | affinity = info.taskAffinity; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 232 | stringName = null; |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | if (info.targetActivity == null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 235 | if (_intent != null) { |
| 236 | // If this Intent has a selector, we want to clear it for the |
| 237 | // recent task since it is not relevant if the user later wants |
| 238 | // to re-launch the app. |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 239 | if (_intent.getSelector() != null || _intent.getSourceBounds() != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 240 | _intent = new Intent(_intent); |
| 241 | _intent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 242 | _intent.setSourceBounds(null); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 245 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 246 | "Setting Intent of " + this + " to " + _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | intent = _intent; |
| 248 | realActivity = _intent != null ? _intent.getComponent() : null; |
| 249 | origActivity = null; |
| 250 | } else { |
| 251 | ComponentName targetComponent = new ComponentName( |
| 252 | info.packageName, info.targetActivity); |
| 253 | if (_intent != null) { |
| 254 | Intent targetIntent = new Intent(_intent); |
| 255 | targetIntent.setComponent(targetComponent); |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 256 | targetIntent.setSelector(null); |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 257 | targetIntent.setSourceBounds(null); |
Dianne Hackborn | 7f96b79 | 2012-05-29 18:46:45 -0700 | [diff] [blame] | 258 | if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG, |
| 259 | "Setting Intent of " + this + " to target " + targetIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | intent = targetIntent; |
| 261 | realActivity = targetComponent; |
| 262 | origActivity = _intent.getComponent(); |
| 263 | } else { |
| 264 | intent = null; |
| 265 | realActivity = targetComponent; |
| 266 | origActivity = new ComponentName(info.packageName, info.name); |
| 267 | } |
| 268 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | if (intent != null && |
| 271 | (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
| 272 | // Once we are set to an Intent with this flag, we count this |
| 273 | // task as having a true root activity. |
| 274 | rootWasReset = true; |
| 275 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 276 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 277 | userId = UserHandle.getUserId(info.applicationInfo.uid); |
| 278 | creatorUid = info.applicationInfo.uid; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 279 | if ((info.flags & ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS) != 0) { |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 280 | // If the activity itself has requested auto-remove, then just always do it. |
| 281 | autoRemoveRecents = true; |
| 282 | } else if ((intent.getFlags()&(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
| 283 | |Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS)) == Intent.FLAG_ACTIVITY_NEW_DOCUMENT) { |
| 284 | // If the caller has not asked for the document to be retained, then we may |
| 285 | // want to turn on auto-remove, depending on whether the target has set its |
| 286 | // own document launch mode. |
| 287 | if (info.documentLaunchMode != ActivityInfo.DOCUMENT_LAUNCH_NONE) { |
| 288 | autoRemoveRecents = false; |
| 289 | } else { |
| 290 | autoRemoveRecents = true; |
| 291 | } |
| 292 | } else { |
| 293 | autoRemoveRecents = false; |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 296 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 297 | void setTaskToReturnTo(int taskToReturnTo) { |
Craig Mautner | 0b633fc | 2014-07-23 10:42:18 -0700 | [diff] [blame] | 298 | if (IGNORE_RETURN_TO_RECENTS && taskToReturnTo == RECENTS_ACTIVITY_TYPE) { |
| 299 | taskToReturnTo = HOME_ACTIVITY_TYPE; |
| 300 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 301 | mTaskToReturnTo = taskToReturnTo; |
| 302 | } |
| 303 | |
| 304 | int getTaskToReturnTo() { |
| 305 | return mTaskToReturnTo; |
| 306 | } |
| 307 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 308 | void setPrevAffiliate(TaskRecord prevAffiliate) { |
| 309 | mPrevAffiliate = prevAffiliate; |
| 310 | mPrevAffiliateTaskId = prevAffiliate == null ? -1 : prevAffiliate.taskId; |
| 311 | } |
| 312 | |
| 313 | void setNextAffiliate(TaskRecord nextAffiliate) { |
| 314 | mNextAffiliate = nextAffiliate; |
| 315 | mNextAffiliateTaskId = nextAffiliate == null ? -1 : nextAffiliate.taskId; |
| 316 | } |
| 317 | |
| 318 | // Close up recents linked list. |
| 319 | void closeRecentsChain() { |
| 320 | if (mPrevAffiliate != null) { |
| 321 | mPrevAffiliate.setNextAffiliate(mNextAffiliate); |
| 322 | } |
| 323 | if (mNextAffiliate != null) { |
| 324 | mNextAffiliate.setPrevAffiliate(mPrevAffiliate); |
| 325 | } |
| 326 | setPrevAffiliate(null); |
| 327 | setNextAffiliate(null); |
| 328 | } |
| 329 | |
| 330 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
| 331 | closeRecentsChain(); |
| 332 | mAffiliatedTaskId = taskToAffiliateWith.mAffiliatedTaskId; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 333 | mAffiliatedTaskColor = taskToAffiliateWith.mAffiliatedTaskColor; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 334 | // Find the end |
| 335 | while (taskToAffiliateWith.mNextAffiliate != null) { |
| 336 | final TaskRecord nextRecents = taskToAffiliateWith.mNextAffiliate; |
| 337 | if (nextRecents.mAffiliatedTaskId != mAffiliatedTaskId) { |
| 338 | Slog.e(TAG, "setTaskToAffiliateWith: nextRecents=" + nextRecents + " affilTaskId=" |
| 339 | + nextRecents.mAffiliatedTaskId + " should be " + mAffiliatedTaskId); |
| 340 | if (nextRecents.mPrevAffiliate == taskToAffiliateWith) { |
| 341 | nextRecents.setPrevAffiliate(null); |
| 342 | } |
| 343 | taskToAffiliateWith.setNextAffiliate(null); |
| 344 | break; |
| 345 | } |
| 346 | taskToAffiliateWith = nextRecents; |
| 347 | } |
| 348 | taskToAffiliateWith.setNextAffiliate(this); |
| 349 | setPrevAffiliate(taskToAffiliateWith); |
| 350 | setNextAffiliate(null); |
| 351 | } |
| 352 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 353 | void setLastThumbnail(Bitmap thumbnail) { |
| 354 | mLastThumbnail = thumbnail; |
| 355 | if (thumbnail == null) { |
| 356 | if (mLastThumbnailFile != null) { |
| 357 | mLastThumbnailFile.delete(); |
| 358 | } |
| 359 | } else { |
| 360 | mService.mTaskPersister.saveImage(thumbnail, mFilename); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | void getLastThumbnail(TaskThumbnail thumbs) { |
| 365 | thumbs.mainThumbnail = mLastThumbnail; |
| 366 | thumbs.thumbnailFileDescriptor = null; |
Craig Mautner | f4f8bb7 | 2014-07-29 10:41:40 -0700 | [diff] [blame] | 367 | if (mLastThumbnail == null) { |
| 368 | thumbs.mainThumbnail = mService.mTaskPersister.getThumbnail(mFilename); |
| 369 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 370 | if (mLastThumbnailFile.exists()) { |
| 371 | try { |
| 372 | thumbs.thumbnailFileDescriptor = ParcelFileDescriptor.open(mLastThumbnailFile, |
| 373 | ParcelFileDescriptor.MODE_READ_ONLY); |
| 374 | } catch (IOException e) { |
Dianne Hackborn | 9844d29 | 2013-10-04 16:44:22 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 379 | void freeLastThumbnail() { |
| 380 | mLastThumbnail = null; |
| 381 | } |
| 382 | |
| 383 | void disposeThumbnail() { |
| 384 | mLastThumbnail = null; |
| 385 | lastDescription = null; |
| 386 | } |
| 387 | |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 388 | /** Returns the intent for the root activity for this task */ |
| 389 | Intent getBaseIntent() { |
| 390 | return intent != null ? intent : affinityIntent; |
| 391 | } |
| 392 | |
Winson Chung | 3b3f464 | 2014-04-22 10:08:18 -0700 | [diff] [blame] | 393 | /** Returns the first non-finishing activity from the root. */ |
| 394 | ActivityRecord getRootActivity() { |
| 395 | for (int i = 0; i < mActivities.size(); i++) { |
| 396 | final ActivityRecord r = mActivities.get(i); |
| 397 | if (r.finishing) { |
| 398 | continue; |
| 399 | } |
| 400 | return r; |
| 401 | } |
| 402 | return null; |
| 403 | } |
| 404 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 405 | ActivityRecord getTopActivity() { |
| 406 | for (int i = mActivities.size() - 1; i >= 0; --i) { |
| 407 | final ActivityRecord r = mActivities.get(i); |
| 408 | if (r.finishing) { |
| 409 | continue; |
| 410 | } |
| 411 | return r; |
| 412 | } |
| 413 | return null; |
| 414 | } |
| 415 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 416 | ActivityRecord topRunningActivityLocked(ActivityRecord notTop) { |
| 417 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 418 | ActivityRecord r = mActivities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 419 | if (!r.finishing && r != notTop && stack.okToShowLocked(r)) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 420 | return r; |
| 421 | } |
| 422 | } |
| 423 | return null; |
| 424 | } |
| 425 | |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 426 | /** Call after activity movement or finish to make sure that frontOfTask is set correctly */ |
| 427 | final void setFrontOfTask() { |
| 428 | boolean foundFront = false; |
| 429 | final int numActivities = mActivities.size(); |
Craig Mautner | 704e40b | 2013-12-18 16:43:51 -0800 | [diff] [blame] | 430 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 431 | final ActivityRecord r = mActivities.get(activityNdx); |
| 432 | if (foundFront || r.finishing) { |
| 433 | r.frontOfTask = false; |
| 434 | } else { |
| 435 | r.frontOfTask = true; |
| 436 | // Set frontOfTask false for every following activity. |
| 437 | foundFront = true; |
| 438 | } |
| 439 | } |
Craig Mautner | 9587ee0 | 2014-06-23 15:00:10 +0000 | [diff] [blame] | 440 | if (!foundFront && numActivities > 0) { |
| 441 | // All activities of this task are finishing. As we ought to have a frontOfTask |
| 442 | // activity, make the bottom activity front. |
| 443 | mActivities.get(0).frontOfTask = true; |
| 444 | } |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 447 | /** |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 448 | * 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] | 449 | */ |
| 450 | final void moveActivityToFrontLocked(ActivityRecord newTop) { |
| 451 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop |
| 452 | + " to stack at top", new RuntimeException("here").fillInStackTrace()); |
| 453 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 454 | mActivities.remove(newTop); |
| 455 | mActivities.add(newTop); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 456 | updateEffectiveIntent(); |
Craig Mautner | 3b475fe | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 457 | |
| 458 | setFrontOfTask(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 461 | void addActivityAtBottom(ActivityRecord r) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 462 | addActivityAtIndex(0, r); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void addActivityToTop(ActivityRecord r) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 466 | addActivityAtIndex(mActivities.size(), r); |
| 467 | } |
| 468 | |
| 469 | void addActivityAtIndex(int index, ActivityRecord r) { |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 470 | // 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] | 471 | if (!mActivities.remove(r) && r.fullscreen) { |
| 472 | // Was not previously in list. |
| 473 | numFullscreen++; |
| 474 | } |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 475 | // Only set this based on the first activity |
| 476 | if (mActivities.isEmpty()) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 477 | taskType = r.mActivityType; |
| 478 | isPersistable = r.isPersistable(); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 479 | mCallingUid = r.launchedFromUid; |
| 480 | mCallingPackage = r.launchedFromPackage; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 481 | // Clamp to [1, 100]. |
| 482 | maxRecents = Math.min(Math.max(r.info.maxRecents, 1), 100); |
Craig Mautner | 2c1faed | 2013-07-23 12:56:02 -0700 | [diff] [blame] | 483 | } else { |
| 484 | // Otherwise make all added activities match this one. |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 485 | r.mActivityType = taskType; |
Craig Mautner | 7873300 | 2013-06-10 13:54:49 -0700 | [diff] [blame] | 486 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 487 | mActivities.add(index, r); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 488 | updateEffectiveIntent(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 489 | if (r.isPersistable()) { |
| 490 | mService.notifyTaskPersisterLocked(this, false); |
| 491 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 492 | } |
| 493 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 494 | /** @return true if this was the last activity in the task */ |
| 495 | boolean removeActivity(ActivityRecord r) { |
| 496 | if (mActivities.remove(r) && r.fullscreen) { |
| 497 | // Was previously in list. |
| 498 | numFullscreen--; |
| 499 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 500 | if (r.isPersistable()) { |
| 501 | mService.notifyTaskPersisterLocked(this, false); |
| 502 | } |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 503 | if (mActivities.isEmpty()) { |
Craig Mautner | 5afcd4d | 2014-06-21 18:11:33 -0700 | [diff] [blame] | 504 | return !mReuseTask; |
Craig Mautner | 4132620 | 2014-06-20 14:38:21 -0700 | [diff] [blame] | 505 | } |
| 506 | updateEffectiveIntent(); |
| 507 | return false; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 508 | } |
| 509 | |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 510 | boolean autoRemoveFromRecents() { |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 511 | // We will automatically remove the task either if it has explicitly asked for |
| 512 | // this, or it is empty and has never contained an activity that got shown to |
| 513 | // the user. |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 514 | return autoRemoveRecents || (mActivities.isEmpty() && !hasBeenVisible); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 517 | /** |
| 518 | * Completely remove all activities associated with an existing |
| 519 | * task starting at a specified index. |
| 520 | */ |
| 521 | final void performClearTaskAtIndexLocked(int activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 522 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 523 | for ( ; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 524 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 525 | if (r.finishing) { |
| 526 | continue; |
| 527 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 528 | if (stack == null) { |
| 529 | // Task was restored from persistent storage. |
| 530 | r.takeFromHistory(); |
| 531 | mActivities.remove(activityNdx); |
| 532 | --activityNdx; |
| 533 | --numActivities; |
| 534 | } else if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", |
| 535 | false)) { |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 536 | --activityNdx; |
| 537 | --numActivities; |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * Completely remove all activities associated with an existing task. |
| 544 | */ |
| 545 | final void performClearTaskLocked() { |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 546 | mReuseTask = true; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 547 | performClearTaskAtIndexLocked(0); |
Craig Mautner | 362449a | 2014-06-20 14:04:39 -0700 | [diff] [blame] | 548 | mReuseTask = false; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Perform clear operation as requested by |
| 553 | * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the |
| 554 | * stack to the given task, then look for |
| 555 | * an instance of that activity in the stack and, if found, finish all |
| 556 | * activities on top of it and return the instance. |
| 557 | * |
| 558 | * @param newR Description of the new activity being started. |
| 559 | * @return Returns the old activity that should be continued to be used, |
| 560 | * or null if none was found. |
| 561 | */ |
| 562 | final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 563 | int numActivities = mActivities.size(); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 564 | for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 565 | ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 566 | if (r.finishing) { |
| 567 | continue; |
| 568 | } |
| 569 | if (r.realActivity.equals(newR.realActivity)) { |
| 570 | // Here it is! Now finish everything in front... |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 571 | final ActivityRecord ret = r; |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 572 | |
| 573 | for (++activityNdx; activityNdx < numActivities; ++activityNdx) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 574 | r = mActivities.get(activityNdx); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 575 | if (r.finishing) { |
| 576 | continue; |
| 577 | } |
| 578 | ActivityOptions opts = r.takeOptionsLocked(); |
| 579 | if (opts != null) { |
| 580 | ret.updateOptionsLocked(opts); |
| 581 | } |
| 582 | if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", |
| 583 | false)) { |
| 584 | --activityNdx; |
| 585 | --numActivities; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | // Finally, if this is a normal launch mode (that is, not |
| 590 | // expecting onNewIntent()), then we will finish the current |
| 591 | // instance of the activity so a new fresh one can be started. |
| 592 | if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE |
| 593 | && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) { |
| 594 | if (!ret.finishing) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 595 | stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null, |
| 596 | "clear", false); |
Craig Mautner | b0f7dc7 | 2013-04-01 16:34:45 -0700 | [diff] [blame] | 597 | return null; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | return ret; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | return null; |
| 606 | } |
| 607 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 608 | public TaskThumbnail getTaskThumbnailLocked() { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 609 | if (stack != null) { |
| 610 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 611 | if (resumedActivity != null && resumedActivity.task == this) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 612 | final Bitmap thumbnail = stack.screenshotActivities(resumedActivity); |
| 613 | setLastThumbnail(thumbnail); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 614 | } |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 615 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 616 | final TaskThumbnail taskThumbnail = new TaskThumbnail(); |
| 617 | getLastThumbnail(taskThumbnail); |
| 618 | return taskThumbnail; |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 621 | public void removeTaskActivitiesLocked() { |
| 622 | // Just remove the entire task. |
| 623 | performClearTaskAtIndexLocked(0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 626 | boolean isHomeTask() { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 627 | return taskType == HOME_ACTIVITY_TYPE; |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 630 | boolean isApplicationTask() { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 631 | return taskType == APPLICATION_ACTIVITY_TYPE; |
| 632 | } |
| 633 | |
| 634 | boolean isOverHomeStack() { |
| 635 | return mTaskToReturnTo == HOME_ACTIVITY_TYPE || mTaskToReturnTo == RECENTS_ACTIVITY_TYPE; |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 638 | /** |
| 639 | * Find the activity in the history stack within the given task. Returns |
| 640 | * the index within the history at which it's found, or < 0 if not found. |
| 641 | */ |
| 642 | final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) { |
| 643 | final ComponentName realActivity = r.realActivity; |
| 644 | for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 645 | ActivityRecord candidate = mActivities.get(activityNdx); |
| 646 | if (candidate.finishing) { |
| 647 | continue; |
| 648 | } |
| 649 | if (candidate.realActivity.equals(realActivity)) { |
| 650 | return candidate; |
| 651 | } |
| 652 | } |
| 653 | return null; |
| 654 | } |
| 655 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 656 | /** Updates the last task description values. */ |
| 657 | void updateTaskDescription() { |
| 658 | // Traverse upwards looking for any break between main task activities and |
| 659 | // utility activities. |
| 660 | int activityNdx; |
| 661 | final int numActivities = mActivities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 662 | final boolean relinquish = numActivities == 0 ? false : |
| 663 | (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 664 | for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 665 | ++activityNdx) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 666 | final ActivityRecord r = mActivities.get(activityNdx); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 667 | if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
| 668 | // This will be the top activity for determining taskDescription. Pre-inc to |
| 669 | // overcome initial decrement below. |
| 670 | ++activityNdx; |
| 671 | break; |
| 672 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 673 | if (r.intent != null && |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 674 | (r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 675 | break; |
| 676 | } |
| 677 | } |
| 678 | if (activityNdx > 0) { |
| 679 | // Traverse downwards starting below break looking for set label, icon. |
| 680 | // Note that if there are activities in the task but none of them set the |
| 681 | // recent activity values, then we do not fall back to the last set |
| 682 | // values in the TaskRecord. |
| 683 | String label = null; |
| 684 | Bitmap icon = null; |
| 685 | int colorPrimary = 0; |
| 686 | for (--activityNdx; activityNdx >= 0; --activityNdx) { |
| 687 | final ActivityRecord r = mActivities.get(activityNdx); |
| 688 | if (r.taskDescription != null) { |
| 689 | if (label == null) { |
| 690 | label = r.taskDescription.getLabel(); |
| 691 | } |
| 692 | if (icon == null) { |
| 693 | icon = r.taskDescription.getIcon(); |
| 694 | } |
| 695 | if (colorPrimary == 0) { |
| 696 | colorPrimary = r.taskDescription.getPrimaryColor(); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | } |
| 700 | lastTaskDescription = new ActivityManager.TaskDescription(label, icon, colorPrimary); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 701 | // Update the task affiliation color if we are the parent of the group |
| 702 | if (taskId == mAffiliatedTaskId) { |
| 703 | mAffiliatedTaskColor = lastTaskDescription.getPrimaryColor(); |
| 704 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 708 | int findEffectiveRootIndex() { |
| 709 | int activityNdx; |
| 710 | final int topActivityNdx = mActivities.size() - 1; |
| 711 | for (activityNdx = 0; activityNdx < topActivityNdx; ++activityNdx) { |
| 712 | final ActivityRecord r = mActivities.get(activityNdx); |
| 713 | if (r.finishing) { |
| 714 | continue; |
| 715 | } |
| 716 | if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) { |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | return activityNdx; |
| 721 | } |
| 722 | |
| 723 | void updateEffectiveIntent() { |
| 724 | final int effectiveRootIndex = findEffectiveRootIndex(); |
| 725 | final ActivityRecord r = mActivities.get(effectiveRootIndex); |
| 726 | setIntent(r.intent, r.info); |
| 727 | } |
| 728 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 729 | void saveTaskDescription(ActivityManager.TaskDescription taskDescription, |
| 730 | String iconFilename, XmlSerializer out) throws IOException { |
| 731 | if (taskDescription != null) { |
| 732 | final String label = taskDescription.getLabel(); |
| 733 | if (label != null) { |
| 734 | out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, label); |
| 735 | } |
| 736 | final int colorPrimary = taskDescription.getPrimaryColor(); |
| 737 | if (colorPrimary != 0) { |
| 738 | out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR, Integer.toHexString(colorPrimary)); |
| 739 | } |
| 740 | final Bitmap icon = taskDescription.getIcon(); |
| 741 | if (icon != null) { |
| 742 | mService.mTaskPersister.saveImage(icon, iconFilename); |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | static boolean readTaskDescriptionAttribute(ActivityManager.TaskDescription taskDescription, |
| 748 | String attrName, String attrValue) { |
| 749 | if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) { |
| 750 | taskDescription.setLabel(attrValue); |
| 751 | } else if (ATTR_TASKDESCRIPTIONCOLOR.equals(attrName)) { |
| 752 | taskDescription.setPrimaryColor((int) Long.parseLong(attrValue, 16)); |
| 753 | } else { |
| 754 | return false; |
| 755 | } |
| 756 | return true; |
| 757 | } |
| 758 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 759 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 760 | Slog.i(TAG, "Saving task=" + this); |
| 761 | |
| 762 | out.attribute(null, ATTR_TASKID, String.valueOf(taskId)); |
| 763 | if (realActivity != null) { |
| 764 | out.attribute(null, ATTR_REALACTIVITY, realActivity.flattenToShortString()); |
| 765 | } |
| 766 | if (origActivity != null) { |
| 767 | out.attribute(null, ATTR_ORIGACTIVITY, origActivity.flattenToShortString()); |
| 768 | } |
| 769 | if (affinity != null) { |
| 770 | out.attribute(null, ATTR_AFFINITY, affinity); |
| 771 | } |
| 772 | out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset)); |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 773 | out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 774 | out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode)); |
| 775 | out.attribute(null, ATTR_USERID, String.valueOf(userId)); |
| 776 | out.attribute(null, ATTR_TASKTYPE, String.valueOf(taskType)); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 777 | out.attribute(null, ATTR_FIRSTACTIVETIME, String.valueOf(firstActiveTime)); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 778 | out.attribute(null, ATTR_LASTACTIVETIME, String.valueOf(lastActiveTime)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 779 | out.attribute(null, ATTR_LASTTIMEMOVED, String.valueOf(mLastTimeMoved)); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 780 | out.attribute(null, ATTR_NEVERRELINQUISH, String.valueOf(mNeverRelinquishIdentity)); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 781 | if (lastDescription != null) { |
| 782 | out.attribute(null, ATTR_LASTDESCRIPTION, lastDescription.toString()); |
| 783 | } |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 784 | if (lastTaskDescription != null) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 785 | saveTaskDescription(lastTaskDescription, String.valueOf(taskId) + |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 786 | LAST_ACTIVITY_ICON_SUFFIX + lastActiveTime, out); |
| 787 | } |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 788 | out.attribute(null, ATTR_TASK_AFFILIATION_COLOR, String.valueOf(mAffiliatedTaskColor)); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 789 | out.attribute(null, ATTR_TASK_AFFILIATION, String.valueOf(mAffiliatedTaskId)); |
| 790 | out.attribute(null, ATTR_PREV_AFFILIATION, String.valueOf(mPrevAffiliateTaskId)); |
| 791 | out.attribute(null, ATTR_NEXT_AFFILIATION, String.valueOf(mNextAffiliateTaskId)); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 792 | out.attribute(null, ATTR_CALLING_UID, String.valueOf(mCallingUid)); |
| 793 | out.attribute(null, ATTR_CALLING_PACKAGE, mCallingPackage == null ? "" : mCallingPackage); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 794 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 795 | if (affinityIntent != null) { |
| 796 | out.startTag(null, TAG_AFFINITYINTENT); |
| 797 | affinityIntent.saveToXml(out); |
| 798 | out.endTag(null, TAG_AFFINITYINTENT); |
| 799 | } |
| 800 | |
| 801 | out.startTag(null, TAG_INTENT); |
| 802 | intent.saveToXml(out); |
| 803 | out.endTag(null, TAG_INTENT); |
| 804 | |
| 805 | final ArrayList<ActivityRecord> activities = mActivities; |
| 806 | final int numActivities = activities.size(); |
| 807 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 808 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 809 | if (r.info.persistableMode == ActivityInfo.PERSIST_ROOT_ONLY || !r.isPersistable() || |
| 810 | ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) && |
| 811 | activityNdx > 0) { |
Craig Mautner | f357c0c | 2014-06-09 09:23:27 -0700 | [diff] [blame] | 812 | // Stop at first non-persistable or first break in task (CLEAR_WHEN_TASK_RESET). |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 813 | break; |
| 814 | } |
| 815 | out.startTag(null, TAG_ACTIVITY); |
| 816 | r.saveToXml(out); |
| 817 | out.endTag(null, TAG_ACTIVITY); |
| 818 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) |
| 822 | throws IOException, XmlPullParserException { |
| 823 | Intent intent = null; |
| 824 | Intent affinityIntent = null; |
| 825 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 826 | ComponentName realActivity = null; |
| 827 | ComponentName origActivity = null; |
| 828 | String affinity = null; |
| 829 | boolean rootHasReset = false; |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 830 | boolean autoRemoveRecents = false; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 831 | boolean askedCompatMode = false; |
| 832 | int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 833 | int userId = 0; |
| 834 | String lastDescription = null; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 835 | long firstActiveTime = -1; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 836 | long lastActiveTime = -1; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 837 | long lastTimeOnTop = 0; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 838 | boolean neverRelinquishIdentity = true; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 839 | int taskId = -1; |
| 840 | final int outerDepth = in.getDepth(); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 841 | ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 842 | int taskAffiliation = -1; |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 843 | int taskAffiliationColor = 0; |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 844 | int prevTaskId = -1; |
| 845 | int nextTaskId = -1; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 846 | int callingUid = -1; |
| 847 | String callingPackage = ""; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 848 | |
| 849 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 850 | final String attrName = in.getAttributeName(attrNdx); |
| 851 | final String attrValue = in.getAttributeValue(attrNdx); |
| 852 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" + |
| 853 | attrName + " value=" + attrValue); |
| 854 | if (ATTR_TASKID.equals(attrName)) { |
| 855 | taskId = Integer.valueOf(attrValue); |
| 856 | } else if (ATTR_REALACTIVITY.equals(attrName)) { |
| 857 | realActivity = ComponentName.unflattenFromString(attrValue); |
| 858 | } else if (ATTR_ORIGACTIVITY.equals(attrName)) { |
| 859 | origActivity = ComponentName.unflattenFromString(attrValue); |
| 860 | } else if (ATTR_AFFINITY.equals(attrName)) { |
| 861 | affinity = attrValue; |
| 862 | } else if (ATTR_ROOTHASRESET.equals(attrName)) { |
| 863 | rootHasReset = Boolean.valueOf(attrValue); |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 864 | } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) { |
| 865 | autoRemoveRecents = Boolean.valueOf(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 866 | } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) { |
| 867 | askedCompatMode = Boolean.valueOf(attrValue); |
| 868 | } else if (ATTR_USERID.equals(attrName)) { |
| 869 | userId = Integer.valueOf(attrValue); |
| 870 | } else if (ATTR_TASKTYPE.equals(attrName)) { |
| 871 | taskType = Integer.valueOf(attrValue); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 872 | } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) { |
| 873 | firstActiveTime = Long.valueOf(attrValue); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 874 | } else if (ATTR_LASTACTIVETIME.equals(attrName)) { |
| 875 | lastActiveTime = Long.valueOf(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 876 | } else if (ATTR_LASTDESCRIPTION.equals(attrName)) { |
| 877 | lastDescription = attrValue; |
| 878 | } else if (ATTR_LASTTIMEMOVED.equals(attrName)) { |
| 879 | lastTimeOnTop = Long.valueOf(attrValue); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 880 | } else if (ATTR_NEVERRELINQUISH.equals(attrName)) { |
| 881 | neverRelinquishIdentity = Boolean.valueOf(attrValue); |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 882 | } else if (readTaskDescriptionAttribute(taskDescription, attrName, attrValue)) { |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 883 | // Completed in TaskPersister.readTaskDescriptionAttribute() |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 884 | } else if (ATTR_TASK_AFFILIATION.equals(attrName)) { |
| 885 | taskAffiliation = Integer.valueOf(attrValue); |
| 886 | } else if (ATTR_PREV_AFFILIATION.equals(attrName)) { |
| 887 | prevTaskId = Integer.valueOf(attrValue); |
| 888 | } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) { |
| 889 | nextTaskId = Integer.valueOf(attrValue); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 890 | } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) { |
| 891 | taskAffiliationColor = Integer.valueOf(attrValue); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 892 | } else if (ATTR_CALLING_UID.equals(attrName)) { |
| 893 | callingUid = Integer.valueOf(attrValue); |
| 894 | } else if (ATTR_CALLING_PACKAGE.equals(attrName)) { |
| 895 | callingPackage = attrValue; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 896 | } else { |
| 897 | Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | int event; |
| 902 | while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && |
| 903 | (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) { |
| 904 | if (event == XmlPullParser.START_TAG) { |
| 905 | final String name = in.getName(); |
| 906 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" + |
| 907 | name); |
| 908 | if (TAG_AFFINITYINTENT.equals(name)) { |
| 909 | affinityIntent = Intent.restoreFromXml(in); |
| 910 | } else if (TAG_INTENT.equals(name)) { |
| 911 | intent = Intent.restoreFromXml(in); |
| 912 | } else if (TAG_ACTIVITY.equals(name)) { |
| 913 | ActivityRecord activity = |
| 914 | ActivityRecord.restoreFromXml(in, taskId, stackSupervisor); |
| 915 | if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: activity=" + |
| 916 | activity); |
| 917 | if (activity != null) { |
| 918 | activities.add(activity); |
| 919 | } |
| 920 | } else { |
| 921 | Slog.e(TAG, "restoreTask: Unexpected name=" + name); |
| 922 | XmlUtils.skipCurrentTag(in); |
| 923 | } |
| 924 | } |
| 925 | } |
| 926 | |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 927 | if (lastActiveTime >= 0) { |
| 928 | taskDescription.setIcon(TaskPersister.restoreImage(String.valueOf(taskId) + |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 929 | LAST_ACTIVITY_ICON_SUFFIX + lastActiveTime + TaskPersister.IMAGE_EXTENSION)); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 932 | final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent, |
| 933 | affinityIntent, affinity, realActivity, origActivity, rootHasReset, |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 934 | autoRemoveRecents, askedCompatMode, taskType, userId, lastDescription, activities, |
| 935 | firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity, |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame^] | 936 | taskDescription, taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor, |
| 937 | callingUid, callingPackage); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 938 | |
| 939 | for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 940 | activities.get(activityNdx).task = task; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 943 | Slog.i(TAG, "Restored task=" + task); |
| 944 | return task; |
| 945 | } |
| 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | void dump(PrintWriter pw, String prefix) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 948 | if (rootWasReset || userId != 0 || numFullscreen != 0) { |
| 949 | pw.print(prefix); pw.print(" rootWasReset="); pw.print(rootWasReset); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 950 | pw.print(" userId="); pw.print(userId); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 951 | pw.print(" taskType="); pw.print(taskType); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 952 | pw.print(" numFullscreen="); pw.print(numFullscreen); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 953 | pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 954 | } |
| 955 | if (affinity != null) { |
| 956 | pw.print(prefix); pw.print("affinity="); pw.println(affinity); |
| 957 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 958 | if (voiceSession != null || voiceInteractor != null) { |
| 959 | pw.print(prefix); pw.print("VOICE: session=0x"); |
| 960 | pw.print(Integer.toHexString(System.identityHashCode(voiceSession))); |
| 961 | pw.print(" interactor=0x"); |
| 962 | pw.println(Integer.toHexString(System.identityHashCode(voiceInteractor))); |
| 963 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 964 | if (intent != null) { |
| 965 | StringBuilder sb = new StringBuilder(128); |
| 966 | sb.append(prefix); sb.append("intent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 967 | intent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 968 | sb.append('}'); |
| 969 | pw.println(sb.toString()); |
| 970 | } |
| 971 | if (affinityIntent != null) { |
| 972 | StringBuilder sb = new StringBuilder(128); |
| 973 | sb.append(prefix); sb.append("affinityIntent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 974 | affinityIntent.toShortString(sb, false, true, false, true); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 975 | sb.append('}'); |
| 976 | pw.println(sb.toString()); |
| 977 | } |
| 978 | if (origActivity != null) { |
| 979 | pw.print(prefix); pw.print("origActivity="); |
| 980 | pw.println(origActivity.flattenToShortString()); |
| 981 | } |
| 982 | if (realActivity != null) { |
| 983 | pw.print(prefix); pw.print("realActivity="); |
| 984 | pw.println(realActivity.flattenToShortString()); |
| 985 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 986 | pw.print(prefix); pw.print("Activities="); pw.println(mActivities); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 987 | if (!askedCompatMode) { |
| 988 | pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode); |
| 989 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 990 | pw.print(prefix); pw.print("lastThumbnail="); pw.print(mLastThumbnail); |
| 991 | pw.print(" lastThumbnailFile="); pw.print(mLastThumbnailFile); |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 992 | pw.print(" lastDescription="); pw.println(lastDescription); |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 993 | pw.print(prefix); pw.print("hasBeenVisible="); pw.print(hasBeenVisible); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 994 | pw.print(" firstActiveTime="); pw.print(lastActiveTime); |
Dianne Hackborn | d38aed8 | 2014-06-10 21:36:35 -0700 | [diff] [blame] | 995 | pw.print(" lastActiveTime="); pw.print(lastActiveTime); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 996 | pw.print(" (inactive for "); |
| 997 | pw.print((getInactiveDuration()/1000)); pw.println("s)"); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 998 | pw.print(prefix); pw.print("isPersistable="); pw.print(isPersistable); |
| 999 | pw.print(" affiliation="); pw.print(mAffiliatedTaskId); |
| 1000 | pw.print(" prevAffiliation="); pw.print(mPrevAffiliateTaskId); |
| 1001 | pw.print(" nextAffiliation="); pw.println(mNextAffiliateTaskId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1004 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1006 | StringBuilder sb = new StringBuilder(128); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1007 | if (stringName != null) { |
| 1008 | sb.append(stringName); |
| 1009 | sb.append(" U="); |
| 1010 | sb.append(userId); |
| 1011 | sb.append(" sz="); |
| 1012 | sb.append(mActivities.size()); |
| 1013 | sb.append('}'); |
| 1014 | return sb.toString(); |
| 1015 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1016 | sb.append("TaskRecord{"); |
| 1017 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1018 | sb.append(" #"); |
| 1019 | sb.append(taskId); |
| 1020 | if (affinity != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1021 | sb.append(" A="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1022 | sb.append(affinity); |
| 1023 | } else if (intent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1024 | sb.append(" I="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1025 | sb.append(intent.getComponent().flattenToShortString()); |
| 1026 | } else if (affinityIntent != null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1027 | sb.append(" aI="); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1028 | sb.append(affinityIntent.getComponent().flattenToShortString()); |
| 1029 | } else { |
| 1030 | sb.append(" ??"); |
| 1031 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1032 | stringName = sb.toString(); |
| 1033 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | } |
| 1035 | } |