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