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