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