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