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