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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 20 | import static android.app.ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.TaskDescription.ATTR_TASKDESCRIPTION_PREFIX; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 22 | import static android.app.ActivityOptions.ANIM_CLIP_REVEAL; |
| 23 | import static android.app.ActivityOptions.ANIM_CUSTOM; |
| 24 | import static android.app.ActivityOptions.ANIM_NONE; |
| 25 | import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS; |
| 26 | import static android.app.ActivityOptions.ANIM_REMOTE_ANIMATION; |
| 27 | import static android.app.ActivityOptions.ANIM_SCALE_UP; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 28 | import static android.app.ActivityOptions.ANIM_SCENE_TRANSITION; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 29 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN; |
| 30 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP; |
| 31 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN; |
| 32 | import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 33 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 34 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 35 | import static android.app.AppOpsManager.MODE_ALLOWED; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 36 | import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 37 | import static android.app.WaitResult.INVALID_DELAY; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 39 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 40 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 41 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 42 | import static android.app.WindowConfiguration.ROTATION_UNDEFINED; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 43 | import static android.app.WindowConfiguration.activityTypeToString; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 44 | import static android.content.Intent.ACTION_MAIN; |
| 45 | import static android.content.Intent.CATEGORY_HOME; |
| 46 | import static android.content.Intent.CATEGORY_LAUNCHER; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 47 | import static android.content.Intent.CATEGORY_SECONDARY_HOME; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 48 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 49 | import static android.content.Intent.FLAG_ACTIVITY_NO_HISTORY; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 50 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 51 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 52 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
| 53 | import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 54 | import static android.content.pm.ActivityInfo.CONFIG_UI_MODE; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 55 | import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 56 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 57 | import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 58 | import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE; |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 59 | import static android.content.pm.ActivityInfo.FLAG_INHERIT_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 60 | import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 61 | import static android.content.pm.ActivityInfo.FLAG_NO_HISTORY; |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 62 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 63 | import static android.content.pm.ActivityInfo.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 64 | import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 65 | import static android.content.pm.ActivityInfo.FLAG_TURN_SCREEN_ON; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 66 | import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE; |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 67 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 68 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 69 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 70 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; |
| 71 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 72 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 73 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 74 | import static android.content.pm.ActivityInfo.PERSIST_ACROSS_REBOOTS; |
| 75 | import static android.content.pm.ActivityInfo.PERSIST_ROOT_ONLY; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 76 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 77 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 78 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 79 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 80 | import static android.content.pm.ActivityInfo.isFixedOrientationLandscape; |
| 81 | import static android.content.pm.ActivityInfo.isFixedOrientationPortrait; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 82 | import static android.content.res.Configuration.EMPTY; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 83 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 84 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 85 | import static android.content.res.Configuration.ORIENTATION_UNDEFINED; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 86 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 87 | import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 88 | import static android.os.Build.VERSION_CODES.HONEYCOMB; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 89 | import static android.os.Build.VERSION_CODES.O; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 90 | import static android.os.Process.SYSTEM_UID; |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 91 | import static android.view.Display.DEFAULT_DISPLAY; |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 92 | import static android.view.Display.INVALID_DISPLAY; |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 93 | import static android.view.Surface.ROTATION_270; |
| 94 | import static android.view.Surface.ROTATION_90; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 95 | |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 96 | import static com.android.server.am.ActivityRecordProto.CONFIGURATION_CONTAINER; |
| 97 | import static com.android.server.am.ActivityRecordProto.FRONT_OF_TASK; |
| 98 | import static com.android.server.am.ActivityRecordProto.IDENTIFIER; |
| 99 | import static com.android.server.am.ActivityRecordProto.PROC_ID; |
| 100 | import static com.android.server.am.ActivityRecordProto.STATE; |
| 101 | import static com.android.server.am.ActivityRecordProto.TRANSLUCENT; |
| 102 | import static com.android.server.am.ActivityRecordProto.VISIBLE; |
| 103 | import static com.android.server.am.EventLogTags.AM_RELAUNCH_ACTIVITY; |
| 104 | import static com.android.server.am.EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 105 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 106 | import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; |
| 107 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 108 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 109 | import static com.android.server.wm.ActivityStack.ActivityState.RESTARTING_PROCESS; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 110 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 111 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 112 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
| 113 | import static com.android.server.wm.ActivityStack.LAUNCH_TICK; |
| 114 | import static com.android.server.wm.ActivityStack.LAUNCH_TICK_MSG; |
| 115 | import static com.android.server.wm.ActivityStack.PAUSE_TIMEOUT_MSG; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 116 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 117 | import static com.android.server.wm.ActivityStack.STOP_TIMEOUT_MSG; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 118 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 119 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 120 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SAVED_STATE; |
| 121 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 122 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 123 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TRANSITION; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 124 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 125 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 126 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 127 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SAVED_STATE; |
| 128 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; |
| 129 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 130 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 131 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 132 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 133 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; |
| 134 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 135 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 136 | import static com.android.server.wm.IdentifierProto.HASH_CODE; |
| 137 | import static com.android.server.wm.IdentifierProto.TITLE; |
| 138 | import static com.android.server.wm.IdentifierProto.USER_ID; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 139 | import static com.android.server.wm.TaskPersister.DEBUG; |
| 140 | import static com.android.server.wm.TaskPersister.IMAGE_EXTENSION; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 141 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 142 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 143 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
| 144 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
| 145 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 146 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 147 | import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; |
| 148 | import static org.xmlpull.v1.XmlPullParser.END_TAG; |
| 149 | import static org.xmlpull.v1.XmlPullParser.START_TAG; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 150 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 151 | import android.annotation.NonNull; |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 152 | import android.annotation.Nullable; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 153 | import android.app.ActivityManager.TaskDescription; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 154 | import android.app.ActivityOptions; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 155 | import android.app.PendingIntent; |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 156 | import android.app.PictureInPictureParams; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 157 | import android.app.ResultInfo; |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 158 | import android.app.WaitResult.LaunchState; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 159 | import android.app.servertransaction.ActivityConfigurationChangeItem; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 160 | import android.app.servertransaction.ActivityLifecycleItem; |
| 161 | import android.app.servertransaction.ActivityRelaunchItem; |
| 162 | import android.app.servertransaction.ClientTransaction; |
| 163 | import android.app.servertransaction.ClientTransactionItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 164 | import android.app.servertransaction.MoveToDisplayItem; |
| 165 | import android.app.servertransaction.MultiWindowModeChangeItem; |
| 166 | import android.app.servertransaction.NewIntentItem; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 167 | import android.app.servertransaction.PauseActivityItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 168 | import android.app.servertransaction.PipModeChangeItem; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 169 | import android.app.servertransaction.ResumeActivityItem; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 170 | import android.app.servertransaction.StopActivityItem; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 171 | import android.app.servertransaction.TopResumedActivityChangeItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 172 | import android.app.servertransaction.WindowVisibilityItem; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 173 | import android.app.usage.UsageEvents.Event; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | import android.content.ComponentName; |
| 175 | import android.content.Intent; |
| 176 | import android.content.pm.ActivityInfo; |
| 177 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 178 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | import android.content.res.Configuration; |
| 180 | import android.graphics.Bitmap; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 181 | import android.graphics.GraphicBuffer; |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 182 | import android.graphics.Rect; |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 183 | import android.os.Binder; |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 184 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | import android.os.Bundle; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 186 | import android.os.Debug; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 187 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | import android.os.Message; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 189 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | import android.os.Process; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 191 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 193 | import android.os.UserHandle; |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 194 | import android.os.storage.StorageManager; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 195 | import android.service.voice.IVoiceInteractionSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | import android.util.EventLog; |
| 197 | import android.util.Log; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 198 | import android.util.MergedConfiguration; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 199 | import android.util.Slog; |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 200 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 201 | import android.util.proto.ProtoOutputStream; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 202 | import android.view.AppTransitionAnimationSpec; |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 203 | import android.view.DisplayCutout; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 204 | import android.view.IAppTransitionAnimationSpecsFuture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | import android.view.IApplicationToken; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 206 | import android.view.RemoteAnimationDefinition; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 207 | import android.view.WindowManager.LayoutParams; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 208 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 209 | import com.android.internal.R; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 210 | import com.android.internal.annotations.VisibleForTesting; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 211 | import com.android.internal.app.ResolverActivity; |
| 212 | import com.android.internal.content.ReferrerIntent; |
| 213 | import com.android.internal.util.XmlUtils; |
| 214 | import com.android.server.AttributeCache; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 215 | import com.android.server.AttributeCache.Entry; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 216 | import com.android.server.am.AppTimeTracker; |
| 217 | import com.android.server.am.PendingIntentRecord; |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 218 | import com.android.server.uri.NeededUriGrants; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 219 | import com.android.server.uri.UriPermissionOwner; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 220 | import com.android.server.wm.ActivityMetricsLogger.WindowingModeTransitionInfoSnapshot; |
| 221 | import com.android.server.wm.ActivityStack.ActivityState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 223 | import org.xmlpull.v1.XmlPullParser; |
| 224 | import org.xmlpull.v1.XmlPullParserException; |
| 225 | import org.xmlpull.v1.XmlSerializer; |
| 226 | |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 227 | import java.io.File; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 228 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | import java.io.PrintWriter; |
| 230 | import java.lang.ref.WeakReference; |
| 231 | import java.util.ArrayList; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 232 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | import java.util.HashSet; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 234 | import java.util.List; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 235 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * An entry in the history stack, representing an activity. |
| 239 | */ |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 240 | final class ActivityRecord extends ConfigurationContainer { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 241 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_ATM; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 242 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
| 243 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 244 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 245 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 246 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 247 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
Winson Chung | 16e185e | 2017-11-07 08:30:54 -0800 | [diff] [blame] | 248 | // TODO(b/67864419): Remove once recents component is overridden |
| 249 | private static final String LEGACY_RECENTS_PACKAGE_NAME = "com.android.systemui.recents"; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 250 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 251 | private static final boolean SHOW_ACTIVITY_START_TIME = true; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 252 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 253 | private static final String ATTR_ID = "id"; |
| 254 | private static final String TAG_INTENT = "intent"; |
| 255 | private static final String ATTR_USERID = "user_id"; |
| 256 | private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle"; |
| 257 | private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 258 | private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 259 | private static final String ATTR_RESOLVEDTYPE = "resolved_type"; |
| 260 | private static final String ATTR_COMPONENTSPECIFIED = "component_specified"; |
Dianne Hackborn | 337abb3 | 2014-09-24 12:44:29 -0700 | [diff] [blame] | 261 | static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 262 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 263 | final ActivityTaskManagerService mAtmService; // owner |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 264 | final IApplicationToken.Stub appToken; // window manager token |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 265 | // TODO: Remove after unification |
| 266 | AppWindowToken mAppWindowToken; |
| 267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | final ActivityInfo info; // all about me |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 269 | // TODO: This is duplicated state already contained in info.applicationInfo - remove |
| 270 | ApplicationInfo appInfo; // information about activity's app |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 271 | final int launchedFromPid; // always the pid who started the activity. |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 272 | final int launchedFromUid; // always the uid who started the activity. |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 273 | final String launchedFromPackage; // always the package who started the activity. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 274 | final int mUserId; // Which user is this running for? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | final Intent intent; // the original intent that generated us |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 276 | final ComponentName mActivityComponent; // the intent component, or target of an alias. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | final String shortComponentName; // the short component name of the intent |
| 278 | final String resolvedType; // as per original caller; |
| 279 | final String packageName; // the package implementing intent's component |
| 280 | final String processName; // process where this component wants to run |
| 281 | final String taskAffinity; // as per ActivityInfo.taskAffinity |
| 282 | final boolean stateNotNeeded; // As per ActivityInfo.flags |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 283 | boolean fullscreen; // The activity is opaque and fills the entire space of this task. |
| 284 | // TODO: See if it possible to combine this with the fullscreen field. |
| 285 | final boolean hasWallpaper; // Has a wallpaper window as a background. |
Louis Chang | d58cb67 | 2018-12-24 17:45:16 +0800 | [diff] [blame] | 286 | @VisibleForTesting |
| 287 | boolean noDisplay; // activity is not displayed? |
| 288 | @VisibleForTesting |
| 289 | int mHandoverLaunchDisplayId = INVALID_DISPLAY; // Handover launch display id to next activity. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 290 | private final boolean componentSpecified; // did caller specify an explicit component? |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 291 | final boolean rootVoiceInteraction; // was this the root activity of a voice interaction? |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 292 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 293 | private CharSequence nonLocalizedLabel; // the label information from the package mgr. |
| 294 | private int labelRes; // the label information from the package mgr. |
| 295 | private int icon; // resource identifier of activity's icon. |
| 296 | private int logo; // resource identifier of activity's logo. |
| 297 | private int theme; // resource identifier of activity's theme. |
| 298 | private int realTheme; // actual theme resource we will use, never 0. |
| 299 | private int windowFlags; // custom window flags for preview window. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 300 | private TaskRecord task; // the task this is in. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 301 | private long createTime = System.currentTimeMillis(); |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 302 | long lastVisibleTime; // last time this activity became visible |
| 303 | long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity |
| 304 | long pauseTime; // last time we started pausing the activity |
| 305 | long launchTickTime; // base time for launch tick messages |
| 306 | long topResumedStateLossTime; // last time we reported top resumed state loss to an activity |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 307 | // Last configuration reported to the activity in the client process. |
| 308 | private MergedConfiguration mLastReportedConfiguration; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 309 | private int mLastReportedDisplayId; |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 310 | private boolean mLastReportedMultiWindowMode; |
| 311 | private boolean mLastReportedPictureInPictureMode; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 312 | CompatibilityInfo compat;// last used compatibility mode |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 313 | ActivityRecord resultTo; // who started this entry, so will get our reply |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | final String resultWho; // additional identifier for use by resultTo. |
| 315 | final int requestCode; // code given by requester (resultTo) |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 316 | ArrayList<ResultInfo> results; // pending ActivityResult objs we have received |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 318 | ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 319 | ActivityOptions pendingOptions; // most recently given options |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 320 | ActivityOptions returningOptions; // options that are coming back via convertToTranslucent |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 321 | AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 322 | ActivityServiceConnectionsHolder mServiceConnectionsHolder; // Service connections. |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 323 | UriPermissionOwner uriPermissions; // current special URI access perms. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 324 | WindowProcessController app; // if non-null, hosting application |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 325 | private ActivityState mState; // current state we are in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | Bundle icicle; // last saved activity state |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 327 | PersistableBundle persistentState; // last persistently saved activity state |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 328 | // TODO: See if this is still needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | boolean frontOfTask; // is this the root activity of its task? |
| 330 | boolean launchFailed; // set if a launched failed, to abort on 2nd try |
| 331 | boolean haveState; // have we gotten the last activity state? |
| 332 | boolean stopped; // is activity pause finished? |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 333 | boolean delayedResume; // not yet resumed because of stopped app switches? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | boolean finishing; // activity in pending finish list? |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 335 | boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is |
| 336 | // completed |
| 337 | boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | int configChangeFlags; // which config values have changed |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 339 | private boolean keysPaused; // has key dispatching been paused for it? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | int launchMode; // the launch mode activity attribute. |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 341 | int lockTaskLaunchMode; // the lockTaskMode manifest attribute, subject to override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | boolean visible; // does this activity's window need to be shown? |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 343 | boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard |
| 344 | // might hide this activity? |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 345 | private boolean mDeferHidingClient; // If true we told WM to defer reporting to the client |
| 346 | // process that it is hidden. |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 347 | boolean sleeping; // have we told the activity to sleep? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | boolean nowVisible; // is this activity's window visible? |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 349 | boolean mDrawn; // is this activity's window drawn? |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 350 | boolean mClientVisibilityDeferred;// was the visibility change message to client deferred? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | boolean idle; // has the activity gone idle? |
| 352 | boolean hasBeenLaunched;// has this activity ever been launched? |
| 353 | boolean frozenBeforeDestroy;// has been frozen but not yet destroyed. |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 354 | boolean immersive; // immersive mode (don't interrupt if possible) |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 355 | boolean forceNewConfig; // force re-create with new config next time |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 356 | boolean supportsEnterPipOnTaskSwitch; // This flag is set by the system to indicate that the |
| 357 | // activity can enter picture in picture while pausing (only when switching to another task) |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 358 | PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build(); |
| 359 | // The PiP params used when deferring the entering of picture-in-picture. |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 360 | int launchCount; // count of launches since last state |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 361 | long lastLaunchTime; // time of last launch of this activity |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 362 | ComponentName requestedVrComponent; // the requested component for handling VR mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 364 | String stringName; // for caching of toString(). |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 365 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 366 | private boolean inHistory; // are we in the history stack? |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 367 | final ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 368 | final RootActivityContainer mRootActivityContainer; |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 369 | |
| 370 | static final int STARTING_WINDOW_NOT_SHOWN = 0; |
| 371 | static final int STARTING_WINDOW_SHOWN = 1; |
| 372 | static final int STARTING_WINDOW_REMOVED = 2; |
| 373 | int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN; |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 374 | boolean mTaskOverlay = false; // Task is always on-top of other activities in the task. |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 375 | |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 376 | // Marking the reason why this activity is being relaunched. Mainly used to track that this |
| 377 | // activity is being relaunched to fulfill a resize request due to compatibility issues, e.g. in |
| 378 | // pre-NYC apps that don't have a sense of being resized. |
| 379 | int mRelaunchReason = RELAUNCH_REASON_NONE; |
| 380 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 381 | TaskDescription taskDescription; // the recents information for this activity |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 382 | boolean mLaunchTaskBehind; // this activity is actively being launched with |
| 383 | // ActivityOptions.setLaunchTaskBehind, will be cleared once launch is completed. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 384 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 385 | // These configurations are collected from application's resources based on size-sensitive |
| 386 | // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800 |
| 387 | // and drawable-sw400dp will be added to both as 400. |
| 388 | private int[] mVerticalSizeConfigurations; |
| 389 | private int[] mHorizontalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 390 | private int[] mSmallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 391 | |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 392 | /** |
| 393 | * The precomputed display insets for resolving configuration. It will be non-null if |
| 394 | * {@link #shouldUseSizeCompatMode} returns {@code true}. |
| 395 | */ |
| 396 | private CompatDisplayInsets mCompatDisplayInsets; |
| 397 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 398 | boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session |
| 399 | IVoiceInteractionSession voiceSession; // Voice interaction session for this activity |
| 400 | |
Robert Carr | d226512 | 2016-08-05 10:25:21 -0700 | [diff] [blame] | 401 | // A hint to override the window specified rotation animation, or -1 |
| 402 | // to use the window specified value. We use this so that |
| 403 | // we can select the right animation in the cases of starting |
| 404 | // windows, where the app hasn't had time to set a value |
| 405 | // on the window. |
| 406 | int mRotationAnimationHint = -1; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 407 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 408 | private boolean mShowWhenLocked; |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 409 | private boolean mInheritShownWhenLocked; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 410 | private boolean mTurnScreenOn; |
| 411 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 412 | /** |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 413 | * Current sequencing integer of the configuration, for skipping old activity configurations. |
| 414 | */ |
| 415 | private int mConfigurationSeq; |
| 416 | |
| 417 | /** |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 418 | * Temp configs used in {@link #ensureActivityConfiguration(int, boolean)} |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 419 | */ |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 420 | private final Configuration mTmpConfig = new Configuration(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 421 | private final Rect mTmpBounds = new Rect(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 422 | |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 423 | // Token for targeting this activity for assist purposes. |
| 424 | final Binder assistToken = new Binder(); |
| 425 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 426 | private static String startingWindowStateToString(int state) { |
| 427 | switch (state) { |
| 428 | case STARTING_WINDOW_NOT_SHOWN: |
| 429 | return "STARTING_WINDOW_NOT_SHOWN"; |
| 430 | case STARTING_WINDOW_SHOWN: |
| 431 | return "STARTING_WINDOW_SHOWN"; |
| 432 | case STARTING_WINDOW_REMOVED: |
| 433 | return "STARTING_WINDOW_REMOVED"; |
| 434 | default: |
| 435 | return "unknown state=" + state; |
| 436 | } |
| 437 | } |
| 438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 440 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 441 | pw.print(prefix); pw.print("packageName="); pw.print(packageName); |
| 442 | pw.print(" processName="); pw.println(processName); |
| 443 | pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 444 | pw.print(" launchedFromPackage="); pw.print(launchedFromPackage); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 445 | pw.print(" userId="); pw.println(mUserId); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 446 | pw.print(prefix); pw.print("app="); pw.println(app); |
| 447 | pw.print(prefix); pw.println(intent.toInsecureStringWithClip()); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 448 | pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask); |
| 449 | pw.print(" task="); pw.println(task); |
| 450 | pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 451 | pw.print(prefix); pw.print("mActivityComponent="); |
| 452 | pw.println(mActivityComponent.flattenToShortString()); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 453 | if (appInfo != null) { |
| 454 | pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir); |
| 455 | if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) { |
| 456 | pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir); |
| 457 | } |
| 458 | pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 459 | if (appInfo.splitSourceDirs != null) { |
| 460 | pw.print(prefix); pw.print("splitDir="); |
| 461 | pw.println(Arrays.toString(appInfo.splitSourceDirs)); |
| 462 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 463 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 464 | pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded); |
| 465 | pw.print(" componentSpecified="); pw.print(componentSpecified); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 466 | pw.print(" mActivityType="); pw.println( |
| 467 | activityTypeToString(getActivityType())); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 468 | if (rootVoiceInteraction) { |
| 469 | pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction); |
| 470 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 471 | pw.print(prefix); pw.print("compat="); pw.print(compat); |
| 472 | pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes)); |
| 473 | pw.print(" icon=0x"); pw.print(Integer.toHexString(icon)); |
| 474 | pw.print(" theme=0x"); pw.println(Integer.toHexString(theme)); |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 475 | pw.println(prefix + "mLastReportedConfigurations:"); |
| 476 | mLastReportedConfiguration.dump(pw, prefix + " "); |
| 477 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 478 | pw.print(prefix); pw.print("CurrentConfiguration="); pw.println(getConfiguration()); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 479 | if (!getRequestedOverrideConfiguration().equals(EMPTY)) { |
| 480 | pw.println(prefix + "RequestedOverrideConfiguration=" |
| 481 | + getRequestedOverrideConfiguration()); |
| 482 | } |
| 483 | if (!getResolvedOverrideConfiguration().equals(getRequestedOverrideConfiguration())) { |
| 484 | pw.println(prefix + "ResolvedOverrideConfiguration=" |
| 485 | + getResolvedOverrideConfiguration()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 486 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 487 | if (!matchParentBounds()) { |
| 488 | pw.println(prefix + "bounds=" + getBounds()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 489 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 490 | if (resultTo != null || resultWho != null) { |
| 491 | pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); |
| 492 | pw.print(" resultWho="); pw.print(resultWho); |
| 493 | pw.print(" resultCode="); pw.println(requestCode); |
| 494 | } |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 495 | if (taskDescription != null) { |
| 496 | final String iconFilename = taskDescription.getIconFilename(); |
| 497 | if (iconFilename != null || taskDescription.getLabel() != null || |
| 498 | taskDescription.getPrimaryColor() != 0) { |
| 499 | pw.print(prefix); pw.print("taskDescription:"); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 500 | pw.print(" label=\""); pw.print(taskDescription.getLabel()); |
| 501 | pw.print("\""); |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 502 | pw.print(" icon="); pw.print(taskDescription.getInMemoryIcon() != null |
| 503 | ? taskDescription.getInMemoryIcon().getByteCount() + " bytes" |
| 504 | : "null"); |
| 505 | pw.print(" iconResource="); pw.print(taskDescription.getIconResource()); |
| 506 | pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename()); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 507 | pw.print(" primaryColor="); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 508 | pw.println(Integer.toHexString(taskDescription.getPrimaryColor())); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 509 | pw.print(prefix + " backgroundColor="); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 510 | pw.println(Integer.toHexString(taskDescription.getBackgroundColor())); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 511 | pw.print(prefix + " statusBarColor="); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 512 | pw.println(Integer.toHexString(taskDescription.getStatusBarColor())); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 513 | pw.print(prefix + " navigationBarColor="); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 514 | pw.println(Integer.toHexString(taskDescription.getNavigationBarColor())); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 515 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 516 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 517 | if (results != null) { |
| 518 | pw.print(prefix); pw.print("results="); pw.println(results); |
| 519 | } |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 520 | if (pendingResults != null && pendingResults.size() > 0) { |
| 521 | pw.print(prefix); pw.println("Pending Results:"); |
| 522 | for (WeakReference<PendingIntentRecord> wpir : pendingResults) { |
| 523 | PendingIntentRecord pir = wpir != null ? wpir.get() : null; |
| 524 | pw.print(prefix); pw.print(" - "); |
| 525 | if (pir == null) { |
| 526 | pw.println("null"); |
| 527 | } else { |
| 528 | pw.println(pir); |
| 529 | pir.dump(pw, prefix + " "); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | if (newIntents != null && newIntents.size() > 0) { |
| 534 | pw.print(prefix); pw.println("Pending New Intents:"); |
| 535 | for (int i=0; i<newIntents.size(); i++) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 536 | Intent intent = newIntents.get(i); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 537 | pw.print(prefix); pw.print(" - "); |
| 538 | if (intent == null) { |
| 539 | pw.println("null"); |
| 540 | } else { |
| 541 | pw.println(intent.toShortString(false, true, false, true)); |
| 542 | } |
| 543 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 544 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 545 | if (pendingOptions != null) { |
| 546 | pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions); |
| 547 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 548 | if (appTimeTracker != null) { |
| 549 | appTimeTracker.dumpWithHeader(pw, prefix, false); |
| 550 | } |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 551 | if (uriPermissions != null) { |
Jeff Sharkey | 846318a | 2014-04-04 12:12:41 -0700 | [diff] [blame] | 552 | uriPermissions.dump(pw, prefix); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 553 | } |
| 554 | pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed); |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 555 | pw.print(" launchCount="); pw.print(launchCount); |
| 556 | pw.print(" lastLaunchTime="); |
| 557 | if (lastLaunchTime == 0) pw.print("0"); |
| 558 | else TimeUtils.formatDuration(lastLaunchTime, now, pw); |
| 559 | pw.println(); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 560 | pw.print(prefix); pw.print("haveState="); pw.print(haveState); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 561 | pw.print(" icicle="); pw.println(icicle); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 562 | pw.print(prefix); pw.print("state="); pw.print(mState); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 563 | pw.print(" stopped="); pw.print(stopped); |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 564 | pw.print(" delayedResume="); pw.print(delayedResume); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 565 | pw.print(" finishing="); pw.println(finishing); |
| 566 | pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused); |
| 567 | pw.print(" inHistory="); pw.print(inHistory); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 568 | pw.print(" visible="); pw.print(visible); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 569 | pw.print(" sleeping="); pw.print(sleeping); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 570 | pw.print(" idle="); pw.print(idle); |
| 571 | pw.print(" mStartingWindowState="); |
| 572 | pw.println(startingWindowStateToString(mStartingWindowState)); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 573 | pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen); |
| 574 | pw.print(" noDisplay="); pw.print(noDisplay); |
| 575 | pw.print(" immersive="); pw.print(immersive); |
| 576 | pw.print(" launchMode="); pw.println(launchMode); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 577 | pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 578 | pw.print(" forceNewConfig="); pw.println(forceNewConfig); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 579 | pw.print(prefix); pw.print("mActivityType="); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 580 | pw.println(activityTypeToString(getActivityType())); |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 581 | if (requestedVrComponent != null) { |
| 582 | pw.print(prefix); |
| 583 | pw.print("requestedVrComponent="); |
| 584 | pw.println(requestedVrComponent); |
| 585 | } |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 586 | if (lastVisibleTime != 0 || nowVisible) { |
| 587 | pw.print(prefix); pw.print(" nowVisible="); pw.print(nowVisible); |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 588 | pw.print(" lastVisibleTime="); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 589 | if (lastVisibleTime == 0) pw.print("0"); |
| 590 | else TimeUtils.formatDuration(lastVisibleTime, now, pw); |
| 591 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 592 | } |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 593 | if (mDeferHidingClient) { |
| 594 | pw.println(prefix + "mDeferHidingClient=" + mDeferHidingClient); |
| 595 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 596 | if (deferRelaunchUntilPaused || configChangeFlags != 0) { |
| 597 | pw.print(prefix); pw.print("deferRelaunchUntilPaused="); pw.print(deferRelaunchUntilPaused); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 598 | pw.print(" configChangeFlags="); |
| 599 | pw.println(Integer.toHexString(configChangeFlags)); |
| 600 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 601 | if (mServiceConnectionsHolder != null) { |
| 602 | pw.print(prefix); pw.print("connections="); pw.println(mServiceConnectionsHolder); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 603 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 604 | if (info != null) { |
| 605 | pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode)); |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 606 | pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode |
| 607 | + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 608 | if (info.supportsPictureInPicture()) { |
| 609 | pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture()); |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 610 | pw.println(prefix + "supportsEnterPipOnTaskSwitch: " |
| 611 | + supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 612 | } |
| 613 | if (info.maxAspectRatio != 0) { |
| 614 | pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio); |
| 615 | } |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 616 | if (info.minAspectRatio != 0) { |
| 617 | pw.println(prefix + "minAspectRatio=" + info.minAspectRatio); |
| 618 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | } |
| 621 | |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 622 | void updateApplicationInfo(ApplicationInfo aInfo) { |
| 623 | appInfo = aInfo; |
| 624 | info.applicationInfo = aInfo; |
| 625 | } |
| 626 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 627 | private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 628 | return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp); |
| 629 | } |
| 630 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 631 | private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 632 | return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp); |
| 633 | } |
| 634 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 635 | private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 636 | return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp); |
| 637 | } |
| 638 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 639 | /** |
| 640 | * The purpose of this method is to decide whether the activity needs to be relaunched upon |
| 641 | * changing its size. In most cases the activities don't need to be relaunched, if the resize |
| 642 | * is small, all the activity content has to do is relayout itself within new bounds. There are |
| 643 | * cases however, where the activity's content would be completely changed in the new size and |
| 644 | * the full relaunch is required. |
| 645 | * |
| 646 | * The activity will report to us vertical and horizontal thresholds after which a relaunch is |
| 647 | * required. These thresholds are collected from the application resource qualifiers. For |
| 648 | * example, if application has layout-w600dp resource directory, then it needs a relaunch when |
| 649 | * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if |
| 650 | * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side |
| 651 | * of the threshold. |
| 652 | */ |
| 653 | private static boolean crossesSizeThreshold(int[] thresholds, int firstDp, |
| 654 | int secondDp) { |
| 655 | if (thresholds == null) { |
| 656 | return false; |
| 657 | } |
| 658 | for (int i = thresholds.length - 1; i >= 0; i--) { |
| 659 | final int threshold = thresholds[i]; |
| 660 | if ((firstDp < threshold && secondDp >= threshold) |
| 661 | || (firstDp >= threshold && secondDp < threshold)) { |
| 662 | return true; |
| 663 | } |
| 664 | } |
| 665 | return false; |
| 666 | } |
| 667 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 668 | void setSizeConfigurations(int[] horizontalSizeConfiguration, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 669 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 670 | mHorizontalSizeConfigurations = horizontalSizeConfiguration; |
| 671 | mVerticalSizeConfigurations = verticalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 672 | mSmallestSizeConfigurations = smallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 675 | private void scheduleActivityMovedToDisplay(int displayId, Configuration config) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 676 | if (!attachedToProcess()) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 677 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.w(TAG, |
| 678 | "Can't report activity moved to display - client not running, activityRecord=" |
| 679 | + this + ", displayId=" + displayId); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 680 | return; |
| 681 | } |
| 682 | try { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 683 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 684 | "Reporting activity moved to display" + ", activityRecord=" + this |
| 685 | + ", displayId=" + displayId + ", config=" + config); |
Chong Zhang | 6be533e | 2016-06-17 16:24:21 -0700 | [diff] [blame] | 686 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 687 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 688 | MoveToDisplayItem.obtain(displayId, config)); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 689 | } catch (RemoteException e) { |
| 690 | // If process died, whatever. |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | private void scheduleConfigurationChanged(Configuration config) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 695 | if (!attachedToProcess()) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 696 | if (DEBUG_CONFIGURATION) Slog.w(TAG, |
| 697 | "Can't report activity configuration update - client not running" |
| 698 | + ", activityRecord=" + this); |
| 699 | return; |
| 700 | } |
| 701 | try { |
| 702 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + ", config: " |
| 703 | + config); |
| 704 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 705 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 706 | ActivityConfigurationChangeItem.obtain(config)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 707 | } catch (RemoteException e) { |
| 708 | // If process died, whatever. |
| 709 | } |
| 710 | } |
| 711 | |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 712 | boolean scheduleTopResumedActivityChanged(boolean onTop) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 713 | if (!attachedToProcess()) { |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 714 | if (DEBUG_STATES) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 715 | Slog.w(TAG, "Can't report activity position update - client not running" |
| 716 | + ", activityRecord=" + this); |
| 717 | } |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 718 | return false; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 719 | } |
| 720 | try { |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 721 | if (DEBUG_STATES) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 722 | Slog.v(TAG, "Sending position change to " + this + ", onTop: " + onTop); |
| 723 | } |
| 724 | |
| 725 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 726 | TopResumedActivityChangeItem.obtain(onTop)); |
| 727 | } catch (RemoteException e) { |
| 728 | // If process died, whatever. |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 729 | return false; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 730 | } |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 731 | return true; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 732 | } |
| 733 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 734 | void updateMultiWindowMode() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 735 | if (task == null || task.getStack() == null || !attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 736 | return; |
| 737 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 738 | |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 739 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 740 | // Don't do anything if we are currently deferring multi-window mode change. |
| 741 | return; |
| 742 | } |
| 743 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 744 | // An activity is considered to be in multi-window mode if its task isn't fullscreen. |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 745 | final boolean inMultiWindowMode = inMultiWindowMode(); |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 746 | if (inMultiWindowMode != mLastReportedMultiWindowMode) { |
| 747 | mLastReportedMultiWindowMode = inMultiWindowMode; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 748 | scheduleMultiWindowModeChanged(getConfiguration()); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | private void scheduleMultiWindowModeChanged(Configuration overrideConfig) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 753 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 754 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 755 | MultiWindowModeChangeItem.obtain(mLastReportedMultiWindowMode, overrideConfig)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 756 | } catch (Exception e) { |
| 757 | // If process died, I don't care. |
| 758 | } |
| 759 | } |
| 760 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 761 | void updatePictureInPictureMode(Rect targetStackBounds, boolean forceUpdate) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 762 | if (task == null || task.getStack() == null || !attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 763 | return; |
| 764 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 765 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 766 | final boolean inPictureInPictureMode = inPinnedWindowingMode() && targetStackBounds != null; |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 767 | if (inPictureInPictureMode != mLastReportedPictureInPictureMode || forceUpdate) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 768 | // Picture-in-picture mode changes also trigger a multi-window mode change as well, so |
Winson Chung | 059955f | 2018-08-08 16:10:20 -0700 | [diff] [blame] | 769 | // update that here in order. Set the last reported MW state to the same as the PiP |
| 770 | // state since we haven't yet actually resized the task (these callbacks need to |
| 771 | // preceed the configuration change from the resiez. |
| 772 | // TODO(110009072): Once we move these callbacks to the client, remove all logic related |
| 773 | // to forcing the update of the picture-in-picture mode as a part of the PiP animation. |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 774 | mLastReportedPictureInPictureMode = inPictureInPictureMode; |
Winson Chung | 059955f | 2018-08-08 16:10:20 -0700 | [diff] [blame] | 775 | mLastReportedMultiWindowMode = inPictureInPictureMode; |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 776 | final Configuration newConfig = new Configuration(); |
| 777 | if (targetStackBounds != null && !targetStackBounds.isEmpty()) { |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 778 | newConfig.setTo(task.getRequestedOverrideConfiguration()); |
| 779 | Rect outBounds = newConfig.windowConfiguration.getBounds(); |
| 780 | task.adjustForMinimalTaskDimensions(outBounds, outBounds); |
| 781 | task.computeConfigResourceOverrides(newConfig, task.getParent().getConfiguration()); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 782 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 783 | schedulePictureInPictureModeChanged(newConfig); |
| 784 | scheduleMultiWindowModeChanged(newConfig); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | private void schedulePictureInPictureModeChanged(Configuration overrideConfig) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 789 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 790 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 791 | PipModeChangeItem.obtain(mLastReportedPictureInPictureMode, |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 792 | overrideConfig)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 793 | } catch (Exception e) { |
| 794 | // If process died, no one cares. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 798 | @Override |
| 799 | protected int getChildCount() { |
| 800 | // {@link ActivityRecord} is a leaf node and has no children. |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | @Override |
| 805 | protected ConfigurationContainer getChildAt(int index) { |
| 806 | return null; |
| 807 | } |
| 808 | |
| 809 | @Override |
| 810 | protected ConfigurationContainer getParent() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 811 | return getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 814 | TaskRecord getTaskRecord() { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 815 | return task; |
| 816 | } |
| 817 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 818 | /** |
| 819 | * Sets reference to the {@link TaskRecord} the {@link ActivityRecord} will treat as its parent. |
| 820 | * Note that this does not actually add the {@link ActivityRecord} as a {@link TaskRecord} |
| 821 | * children. However, this method will clean up references to this {@link ActivityRecord} in |
| 822 | * {@link ActivityStack}. |
| 823 | * @param task The new parent {@link TaskRecord}. |
| 824 | */ |
| 825 | void setTask(TaskRecord task) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 826 | setTask(task /* task */, false /* reparenting */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** |
| 830 | * This method should only be called by {@link TaskRecord#removeActivity(ActivityRecord)}. |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 831 | * @param task The new parent task. |
| 832 | * @param reparenting Whether we're in the middle of reparenting. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 833 | */ |
| 834 | void setTask(TaskRecord task, boolean reparenting) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 835 | // Do nothing if the {@link TaskRecord} is the same as the current {@link getTaskRecord}. |
| 836 | if (task != null && task == getTaskRecord()) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 837 | return; |
| 838 | } |
| 839 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 840 | final ActivityStack oldStack = getActivityStack(); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 841 | final ActivityStack newStack = task != null ? task.getStack() : null; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 842 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 843 | // Inform old stack (if present) of activity removal and new stack (if set) of activity |
| 844 | // addition. |
| 845 | if (oldStack != newStack) { |
| 846 | if (!reparenting && oldStack != null) { |
| 847 | oldStack.onActivityRemovedFromStack(this); |
| 848 | } |
| 849 | |
| 850 | if (newStack != null) { |
| 851 | newStack.onActivityAddedToStack(this); |
| 852 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | this.task = task; |
| 856 | |
| 857 | if (!reparenting) { |
| 858 | onParentChanged(); |
| 859 | } |
| 860 | } |
| 861 | |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 862 | /** |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 863 | * Notifies AWT that this app is waiting to pause in order to determine if it will enter PIP. |
| 864 | * This information helps AWT know that the app is in the process of pausing before it gets the |
| 865 | * signal on the WM side. |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 866 | */ |
| 867 | void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 868 | if (mAppWindowToken == null) { |
| 869 | return; |
| 870 | } |
| 871 | |
| 872 | mAppWindowToken.setWillCloseOrEnterPip(willCloseOrEnterPip); |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 875 | static class Token extends IApplicationToken.Stub { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 876 | private final WeakReference<ActivityRecord> weakActivity; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 877 | private final String name; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 878 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 879 | Token(ActivityRecord activity, Intent intent) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 880 | weakActivity = new WeakReference<>(activity); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 881 | name = intent.getComponent().flattenToShortString(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Charles Chen | 69362cd | 2019-03-29 15:18:45 +0800 | [diff] [blame] | 884 | private static @Nullable ActivityRecord tokenToActivityRecordLocked(Token token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 885 | if (token == null) { |
| 886 | return null; |
| 887 | } |
| 888 | ActivityRecord r = token.weakActivity.get(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 889 | if (r == null || r.getActivityStack() == null) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 890 | return null; |
| 891 | } |
| 892 | return r; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 893 | } |
| 894 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 895 | @Override |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 896 | public String toString() { |
| 897 | StringBuilder sb = new StringBuilder(128); |
| 898 | sb.append("Token{"); |
| 899 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 900 | sb.append(' '); |
| 901 | sb.append(weakActivity.get()); |
| 902 | sb.append('}'); |
| 903 | return sb.toString(); |
| 904 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 905 | |
| 906 | @Override |
| 907 | public String getName() { |
| 908 | return name; |
| 909 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 910 | } |
| 911 | |
Charles Chen | 69362cd | 2019-03-29 15:18:45 +0800 | [diff] [blame] | 912 | static @Nullable ActivityRecord forTokenLocked(IBinder token) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 913 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 914 | return Token.tokenToActivityRecordLocked((Token)token); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 915 | } catch (ClassCastException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 916 | Slog.w(TAG, "Bad activity token: " + token, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 917 | return null; |
| 918 | } |
| 919 | } |
| 920 | |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 921 | static boolean isResolverActivity(String className) { |
| 922 | return ResolverActivity.class.getName().equals(className); |
| 923 | } |
| 924 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 925 | boolean isResolverActivity() { |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 926 | return isResolverActivity(mActivityComponent.getClassName()); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 929 | boolean isResolverOrChildActivity() { |
| 930 | if (!"android".equals(packageName)) { |
| 931 | return false; |
| 932 | } |
| 933 | try { |
| 934 | return ResolverActivity.class.isAssignableFrom( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 935 | Object.class.getClassLoader().loadClass(mActivityComponent.getClassName())); |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 936 | } catch (ClassNotFoundException e) { |
| 937 | return false; |
| 938 | } |
| 939 | } |
| 940 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 941 | ActivityRecord(ActivityTaskManagerService _service, WindowProcessController _caller, |
| 942 | int _launchedFromPid, int _launchedFromUid, String _launchedFromPackage, Intent _intent, |
| 943 | String _resolvedType, ActivityInfo aInfo, Configuration _configuration, |
| 944 | ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified, |
| 945 | boolean _rootVoiceInteraction, ActivityStackSupervisor supervisor, |
| 946 | ActivityOptions options, ActivityRecord sourceRecord) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 947 | mAtmService = _service; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 948 | mRootActivityContainer = _service.mRootActivityContainer; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 949 | appToken = new Token(this, _intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | info = aInfo; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 951 | launchedFromPid = _launchedFromPid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | launchedFromUid = _launchedFromUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 953 | launchedFromPackage = _launchedFromPackage; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 954 | mUserId = UserHandle.getUserId(aInfo.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | intent = _intent; |
| 956 | shortComponentName = _intent.getComponent().flattenToShortString(); |
| 957 | resolvedType = _resolvedType; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 958 | componentSpecified = _componentSpecified; |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 959 | rootVoiceInteraction = _rootVoiceInteraction; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 960 | mLastReportedConfiguration = new MergedConfiguration(_configuration); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | resultTo = _resultTo; |
| 962 | resultWho = _resultWho; |
| 963 | requestCode = _reqCode; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 964 | setState(INITIALIZING, "ActivityRecord ctor"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | frontOfTask = false; |
| 966 | launchFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | stopped = false; |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 968 | delayedResume = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | finishing = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 970 | deferRelaunchUntilPaused = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | keysPaused = false; |
| 972 | inHistory = false; |
Chong Zhang | a48ef66 | 2015-08-18 19:21:47 -0700 | [diff] [blame] | 973 | visible = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | nowVisible = false; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 975 | mDrawn = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | idle = false; |
| 977 | hasBeenLaunched = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 978 | mStackSupervisor = supervisor; |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 979 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 980 | // This starts out true, since the initial state of an activity is that we have everything, |
| 981 | // and we shouldn't never consider it lacking in state to be removed if it dies. |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 982 | haveState = true; |
| 983 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 984 | // If the class name in the intent doesn't match that of the target, this is |
| 985 | // probably an alias. We have to create a new ComponentName object to keep track |
| 986 | // of the real activity name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly. |
| 987 | if (aInfo.targetActivity == null |
| 988 | || (aInfo.targetActivity.equals(_intent.getComponent().getClassName()) |
| 989 | && (aInfo.launchMode == LAUNCH_MULTIPLE |
| 990 | || aInfo.launchMode == LAUNCH_SINGLE_TOP))) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 991 | mActivityComponent = _intent.getComponent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 993 | mActivityComponent = new ComponentName(aInfo.packageName, aInfo.targetActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 995 | taskAffinity = aInfo.taskAffinity; |
| 996 | stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0; |
| 997 | appInfo = aInfo.applicationInfo; |
| 998 | nonLocalizedLabel = aInfo.nonLocalizedLabel; |
| 999 | labelRes = aInfo.labelRes; |
| 1000 | if (nonLocalizedLabel == null && labelRes == 0) { |
| 1001 | ApplicationInfo app = aInfo.applicationInfo; |
| 1002 | nonLocalizedLabel = app.nonLocalizedLabel; |
| 1003 | labelRes = app.labelRes; |
| 1004 | } |
| 1005 | icon = aInfo.getIconResource(); |
| 1006 | logo = aInfo.getLogoResource(); |
| 1007 | theme = aInfo.getThemeResource(); |
| 1008 | realTheme = theme; |
| 1009 | if (realTheme == 0) { |
| 1010 | realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB |
| 1011 | ? android.R.style.Theme : android.R.style.Theme_Holo; |
| 1012 | } |
| 1013 | if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
| 1014 | windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1015 | } |
| 1016 | if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null |
| 1017 | && (aInfo.applicationInfo.uid == SYSTEM_UID |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1018 | || aInfo.applicationInfo.uid == _caller.mInfo.uid)) { |
| 1019 | processName = _caller.mName; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1020 | } else { |
| 1021 | processName = aInfo.processName; |
| 1022 | } |
| 1023 | |
| 1024 | if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) { |
| 1025 | intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 1026 | } |
| 1027 | |
| 1028 | packageName = aInfo.applicationInfo.packageName; |
| 1029 | launchMode = aInfo.launchMode; |
| 1030 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1031 | Entry ent = AttributeCache.instance().get(packageName, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1032 | realTheme, com.android.internal.R.styleable.Window, mUserId); |
Bryce Lee | e83f34cd | 2017-10-31 19:50:54 -0700 | [diff] [blame] | 1033 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1034 | if (ent != null) { |
| 1035 | fullscreen = !ActivityInfo.isTranslucentOrFloating(ent.array); |
| 1036 | hasWallpaper = ent.array.getBoolean(R.styleable.Window_windowShowWallpaper, false); |
| 1037 | noDisplay = ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false); |
| 1038 | } else { |
| 1039 | hasWallpaper = false; |
| 1040 | noDisplay = false; |
| 1041 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1042 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1043 | setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1044 | |
| 1045 | immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0; |
| 1046 | |
| 1047 | requestedVrComponent = (aInfo.requestedVrComponent == null) ? |
| 1048 | null : ComponentName.unflattenFromString(aInfo.requestedVrComponent); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1049 | |
| 1050 | mShowWhenLocked = (aInfo.flags & FLAG_SHOW_WHEN_LOCKED) != 0; |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 1051 | mInheritShownWhenLocked = (aInfo.privateFlags & FLAG_INHERIT_SHOW_WHEN_LOCKED) != 0; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1052 | mTurnScreenOn = (aInfo.flags & FLAG_TURN_SCREEN_ON) != 0; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1053 | |
| 1054 | mRotationAnimationHint = aInfo.rotationAnimation; |
| 1055 | lockTaskLaunchMode = aInfo.lockTaskLaunchMode; |
| 1056 | if (appInfo.isPrivilegedApp() && (lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_ALWAYS |
| 1057 | || lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_NEVER)) { |
| 1058 | lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 1059 | } |
| 1060 | |
| 1061 | if (options != null) { |
| 1062 | pendingOptions = options; |
| 1063 | mLaunchTaskBehind = options.getLaunchTaskBehind(); |
| 1064 | |
| 1065 | final int rotationAnimation = pendingOptions.getRotationAnimationHint(); |
| 1066 | // Only override manifest supplied option if set. |
| 1067 | if (rotationAnimation >= 0) { |
| 1068 | mRotationAnimationHint = rotationAnimation; |
| 1069 | } |
| 1070 | final PendingIntent usageReport = pendingOptions.getUsageTimeReport(); |
| 1071 | if (usageReport != null) { |
| 1072 | appTimeTracker = new AppTimeTracker(usageReport); |
| 1073 | } |
| 1074 | final boolean useLockTask = pendingOptions.getLockTaskMode(); |
| 1075 | if (useLockTask && lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_DEFAULT) { |
| 1076 | lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 1077 | } |
Louis Chang | d58cb67 | 2018-12-24 17:45:16 +0800 | [diff] [blame] | 1078 | // Gets launch display id from options. It returns INVALID_DISPLAY if not set. |
| 1079 | mHandoverLaunchDisplayId = options.getLaunchDisplayId(); |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1080 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1083 | void setProcess(WindowProcessController proc) { |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1084 | app = proc; |
| 1085 | final ActivityRecord root = task != null ? task.getRootActivity() : null; |
| 1086 | if (root == this) { |
| 1087 | task.setRootProcess(proc); |
| 1088 | } |
| 1089 | } |
| 1090 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1091 | boolean hasProcess() { |
| 1092 | return app != null; |
| 1093 | } |
| 1094 | |
| 1095 | boolean attachedToProcess() { |
| 1096 | return hasProcess() && app.hasThread(); |
| 1097 | } |
| 1098 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1099 | void createAppWindowToken() { |
| 1100 | if (mAppWindowToken != null) { |
| 1101 | throw new IllegalArgumentException("App Window Token=" + mAppWindowToken |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1102 | + " already created for r=" + this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | inHistory = true; |
| 1106 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 1107 | // TODO(b/36505427): Maybe this call should be moved inside updateOverrideConfiguration() |
| 1108 | task.updateOverrideConfigurationFromLaunchBounds(); |
| 1109 | // Make sure override configuration is up-to-date before using to create window controller. |
| 1110 | updateOverrideConfiguration(); |
| 1111 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1112 | // TODO: remove after unification |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1113 | mAppWindowToken = mAtmService.mWindowManager.mRoot.getAppWindowToken(appToken.asBinder()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1114 | if (mAppWindowToken != null) { |
| 1115 | // TODO: Should this throw an exception instead? |
| 1116 | Slog.w(TAG, "Attempted to add existing app token: " + appToken); |
| 1117 | } else { |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 1118 | final Task container = task.getTask(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1119 | if (container == null) { |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 1120 | throw new IllegalArgumentException("createAppWindowToken: invalid task =" + task); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1121 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1122 | mAppWindowToken = createAppWindow(mAtmService.mWindowManager, appToken, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1123 | task.voiceSession != null, container.getDisplayContent(), |
| 1124 | ActivityTaskManagerService.getInputDispatchingTimeoutLocked(this) |
| 1125 | * 1000000L, fullscreen, |
| 1126 | (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, appInfo.targetSdkVersion, |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 1127 | info.screenOrientation, mRotationAnimationHint, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1128 | mLaunchTaskBehind, isAlwaysFocusable()); |
| 1129 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1130 | Slog.v(TAG, "addAppToken: " |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 1131 | + mAppWindowToken + " task=" + container + " at " |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1132 | + Integer.MAX_VALUE); |
| 1133 | } |
| 1134 | container.addChild(mAppWindowToken, Integer.MAX_VALUE /* add on top */); |
| 1135 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1136 | |
| 1137 | task.addActivityToTop(this); |
| 1138 | |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 1139 | // When an activity is started directly into a split-screen fullscreen stack, we need to |
| 1140 | // update the initial multi-window modes so that the callbacks are scheduled correctly when |
| 1141 | // the user leaves that mode. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1142 | mLastReportedMultiWindowMode = inMultiWindowMode(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1143 | mLastReportedPictureInPictureMode = inPinnedWindowingMode(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1144 | } |
| 1145 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1146 | boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo, |
| 1147 | CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, |
| 1148 | IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning, |
| 1149 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents) { |
| 1150 | if (DEBUG_STARTING_WINDOW) { |
| 1151 | Slog.v(TAG, "setAppStartingWindow: token=" + appToken |
| 1152 | + " pkg=" + pkg + " transferFrom=" + transferFrom + " newTask=" + newTask |
| 1153 | + " taskSwitch=" + taskSwitch + " processRunning=" + processRunning |
| 1154 | + " allowTaskSnapshot=" + allowTaskSnapshot); |
| 1155 | } |
| 1156 | if (mAppWindowToken == null) { |
| 1157 | Slog.w(TAG_WM, "Attempted to set icon of non-existing app token: " + appToken); |
| 1158 | return false; |
| 1159 | } |
Yunfan Chen | 48c0ed08 | 2018-12-05 18:15:35 -0800 | [diff] [blame] | 1160 | if (mAppWindowToken.getTask() == null) { |
| 1161 | // Can be removed after unification of Task and TaskRecord. |
| 1162 | Slog.w(TAG_WM, "Attempted to start a window to an app token not having attached to any" |
| 1163 | + " task: " + appToken); |
| 1164 | return false; |
| 1165 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1166 | return mAppWindowToken.addStartingWindow(pkg, theme, compatInfo, nonLocalizedLabel, |
| 1167 | labelRes, icon, logo, windowFlags, transferFrom, newTask, taskSwitch, |
| 1168 | processRunning, allowTaskSnapshot, activityCreated, fromRecents); |
| 1169 | } |
| 1170 | |
| 1171 | // TODO: Remove after unification |
| 1172 | @VisibleForTesting |
| 1173 | AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token, |
| 1174 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 1175 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 1176 | int rotationAnimationHint, boolean launchTaskBehind, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1177 | boolean alwaysFocusable) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1178 | return new AppWindowToken(service, token, mActivityComponent, voiceInteraction, dc, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1179 | inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk, orientation, |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 1180 | rotationAnimationHint, launchTaskBehind, alwaysFocusable, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1181 | this); |
| 1182 | } |
| 1183 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1184 | void removeWindowContainer() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1185 | if (mAtmService.mWindowManager.mRoot == null) return; |
Yunfan Chen | d4ef301 | 2018-11-28 21:14:32 -0800 | [diff] [blame] | 1186 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1187 | final DisplayContent dc = mAtmService.mWindowManager.mRoot.getDisplayContent( |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1188 | getDisplayId()); |
| 1189 | if (dc == null) { |
| 1190 | Slog.w(TAG, "removeWindowContainer: Attempted to remove token: " |
| 1191 | + appToken + " from non-existing displayId=" + getDisplayId()); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1192 | return; |
| 1193 | } |
Wale Ogunwale | cc367f4 | 2017-02-01 08:12:14 -0800 | [diff] [blame] | 1194 | // Resume key dispatching if it is currently paused before we remove the container. |
| 1195 | resumeKeyDispatchingLocked(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1196 | dc.removeAppToken(appToken.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | } |
| 1198 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1199 | /** |
| 1200 | * Reparents this activity into {@param newTask} at the provided {@param position}. The caller |
| 1201 | * should ensure that the {@param newTask} is not already the parent of this activity. |
| 1202 | */ |
| 1203 | void reparent(TaskRecord newTask, int position, String reason) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1204 | if (mAppWindowToken == null) { |
| 1205 | Slog.w(TAG, "reparent: Attempted to reparent non-existing app token: " + appToken); |
| 1206 | return; |
| 1207 | } |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1208 | final TaskRecord prevTask = task; |
| 1209 | if (prevTask == newTask) { |
| 1210 | throw new IllegalArgumentException(reason + ": task=" + newTask |
| 1211 | + " is already the parent of r=" + this); |
| 1212 | } |
| 1213 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1214 | // TODO: Ensure that we do not directly reparent activities across stacks, as that may leave |
| 1215 | // the stacks in strange states. For now, we should use Task.reparent() to ensure that |
| 1216 | // the stack is left in an OK state. |
| 1217 | if (prevTask != null && newTask != null && prevTask.getStack() != newTask.getStack()) { |
| 1218 | throw new IllegalArgumentException(reason + ": task=" + newTask |
| 1219 | + " is in a different stack (" + newTask.getStackId() + ") than the parent of" |
| 1220 | + " r=" + this + " (" + prevTask.getStackId() + ")"); |
| 1221 | } |
| 1222 | |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 1223 | mAppWindowToken.reparent(newTask.getTask(), position); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1224 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1225 | // Reparenting prevents informing the parent stack of activity removal in the case that |
| 1226 | // the new stack has the same parent. we must manually signal here if this is not the case. |
| 1227 | final ActivityStack prevStack = prevTask.getStack(); |
| 1228 | |
| 1229 | if (prevStack != newTask.getStack()) { |
| 1230 | prevStack.onActivityRemovedFromStack(this); |
| 1231 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1232 | // Remove the activity from the old task and add it to the new task. |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 1233 | prevTask.removeActivity(this, true /* reparenting */); |
Bryce Lee | 0f9bde8 | 2017-02-22 16:39:06 -0800 | [diff] [blame] | 1234 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1235 | newTask.addActivityAtIndex(position, this); |
| 1236 | } |
| 1237 | |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1238 | private boolean isHomeIntent(Intent intent) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1239 | return ACTION_MAIN.equals(intent.getAction()) |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 1240 | && (intent.hasCategory(CATEGORY_HOME) |
| 1241 | || intent.hasCategory(CATEGORY_SECONDARY_HOME)) |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1242 | && intent.getCategories().size() == 1 |
| 1243 | && intent.getData() == null |
| 1244 | && intent.getType() == null; |
| 1245 | } |
| 1246 | |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 1247 | static boolean isMainIntent(Intent intent) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1248 | return ACTION_MAIN.equals(intent.getAction()) |
| 1249 | && intent.hasCategory(CATEGORY_LAUNCHER) |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 1250 | && intent.getCategories().size() == 1 |
| 1251 | && intent.getData() == null |
| 1252 | && intent.getType() == null; |
| 1253 | } |
| 1254 | |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1255 | private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) { |
| 1256 | if (uid == Process.myUid() || uid == 0) { |
| 1257 | // System process can launch home activity. |
| 1258 | return true; |
| 1259 | } |
Winson Chung | 547afd2 | 2018-05-17 16:03:25 -0700 | [diff] [blame] | 1260 | // Allow the recents component to launch the home activity. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1261 | final RecentTasks recentTasks = mStackSupervisor.mService.getRecentTasks(); |
Winson Chung | 547afd2 | 2018-05-17 16:03:25 -0700 | [diff] [blame] | 1262 | if (recentTasks != null && recentTasks.isCallerRecents(uid)) { |
| 1263 | return true; |
| 1264 | } |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1265 | // Resolver activity can launch home activity. |
| 1266 | return sourceRecord != null && sourceRecord.isResolverActivity(); |
| 1267 | } |
| 1268 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1269 | /** |
| 1270 | * @return whether the given package name can launch an assist activity. |
| 1271 | */ |
| 1272 | private boolean canLaunchAssistActivity(String packageName) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1273 | final ComponentName assistComponent = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1274 | mAtmService.mActiveVoiceInteractionServiceComponent; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1275 | if (assistComponent != null) { |
| 1276 | return assistComponent.getPackageName().equals(packageName); |
| 1277 | } |
| 1278 | return false; |
| 1279 | } |
| 1280 | |
| 1281 | private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent, |
| 1282 | ActivityOptions options, ActivityRecord sourceRecord) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1283 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1284 | if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord)) |
| 1285 | && isHomeIntent(intent) && !isResolverActivity()) { |
| 1286 | // This sure looks like a home activity! |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1287 | activityType = ACTIVITY_TYPE_HOME; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 1288 | |
| 1289 | if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE |
| 1290 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 1291 | // We only allow home activities to be resizeable if they explicitly requested it. |
| 1292 | info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
| 1293 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1294 | } else if (mActivityComponent.getClassName().contains(LEGACY_RECENTS_PACKAGE_NAME) |
| 1295 | || mAtmService.getRecentTasks().isRecentsComponent(mActivityComponent, appInfo.uid)) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1296 | activityType = ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1297 | } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_ASSISTANT |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1298 | && canLaunchAssistActivity(launchedFromPackage)) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1299 | activityType = ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1300 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1301 | setActivityType(activityType); |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1304 | void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) { |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 1305 | if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) { |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1306 | task.setTaskToAffiliateWith(taskToAffiliateWith); |
| 1307 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1310 | /** |
| 1311 | * @return Stack value from current task, null if there is no task. |
| 1312 | */ |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1313 | <T extends ActivityStack> T getActivityStack() { |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 1314 | return task != null ? (T) task.getStack() : null; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 1317 | int getStackId() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1318 | return getActivityStack() != null ? getActivityStack().mStackId : INVALID_STACK_ID; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1321 | ActivityDisplay getDisplay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1322 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1323 | return stack != null ? stack.getDisplay() : null; |
| 1324 | } |
| 1325 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1326 | boolean changeWindowTranslucency(boolean toOpaque) { |
| 1327 | if (fullscreen == toOpaque) { |
| 1328 | return false; |
| 1329 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1330 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1331 | // Keep track of the number of fullscreen activities in this task. |
| 1332 | task.numFullscreen += toOpaque ? +1 : -1; |
| 1333 | |
| 1334 | fullscreen = toOpaque; |
| 1335 | return true; |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1338 | void takeFromHistory() { |
| 1339 | if (inHistory) { |
| 1340 | inHistory = false; |
| 1341 | if (task != null && !finishing) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1342 | task = null; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1343 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1344 | clearOptionsLocked(); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | boolean isInHistory() { |
| 1349 | return inHistory; |
| 1350 | } |
| 1351 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1352 | boolean isInStackLocked() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1353 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1354 | return stack != null && stack.isInStackLocked(this) != null; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1357 | boolean isPersistable() { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1358 | return (info.persistableMode == PERSIST_ROOT_ONLY || |
| 1359 | info.persistableMode == PERSIST_ACROSS_REBOOTS) && |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1360 | (intent == null || (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1363 | boolean isFocusable() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1364 | return mRootActivityContainer.isFocusable(this, isAlwaysFocusable()); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | boolean isResizeable() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1368 | return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture(); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1371 | /** |
| 1372 | * @return whether this activity is non-resizeable or forced to be resizeable |
| 1373 | */ |
| 1374 | boolean isNonResizableOrForcedResizable() { |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 1375 | return info.resizeMode != RESIZE_MODE_RESIZEABLE |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 1376 | && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1379 | /** |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1380 | * @return whether this activity supports PiP multi-window and can be put in the pinned stack. |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1381 | */ |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1382 | boolean supportsPictureInPicture() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1383 | return mAtmService.mSupportsPictureInPicture && isActivityTypeStandardOrUndefined() |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1384 | && info.supportsPictureInPicture(); |
| 1385 | } |
| 1386 | |
| 1387 | /** |
| 1388 | * @return whether this activity supports split-screen multi-window and can be put in the docked |
| 1389 | * stack. |
| 1390 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1391 | @Override |
| 1392 | public boolean supportsSplitScreenWindowingMode() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1393 | // An activity can not be docked even if it is considered resizeable because it only |
| 1394 | // supports picture-in-picture mode but has a non-resizeable resizeMode |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1395 | return super.supportsSplitScreenWindowingMode() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1396 | && mAtmService.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | /** |
| 1400 | * @return whether this activity supports freeform multi-window and can be put in the freeform |
| 1401 | * stack. |
| 1402 | */ |
| 1403 | boolean supportsFreeform() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1404 | return mAtmService.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * @return whether this activity supports non-PiP multi-window. |
| 1409 | */ |
| 1410 | private boolean supportsResizeableMultiWindow() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1411 | return mAtmService.mSupportsMultiWindow && !isActivityTypeHome() |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1412 | && (ActivityInfo.isResizeableMode(info.resizeMode) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1413 | || mAtmService.mForceResizableActivities); |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1414 | } |
| 1415 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1416 | /** |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1417 | * Check whether this activity can be launched on the specified display. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1418 | * |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1419 | * @param displayId Target display id. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1420 | * @return {@code true} if either it is the default display or this activity can be put on a |
| 1421 | * secondary screen. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1422 | */ |
| 1423 | boolean canBeLaunchedOnDisplay(int displayId) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1424 | return mAtmService.mStackSupervisor.canPlaceEntityOnDisplay(displayId, launchedFromPid, |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 1425 | launchedFromUid, info); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | /** |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 1429 | * @param beforeStopping Whether this check is for an auto-enter-pip operation, that is to say |
| 1430 | * the activity has requested to enter PiP when it would otherwise be stopped. |
| 1431 | * |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 1432 | * @return whether this activity is currently allowed to enter PIP. |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1433 | */ |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 1434 | boolean checkEnterPictureInPictureState(String caller, boolean beforeStopping) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 1435 | if (!supportsPictureInPicture()) { |
| 1436 | return false; |
| 1437 | } |
| 1438 | |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1439 | // Check app-ops and see if PiP is supported for this package |
| 1440 | if (!checkEnterPictureInPictureAppOpsState()) { |
| 1441 | return false; |
| 1442 | } |
| 1443 | |
Winson Chung | f1bfee1 | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1444 | // Check to see if we are in VR mode, and disallow PiP if so |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1445 | if (mAtmService.shouldDisableNonVrUiLocked()) { |
Winson Chung | f1bfee1 | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
| 1448 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1449 | boolean isKeyguardLocked = mAtmService.isKeyguardLocked(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1450 | boolean isCurrentAppLocked = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1451 | mAtmService.getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1452 | final ActivityDisplay display = getDisplay(); |
| 1453 | boolean hasPinnedStack = display != null && display.hasPinnedStack(); |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 1454 | // Don't return early if !isNotLocked, since we want to throw an exception if the activity |
| 1455 | // is in an incorrect state |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 1456 | boolean isNotLockedOrOnKeyguard = !isKeyguardLocked && !isCurrentAppLocked; |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 1457 | |
| 1458 | // We don't allow auto-PiP when something else is already pipped. |
| 1459 | if (beforeStopping && hasPinnedStack) { |
| 1460 | return false; |
| 1461 | } |
| 1462 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1463 | switch (mState) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1464 | case RESUMED: |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 1465 | // When visible, allow entering PiP if the app is not locked. If it is over the |
| 1466 | // keyguard, then we will prompt to unlock in the caller before entering PiP. |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 1467 | return !isCurrentAppLocked && |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1468 | (supportsEnterPipOnTaskSwitch || !beforeStopping); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1469 | case PAUSING: |
| 1470 | case PAUSED: |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 1471 | // When pausing, then only allow enter PiP as in the resume state, and in addition, |
| 1472 | // require that there is not an existing PiP activity and that the current system |
| 1473 | // state supports entering PiP |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 1474 | return isNotLockedOrOnKeyguard && !hasPinnedStack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1475 | && supportsEnterPipOnTaskSwitch; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1476 | case STOPPING: |
| 1477 | // When stopping in a valid state, then only allow enter PiP as in the pause state. |
| 1478 | // Otherwise, fall through to throw an exception if the caller is trying to enter |
| 1479 | // PiP in an invalid stopping state. |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1480 | if (supportsEnterPipOnTaskSwitch) { |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1481 | return isNotLockedOrOnKeyguard && !hasPinnedStack; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1482 | } |
| 1483 | default: |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 1484 | return false; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 1485 | } |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1488 | /** |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1489 | * @return Whether AppOps allows this package to enter picture-in-picture. |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1490 | */ |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1491 | private boolean checkEnterPictureInPictureAppOpsState() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1492 | return mAtmService.getAppOpsService().checkOperation( |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1493 | OP_PICTURE_IN_PICTURE, appInfo.uid, packageName) == MODE_ALLOWED; |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1494 | } |
| 1495 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 1496 | boolean isAlwaysFocusable() { |
| 1497 | return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1500 | /** Move activity with its stack to front and make the stack focused. */ |
| 1501 | boolean moveFocusableActivityToTop(String reason) { |
| 1502 | if (!isFocusable()) { |
| 1503 | if (DEBUG_FOCUS) { |
| 1504 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: unfocusable activity=" + this); |
| 1505 | } |
| 1506 | return false; |
| 1507 | } |
| 1508 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1509 | final TaskRecord task = getTaskRecord(); |
| 1510 | final ActivityStack stack = getActivityStack(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1511 | if (stack == null) { |
| 1512 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: activity=" |
| 1513 | + this + " task=" + task); |
| 1514 | return false; |
| 1515 | } |
| 1516 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1517 | if (mRootActivityContainer.getTopResumedActivity() == this) { |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1518 | if (DEBUG_FOCUS) { |
| 1519 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: already on top, activity=" + this); |
| 1520 | } |
| 1521 | return false; |
| 1522 | } |
| 1523 | |
| 1524 | if (DEBUG_FOCUS) { |
| 1525 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: activity=" + this); |
| 1526 | } |
| 1527 | |
| 1528 | stack.moveToFront(reason, task); |
| 1529 | // Report top activity change to tracking services and WM |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1530 | if (mRootActivityContainer.getTopResumedActivity() == this) { |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1531 | // TODO(b/111361570): Support multiple focused apps in WM |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1532 | mAtmService.setResumedActivityUncheckLocked(this, reason); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1533 | } |
| 1534 | return true; |
| 1535 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1536 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1537 | void makeFinishingLocked() { |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1538 | if (finishing) { |
| 1539 | return; |
| 1540 | } |
| 1541 | finishing = true; |
| 1542 | if (stopped) { |
| 1543 | clearOptionsLocked(); |
| 1544 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 1545 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1546 | if (mAtmService != null) { |
| 1547 | mAtmService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1551 | UriPermissionOwner getUriPermissionsLocked() { |
| 1552 | if (uriPermissions == null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1553 | uriPermissions = new UriPermissionOwner(mAtmService.mUgmInternal, this); |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1554 | } |
| 1555 | return uriPermissions; |
| 1556 | } |
| 1557 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1558 | void addResultLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | int requestCode, int resultCode, |
| 1560 | Intent resultData) { |
| 1561 | ActivityResult r = new ActivityResult(from, resultWho, |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 1562 | requestCode, resultCode, resultData); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | if (results == null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1564 | results = new ArrayList<ResultInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | } |
| 1566 | results.add(r); |
| 1567 | } |
| 1568 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1569 | void removeResultsLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | int requestCode) { |
| 1571 | if (results != null) { |
| 1572 | for (int i=results.size()-1; i>=0; i--) { |
| 1573 | ActivityResult r = (ActivityResult)results.get(i); |
| 1574 | if (r.mFrom != from) continue; |
| 1575 | if (r.mResultWho == null) { |
| 1576 | if (resultWho != null) continue; |
| 1577 | } else { |
| 1578 | if (!r.mResultWho.equals(resultWho)) continue; |
| 1579 | } |
| 1580 | if (r.mRequestCode != requestCode) continue; |
| 1581 | |
| 1582 | results.remove(i); |
| 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1587 | private void addNewIntentLocked(ReferrerIntent intent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | if (newIntents == null) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1589 | newIntents = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | } |
| 1591 | newIntents.add(intent); |
| 1592 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1593 | |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1594 | final boolean isSleeping() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1595 | final ActivityStack stack = getActivityStack(); |
| 1596 | return stack != null ? stack.shouldSleepActivities() : mAtmService.isSleepingLocked(); |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1599 | /** |
| 1600 | * Deliver a new Intent to an existing activity, so that its onNewIntent() |
| 1601 | * method will be called at the proper time. |
| 1602 | */ |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 1603 | final void deliverNewIntentLocked(int callingUid, Intent intent, NeededUriGrants intentGrants, |
| 1604 | String referrer) { |
Dianne Hackborn | 514074f | 2013-02-11 10:52:46 -0800 | [diff] [blame] | 1605 | // The activity now gets access to the data associated with this Intent. |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 1606 | mAtmService.mUgmInternal.grantUriPermissionUncheckedFromIntent(intentGrants, |
| 1607 | getUriPermissionsLocked()); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1608 | final ReferrerIntent rintent = new ReferrerIntent(intent, referrer); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1609 | boolean unsent = true; |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1610 | final boolean isTopActivityWhileSleeping = isTopRunningActivity() && isSleeping(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 1611 | |
| 1612 | // We want to immediately deliver the intent to the activity if: |
Wale Ogunwale | 03f7e9e | 2016-09-22 09:04:09 -0700 | [diff] [blame] | 1613 | // - It is currently resumed or paused. i.e. it is currently visible to the user and we want |
| 1614 | // the user to see the visual effects caused by the intent delivery now. |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 1615 | // - The device is sleeping and it is the top activity behind the lock screen (b/6700897). |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1616 | if ((mState == RESUMED || mState == PAUSED || isTopActivityWhileSleeping) |
| 1617 | && attachedToProcess()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1618 | try { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1619 | ArrayList<ReferrerIntent> ar = new ArrayList<>(1); |
| 1620 | ar.add(rintent); |
Louis Chang | 92d1652 | 2019-02-27 12:56:18 +0800 | [diff] [blame] | 1621 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 1622 | NewIntentItem.obtain(ar)); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1623 | unsent = false; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 1624 | } catch (RemoteException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1625 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 1626 | } catch (NullPointerException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1627 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 1630 | if (unsent) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1631 | addNewIntentLocked(rintent); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1632 | } |
| 1633 | } |
| 1634 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1635 | void updateOptionsLocked(ActivityOptions options) { |
| 1636 | if (options != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 1637 | if (DEBUG_TRANSITION) Slog.i(TAG, "Update options for " + this); |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1638 | if (pendingOptions != null) { |
| 1639 | pendingOptions.abort(); |
| 1640 | } |
| 1641 | pendingOptions = options; |
| 1642 | } |
| 1643 | } |
| 1644 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1645 | void applyOptionsLocked() { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1646 | if (pendingOptions != null |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1647 | && pendingOptions.getAnimationType() != ANIM_SCENE_TRANSITION) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 1648 | if (DEBUG_TRANSITION) Slog.i(TAG, "Applying options for " + this); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1649 | applyOptionsLocked(pendingOptions, intent); |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1650 | if (task == null) { |
| 1651 | clearOptionsLocked(false /* withAbort */); |
| 1652 | } else { |
| 1653 | // This will clear the options for all the ActivityRecords for this Task. |
| 1654 | task.clearAllPendingOptions(); |
| 1655 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1659 | /** |
| 1660 | * Apply override app transition base on options & animation type. |
| 1661 | */ |
| 1662 | void applyOptionsLocked(ActivityOptions pendingOptions, Intent intent) { |
| 1663 | final int animationType = pendingOptions.getAnimationType(); |
| 1664 | final DisplayContent displayContent = mAppWindowToken.getDisplayContent(); |
| 1665 | switch (animationType) { |
| 1666 | case ANIM_CUSTOM: |
| 1667 | displayContent.mAppTransition.overridePendingAppTransition( |
| 1668 | pendingOptions.getPackageName(), |
| 1669 | pendingOptions.getCustomEnterResId(), |
| 1670 | pendingOptions.getCustomExitResId(), |
| 1671 | pendingOptions.getOnAnimationStartListener()); |
| 1672 | break; |
| 1673 | case ANIM_CLIP_REVEAL: |
| 1674 | displayContent.mAppTransition.overridePendingAppTransitionClipReveal( |
| 1675 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1676 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 1677 | if (intent.getSourceBounds() == null) { |
| 1678 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1679 | pendingOptions.getStartY(), |
| 1680 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1681 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1682 | } |
| 1683 | break; |
| 1684 | case ANIM_SCALE_UP: |
| 1685 | displayContent.mAppTransition.overridePendingAppTransitionScaleUp( |
| 1686 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1687 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 1688 | if (intent.getSourceBounds() == null) { |
| 1689 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1690 | pendingOptions.getStartY(), |
| 1691 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1692 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1693 | } |
| 1694 | break; |
| 1695 | case ANIM_THUMBNAIL_SCALE_UP: |
| 1696 | case ANIM_THUMBNAIL_SCALE_DOWN: |
| 1697 | final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP); |
| 1698 | final GraphicBuffer buffer = pendingOptions.getThumbnail(); |
| 1699 | displayContent.mAppTransition.overridePendingAppTransitionThumb(buffer, |
| 1700 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1701 | pendingOptions.getOnAnimationStartListener(), |
| 1702 | scaleUp); |
| 1703 | if (intent.getSourceBounds() == null && buffer != null) { |
| 1704 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1705 | pendingOptions.getStartY(), |
| 1706 | pendingOptions.getStartX() + buffer.getWidth(), |
| 1707 | pendingOptions.getStartY() + buffer.getHeight())); |
| 1708 | } |
| 1709 | break; |
| 1710 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 1711 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
| 1712 | final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs(); |
| 1713 | final IAppTransitionAnimationSpecsFuture specsFuture = |
| 1714 | pendingOptions.getSpecsFuture(); |
| 1715 | if (specsFuture != null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1716 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumbFuture( |
| 1717 | specsFuture, pendingOptions.getOnAnimationStartListener(), |
| 1718 | animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP); |
| 1719 | } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN |
| 1720 | && specs != null) { |
| 1721 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumb( |
| 1722 | specs, pendingOptions.getOnAnimationStartListener(), |
| 1723 | pendingOptions.getAnimationFinishedListener(), false); |
| 1724 | } else { |
| 1725 | displayContent.mAppTransition.overridePendingAppTransitionAspectScaledThumb( |
| 1726 | pendingOptions.getThumbnail(), |
| 1727 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 1728 | pendingOptions.getWidth(), pendingOptions.getHeight(), |
| 1729 | pendingOptions.getOnAnimationStartListener(), |
| 1730 | (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP)); |
| 1731 | if (intent.getSourceBounds() == null) { |
| 1732 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 1733 | pendingOptions.getStartY(), |
| 1734 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 1735 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 1736 | } |
| 1737 | } |
| 1738 | break; |
| 1739 | case ANIM_OPEN_CROSS_PROFILE_APPS: |
| 1740 | displayContent.mAppTransition |
| 1741 | .overridePendingAppTransitionStartCrossProfileApps(); |
| 1742 | break; |
| 1743 | case ANIM_REMOTE_ANIMATION: |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1744 | displayContent.mAppTransition.overridePendingAppTransitionRemote( |
| 1745 | pendingOptions.getRemoteAnimationAdapter()); |
| 1746 | break; |
| 1747 | case ANIM_NONE: |
| 1748 | break; |
| 1749 | default: |
| 1750 | Slog.e(TAG_WM, "applyOptionsLocked: Unknown animationType=" + animationType); |
| 1751 | break; |
| 1752 | } |
| 1753 | } |
| 1754 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1755 | ActivityOptions getOptionsForTargetActivityLocked() { |
| 1756 | return pendingOptions != null ? pendingOptions.forTargetActivity() : null; |
| 1757 | } |
| 1758 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1759 | void clearOptionsLocked() { |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1760 | clearOptionsLocked(true /* withAbort */); |
| 1761 | } |
| 1762 | |
| 1763 | void clearOptionsLocked(boolean withAbort) { |
| 1764 | if (withAbort && pendingOptions != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1765 | pendingOptions.abort(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1766 | } |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 1767 | pendingOptions = null; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 1770 | ActivityOptions takeOptionsLocked(boolean fromClient) { |
| 1771 | if (DEBUG_TRANSITION) Slog.i(TAG, "Taking options for " + this + " callers=" |
| 1772 | + Debug.getCallers(6)); |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1773 | ActivityOptions opts = pendingOptions; |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 1774 | |
| 1775 | // If we are trying to take activity options from the client, do not null it out if it's a |
| 1776 | // remote animation as the client doesn't need it ever. This is a workaround when client is |
| 1777 | // faster to take the options than we are to resume the next activity. |
| 1778 | // TODO (b/132432864): Fix the root cause of these transition preparing/applying options |
| 1779 | // timing somehow |
| 1780 | if (!fromClient || opts == null || opts.getRemoteAnimationAdapter() == null) { |
| 1781 | pendingOptions = null; |
| 1782 | } |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 1783 | return opts; |
| 1784 | } |
| 1785 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1786 | void removeUriPermissionsLocked() { |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1787 | if (uriPermissions != null) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 1788 | uriPermissions.removeUriPermissions(); |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 1789 | uriPermissions = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1790 | } |
| 1791 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | |
| 1793 | void pauseKeyDispatchingLocked() { |
| 1794 | if (!keysPaused) { |
| 1795 | keysPaused = true; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1796 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1797 | // TODO: remove the check after unification with AppWindowToken. The DC check is not |
| 1798 | // needed after no mock mAppWindowToken in tests. |
| 1799 | if (mAppWindowToken != null && mAppWindowToken.getDisplayContent() != null) { |
| 1800 | mAppWindowToken.getDisplayContent().getInputMonitor().pauseDispatchingLw( |
| 1801 | mAppWindowToken); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1802 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | void resumeKeyDispatchingLocked() { |
| 1807 | if (keysPaused) { |
| 1808 | keysPaused = false; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1809 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1810 | // TODO: remove the check after unification with AppWindowToken. The DC check is not |
| 1811 | // needed after no mock mAppWindowToken in tests. |
| 1812 | if (mAppWindowToken != null && mAppWindowToken.getDisplayContent() != null) { |
| 1813 | mAppWindowToken.getDisplayContent().getInputMonitor().resumeDispatchingLw( |
| 1814 | mAppWindowToken); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1815 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1819 | private void updateTaskDescription(CharSequence description) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1820 | task.lastDescription = description; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1823 | void setDeferHidingClient(boolean deferHidingClient) { |
| 1824 | if (mDeferHidingClient == deferHidingClient) { |
| 1825 | return; |
| 1826 | } |
| 1827 | mDeferHidingClient = deferHidingClient; |
| 1828 | if (!mDeferHidingClient && !visible) { |
| 1829 | // Hiding the client is no longer deferred and the app isn't visible still, go ahead and |
| 1830 | // update the visibility. |
| 1831 | setVisibility(false); |
| 1832 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1835 | void setVisibility(boolean visible) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1836 | if (mAppWindowToken == null) { |
| 1837 | Slog.w(TAG_WM, "Attempted to set visibility of non-existing app token: " |
| 1838 | + appToken); |
| 1839 | return; |
| 1840 | } |
| 1841 | mAppWindowToken.setVisibility(visible, mDeferHidingClient); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 1842 | mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1845 | // TODO: Look into merging with #commitVisibility() |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1846 | void setVisible(boolean newVisible) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1847 | visible = newVisible; |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1848 | mDeferHidingClient = !visible && mDeferHidingClient; |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1849 | setVisibility(visible); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1850 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 1851 | } |
| 1852 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1853 | void setState(ActivityState state, String reason) { |
| 1854 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State movement: " + this + " from:" + getState() |
| 1855 | + " to:" + state + " reason:" + reason); |
Bryce Lee | 6ff1707 | 2018-02-28 07:26:17 -0800 | [diff] [blame] | 1856 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1857 | if (state == mState) { |
| 1858 | // No need to do anything if state doesn't change. |
| 1859 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State unchanged from:" + state); |
| 1860 | return; |
| 1861 | } |
| 1862 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1863 | mState = state; |
| 1864 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1865 | final TaskRecord parent = getTaskRecord(); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1866 | |
| 1867 | if (parent != null) { |
| 1868 | parent.onActivityStateChanged(this, state, reason); |
| 1869 | } |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 1870 | |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 1871 | // The WindowManager interprets the app stopping signal as |
| 1872 | // an indication that the Surface will eventually be destroyed. |
| 1873 | // This however isn't necessarily true if we are going to sleep. |
| 1874 | if (state == STOPPING && !isSleeping()) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1875 | if (mAppWindowToken == null) { |
| 1876 | Slog.w(TAG_WM, "Attempted to notify stopping on non-existing app token: " |
| 1877 | + appToken); |
| 1878 | return; |
| 1879 | } |
| 1880 | mAppWindowToken.detachChildren(); |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 1881 | } |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 1882 | |
| 1883 | if (state == RESUMED) { |
| 1884 | mAtmService.updateBatteryStats(this, true); |
| 1885 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_RESUMED); |
| 1886 | } else if (state == PAUSED) { |
| 1887 | mAtmService.updateBatteryStats(this, false); |
| 1888 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_PAUSED); |
| 1889 | } else if (state == STOPPED) { |
| 1890 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_STOPPED); |
| 1891 | } else if (state == DESTROYED) { |
| 1892 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_DESTROYED); |
| 1893 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | ActivityState getState() { |
| 1897 | return mState; |
| 1898 | } |
| 1899 | |
| 1900 | /** |
| 1901 | * Returns {@code true} if the Activity is in the specified state. |
| 1902 | */ |
| 1903 | boolean isState(ActivityState state) { |
| 1904 | return state == mState; |
| 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1909 | */ |
| 1910 | boolean isState(ActivityState state1, ActivityState state2) { |
| 1911 | return state1 == mState || state2 == mState; |
| 1912 | } |
| 1913 | |
| 1914 | /** |
| 1915 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1916 | */ |
| 1917 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3) { |
| 1918 | return state1 == mState || state2 == mState || state3 == mState; |
| 1919 | } |
| 1920 | |
| 1921 | /** |
| 1922 | * Returns {@code true} if the Activity is in one of the specified states. |
| 1923 | */ |
| 1924 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3, |
| 1925 | ActivityState state4) { |
| 1926 | return state1 == mState || state2 == mState || state3 == mState || state4 == mState; |
| 1927 | } |
| 1928 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 1929 | void notifyAppResumed(boolean wasStopped) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1930 | if (mAppWindowToken == null) { |
| 1931 | Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " |
| 1932 | + appToken); |
| 1933 | return; |
| 1934 | } |
| 1935 | mAppWindowToken.notifyAppResumed(wasStopped); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | void notifyUnknownVisibilityLaunched() { |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1939 | |
| 1940 | // No display activities never add a window, so there is no point in waiting them for |
| 1941 | // relayout. |
| 1942 | if (!noDisplay) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1943 | if (mAppWindowToken != null) { |
| 1944 | mAppWindowToken.getDisplayContent().mUnknownAppVisibilityController |
| 1945 | .notifyLaunched(mAppWindowToken); |
| 1946 | } |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1947 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1948 | } |
| 1949 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1950 | /** |
| 1951 | * @return true if the input activity should be made visible, ignoring any effect Keyguard |
| 1952 | * might have on the visibility |
| 1953 | * |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 1954 | * TODO(b/123540470): Combine this method and {@link #shouldBeVisible(boolean)}. |
| 1955 | * |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1956 | * @see {@link ActivityStack#checkKeyguardVisibility} |
| 1957 | */ |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1958 | boolean shouldBeVisibleIgnoringKeyguard(boolean behindFullscreenActivity) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1959 | if (!okToShowLocked()) { |
| 1960 | return false; |
| 1961 | } |
| 1962 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 1963 | return !behindFullscreenActivity || mLaunchTaskBehind; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 1966 | boolean shouldBeVisible(boolean behindFullscreenActivity) { |
| 1967 | // Check whether activity should be visible without Keyguard influence |
| 1968 | visibleIgnoringKeyguard = shouldBeVisibleIgnoringKeyguard(behindFullscreenActivity); |
| 1969 | |
| 1970 | final ActivityStack stack = getActivityStack(); |
| 1971 | if (stack == null) { |
| 1972 | return false; |
| 1973 | } |
| 1974 | |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 1975 | // Whether the activity is on the sleeping display. |
| 1976 | // TODO(b/129750406): This should be applied for the default display, too. |
| 1977 | final boolean isDisplaySleeping = getDisplay().isSleeping() |
| 1978 | && getDisplayId() != DEFAULT_DISPLAY; |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 1979 | // Whether this activity is the top activity of this stack. |
| 1980 | final boolean isTop = this == stack.getTopActivity(); |
| 1981 | // Exclude the case where this is the top activity in a pinned stack. |
| 1982 | final boolean isTopNotPinnedStack = stack.isAttached() |
| 1983 | && stack.getDisplay().isTopNotPinnedStack(stack); |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 1984 | // Now check whether it's really visible depending on Keyguard state, and update |
| 1985 | // {@link ActivityStack} internal states. |
| 1986 | final boolean visibleIgnoringDisplayStatus = stack.checkKeyguardVisibility(this, |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 1987 | visibleIgnoringKeyguard, isTop && isTopNotPinnedStack); |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 1988 | return visibleIgnoringDisplayStatus && !isDisplaySleeping; |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | boolean shouldBeVisible() { |
| 1992 | final ActivityStack stack = getActivityStack(); |
| 1993 | if (stack == null) { |
| 1994 | return false; |
| 1995 | } |
| 1996 | |
| 1997 | // TODO: Use real value of behindFullscreenActivity calculated using the same logic in |
| 1998 | // ActivityStack#ensureActivitiesVisibleLocked(). |
| 1999 | return shouldBeVisible(!stack.shouldBeVisible(null /* starting */)); |
| 2000 | } |
| 2001 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2002 | void makeVisibleIfNeeded(ActivityRecord starting, boolean reportToClient) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2003 | // This activity is not currently visible, but is running. Tell it to become visible. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2004 | if (mState == RESUMED || this == starting) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2005 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2006 | "Not making visible, r=" + this + " state=" + mState + " starting=" + starting); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2007 | return; |
| 2008 | } |
| 2009 | |
| 2010 | // If this activity is paused, tell it to now show its window. |
| 2011 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2012 | "Making visible and scheduling visibility: " + this); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2013 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2014 | try { |
| 2015 | if (stack.mTranslucentActivityWaiting != null) { |
| 2016 | updateOptionsLocked(returningOptions); |
| 2017 | stack.mUndrawnActivitiesBelowTopTranslucent.add(this); |
| 2018 | } |
| 2019 | setVisible(true); |
| 2020 | sleeping = false; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 2021 | app.postPendingUiCleanMsg(true); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2022 | if (reportToClient) { |
| 2023 | makeClientVisible(); |
| 2024 | } else { |
| 2025 | mClientVisibilityDeferred = true; |
| 2026 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2027 | // The activity may be waiting for stop, but that is no longer appropriate for it. |
| 2028 | mStackSupervisor.mStoppingActivities.remove(this); |
| 2029 | mStackSupervisor.mGoingToSleepActivities.remove(this); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2030 | } catch (Exception e) { |
| 2031 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 2032 | Slog.w(TAG, "Exception thrown making visible: " + intent.getComponent(), e); |
| 2033 | } |
| 2034 | handleAlreadyVisible(); |
| 2035 | } |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 2036 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2037 | /** Send visibility change message to the client and pause if needed. */ |
| 2038 | void makeClientVisible() { |
| 2039 | mClientVisibilityDeferred = false; |
| 2040 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2041 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2042 | WindowVisibilityItem.obtain(true /* showWindow */)); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2043 | makeActiveIfNeeded(null /* activeActivity*/); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2044 | } catch (Exception e) { |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2045 | Slog.w(TAG, "Exception thrown sending visibility update: " + intent.getComponent(), e); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2046 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2049 | /** |
| 2050 | * Make activity resumed or paused if needed. |
| 2051 | * @param activeActivity an activity that is resumed or just completed pause action. |
| 2052 | * We won't change the state of this activity. |
| 2053 | */ |
| 2054 | boolean makeActiveIfNeeded(ActivityRecord activeActivity) { |
| 2055 | if (shouldResumeActivity(activeActivity)) { |
| 2056 | if (DEBUG_VISIBILITY) { |
| 2057 | Slog.v("TAG_VISIBILITY", "Resume visible activity, " + this); |
| 2058 | } |
| 2059 | return getActivityStack().resumeTopActivityUncheckedLocked(activeActivity /* prev */, |
| 2060 | null /* options */); |
| 2061 | } else if (shouldPauseActivity(activeActivity)) { |
| 2062 | if (DEBUG_VISIBILITY) { |
| 2063 | Slog.v("TAG_VISIBILITY", "Pause visible activity, " + this); |
| 2064 | } |
| 2065 | // An activity must be in the {@link PAUSING} state for the system to validate |
| 2066 | // the move to {@link PAUSED}. |
| 2067 | setState(PAUSING, "makeVisibleIfNeeded"); |
| 2068 | try { |
| 2069 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 2070 | PauseActivityItem.obtain(finishing, false /* userLeaving */, |
| 2071 | configChangeFlags, false /* dontReport */)); |
| 2072 | } catch (Exception e) { |
| 2073 | Slog.w(TAG, "Exception thrown sending pause: " + intent.getComponent(), e); |
| 2074 | } |
| 2075 | } |
| 2076 | return false; |
| 2077 | } |
| 2078 | |
| 2079 | /** |
| 2080 | * Check if activity should be moved to PAUSED state. The activity: |
| 2081 | * - should be eligible to be made active (see {@link #shouldMakeActive(ActivityRecord)}) |
| 2082 | * - should be non-focusable |
| 2083 | * - should not be currently pausing or paused |
| 2084 | * @param activeActivity the activity that is active or just completed pause action. We won't |
| 2085 | * resume if this activity is active. |
| 2086 | */ |
| 2087 | private boolean shouldPauseActivity(ActivityRecord activeActivity) { |
| 2088 | return shouldMakeActive(activeActivity) && !isFocusable() && !isState(PAUSING, PAUSED); |
| 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * Check if activity should be moved to RESUMED state. The activity: |
| 2093 | * - should be eligible to be made active (see {@link #shouldMakeActive(ActivityRecord)}) |
| 2094 | * - should be focusable |
| 2095 | * @param activeActivity the activity that is active or just completed pause action. We won't |
| 2096 | * resume if this activity is active. |
| 2097 | */ |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2098 | @VisibleForTesting |
| 2099 | boolean shouldResumeActivity(ActivityRecord activeActivity) { |
| 2100 | return shouldMakeActive(activeActivity) && isFocusable() && !isState(RESUMED) |
| 2101 | && getActivityStack().getVisibility(activeActivity) == STACK_VISIBILITY_VISIBLE; |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | /** |
| 2105 | * Check if activity is eligible to be made active (resumed of paused). The activity: |
| 2106 | * - should be paused, stopped or stopping |
Andrii Kulian | 996df0d | 2019-01-24 17:04:36 -0800 | [diff] [blame] | 2107 | * - should not be the currently active one or launching behind other tasks |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2108 | * - should be either the topmost in task, or right below the top activity that is finishing |
| 2109 | * If all of these conditions are not met at the same time, the activity cannot be made active. |
| 2110 | */ |
Andrii Kulian | f219536 | 2019-01-31 18:20:11 -0800 | [diff] [blame] | 2111 | @VisibleForTesting |
| 2112 | boolean shouldMakeActive(ActivityRecord activeActivity) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2113 | // If the activity is stopped, stopping, cycle to an active state. We avoid doing |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 2114 | // this when there is an activity waiting to become translucent as the extra binder |
| 2115 | // calls will lead to noticeable jank. A later call to |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2116 | // ActivityStack#ensureActivitiesVisibleLocked will bring the activity to a proper |
| 2117 | // active state. |
| 2118 | if (!isState(RESUMED, PAUSED, STOPPED, STOPPING) |
| 2119 | || getActivityStack().mTranslucentActivityWaiting != null) { |
| 2120 | return false; |
| 2121 | } |
| 2122 | |
| 2123 | if (this == activeActivity) { |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 2124 | return false; |
| 2125 | } |
| 2126 | |
Andrii Kulian | f219536 | 2019-01-31 18:20:11 -0800 | [diff] [blame] | 2127 | if (!mStackSupervisor.readyToResume()) { |
| 2128 | // Making active is currently deferred (e.g. because an activity launch is in progress). |
| 2129 | return false; |
| 2130 | } |
| 2131 | |
Andrii Kulian | 996df0d | 2019-01-24 17:04:36 -0800 | [diff] [blame] | 2132 | if (this.mLaunchTaskBehind) { |
| 2133 | // This activity is being launched from behind, which means that it's not intended to be |
| 2134 | // presented to user right now, even if it's set to be visible. |
| 2135 | return false; |
| 2136 | } |
| 2137 | |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 2138 | // Check if position in task allows to become paused |
| 2139 | final int positionInTask = task.mActivities.indexOf(this); |
| 2140 | if (positionInTask == -1) { |
| 2141 | throw new IllegalStateException("Activity not found in its task"); |
| 2142 | } |
| 2143 | if (positionInTask == task.mActivities.size() - 1) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2144 | // It's the topmost activity in the task - should become resumed now |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 2145 | return true; |
| 2146 | } |
| 2147 | // Check if activity above is finishing now and this one becomes the topmost in task. |
| 2148 | final ActivityRecord activityAbove = task.mActivities.get(positionInTask + 1); |
| 2149 | if (activityAbove.finishing && results == null) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2150 | // We will only allow making active if activity above wasn't launched for result. |
| 2151 | // Otherwise it will cause this activity to resume before getting result. |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 2152 | return true; |
| 2153 | } |
| 2154 | return false; |
| 2155 | } |
| 2156 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2157 | boolean handleAlreadyVisible() { |
| 2158 | stopFreezingScreenLocked(false); |
| 2159 | try { |
| 2160 | if (returningOptions != null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2161 | app.getThread().scheduleOnNewActivityOptions(appToken, returningOptions.toBundle()); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2162 | } |
| 2163 | } catch(RemoteException e) { |
| 2164 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2165 | return mState == RESUMED; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | static void activityResumedLocked(IBinder token) { |
| 2169 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2170 | if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r); |
Charles Chen | 69362cd | 2019-03-29 15:18:45 +0800 | [diff] [blame] | 2171 | if (r == null) { |
| 2172 | // If an app reports resumed after a long delay, the record on server side might have |
| 2173 | // been removed (e.g. destroy timeout), so the token could be null. |
| 2174 | return; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2175 | } |
Charles Chen | 69362cd | 2019-03-29 15:18:45 +0800 | [diff] [blame] | 2176 | r.icicle = null; |
| 2177 | r.haveState = false; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2178 | |
| 2179 | final ActivityDisplay display = r.getDisplay(); |
| 2180 | if (display != null) { |
| 2181 | display.handleActivitySizeCompatModeIfNeeded(r); |
| 2182 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | /** |
| 2186 | * Once we know that we have asked an application to put an activity in the resumed state |
| 2187 | * (either by launching it or explicitly telling it), this function updates the rest of our |
| 2188 | * state to match that fact. |
| 2189 | */ |
| 2190 | void completeResumeLocked() { |
| 2191 | final boolean wasVisible = visible; |
Jorim Jaggi | 8d06205 | 2017-08-22 14:55:17 +0200 | [diff] [blame] | 2192 | setVisible(true); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2193 | if (!wasVisible) { |
| 2194 | // Visibility has changed, so take a note of it so we call the TaskStackChangedListener |
| 2195 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 2196 | } |
| 2197 | idle = false; |
| 2198 | results = null; |
| 2199 | newIntents = null; |
| 2200 | stopped = false; |
| 2201 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2202 | if (isActivityTypeHome()) { |
Louis Chang | dcdde95 | 2018-12-04 15:38:44 +0800 | [diff] [blame] | 2203 | mStackSupervisor.updateHomeProcess(task.mActivities.get(0).app); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | if (nowVisible) { |
Louis Chang | a59937a | 2019-03-20 17:17:22 +0800 | [diff] [blame] | 2207 | mStackSupervisor.stopWaitingForActivityVisible(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | // Schedule an idle timeout in case the app doesn't do it for us. |
| 2211 | mStackSupervisor.scheduleIdleTimeoutLocked(this); |
| 2212 | |
| 2213 | mStackSupervisor.reportResumedActivityLocked(this); |
| 2214 | |
| 2215 | resumeKeyDispatchingLocked(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2216 | final ActivityStack stack = getActivityStack(); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2217 | mStackSupervisor.mNoAnimActivities.clear(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2218 | |
| 2219 | // Mark the point when the activity is resuming |
| 2220 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 2221 | // not after the onResume. But for subsequent starts, onResume is fine. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2222 | if (hasProcess()) { |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 2223 | cpuTimeAtResume = app.getCpuTime(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2224 | } else { |
| 2225 | cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 2226 | } |
| 2227 | |
| 2228 | returningOptions = null; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2229 | |
| 2230 | if (canTurnScreenOn()) { |
| 2231 | mStackSupervisor.wakeUp("turnScreenOnFlag"); |
| 2232 | } else { |
| 2233 | // If the screen is going to turn on because the caller explicitly requested it and |
| 2234 | // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will |
| 2235 | // pause and then resume again later, which will result in a double life-cycle event. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2236 | stack.checkReadyForSleep(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2237 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState, |
| 2241 | CharSequence description) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2242 | final ActivityStack stack = getActivityStack(); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2243 | final boolean isStopping = mState == STOPPING; |
| 2244 | if (!isStopping && mState != RESTARTING_PROCESS) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2245 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2246 | stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2247 | return; |
| 2248 | } |
| 2249 | if (newPersistentState != null) { |
| 2250 | persistentState = newPersistentState; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2251 | mAtmService.notifyTaskPersisterLocked(task, false); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2252 | } |
| 2253 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2254 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2255 | if (newIcicle != null) { |
| 2256 | // If icicle is null, this is happening due to a timeout, so we haven't really saved |
| 2257 | // the state. |
| 2258 | icicle = newIcicle; |
| 2259 | haveState = true; |
| 2260 | launchCount = 0; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 2261 | updateTaskDescription(description); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2262 | } |
| 2263 | if (!stopped) { |
| 2264 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)"); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2265 | stack.mHandler.removeMessages(STOP_TIMEOUT_MSG, this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2266 | stopped = true; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2267 | if (isStopping) { |
| 2268 | setState(STOPPED, "activityStoppedLocked"); |
| 2269 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2270 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2271 | if (mAppWindowToken != null) { |
| 2272 | mAppWindowToken.notifyAppStopped(); |
| 2273 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2274 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2275 | if (finishing) { |
| 2276 | clearOptionsLocked(); |
| 2277 | } else { |
| 2278 | if (deferRelaunchUntilPaused) { |
| 2279 | stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2280 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2281 | } else { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2282 | mRootActivityContainer.updatePreviousProcess(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2283 | } |
| 2284 | } |
| 2285 | } |
| 2286 | } |
| 2287 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2288 | void startLaunchTickingLocked() { |
Jeff Sharkey | 5ab0243 | 2017-06-27 11:01:36 -0600 | [diff] [blame] | 2289 | if (Build.IS_USER) { |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2290 | return; |
| 2291 | } |
| 2292 | if (launchTickTime == 0) { |
| 2293 | launchTickTime = SystemClock.uptimeMillis(); |
| 2294 | continueLaunchTickingLocked(); |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | boolean continueLaunchTickingLocked() { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2299 | if (launchTickTime == 0) { |
| 2300 | return false; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2301 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2302 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2303 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2304 | if (stack == null) { |
| 2305 | return false; |
| 2306 | } |
| 2307 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2308 | Message msg = stack.mHandler.obtainMessage(LAUNCH_TICK_MSG, this); |
| 2309 | stack.mHandler.removeMessages(LAUNCH_TICK_MSG); |
| 2310 | stack.mHandler.sendMessageDelayed(msg, LAUNCH_TICK); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2311 | return true; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | void finishLaunchTickingLocked() { |
| 2315 | launchTickTime = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2316 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2317 | if (stack != null) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2318 | stack.mHandler.removeMessages(LAUNCH_TICK_MSG); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2319 | } |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | // IApplicationToken |
| 2323 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2324 | public boolean mayFreezeScreenLocked(WindowProcessController app) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | // Only freeze the screen if this activity is currently attached to |
| 2326 | // an application, and that application is not blocked or unresponding. |
| 2327 | // In any other case, we can't count on getting the screen unfrozen, |
| 2328 | // so it is best to leave as-is. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2329 | return hasProcess() && !app.isCrashing() && !app.isNotResponding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2331 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2332 | public void startFreezingScreenLocked(WindowProcessController app, int configChanges) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2333 | if (mayFreezeScreenLocked(app)) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2334 | if (mAppWindowToken == null) { |
| 2335 | Slog.w(TAG_WM, |
| 2336 | "Attempted to freeze screen with non-existing app token: " + appToken); |
| 2337 | return; |
| 2338 | } |
| 2339 | |
Evan Rosky | b1e75f7 | 2019-04-26 20:23:26 -0700 | [diff] [blame] | 2340 | // Window configuration changes only effect windows, so don't require a screen freeze. |
| 2341 | int freezableConfigChanges = configChanges & ~(CONFIG_WINDOW_CONFIGURATION); |
| 2342 | if (freezableConfigChanges == 0 && mAppWindowToken.okToDisplay()) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2343 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Skipping set freeze of " + appToken); |
| 2344 | return; |
| 2345 | } |
| 2346 | |
| 2347 | mAppWindowToken.startFreezingScreen(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | } |
| 2349 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2351 | public void stopFreezingScreenLocked(boolean force) { |
| 2352 | if (force || frozenBeforeDestroy) { |
| 2353 | frozenBeforeDestroy = false; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2354 | if (mAppWindowToken == null) { |
| 2355 | return; |
| 2356 | } |
| 2357 | if (DEBUG_ORIENTATION) { |
| 2358 | Slog.v(TAG_WM, "Clear freezing of " + appToken + ": hidden=" |
| 2359 | + mAppWindowToken.isHidden() + " freezing=" |
| 2360 | + mAppWindowToken.isFreezingScreen()); |
| 2361 | } |
| 2362 | mAppWindowToken.stopFreezingScreen(true, force); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2363 | } |
| 2364 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2365 | |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 2366 | public void reportFullyDrawnLocked(boolean restoredFromBundle) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 2367 | final WindowingModeTransitionInfoSnapshot info = mStackSupervisor |
| 2368 | .getActivityMetricsLogger().logAppTransitionReportedDrawn(this, restoredFromBundle); |
| 2369 | if (info != null) { |
| 2370 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 2371 | info.windowsFullyDrawnDelayMs, info.getLaunchState()); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2372 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 2373 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2374 | |
| 2375 | /** |
| 2376 | * Called when the starting window for this container is drawn. |
| 2377 | */ |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 2378 | public void onStartingWindowDrawn(long timestamp) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2379 | synchronized (mAtmService.mGlobalLock) { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2380 | mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn( |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 2381 | getWindowingMode(), timestamp); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2385 | /** Called when the windows associated app window container are drawn. */ |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 2386 | public void onWindowsDrawn(boolean drawn, long timestamp) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2387 | synchronized (mAtmService.mGlobalLock) { |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 2388 | mDrawn = drawn; |
| 2389 | if (!drawn) { |
| 2390 | return; |
| 2391 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 2392 | final WindowingModeTransitionInfoSnapshot info = mStackSupervisor |
| 2393 | .getActivityMetricsLogger().notifyWindowsDrawn(getWindowingMode(), timestamp); |
| 2394 | final int windowsDrawnDelayMs = info != null ? info.windowsDrawnDelayMs : INVALID_DELAY; |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 2395 | final @LaunchState int launchState = info != null ? info.getLaunchState() : -1; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 2396 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 2397 | windowsDrawnDelayMs, launchState); |
Louis Chang | a59937a | 2019-03-20 17:17:22 +0800 | [diff] [blame] | 2398 | mStackSupervisor.stopWaitingForActivityVisible(this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2399 | finishLaunchTickingLocked(); |
| 2400 | if (task != null) { |
| 2401 | task.hasBeenVisible = true; |
| 2402 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2406 | /** Called when the windows associated app window container are visible. */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2407 | public void onWindowsVisible() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2408 | synchronized (mAtmService.mGlobalLock) { |
Louis Chang | a59937a | 2019-03-20 17:17:22 +0800 | [diff] [blame] | 2409 | mStackSupervisor.stopWaitingForActivityVisible(this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2410 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this); |
| 2411 | if (!nowVisible) { |
| 2412 | nowVisible = true; |
| 2413 | lastVisibleTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2414 | mAtmService.scheduleAppGcsLocked(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2419 | /** Called when the windows associated app window container are no longer visible. */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2420 | public void onWindowsGone() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2421 | synchronized (mAtmService.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2422 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this); |
| 2423 | nowVisible = false; |
| 2424 | } |
| 2425 | } |
| 2426 | |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2427 | void onAnimationFinished() { |
| 2428 | if (mRootActivityContainer.allResumedActivitiesIdle() |
| 2429 | || mStackSupervisor.isStoppingNoHistoryActivity()) { |
| 2430 | // If all activities are already idle or there is an activity that must be |
| 2431 | // stopped immediately after visible, then we now need to make sure we perform |
| 2432 | // the full stop of this activity. This is because we won't do that while they are still |
| 2433 | // waiting for the animation to finish. |
| 2434 | if (mStackSupervisor.mStoppingActivities.contains(this)) { |
| 2435 | mStackSupervisor.scheduleIdleLocked(); |
| 2436 | } |
| 2437 | } else { |
| 2438 | // Instead of doing the full stop routine here, let's just hide any activities |
| 2439 | // we now can, and let them stop when the normal idle happens. |
| 2440 | mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */, |
| 2441 | false /* remove */, true /* processPausingActivities */); |
| 2442 | } |
| 2443 | } |
| 2444 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2445 | /** |
| 2446 | * Called when the key dispatching to a window associated with the app window container |
| 2447 | * timed-out. |
| 2448 | * |
| 2449 | * @param reason The reason for the key dispatching time out. |
| 2450 | * @param windowPid The pid of the window key dispatching timed out on. |
| 2451 | * @return True if input dispatching should be aborted. |
| 2452 | */ |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2453 | public boolean keyDispatchingTimedOut(String reason, int windowPid) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2454 | ActivityRecord anrActivity; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2455 | WindowProcessController anrApp; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2456 | boolean windowFromSameProcessAsActivity; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2457 | synchronized (mAtmService.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2458 | anrActivity = getWaitingHistoryRecordLocked(); |
| 2459 | anrApp = app; |
Brian Carlstrom | 7b0f2e8 | 2017-03-31 00:24:18 -0700 | [diff] [blame] | 2460 | windowFromSameProcessAsActivity = |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2461 | !hasProcess() || app.getPid() == windowPid || windowPid == -1; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2462 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2463 | |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2464 | if (windowFromSameProcessAsActivity) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2465 | return mAtmService.mAmInternal.inputDispatchingTimedOut(anrApp.mOwner, |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2466 | anrActivity.shortComponentName, anrActivity.appInfo, shortComponentName, |
| 2467 | app, false, reason); |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2468 | } else { |
| 2469 | // In this case another process added windows using this activity token. So, we call the |
| 2470 | // generic service input dispatch timed out method so that the right process is blamed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2471 | return mAtmService.mAmInternal.inputDispatchingTimedOut( |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 2472 | windowPid, false /* aboveSystem */, reason) < 0; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 2473 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | private ActivityRecord getWaitingHistoryRecordLocked() { |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2477 | // First find the real culprit... if this activity has stopped, then the key dispatching |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2478 | // timeout should not be caused by this. |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2479 | if (stopped) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2480 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2481 | // Try to use the one which is closest to top. |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2482 | ActivityRecord r = stack.getResumedActivity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | if (r == null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2484 | r = stack.mPausingActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2486 | if (r != null) { |
| 2487 | return r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | } |
| 2489 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 2490 | return this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2493 | /** Checks whether the activity should be shown for current user. */ |
| 2494 | public boolean okToShowLocked() { |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 2495 | // We cannot show activities when the device is locked and the application is not |
| 2496 | // encryption aware. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2497 | if (!StorageManager.isUserKeyUnlocked(mUserId) |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 2498 | && !info.applicationInfo.isEncryptionAware()) { |
| 2499 | return false; |
| 2500 | } |
| 2501 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2502 | return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0 |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2503 | || (mStackSupervisor.isCurrentProfileLocked(mUserId) |
| 2504 | && mAtmService.mAmInternal.isUserRunning(mUserId, 0 /* flags */)); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | /** |
| 2508 | * This method will return true if the activity is either visible, is becoming visible, is |
| 2509 | * currently pausing, or is resumed. |
| 2510 | */ |
| 2511 | public boolean isInterestingToUserLocked() { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2512 | return visible || nowVisible || mState == PAUSING || mState == RESUMED; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2513 | } |
| 2514 | |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 2515 | void setSleeping(boolean _sleeping) { |
| 2516 | setSleeping(_sleeping, false); |
| 2517 | } |
| 2518 | |
| 2519 | void setSleeping(boolean _sleeping, boolean force) { |
| 2520 | if (!force && sleeping == _sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2521 | return; |
| 2522 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2523 | if (attachedToProcess()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2524 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2525 | app.getThread().scheduleSleeping(appToken, _sleeping); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2526 | if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) { |
| 2527 | mStackSupervisor.mGoingToSleepActivities.add(this); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2528 | } |
| 2529 | sleeping = _sleeping; |
| 2530 | } catch (RemoteException e) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2531 | Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 2535 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2536 | static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2537 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2538 | if (r == null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2539 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2540 | } |
| 2541 | final TaskRecord task = r.task; |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2542 | final int activityNdx = task.mActivities.indexOf(r); |
| 2543 | if (activityNdx < 0 || (onlyRoot && activityNdx > task.findEffectiveRootIndex())) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 2544 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2545 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2546 | return task.taskId; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | static ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2550 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2551 | return (r != null) ? r.getActivityStack().isInStackLocked(r) : null; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2552 | } |
| 2553 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 2554 | static ActivityStack getStackLocked(IBinder token) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2555 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2556 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2557 | return r.getActivityStack(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2558 | } |
| 2559 | return null; |
| 2560 | } |
| 2561 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2562 | /** |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2563 | * @return display id to which this record is attached, |
| 2564 | * {@link android.view.Display#INVALID_DISPLAY} if not attached. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2565 | */ |
| 2566 | int getDisplayId() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2567 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2568 | if (stack == null) { |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2569 | return INVALID_DISPLAY; |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2570 | } |
| 2571 | return stack.mDisplayId; |
| 2572 | } |
| 2573 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2574 | final boolean isDestroyable() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2575 | if (finishing || !hasProcess()) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2576 | // This would be redundant. |
| 2577 | return false; |
| 2578 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2579 | final ActivityStack stack = getActivityStack(); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2580 | if (stack == null || this == stack.getResumedActivity() || this == stack.mPausingActivity |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2581 | || !haveState || !stopped) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2582 | // We're not ready for this kind of thing. |
| 2583 | return false; |
| 2584 | } |
| 2585 | if (visible) { |
| 2586 | // The user would notice this! |
| 2587 | return false; |
| 2588 | } |
| 2589 | return true; |
| 2590 | } |
| 2591 | |
Winson Chung | 3bad5cc0 | 2014-08-19 17:44:32 -0700 | [diff] [blame] | 2592 | private static String createImageFilename(long createTime, int taskId) { |
| 2593 | return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime + |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2594 | IMAGE_EXTENSION; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2597 | void setTaskDescription(TaskDescription _taskDescription) { |
| 2598 | Bitmap icon; |
| 2599 | if (_taskDescription.getIconFilename() == null && |
| 2600 | (icon = _taskDescription.getIcon()) != null) { |
| 2601 | final String iconFilename = createImageFilename(createTime, task.taskId); |
Winson Chung | c8408b8 | 2017-01-25 17:58:56 -0800 | [diff] [blame] | 2602 | final File iconFile = new File(TaskPersister.getUserImagesDir(task.userId), |
| 2603 | iconFilename); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 2604 | final String iconFilePath = iconFile.getAbsolutePath(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2605 | mAtmService.getRecentTasks().saveImage(icon, iconFilePath); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 2606 | _taskDescription.setIconFilename(iconFilePath); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 2607 | } |
| 2608 | taskDescription = _taskDescription; |
| 2609 | } |
| 2610 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2611 | void setVoiceSessionLocked(IVoiceInteractionSession session) { |
| 2612 | voiceSession = session; |
| 2613 | pendingVoiceInteractionStart = false; |
| 2614 | } |
| 2615 | |
| 2616 | void clearVoiceSessionLocked() { |
| 2617 | voiceSession = null; |
| 2618 | pendingVoiceInteractionStart = false; |
| 2619 | } |
| 2620 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2621 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 2622 | showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */); |
| 2623 | } |
| 2624 | |
| 2625 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch, |
| 2626 | boolean fromRecents) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2627 | if (mAppWindowToken == null) { |
Jorim Jaggi | 7017643 | 2017-01-18 12:52:13 +0100 | [diff] [blame] | 2628 | return; |
| 2629 | } |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 2630 | if (mTaskOverlay) { |
| 2631 | // We don't show starting window for overlay activities. |
| 2632 | return; |
| 2633 | } |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 2634 | if (pendingOptions != null |
| 2635 | && pendingOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2636 | // Don't show starting window when using shared element transition. |
| 2637 | return; |
| 2638 | } |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 2639 | |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2640 | final CompatibilityInfo compatInfo = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2641 | mAtmService.compatibilityInfoForPackageLocked(info.applicationInfo); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2642 | final boolean shown = addStartingWindow(packageName, theme, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2643 | compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 2644 | prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(), |
Jorim Jaggi | 70aa4d1 | 2017-05-15 00:05:54 +0200 | [diff] [blame] | 2645 | allowTaskSnapshot(), |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2646 | mState.ordinal() >= RESUMED.ordinal() && mState.ordinal() <= STOPPED.ordinal(), |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 2647 | fromRecents); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2648 | if (shown) { |
| 2649 | mStartingWindowState = STARTING_WINDOW_SHOWN; |
| 2650 | } |
| 2651 | } |
| 2652 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2653 | void removeOrphanedStartingWindow(boolean behindFullscreenActivity) { |
Jorim Jaggi | cb95605 | 2017-05-09 16:27:24 +0200 | [diff] [blame] | 2654 | if (mStartingWindowState == STARTING_WINDOW_SHOWN && behindFullscreenActivity) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2655 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this); |
| 2656 | mStartingWindowState = STARTING_WINDOW_REMOVED; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2657 | mAppWindowToken.removeStartingWindow(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2658 | } |
| 2659 | } |
| 2660 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2661 | void setRequestedOrientation(int requestedOrientation) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 2662 | setOrientation(requestedOrientation, mayFreezeScreenLocked(app)); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2663 | mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged( |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 2664 | task.taskId, requestedOrientation); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 2665 | } |
| 2666 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 2667 | private void setOrientation(int requestedOrientation, boolean freezeScreenIfNeeded) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2668 | if (mAppWindowToken == null) { |
| 2669 | Slog.w(TAG_WM, |
| 2670 | "Attempted to set orientation of non-existing app token: " + appToken); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 2671 | return; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2672 | } |
| 2673 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 2674 | final IBinder binder = |
| 2675 | (freezeScreenIfNeeded && appToken != null) ? appToken.asBinder() : null; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 2676 | mAppWindowToken.setOrientation(requestedOrientation, binder, this); |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 2677 | |
| 2678 | // Push the new configuration to the requested app in case where it's not pushed, e.g. when |
| 2679 | // the request is handled at task level with letterbox. |
| 2680 | if (!getMergedOverrideConfiguration().equals( |
| 2681 | mLastReportedConfiguration.getMergedConfiguration())) { |
| 2682 | ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */); |
| 2683 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | int getOrientation() { |
| 2687 | if (mAppWindowToken == null) { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2688 | return info.screenOrientation; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | return mAppWindowToken.getOrientationIgnoreVisibility(); |
| 2692 | } |
| 2693 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 2694 | void setDisablePreviewScreenshots(boolean disable) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 2695 | if (mAppWindowToken == null) { |
| 2696 | Slog.w(TAG_WM, "Attempted to set disable screenshots of non-existing app" |
| 2697 | + " token: " + appToken); |
| 2698 | return; |
| 2699 | } |
| 2700 | mAppWindowToken.setDisablePreviewScreenshots(disable); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2703 | /** |
| 2704 | * Set the last reported global configuration to the client. Should be called whenever a new |
| 2705 | * global configuration is sent to the client for this activity. |
| 2706 | */ |
| 2707 | void setLastReportedGlobalConfiguration(@NonNull Configuration config) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2708 | mLastReportedConfiguration.setGlobalConfiguration(config); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2711 | /** |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2712 | * Set the last reported configuration to the client. Should be called whenever |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2713 | * a new merged configuration is sent to the client for this activity. |
| 2714 | */ |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2715 | void setLastReportedConfiguration(@NonNull MergedConfiguration config) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2716 | setLastReportedConfiguration(config.getGlobalConfiguration(), |
| 2717 | config.getOverrideConfiguration()); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2718 | } |
| 2719 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2720 | private void setLastReportedConfiguration(Configuration global, Configuration override) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 2721 | mLastReportedConfiguration.setConfiguration(global, override); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2724 | /** |
| 2725 | * Get the configuration orientation by the requested screen orientation |
| 2726 | * ({@link ActivityInfo.ScreenOrientation}) of this activity. |
| 2727 | * |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 2728 | * @return orientation in ({@link Configuration#ORIENTATION_LANDSCAPE}, |
| 2729 | * {@link Configuration#ORIENTATION_PORTRAIT}, |
| 2730 | * {@link Configuration#ORIENTATION_UNDEFINED}). |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2731 | */ |
| 2732 | int getRequestedConfigurationOrientation() { |
| 2733 | final int screenOrientation = getOrientation(); |
| 2734 | if (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 2735 | // NOSENSOR means the display's "natural" orientation, so return that. |
| 2736 | final ActivityDisplay display = getDisplay(); |
| 2737 | if (display != null && display.mDisplayContent != null) { |
| 2738 | return display.mDisplayContent.getNaturalOrientation(); |
| 2739 | } |
| 2740 | } else if (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 2741 | // LOCKED means the activity's orientation remains unchanged, so return existing value. |
| 2742 | return getConfiguration().orientation; |
| 2743 | } else if (isFixedOrientationLandscape(screenOrientation)) { |
| 2744 | return ORIENTATION_LANDSCAPE; |
| 2745 | } else if (isFixedOrientationPortrait(screenOrientation)) { |
| 2746 | return ORIENTATION_PORTRAIT; |
| 2747 | } |
| 2748 | return ORIENTATION_UNDEFINED; |
| 2749 | } |
| 2750 | |
| 2751 | /** |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2752 | * @return {@code true} if this activity is in size compatibility mode that uses the different |
| 2753 | * density or bounds from its parent. |
| 2754 | */ |
| 2755 | boolean inSizeCompatMode() { |
| 2756 | if (!shouldUseSizeCompatMode()) { |
| 2757 | return false; |
| 2758 | } |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2759 | final Configuration resolvedConfig = getResolvedOverrideConfiguration(); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2760 | final Rect resolvedAppBounds = resolvedConfig.windowConfiguration.getAppBounds(); |
| 2761 | if (resolvedAppBounds == null) { |
| 2762 | // The override configuration has not been resolved yet. |
| 2763 | return false; |
| 2764 | } |
| 2765 | |
| 2766 | final Configuration parentConfig = getParent().getConfiguration(); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2767 | // Although colorMode, screenLayout, smallestScreenWidthDp are also fixed, generally these |
| 2768 | // fields should be changed with density and bounds, so here only compares the most |
| 2769 | // significant field. |
| 2770 | if (parentConfig.densityDpi != resolvedConfig.densityDpi) { |
| 2771 | return true; |
| 2772 | } |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2773 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2774 | final Rect parentAppBounds = parentConfig.windowConfiguration.getAppBounds(); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 2775 | final int appWidth = resolvedAppBounds.width(); |
| 2776 | final int appHeight = resolvedAppBounds.height(); |
| 2777 | final int parentAppWidth = parentAppBounds.width(); |
| 2778 | final int parentAppHeight = parentAppBounds.height(); |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 2779 | if (parentAppWidth == appWidth && parentAppHeight == appHeight) { |
| 2780 | // Matched the parent bounds. |
| 2781 | return false; |
| 2782 | } |
| 2783 | if (parentAppWidth > appWidth && parentAppHeight > appHeight) { |
| 2784 | // Both sides are smaller than the parent. |
| 2785 | return true; |
| 2786 | } |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 2787 | if (parentAppWidth < appWidth || parentAppHeight < appHeight) { |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2788 | // One side is larger than the parent. |
| 2789 | return true; |
| 2790 | } |
| 2791 | |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 2792 | // The rest of the condition is that only one side is smaller than the parent, but it still |
| 2793 | // needs to exclude the cases where the size is limited by the fixed aspect ratio. |
| 2794 | if (info.maxAspectRatio > 0) { |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 2795 | final float aspectRatio = (0.5f + Math.max(appWidth, appHeight)) |
| 2796 | / Math.min(appWidth, appHeight); |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 2797 | if (aspectRatio >= info.maxAspectRatio) { |
| 2798 | // The current size has reached the max aspect ratio. |
| 2799 | return false; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 2800 | } |
| 2801 | } |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 2802 | if (info.minAspectRatio > 0) { |
| 2803 | // The activity should have at least the min aspect ratio, so this checks if the parent |
| 2804 | // still has available space to provide larger aspect ratio. |
| 2805 | final float parentAspectRatio = (0.5f + Math.max(parentAppWidth, parentAppHeight)) |
| 2806 | / Math.min(parentAppWidth, parentAppHeight); |
| 2807 | if (parentAspectRatio <= info.minAspectRatio) { |
| 2808 | // The long side has reached the parent. |
| 2809 | return false; |
| 2810 | } |
| 2811 | } |
| 2812 | return true; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | /** |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2816 | * Indicates the activity will keep the bounds and screen configuration when it was first |
| 2817 | * launched, no matter how its parent changes. |
| 2818 | * |
| 2819 | * @return {@code true} if this activity is declared as non-resizable and fixed orientation or |
| 2820 | * aspect ratio. |
| 2821 | */ |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2822 | boolean shouldUseSizeCompatMode() { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2823 | return !isResizeable() && (info.isFixedOrientation() || info.hasFixedAspectRatio()) |
| 2824 | // The configuration of non-standard type should be enforced by system. |
| 2825 | && isActivityTypeStandard() |
| 2826 | && !mAtmService.mForceResizableActivities; |
| 2827 | } |
| 2828 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2829 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2830 | private void updateOverrideConfiguration() { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2831 | final Configuration overrideConfig = mTmpConfig; |
| 2832 | if (shouldUseSizeCompatMode()) { |
| 2833 | if (mCompatDisplayInsets != null) { |
| 2834 | // The override configuration is set only once in size compatibility mode. |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2835 | return; |
| 2836 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2837 | final Configuration parentConfig = getParent().getConfiguration(); |
| 2838 | if (!hasProcess() && !isConfigurationCompatible(parentConfig)) { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2839 | // Don't compute when launching in fullscreen and the fixed orientation is not the |
| 2840 | // current orientation. It is more accurately to compute the override bounds from |
| 2841 | // the updated configuration after the fixed orientation is applied. |
| 2842 | return; |
| 2843 | } |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2844 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2845 | // Ensure the screen related fields are set. It is used to prevent activity relaunch |
| 2846 | // when moving between displays. For screenWidthDp and screenWidthDp, because they |
| 2847 | // are relative to bounds and density, they will be calculated in |
| 2848 | // {@link TaskRecord#computeConfigResourceOverrides} and the result will also be |
| 2849 | // relatively fixed. |
| 2850 | overrideConfig.unset(); |
| 2851 | overrideConfig.colorMode = parentConfig.colorMode; |
| 2852 | overrideConfig.densityDpi = parentConfig.densityDpi; |
| 2853 | overrideConfig.screenLayout = parentConfig.screenLayout |
| 2854 | & (Configuration.SCREENLAYOUT_LONG_MASK |
| 2855 | | Configuration.SCREENLAYOUT_SIZE_MASK); |
| 2856 | // The smallest screen width is the short side of screen bounds. Because the bounds |
| 2857 | // and density won't be changed, smallestScreenWidthDp is also fixed. |
| 2858 | overrideConfig.smallestScreenWidthDp = parentConfig.smallestScreenWidthDp; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2859 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2860 | // The role of CompatDisplayInsets is like the override bounds. |
| 2861 | final ActivityDisplay display = getDisplay(); |
| 2862 | if (display != null && display.mDisplayContent != null) { |
| 2863 | mCompatDisplayInsets = new CompatDisplayInsets(display.mDisplayContent); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2864 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2865 | } else { |
| 2866 | // We must base this on the parent configuration, because we set our override |
| 2867 | // configuration's appBounds based on the result of this method. If we used our own |
| 2868 | // configuration, it would be influenced by past invocations. |
| 2869 | computeBounds(mTmpBounds, getParent().getWindowConfiguration().getAppBounds()); |
| 2870 | |
| 2871 | if (mTmpBounds.equals(getRequestedOverrideBounds())) { |
| 2872 | // The bounds is not changed or the activity is resizable (both the 2 bounds are |
| 2873 | // empty). |
| 2874 | return; |
| 2875 | } |
| 2876 | |
| 2877 | overrideConfig.unset(); |
| 2878 | overrideConfig.windowConfiguration.setBounds(mTmpBounds); |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 2879 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2880 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2881 | onRequestedOverrideConfigurationChanged(overrideConfig); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 2884 | @Override |
| 2885 | void resolveOverrideConfiguration(Configuration newParentConfiguration) { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2886 | if (mCompatDisplayInsets != null) { |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2887 | resolveSizeCompatModeConfiguration(newParentConfiguration); |
| 2888 | } else { |
| 2889 | super.resolveOverrideConfiguration(newParentConfiguration); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2890 | // If the activity has override bounds, the relative configuration (e.g. screen size, |
| 2891 | // layout) needs to be resolved according to the bounds. |
| 2892 | if (!matchParentBounds()) { |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2893 | task.computeConfigResourceOverrides(getResolvedOverrideConfiguration(), |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 2894 | newParentConfiguration); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2895 | } |
| 2896 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 2897 | |
| 2898 | // Assign configuration sequence number into hierarchy because there is a different way than |
| 2899 | // ensureActivityConfiguration() in this class that uses configuration in WindowState during |
| 2900 | // layout traversals. |
| 2901 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 2902 | getResolvedOverrideConfiguration().seq = mConfigurationSeq; |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2903 | } |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2904 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2905 | /** |
| 2906 | * Resolves consistent screen configuration for orientation and rotation changes without |
| 2907 | * inheriting the parent bounds. |
| 2908 | */ |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2909 | private void resolveSizeCompatModeConfiguration(Configuration newParentConfiguration) { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2910 | final Configuration resolvedConfig = getResolvedOverrideConfiguration(); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2911 | final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds(); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2912 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2913 | final int parentRotation = newParentConfiguration.windowConfiguration.getRotation(); |
| 2914 | final int parentOrientation = newParentConfiguration.orientation; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2915 | int orientation = getConfiguration().orientation; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2916 | if (orientation != parentOrientation && isConfigurationCompatible(newParentConfiguration)) { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2917 | // The activity is compatible to apply the orientation change or it requests different |
| 2918 | // fixed orientation. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2919 | orientation = parentOrientation; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2920 | } else { |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2921 | if (!resolvedBounds.isEmpty() |
| 2922 | // The decor insets may be different according to the rotation. |
| 2923 | && getWindowConfiguration().getRotation() == parentRotation) { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2924 | // Keep the computed resolved override configuration. |
| 2925 | return; |
| 2926 | } |
| 2927 | final int requestedOrientation = getRequestedConfigurationOrientation(); |
| 2928 | if (requestedOrientation != ORIENTATION_UNDEFINED) { |
| 2929 | orientation = requestedOrientation; |
| 2930 | } |
| 2931 | } |
| 2932 | |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2933 | super.resolveOverrideConfiguration(newParentConfiguration); |
| 2934 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2935 | boolean useParentOverrideBounds = false; |
| 2936 | final Rect displayBounds = mTmpBounds; |
| 2937 | final Rect containingAppBounds = new Rect(); |
| 2938 | if (task.handlesOrientationChangeFromDescendant()) { |
| 2939 | // Prefer to use the orientation which is determined by this activity to calculate |
| 2940 | // bounds because the parent will follow the requested orientation. |
| 2941 | mCompatDisplayInsets.getDisplayBoundsByOrientation(displayBounds, orientation); |
| 2942 | } else { |
| 2943 | // The parent hierarchy doesn't handle the orientation changes. This is usually because |
| 2944 | // the aspect ratio of display is close to square or the display rotation is fixed. |
| 2945 | // In this case, task will compute override bounds to fit the app with respect to the |
| 2946 | // requested orientation. So here we perform similar calculation to have consistent |
| 2947 | // bounds even the original parent hierarchies were changed. |
| 2948 | final int baseOrientation = task.getParent().getConfiguration().orientation; |
| 2949 | mCompatDisplayInsets.getDisplayBoundsByOrientation(displayBounds, baseOrientation); |
| 2950 | task.computeFullscreenBounds(containingAppBounds, this, displayBounds, baseOrientation); |
| 2951 | useParentOverrideBounds = !containingAppBounds.isEmpty(); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2952 | } |
| 2953 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2954 | // The offsets will be non-zero if the parent has override bounds. |
| 2955 | final int containingOffsetX = containingAppBounds.left; |
| 2956 | final int containingOffsetY = containingAppBounds.top; |
| 2957 | if (!useParentOverrideBounds) { |
| 2958 | containingAppBounds.set(displayBounds); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2959 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2960 | if (parentRotation != ROTATION_UNDEFINED) { |
| 2961 | // Ensure the container bounds won't overlap with the decors. |
| 2962 | TaskRecord.intersectWithInsetsIfFits(containingAppBounds, displayBounds, |
| 2963 | mCompatDisplayInsets.mNonDecorInsets[parentRotation]); |
| 2964 | } |
| 2965 | |
| 2966 | computeBounds(resolvedBounds, containingAppBounds); |
| 2967 | if (resolvedBounds.isEmpty()) { |
| 2968 | // Use the entire available bounds because there is no restriction. |
| 2969 | resolvedBounds.set(useParentOverrideBounds ? containingAppBounds : displayBounds); |
| 2970 | } else { |
| 2971 | // The offsets are included in width and height by {@link #computeBounds}, so we have to |
| 2972 | // restore it. |
| 2973 | resolvedBounds.left += containingOffsetX; |
| 2974 | resolvedBounds.top += containingOffsetY; |
| 2975 | } |
| 2976 | task.computeConfigResourceOverrides(resolvedConfig, newParentConfiguration, |
| 2977 | mCompatDisplayInsets); |
| 2978 | |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2979 | // The horizontal inset included in width is not needed if the activity cannot fill the |
| 2980 | // parent, because the offset will be applied by {@link AppWindowToken#mSizeCompatBounds}. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 2981 | final Rect resolvedAppBounds = resolvedConfig.windowConfiguration.getAppBounds(); |
| 2982 | final Rect parentAppBounds = newParentConfiguration.windowConfiguration.getAppBounds(); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2983 | if (resolvedBounds.width() < parentAppBounds.width()) { |
| 2984 | resolvedBounds.right -= resolvedAppBounds.left; |
| 2985 | } |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 2986 | // Use parent orientation if it cannot be decided by bounds, so the activity can fit inside |
| 2987 | // the parent bounds appropriately. |
| 2988 | if (resolvedConfig.screenWidthDp == resolvedConfig.screenHeightDp) { |
| 2989 | resolvedConfig.orientation = newParentConfiguration.orientation; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 2990 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | @Override |
| 2994 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 2995 | super.onConfigurationChanged(newParentConfig); |
| 2996 | |
| 2997 | // Configuration's equality doesn't consider seq so if only seq number changes in resolved |
| 2998 | // override configuration. Therefore ConfigurationContainer doesn't change merged override |
| 2999 | // configuration, but it's used to push configuration changes so explicitly update that. |
| 3000 | if (getMergedOverrideConfiguration().seq != getResolvedOverrideConfiguration().seq) { |
| 3001 | onMergedOverrideConfigurationChanged(); |
| 3002 | } |
| 3003 | |
| 3004 | // TODO(b/80414790): Remove code below after unification. |
| 3005 | // Same as above it doesn't notify configuration listeners, and consequently AppWindowToken |
| 3006 | // can't get updated seq number. However WindowState's merged override configuration needs |
| 3007 | // to have this seq number because that's also used for activity config pushes during layout |
| 3008 | // traversal. Therefore explicitly update them here. |
| 3009 | if (mAppWindowToken == null) { |
| 3010 | return; |
| 3011 | } |
| 3012 | final Configuration appWindowTokenRequestedOverrideConfig = |
| 3013 | mAppWindowToken.getRequestedOverrideConfiguration(); |
| 3014 | if (appWindowTokenRequestedOverrideConfig.seq != getResolvedOverrideConfiguration().seq) { |
| 3015 | appWindowTokenRequestedOverrideConfig.seq = |
| 3016 | getResolvedOverrideConfiguration().seq; |
| 3017 | mAppWindowToken.onMergedOverrideConfigurationChanged(); |
| 3018 | } |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 3019 | |
| 3020 | final ActivityDisplay display = getDisplay(); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 3021 | if (display == null) { |
| 3022 | return; |
| 3023 | } |
| 3024 | if (visible) { |
| 3025 | // It may toggle the UI for user to restart the size compatibility mode activity. |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 3026 | display.handleActivitySizeCompatModeIfNeeded(this); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 3027 | } else if (shouldUseSizeCompatMode()) { |
| 3028 | // The override changes can only be obtained from display, because we don't have the |
| 3029 | // difference of full configuration in each hierarchy. |
| 3030 | final int displayChanges = display.getLastOverrideConfigurationChanges(); |
| 3031 | final int orientationChanges = CONFIG_WINDOW_CONFIGURATION |
| 3032 | | CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION; |
| 3033 | final boolean hasNonOrienSizeChanged = hasResizeChange(displayChanges) |
| 3034 | // Filter out the case of simple orientation change. |
| 3035 | && (displayChanges & orientationChanges) != orientationChanges; |
| 3036 | // For background activity that uses size compatibility mode, if the size or density of |
| 3037 | // the display is changed, then reset the override configuration and kill the activity's |
| 3038 | // process if its process state is not important to user. |
| 3039 | if (hasNonOrienSizeChanged || (displayChanges & ActivityInfo.CONFIG_DENSITY) != 0) { |
| 3040 | restartProcessIfVisible(); |
| 3041 | } |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 3042 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 3043 | } |
| 3044 | |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 3045 | /** Returns true if the configuration is compatible with this activity. */ |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 3046 | boolean isConfigurationCompatible(Configuration config) { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 3047 | final int orientation = getOrientation(); |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 3048 | if (isFixedOrientationPortrait(orientation) |
| 3049 | && config.orientation != ORIENTATION_PORTRAIT) { |
| 3050 | return false; |
| 3051 | } |
| 3052 | if (isFixedOrientationLandscape(orientation) |
| 3053 | && config.orientation != ORIENTATION_LANDSCAPE) { |
| 3054 | return false; |
| 3055 | } |
| 3056 | return true; |
| 3057 | } |
| 3058 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 3059 | /** |
| 3060 | * Computes the bounds to fit the Activity within the bounds of the {@link Configuration}. |
| 3061 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3062 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3063 | private void computeBounds(Rect outBounds, Rect containingAppBounds) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3064 | outBounds.setEmpty(); |
| 3065 | final float maxAspectRatio = info.maxAspectRatio; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3066 | final ActivityStack stack = getActivityStack(); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3067 | final float minAspectRatio = info.minAspectRatio; |
| 3068 | |
| 3069 | if (task == null || stack == null || task.inMultiWindowMode() |
| 3070 | || (maxAspectRatio == 0 && minAspectRatio == 0) |
Bryce Lee | e5ab450 | 2017-07-11 08:58:05 -0700 | [diff] [blame] | 3071 | || isInVrUiMode(getConfiguration())) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3072 | // We don't set override configuration if that activity task isn't fullscreen. I.e. the |
| 3073 | // activity is in multi-window mode. Or, there isn't a max aspect ratio specified for |
Bryce Lee | e5ab450 | 2017-07-11 08:58:05 -0700 | [diff] [blame] | 3074 | // the activity. This is indicated by an empty {@link outBounds}. We also don't set it |
| 3075 | // if we are in VR mode. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3076 | return; |
| 3077 | } |
| 3078 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3079 | final int containingAppWidth = containingAppBounds.width(); |
| 3080 | final int containingAppHeight = containingAppBounds.height(); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3081 | final float containingRatio = Math.max(containingAppWidth, containingAppHeight) |
| 3082 | / (float) Math.min(containingAppWidth, containingAppHeight); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 3083 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3084 | int activityWidth = containingAppWidth; |
| 3085 | int activityHeight = containingAppHeight; |
| 3086 | |
| 3087 | if (containingRatio > maxAspectRatio && maxAspectRatio != 0) { |
| 3088 | if (containingAppWidth < containingAppHeight) { |
| 3089 | // Width is the shorter side, so we use that to figure-out what the max. height |
| 3090 | // should be given the aspect ratio. |
| 3091 | activityHeight = (int) ((activityWidth * maxAspectRatio) + 0.5f); |
| 3092 | } else { |
| 3093 | // Height is the shorter side, so we use that to figure-out what the max. width |
| 3094 | // should be given the aspect ratio. |
| 3095 | activityWidth = (int) ((activityHeight * maxAspectRatio) + 0.5f); |
| 3096 | } |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 3097 | } else if (containingRatio < minAspectRatio) { |
| 3098 | boolean adjustWidth; |
| 3099 | switch (getRequestedConfigurationOrientation()) { |
| 3100 | case ORIENTATION_LANDSCAPE: |
| 3101 | // Width should be the longer side for this landscape app, so we use the width |
| 3102 | // to figure-out what the max. height should be given the aspect ratio. |
| 3103 | adjustWidth = false; |
| 3104 | break; |
| 3105 | case ORIENTATION_PORTRAIT: |
| 3106 | // Height should be the longer side for this portrait app, so we use the height |
| 3107 | // to figure-out what the max. width should be given the aspect ratio. |
| 3108 | adjustWidth = true; |
| 3109 | break; |
| 3110 | default: |
| 3111 | // This app doesn't have a preferred orientation, so we keep the length of the |
| 3112 | // longer side, and use it to figure-out the length of the shorter side. |
| 3113 | if (containingAppWidth < containingAppHeight) { |
| 3114 | // Width is the shorter side, so we use the height to figure-out what the |
| 3115 | // max. width should be given the aspect ratio. |
| 3116 | adjustWidth = true; |
| 3117 | } else { |
| 3118 | // Height is the shorter side, so we use the width to figure-out what the |
| 3119 | // max. height should be given the aspect ratio. |
| 3120 | adjustWidth = false; |
| 3121 | } |
| 3122 | break; |
| 3123 | } |
| 3124 | if (adjustWidth) { |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3125 | activityWidth = (int) ((activityHeight / minAspectRatio) + 0.5f); |
| 3126 | } else { |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3127 | activityHeight = (int) ((activityWidth / minAspectRatio) + 0.5f); |
| 3128 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3131 | if (containingAppWidth <= activityWidth && containingAppHeight <= activityHeight) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3132 | // The display matches or is less than the activity aspect ratio, so nothing else to do. |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 3133 | // Return the existing bounds. If this method is running for the first time, |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 3134 | // {@link #getRequestedOverrideBounds()} will be empty (representing no override). If |
| 3135 | // the method has run before, then effect of {@link #getRequestedOverrideBounds()} will |
| 3136 | // already have been applied to the value returned from {@link getConfiguration}. Refer |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 3137 | // to {@link TaskRecord#computeConfigResourceOverrides()}. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 3138 | outBounds.set(getRequestedOverrideBounds()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3139 | return; |
| 3140 | } |
| 3141 | |
| 3142 | // Compute configuration based on max supported width and height. |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 3143 | // Also account for the left / top insets (e.g. from display cutouts), which will be clipped |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 3144 | // away later in {@link TaskRecord#computeConfigResourceOverrides()}. Otherwise, the app |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 3145 | // bounds would end up too small. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3146 | outBounds.set(0, 0, activityWidth + containingAppBounds.left, |
| 3147 | activityHeight + containingAppBounds.top); |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 3150 | /** |
| 3151 | * @return {@code true} if this activity was reparented to another display but |
| 3152 | * {@link #ensureActivityConfiguration} is not called. |
| 3153 | */ |
| 3154 | boolean shouldUpdateConfigForDisplayChanged() { |
| 3155 | return mLastReportedDisplayId != getDisplayId(); |
| 3156 | } |
| 3157 | |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 3158 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow) { |
| 3159 | return ensureActivityConfiguration(globalChanges, preserveWindow, |
| 3160 | false /* ignoreStopState */); |
| 3161 | } |
| 3162 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3163 | /** |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 3164 | * Make sure the given activity matches the current configuration. Ensures the HistoryRecord |
| 3165 | * is updated with the correct configuration and all other bookkeeping is handled. |
| 3166 | * |
| 3167 | * @param globalChanges The changes to the global configuration. |
| 3168 | * @param preserveWindow If the activity window should be preserved on screen if the activity |
| 3169 | * is relaunched. |
| 3170 | * @param ignoreStopState If we should try to relaunch the activity even if it is in the stopped |
| 3171 | * state. This is useful for the case where we know the activity will be |
| 3172 | * visible soon and we want to ensure its configuration before we make it |
| 3173 | * visible. |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 3174 | * @return False if the activity was relaunched and true if it wasn't relaunched because we |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 3175 | * can't or the app handles the specific configuration that is changing. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3176 | */ |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 3177 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow, |
| 3178 | boolean ignoreStopState) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3179 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3180 | if (stack.mConfigWillChange) { |
| 3181 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3182 | "Skipping config check (will change): " + this); |
| 3183 | return true; |
| 3184 | } |
| 3185 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3186 | // We don't worry about activities that are finishing. |
| 3187 | if (finishing) { |
| 3188 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3189 | "Configuration doesn't matter in finishing " + this); |
| 3190 | stopFreezingScreenLocked(false); |
| 3191 | return true; |
| 3192 | } |
| 3193 | |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 3194 | if (!ignoreStopState && (mState == STOPPING || mState == STOPPED)) { |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 3195 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3196 | "Skipping config check stopped or stopping: " + this); |
| 3197 | return true; |
| 3198 | } |
| 3199 | |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 3200 | if (!shouldBeVisible()) { |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 3201 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3202 | "Skipping config check invisible stack: " + this); |
| 3203 | return true; |
| 3204 | } |
| 3205 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3206 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3207 | "Ensuring correct configuration: " + this); |
| 3208 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3209 | final int newDisplayId = getDisplayId(); |
| 3210 | final boolean displayChanged = mLastReportedDisplayId != newDisplayId; |
| 3211 | if (displayChanged) { |
| 3212 | mLastReportedDisplayId = newDisplayId; |
| 3213 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3214 | // TODO(b/36505427): Is there a better place to do this? |
| 3215 | updateOverrideConfiguration(); |
| 3216 | |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 3217 | // Short circuit: if the two full configurations are equal (the common case), then there is |
| 3218 | // nothing to do. We test the full configuration instead of the global and merged override |
| 3219 | // configurations because there are cases (like moving a task to the pinned stack) where |
| 3220 | // the combine configurations are equal, but would otherwise differ in the override config |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 3221 | mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration()); |
| 3222 | if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3223 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3224 | "Configuration & display unchanged in " + this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3225 | return true; |
| 3226 | } |
| 3227 | |
| 3228 | // Okay we now are going to make this activity have the new config. |
| 3229 | // But then we need to figure out how it needs to deal with that. |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 3230 | |
| 3231 | // Find changes between last reported merged configuration and the current one. This is used |
| 3232 | // to decide whether to relaunch an activity or just report a configuration change. |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 3233 | final int changes = getConfigurationChanges(mTmpConfig); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 3234 | |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 3235 | // Update last reported values. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3236 | final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration(); |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 3237 | |
Andrii Kulian | beadacc | 2019-05-20 12:18:01 +0000 | [diff] [blame] | 3238 | setLastReportedConfiguration(mAtmService.getGlobalConfiguration(), newMergedOverrideConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3239 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3240 | if (mState == INITIALIZING) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3241 | // No need to relaunch or schedule new config for activity that hasn't been launched |
| 3242 | // yet. We do, however, return after applying the config to activity record, so that |
| 3243 | // it will use it for launch transaction. |
| 3244 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3245 | "Skipping config check for initializing activity: " + this); |
| 3246 | return true; |
| 3247 | } |
| 3248 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3249 | if (changes == 0 && !forceNewConfig) { |
| 3250 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3251 | "Configuration no differences in " + this); |
| 3252 | // There are no significant differences, so we won't relaunch but should still deliver |
| 3253 | // the new configuration to the client process. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3254 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3255 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3256 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3257 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3258 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3259 | return true; |
| 3260 | } |
| 3261 | |
| 3262 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 3263 | "Configuration changes for " + this + ", allChanges=" |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3264 | + Configuration.configurationDiffToString(changes)); |
| 3265 | |
| 3266 | // If the activity isn't currently running, just leave the new configuration and it will |
| 3267 | // pick that up next time it starts. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3268 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3269 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3270 | "Configuration doesn't matter not running " + this); |
| 3271 | stopFreezingScreenLocked(false); |
| 3272 | forceNewConfig = false; |
| 3273 | return true; |
| 3274 | } |
| 3275 | |
| 3276 | // Figure out how to handle the changes between the configurations. |
| 3277 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3278 | "Checking to restart " + info.name + ": changed=0x" |
| 3279 | + Integer.toHexString(changes) + ", handles=0x" |
| 3280 | + Integer.toHexString(info.getRealConfigChanged()) |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 3281 | + ", mLastReportedConfiguration=" + mLastReportedConfiguration); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3282 | |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 3283 | if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3284 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 3285 | configChangeFlags |= changes; |
| 3286 | startFreezingScreenLocked(app, globalChanges); |
| 3287 | forceNewConfig = false; |
| 3288 | preserveWindow &= isResizeOnlyChange(changes); |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 3289 | final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged()); |
| 3290 | if (hasResizeChange) { |
| 3291 | final boolean isDragResizing = |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 3292 | getTaskRecord().getTask().isDragResizing(); |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 3293 | mRelaunchReason = isDragResizing ? RELAUNCH_REASON_FREE_RESIZE |
| 3294 | : RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 3295 | } else { |
| 3296 | mRelaunchReason = RELAUNCH_REASON_NONE; |
| 3297 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3298 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3299 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3300 | "Config is destroying non-running " + this); |
| 3301 | stack.destroyActivityLocked(this, true, "config"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3302 | } else if (mState == PAUSING) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3303 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 3304 | // do anything now, but just flag that it needs to be restarted when done pausing. |
| 3305 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3306 | "Config is skipping already pausing " + this); |
| 3307 | deferRelaunchUntilPaused = true; |
| 3308 | preserveWindowOnDeferredRelaunch = preserveWindow; |
| 3309 | return true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3310 | } else if (mState == RESUMED) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3311 | // Try to optimize this case: the configuration is changing and we need to restart |
| 3312 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
| 3313 | // "restart!". |
| 3314 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3315 | "Config is relaunching resumed " + this); |
| 3316 | |
| 3317 | if (DEBUG_STATES && !visible) { |
| 3318 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this |
| 3319 | + " called by " + Debug.getCallers(4)); |
| 3320 | } |
| 3321 | |
| 3322 | relaunchActivityLocked(true /* andResume */, preserveWindow); |
| 3323 | } else { |
| 3324 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 3325 | "Config is relaunching non-resumed " + this); |
| 3326 | relaunchActivityLocked(false /* andResume */, preserveWindow); |
| 3327 | } |
| 3328 | |
| 3329 | // All done... tell the caller we weren't able to keep this activity around. |
| 3330 | return false; |
| 3331 | } |
| 3332 | |
| 3333 | // Default case: the activity can handle this new configuration, so hand it over. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3334 | // NOTE: We only forward the override configuration as the system level configuration |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3335 | // changes is always sent to all processes when they happen so it can just use whatever |
| 3336 | // system level configuration it last got. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3337 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3338 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3339 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3340 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3341 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3342 | stopFreezingScreenLocked(false); |
| 3343 | |
| 3344 | return true; |
| 3345 | } |
| 3346 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3347 | /** |
| 3348 | * When assessing a configuration change, decide if the changes flags and the new configurations |
| 3349 | * should cause the Activity to relaunch. |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 3350 | * |
| 3351 | * @param changes the changes due to the given configuration. |
| 3352 | * @param changesConfig the configuration that was used to calculate the given changes via a |
| 3353 | * call to getConfigurationChanges. |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3354 | */ |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 3355 | private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3356 | int configChanged = info.getRealConfigChanged(); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 3357 | boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig); |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3358 | |
| 3359 | // Override for apps targeting pre-O sdks |
| 3360 | // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode |
| 3361 | // to the config change. |
| 3362 | // For O and later, apps will be required to add configChanges="uimode" to their manifest. |
| 3363 | if (appInfo.targetSdkVersion < O |
| 3364 | && requestedVrComponent != null |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 3365 | && onlyVrUiModeChanged) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3366 | configChanged |= CONFIG_UI_MODE; |
| 3367 | } |
| 3368 | |
| 3369 | return (changes&(~configChanged)) != 0; |
| 3370 | } |
| 3371 | |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 3372 | /** |
| 3373 | * Returns true if the configuration change is solely due to the UI mode switching into or out |
| 3374 | * of UI_MODE_TYPE_VR_HEADSET. |
| 3375 | */ |
| 3376 | private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) { |
| 3377 | final Configuration currentConfig = getConfiguration(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3378 | return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig) |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 3379 | != isInVrUiMode(lastReportedConfig)); |
| 3380 | } |
| 3381 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3382 | private int getConfigurationChanges(Configuration lastReportedConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3383 | // Determine what has changed. May be nothing, if this is a config that has come back from |
| 3384 | // the app after going idle. In that case we just want to leave the official config object |
| 3385 | // now in the activity and do nothing else. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3386 | final Configuration currentConfig = getConfiguration(); |
| 3387 | int changes = lastReportedConfig.diff(currentConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3388 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 3389 | // the app. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3390 | if ((changes & CONFIG_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 3391 | final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp, |
| 3392 | currentConfig.screenWidthDp) |
| 3393 | || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp, |
| 3394 | currentConfig.screenHeightDp); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3395 | if (!crosses) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3396 | changes &= ~CONFIG_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3397 | } |
| 3398 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3399 | if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 3400 | final int oldSmallest = lastReportedConfig.smallestScreenWidthDp; |
| 3401 | final int newSmallest = currentConfig.smallestScreenWidthDp; |
| 3402 | if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3403 | changes &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3404 | } |
| 3405 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 3406 | // We don't want window configuration to cause relaunches. |
| 3407 | if ((changes & CONFIG_WINDOW_CONFIGURATION) != 0) { |
| 3408 | changes &= ~CONFIG_WINDOW_CONFIGURATION; |
| 3409 | } |
Bryce Lee | 600dadd | 2017-07-25 10:48:42 -0700 | [diff] [blame] | 3410 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3411 | return changes; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | private static boolean isResizeOnlyChange(int change) { |
| 3415 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 3416 | | CONFIG_SCREEN_LAYOUT)) == 0; |
| 3417 | } |
| 3418 | |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 3419 | private static boolean hasResizeChange(int change) { |
| 3420 | return (change & (CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 3421 | | CONFIG_SCREEN_LAYOUT)) != 0; |
| 3422 | } |
| 3423 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3424 | void relaunchActivityLocked(boolean andResume, boolean preserveWindow) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3425 | if (mAtmService.mSuppressResizeConfigChanges && preserveWindow) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3426 | configChangeFlags = 0; |
| 3427 | return; |
| 3428 | } |
| 3429 | |
| 3430 | List<ResultInfo> pendingResults = null; |
| 3431 | List<ReferrerIntent> pendingNewIntents = null; |
| 3432 | if (andResume) { |
| 3433 | pendingResults = results; |
| 3434 | pendingNewIntents = newIntents; |
| 3435 | } |
| 3436 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3437 | "Relaunching: " + this + " with results=" + pendingResults |
| 3438 | + " newIntents=" + pendingNewIntents + " andResume=" + andResume |
| 3439 | + " preserveWindow=" + preserveWindow); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3440 | EventLog.writeEvent(andResume ? AM_RELAUNCH_RESUME_ACTIVITY |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3441 | : AM_RELAUNCH_ACTIVITY, mUserId, System.identityHashCode(this), |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3442 | task.taskId, shortComponentName); |
| 3443 | |
| 3444 | startFreezingScreenLocked(app, 0); |
| 3445 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3446 | try { |
| 3447 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 3448 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this |
| 3449 | + " callers=" + Debug.getCallers(6)); |
| 3450 | forceNewConfig = false; |
| 3451 | mStackSupervisor.activityRelaunchingLocked(this); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3452 | final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(pendingResults, |
| 3453 | pendingNewIntents, configChangeFlags, |
Andrii Kulian | beadacc | 2019-05-20 12:18:01 +0000 | [diff] [blame] | 3454 | new MergedConfiguration(mAtmService.getGlobalConfiguration(), |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3455 | getMergedOverrideConfiguration()), |
| 3456 | preserveWindow); |
| 3457 | final ActivityLifecycleItem lifecycleItem; |
| 3458 | if (andResume) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3459 | lifecycleItem = ResumeActivityItem.obtain( |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3460 | getDisplay().mDisplayContent.isNextTransitionForward()); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3461 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 3462 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3463 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3464 | final ClientTransaction transaction = ClientTransaction.obtain(app.getThread(), appToken); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3465 | transaction.addCallback(callbackItem); |
| 3466 | transaction.setLifecycleStateRequest(lifecycleItem); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3467 | mAtmService.getLifecycleManager().scheduleTransaction(transaction); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3468 | // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3469 | // request resume if this activity is currently resumed, which implies we aren't |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3470 | // sleeping. |
| 3471 | } catch (RemoteException e) { |
| 3472 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
| 3473 | } |
| 3474 | |
| 3475 | if (andResume) { |
| 3476 | if (DEBUG_STATES) { |
| 3477 | Slog.d(TAG_STATES, "Resumed after relaunch " + this); |
| 3478 | } |
| 3479 | results = null; |
| 3480 | newIntents = null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3481 | mAtmService.getAppWarningsLocked().onResumeActivity(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3482 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3483 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 3484 | if (stack != null) { |
| 3485 | stack.mHandler.removeMessages(PAUSE_TIMEOUT_MSG, this); |
| 3486 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3487 | setState(PAUSED, "relaunchActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | configChangeFlags = 0; |
| 3491 | deferRelaunchUntilPaused = false; |
| 3492 | preserveWindowOnDeferredRelaunch = false; |
| 3493 | } |
| 3494 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 3495 | /** |
| 3496 | * Request the process of the activity to restart with its saved state (from |
| 3497 | * {@link android.app.Activity#onSaveInstanceState}) if possible. It also forces to recompute |
| 3498 | * the override configuration. Note if the activity is in background, the process will be killed |
| 3499 | * directly with keeping its record. |
| 3500 | */ |
| 3501 | void restartProcessIfVisible() { |
| 3502 | Slog.i(TAG, "Request to restart process of " + this); |
| 3503 | |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 3504 | // Reset the existing override configuration so it can be updated according to the latest |
| 3505 | // configuration. |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3506 | getRequestedOverrideConfiguration().unset(); |
| 3507 | getResolvedOverrideConfiguration().unset(); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3508 | mCompatDisplayInsets = null; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 3509 | if (visible) { |
| 3510 | // Configuration will be ensured when becoming visible, so if it is already visible, |
| 3511 | // then the manual update is needed. |
| 3512 | updateOverrideConfiguration(); |
| 3513 | } |
| 3514 | |
| 3515 | if (!attachedToProcess()) { |
| 3516 | return; |
| 3517 | } |
| 3518 | |
| 3519 | // The restarting state avoids removing this record when process is died. |
| 3520 | setState(RESTARTING_PROCESS, "restartActivityProcess"); |
| 3521 | |
| 3522 | if (!visible || haveState) { |
| 3523 | // Kill its process immediately because the activity should be in background. |
| 3524 | // The activity state will be update to {@link #DESTROYED} in |
| 3525 | // {@link ActivityStack#cleanUpActivityLocked} when handling process died. |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 3526 | mAtmService.mH.post(() -> { |
| 3527 | final WindowProcessController wpc; |
| 3528 | synchronized (mAtmService.mGlobalLock) { |
| 3529 | if (!hasProcess() |
| 3530 | || app.getReportedProcState() <= PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 3531 | return; |
| 3532 | } |
| 3533 | wpc = app; |
| 3534 | } |
| 3535 | mAtmService.mAmInternal.killProcess(wpc.mName, wpc.mUid, "resetConfig"); |
| 3536 | }); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 3537 | return; |
| 3538 | } |
| 3539 | |
| 3540 | if (mAppWindowToken != null) { |
| 3541 | mAppWindowToken.startFreezingScreen(); |
| 3542 | } |
| 3543 | // The process will be killed until the activity reports stopped with saved state (see |
| 3544 | // {@link ActivityTaskManagerService.activityStopped}). |
| 3545 | try { |
| 3546 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 3547 | StopActivityItem.obtain(false /* showWindow */, 0 /* configChanges */)); |
| 3548 | } catch (RemoteException e) { |
| 3549 | Slog.w(TAG, "Exception thrown during restart " + this, e); |
| 3550 | } |
| 3551 | mStackSupervisor.scheduleRestartTimeout(this); |
| 3552 | } |
| 3553 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 3554 | private boolean isProcessRunning() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3555 | WindowProcessController proc = app; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3556 | if (proc == null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3557 | proc = mAtmService.mProcessNames.get(processName, info.applicationInfo.uid); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3558 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3559 | return proc != null && proc.hasThread(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3560 | } |
| 3561 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 3562 | /** |
| 3563 | * @return Whether a task snapshot starting window may be shown. |
| 3564 | */ |
| 3565 | private boolean allowTaskSnapshot() { |
| 3566 | if (newIntents == null) { |
| 3567 | return true; |
| 3568 | } |
| 3569 | |
| 3570 | // Restrict task snapshot starting window to launcher start, or there is no intent at all |
| 3571 | // (eg. task being brought to front). If the intent is something else, likely the app is |
| 3572 | // going to show some specific page or view, instead of what's left last time. |
| 3573 | for (int i = newIntents.size() - 1; i >= 0; i--) { |
| 3574 | final Intent intent = newIntents.get(i); |
| 3575 | if (intent != null && !ActivityRecord.isMainIntent(intent)) { |
| 3576 | return false; |
| 3577 | } |
| 3578 | } |
| 3579 | return true; |
| 3580 | } |
| 3581 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3582 | /** |
| 3583 | * Returns {@code true} if the associated activity has the no history flag set on it. |
| 3584 | * {@code false} otherwise. |
| 3585 | */ |
| 3586 | boolean isNoHistory() { |
| 3587 | return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3588 | || (info.flags & FLAG_NO_HISTORY) != 0; |
| 3589 | } |
| 3590 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3591 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 3592 | out.attribute(null, ATTR_ID, String.valueOf(createTime)); |
| 3593 | out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid)); |
| 3594 | if (launchedFromPackage != null) { |
| 3595 | out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage); |
| 3596 | } |
| 3597 | if (resolvedType != null) { |
| 3598 | out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType); |
| 3599 | } |
| 3600 | out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified)); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3601 | out.attribute(null, ATTR_USERID, String.valueOf(mUserId)); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3602 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3603 | if (taskDescription != null) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 3604 | taskDescription.saveToXml(out); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | out.startTag(null, TAG_INTENT); |
| 3608 | intent.saveToXml(out); |
| 3609 | out.endTag(null, TAG_INTENT); |
| 3610 | |
| 3611 | if (isPersistable() && persistentState != null) { |
| 3612 | out.startTag(null, TAG_PERSISTABLEBUNDLE); |
| 3613 | persistentState.saveToXml(out); |
| 3614 | out.endTag(null, TAG_PERSISTABLEBUNDLE); |
| 3615 | } |
| 3616 | } |
| 3617 | |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 3618 | static ActivityRecord restoreFromXml(XmlPullParser in, |
| 3619 | ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3620 | Intent intent = null; |
| 3621 | PersistableBundle persistentState = null; |
| 3622 | int launchedFromUid = 0; |
| 3623 | String launchedFromPackage = null; |
| 3624 | String resolvedType = null; |
| 3625 | boolean componentSpecified = false; |
| 3626 | int userId = 0; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3627 | long createTime = -1; |
| 3628 | final int outerDepth = in.getDepth(); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3629 | TaskDescription taskDescription = new TaskDescription(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3630 | |
| 3631 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 3632 | final String attrName = in.getAttributeName(attrNdx); |
| 3633 | final String attrValue = in.getAttributeValue(attrNdx); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3634 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3635 | "ActivityRecord: attribute name=" + attrName + " value=" + attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3636 | if (ATTR_ID.equals(attrName)) { |
Tobias Thierer | 28532d0 | 2016-04-21 14:52:10 +0100 | [diff] [blame] | 3637 | createTime = Long.parseLong(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3638 | } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3639 | launchedFromUid = Integer.parseInt(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3640 | } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) { |
| 3641 | launchedFromPackage = attrValue; |
| 3642 | } else if (ATTR_RESOLVEDTYPE.equals(attrName)) { |
| 3643 | resolvedType = attrValue; |
| 3644 | } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) { |
Tobias Thierer | b0800dc | 2016-04-21 17:51:41 +0100 | [diff] [blame] | 3645 | componentSpecified = Boolean.parseBoolean(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3646 | } else if (ATTR_USERID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3647 | userId = Integer.parseInt(attrValue); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3648 | } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 3649 | taskDescription.restoreFromXml(attrName, attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3650 | } else { |
| 3651 | Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName); |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | int event; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3656 | while (((event = in.next()) != END_DOCUMENT) && |
| 3657 | (event != END_TAG || in.getDepth() >= outerDepth)) { |
| 3658 | if (event == START_TAG) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3659 | final String name = in.getName(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3660 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3661 | Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3662 | if (TAG_INTENT.equals(name)) { |
| 3663 | intent = Intent.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3664 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3665 | Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3666 | } else if (TAG_PERSISTABLEBUNDLE.equals(name)) { |
| 3667 | persistentState = PersistableBundle.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3668 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3669 | "ActivityRecord: persistentState=" + persistentState); |
| 3670 | } else { |
| 3671 | Slog.w(TAG, "restoreActivity: unexpected name=" + name); |
| 3672 | XmlUtils.skipCurrentTag(in); |
| 3673 | } |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | if (intent == null) { |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3678 | throw new XmlPullParserException("restoreActivity error intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3679 | } |
| 3680 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3681 | final ActivityTaskManagerService service = stackSupervisor.mService; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3682 | final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 3683 | userId, Binder.getCallingUid()); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3684 | if (aInfo == null) { |
Craig Mautner | 77b0426 | 2014-06-27 15:22:12 -0700 | [diff] [blame] | 3685 | throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent + |
| 3686 | " resolvedType=" + resolvedType); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 3687 | } |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3688 | final ActivityRecord r = new ActivityRecord(service, null /* caller */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3689 | 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3690 | aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 3691 | 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */, |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3692 | stackSupervisor, null /* options */, null /* sourceRecord */); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3693 | |
| 3694 | r.persistentState = persistentState; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 3695 | r.taskDescription = taskDescription; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3696 | r.createTime = createTime; |
| 3697 | |
| 3698 | return r; |
| 3699 | } |
| 3700 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3701 | private static boolean isInVrUiMode(Configuration config) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3702 | return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 3703 | } |
| 3704 | |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 3705 | int getUid() { |
| 3706 | return info.applicationInfo.uid; |
| 3707 | } |
| 3708 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3709 | void setShowWhenLocked(boolean showWhenLocked) { |
| 3710 | mShowWhenLocked = showWhenLocked; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3711 | mRootActivityContainer.ensureActivitiesVisible(null, 0 /* configChanges */, |
Kevin Chyn | 4463948 | 2017-10-09 18:34:41 -0700 | [diff] [blame] | 3712 | false /* preserveWindows */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 3715 | void setInheritShowWhenLocked(boolean inheritShowWhenLocked) { |
| 3716 | mInheritShownWhenLocked = inheritShowWhenLocked; |
| 3717 | mRootActivityContainer.ensureActivitiesVisible(null, 0, false); |
| 3718 | } |
| 3719 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3720 | /** |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 3721 | * @return true if the activity windowing mode is not |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 3722 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_PINNED} and a) activity |
| 3723 | * contains windows that have {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the |
| 3724 | * activity has set {@link #mShowWhenLocked}, or b) if the activity has set |
| 3725 | * {@link #mInheritShownWhenLocked} and the activity behind this satisfies the |
| 3726 | * conditions a) above. |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 3727 | * Multi-windowing mode will be exited if true is returned. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3728 | */ |
| 3729 | boolean canShowWhenLocked() { |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 3730 | if (!inPinnedWindowingMode() && (mShowWhenLocked |
| 3731 | || (mAppWindowToken != null && mAppWindowToken.containsShowWhenLockedWindow()))) { |
| 3732 | return true; |
| 3733 | } else if (mInheritShownWhenLocked) { |
| 3734 | ActivityRecord r = getActivityBelow(); |
| 3735 | return r != null && !r.inPinnedWindowingMode() && (r.mShowWhenLocked |
| 3736 | || (r.mAppWindowToken != null |
| 3737 | && r.mAppWindowToken.containsShowWhenLockedWindow())); |
| 3738 | } else { |
| 3739 | return false; |
| 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | /** |
| 3744 | * @return an {@link ActivityRecord} of the activity below this activity, or {@code null} if no |
| 3745 | * such activity exists. |
| 3746 | */ |
| 3747 | @Nullable |
| 3748 | private ActivityRecord getActivityBelow() { |
| 3749 | final int pos = task.mActivities.indexOf(this); |
| 3750 | if (pos == -1) { |
| 3751 | throw new IllegalStateException("Activity not found in its task"); |
| 3752 | } |
| 3753 | return pos == 0 ? null : task.getChildAt(pos - 1); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | void setTurnScreenOn(boolean turnScreenOn) { |
| 3757 | mTurnScreenOn = turnScreenOn; |
| 3758 | } |
| 3759 | |
| 3760 | /** |
| 3761 | * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag |
| 3762 | * {@link #mTurnScreenOn} is set and checks whether the ActivityRecord should be visible |
| 3763 | * depending on Keyguard state |
| 3764 | * |
| 3765 | * @return true if the screen can be turned on, false otherwise. |
| 3766 | */ |
| 3767 | boolean canTurnScreenOn() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3768 | final ActivityStack stack = getActivityStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3769 | return mTurnScreenOn && stack != null && |
| 3770 | stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */); |
| 3771 | } |
| 3772 | |
Louis Chang | 77ce34d | 2019-01-03 15:45:12 +0800 | [diff] [blame] | 3773 | /** |
| 3774 | * Check if this activity is able to resume. For pre-Q apps, only the topmost activities of each |
| 3775 | * process are allowed to be resumed. |
| 3776 | * |
| 3777 | * @return true if this activity can be resumed. |
| 3778 | */ |
| 3779 | boolean canResumeByCompat() { |
| 3780 | return app == null || app.updateTopResumingActivityInProcessIfNeeded(this); |
| 3781 | } |
| 3782 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3783 | boolean getTurnScreenOnFlag() { |
| 3784 | return mTurnScreenOn; |
| 3785 | } |
| 3786 | |
| 3787 | boolean isTopRunningActivity() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3788 | return mRootActivityContainer.topRunningActivity() == this; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 3789 | } |
| 3790 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 3791 | /** |
| 3792 | * @return {@code true} if this is the resumed activity on its current display, {@code false} |
| 3793 | * otherwise. |
| 3794 | */ |
| 3795 | boolean isResumedActivityOnDisplay() { |
| 3796 | final ActivityDisplay display = getDisplay(); |
| 3797 | return display != null && this == display.getResumedActivity(); |
| 3798 | } |
| 3799 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 3800 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3801 | if (mAppWindowToken == null) { |
| 3802 | Slog.w(TAG_WM, "Attempted to register remote animations with non-existing app" |
| 3803 | + " token: " + appToken); |
| 3804 | return; |
| 3805 | } |
| 3806 | mAppWindowToken.registerRemoteAnimations(definition); |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3809 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3811 | if (stringName != null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 3812 | return stringName + " t" + (task == null ? INVALID_TASK_ID : task.taskId) + |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3813 | (finishing ? " f}" : "}"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3814 | } |
| 3815 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 3816 | sb.append("ActivityRecord{"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3817 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3818 | sb.append(" u"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3819 | sb.append(mUserId); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 3820 | sb.append(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3821 | sb.append(intent.getComponent().flattenToShortString()); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3822 | stringName = sb.toString(); |
| 3823 | return toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3825 | |
| 3826 | void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) { |
| 3827 | final long token = proto.start(fieldId); |
| 3828 | proto.write(HASH_CODE, System.identityHashCode(this)); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3829 | proto.write(USER_ID, mUserId); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3830 | proto.write(TITLE, intent.getComponent().flattenToShortString()); |
| 3831 | proto.end(token); |
| 3832 | } |
| 3833 | |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 3834 | /** |
| 3835 | * Write all fields to an {@code ActivityRecordProto}. This assumes the |
| 3836 | * {@code ActivityRecordProto} is the outer-most proto data. |
| 3837 | */ |
| 3838 | void writeToProto(ProtoOutputStream proto) { |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3839 | super.writeToProto(proto, CONFIGURATION_CONTAINER, WindowTraceLogLevel.ALL); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3840 | writeIdentifierToProto(proto, IDENTIFIER); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3841 | proto.write(STATE, mState.toString()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3842 | proto.write(VISIBLE, visible); |
| 3843 | proto.write(FRONT_OF_TASK, frontOfTask); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3844 | if (hasProcess()) { |
| 3845 | proto.write(PROC_ID, app.getPid()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3846 | } |
Wale Ogunwale | 30eab1f | 2018-05-24 18:25:25 -0700 | [diff] [blame] | 3847 | proto.write(TRANSLUCENT, !fullscreen); |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 3851 | final long token = proto.start(fieldId); |
| 3852 | writeToProto(proto); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3853 | proto.end(token); |
| 3854 | } |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3855 | |
| 3856 | /** |
| 3857 | * The precomputed insets of the display in each rotation. This is used to make the size |
| 3858 | * compatibility mode activity compute the configuration without relying on its current display. |
| 3859 | */ |
| 3860 | static class CompatDisplayInsets { |
| 3861 | final int mDisplayWidth; |
| 3862 | final int mDisplayHeight; |
| 3863 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3864 | /** |
| 3865 | * The nonDecorInsets for each rotation. Includes the navigation bar and cutout insets. It |
| 3866 | * is used to compute the appBounds. |
| 3867 | */ |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3868 | final Rect[] mNonDecorInsets = new Rect[4]; |
| 3869 | /** |
| 3870 | * The stableInsets for each rotation. Includes the status bar inset and the |
| 3871 | * nonDecorInsets. It is used to compute {@link Configuration#screenWidthDp} and |
| 3872 | * {@link Configuration#screenHeightDp}. |
| 3873 | */ |
| 3874 | final Rect[] mStableInsets = new Rect[4]; |
| 3875 | |
| 3876 | CompatDisplayInsets(DisplayContent display) { |
| 3877 | mDisplayWidth = display.mBaseDisplayWidth; |
| 3878 | mDisplayHeight = display.mBaseDisplayHeight; |
| 3879 | final DisplayPolicy policy = display.getDisplayPolicy(); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3880 | for (int rotation = 0; rotation < 4; rotation++) { |
| 3881 | mNonDecorInsets[rotation] = new Rect(); |
| 3882 | mStableInsets[rotation] = new Rect(); |
| 3883 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 3884 | final int dw = rotated ? mDisplayHeight : mDisplayWidth; |
| 3885 | final int dh = rotated ? mDisplayWidth : mDisplayHeight; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3886 | final DisplayCutout cutout = display.calculateDisplayCutoutForRotation(rotation) |
| 3887 | .getDisplayCutout(); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3888 | policy.getNonDecorInsetsLw(rotation, dw, dh, cutout, mNonDecorInsets[rotation]); |
| 3889 | mStableInsets[rotation].set(mNonDecorInsets[rotation]); |
| 3890 | policy.convertNonDecorInsetsToStableInsets(mStableInsets[rotation], rotation); |
| 3891 | } |
| 3892 | } |
| 3893 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3894 | void getDisplayBoundsByRotation(Rect outBounds, int rotation) { |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3895 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 3896 | final int dw = rotated ? mDisplayHeight : mDisplayWidth; |
| 3897 | final int dh = rotated ? mDisplayWidth : mDisplayHeight; |
| 3898 | outBounds.set(0, 0, dw, dh); |
| 3899 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 3900 | |
| 3901 | void getDisplayBoundsByOrientation(Rect outBounds, int orientation) { |
| 3902 | final int longSide = Math.max(mDisplayWidth, mDisplayHeight); |
| 3903 | final int shortSide = Math.min(mDisplayWidth, mDisplayHeight); |
| 3904 | final boolean isLandscape = orientation == ORIENTATION_LANDSCAPE; |
| 3905 | outBounds.set(0, 0, isLandscape ? longSide : shortSide, |
| 3906 | isLandscape ? shortSide : longSide); |
| 3907 | } |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 3908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | } |