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