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