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