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