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