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