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