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