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