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