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; |
Louis Chang | 477e93e | 2019-04-24 18:35:20 +0800 | [diff] [blame] | 33 | import static android.app.ActivityOptions.ANIM_UNDEFINED; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 34 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 35 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 36 | import static android.app.AppOpsManager.MODE_ALLOWED; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 37 | import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 38 | import static android.app.WaitResult.INVALID_DELAY; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 39 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 40 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 41 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 42 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 43 | import static android.app.WindowConfiguration.ROTATION_UNDEFINED; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 44 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 45 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 46 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 47 | import static android.app.WindowConfiguration.activityTypeToString; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 48 | import static android.content.Intent.ACTION_MAIN; |
| 49 | import static android.content.Intent.CATEGORY_HOME; |
| 50 | import static android.content.Intent.CATEGORY_LAUNCHER; |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 51 | import static android.content.Intent.CATEGORY_SECONDARY_HOME; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 52 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 53 | import static android.content.Intent.FLAG_ACTIVITY_NO_HISTORY; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 54 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 55 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 56 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
| 57 | import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 58 | import static android.content.pm.ActivityInfo.CONFIG_UI_MODE; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 59 | import static android.content.pm.ActivityInfo.CONFIG_WINDOW_CONFIGURATION; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 60 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 61 | import static android.content.pm.ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 62 | import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 63 | import static android.content.pm.ActivityInfo.FLAG_INHERIT_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 64 | import static android.content.pm.ActivityInfo.FLAG_MULTIPROCESS; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 65 | import static android.content.pm.ActivityInfo.FLAG_NO_HISTORY; |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 66 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 67 | import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 68 | import static android.content.pm.ActivityInfo.FLAG_TURN_SCREEN_ON; |
| 69 | import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE; |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 70 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 71 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 72 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 73 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; |
| 74 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 75 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 76 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 77 | import static android.content.pm.ActivityInfo.PERSIST_ACROSS_REBOOTS; |
| 78 | import static android.content.pm.ActivityInfo.PERSIST_ROOT_ONLY; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 79 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 80 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 81 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 82 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 83 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
| 84 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 85 | import static android.content.pm.ActivityInfo.isFixedOrientationLandscape; |
| 86 | import static android.content.pm.ActivityInfo.isFixedOrientationPortrait; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 87 | import static android.content.res.Configuration.EMPTY; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 88 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 89 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 90 | import static android.content.res.Configuration.ORIENTATION_UNDEFINED; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 91 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 92 | import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 93 | import static android.os.Build.VERSION_CODES.HONEYCOMB; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 94 | import static android.os.Build.VERSION_CODES.O; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 95 | import static android.os.Process.SYSTEM_UID; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 96 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
| 97 | import static android.view.Display.COLOR_MODE_DEFAULT; |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 98 | import static android.view.Display.DEFAULT_DISPLAY; |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 99 | import static android.view.Display.INVALID_DISPLAY; |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 100 | import static android.view.Surface.ROTATION_270; |
| 101 | import static android.view.Surface.ROTATION_90; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 102 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 103 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
| 104 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 105 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 106 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 107 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 108 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 109 | import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 110 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
| 111 | import static android.view.WindowManager.TRANSIT_TASK_CHANGE_WINDOWING_MODE; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 112 | import static android.view.WindowManager.TRANSIT_TASK_CLOSE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 113 | import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND; |
| 114 | import static android.view.WindowManager.TRANSIT_UNSET; |
| 115 | import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 116 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 117 | import static com.android.server.am.ActivityRecordProto.APP_WINDOW_TOKEN; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 118 | import static com.android.server.am.ActivityRecordProto.FRONT_OF_TASK; |
| 119 | import static com.android.server.am.ActivityRecordProto.IDENTIFIER; |
| 120 | import static com.android.server.am.ActivityRecordProto.PROC_ID; |
| 121 | import static com.android.server.am.ActivityRecordProto.STATE; |
| 122 | import static com.android.server.am.ActivityRecordProto.TRANSLUCENT; |
| 123 | import static com.android.server.am.ActivityRecordProto.VISIBLE; |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 124 | import static com.android.server.am.ActivityRecordProto.VISIBLE_REQUESTED; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 125 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 126 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 127 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 128 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 129 | import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 130 | import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; |
| 131 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 132 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 133 | import static com.android.server.wm.ActivityStack.ActivityState.RESTARTING_PROCESS; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 134 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 135 | import static com.android.server.wm.ActivityStack.ActivityState.STARTED; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 136 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 137 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 138 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 139 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 140 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_APP; |
| 141 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 142 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 143 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONTAINERS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 144 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 145 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE; |
| 146 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 147 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SAVED_STATE; |
| 148 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 149 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 150 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TRANSITION; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 151 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_USER_LEAVING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 152 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 153 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 154 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_APP; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 155 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 156 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONTAINERS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 157 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 158 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_PAUSE; |
| 159 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RESULTS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 160 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SAVED_STATE; |
| 161 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; |
| 162 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 163 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TRANSITION; |
| 164 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_LEAVING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 165 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 166 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 167 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 168 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; |
| 169 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 170 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
Louis Chang | 746c224 | 2019-10-08 16:30:44 +0800 | [diff] [blame] | 171 | import static com.android.server.wm.ActivityTaskManagerService.getInputDispatchingTimeoutLocked; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 172 | import static com.android.server.wm.AppWindowTokenProto.ALL_DRAWN; |
| 173 | import static com.android.server.wm.AppWindowTokenProto.APP_STOPPED; |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 174 | import static com.android.server.wm.AppWindowTokenProto.CLIENT_VISIBLE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 175 | import static com.android.server.wm.AppWindowTokenProto.DEFER_HIDING_CLIENT; |
| 176 | import static com.android.server.wm.AppWindowTokenProto.FILLS_PARENT; |
| 177 | import static com.android.server.wm.AppWindowTokenProto.FROZEN_BOUNDS; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 178 | import static com.android.server.wm.AppWindowTokenProto.IS_ANIMATING; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 179 | import static com.android.server.wm.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START; |
| 180 | import static com.android.server.wm.AppWindowTokenProto.LAST_ALL_DRAWN; |
| 181 | import static com.android.server.wm.AppWindowTokenProto.LAST_SURFACE_SHOWING; |
| 182 | import static com.android.server.wm.AppWindowTokenProto.NAME; |
| 183 | import static com.android.server.wm.AppWindowTokenProto.NUM_DRAWN_WINDOWS; |
| 184 | import static com.android.server.wm.AppWindowTokenProto.NUM_INTERESTING_WINDOWS; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 185 | import static com.android.server.wm.AppWindowTokenProto.REPORTED_DRAWN; |
| 186 | import static com.android.server.wm.AppWindowTokenProto.REPORTED_VISIBLE; |
| 187 | import static com.android.server.wm.AppWindowTokenProto.STARTING_DISPLAYED; |
| 188 | import static com.android.server.wm.AppWindowTokenProto.STARTING_MOVED; |
| 189 | import static com.android.server.wm.AppWindowTokenProto.STARTING_WINDOW; |
| 190 | import static com.android.server.wm.AppWindowTokenProto.THUMBNAIL; |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 191 | import static com.android.server.wm.AppWindowTokenProto.VISIBLE_SET_FROM_TRANSFERRED_STARTING_WINDOW; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 192 | import static com.android.server.wm.AppWindowTokenProto.WINDOW_TOKEN; |
| 193 | import static com.android.server.wm.IdentifierProto.HASH_CODE; |
| 194 | import static com.android.server.wm.IdentifierProto.TITLE; |
| 195 | import static com.android.server.wm.IdentifierProto.USER_ID; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 196 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 197 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
| 198 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS_ANIM; |
| 199 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 200 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; |
| 201 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 202 | import static com.android.server.wm.TaskPersister.DEBUG; |
| 203 | import static com.android.server.wm.TaskPersister.IMAGE_EXTENSION; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 204 | import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; |
| 205 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 206 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 207 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 208 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 209 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 210 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 211 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
| 212 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 213 | import static com.android.server.wm.WindowState.LEGACY_POLICY_VISIBILITY; |
| 214 | import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 215 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 216 | |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 217 | import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; |
| 218 | import static org.xmlpull.v1.XmlPullParser.END_TAG; |
| 219 | import static org.xmlpull.v1.XmlPullParser.START_TAG; |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 220 | |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 221 | import android.annotation.IntDef; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 222 | import android.annotation.NonNull; |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 223 | import android.annotation.Nullable; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 224 | import android.annotation.Size; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 225 | import android.app.Activity; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 226 | import android.app.ActivityManager; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 227 | import android.app.ActivityManager.TaskDescription; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 228 | import android.app.ActivityOptions; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 229 | import android.app.PendingIntent; |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 230 | import android.app.PictureInPictureParams; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 231 | import android.app.ResultInfo; |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 232 | import android.app.WaitResult.LaunchState; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 233 | import android.app.servertransaction.ActivityConfigurationChangeItem; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 234 | import android.app.servertransaction.ActivityLifecycleItem; |
| 235 | import android.app.servertransaction.ActivityRelaunchItem; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 236 | import android.app.servertransaction.ActivityResultItem; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 237 | import android.app.servertransaction.ClientTransaction; |
| 238 | import android.app.servertransaction.ClientTransactionItem; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 239 | import android.app.servertransaction.DestroyActivityItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 240 | import android.app.servertransaction.MoveToDisplayItem; |
| 241 | import android.app.servertransaction.MultiWindowModeChangeItem; |
| 242 | import android.app.servertransaction.NewIntentItem; |
Bryce Lee | 0bd8d42 | 2018-01-09 09:45:57 -0800 | [diff] [blame] | 243 | import android.app.servertransaction.PauseActivityItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 244 | import android.app.servertransaction.PipModeChangeItem; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 245 | import android.app.servertransaction.ResumeActivityItem; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 246 | import android.app.servertransaction.StopActivityItem; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 247 | import android.app.servertransaction.TopResumedActivityChangeItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 248 | import android.app.servertransaction.WindowVisibilityItem; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 249 | import android.app.usage.UsageEvents.Event; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | import android.content.ComponentName; |
| 251 | import android.content.Intent; |
| 252 | import android.content.pm.ActivityInfo; |
| 253 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 254 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | import android.content.res.Configuration; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 256 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | import android.graphics.Bitmap; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 258 | import android.graphics.GraphicBuffer; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 259 | import android.graphics.PixelFormat; |
| 260 | import android.graphics.Point; |
Dianne Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 261 | import android.graphics.Rect; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 262 | import android.net.Uri; |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 263 | import android.os.Binder; |
Bryce Lee | 3979159 | 2017-04-26 09:29:12 -0700 | [diff] [blame] | 264 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | import android.os.Bundle; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 266 | import android.os.Debug; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 267 | import android.os.IBinder; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 268 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | import android.os.Process; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 270 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | import android.os.SystemClock; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 272 | import android.os.Trace; |
| 273 | import android.os.UserHandle; |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 274 | import android.os.storage.StorageManager; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 275 | import android.service.voice.IVoiceInteractionSession; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 276 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | import android.util.EventLog; |
| 278 | import android.util.Log; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 279 | import android.util.MergedConfiguration; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 280 | import android.util.Slog; |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 281 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 282 | import android.util.proto.ProtoOutputStream; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 283 | import android.view.AppTransitionAnimationSpec; |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 284 | import android.view.DisplayCutout; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 285 | import android.view.DisplayInfo; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 286 | import android.view.IAppTransitionAnimationSpecsFuture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | import android.view.IApplicationToken; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 288 | import android.view.InputApplicationHandle; |
| 289 | import android.view.RemoteAnimationAdapter; |
| 290 | import android.view.RemoteAnimationDefinition; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 291 | import android.view.RemoteAnimationTarget; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 292 | import android.view.SurfaceControl; |
| 293 | import android.view.SurfaceControl.Transaction; |
| 294 | import android.view.WindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 295 | import android.view.WindowManager.LayoutParams; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 296 | import android.view.animation.Animation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 297 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 298 | import com.android.internal.R; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 299 | import com.android.internal.annotations.VisibleForTesting; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 300 | import com.android.internal.app.ResolverActivity; |
| 301 | import com.android.internal.content.ReferrerIntent; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 302 | import com.android.internal.util.ToBooleanFunction; |
Filip Gruszczynski | 3d02671 | 2015-12-16 13:46:38 -0800 | [diff] [blame] | 303 | import com.android.internal.util.XmlUtils; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 304 | import com.android.internal.util.function.pooled.PooledConsumer; |
| 305 | import com.android.internal.util.function.pooled.PooledFunction; |
| 306 | import com.android.internal.util.function.pooled.PooledLambda; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 307 | import com.android.server.AttributeCache; |
| 308 | import com.android.server.LocalServices; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 309 | import com.android.server.am.AppTimeTracker; |
| 310 | import com.android.server.am.PendingIntentRecord; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 311 | import com.android.server.display.color.ColorDisplayService; |
| 312 | import com.android.server.policy.WindowManagerPolicy; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 313 | import com.android.server.protolog.common.ProtoLog; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 314 | import com.android.server.uri.UriPermissionOwner; |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 315 | import com.android.server.wm.ActivityMetricsLogger.TransitionInfoSnapshot; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 316 | import com.android.server.wm.ActivityStack.ActivityState; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 317 | import com.android.server.wm.WindowManagerService.H; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 318 | import com.android.server.wm.utils.InsetUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 320 | import com.google.android.collect.Sets; |
| 321 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 322 | import org.xmlpull.v1.XmlPullParser; |
| 323 | import org.xmlpull.v1.XmlPullParserException; |
| 324 | import org.xmlpull.v1.XmlSerializer; |
| 325 | |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 326 | import java.io.File; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 327 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | import java.io.PrintWriter; |
| 329 | import java.lang.ref.WeakReference; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 330 | import java.util.ArrayDeque; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | import java.util.ArrayList; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 332 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | import java.util.HashSet; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 334 | import java.util.List; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 335 | import java.util.Objects; |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 336 | import java.util.function.Consumer; |
| 337 | import java.util.function.Function; |
| 338 | import java.util.function.Predicate; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * An entry in the history stack, representing an activity. |
| 342 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 343 | final class ActivityRecord extends WindowToken implements WindowManagerService.AppFreezeListener { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 344 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_ATM; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 345 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 346 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 347 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 348 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
| 349 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 350 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
| 351 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 352 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 353 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 354 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 355 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 356 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 357 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 358 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 359 | private static final String ATTR_ID = "id"; |
| 360 | private static final String TAG_INTENT = "intent"; |
| 361 | private static final String ATTR_USERID = "user_id"; |
| 362 | private static final String TAG_PERSISTABLEBUNDLE = "persistable_bundle"; |
| 363 | private static final String ATTR_LAUNCHEDFROMUID = "launched_from_uid"; |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 364 | private static final String ATTR_LAUNCHEDFROMPACKAGE = "launched_from_package"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 365 | private static final String ATTR_RESOLVEDTYPE = "resolved_type"; |
| 366 | private static final String ATTR_COMPONENTSPECIFIED = "component_specified"; |
Dianne Hackborn | 337abb3 | 2014-09-24 12:44:29 -0700 | [diff] [blame] | 367 | static final String ACTIVITY_ICON_SUFFIX = "_activity_icon_"; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 368 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 369 | // How many activities have to be scheduled to stop to force a stop pass. |
| 370 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 371 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 372 | private static final int STARTING_WINDOW_TYPE_NONE = 0; |
| 373 | private static final int STARTING_WINDOW_TYPE_SNAPSHOT = 1; |
| 374 | private static final int STARTING_WINDOW_TYPE_SPLASH_SCREEN = 2; |
| 375 | |
| 376 | /** |
| 377 | * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k. |
| 378 | */ |
| 379 | @VisibleForTesting static final int Z_BOOST_BASE = 800570000; |
Vishnu Nair | 19479df | 2019-10-30 08:03:15 -0700 | [diff] [blame] | 380 | static final int INVALID_PID = -1; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 381 | |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 382 | // How long we wait until giving up on the last activity to pause. This |
| 383 | // is short because it directly impacts the responsiveness of starting the |
| 384 | // next activity. |
| 385 | private static final int PAUSE_TIMEOUT = 500; |
| 386 | |
| 387 | // Ticks during which we check progress while waiting for an app to launch. |
| 388 | private static final int LAUNCH_TICK = 500; |
| 389 | |
| 390 | // How long we wait for the activity to tell us it has stopped before |
| 391 | // giving up. This is a good amount of time because we really need this |
| 392 | // from the application in order to get its saved state. Once the stop |
| 393 | // is complete we may start destroying client resources triggering |
| 394 | // crashes if the UI thread was hung. We put this timeout one second behind |
| 395 | // the ANR timeout so these situations will generate ANR instead of |
| 396 | // Surface lost or other errors. |
| 397 | private static final int STOP_TIMEOUT = 11 * 1000; |
| 398 | |
| 399 | // How long we wait until giving up on an activity telling us it has |
| 400 | // finished destroying itself. |
| 401 | private static final int DESTROY_TIMEOUT = 10 * 1000; |
| 402 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 403 | final ActivityTaskManagerService mAtmService; |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 404 | final ActivityInfo info; // activity info provided by developer in AndroidManifest |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 405 | // Non-null only for application tokens. |
| 406 | // TODO: rename to mActivityToken |
| 407 | final ActivityRecord.Token appToken; |
| 408 | // Which user is this running for? |
| 409 | final int mUserId; |
| 410 | // The package implementing intent's component |
| 411 | // TODO: rename to mPackageName |
| 412 | final String packageName; |
| 413 | // the intent component, or target of an alias. |
| 414 | final ComponentName mActivityComponent; |
| 415 | // Has a wallpaper window as a background. |
| 416 | // TODO: Rename to mHasWallpaper and also see if it possible to combine this with the |
| 417 | // mOccludesParent field. |
| 418 | final boolean hasWallpaper; |
| 419 | // Input application handle used by the input dispatcher. |
| 420 | final InputApplicationHandle mInputApplicationHandle; |
| 421 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 422 | final int launchedFromPid; // always the pid who started the activity. |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 423 | final int launchedFromUid; // always the uid who started the activity. |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 424 | final String launchedFromPackage; // always the package who started the activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | final Intent intent; // the original intent that generated us |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | final String shortComponentName; // the short component name of the intent |
| 427 | final String resolvedType; // as per original caller; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | final String processName; // process where this component wants to run |
| 429 | final String taskAffinity; // as per ActivityInfo.taskAffinity |
| 430 | final boolean stateNotNeeded; // As per ActivityInfo.flags |
Louis Chang | d58cb67 | 2018-12-24 17:45:16 +0800 | [diff] [blame] | 431 | @VisibleForTesting |
| 432 | int mHandoverLaunchDisplayId = INVALID_DISPLAY; // Handover launch display id to next activity. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 433 | private final boolean componentSpecified; // did caller specify an explicit component? |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 434 | final boolean rootVoiceInteraction; // was this the root activity of a voice interaction? |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 435 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 436 | private CharSequence nonLocalizedLabel; // the label information from the package mgr. |
| 437 | private int labelRes; // the label information from the package mgr. |
| 438 | private int icon; // resource identifier of activity's icon. |
| 439 | private int logo; // resource identifier of activity's logo. |
| 440 | private int theme; // resource identifier of activity's theme. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 441 | private int windowFlags; // custom window flags for preview window. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 442 | private Task task; // the task this is in. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 443 | private long createTime = System.currentTimeMillis(); |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 444 | long lastVisibleTime; // last time this activity became visible |
| 445 | long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity |
| 446 | long pauseTime; // last time we started pausing the activity |
| 447 | long launchTickTime; // base time for launch tick messages |
| 448 | 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] | 449 | // Last configuration reported to the activity in the client process. |
| 450 | private MergedConfiguration mLastReportedConfiguration; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 451 | private int mLastReportedDisplayId; |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 452 | boolean mLastReportedMultiWindowMode; |
| 453 | boolean mLastReportedPictureInPictureMode; |
Dianne Hackborn | 8ea5e1d | 2011-05-27 16:45:31 -0700 | [diff] [blame] | 454 | CompatibilityInfo compat;// last used compatibility mode |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 455 | 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] | 456 | final String resultWho; // additional identifier for use by resultTo. |
| 457 | final int requestCode; // code given by requester (resultTo) |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 458 | ArrayList<ResultInfo> results; // pending ActivityResult objs we have received |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 460 | ArrayList<ReferrerIntent> newIntents; // any pending new intents for single-top mode |
Louis Chang | 746c224 | 2019-10-08 16:30:44 +0800 | [diff] [blame] | 461 | Intent mLastNewIntent; // the last new intent we delivered to client |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 462 | ActivityOptions pendingOptions; // most recently given options |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 463 | ActivityOptions returningOptions; // options that are coming back via convertToTranslucent |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 464 | 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] | 465 | ActivityServiceConnectionsHolder mServiceConnectionsHolder; // Service connections. |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 466 | UriPermissionOwner uriPermissions; // current special URI access perms. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 467 | WindowProcessController app; // if non-null, hosting application |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 468 | private ActivityState mState; // current state we are in |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 469 | private Bundle mIcicle; // last saved activity state |
| 470 | private PersistableBundle mPersistentState; // last persistently saved activity state |
| 471 | private boolean mHaveState = true; // Indicates whether the last saved state of activity is |
| 472 | // preserved. This starts out 'true', since the initial state |
| 473 | // of an activity is that we have everything, and we should |
| 474 | // never consider it lacking in state to be removed if it |
| 475 | // dies. After an activity is launched it follows the value |
| 476 | // of #mIcicle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | boolean launchFailed; // set if a launched failed, to abort on 2nd try |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | boolean stopped; // is activity pause finished? |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 479 | 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] | 480 | boolean finishing; // activity in pending finish list? |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 481 | boolean deferRelaunchUntilPaused; // relaunch of activity is being deferred until pause is |
| 482 | // completed |
| 483 | boolean preserveWindowOnDeferredRelaunch; // activity windows are preserved on deferred relaunch |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | int configChangeFlags; // which config values have changed |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 485 | 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] | 486 | int launchMode; // the launch mode activity attribute. |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 487 | int lockTaskLaunchMode; // the lockTaskMode manifest attribute, subject to override |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 488 | private boolean mVisible; // Should this token's windows be visible? |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 489 | boolean visibleIgnoringKeyguard; // is this activity visible, ignoring the fact that Keyguard |
| 490 | // might hide this activity? |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 491 | // True if the visible state of this token was forced to true due to a transferred starting |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 492 | // window. |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 493 | private boolean mVisibleSetFromTransferredStartingWindow; |
| 494 | // TODO: figure out how to consolidate with the same variable in ActivityRecord. |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 495 | private boolean mDeferHidingClient; // If true we told WM to defer reporting to the client |
| 496 | // process that it is hidden. |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 497 | private boolean mLastDeferHidingClient; // If true we will defer setting mClientVisible to false |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 498 | // and reporting to the client that it is hidden. |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 499 | boolean sleeping; // have we told the activity to sleep? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | boolean nowVisible; // is this activity's window visible? |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 501 | boolean mDrawn; // is this activity's window drawn? |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 502 | 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] | 503 | boolean idle; // has the activity gone idle? |
| 504 | boolean hasBeenLaunched;// has this activity ever been launched? |
| 505 | boolean frozenBeforeDestroy;// has been frozen but not yet destroyed. |
Daniel Sandler | 69a4817 | 2010-06-23 16:29:36 -0400 | [diff] [blame] | 506 | boolean immersive; // immersive mode (don't interrupt if possible) |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 507 | boolean forceNewConfig; // force re-create with new config next time |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 508 | boolean supportsEnterPipOnTaskSwitch; // This flag is set by the system to indicate that the |
| 509 | // 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] | 510 | PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build(); |
| 511 | // The PiP params used when deferring the entering of picture-in-picture. |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 512 | int launchCount; // count of launches since last state |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 513 | long lastLaunchTime; // time of last launch of this activity |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 514 | ComponentName requestedVrComponent; // the requested component for handling VR mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 516 | boolean inHistory; // are we in the history stack? |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 517 | final ActivityStackSupervisor mStackSupervisor; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 518 | final RootWindowContainer mRootWindowContainer; |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 519 | |
| 520 | static final int STARTING_WINDOW_NOT_SHOWN = 0; |
| 521 | static final int STARTING_WINDOW_SHOWN = 1; |
| 522 | static final int STARTING_WINDOW_REMOVED = 2; |
| 523 | int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN; |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 524 | private 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] | 525 | |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 526 | // Marking the reason why this activity is being relaunched. Mainly used to track that this |
| 527 | // activity is being relaunched to fulfill a resize request due to compatibility issues, e.g. in |
| 528 | // pre-NYC apps that don't have a sense of being resized. |
| 529 | int mRelaunchReason = RELAUNCH_REASON_NONE; |
| 530 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 531 | TaskDescription taskDescription; // the recents information for this activity |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 532 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 533 | // These configurations are collected from application's resources based on size-sensitive |
| 534 | // qualifiers. For example, layout-w800dp will be added to mHorizontalSizeConfigurations as 800 |
| 535 | // and drawable-sw400dp will be added to both as 400. |
| 536 | private int[] mVerticalSizeConfigurations; |
| 537 | private int[] mHorizontalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 538 | private int[] mSmallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 539 | |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 540 | /** |
| 541 | * The precomputed display insets for resolving configuration. It will be non-null if |
| 542 | * {@link #shouldUseSizeCompatMode} returns {@code true}. |
| 543 | */ |
| 544 | private CompatDisplayInsets mCompatDisplayInsets; |
| 545 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 546 | boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session |
| 547 | IVoiceInteractionSession voiceSession; // Voice interaction session for this activity |
| 548 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 549 | boolean mVoiceInteraction; |
| 550 | |
| 551 | private int mPendingRelaunchCount; |
| 552 | |
| 553 | // True if we are current in the process of removing this app token from the display |
| 554 | private boolean mRemovingFromDisplay = false; |
| 555 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 556 | private RemoteAnimationDefinition mRemoteAnimationDefinition; |
| 557 | |
| 558 | private AnimatingActivityRegistry mAnimatingActivityRegistry; |
| 559 | |
| 560 | private Task mLastParent; |
| 561 | |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 562 | // Have we told the window clients to show themselves? |
| 563 | private boolean mClientVisible; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 564 | |
| 565 | boolean firstWindowDrawn; |
| 566 | // Last drawn state we reported to the app token. |
| 567 | private boolean reportedDrawn; |
| 568 | private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults = |
| 569 | new WindowState.UpdateReportedVisibilityResults(); |
| 570 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 571 | boolean mUseTransferredAnimation; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 572 | |
| 573 | /** |
| 574 | * @see #currentLaunchCanTurnScreenOn() |
| 575 | */ |
| 576 | private boolean mCurrentLaunchCanTurnScreenOn = true; |
| 577 | |
| 578 | /** |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 579 | * This leash is used to "freeze" the app surface in place after the state change, but before |
| 580 | * the animation is ready to start. |
| 581 | */ |
| 582 | private SurfaceControl mTransitChangeLeash = null; |
| 583 | |
| 584 | /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */ |
| 585 | private boolean mLastSurfaceShowing = true; |
| 586 | |
| 587 | private Letterbox mLetterbox; |
| 588 | |
| 589 | /** |
| 590 | * The activity is opaque and fills the entire space of this task. |
| 591 | * @see WindowContainer#fillsParent() |
| 592 | */ |
| 593 | private boolean mOccludesParent; |
| 594 | |
| 595 | // The input dispatching timeout for this application token in nanoseconds. |
| 596 | long mInputDispatchingTimeoutNanos; |
| 597 | |
| 598 | private boolean mShowWhenLocked; |
| 599 | private boolean mInheritShownWhenLocked; |
| 600 | private boolean mTurnScreenOn; |
| 601 | |
| 602 | /** Have we been asked to have this token keep the screen frozen? */ |
| 603 | private boolean mFreezingScreen; |
| 604 | |
| 605 | // These are used for determining when all windows associated with |
| 606 | // an activity have been drawn, so they can be made visible together |
| 607 | // at the same time. |
| 608 | // initialize so that it doesn't match mTransactionSequence which is an int. |
| 609 | private long mLastTransactionSequence = Long.MIN_VALUE; |
| 610 | private int mNumInterestingWindows; |
| 611 | private int mNumDrawnWindows; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 612 | boolean allDrawn; |
| 613 | private boolean mLastAllDrawn; |
| 614 | |
| 615 | private boolean mLastContainsShowWhenLockedWindow; |
| 616 | private boolean mLastContainsDismissKeyguardWindow; |
| 617 | |
| 618 | /** |
| 619 | * A flag to determine if this AR is in the process of closing or entering PIP. This is needed |
| 620 | * to help AR know that the app is in the process of closing but hasn't yet started closing on |
| 621 | * the WM side. |
| 622 | */ |
| 623 | private boolean mWillCloseOrEnterPip; |
| 624 | |
| 625 | /** |
| 626 | * The scale to fit at least one side of the activity to its parent. If the activity uses |
| 627 | * 1920x1080, and the actually size on the screen is 960x540, then the scale is 0.5. |
| 628 | */ |
| 629 | private float mSizeCompatScale = 1f; |
| 630 | /** |
| 631 | * The bounds in global coordinates for activity in size compatibility mode. |
| 632 | * @see ActivityRecord#hasSizeCompatBounds() |
| 633 | */ |
| 634 | private Rect mSizeCompatBounds; |
| 635 | |
| 636 | // activity is not displayed? |
| 637 | // TODO: rename to mNoDisplay |
| 638 | @VisibleForTesting |
| 639 | boolean noDisplay; |
| 640 | boolean mShowForAllUsers; |
| 641 | // TODO: Make this final |
| 642 | int mTargetSdk; |
| 643 | |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 644 | // Is this window's surface needed? This is almost like visible, except |
| 645 | // it will sometimes be true a little earlier: when the activity record has |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 646 | // been shown, but is still waiting for its app transition to execute |
| 647 | // before making its windows shown. |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 648 | boolean mVisibleRequested; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 649 | |
| 650 | // Last visibility state we reported to the app token. |
| 651 | boolean reportedVisible; |
| 652 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 653 | boolean mDisablePreviewScreenshots; |
| 654 | |
| 655 | // Information about an application starting window if displayed. |
| 656 | // Note: these are de-referenced before the starting window animates away. |
| 657 | StartingData mStartingData; |
| 658 | WindowState startingWindow; |
| 659 | WindowManagerPolicy.StartingSurface startingSurface; |
| 660 | boolean startingDisplayed; |
| 661 | boolean startingMoved; |
| 662 | |
| 663 | // TODO: Have a WindowContainer state for tracking exiting/deferred removal. |
| 664 | boolean mIsExiting; |
| 665 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 666 | boolean mEnteringAnimation; |
| 667 | |
| 668 | boolean mAppStopped; |
| 669 | // A hint to override the window specified rotation animation, or -1 to use the window specified |
| 670 | // value. We use this so that we can select the right animation in the cases of starting |
| 671 | // windows, where the app hasn't had time to set a value on the window. |
| 672 | int mRotationAnimationHint = -1; |
| 673 | |
| 674 | ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>(); |
| 675 | ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>(); |
| 676 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 677 | private AppSaturationInfo mLastAppSaturationInfo; |
| 678 | |
| 679 | private final ColorDisplayService.ColorTransformController mColorTransformController = |
| 680 | (matrix, translation) -> mWmService.mH.post(() -> { |
| 681 | synchronized (mWmService.mGlobalLock) { |
| 682 | if (mLastAppSaturationInfo == null) { |
| 683 | mLastAppSaturationInfo = new AppSaturationInfo(); |
| 684 | } |
| 685 | |
| 686 | mLastAppSaturationInfo.setSaturation(matrix, translation); |
| 687 | updateColorTransform(); |
| 688 | } |
| 689 | }); |
| 690 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 691 | /** |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 692 | * Current sequencing integer of the configuration, for skipping old activity configurations. |
| 693 | */ |
| 694 | private int mConfigurationSeq; |
| 695 | |
| 696 | /** |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 697 | * Temp configs used in {@link #ensureActivityConfiguration(int, boolean)} |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 698 | */ |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 699 | private final Configuration mTmpConfig = new Configuration(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 700 | private final Rect mTmpBounds = new Rect(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 701 | |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 702 | // Token for targeting this activity for assist purposes. |
| 703 | final Binder assistToken = new Binder(); |
| 704 | |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 705 | private final Runnable mPauseTimeoutRunnable = new Runnable() { |
| 706 | @Override |
| 707 | public void run() { |
| 708 | // We don't at this point know if the activity is fullscreen, |
| 709 | // so we need to be conservative and assume it isn't. |
| 710 | Slog.w(TAG, "Activity pause timeout for " + ActivityRecord.this); |
| 711 | synchronized (mAtmService.mGlobalLock) { |
| 712 | if (hasProcess()) { |
| 713 | mAtmService.logAppTooSlow(app, pauseTime, "pausing " + ActivityRecord.this); |
| 714 | } |
| 715 | activityPaused(true); |
| 716 | } |
| 717 | } |
| 718 | }; |
| 719 | |
| 720 | private final Runnable mLaunchTickRunnable = new Runnable() { |
| 721 | @Override |
| 722 | public void run() { |
| 723 | synchronized (mAtmService.mGlobalLock) { |
| 724 | if (continueLaunchTicking()) { |
| 725 | mAtmService.logAppTooSlow( |
| 726 | app, launchTickTime, "launching " + ActivityRecord.this); |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | }; |
| 731 | |
| 732 | private final Runnable mDestroyTimeoutRunnable = new Runnable() { |
| 733 | @Override |
| 734 | public void run() { |
| 735 | synchronized (mAtmService.mGlobalLock) { |
| 736 | Slog.w(TAG, "Activity destroy timeout for " + ActivityRecord.this); |
| 737 | destroyed("destroyTimeout"); |
| 738 | } |
| 739 | } |
| 740 | }; |
| 741 | |
| 742 | private final Runnable mStopTimeoutRunnable = new Runnable() { |
| 743 | @Override |
| 744 | public void run() { |
| 745 | synchronized (mAtmService.mGlobalLock) { |
| 746 | Slog.w(TAG, "Activity stop timeout for " + ActivityRecord.this); |
| 747 | if (isInHistory()) { |
| 748 | activityStopped(null /*icicle*/, null /*persistentState*/, null /*description*/); |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | }; |
| 753 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 754 | private static String startingWindowStateToString(int state) { |
| 755 | switch (state) { |
| 756 | case STARTING_WINDOW_NOT_SHOWN: |
| 757 | return "STARTING_WINDOW_NOT_SHOWN"; |
| 758 | case STARTING_WINDOW_SHOWN: |
| 759 | return "STARTING_WINDOW_SHOWN"; |
| 760 | case STARTING_WINDOW_REMOVED: |
| 761 | return "STARTING_WINDOW_REMOVED"; |
| 762 | default: |
| 763 | return "unknown state=" + state; |
| 764 | } |
| 765 | } |
| 766 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 767 | @Override |
| 768 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 769 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 770 | pw.print(prefix); pw.print("packageName="); pw.print(packageName); |
| 771 | pw.print(" processName="); pw.println(processName); |
| 772 | pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 773 | pw.print(" launchedFromPackage="); pw.print(launchedFromPackage); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 774 | pw.print(" userId="); pw.println(mUserId); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 775 | pw.print(prefix); pw.print("app="); pw.println(app); |
Hui Yu | 6d5c3b9 | 2019-10-22 15:35:53 -0700 | [diff] [blame] | 776 | pw.print(prefix); pw.println(intent.toInsecureString()); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 777 | pw.print(prefix); pw.print("rootOfTask="); pw.print(isRootOfTask()); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 778 | pw.print(" task="); pw.println(task); |
| 779 | pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 780 | pw.print(prefix); pw.print("mActivityComponent="); |
| 781 | pw.println(mActivityComponent.flattenToShortString()); |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 782 | if (info != null && info.applicationInfo != null) { |
| 783 | final ApplicationInfo appInfo = info.applicationInfo; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 784 | pw.print(prefix); pw.print("baseDir="); pw.println(appInfo.sourceDir); |
| 785 | if (!Objects.equals(appInfo.sourceDir, appInfo.publicSourceDir)) { |
| 786 | pw.print(prefix); pw.print("resDir="); pw.println(appInfo.publicSourceDir); |
| 787 | } |
| 788 | pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 789 | if (appInfo.splitSourceDirs != null) { |
| 790 | pw.print(prefix); pw.print("splitDir="); |
| 791 | pw.println(Arrays.toString(appInfo.splitSourceDirs)); |
| 792 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 793 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 794 | pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded); |
| 795 | pw.print(" componentSpecified="); pw.print(componentSpecified); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 796 | pw.print(" mActivityType="); pw.println( |
| 797 | activityTypeToString(getActivityType())); |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 798 | if (rootVoiceInteraction) { |
| 799 | pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction); |
| 800 | } |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 801 | pw.print(prefix); pw.print("compat="); pw.print(compat); |
| 802 | pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes)); |
| 803 | pw.print(" icon=0x"); pw.print(Integer.toHexString(icon)); |
| 804 | pw.print(" theme=0x"); pw.println(Integer.toHexString(theme)); |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 805 | pw.println(prefix + "mLastReportedConfigurations:"); |
| 806 | mLastReportedConfiguration.dump(pw, prefix + " "); |
| 807 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 808 | pw.print(prefix); pw.print("CurrentConfiguration="); pw.println(getConfiguration()); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 809 | if (!getRequestedOverrideConfiguration().equals(EMPTY)) { |
| 810 | pw.println(prefix + "RequestedOverrideConfiguration=" |
| 811 | + getRequestedOverrideConfiguration()); |
| 812 | } |
| 813 | if (!getResolvedOverrideConfiguration().equals(getRequestedOverrideConfiguration())) { |
| 814 | pw.println(prefix + "ResolvedOverrideConfiguration=" |
| 815 | + getResolvedOverrideConfiguration()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 816 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 817 | if (!matchParentBounds()) { |
| 818 | pw.println(prefix + "bounds=" + getBounds()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 819 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 820 | if (resultTo != null || resultWho != null) { |
| 821 | pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); |
| 822 | pw.print(" resultWho="); pw.print(resultWho); |
| 823 | pw.print(" resultCode="); pw.println(requestCode); |
| 824 | } |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 825 | if (taskDescription != null) { |
| 826 | final String iconFilename = taskDescription.getIconFilename(); |
| 827 | if (iconFilename != null || taskDescription.getLabel() != null || |
| 828 | taskDescription.getPrimaryColor() != 0) { |
| 829 | pw.print(prefix); pw.print("taskDescription:"); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 830 | pw.print(" label=\""); pw.print(taskDescription.getLabel()); |
| 831 | pw.print("\""); |
Matthew Ng | 54bc942 | 2017-10-02 17:16:28 -0700 | [diff] [blame] | 832 | pw.print(" icon="); pw.print(taskDescription.getInMemoryIcon() != null |
| 833 | ? taskDescription.getInMemoryIcon().getByteCount() + " bytes" |
| 834 | : "null"); |
| 835 | pw.print(" iconResource="); pw.print(taskDescription.getIconResource()); |
| 836 | pw.print(" iconFilename="); pw.print(taskDescription.getIconFilename()); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 837 | pw.print(" primaryColor="); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 838 | pw.println(Integer.toHexString(taskDescription.getPrimaryColor())); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 839 | pw.print(prefix + " backgroundColor="); |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 840 | pw.print(Integer.toHexString(taskDescription.getBackgroundColor())); |
| 841 | pw.print(" statusBarColor="); |
| 842 | pw.print(Integer.toHexString(taskDescription.getStatusBarColor())); |
| 843 | pw.print(" navigationBarColor="); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 844 | pw.println(Integer.toHexString(taskDescription.getNavigationBarColor())); |
Craig Mautner | 29c58ca | 2014-10-14 16:17:06 -0700 | [diff] [blame] | 845 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 846 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 847 | if (results != null) { |
| 848 | pw.print(prefix); pw.print("results="); pw.println(results); |
| 849 | } |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 850 | if (pendingResults != null && pendingResults.size() > 0) { |
| 851 | pw.print(prefix); pw.println("Pending Results:"); |
| 852 | for (WeakReference<PendingIntentRecord> wpir : pendingResults) { |
| 853 | PendingIntentRecord pir = wpir != null ? wpir.get() : null; |
| 854 | pw.print(prefix); pw.print(" - "); |
| 855 | if (pir == null) { |
| 856 | pw.println("null"); |
| 857 | } else { |
| 858 | pw.println(pir); |
| 859 | pir.dump(pw, prefix + " "); |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | if (newIntents != null && newIntents.size() > 0) { |
| 864 | pw.print(prefix); pw.println("Pending New Intents:"); |
| 865 | for (int i=0; i<newIntents.size(); i++) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 866 | Intent intent = newIntents.get(i); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 867 | pw.print(prefix); pw.print(" - "); |
| 868 | if (intent == null) { |
| 869 | pw.println("null"); |
| 870 | } else { |
Hui Yu | 6d5c3b9 | 2019-10-22 15:35:53 -0700 | [diff] [blame] | 871 | pw.println(intent.toShortString(false, true, false, false)); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 874 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 875 | if (pendingOptions != null) { |
| 876 | pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions); |
| 877 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 878 | if (appTimeTracker != null) { |
| 879 | appTimeTracker.dumpWithHeader(pw, prefix, false); |
| 880 | } |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 881 | if (uriPermissions != null) { |
Jeff Sharkey | 846318a | 2014-04-04 12:12:41 -0700 | [diff] [blame] | 882 | uriPermissions.dump(pw, prefix); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 883 | } |
| 884 | pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed); |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 885 | pw.print(" launchCount="); pw.print(launchCount); |
| 886 | pw.print(" lastLaunchTime="); |
| 887 | if (lastLaunchTime == 0) pw.print("0"); |
| 888 | else TimeUtils.formatDuration(lastLaunchTime, now, pw); |
| 889 | pw.println(); |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 890 | pw.print(prefix); pw.print("mHaveState="); pw.print(mHaveState); |
| 891 | pw.print(" mIcicle="); pw.println(mIcicle); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 892 | pw.print(prefix); pw.print("state="); pw.print(mState); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 893 | pw.print(" stopped="); pw.print(stopped); |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 894 | pw.print(" delayedResume="); pw.print(delayedResume); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 895 | pw.print(" finishing="); pw.println(finishing); |
| 896 | pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused); |
| 897 | pw.print(" inHistory="); pw.print(inHistory); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 898 | pw.print(" sleeping="); pw.print(sleeping); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 899 | pw.print(" idle="); pw.print(idle); |
| 900 | pw.print(" mStartingWindowState="); |
| 901 | pw.println(startingWindowStateToString(mStartingWindowState)); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 902 | pw.print(prefix); pw.print("occludesParent="); pw.print(occludesParent()); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 903 | pw.print(" noDisplay="); pw.print(noDisplay); |
| 904 | pw.print(" immersive="); pw.print(immersive); |
| 905 | pw.print(" launchMode="); pw.println(launchMode); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 906 | pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 907 | pw.print(" forceNewConfig="); pw.println(forceNewConfig); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 908 | pw.print(prefix); pw.print("mActivityType="); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 909 | pw.println(activityTypeToString(getActivityType())); |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 910 | if (requestedVrComponent != null) { |
| 911 | pw.print(prefix); |
| 912 | pw.print("requestedVrComponent="); |
| 913 | pw.println(requestedVrComponent); |
| 914 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 915 | super.dump(pw, prefix, dumpAll); |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 916 | if (mVoiceInteraction) { |
| 917 | pw.println(prefix + "mVoiceInteraction=true"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 918 | } |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 919 | pw.print(prefix); pw.print("mOccludesParent="); pw.print(mOccludesParent); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 920 | pw.print(" mOrientation="); pw.println(mOrientation); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 921 | pw.println(prefix + "mVisibleRequested=" + mVisibleRequested |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 922 | + " mVisible=" + mVisible + " mClientVisible=" + mClientVisible |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 923 | + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "") |
| 924 | + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible); |
| 925 | if (paused) { |
| 926 | pw.print(prefix); pw.print("paused="); pw.println(paused); |
| 927 | } |
| 928 | if (mAppStopped) { |
| 929 | pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped); |
| 930 | } |
| 931 | if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0 |
| 932 | || allDrawn || mLastAllDrawn) { |
| 933 | pw.print(prefix); pw.print("mNumInterestingWindows="); |
| 934 | pw.print(mNumInterestingWindows); |
| 935 | pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 936 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 937 | pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn); |
| 938 | pw.println(")"); |
| 939 | } |
Wale Ogunwale | 7a8889a | 2019-11-16 08:23:42 -0800 | [diff] [blame] | 940 | if (mStartingData != null || firstWindowDrawn || mIsExiting) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 941 | pw.print(prefix); pw.print("startingData="); pw.print(mStartingData); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 942 | pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn); |
| 943 | pw.print(" mIsExiting="); pw.println(mIsExiting); |
| 944 | } |
| 945 | if (startingWindow != null || startingSurface != null |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 946 | || startingDisplayed || startingMoved || mVisibleSetFromTransferredStartingWindow) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 947 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 948 | pw.print(" startingSurface="); pw.print(startingSurface); |
| 949 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 950 | pw.print(" startingMoved="); pw.print(startingMoved); |
| 951 | pw.println(" mHiddenSetFromTransferredStartingWindow=" |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 952 | + mVisibleSetFromTransferredStartingWindow); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 953 | } |
| 954 | if (!mFrozenBounds.isEmpty()) { |
| 955 | pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds); |
| 956 | pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig); |
| 957 | } |
| 958 | if (mPendingRelaunchCount != 0) { |
| 959 | pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount); |
| 960 | } |
| 961 | if (mSizeCompatScale != 1f || mSizeCompatBounds != null) { |
| 962 | pw.println(prefix + "mSizeCompatScale=" + mSizeCompatScale + " mSizeCompatBounds=" |
| 963 | + mSizeCompatBounds); |
| 964 | } |
| 965 | if (mRemovingFromDisplay) { |
| 966 | pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay); |
| 967 | } |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 968 | if (lastVisibleTime != 0 || nowVisible) { |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 969 | pw.print(prefix); pw.print("nowVisible="); pw.print(nowVisible); |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 970 | pw.print(" lastVisibleTime="); |
Dianne Hackborn | f530ac3 | 2012-06-21 14:17:48 -0700 | [diff] [blame] | 971 | if (lastVisibleTime == 0) pw.print("0"); |
| 972 | else TimeUtils.formatDuration(lastVisibleTime, now, pw); |
| 973 | pw.println(); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 974 | } |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 975 | if (mDeferHidingClient) { |
| 976 | pw.println(prefix + "mDeferHidingClient=" + mDeferHidingClient); |
| 977 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 978 | if (deferRelaunchUntilPaused || configChangeFlags != 0) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 979 | pw.print(prefix); pw.print("deferRelaunchUntilPaused="); |
| 980 | pw.print(deferRelaunchUntilPaused); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 981 | pw.print(" configChangeFlags="); |
| 982 | pw.println(Integer.toHexString(configChangeFlags)); |
| 983 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 984 | if (mServiceConnectionsHolder != null) { |
| 985 | pw.print(prefix); pw.print("connections="); pw.println(mServiceConnectionsHolder); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 986 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 987 | if (info != null) { |
| 988 | pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode)); |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 989 | pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode |
| 990 | + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 991 | if (info.supportsPictureInPicture()) { |
| 992 | pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture()); |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 993 | pw.println(prefix + "supportsEnterPipOnTaskSwitch: " |
| 994 | + supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 995 | } |
| 996 | if (info.maxAspectRatio != 0) { |
| 997 | pw.println(prefix + "maxAspectRatio=" + info.maxAspectRatio); |
| 998 | } |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 999 | if (info.minAspectRatio != 0) { |
| 1000 | pw.println(prefix + "minAspectRatio=" + info.minAspectRatio); |
| 1001 | } |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1002 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1005 | void setAppTimeTracker(AppTimeTracker att) { |
| 1006 | appTimeTracker = att; |
| 1007 | } |
| 1008 | |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 1009 | /** Update the saved state of an activity. */ |
| 1010 | void setSavedState(@Nullable Bundle savedState) { |
| 1011 | mIcicle = savedState; |
| 1012 | mHaveState = mIcicle != null; |
| 1013 | } |
| 1014 | |
| 1015 | /** |
| 1016 | * Get the actual Bundle instance of the saved state. |
| 1017 | * @see #hasSavedState() for checking if the record has saved state. |
| 1018 | */ |
| 1019 | @Nullable Bundle getSavedState() { |
| 1020 | return mIcicle; |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * Check if the activity has saved state. |
| 1025 | * @return {@code true} if the client reported a non-empty saved state from last onStop(), or |
| 1026 | * if this record was just created and the client is yet to be launched and resumed. |
| 1027 | */ |
| 1028 | boolean hasSavedState() { |
| 1029 | return mHaveState; |
| 1030 | } |
| 1031 | |
| 1032 | /** @return The actual PersistableBundle instance of the saved persistent state. */ |
| 1033 | @Nullable PersistableBundle getPersistentSavedState() { |
| 1034 | return mPersistentState; |
| 1035 | } |
| 1036 | |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 1037 | void updateApplicationInfo(ApplicationInfo aInfo) { |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 1038 | info.applicationInfo = aInfo; |
| 1039 | } |
| 1040 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1041 | private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 1042 | return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp); |
| 1043 | } |
| 1044 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1045 | private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 1046 | return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp); |
| 1047 | } |
| 1048 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1049 | private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 1050 | return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp); |
| 1051 | } |
| 1052 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 1053 | /** |
| 1054 | * The purpose of this method is to decide whether the activity needs to be relaunched upon |
| 1055 | * changing its size. In most cases the activities don't need to be relaunched, if the resize |
| 1056 | * is small, all the activity content has to do is relayout itself within new bounds. There are |
| 1057 | * cases however, where the activity's content would be completely changed in the new size and |
| 1058 | * the full relaunch is required. |
| 1059 | * |
| 1060 | * The activity will report to us vertical and horizontal thresholds after which a relaunch is |
| 1061 | * required. These thresholds are collected from the application resource qualifiers. For |
| 1062 | * example, if application has layout-w600dp resource directory, then it needs a relaunch when |
| 1063 | * we resize from width of 650dp to 550dp, as it crosses the 600dp threshold. However, if |
| 1064 | * it resizes width from 620dp to 700dp, it won't be relaunched as it stays on the same side |
| 1065 | * of the threshold. |
| 1066 | */ |
| 1067 | private static boolean crossesSizeThreshold(int[] thresholds, int firstDp, |
| 1068 | int secondDp) { |
| 1069 | if (thresholds == null) { |
| 1070 | return false; |
| 1071 | } |
| 1072 | for (int i = thresholds.length - 1; i >= 0; i--) { |
| 1073 | final int threshold = thresholds[i]; |
| 1074 | if ((firstDp < threshold && secondDp >= threshold) |
| 1075 | || (firstDp >= threshold && secondDp < threshold)) { |
| 1076 | return true; |
| 1077 | } |
| 1078 | } |
| 1079 | return false; |
| 1080 | } |
| 1081 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1082 | void setSizeConfigurations(int[] horizontalSizeConfiguration, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 1083 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 1084 | mHorizontalSizeConfigurations = horizontalSizeConfiguration; |
| 1085 | mVerticalSizeConfigurations = verticalSizeConfigurations; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 1086 | mSmallestSizeConfigurations = smallestSizeConfigurations; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1089 | private void scheduleActivityMovedToDisplay(int displayId, Configuration config) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1090 | if (!attachedToProcess()) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1091 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.w(TAG, |
| 1092 | "Can't report activity moved to display - client not running, activityRecord=" |
| 1093 | + this + ", displayId=" + displayId); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1094 | return; |
| 1095 | } |
| 1096 | try { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1097 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 1098 | "Reporting activity moved to display" + ", activityRecord=" + this |
| 1099 | + ", displayId=" + displayId + ", config=" + config); |
Chong Zhang | 6be533e | 2016-06-17 16:24:21 -0700 | [diff] [blame] | 1100 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1101 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1102 | MoveToDisplayItem.obtain(displayId, config)); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1103 | } catch (RemoteException e) { |
| 1104 | // If process died, whatever. |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | private void scheduleConfigurationChanged(Configuration config) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1109 | if (!attachedToProcess()) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1110 | if (DEBUG_CONFIGURATION) Slog.w(TAG, |
| 1111 | "Can't report activity configuration update - client not running" |
| 1112 | + ", activityRecord=" + this); |
| 1113 | return; |
| 1114 | } |
| 1115 | try { |
| 1116 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + ", config: " |
| 1117 | + config); |
| 1118 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1119 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1120 | ActivityConfigurationChangeItem.obtain(config)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1121 | } catch (RemoteException e) { |
| 1122 | // If process died, whatever. |
| 1123 | } |
| 1124 | } |
| 1125 | |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 1126 | boolean scheduleTopResumedActivityChanged(boolean onTop) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1127 | if (!attachedToProcess()) { |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1128 | if (DEBUG_STATES) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1129 | Slog.w(TAG, "Can't report activity position update - client not running" |
| 1130 | + ", activityRecord=" + this); |
| 1131 | } |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 1132 | return false; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1133 | } |
| 1134 | try { |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1135 | if (DEBUG_STATES) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1136 | Slog.v(TAG, "Sending position change to " + this + ", onTop: " + onTop); |
| 1137 | } |
| 1138 | |
| 1139 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 1140 | TopResumedActivityChangeItem.obtain(onTop)); |
| 1141 | } catch (RemoteException e) { |
| 1142 | // If process died, whatever. |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 1143 | return false; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1144 | } |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 1145 | return true; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1148 | void updateMultiWindowMode() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1149 | if (task == null || task.getStack() == null || !attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1150 | return; |
| 1151 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1152 | |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 1153 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 1154 | // Don't do anything if we are currently deferring multi-window mode change. |
| 1155 | return; |
| 1156 | } |
| 1157 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1158 | // 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] | 1159 | final boolean inMultiWindowMode = inMultiWindowMode(); |
Winson Chung | 609e1e9 | 2017-05-08 10:52:12 -0700 | [diff] [blame] | 1160 | if (inMultiWindowMode != mLastReportedMultiWindowMode) { |
| 1161 | mLastReportedMultiWindowMode = inMultiWindowMode; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1162 | scheduleMultiWindowModeChanged(getConfiguration()); |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | private void scheduleMultiWindowModeChanged(Configuration overrideConfig) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1167 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1168 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1169 | MultiWindowModeChangeItem.obtain(mLastReportedMultiWindowMode, overrideConfig)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1170 | } catch (Exception e) { |
| 1171 | // If process died, I don't care. |
| 1172 | } |
| 1173 | } |
| 1174 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 1175 | void updatePictureInPictureMode(Rect targetStackBounds, boolean forceUpdate) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1176 | if (task == null || task.getStack() == null || !attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1177 | return; |
| 1178 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1179 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1180 | final boolean inPictureInPictureMode = inPinnedWindowingMode() && targetStackBounds != null; |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 1181 | if (inPictureInPictureMode != mLastReportedPictureInPictureMode || forceUpdate) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1182 | // 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] | 1183 | // update that here in order. Set the last reported MW state to the same as the PiP |
| 1184 | // state since we haven't yet actually resized the task (these callbacks need to |
| 1185 | // preceed the configuration change from the resiez. |
| 1186 | // TODO(110009072): Once we move these callbacks to the client, remove all logic related |
| 1187 | // 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] | 1188 | mLastReportedPictureInPictureMode = inPictureInPictureMode; |
Winson Chung | 059955f | 2018-08-08 16:10:20 -0700 | [diff] [blame] | 1189 | mLastReportedMultiWindowMode = inPictureInPictureMode; |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1190 | final Configuration newConfig = new Configuration(); |
| 1191 | if (targetStackBounds != null && !targetStackBounds.isEmpty()) { |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 1192 | newConfig.setTo(task.getRequestedOverrideConfiguration()); |
| 1193 | Rect outBounds = newConfig.windowConfiguration.getBounds(); |
| 1194 | task.adjustForMinimalTaskDimensions(outBounds, outBounds); |
| 1195 | task.computeConfigResourceOverrides(newConfig, task.getParent().getConfiguration()); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1196 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1197 | schedulePictureInPictureModeChanged(newConfig); |
| 1198 | scheduleMultiWindowModeChanged(newConfig); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | private void schedulePictureInPictureModeChanged(Configuration overrideConfig) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1203 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1204 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1205 | PipModeChangeItem.obtain(mLastReportedPictureInPictureMode, |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1206 | overrideConfig)); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 1207 | } catch (Exception e) { |
| 1208 | // If process died, no one cares. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1212 | Task getTask() { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 1213 | return task; |
| 1214 | } |
| 1215 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1216 | /** |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1217 | * Sets the Task on this activity for the purposes of re-use during launch where we will |
| 1218 | * re-use another activity instead of this one for the launch. |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 1219 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1220 | void setTaskForReuse(Task task) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1221 | this.task = task; |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1224 | ActivityStack getStack() { |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 1225 | return task != null ? task.getStack() : null; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1229 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1230 | final Task oldTask = oldParent != null ? (Task) oldParent : null; |
| 1231 | final Task newTask = newParent != null ? (Task) newParent : null; |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1232 | this.task = newTask; |
| 1233 | |
| 1234 | super.onParentChanged(newParent, oldParent); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1235 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1236 | if (isPersistable()) { |
| 1237 | if (oldTask != null) { |
| 1238 | mAtmService.notifyTaskPersisterLocked(oldTask, false); |
| 1239 | } |
| 1240 | if (newTask != null) { |
| 1241 | mAtmService.notifyTaskPersisterLocked(newTask, false); |
| 1242 | } |
| 1243 | } |
| 1244 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1245 | if (oldParent == null && newParent != null) { |
| 1246 | // First time we are adding the activity to the system. |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1247 | mVoiceInteraction = newTask.voiceSession != null; |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1248 | mInputDispatchingTimeoutNanos = getInputDispatchingTimeoutLocked(this) * 1000000L; |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 1249 | |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1250 | // TODO(b/36505427): Maybe this call should be moved inside |
| 1251 | // updateOverrideConfiguration() |
| 1252 | newTask.updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1253 | // Make sure override configuration is up-to-date before using to create window |
| 1254 | // controller. |
| 1255 | updateSizeCompatMode(); |
| 1256 | // When an activity is started directly into a split-screen fullscreen stack, we need to |
| 1257 | // update the initial multi-window modes so that the callbacks are scheduled correctly |
| 1258 | // when the user leaves that mode. |
| 1259 | mLastReportedMultiWindowMode = inMultiWindowMode(); |
| 1260 | mLastReportedPictureInPictureMode = inPinnedWindowingMode(); |
| 1261 | } |
| 1262 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1263 | // When the associated task is {@code null}, the {@link ActivityRecord} can no longer |
| 1264 | // access visual elements like the {@link DisplayContent}. We must remove any associations |
| 1265 | // such as animations. |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1266 | if (task == null) { |
| 1267 | // It is possible we have been marked as a closing app earlier. We must remove ourselves |
| 1268 | // from this list so we do not participate in any future animations. |
| 1269 | if (getDisplayContent() != null) { |
| 1270 | getDisplayContent().mClosingApps.remove(this); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1271 | } |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 1272 | } else if (mLastParent != null && mLastParent.getStack() != null) { |
| 1273 | task.getStack().mExitingActivities.remove(this); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1274 | } |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1275 | final ActivityStack stack = getStack(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1276 | |
| 1277 | // If we reparent, make sure to remove ourselves from the old animation registry. |
| 1278 | if (mAnimatingActivityRegistry != null) { |
| 1279 | mAnimatingActivityRegistry.notifyFinished(this); |
| 1280 | } |
| 1281 | mAnimatingActivityRegistry = stack != null |
| 1282 | ? stack.getAnimatingActivityRegistry() |
| 1283 | : null; |
| 1284 | |
| 1285 | mLastParent = task; |
| 1286 | |
| 1287 | updateColorTransform(); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1288 | |
| 1289 | final ActivityStack oldStack = (oldTask != null) ? oldTask.getStack() : null; |
| 1290 | final ActivityStack newStack = (newTask != null) ? newTask.getStack() : null; |
| 1291 | // Inform old stack (if present) of activity removal and new stack (if set) of activity |
| 1292 | // addition. |
| 1293 | if (oldStack != newStack) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1294 | if (oldStack != null) { |
| 1295 | oldStack.onActivityRemovedFromStack(this); |
| 1296 | } |
| 1297 | if (newStack != null) { |
| 1298 | newStack.onActivityAddedToStack(this); |
| 1299 | } |
| 1300 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | private void updateColorTransform() { |
| 1304 | if (mSurfaceControl != null && mLastAppSaturationInfo != null) { |
| 1305 | getPendingTransaction().setColorTransform(mSurfaceControl, |
| 1306 | mLastAppSaturationInfo.mMatrix, mLastAppSaturationInfo.mTranslation); |
| 1307 | mWmService.scheduleAnimationLocked(); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | @Override |
| 1312 | void onDisplayChanged(DisplayContent dc) { |
| 1313 | DisplayContent prevDc = mDisplayContent; |
| 1314 | super.onDisplayChanged(dc); |
| 1315 | if (prevDc == null || prevDc == mDisplayContent) { |
| 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | if (prevDc.mOpeningApps.remove(this)) { |
| 1320 | // Transfer opening transition to new display. |
| 1321 | mDisplayContent.mOpeningApps.add(this); |
| 1322 | mDisplayContent.prepareAppTransition(prevDc.mAppTransition.getAppTransition(), true); |
| 1323 | mDisplayContent.executeAppTransition(); |
| 1324 | } |
| 1325 | |
| 1326 | if (prevDc.mChangingApps.remove(this)) { |
| 1327 | // This gets called *after* the ActivityRecord has been reparented to the new display. |
| 1328 | // That reparenting resulted in this window changing modes (eg. FREEFORM -> FULLSCREEN), |
| 1329 | // so this token is now "frozen" while waiting for the animation to start on prevDc |
| 1330 | // (which will be cancelled since the window is no-longer a child). However, since this |
| 1331 | // is no longer a child of prevDc, this won't be notified of the cancelled animation, |
| 1332 | // so we need to cancel the change transition here. |
| 1333 | clearChangeLeash(getPendingTransaction(), true /* cancel */); |
| 1334 | } |
| 1335 | prevDc.mClosingApps.remove(this); |
| 1336 | |
| 1337 | if (prevDc.mFocusedApp == this) { |
| 1338 | prevDc.setFocusedApp(null); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1339 | if (dc.getTopMostActivity() == this) { |
| 1340 | dc.setFocusedApp(this); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | if (mLetterbox != null) { |
| 1345 | mLetterbox.onMovedToDisplay(mDisplayContent.getDisplayId()); |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | void layoutLetterbox(WindowState winHint) { |
| 1350 | final WindowState w = findMainWindow(); |
| 1351 | if (w == null || winHint != null && w != winHint) { |
| 1352 | return; |
| 1353 | } |
| 1354 | final boolean surfaceReady = w.isDrawnLw() // Regular case |
| 1355 | || w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready. |
| 1356 | || w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface. |
| 1357 | final boolean needsLetterbox = surfaceReady && w.isLetterboxedAppWindow() && fillsParent(); |
| 1358 | if (needsLetterbox) { |
| 1359 | if (mLetterbox == null) { |
| 1360 | mLetterbox = new Letterbox(() -> makeChildSurface(null), |
| 1361 | mWmService.mTransactionFactory); |
| 1362 | mLetterbox.attachInput(w); |
| 1363 | } |
| 1364 | getPosition(mTmpPoint); |
| 1365 | // Get the bounds of the "space-to-fill". In multi-window mode, the task-level |
| 1366 | // represents this. In fullscreen-mode, the stack does (since the orientation letterbox |
| 1367 | // is also applied to the task). |
| 1368 | Rect spaceToFill = (inMultiWindowMode() || getStack() == null) |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1369 | ? task.getDisplayedBounds() : getStack().getDisplayedBounds(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1370 | mLetterbox.layout(spaceToFill, w.getFrameLw(), mTmpPoint); |
| 1371 | } else if (mLetterbox != null) { |
| 1372 | mLetterbox.hide(); |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | void updateLetterboxSurface(WindowState winHint) { |
| 1377 | final WindowState w = findMainWindow(); |
| 1378 | if (w != winHint && winHint != null && w != null) { |
| 1379 | return; |
| 1380 | } |
| 1381 | layoutLetterbox(winHint); |
| 1382 | if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) { |
| 1383 | mLetterbox.applySurfaceChanges(getPendingTransaction()); |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | Rect getLetterboxInsets() { |
| 1388 | if (mLetterbox != null) { |
| 1389 | return mLetterbox.getInsets(); |
| 1390 | } else { |
| 1391 | return new Rect(); |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | /** Gets the inner bounds of letterbox. The bounds will be empty if there is no letterbox. */ |
| 1396 | void getLetterboxInnerBounds(Rect outBounds) { |
| 1397 | if (mLetterbox != null) { |
| 1398 | outBounds.set(mLetterbox.getInnerFrame()); |
| 1399 | } else { |
| 1400 | outBounds.setEmpty(); |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | /** |
| 1405 | * @return {@code true} if there is a letterbox and any part of that letterbox overlaps with |
| 1406 | * the given {@code rect}. |
| 1407 | */ |
| 1408 | boolean isLetterboxOverlappingWith(Rect rect) { |
| 1409 | return mLetterbox != null && mLetterbox.isOverlappingWith(rect); |
| 1410 | } |
| 1411 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1412 | static class Token extends IApplicationToken.Stub { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1413 | private WeakReference<ActivityRecord> weakActivity; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1414 | private final String name; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1415 | private final String tokenString; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1416 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1417 | Token(Intent intent) { |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1418 | name = intent.getComponent().flattenToShortString(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1419 | tokenString = "Token{" + Integer.toHexString(System.identityHashCode(this)) + "}"; |
| 1420 | } |
| 1421 | |
| 1422 | private void attach(ActivityRecord activity) { |
| 1423 | if (weakActivity != null) { |
| 1424 | throw new IllegalStateException("Already attached..." + this); |
| 1425 | } |
| 1426 | weakActivity = new WeakReference<>(activity); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
Charles Chen | 69362cd | 2019-03-29 15:18:45 +0800 | [diff] [blame] | 1429 | private static @Nullable ActivityRecord tokenToActivityRecordLocked(Token token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1430 | if (token == null) { |
| 1431 | return null; |
| 1432 | } |
| 1433 | ActivityRecord r = token.weakActivity.get(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1434 | if (r == null || r.getActivityStack() == null) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1435 | return null; |
| 1436 | } |
| 1437 | return r; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1438 | } |
| 1439 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1440 | @Override |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1441 | public String toString() { |
| 1442 | StringBuilder sb = new StringBuilder(128); |
| 1443 | sb.append("Token{"); |
| 1444 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1445 | sb.append(' '); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1446 | if (weakActivity != null) { |
| 1447 | sb.append(weakActivity.get()); |
| 1448 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1449 | sb.append('}'); |
| 1450 | return sb.toString(); |
| 1451 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1452 | |
| 1453 | @Override |
| 1454 | public String getName() { |
| 1455 | return name; |
| 1456 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1457 | } |
| 1458 | |
Charles Chen | 69362cd | 2019-03-29 15:18:45 +0800 | [diff] [blame] | 1459 | static @Nullable ActivityRecord forTokenLocked(IBinder token) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1460 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1461 | return Token.tokenToActivityRecordLocked((Token)token); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1462 | } catch (ClassCastException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1463 | Slog.w(TAG, "Bad activity token: " + token, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1464 | return null; |
| 1465 | } |
| 1466 | } |
| 1467 | |
Riddle Hsu | ff9e828 | 2019-04-24 23:55:11 +0800 | [diff] [blame] | 1468 | static boolean isResolverActivity(String className) { |
| 1469 | return ResolverActivity.class.getName().equals(className); |
| 1470 | } |
| 1471 | |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 1472 | boolean isResolverOrDelegateActivity() { |
| 1473 | return isResolverActivity(mActivityComponent.getClassName()) || Objects.equals( |
| 1474 | mActivityComponent, mAtmService.mStackSupervisor.getSystemChooserActivity()); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 1477 | boolean isResolverOrChildActivity() { |
| 1478 | if (!"android".equals(packageName)) { |
| 1479 | return false; |
| 1480 | } |
| 1481 | try { |
| 1482 | return ResolverActivity.class.isAssignableFrom( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1483 | Object.class.getClassLoader().loadClass(mActivityComponent.getClassName())); |
Patrick Baumann | 31426b2 | 2018-05-21 13:46:40 -0700 | [diff] [blame] | 1484 | } catch (ClassNotFoundException e) { |
| 1485 | return false; |
| 1486 | } |
| 1487 | } |
| 1488 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1489 | ActivityRecord(ActivityTaskManagerService _service, WindowProcessController _caller, |
| 1490 | int _launchedFromPid, int _launchedFromUid, String _launchedFromPackage, Intent _intent, |
| 1491 | String _resolvedType, ActivityInfo aInfo, Configuration _configuration, |
| 1492 | ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified, |
| 1493 | boolean _rootVoiceInteraction, ActivityStackSupervisor supervisor, |
| 1494 | ActivityOptions options, ActivityRecord sourceRecord) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1495 | super(_service.mWindowManager, new Token(_intent).asBinder(), TYPE_APPLICATION, true, |
| 1496 | null /* displayContent */, false /* ownerCanManageAppTokens */); |
| 1497 | |
| 1498 | mAtmService = _service; |
| 1499 | appToken = (Token) token; |
| 1500 | info = aInfo; |
| 1501 | mUserId = UserHandle.getUserId(info.applicationInfo.uid); |
| 1502 | packageName = info.applicationInfo.packageName; |
| 1503 | mInputApplicationHandle = new InputApplicationHandle(appToken); |
| 1504 | intent = _intent; |
| 1505 | |
| 1506 | // If the class name in the intent doesn't match that of the target, this is probably an |
| 1507 | // alias. We have to create a new ComponentName object to keep track of the real activity |
| 1508 | // name, so that FLAG_ACTIVITY_CLEAR_TOP is handled properly. |
| 1509 | if (info.targetActivity == null |
| 1510 | || (info.targetActivity.equals(intent.getComponent().getClassName()) |
| 1511 | && (info.launchMode == LAUNCH_MULTIPLE |
| 1512 | || info.launchMode == LAUNCH_SINGLE_TOP))) { |
| 1513 | mActivityComponent = intent.getComponent(); |
| 1514 | } else { |
| 1515 | mActivityComponent = |
| 1516 | new ComponentName(info.packageName, info.targetActivity); |
| 1517 | } |
| 1518 | |
| 1519 | mTargetSdk = info.applicationInfo.targetSdkVersion; |
| 1520 | mShowForAllUsers = (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0; |
| 1521 | setOrientation(info.screenOrientation); |
| 1522 | mRotationAnimationHint = info.rotationAnimation; |
| 1523 | |
| 1524 | mShowWhenLocked = (aInfo.flags & ActivityInfo.FLAG_SHOW_WHEN_LOCKED) != 0; |
| 1525 | mInheritShownWhenLocked = (aInfo.privateFlags & FLAG_INHERIT_SHOW_WHEN_LOCKED) != 0; |
| 1526 | mTurnScreenOn = (aInfo.flags & FLAG_TURN_SCREEN_ON) != 0; |
| 1527 | |
| 1528 | int realTheme = info.getThemeResource(); |
| 1529 | if (realTheme == Resources.ID_NULL) { |
| 1530 | realTheme = aInfo.applicationInfo.targetSdkVersion < HONEYCOMB |
| 1531 | ? android.R.style.Theme : android.R.style.Theme_Holo; |
| 1532 | } |
| 1533 | |
| 1534 | final AttributeCache.Entry ent = AttributeCache.instance().get(packageName, |
| 1535 | realTheme, com.android.internal.R.styleable.Window, mUserId); |
| 1536 | |
| 1537 | if (ent != null) { |
| 1538 | mOccludesParent = !ActivityInfo.isTranslucentOrFloating(ent.array); |
| 1539 | hasWallpaper = ent.array.getBoolean(R.styleable.Window_windowShowWallpaper, false); |
| 1540 | noDisplay = ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false); |
| 1541 | } else { |
| 1542 | hasWallpaper = false; |
| 1543 | noDisplay = false; |
| 1544 | } |
| 1545 | |
| 1546 | if (options != null) { |
| 1547 | mLaunchTaskBehind = options.getLaunchTaskBehind(); |
| 1548 | |
| 1549 | final int rotationAnimation = options.getRotationAnimationHint(); |
| 1550 | // Only override manifest supplied option if set. |
| 1551 | if (rotationAnimation >= 0) { |
| 1552 | mRotationAnimationHint = rotationAnimation; |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | // Application tokens start out hidden. |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 1557 | setVisible(false); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 1558 | mVisibleRequested = false; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1559 | |
| 1560 | ColorDisplayService.ColorDisplayServiceInternal cds = LocalServices.getService( |
| 1561 | ColorDisplayService.ColorDisplayServiceInternal.class); |
| 1562 | cds.attachColorTransformController(packageName, mUserId, |
| 1563 | new WeakReference<>(mColorTransformController)); |
| 1564 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1565 | appToken.attach(this); |
| 1566 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1567 | mRootWindowContainer = _service.mRootWindowContainer; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1568 | launchedFromPid = _launchedFromPid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | launchedFromUid = _launchedFromUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1570 | launchedFromPackage = _launchedFromPackage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | shortComponentName = _intent.getComponent().flattenToShortString(); |
| 1572 | resolvedType = _resolvedType; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1573 | componentSpecified = _componentSpecified; |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 1574 | rootVoiceInteraction = _rootVoiceInteraction; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 1575 | mLastReportedConfiguration = new MergedConfiguration(_configuration); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | resultTo = _resultTo; |
| 1577 | resultWho = _resultWho; |
| 1578 | requestCode = _reqCode; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1579 | setState(INITIALIZING, "ActivityRecord ctor"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | launchFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | stopped = false; |
Dianne Hackborn | 95fc68f | 2009-05-19 18:37:45 -0700 | [diff] [blame] | 1582 | delayedResume = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | finishing = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1584 | deferRelaunchUntilPaused = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | keysPaused = false; |
| 1586 | inHistory = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | nowVisible = false; |
Vishnu Nair | 9ba3165 | 2018-11-13 14:34:05 -0800 | [diff] [blame] | 1588 | mDrawn = false; |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 1589 | mClientVisible = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | idle = false; |
| 1591 | hasBeenLaunched = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1592 | mStackSupervisor = supervisor; |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 1593 | |
Charles Chen | f365d3a | 2019-11-14 17:22:05 +0800 | [diff] [blame] | 1594 | // b/35954083: Limit task affinity to uid to avoid various issues associated with sharing |
| 1595 | // affinity across uids. |
| 1596 | final String uid = Integer.toString(info.applicationInfo.uid); |
| 1597 | if (info.taskAffinity != null && !info.taskAffinity.startsWith(uid)) { |
| 1598 | info.taskAffinity = uid + ":" + info.taskAffinity; |
| 1599 | } |
| 1600 | taskAffinity = info.taskAffinity; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1601 | stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1602 | nonLocalizedLabel = aInfo.nonLocalizedLabel; |
| 1603 | labelRes = aInfo.labelRes; |
| 1604 | if (nonLocalizedLabel == null && labelRes == 0) { |
| 1605 | ApplicationInfo app = aInfo.applicationInfo; |
| 1606 | nonLocalizedLabel = app.nonLocalizedLabel; |
| 1607 | labelRes = app.labelRes; |
| 1608 | } |
| 1609 | icon = aInfo.getIconResource(); |
| 1610 | logo = aInfo.getLogoResource(); |
| 1611 | theme = aInfo.getThemeResource(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1612 | if ((aInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
| 1613 | windowFlags |= LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1614 | } |
| 1615 | if ((aInfo.flags & FLAG_MULTIPROCESS) != 0 && _caller != null |
| 1616 | && (aInfo.applicationInfo.uid == SYSTEM_UID |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1617 | || aInfo.applicationInfo.uid == _caller.mInfo.uid)) { |
| 1618 | processName = _caller.mName; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1619 | } else { |
| 1620 | processName = aInfo.processName; |
| 1621 | } |
| 1622 | |
| 1623 | if ((aInfo.flags & FLAG_EXCLUDE_FROM_RECENTS) != 0) { |
| 1624 | intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 1625 | } |
| 1626 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1627 | launchMode = aInfo.launchMode; |
| 1628 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 1629 | setActivityType(_componentSpecified, _launchedFromUid, _intent, options, sourceRecord); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1630 | |
| 1631 | immersive = (aInfo.flags & FLAG_IMMERSIVE) != 0; |
| 1632 | |
| 1633 | requestedVrComponent = (aInfo.requestedVrComponent == null) ? |
| 1634 | null : ComponentName.unflattenFromString(aInfo.requestedVrComponent); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1635 | |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1636 | lockTaskLaunchMode = aInfo.lockTaskLaunchMode; |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 1637 | if (info.applicationInfo.isPrivilegedApp() |
| 1638 | && (lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_ALWAYS |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1639 | || lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_NEVER)) { |
| 1640 | lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_DEFAULT; |
| 1641 | } |
| 1642 | |
| 1643 | if (options != null) { |
| 1644 | pendingOptions = options; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1645 | final PendingIntent usageReport = pendingOptions.getUsageTimeReport(); |
| 1646 | if (usageReport != null) { |
| 1647 | appTimeTracker = new AppTimeTracker(usageReport); |
| 1648 | } |
| 1649 | final boolean useLockTask = pendingOptions.getLockTaskMode(); |
| 1650 | if (useLockTask && lockTaskLaunchMode == LOCK_TASK_LAUNCH_MODE_DEFAULT) { |
| 1651 | lockTaskLaunchMode = LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED; |
| 1652 | } |
Louis Chang | d58cb67 | 2018-12-24 17:45:16 +0800 | [diff] [blame] | 1653 | // Gets launch display id from options. It returns INVALID_DISPLAY if not set. |
| 1654 | mHandoverLaunchDisplayId = options.getLaunchDisplayId(); |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1655 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1656 | } |
| 1657 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1658 | @Override |
| 1659 | ActivityRecord asActivityRecord() { |
| 1660 | // I am an activity record! |
| 1661 | return this; |
| 1662 | } |
| 1663 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1664 | @Override |
| 1665 | boolean hasActivity() { |
| 1666 | // I am an activity! |
| 1667 | return true; |
| 1668 | } |
| 1669 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1670 | void setProcess(WindowProcessController proc) { |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1671 | app = proc; |
| 1672 | final ActivityRecord root = task != null ? task.getRootActivity() : null; |
| 1673 | if (root == this) { |
| 1674 | task.setRootProcess(proc); |
| 1675 | } |
| 1676 | } |
| 1677 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1678 | boolean hasProcess() { |
| 1679 | return app != null; |
| 1680 | } |
| 1681 | |
| 1682 | boolean attachedToProcess() { |
| 1683 | return hasProcess() && app.hasThread(); |
| 1684 | } |
| 1685 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1686 | boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo, |
| 1687 | CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, |
| 1688 | IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning, |
| 1689 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1690 | // If the display is frozen, we won't do anything until the actual window is |
| 1691 | // displayed so there is no reason to put in the starting window. |
| 1692 | if (!okToDisplay()) { |
Yunfan Chen | 48c0ed08 | 2018-12-05 18:15:35 -0800 | [diff] [blame] | 1693 | return false; |
| 1694 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1695 | |
| 1696 | if (mStartingData != null) { |
| 1697 | return false; |
| 1698 | } |
| 1699 | |
| 1700 | final WindowState mainWin = findMainWindow(); |
| 1701 | if (mainWin != null && mainWin.mWinAnimator.getShown()) { |
| 1702 | // App already has a visible window...why would you want a starting window? |
| 1703 | return false; |
| 1704 | } |
| 1705 | |
| 1706 | final ActivityManager.TaskSnapshot snapshot = |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1707 | mWmService.mTaskSnapshotController.getSnapshot(task.mTaskId, task.mUserId, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1708 | false /* restoreFromDisk */, false /* reducedResolution */); |
| 1709 | final int type = getStartingWindowType(newTask, taskSwitch, processRunning, |
| 1710 | allowTaskSnapshot, activityCreated, fromRecents, snapshot); |
| 1711 | |
| 1712 | if (type == STARTING_WINDOW_TYPE_SNAPSHOT) { |
Riddle Hsu | 440f88b | 2019-11-06 22:17:35 +0800 | [diff] [blame] | 1713 | if (isActivityTypeHome()) { |
| 1714 | // The snapshot of home is only used once because it won't be updated while screen |
| 1715 | // is on (see {@link TaskSnapshotController#screenTurningOff}). |
| 1716 | mWmService.mTaskSnapshotController.removeSnapshotCache(task.mTaskId); |
| 1717 | // TODO(b/9684093): Use more general condition to specify the case. |
| 1718 | if (mDisplayContent.mAppTransition |
| 1719 | .getAppTransition() != WindowManager.TRANSIT_KEYGUARD_GOING_AWAY) { |
| 1720 | // Only use snapshot of home as starting window when unlocking. |
| 1721 | return false; |
| 1722 | } |
| 1723 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1724 | return createSnapshot(snapshot); |
| 1725 | } |
| 1726 | |
| 1727 | // If this is a translucent window, then don't show a starting window -- the current |
| 1728 | // effect (a full-screen opaque starting window that fades away to the real contents |
| 1729 | // when it is ready) does not work for this. |
| 1730 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Checking theme of starting window: 0x%x", theme); |
| 1731 | if (theme != 0) { |
| 1732 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 1733 | com.android.internal.R.styleable.Window, |
| 1734 | mWmService.mCurrentUserId); |
| 1735 | if (ent == null) { |
| 1736 | // Whoops! App doesn't exist. Um. Okay. We'll just pretend like we didn't |
| 1737 | // see that. |
| 1738 | return false; |
| 1739 | } |
| 1740 | final boolean windowIsTranslucent = ent.array.getBoolean( |
| 1741 | com.android.internal.R.styleable.Window_windowIsTranslucent, false); |
| 1742 | final boolean windowIsFloating = ent.array.getBoolean( |
| 1743 | com.android.internal.R.styleable.Window_windowIsFloating, false); |
| 1744 | final boolean windowShowWallpaper = ent.array.getBoolean( |
| 1745 | com.android.internal.R.styleable.Window_windowShowWallpaper, false); |
| 1746 | final boolean windowDisableStarting = ent.array.getBoolean( |
| 1747 | com.android.internal.R.styleable.Window_windowDisablePreview, false); |
| 1748 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Translucent=%s Floating=%s ShowWallpaper=%s", |
| 1749 | windowIsTranslucent, windowIsFloating, windowShowWallpaper); |
| 1750 | if (windowIsTranslucent) { |
| 1751 | return false; |
| 1752 | } |
| 1753 | if (windowIsFloating || windowDisableStarting) { |
| 1754 | return false; |
| 1755 | } |
| 1756 | if (windowShowWallpaper) { |
| 1757 | if (getDisplayContent().mWallpaperController |
| 1758 | .getWallpaperTarget() == null) { |
| 1759 | // If this theme is requesting a wallpaper, and the wallpaper |
| 1760 | // is not currently visible, then this effectively serves as |
| 1761 | // an opaque window and our starting window transition animation |
| 1762 | // can still work. We just need to make sure the starting window |
| 1763 | // is also showing the wallpaper. |
| 1764 | windowFlags |= FLAG_SHOW_WALLPAPER; |
| 1765 | } else { |
| 1766 | return false; |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | if (transferStartingWindow(transferFrom)) { |
| 1772 | return true; |
| 1773 | } |
| 1774 | |
| 1775 | // There is no existing starting window, and we don't want to create a splash screen, so |
| 1776 | // that's it! |
| 1777 | if (type != STARTING_WINDOW_TYPE_SPLASH_SCREEN) { |
| 1778 | return false; |
| 1779 | } |
| 1780 | |
| 1781 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Creating SplashScreenStartingData"); |
| 1782 | mStartingData = new SplashScreenStartingData(mWmService, pkg, |
| 1783 | theme, compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
| 1784 | getMergedOverrideConfiguration()); |
| 1785 | scheduleAddStartingWindow(); |
| 1786 | return true; |
| 1787 | } |
| 1788 | |
| 1789 | private boolean createSnapshot(ActivityManager.TaskSnapshot snapshot) { |
| 1790 | if (snapshot == null) { |
| 1791 | return false; |
| 1792 | } |
| 1793 | |
| 1794 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Creating SnapshotStartingData"); |
| 1795 | mStartingData = new SnapshotStartingData(mWmService, snapshot); |
| 1796 | scheduleAddStartingWindow(); |
| 1797 | return true; |
| 1798 | } |
| 1799 | |
| 1800 | void scheduleAddStartingWindow() { |
| 1801 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 1802 | // want to process the message ASAP, before any other queued |
| 1803 | // messages. |
| 1804 | if (!mWmService.mAnimationHandler.hasCallbacks(mAddStartingWindow)) { |
| 1805 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Enqueueing ADD_STARTING"); |
| 1806 | mWmService.mAnimationHandler.postAtFrontOfQueue(mAddStartingWindow); |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | private class AddStartingWindow implements Runnable { |
| 1811 | |
| 1812 | @Override |
| 1813 | public void run() { |
| 1814 | // Can be accessed without holding the global lock |
| 1815 | final StartingData startingData; |
| 1816 | synchronized (mWmService.mGlobalLock) { |
| 1817 | // There can only be one adding request, silly caller! |
| 1818 | mWmService.mAnimationHandler.removeCallbacks(this); |
| 1819 | |
| 1820 | if (mStartingData == null) { |
| 1821 | // Animation has been canceled... do nothing. |
| 1822 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, |
| 1823 | "startingData was nulled out before handling" |
| 1824 | + " mAddStartingWindow: %s", ActivityRecord.this); |
| 1825 | return; |
| 1826 | } |
| 1827 | startingData = mStartingData; |
| 1828 | } |
| 1829 | |
| 1830 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Add starting %s: startingData=%s", |
| 1831 | this, startingData); |
| 1832 | |
| 1833 | |
| 1834 | WindowManagerPolicy.StartingSurface surface = null; |
| 1835 | try { |
| 1836 | surface = startingData.createStartingSurface(ActivityRecord.this); |
| 1837 | } catch (Exception e) { |
| 1838 | Slog.w(TAG, "Exception when adding starting window", e); |
| 1839 | } |
| 1840 | if (surface != null) { |
| 1841 | boolean abort = false; |
| 1842 | synchronized (mWmService.mGlobalLock) { |
Wale Ogunwale | 7a8889a | 2019-11-16 08:23:42 -0800 | [diff] [blame] | 1843 | // If the window was successfully added, then we need to remove it. |
| 1844 | if (mStartingData == null) { |
| 1845 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Aborted starting %s: startingData=%s", |
| 1846 | ActivityRecord.this, mStartingData); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1847 | |
| 1848 | startingWindow = null; |
| 1849 | mStartingData = null; |
| 1850 | abort = true; |
| 1851 | } else { |
| 1852 | startingSurface = surface; |
| 1853 | } |
| 1854 | if (!abort) { |
| 1855 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, |
| 1856 | "Added starting %s: startingWindow=%s startingView=%s", |
| 1857 | ActivityRecord.this, startingWindow, startingSurface); |
| 1858 | } |
| 1859 | } |
| 1860 | if (abort) { |
| 1861 | surface.remove(); |
| 1862 | } |
| 1863 | } else { |
| 1864 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Surface returned was null: %s", |
| 1865 | ActivityRecord.this); |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | private final AddStartingWindow mAddStartingWindow = new AddStartingWindow(); |
| 1871 | |
| 1872 | private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning, |
| 1873 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents, |
| 1874 | ActivityManager.TaskSnapshot snapshot) { |
| 1875 | if (getDisplayContent().mAppTransition.getAppTransition() |
| 1876 | == TRANSIT_DOCK_TASK_FROM_RECENTS) { |
| 1877 | // TODO(b/34099271): Remove this statement to add back the starting window and figure |
| 1878 | // out why it causes flickering, the starting window appears over the thumbnail while |
| 1879 | // the docked from recents transition occurs |
| 1880 | return STARTING_WINDOW_TYPE_NONE; |
| 1881 | } else if (newTask || !processRunning || (taskSwitch && !activityCreated)) { |
| 1882 | return STARTING_WINDOW_TYPE_SPLASH_SCREEN; |
| 1883 | } else if (taskSwitch && allowTaskSnapshot) { |
Jorim Jaggi | 5cb681b | 2019-12-20 11:36:30 +0000 | [diff] [blame] | 1884 | return snapshot == null ? STARTING_WINDOW_TYPE_NONE |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1885 | : snapshotOrientationSameAsTask(snapshot) || fromRecents |
| 1886 | ? STARTING_WINDOW_TYPE_SNAPSHOT : STARTING_WINDOW_TYPE_SPLASH_SCREEN; |
| 1887 | } else { |
| 1888 | return STARTING_WINDOW_TYPE_NONE; |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | private boolean snapshotOrientationSameAsTask(ActivityManager.TaskSnapshot snapshot) { |
| 1893 | if (snapshot == null) { |
| 1894 | return false; |
| 1895 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1896 | return task.getConfiguration().orientation == snapshot.getOrientation(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | void removeStartingWindow() { |
| 1900 | if (startingWindow == null) { |
| 1901 | if (mStartingData != null) { |
| 1902 | // Starting window has not been added yet, but it is scheduled to be added. |
| 1903 | // Go ahead and cancel the request. |
| 1904 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Clearing startingData for token=%s", this); |
| 1905 | mStartingData = null; |
| 1906 | } |
| 1907 | return; |
| 1908 | } |
| 1909 | |
| 1910 | final WindowManagerPolicy.StartingSurface surface; |
| 1911 | if (mStartingData != null) { |
| 1912 | surface = startingSurface; |
| 1913 | mStartingData = null; |
| 1914 | startingSurface = null; |
| 1915 | startingWindow = null; |
| 1916 | startingDisplayed = false; |
| 1917 | if (surface == null) { |
| 1918 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, |
| 1919 | "startingWindow was set but startingSurface==null, couldn't " |
| 1920 | + "remove"); |
| 1921 | |
| 1922 | return; |
| 1923 | } |
| 1924 | } else { |
| 1925 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, |
| 1926 | "Tried to remove starting window but startingWindow was null: %s", |
| 1927 | this); |
| 1928 | return; |
| 1929 | } |
| 1930 | |
| 1931 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Schedule remove starting %s startingWindow=%s" |
| 1932 | + " startingView=%s Callers=%s", |
| 1933 | this, startingWindow, startingSurface, Debug.getCallers(5)); |
| 1934 | |
| 1935 | |
| 1936 | // Use the same thread to remove the window as we used to add it, as otherwise we end up |
| 1937 | // with things in the view hierarchy being called from different threads. |
| 1938 | mWmService.mAnimationHandler.post(() -> { |
| 1939 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Removing startingView=%s", surface); |
| 1940 | try { |
| 1941 | surface.remove(); |
| 1942 | } catch (Exception e) { |
| 1943 | Slog.w(TAG_WM, "Exception when removing starting window", e); |
| 1944 | } |
| 1945 | }); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1946 | } |
| 1947 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1948 | private void removeAppTokenFromDisplay() { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1949 | if (mWmService.mRoot == null) return; |
Yunfan Chen | d4ef301 | 2018-11-28 21:14:32 -0800 | [diff] [blame] | 1950 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1951 | final DisplayContent dc = mWmService.mRoot.getDisplayContent(getDisplayId()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1952 | if (dc == null) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1953 | Slog.w(TAG, "removeAppTokenFromDisplay: Attempted to remove token: " |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1954 | + appToken + " from non-existing displayId=" + getDisplayId()); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1955 | return; |
| 1956 | } |
Wale Ogunwale | cc367f4 | 2017-02-01 08:12:14 -0800 | [diff] [blame] | 1957 | // Resume key dispatching if it is currently paused before we remove the container. |
| 1958 | resumeKeyDispatchingLocked(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1959 | dc.removeAppToken(appToken.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1960 | } |
| 1961 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1962 | /** |
| 1963 | * Reparents this activity into {@param newTask} at the provided {@param position}. The caller |
| 1964 | * should ensure that the {@param newTask} is not already the parent of this activity. |
| 1965 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1966 | void reparent(Task newTask, int position, String reason) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1967 | if (getParent() == null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 1968 | Slog.w(TAG, "reparent: Attempted to reparent non-existing app token: " + appToken); |
| 1969 | return; |
| 1970 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1971 | final Task prevTask = task; |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1972 | if (prevTask == newTask) { |
| 1973 | throw new IllegalArgumentException(reason + ": task=" + newTask |
| 1974 | + " is already the parent of r=" + this); |
| 1975 | } |
| 1976 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1977 | // TODO: Ensure that we do not directly reparent activities across stacks, as that may leave |
| 1978 | // the stacks in strange states. For now, we should use Task.reparent() to ensure that |
| 1979 | // the stack is left in an OK state. |
| 1980 | if (prevTask != null && newTask != null && prevTask.getStack() != newTask.getStack()) { |
| 1981 | throw new IllegalArgumentException(reason + ": task=" + newTask |
| 1982 | + " is in a different stack (" + newTask.getStackId() + ") than the parent of" |
| 1983 | + " r=" + this + " (" + prevTask.getStackId() + ")"); |
| 1984 | } |
| 1985 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 1986 | ProtoLog.i(WM_DEBUG_ADD_REMOVE, "reparent: moving activity=%s" |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1987 | + " to task=%d at %d", this, task.mTaskId, position); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1988 | reparent(newTask, position); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 1989 | } |
| 1990 | |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1991 | private boolean isHomeIntent(Intent intent) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 1992 | return ACTION_MAIN.equals(intent.getAction()) |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 1993 | && (intent.hasCategory(CATEGORY_HOME) |
| 1994 | || intent.hasCategory(CATEGORY_SECONDARY_HOME)) |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 1995 | && intent.getCategories().size() == 1 |
| 1996 | && intent.getData() == null |
| 1997 | && intent.getType() == null; |
| 1998 | } |
| 1999 | |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 2000 | static boolean isMainIntent(Intent intent) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2001 | return ACTION_MAIN.equals(intent.getAction()) |
| 2002 | && intent.hasCategory(CATEGORY_LAUNCHER) |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 2003 | && intent.getCategories().size() == 1 |
| 2004 | && intent.getData() == null |
| 2005 | && intent.getType() == null; |
| 2006 | } |
| 2007 | |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 2008 | @VisibleForTesting |
| 2009 | boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) { |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 2010 | if (uid == Process.myUid() || uid == 0) { |
| 2011 | // System process can launch home activity. |
| 2012 | return true; |
| 2013 | } |
Winson Chung | 547afd2 | 2018-05-17 16:03:25 -0700 | [diff] [blame] | 2014 | // Allow the recents component to launch the home activity. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2015 | final RecentTasks recentTasks = mStackSupervisor.mService.getRecentTasks(); |
Winson Chung | 547afd2 | 2018-05-17 16:03:25 -0700 | [diff] [blame] | 2016 | if (recentTasks != null && recentTasks.isCallerRecents(uid)) { |
| 2017 | return true; |
| 2018 | } |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 2019 | // Resolver or system chooser activity can launch home activity. |
| 2020 | return sourceRecord != null && sourceRecord.isResolverOrDelegateActivity(); |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2023 | /** |
| 2024 | * @return whether the given package name can launch an assist activity. |
| 2025 | */ |
| 2026 | private boolean canLaunchAssistActivity(String packageName) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2027 | final ComponentName assistComponent = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2028 | mAtmService.mActiveVoiceInteractionServiceComponent; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2029 | if (assistComponent != null) { |
| 2030 | return assistComponent.getPackageName().equals(packageName); |
| 2031 | } |
| 2032 | return false; |
| 2033 | } |
| 2034 | |
| 2035 | private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent, |
| 2036 | ActivityOptions options, ActivityRecord sourceRecord) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2037 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 2038 | if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord)) |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 2039 | && isHomeIntent(intent) && !isResolverOrDelegateActivity()) { |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 2040 | // This sure looks like a home activity! |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2041 | activityType = ACTIVITY_TYPE_HOME; |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 2042 | |
| 2043 | if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE |
| 2044 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 2045 | // We only allow home activities to be resizeable if they explicitly requested it. |
| 2046 | info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
| 2047 | } |
Andrii Kulian | 3b3fb66 | 2019-06-26 17:52:26 -0700 | [diff] [blame] | 2048 | } else if (mAtmService.getRecentTasks().isRecentsComponent(mActivityComponent, |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 2049 | info.applicationInfo.uid)) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2050 | activityType = ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2051 | } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_ASSISTANT |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 2052 | && canLaunchAssistActivity(launchedFromPackage)) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2053 | activityType = ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 2054 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2055 | setActivityType(activityType); |
Wale Ogunwale | 1affbbc | 2016-05-01 09:03:52 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2058 | void setTaskToAffiliateWith(Task taskToAffiliateWith) { |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 2059 | if (launchMode != LAUNCH_SINGLE_INSTANCE && launchMode != LAUNCH_SINGLE_TASK) { |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2060 | task.setTaskToAffiliateWith(taskToAffiliateWith); |
| 2061 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2064 | /** |
| 2065 | * @return Stack value from current task, null if there is no task. |
| 2066 | */ |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2067 | ActivityStack getActivityStack() { |
| 2068 | return task != null ? task.getStack() : null; |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 2071 | int getStackId() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2072 | return getActivityStack() != null ? getActivityStack().mStackId : INVALID_STACK_ID; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 2073 | } |
| 2074 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2075 | DisplayContent getDisplay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2076 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2077 | return stack != null ? stack.getDisplay() : null; |
| 2078 | } |
| 2079 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2080 | @Override |
| 2081 | boolean fillsParent() { |
| 2082 | return occludesParent(); |
| 2083 | } |
| 2084 | |
| 2085 | /** Returns true if this activity is opaque and fills the entire space of this task. */ |
| 2086 | boolean occludesParent() { |
| 2087 | return mOccludesParent; |
| 2088 | } |
| 2089 | |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2090 | boolean setOccludesParent(boolean occludesParent) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2091 | final boolean changed = occludesParent != mOccludesParent; |
| 2092 | mOccludesParent = occludesParent; |
| 2093 | setMainWindowOpaque(occludesParent); |
| 2094 | mWmService.mWindowPlacerLocked.requestTraversal(); |
| 2095 | |
Wale Ogunwale | 7a8889a | 2019-11-16 08:23:42 -0800 | [diff] [blame] | 2096 | if (changed && task != null && !occludesParent) { |
| 2097 | getActivityStack().convertActivityToTranslucent(this); |
Riddle Hsu | ed5789b | 2019-08-21 15:12:03 +0800 | [diff] [blame] | 2098 | } |
| 2099 | // Always ensure visibility if this activity doesn't occlude parent, so the |
| 2100 | // {@link #returningOptions} of the activity under this one can be applied in |
| 2101 | // {@link #handleAlreadyVisible()}. |
| 2102 | if (changed || !occludesParent) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2103 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2104 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2105 | return changed; |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2108 | void setMainWindowOpaque(boolean isOpaque) { |
| 2109 | final WindowState win = findMainWindow(); |
| 2110 | if (win == null) { |
| 2111 | return; |
| 2112 | } |
| 2113 | isOpaque = isOpaque & !PixelFormat.formatHasAlpha(win.getAttrs().format); |
| 2114 | win.mWinAnimator.setOpaqueLocked(isOpaque); |
| 2115 | } |
| 2116 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2117 | void takeFromHistory() { |
| 2118 | if (inHistory) { |
| 2119 | inHistory = false; |
| 2120 | if (task != null && !finishing) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 2121 | task = null; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2122 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 2123 | clearOptionsLocked(); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | boolean isInHistory() { |
| 2128 | return inHistory; |
| 2129 | } |
| 2130 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2131 | boolean isInStackLocked() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2132 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2133 | return stack != null && stack.isInStackLocked(this) != null; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2136 | boolean isPersistable() { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 2137 | return (info.persistableMode == PERSIST_ROOT_ONLY || |
| 2138 | info.persistableMode == PERSIST_ACROSS_REBOOTS) && |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2139 | (intent == null || (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2142 | boolean isFocusable() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2143 | return mRootWindowContainer.isFocusable(this, isAlwaysFocusable()); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | boolean isResizeable() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2147 | return ActivityInfo.isResizeableMode(info.resizeMode) || info.supportsPictureInPicture(); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2150 | /** @return whether this activity is non-resizeable or forced to be resizeable */ |
| 2151 | boolean isNonResizableOrForcedResizable(int windowingMode) { |
| 2152 | if (windowingMode == WINDOWING_MODE_PINNED && info.supportsPictureInPicture()) { |
| 2153 | return false; |
| 2154 | } |
Wale Ogunwale | df241e9 | 2016-10-13 15:14:21 -0700 | [diff] [blame] | 2155 | return info.resizeMode != RESIZE_MODE_RESIZEABLE |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 2156 | && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 2159 | /** |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2160 | * @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] | 2161 | */ |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 2162 | boolean supportsPictureInPicture() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2163 | return mAtmService.mSupportsPictureInPicture && isActivityTypeStandardOrUndefined() |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2164 | && info.supportsPictureInPicture(); |
| 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * @return whether this activity supports split-screen multi-window and can be put in the docked |
| 2169 | * stack. |
| 2170 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2171 | @Override |
| 2172 | public boolean supportsSplitScreenWindowingMode() { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2173 | // An activity can not be docked even if it is considered resizeable because it only |
| 2174 | // supports picture-in-picture mode but has a non-resizeable resizeMode |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2175 | return super.supportsSplitScreenWindowingMode() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2176 | && mAtmService.mSupportsSplitScreenMultiWindow && supportsResizeableMultiWindow(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | /** |
| 2180 | * @return whether this activity supports freeform multi-window and can be put in the freeform |
| 2181 | * stack. |
| 2182 | */ |
| 2183 | boolean supportsFreeform() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2184 | return mAtmService.mSupportsFreeformWindowManagement && supportsResizeableMultiWindow(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | /** |
| 2188 | * @return whether this activity supports non-PiP multi-window. |
| 2189 | */ |
| 2190 | private boolean supportsResizeableMultiWindow() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2191 | return mAtmService.mSupportsMultiWindow && !isActivityTypeHome() |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2192 | && (ActivityInfo.isResizeableMode(info.resizeMode) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2193 | || mAtmService.mForceResizableActivities); |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 2194 | } |
| 2195 | |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 2196 | /** |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2197 | * Check whether this activity can be launched on the specified display. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 2198 | * |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2199 | * @param displayId Target display id. |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 2200 | * @return {@code true} if either it is the default display or this activity can be put on a |
| 2201 | * secondary screen. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2202 | */ |
| 2203 | boolean canBeLaunchedOnDisplay(int displayId) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2204 | return mAtmService.mStackSupervisor.canPlaceEntityOnDisplay(displayId, launchedFromPid, |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 2205 | launchedFromUid, info); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | /** |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 2209 | * @param beforeStopping Whether this check is for an auto-enter-pip operation, that is to say |
| 2210 | * the activity has requested to enter PiP when it would otherwise be stopped. |
| 2211 | * |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2212 | * @return whether this activity is currently allowed to enter PIP. |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 2213 | */ |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2214 | boolean checkEnterPictureInPictureState(String caller, boolean beforeStopping) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2215 | if (!supportsPictureInPicture()) { |
| 2216 | return false; |
| 2217 | } |
| 2218 | |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 2219 | // Check app-ops and see if PiP is supported for this package |
| 2220 | if (!checkEnterPictureInPictureAppOpsState()) { |
| 2221 | return false; |
| 2222 | } |
| 2223 | |
Winson Chung | f1bfee1 | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2224 | // 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] | 2225 | if (mAtmService.shouldDisableNonVrUiLocked()) { |
Winson Chung | f1bfee1 | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2226 | return false; |
| 2227 | } |
| 2228 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2229 | boolean isKeyguardLocked = mAtmService.isKeyguardLocked(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2230 | boolean isCurrentAppLocked = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2231 | mAtmService.getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2232 | final DisplayContent display = getDisplay(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2233 | boolean hasPinnedStack = display != null && display.hasPinnedStack(); |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 2234 | // Don't return early if !isNotLocked, since we want to throw an exception if the activity |
| 2235 | // is in an incorrect state |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 2236 | boolean isNotLockedOrOnKeyguard = !isKeyguardLocked && !isCurrentAppLocked; |
Robert Carr | c33658e | 2017-04-11 18:24:20 -0700 | [diff] [blame] | 2237 | |
| 2238 | // We don't allow auto-PiP when something else is already pipped. |
| 2239 | if (beforeStopping && hasPinnedStack) { |
| 2240 | return false; |
| 2241 | } |
| 2242 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2243 | switch (mState) { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2244 | case RESUMED: |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 2245 | // When visible, allow entering PiP if the app is not locked. If it is over the |
| 2246 | // 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] | 2247 | return !isCurrentAppLocked && |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 2248 | (supportsEnterPipOnTaskSwitch || !beforeStopping); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2249 | case PAUSING: |
| 2250 | case PAUSED: |
Winson Chung | bb34880 | 2017-01-30 12:01:45 -0800 | [diff] [blame] | 2251 | // When pausing, then only allow enter PiP as in the resume state, and in addition, |
| 2252 | // require that there is not an existing PiP activity and that the current system |
| 2253 | // state supports entering PiP |
Winson Chung | e581ebf | 2017-02-21 08:25:03 -0800 | [diff] [blame] | 2254 | return isNotLockedOrOnKeyguard && !hasPinnedStack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 2255 | && supportsEnterPipOnTaskSwitch; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2256 | case STOPPING: |
| 2257 | // When stopping in a valid state, then only allow enter PiP as in the pause state. |
| 2258 | // Otherwise, fall through to throw an exception if the caller is trying to enter |
| 2259 | // PiP in an invalid stopping state. |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 2260 | if (supportsEnterPipOnTaskSwitch) { |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 2261 | return isNotLockedOrOnKeyguard && !hasPinnedStack; |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2262 | } |
| 2263 | default: |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2264 | return false; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2265 | } |
Winson Chung | e630804 | 2016-10-31 09:24:01 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 2268 | /** |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 2269 | * Sets if this {@link ActivityRecord} is in the process of closing or entering PIP. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2270 | * {@link #mWillCloseOrEnterPip}} |
| 2271 | */ |
| 2272 | void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) { |
| 2273 | mWillCloseOrEnterPip = willCloseOrEnterPip; |
| 2274 | } |
| 2275 | |
| 2276 | /** |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 2277 | * Returns whether this {@link ActivityRecord} is considered closing. Conditions are either |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2278 | * 1. Is this app animating and was requested to be hidden |
| 2279 | * 2. App is delayed closing since it might enter PIP. |
| 2280 | */ |
| 2281 | boolean isClosingOrEnteringPip() { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 2282 | return (isAnimating(TRANSITION | PARENTS) && !mVisibleRequested) || mWillCloseOrEnterPip; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2283 | } |
| 2284 | /** |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 2285 | * @return Whether AppOps allows this package to enter picture-in-picture. |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 2286 | */ |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 2287 | private boolean checkEnterPictureInPictureAppOpsState() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2288 | return mAtmService.getAppOpsService().checkOperation( |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 2289 | OP_PICTURE_IN_PICTURE, info.applicationInfo.uid, packageName) == MODE_ALLOWED; |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 2290 | } |
| 2291 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2292 | private boolean isAlwaysFocusable() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2293 | return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0; |
| 2294 | } |
| 2295 | |
Louis Chang | 2104fd9 | 2019-11-04 15:43:53 +0800 | [diff] [blame] | 2296 | boolean windowsAreFocusable() { |
| 2297 | return windowsAreFocusable(false /* fromUserTouch */); |
| 2298 | } |
| 2299 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2300 | // TODO: Does this really need to be different from isAlwaysFocusable()? For the activity side |
| 2301 | // focusable means resumeable. I guess with that in mind maybe we should rename the other |
| 2302 | // method to isResumeable() or something like that. |
Louis Chang | 2104fd9 | 2019-11-04 15:43:53 +0800 | [diff] [blame] | 2303 | boolean windowsAreFocusable(boolean fromUserTouch) { |
| 2304 | if (!fromUserTouch && mTargetSdk < Build.VERSION_CODES.Q) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2305 | final int pid = getPid(); |
| 2306 | final ActivityRecord topFocusedAppOfMyProcess = |
| 2307 | mWmService.mRoot.mTopFocusedAppByProcess.get(pid); |
| 2308 | if (topFocusedAppOfMyProcess != null && topFocusedAppOfMyProcess != this) { |
| 2309 | // For the apps below Q, there can be only one app which has the focused window per |
| 2310 | // process, because legacy apps may not be ready for a multi-focus system. |
| 2311 | return false; |
| 2312 | } |
| 2313 | } |
Louis Chang | a9c9d98 | 2019-11-11 11:20:19 +0800 | [diff] [blame] | 2314 | return (getWindowConfiguration().canReceiveKeys() || isAlwaysFocusable()) |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 2315 | && getDisplay() != null; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Louis Chang | 2104fd9 | 2019-11-04 15:43:53 +0800 | [diff] [blame] | 2318 | /** |
| 2319 | * Move activity with its stack to front and make the stack focused. |
| 2320 | * @param reason the reason to move to top |
| 2321 | * @return {@code true} if the stack is focusable and has been moved to top or the activity |
| 2322 | * is not yet resumed while the stack is already on top, {@code false} otherwise. |
| 2323 | */ |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2324 | boolean moveFocusableActivityToTop(String reason) { |
| 2325 | if (!isFocusable()) { |
| 2326 | if (DEBUG_FOCUS) { |
| 2327 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: unfocusable activity=" + this); |
| 2328 | } |
| 2329 | return false; |
| 2330 | } |
| 2331 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2332 | final ActivityStack stack = getActivityStack(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2333 | if (stack == null) { |
| 2334 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: activity=" |
| 2335 | + this + " task=" + task); |
| 2336 | return false; |
| 2337 | } |
| 2338 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2339 | if (mRootWindowContainer.getTopResumedActivity() == this |
lumark | d0b5c8f | 2019-09-29 11:30:37 +0800 | [diff] [blame] | 2340 | && getDisplayContent().mFocusedApp == this) { |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2341 | if (DEBUG_FOCUS) { |
| 2342 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: already on top, activity=" + this); |
| 2343 | } |
Louis Chang | 2104fd9 | 2019-11-04 15:43:53 +0800 | [diff] [blame] | 2344 | return !isState(RESUMED); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | if (DEBUG_FOCUS) { |
| 2348 | Slog.d(TAG_FOCUS, "moveActivityStackToFront: activity=" + this); |
| 2349 | } |
| 2350 | |
| 2351 | stack.moveToFront(reason, task); |
| 2352 | // Report top activity change to tracking services and WM |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2353 | if (mRootWindowContainer.getTopResumedActivity() == this) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2354 | mAtmService.setResumedActivityUncheckLocked(this, reason); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2355 | } |
| 2356 | return true; |
| 2357 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2358 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2359 | void finishIfSubActivity(ActivityRecord parent, String otherResultWho, int otherRequestCode) { |
| 2360 | if (resultTo != parent |
| 2361 | || requestCode != otherRequestCode |
| 2362 | || !Objects.equals(resultWho, otherResultWho)) return; |
| 2363 | |
| 2364 | finishIfPossible("request-sub", false /* oomAdj */); |
| 2365 | } |
| 2366 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2367 | /** Finish all activities in the task with the same affinity as this one. */ |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2368 | boolean finishIfSameAffinity(ActivityRecord r) { |
| 2369 | // End search once we get to the activity that doesn't have the same affinity. |
| 2370 | if (!Objects.equals(r.taskAffinity, taskAffinity)) return true; |
| 2371 | |
| 2372 | r.finishIfPossible("request-affinity", true /* oomAdj */); |
| 2373 | return false; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * Sets the result for activity that started this one, clears the references to activities |
| 2378 | * started for result from this one, and clears new intents. |
| 2379 | */ |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2380 | private void finishActivityResults(int resultCode, Intent resultData) { |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2381 | // Send the result if needed |
| 2382 | if (resultTo != null) { |
| 2383 | if (DEBUG_RESULTS) { |
| 2384 | Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
| 2385 | + " who=" + resultWho + " req=" + requestCode |
| 2386 | + " res=" + resultCode + " data=" + resultData); |
| 2387 | } |
| 2388 | if (resultTo.mUserId != mUserId) { |
| 2389 | if (resultData != null) { |
| 2390 | resultData.prepareToLeaveUser(mUserId); |
| 2391 | } |
| 2392 | } |
| 2393 | if (info.applicationInfo.uid > 0) { |
| 2394 | mAtmService.mUgmInternal.grantUriPermissionFromIntent(info.applicationInfo.uid, |
| 2395 | resultTo.packageName, resultData, |
| 2396 | resultTo.getUriPermissionsLocked(), resultTo.mUserId); |
| 2397 | } |
| 2398 | resultTo.addResultLocked(this, resultWho, requestCode, resultCode, resultData); |
| 2399 | resultTo = null; |
| 2400 | } else if (DEBUG_RESULTS) { |
| 2401 | Slog.v(TAG_RESULTS, "No result destination from " + this); |
| 2402 | } |
| 2403 | |
| 2404 | // Make sure this HistoryRecord is not holding on to other resources, |
| 2405 | // because clients have remote IPC references to this object so we |
| 2406 | // can't assume that will go away and want to avoid circular IPC refs. |
| 2407 | results = null; |
| 2408 | pendingResults = null; |
| 2409 | newIntents = null; |
| 2410 | setSavedState(null /* savedState */); |
| 2411 | } |
| 2412 | |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 2413 | /** Activity finish request was not executed. */ |
| 2414 | static final int FINISH_RESULT_CANCELLED = 0; |
| 2415 | /** Activity finish was requested, activity will be fully removed later. */ |
| 2416 | static final int FINISH_RESULT_REQUESTED = 1; |
| 2417 | /** Activity finish was requested, activity was removed from history. */ |
| 2418 | static final int FINISH_RESULT_REMOVED = 2; |
| 2419 | |
| 2420 | /** Definition of possible results for activity finish request. */ |
| 2421 | @IntDef(prefix = { "FINISH_RESULT_" }, value = { |
| 2422 | FINISH_RESULT_CANCELLED, |
| 2423 | FINISH_RESULT_REQUESTED, |
| 2424 | FINISH_RESULT_REMOVED, |
| 2425 | }) |
| 2426 | @interface FinishRequest {} |
| 2427 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2428 | /** |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 2429 | * See {@link #finishIfPossible(int, Intent, String, boolean)} |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2430 | */ |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2431 | @FinishRequest int finishIfPossible(String reason, boolean oomAdj) { |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 2432 | return finishIfPossible(Activity.RESULT_CANCELED, null /* resultData */, reason, oomAdj); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | /** |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2436 | * Finish activity if possible. If activity was resumed - we must first pause it to make the |
| 2437 | * activity below resumed. Otherwise we will try to complete the request immediately by calling |
| 2438 | * {@link #completeFinishing(String)}. |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 2439 | * @return One of {@link FinishRequest} values: |
| 2440 | * {@link #FINISH_RESULT_REMOVED} if this activity has been removed from the history list. |
| 2441 | * {@link #FINISH_RESULT_REQUESTED} if removal process was started, but it is still in the list |
| 2442 | * and will be removed from history later. |
| 2443 | * {@link #FINISH_RESULT_CANCELLED} if activity is already finishing or in invalid state and the |
| 2444 | * request to finish it was not ignored. |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2445 | */ |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2446 | @FinishRequest int finishIfPossible(int resultCode, Intent resultData, String reason, |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 2447 | boolean oomAdj) { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 2448 | if (DEBUG_RESULTS || DEBUG_STATES) { |
| 2449 | Slog.v(TAG_STATES, "Finishing activity r=" + this + ", result=" + resultCode |
| 2450 | + ", data=" + resultData + ", reason=" + reason); |
| 2451 | } |
| 2452 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2453 | if (finishing) { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 2454 | Slog.w(TAG, "Duplicate finish request for r=" + this); |
| 2455 | return FINISH_RESULT_CANCELLED; |
| 2456 | } |
| 2457 | |
| 2458 | if (!isInStackLocked()) { |
| 2459 | Slog.w(TAG, "Finish request when not in stack for r=" + this); |
| 2460 | return FINISH_RESULT_CANCELLED; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
Riddle Hsu | 1e7ba58 | 2019-08-26 19:18:34 +0800 | [diff] [blame] | 2463 | final ActivityStack stack = getActivityStack(); |
Riddle Hsu | cf92023 | 2019-10-04 19:05:36 +0800 | [diff] [blame] | 2464 | final boolean mayAdjustTop = (isState(RESUMED) || stack.mResumedActivity == null) |
| 2465 | && stack.isFocusedStackOnDisplay(); |
| 2466 | final boolean shouldAdjustGlobalFocus = mayAdjustTop |
Riddle Hsu | 1e7ba58 | 2019-08-26 19:18:34 +0800 | [diff] [blame] | 2467 | // It must be checked before {@link #makeFinishingLocked} is called, because a stack |
| 2468 | // is not visible if it only contains finishing activities. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2469 | && mRootWindowContainer.isTopDisplayFocusedStack(stack); |
Riddle Hsu | 1e7ba58 | 2019-08-26 19:18:34 +0800 | [diff] [blame] | 2470 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 2471 | mAtmService.deferWindowLayout(); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2472 | try { |
| 2473 | makeFinishingLocked(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2474 | // Make a local reference to its task since this.task could be set to null once this |
| 2475 | // activity is destroyed and detached from task. |
| 2476 | final Task task = getTask(); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 2477 | EventLogTags.writeWmFinishActivity(mUserId, System.identityHashCode(this), |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 2478 | task.mTaskId, shortComponentName, reason); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2479 | ActivityRecord next = task.getActivityAbove(this); |
| 2480 | if (next != null) { |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2481 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
| 2482 | // If the caller asked that this activity (and all above it) |
| 2483 | // be cleared when the task is reset, don't lose that information, |
| 2484 | // but propagate it up to the next activity. |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2485 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | pauseKeyDispatchingLocked(); |
| 2490 | |
Riddle Hsu | 1e7ba58 | 2019-08-26 19:18:34 +0800 | [diff] [blame] | 2491 | // We are finishing the top focused activity and its stack has nothing to be focused so |
| 2492 | // the next focusable stack should be focused. |
Riddle Hsu | cf92023 | 2019-10-04 19:05:36 +0800 | [diff] [blame] | 2493 | if (mayAdjustTop |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2494 | && (stack.topRunningActivity() == null || !stack.isFocusable())) { |
Riddle Hsu | cf92023 | 2019-10-04 19:05:36 +0800 | [diff] [blame] | 2495 | if (shouldAdjustGlobalFocus) { |
| 2496 | // Move the entire hierarchy to top with updating global top resumed activity |
| 2497 | // and focused application if needed. |
| 2498 | stack.adjustFocusToNextFocusableStack("finish-top"); |
| 2499 | } else { |
| 2500 | // Only move the next stack to top in its display. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2501 | final DisplayContent display = stack.getDisplay(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2502 | next = display.topRunningActivity(); |
Riddle Hsu | cf92023 | 2019-10-04 19:05:36 +0800 | [diff] [blame] | 2503 | if (next != null) { |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 2504 | display.positionStackAtTop(next.getActivityStack(), |
Riddle Hsu | cf92023 | 2019-10-04 19:05:36 +0800 | [diff] [blame] | 2505 | false /* includingParents */, "finish-display-top"); |
| 2506 | } |
| 2507 | } |
Riddle Hsu | 1e7ba58 | 2019-08-26 19:18:34 +0800 | [diff] [blame] | 2508 | } |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2509 | |
| 2510 | finishActivityResults(resultCode, resultData); |
| 2511 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2512 | final boolean endTask = task.getActivityBelow(this) == null |
| 2513 | && !task.isClearingToReuseTask(); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2514 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2515 | if (isState(RESUMED)) { |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2516 | if (endTask) { |
| 2517 | mAtmService.getTaskChangeNotificationController().notifyTaskRemovalStarted( |
| 2518 | task.getTaskInfo()); |
| 2519 | } |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2520 | // Prepare app close transition, but don't execute just yet. It is possible that |
| 2521 | // an activity that will be made resumed in place of this one will immediately |
| 2522 | // launch another new activity. In this case current closing transition will be |
| 2523 | // combined with open transition for the new activity. |
| 2524 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) { |
| 2525 | Slog.v(TAG_TRANSITION, "Prepare close transition: finishing " + this); |
| 2526 | } |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2527 | getDisplay().mDisplayContent.prepareAppTransition(transit, false); |
| 2528 | |
| 2529 | // When finishing the activity preemptively take the snapshot before the app window |
| 2530 | // is marked as hidden and any configuration changes take place |
| 2531 | if (mAtmService.mWindowManager.mTaskSnapshotController != null) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2532 | final ArraySet<Task> tasks = Sets.newArraySet(task); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2533 | mAtmService.mWindowManager.mTaskSnapshotController.snapshotTasks(tasks); |
| 2534 | mAtmService.mWindowManager.mTaskSnapshotController |
| 2535 | .addSkipClosingAppSnapshotTasks(tasks); |
| 2536 | } |
| 2537 | |
| 2538 | // Tell window manager to prepare for this one to be removed. |
| 2539 | setVisibility(false); |
| 2540 | |
| 2541 | if (stack.mPausingActivity == null) { |
| 2542 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + this); |
| 2543 | if (DEBUG_USER_LEAVING) { |
| 2544 | Slog.v(TAG_USER_LEAVING, "finish() => pause with userLeaving=false"); |
| 2545 | } |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 2546 | stack.startPausingLocked(false /* userLeaving */, false /* uiSleeping */, |
| 2547 | null /* resuming */); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | if (endTask) { |
| 2551 | mAtmService.getLockTaskController().clearLockedTask(task); |
| 2552 | } |
| 2553 | } else if (!isState(PAUSING)) { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 2554 | if (mVisibleRequested) { |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2555 | // Prepare and execute close transition. |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2556 | prepareActivityHideTransitionAnimation(transit); |
| 2557 | } |
| 2558 | |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2559 | final boolean removedActivity = completeFinishing("finishIfPossible") == null; |
| 2560 | // Performance optimization - only invoke OOM adjustment if the state changed to |
| 2561 | // 'STOPPING'. Otherwise it will not change the OOM scores. |
| 2562 | if (oomAdj && isState(STOPPING)) { |
| 2563 | mAtmService.updateOomAdj(); |
| 2564 | } |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2565 | |
| 2566 | // The following code is an optimization. When the last non-task overlay activity |
| 2567 | // is removed from the task, we remove the entire task from the stack. However, |
| 2568 | // since that is done after the scheduled destroy callback from the activity, that |
| 2569 | // call to change the visibility of the task overlay activities would be out of |
| 2570 | // sync with the activity visibility being set for this finishing activity above. |
| 2571 | // In this case, we can set the visibility of all the task overlay activities when |
| 2572 | // we detect the last one is finishing to keep them in sync. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2573 | if (task.onlyHasTaskOverlayActivities(false /* includeFinishing */)) { |
| 2574 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2575 | ActivityRecord::prepareActivityHideTransitionAnimationIfOvarlay, |
| 2576 | PooledLambda.__(ActivityRecord.class), transit); |
| 2577 | task.forAllActivities(c); |
| 2578 | c.recycle(); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2579 | } |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 2580 | return removedActivity ? FINISH_RESULT_REMOVED : FINISH_RESULT_REQUESTED; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2581 | } else { |
| 2582 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + this); |
| 2583 | } |
| 2584 | |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 2585 | return FINISH_RESULT_REQUESTED; |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2586 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 2587 | mAtmService.continueWindowLayout(); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2591 | private void prepareActivityHideTransitionAnimationIfOvarlay(int transit) { |
| 2592 | if (mTaskOverlay) { |
| 2593 | prepareActivityHideTransitionAnimation(transit); |
| 2594 | } |
| 2595 | } |
| 2596 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2597 | private void prepareActivityHideTransitionAnimation(int transit) { |
| 2598 | final DisplayContent dc = getDisplay().mDisplayContent; |
| 2599 | dc.prepareAppTransition(transit, false); |
| 2600 | setVisibility(false); |
| 2601 | dc.executeAppTransition(); |
| 2602 | } |
| 2603 | |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2604 | /** |
| 2605 | * Complete activity finish request that was initiated earlier. If the activity is still |
| 2606 | * pausing we will wait for it to complete its transition. If the activity that should appear in |
| 2607 | * place of this one is not visible yet - we'll wait for it first. Otherwise - activity can be |
| 2608 | * destroyed right away. |
| 2609 | * @param reason Reason for finishing the activity. |
| 2610 | * @return Flag indicating whether the activity was removed from history. |
| 2611 | */ |
| 2612 | ActivityRecord completeFinishing(String reason) { |
| 2613 | if (!finishing || isState(RESUMED)) { |
| 2614 | throw new IllegalArgumentException( |
| 2615 | "Activity must be finishing and not resumed to complete, r=" + this |
| 2616 | + ", finishing=" + finishing + ", state=" + mState); |
| 2617 | } |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2618 | |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2619 | if (isState(PAUSING)) { |
| 2620 | // Activity is marked as finishing and will be processed once it completes. |
| 2621 | return this; |
| 2622 | } |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2623 | |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2624 | boolean activityRemoved = false; |
| 2625 | |
| 2626 | // If this activity is currently visible, and the resumed activity is not yet visible, then |
| 2627 | // hold off on finishing until the resumed one becomes visible. |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2628 | // The activity that we are finishing may be over the lock screen. In this case, we do not |
| 2629 | // want to consider activities that cannot be shown on the lock screen as running and should |
| 2630 | // proceed with finishing the activity if there is no valid next top running activity. |
| 2631 | // Note that if this finishing activity is floating task, we don't need to wait the |
| 2632 | // next activity resume and can destroy it directly. |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2633 | // TODO(b/137329632): find the next activity directly underneath this one, not just anywhere |
| 2634 | final ActivityRecord next = getDisplay().topRunningActivity( |
| 2635 | true /* considerKeyguardState */); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 2636 | final boolean isVisible = mVisibleRequested || nowVisible; |
lumark | 50b8154 | 2019-09-01 23:11:49 +0800 | [diff] [blame] | 2637 | // isNextNotYetVisible is to check if the next activity is invisible, or it has been |
| 2638 | // requested to be invisible but its windows haven't reported as invisible. If so, it |
| 2639 | // implied that the current finishing activity should be added into stopping list rather |
| 2640 | // than destroy immediately. |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 2641 | final boolean isNextNotYetVisible = next != null |
| 2642 | && (!next.nowVisible || !next.mVisibleRequested); |
lumark | 50b8154 | 2019-09-01 23:11:49 +0800 | [diff] [blame] | 2643 | if (isVisible && isNextNotYetVisible) { |
Andrii Kulian | 34acc14 | 2019-09-24 15:35:50 -0700 | [diff] [blame] | 2644 | // Add this activity to the list of stopping activities. It will be processed and |
| 2645 | // destroyed when the next activity reports idle. |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2646 | addToStopping(false /* scheduleIdle */, false /* idleDelayed */, |
| 2647 | "completeFinishing"); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2648 | setState(STOPPING, "completeFinishing"); |
Andrii Kulian | 34acc14 | 2019-09-24 15:35:50 -0700 | [diff] [blame] | 2649 | } else if (addToFinishingAndWaitForIdle()) { |
| 2650 | // We added this activity to the finishing list and something else is becoming resumed. |
| 2651 | // The activity will complete finishing when the next activity reports idle. No need to |
| 2652 | // do anything else here. |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2653 | } else { |
Andrii Kulian | 34acc14 | 2019-09-24 15:35:50 -0700 | [diff] [blame] | 2654 | // Not waiting for the next one to become visible, and nothing else will be resumed in |
| 2655 | // place of this activity - requesting destruction right away. |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2656 | activityRemoved = destroyIfPossible(reason); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2659 | return activityRemoved ? null : this; |
| 2660 | } |
| 2661 | |
| 2662 | /** |
| 2663 | * Destroy and cleanup the activity both on client and server if possible. If activity is the |
| 2664 | * last one left on display with home stack and there is no other running activity - delay |
| 2665 | * destroying it until the next one starts. |
| 2666 | */ |
| 2667 | boolean destroyIfPossible(String reason) { |
| 2668 | setState(FINISHING, "destroyIfPossible"); |
| 2669 | |
| 2670 | // Make sure the record is cleaned out of other places. |
| 2671 | mStackSupervisor.mStoppingActivities.remove(this); |
| 2672 | mStackSupervisor.mGoingToSleepActivities.remove(this); |
| 2673 | |
| 2674 | final ActivityStack stack = getActivityStack(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2675 | final DisplayContent display = getDisplay(); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2676 | // TODO(b/137329632): Exclude current activity when looking for the next one with |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2677 | // DisplayContent#topRunningActivity(). |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2678 | final ActivityRecord next = display.topRunningActivity(); |
| 2679 | final boolean isLastStackOverEmptyHome = |
| 2680 | next == null && stack.isFocusedStackOnDisplay() && display.getHomeStack() != null; |
| 2681 | if (isLastStackOverEmptyHome) { |
| 2682 | // Don't destroy activity immediately if this is the last activity on the display and |
| 2683 | // the display contains home stack. Although there is no next activity at the moment, |
| 2684 | // another home activity should be started later. Keep this activity alive until next |
| 2685 | // home activity is resumed. This way the user won't see a temporary black screen. |
| 2686 | addToFinishingAndWaitForIdle(); |
| 2687 | return false; |
| 2688 | } |
| 2689 | makeFinishingLocked(); |
| 2690 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2691 | final boolean activityRemoved = destroyImmediately(true /* removeFromApp */, |
| 2692 | "finish-imm:" + reason); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2693 | |
| 2694 | // If the display does not have running activity, the configuration may need to be |
| 2695 | // updated for restoring original orientation of the display. |
| 2696 | if (next == null) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2697 | mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(), |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2698 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
| 2699 | } |
| 2700 | if (activityRemoved) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2701 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | if (DEBUG_CONTAINERS) { |
| 2705 | Slog.d(TAG_CONTAINERS, "destroyIfPossible: r=" + this + " destroy returned removed=" |
| 2706 | + activityRemoved); |
| 2707 | } |
| 2708 | |
| 2709 | return activityRemoved; |
| 2710 | } |
| 2711 | |
Andrii Kulian | 34acc14 | 2019-09-24 15:35:50 -0700 | [diff] [blame] | 2712 | /** |
| 2713 | * Add this activity to the list of finishing and trigger resuming of activities in focused |
| 2714 | * stacks. |
| 2715 | * @return {@code true} if some other activity is being resumed as a result of this call. |
| 2716 | */ |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2717 | @VisibleForTesting |
Andrii Kulian | 34acc14 | 2019-09-24 15:35:50 -0700 | [diff] [blame] | 2718 | boolean addToFinishingAndWaitForIdle() { |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 2719 | if (DEBUG_STATES) Slog.v(TAG, "Enqueueing pending finish: " + this); |
| 2720 | setState(FINISHING, "addToFinishingAndWaitForIdle"); |
Andrii Kulian | 34acc14 | 2019-09-24 15:35:50 -0700 | [diff] [blame] | 2721 | if (!mStackSupervisor.mFinishingActivities.contains(this)) { |
| 2722 | mStackSupervisor.mFinishingActivities.add(this); |
| 2723 | } |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2724 | resumeKeyDispatchingLocked(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2725 | return mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2728 | /** |
| 2729 | * Destroy the current CLIENT SIDE instance of an activity. This may be called both when |
| 2730 | * actually finishing an activity, or when performing a configuration switch where we destroy |
| 2731 | * the current client-side object but then create a new client-side object for this same |
| 2732 | * HistoryRecord. |
| 2733 | * Normally the server-side record will be removed when the client reports back after |
| 2734 | * destruction. If, however, at this point there is no client process attached, the record will |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 2735 | * be removed immediately. |
| 2736 | * |
| 2737 | * @return {@code true} if activity was immediately removed from history, {@code false} |
| 2738 | * otherwise. |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2739 | */ |
| 2740 | boolean destroyImmediately(boolean removeFromApp, String reason) { |
| 2741 | if (DEBUG_SWITCH || DEBUG_CLEANUP) { |
| 2742 | Slog.v(TAG_SWITCH, "Removing activity from " + reason + ": token=" + this |
| 2743 | + ", app=" + (hasProcess() ? app.mName : "(null)")); |
| 2744 | } |
| 2745 | |
| 2746 | if (isState(DESTROYING, DESTROYED)) { |
| 2747 | if (DEBUG_STATES) { |
| 2748 | Slog.v(TAG_STATES, "activity " + this + " already destroying." |
| 2749 | + "skipping request with reason:" + reason); |
| 2750 | } |
| 2751 | return false; |
| 2752 | } |
| 2753 | |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 2754 | EventLogTags.writeWmDestroyActivity(mUserId, System.identityHashCode(this), |
| 2755 | task.mTaskId, shortComponentName, reason); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2756 | |
| 2757 | boolean removedFromHistory = false; |
| 2758 | |
| 2759 | cleanUp(false /* cleanServices */, false /* setState */); |
| 2760 | |
Riddle Hsu | 5477b57 | 2019-11-12 16:07:29 +0800 | [diff] [blame] | 2761 | if (hasProcess()) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2762 | if (removeFromApp) { |
| 2763 | app.removeActivity(this); |
| 2764 | if (!app.hasActivities()) { |
| 2765 | mAtmService.clearHeavyWeightProcessIfEquals(app); |
| 2766 | // Update any services we are bound to that might care about whether |
| 2767 | // their client may have activities. |
| 2768 | // No longer have activities, so update LRU list and oom adj. |
| 2769 | app.updateProcessInfo(true /* updateServiceConnectionActivities */, |
| 2770 | false /* activityChange */, true /* updateOomAdj */); |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | boolean skipDestroy = false; |
| 2775 | |
| 2776 | try { |
| 2777 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + this); |
| 2778 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 2779 | DestroyActivityItem.obtain(finishing, configChangeFlags)); |
| 2780 | } catch (Exception e) { |
| 2781 | // We can just ignore exceptions here... if the process has crashed, our death |
| 2782 | // notification will clean things up. |
| 2783 | if (finishing) { |
| 2784 | removeFromHistory(reason + " exceptionInScheduleDestroy"); |
| 2785 | removedFromHistory = true; |
| 2786 | skipDestroy = true; |
| 2787 | } |
| 2788 | } |
| 2789 | |
| 2790 | nowVisible = false; |
| 2791 | |
| 2792 | // If the activity is finishing, we need to wait on removing it from the list to give it |
| 2793 | // a chance to do its cleanup. During that time it may make calls back with its token |
| 2794 | // so we need to be able to find it on the list and so we don't want to remove it from |
| 2795 | // the list yet. Otherwise, we can just immediately put it in the destroyed state since |
| 2796 | // we are not removing it from the list. |
| 2797 | if (finishing && !skipDestroy) { |
| 2798 | if (DEBUG_STATES) { |
| 2799 | Slog.v(TAG_STATES, "Moving to DESTROYING: " + this + " (destroy requested)"); |
| 2800 | } |
| 2801 | setState(DESTROYING, |
| 2802 | "destroyActivityLocked. finishing and not skipping destroy"); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 2803 | mAtmService.mH.postDelayed(mDestroyTimeoutRunnable, DESTROY_TIMEOUT); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2804 | } else { |
| 2805 | if (DEBUG_STATES) { |
| 2806 | Slog.v(TAG_STATES, "Moving to DESTROYED: " + this + " (destroy skipped)"); |
| 2807 | } |
| 2808 | setState(DESTROYED, |
| 2809 | "destroyActivityLocked. not finishing or skipping destroy"); |
| 2810 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during destroy for activity " + this); |
| 2811 | app = null; |
| 2812 | } |
| 2813 | } else { |
| 2814 | // Remove this record from the history. |
| 2815 | if (finishing) { |
| 2816 | removeFromHistory(reason + " hadNoApp"); |
| 2817 | removedFromHistory = true; |
| 2818 | } else { |
| 2819 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + this + " (no app)"); |
| 2820 | setState(DESTROYED, "destroyActivityLocked. not finishing and had no app"); |
| 2821 | } |
| 2822 | } |
| 2823 | |
| 2824 | configChangeFlags = 0; |
| 2825 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2826 | return removedFromHistory; |
| 2827 | } |
| 2828 | |
| 2829 | boolean safelyDestroy(String reason) { |
| 2830 | if (isDestroyable()) { |
| 2831 | if (DEBUG_SWITCH) { |
| 2832 | final ActivityStack stack = getActivityStack(); |
| 2833 | Slog.v(TAG_SWITCH, "Safely destroying " + this + " in state " + getState() |
| 2834 | + " resumed=" + stack.mResumedActivity |
| 2835 | + " pausing=" + stack.mPausingActivity |
| 2836 | + " for reason " + reason); |
| 2837 | } |
| 2838 | return destroyImmediately(true /* removeFromApp */, reason); |
| 2839 | } |
| 2840 | return false; |
| 2841 | } |
| 2842 | |
| 2843 | /** Note: call {@link #cleanUp(boolean, boolean)} before this method. */ |
| 2844 | void removeFromHistory(String reason) { |
| 2845 | finishActivityResults(Activity.RESULT_CANCELED, null /* resultData */); |
| 2846 | makeFinishingLocked(); |
| 2847 | if (ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE) { |
| 2848 | Slog.i(TAG_ADD_REMOVE, "Removing activity " + this + " from stack callers=" |
| 2849 | + Debug.getCallers(5)); |
| 2850 | } |
| 2851 | |
| 2852 | takeFromHistory(); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 2853 | removeTimeouts(); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2854 | if (DEBUG_STATES) { |
| 2855 | Slog.v(TAG_STATES, "Moving to DESTROYED: " + this + " (removed from history)"); |
| 2856 | } |
| 2857 | setState(DESTROYED, "removeFromHistory"); |
| 2858 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during remove for activity " + this); |
| 2859 | app = null; |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 2860 | removeAppTokenFromDisplay(); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2861 | |
| 2862 | cleanUpActivityServices(); |
| 2863 | removeUriPermissionsLocked(); |
| 2864 | } |
| 2865 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2866 | void makeFinishingLocked() { |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2867 | if (finishing) { |
| 2868 | return; |
| 2869 | } |
| 2870 | finishing = true; |
| 2871 | if (stopped) { |
| 2872 | clearOptionsLocked(); |
| 2873 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2874 | } |
| 2875 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2876 | /** |
| 2877 | * This method is to only be called from the client via binder when the activity is destroyed |
| 2878 | * AND finished. |
| 2879 | */ |
| 2880 | void destroyed(String reason) { |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 2881 | removeDestroyTimeout(); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2882 | |
| 2883 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + this); |
| 2884 | |
| 2885 | if (!isState(DESTROYING, DESTROYED)) { |
| 2886 | throw new IllegalStateException( |
| 2887 | "Reported destroyed for activity that is not destroying: r=" + this); |
| 2888 | } |
| 2889 | |
| 2890 | if (isInStackLocked()) { |
| 2891 | cleanUp(true /* cleanServices */, false /* setState */); |
| 2892 | removeFromHistory(reason); |
| 2893 | } |
| 2894 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2895 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | /** |
| 2899 | * Perform the common clean-up of an activity record. This is called both as part of |
| 2900 | * destroyActivityLocked() (when destroying the client-side representation) and cleaning things |
| 2901 | * up as a result of its hosting processing going away, in which case there is no remaining |
| 2902 | * client-side state to destroy so only the cleanup here is needed. |
| 2903 | * |
| 2904 | * Note: Call before {@link #removeFromHistory(String)}. |
| 2905 | */ |
| 2906 | void cleanUp(boolean cleanServices, boolean setState) { |
| 2907 | final ActivityStack stack = getActivityStack(); |
| 2908 | stack.onActivityRemovedFromStack(this); |
| 2909 | |
| 2910 | deferRelaunchUntilPaused = false; |
| 2911 | frozenBeforeDestroy = false; |
| 2912 | |
| 2913 | if (setState) { |
| 2914 | setState(DESTROYED, "cleanUp"); |
| 2915 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during cleanUp for activity " + this); |
| 2916 | app = null; |
| 2917 | } |
| 2918 | |
| 2919 | // Inform supervisor the activity has been removed. |
| 2920 | mStackSupervisor.cleanupActivity(this); |
| 2921 | |
| 2922 | // Remove any pending results. |
| 2923 | if (finishing && pendingResults != null) { |
| 2924 | for (WeakReference<PendingIntentRecord> apr : pendingResults) { |
| 2925 | PendingIntentRecord rec = apr.get(); |
| 2926 | if (rec != null) { |
| 2927 | mAtmService.mPendingIntentController.cancelIntentSender(rec, |
| 2928 | false /* cleanActivity */); |
| 2929 | } |
| 2930 | } |
| 2931 | pendingResults = null; |
| 2932 | } |
| 2933 | |
| 2934 | if (cleanServices) { |
| 2935 | cleanUpActivityServices(); |
| 2936 | } |
| 2937 | |
| 2938 | // Get rid of any pending idle timeouts. |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 2939 | removeTimeouts(); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2940 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 2941 | // manager so it can update its bookkeeping. |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2942 | clearRelaunching(); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2945 | boolean isRelaunching() { |
| 2946 | return mPendingRelaunchCount > 0; |
| 2947 | } |
| 2948 | |
| 2949 | boolean shouldFreezeBounds() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2950 | // For freeform windows, we can't freeze the bounds at the moment because this would make |
| 2951 | // the resizing unresponsive. |
| 2952 | if (task == null || task.inFreeformWindowingMode()) { |
| 2953 | return false; |
| 2954 | } |
| 2955 | |
| 2956 | // We freeze the bounds while drag resizing to deal with the time between |
| 2957 | // the divider/drag handle being released, and the handling it's new |
| 2958 | // configuration. If we are relaunched outside of the drag resizing state, |
| 2959 | // we need to be careful not to do this. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2960 | return task.isDragResizing(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | void startRelaunching() { |
| 2964 | if (shouldFreezeBounds()) { |
| 2965 | freezeBounds(); |
| 2966 | } |
| 2967 | |
| 2968 | // In the process of tearing down before relaunching, the app will |
| 2969 | // try and clean up it's child surfaces. We need to prevent this from |
| 2970 | // happening, so we sever the children, transfering their ownership |
| 2971 | // from the client it-self to the parent surface (owned by us). |
| 2972 | detachChildren(); |
| 2973 | |
| 2974 | mPendingRelaunchCount++; |
| 2975 | } |
| 2976 | |
| 2977 | /** |
| 2978 | * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds |
| 2979 | * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even |
| 2980 | * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen |
| 2981 | * with a queue. |
| 2982 | */ |
| 2983 | private void freezeBounds() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2984 | mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds)); |
| 2985 | |
| 2986 | if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) { |
| 2987 | // We didn't call prepareFreezingBounds on the task, so use the current value. |
| 2988 | mFrozenMergedConfig.offer(new Configuration(task.getConfiguration())); |
| 2989 | } else { |
| 2990 | mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig)); |
| 2991 | } |
| 2992 | // Calling unset() to make it equal to Configuration.EMPTY. |
| 2993 | task.mPreparedFrozenMergedConfig.unset(); |
| 2994 | } |
| 2995 | |
| 2996 | void detachChildren() { |
| 2997 | SurfaceControl.openTransaction(); |
| 2998 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 2999 | final WindowState w = mChildren.get(i); |
| 3000 | w.mWinAnimator.detachChildren(); |
| 3001 | } |
| 3002 | SurfaceControl.closeTransaction(); |
| 3003 | } |
| 3004 | |
| 3005 | void finishRelaunching() { |
| 3006 | unfreezeBounds(); |
| 3007 | |
| 3008 | if (mPendingRelaunchCount > 0) { |
| 3009 | mPendingRelaunchCount--; |
| 3010 | } else { |
| 3011 | // Update keyguard flags upon finishing relaunch. |
| 3012 | checkKeyguardFlagsChanged(); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | void clearRelaunching() { |
| 3017 | if (mPendingRelaunchCount == 0) { |
| 3018 | return; |
| 3019 | } |
| 3020 | unfreezeBounds(); |
| 3021 | mPendingRelaunchCount = 0; |
| 3022 | } |
| 3023 | |
| 3024 | /** |
| 3025 | * Unfreezes the previously frozen bounds. See {@link #freezeBounds}. |
| 3026 | */ |
| 3027 | private void unfreezeBounds() { |
| 3028 | if (mFrozenBounds.isEmpty()) { |
| 3029 | return; |
| 3030 | } |
| 3031 | mFrozenBounds.remove(); |
| 3032 | if (!mFrozenMergedConfig.isEmpty()) { |
| 3033 | mFrozenMergedConfig.remove(); |
| 3034 | } |
| 3035 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 3036 | final WindowState win = mChildren.get(i); |
| 3037 | win.onUnfreezeBounds(); |
| 3038 | } |
| 3039 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
| 3040 | } |
| 3041 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 3042 | /** |
| 3043 | * Perform clean-up of service connections in an activity record. |
| 3044 | */ |
| 3045 | private void cleanUpActivityServices() { |
| 3046 | if (mServiceConnectionsHolder == null) { |
| 3047 | return; |
| 3048 | } |
| 3049 | // Throw away any services that have been bound by this activity. |
| 3050 | mServiceConnectionsHolder.disconnectActivityFromServices(); |
| 3051 | } |
| 3052 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3053 | @Override |
| 3054 | void removeImmediately() { |
| 3055 | onRemovedFromDisplay(); |
| 3056 | super.removeImmediately(); |
| 3057 | } |
| 3058 | |
| 3059 | @Override |
| 3060 | void removeIfPossible() { |
| 3061 | mIsExiting = false; |
| 3062 | removeAllWindowsIfPossible(); |
| 3063 | removeImmediately(); |
| 3064 | } |
| 3065 | |
| 3066 | @Override |
| 3067 | boolean checkCompleteDeferredRemoval() { |
| 3068 | if (mIsExiting) { |
| 3069 | removeIfPossible(); |
| 3070 | } |
| 3071 | return super.checkCompleteDeferredRemoval(); |
| 3072 | } |
| 3073 | |
| 3074 | void onRemovedFromDisplay() { |
| 3075 | if (mRemovingFromDisplay) { |
| 3076 | return; |
| 3077 | } |
| 3078 | mRemovingFromDisplay = true; |
| 3079 | |
| 3080 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "Removing app token: %s", this); |
| 3081 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3082 | commitVisibility(false /* visible */, true /* performLayout */); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3083 | |
| 3084 | getDisplayContent().mOpeningApps.remove(this); |
| 3085 | getDisplayContent().mChangingApps.remove(this); |
| 3086 | getDisplayContent().mUnknownAppVisibilityController.appRemovedOrHidden(this); |
| 3087 | mWmService.mTaskSnapshotController.onAppRemoved(this); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 3088 | mStackSupervisor.getActivityMetricsLogger().notifyActivityRemoved(this); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3089 | waitingToShow = false; |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3090 | |
| 3091 | boolean delayed = isAnimating(TRANSITION | CHILDREN); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3092 | if (getDisplayContent().mClosingApps.contains(this)) { |
| 3093 | delayed = true; |
| 3094 | } else if (getDisplayContent().mAppTransition.isTransitionSet()) { |
| 3095 | getDisplayContent().mClosingApps.add(this); |
| 3096 | delayed = true; |
| 3097 | } |
| 3098 | |
| 3099 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 3100 | "Removing app %s delayed=%b animation=%s animating=%b", this, delayed, |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3101 | getAnimation(), isAnimating(TRANSITION)); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3102 | |
| 3103 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, "removeAppToken: %s" |
| 3104 | + " delayed=%b Callers=%s", this, delayed, Debug.getCallers(4)); |
| 3105 | |
| 3106 | if (mStartingData != null) { |
| 3107 | removeStartingWindow(); |
| 3108 | } |
| 3109 | |
| 3110 | // If this window was animating, then we need to ensure that the app transition notifies |
| 3111 | // that animations have completed in DisplayContent.handleAnimatingStoppedAndTransition(), |
| 3112 | // so add to that list now |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3113 | if (isAnimating(TRANSITION)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3114 | getDisplayContent().mNoAnimationNotifyOnTransitionFinished.add(token); |
| 3115 | } |
| 3116 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3117 | final ActivityStack stack = getStack(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3118 | if (delayed && !isEmpty()) { |
| 3119 | // set the token aside because it has an active animation to be finished |
| 3120 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
| 3121 | "removeAppToken make exiting: %s", this); |
| 3122 | if (stack != null) { |
| 3123 | stack.mExitingActivities.add(this); |
| 3124 | } |
| 3125 | mIsExiting = true; |
| 3126 | } else { |
| 3127 | // Make sure there is no animation running on this token, so any windows associated |
| 3128 | // with it will be removed as soon as their animations are complete |
| 3129 | cancelAnimation(); |
| 3130 | if (stack != null) { |
| 3131 | stack.mExitingActivities.remove(this); |
| 3132 | } |
| 3133 | removeIfPossible(); |
| 3134 | } |
| 3135 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3136 | stopFreezingScreen(true, true); |
| 3137 | |
| 3138 | final DisplayContent dc = getDisplayContent(); |
| 3139 | if (dc.mFocusedApp == this) { |
| 3140 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 3141 | "Removing focused app token:%s displayId=%d", this, |
| 3142 | dc.getDisplayId()); |
| 3143 | dc.setFocusedApp(null); |
| 3144 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| 3145 | } |
| 3146 | if (mLetterbox != null) { |
| 3147 | mLetterbox.destroy(); |
| 3148 | mLetterbox = null; |
| 3149 | } |
| 3150 | |
| 3151 | if (!delayed) { |
| 3152 | updateReportedVisibilityLocked(); |
| 3153 | } |
| 3154 | |
| 3155 | // Reset the last saved PiP snap fraction on removal. |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame] | 3156 | mDisplayContent.mPinnedStackControllerLocked.resetReentryBounds(mActivityComponent); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3157 | |
| 3158 | mRemovingFromDisplay = false; |
| 3159 | } |
| 3160 | |
| 3161 | /** |
| 3162 | * Returns true if the new child window we are adding to this token is considered greater than |
| 3163 | * the existing child window in this token in terms of z-order. |
| 3164 | */ |
| 3165 | @Override |
| 3166 | protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow, |
| 3167 | WindowState existingWindow) { |
| 3168 | final int type1 = newWindow.mAttrs.type; |
| 3169 | final int type2 = existingWindow.mAttrs.type; |
| 3170 | |
| 3171 | // Base application windows should be z-ordered BELOW all other windows in the app token. |
| 3172 | if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) { |
| 3173 | return false; |
| 3174 | } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) { |
| 3175 | return true; |
| 3176 | } |
| 3177 | |
| 3178 | // Starting windows should be z-ordered ABOVE all other windows in the app token. |
| 3179 | if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) { |
| 3180 | return true; |
| 3181 | } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) { |
| 3182 | return false; |
| 3183 | } |
| 3184 | |
| 3185 | // Otherwise the new window is greater than the existing window. |
| 3186 | return true; |
| 3187 | } |
| 3188 | |
| 3189 | /** |
| 3190 | * @return {@code true} if starting window is in app's hierarchy. |
| 3191 | */ |
| 3192 | boolean hasStartingWindow() { |
| 3193 | if (startingDisplayed || mStartingData != null) { |
| 3194 | return true; |
| 3195 | } |
| 3196 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 3197 | if (getChildAt(i).mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 3198 | return true; |
| 3199 | } |
| 3200 | } |
| 3201 | return false; |
| 3202 | } |
| 3203 | |
| 3204 | boolean isLastWindow(WindowState win) { |
| 3205 | return mChildren.size() == 1 && mChildren.get(0) == win; |
| 3206 | } |
| 3207 | |
| 3208 | @Override |
| 3209 | void addWindow(WindowState w) { |
| 3210 | super.addWindow(w); |
| 3211 | |
| 3212 | boolean gotReplacementWindow = false; |
| 3213 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 3214 | final WindowState candidate = mChildren.get(i); |
| 3215 | gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w); |
| 3216 | } |
| 3217 | |
| 3218 | // if we got a replacement window, reset the timeout to give drawing more time |
| 3219 | if (gotReplacementWindow) { |
| 3220 | mWmService.scheduleWindowReplacementTimeouts(this); |
| 3221 | } |
| 3222 | checkKeyguardFlagsChanged(); |
| 3223 | } |
| 3224 | |
| 3225 | @Override |
| 3226 | void removeChild(WindowState child) { |
| 3227 | if (!mChildren.contains(child)) { |
| 3228 | // This can be true when testing. |
| 3229 | return; |
| 3230 | } |
| 3231 | super.removeChild(child); |
| 3232 | checkKeyguardFlagsChanged(); |
| 3233 | updateLetterboxSurface(child); |
| 3234 | } |
| 3235 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3236 | void onWindowReplacementTimeout() { |
| 3237 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 3238 | (mChildren.get(i)).onWindowReplacementTimeout(); |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | void setAppLayoutChanges(int changes, String reason) { |
| 3243 | if (!mChildren.isEmpty()) { |
| 3244 | final DisplayContent dc = getDisplayContent(); |
| 3245 | dc.pendingLayoutChanges |= changes; |
| 3246 | if (DEBUG_LAYOUT_REPEATS) { |
| 3247 | mWmService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges); |
| 3248 | } |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | void removeReplacedWindowIfNeeded(WindowState replacement) { |
| 3253 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 3254 | final WindowState win = mChildren.get(i); |
| 3255 | if (win.removeReplacedWindowIfNeeded(replacement)) { |
| 3256 | return; |
| 3257 | } |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | boolean transferStartingWindow(IBinder transferFrom) { |
| 3262 | final ActivityRecord fromActivity = getDisplayContent().getActivityRecord(transferFrom); |
| 3263 | if (fromActivity == null) { |
| 3264 | return false; |
| 3265 | } |
| 3266 | |
| 3267 | final WindowState tStartingWindow = fromActivity.startingWindow; |
| 3268 | if (tStartingWindow != null && fromActivity.startingSurface != null) { |
| 3269 | // In this case, the starting icon has already been displayed, so start |
| 3270 | // letting windows get shown immediately without any more transitions. |
| 3271 | getDisplayContent().mSkipAppTransitionAnimation = true; |
| 3272 | |
| 3273 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Moving existing starting %s" |
| 3274 | + " from %s to %s", tStartingWindow, fromActivity, this); |
| 3275 | |
| 3276 | final long origId = Binder.clearCallingIdentity(); |
| 3277 | try { |
| 3278 | // Transfer the starting window over to the new token. |
| 3279 | mStartingData = fromActivity.mStartingData; |
| 3280 | startingSurface = fromActivity.startingSurface; |
| 3281 | startingDisplayed = fromActivity.startingDisplayed; |
| 3282 | fromActivity.startingDisplayed = false; |
| 3283 | startingWindow = tStartingWindow; |
| 3284 | reportedVisible = fromActivity.reportedVisible; |
| 3285 | fromActivity.mStartingData = null; |
| 3286 | fromActivity.startingSurface = null; |
| 3287 | fromActivity.startingWindow = null; |
| 3288 | fromActivity.startingMoved = true; |
| 3289 | tStartingWindow.mToken = this; |
| 3290 | tStartingWindow.mActivityRecord = this; |
| 3291 | |
| 3292 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
| 3293 | "Removing starting %s from %s", tStartingWindow, fromActivity); |
| 3294 | fromActivity.removeChild(tStartingWindow); |
| 3295 | fromActivity.postWindowRemoveStartingWindowCleanup(tStartingWindow); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 3296 | fromActivity.mVisibleSetFromTransferredStartingWindow = false; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3297 | addWindow(tStartingWindow); |
| 3298 | |
| 3299 | // Propagate other interesting state between the tokens. If the old token is displayed, |
| 3300 | // we should immediately force the new one to be displayed. If it is animating, we need |
| 3301 | // to move that animation to the new one. |
| 3302 | if (fromActivity.allDrawn) { |
| 3303 | allDrawn = true; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3304 | } |
| 3305 | if (fromActivity.firstWindowDrawn) { |
| 3306 | firstWindowDrawn = true; |
| 3307 | } |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 3308 | if (fromActivity.isVisible()) { |
| 3309 | setVisible(true); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 3310 | mVisibleRequested = true; |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 3311 | mVisibleSetFromTransferredStartingWindow = true; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3312 | } |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3313 | setClientVisible(fromActivity.mClientVisible); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3314 | |
| 3315 | transferAnimation(fromActivity); |
| 3316 | |
| 3317 | // When transferring an animation, we no longer need to apply an animation to the |
| 3318 | // the token we transfer the animation over. Thus, set this flag to indicate we've |
| 3319 | // transferred the animation. |
| 3320 | mUseTransferredAnimation = true; |
| 3321 | |
| 3322 | mWmService.updateFocusedWindowLocked( |
| 3323 | UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/); |
| 3324 | getDisplayContent().setLayoutNeeded(); |
| 3325 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
| 3326 | } finally { |
| 3327 | Binder.restoreCallingIdentity(origId); |
| 3328 | } |
| 3329 | return true; |
| 3330 | } else if (fromActivity.mStartingData != null) { |
| 3331 | // The previous app was getting ready to show a |
| 3332 | // starting window, but hasn't yet done so. Steal it! |
| 3333 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, |
| 3334 | "Moving pending starting from %s to %s", fromActivity, this); |
| 3335 | mStartingData = fromActivity.mStartingData; |
| 3336 | fromActivity.mStartingData = null; |
| 3337 | fromActivity.startingMoved = true; |
| 3338 | scheduleAddStartingWindow(); |
| 3339 | return true; |
| 3340 | } |
| 3341 | |
| 3342 | // TODO: Transfer thumbnail |
| 3343 | |
| 3344 | return false; |
| 3345 | } |
| 3346 | |
| 3347 | /** |
| 3348 | * Tries to transfer the starting window from a token that's above ourselves in the task but |
| 3349 | * not visible anymore. This is a common scenario apps use: Trampoline activity T start main |
| 3350 | * activity M in the same task. Now, when reopening the task, T starts on top of M but then |
| 3351 | * immediately finishes after, so we have to transfer T to M. |
| 3352 | */ |
| 3353 | void transferStartingWindowFromHiddenAboveTokenIfNeeded() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3354 | final PooledFunction p = PooledLambda.obtainFunction(ActivityRecord::transferStartingWindow, |
| 3355 | this, PooledLambda.__(ActivityRecord.class)); |
| 3356 | task.forAllActivities(p); |
| 3357 | p.recycle(); |
| 3358 | } |
| 3359 | |
| 3360 | private boolean transferStartingWindow(ActivityRecord fromActivity) { |
| 3361 | if (fromActivity == this) return true; |
| 3362 | |
| 3363 | return !fromActivity.mVisibleRequested && transferStartingWindow(fromActivity.token); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | void checkKeyguardFlagsChanged() { |
| 3367 | final boolean containsDismissKeyguard = containsDismissKeyguardWindow(); |
| 3368 | final boolean containsShowWhenLocked = containsShowWhenLockedWindow(); |
| 3369 | if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow |
| 3370 | || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) { |
| 3371 | mWmService.notifyKeyguardFlagsChanged(null /* callback */, |
| 3372 | getDisplayContent().getDisplayId()); |
| 3373 | } |
| 3374 | mLastContainsDismissKeyguardWindow = containsDismissKeyguard; |
| 3375 | mLastContainsShowWhenLockedWindow = containsShowWhenLocked; |
| 3376 | } |
| 3377 | |
| 3378 | boolean containsDismissKeyguardWindow() { |
| 3379 | // Window state is transient during relaunch. We are not guaranteed to be frozen during the |
| 3380 | // entirety of the relaunch. |
| 3381 | if (isRelaunching()) { |
| 3382 | return mLastContainsDismissKeyguardWindow; |
| 3383 | } |
| 3384 | |
| 3385 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 3386 | if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) { |
| 3387 | return true; |
| 3388 | } |
| 3389 | } |
| 3390 | return false; |
| 3391 | } |
| 3392 | |
| 3393 | boolean containsShowWhenLockedWindow() { |
| 3394 | // When we are relaunching, it is possible for us to be unfrozen before our previous |
| 3395 | // windows have been added back. Using the cached value ensures that our previous |
| 3396 | // showWhenLocked preference is honored until relaunching is complete. |
| 3397 | if (isRelaunching()) { |
| 3398 | return mLastContainsShowWhenLockedWindow; |
| 3399 | } |
| 3400 | |
| 3401 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 3402 | if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
| 3403 | return true; |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | return false; |
| 3408 | } |
| 3409 | |
| 3410 | void setShowWhenLocked(boolean showWhenLocked) { |
| 3411 | mShowWhenLocked = showWhenLocked; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3412 | mAtmService.mRootWindowContainer.ensureActivitiesVisible(null /* starting */, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3413 | 0 /* configChanges */, false /* preserveWindows */); |
| 3414 | } |
| 3415 | |
| 3416 | void setInheritShowWhenLocked(boolean inheritShowWhenLocked) { |
| 3417 | mInheritShownWhenLocked = inheritShowWhenLocked; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3418 | mAtmService.mRootWindowContainer.ensureActivitiesVisible(null /* starting */, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3419 | 0 /* configChanges */, false /* preserveWindows */); |
| 3420 | } |
| 3421 | |
| 3422 | /** |
| 3423 | * @return {@code true} if the activity windowing mode is not |
| 3424 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_PINNED} and a) activity |
| 3425 | * contains windows that have {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} set or if the |
| 3426 | * activity has set {@link #mShowWhenLocked}, or b) if the activity has set |
| 3427 | * {@link #mInheritShownWhenLocked} and the activity behind this satisfies the |
| 3428 | * conditions a) above. |
| 3429 | * Multi-windowing mode will be exited if {@code true} is returned. |
| 3430 | */ |
| 3431 | boolean canShowWhenLocked() { |
| 3432 | if (!inPinnedWindowingMode() && (mShowWhenLocked || containsShowWhenLockedWindow())) { |
| 3433 | return true; |
| 3434 | } else if (mInheritShownWhenLocked) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3435 | final ActivityRecord r = task.getActivityBelow(this); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3436 | return r != null && !r.inPinnedWindowingMode() && (r.mShowWhenLocked |
| 3437 | || r.containsShowWhenLockedWindow()); |
| 3438 | } else { |
| 3439 | return false; |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | /** |
| 3444 | * @return Whether we are allowed to show non-starting windows at the moment. We disallow |
| 3445 | * showing windows during transitions in case we have windows that have wide-color-gamut |
| 3446 | * color mode set to avoid jank in the middle of the transition. |
| 3447 | */ |
| 3448 | boolean canShowWindows() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3449 | return allDrawn && !(isAnimating() && hasNonDefaultColorWindow()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | /** |
| 3453 | * @return true if we have a window that has a non-default color mode set; false otherwise. |
| 3454 | */ |
| 3455 | private boolean hasNonDefaultColorWindow() { |
| 3456 | return forAllWindows(ws -> ws.mAttrs.getColorMode() != COLOR_MODE_DEFAULT, |
| 3457 | true /* topToBottom */); |
| 3458 | } |
| 3459 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3460 | WindowState getImeTargetBelowWindow(WindowState w) { |
| 3461 | final int index = mChildren.indexOf(w); |
| 3462 | if (index > 0) { |
| 3463 | final WindowState target = mChildren.get(index - 1); |
| 3464 | if (target.canBeImeTarget()) { |
| 3465 | return target; |
| 3466 | } |
| 3467 | } |
| 3468 | return null; |
| 3469 | } |
| 3470 | |
| 3471 | WindowState getHighestAnimLayerWindow(WindowState currentTarget) { |
| 3472 | WindowState candidate = null; |
| 3473 | for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) { |
| 3474 | final WindowState w = mChildren.get(i); |
| 3475 | if (w.mRemoved) { |
| 3476 | continue; |
| 3477 | } |
| 3478 | if (candidate == null) { |
| 3479 | candidate = w; |
| 3480 | } |
| 3481 | } |
| 3482 | return candidate; |
| 3483 | } |
| 3484 | |
| 3485 | @Override |
| 3486 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 3487 | // For legacy reasons we process the TaskStack.mExitingActivities first in DisplayContent |
| 3488 | // before the non-exiting app tokens. So, we skip the exiting app tokens here. |
| 3489 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 3490 | // in-order. |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3491 | if (mIsExiting && !forAllWindowsUnchecked(WindowState::waitingForReplacement, true)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3492 | return false; |
| 3493 | } |
| 3494 | return forAllWindowsUnchecked(callback, traverseTopToBottom); |
| 3495 | } |
| 3496 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3497 | boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback, |
| 3498 | boolean traverseTopToBottom) { |
| 3499 | return super.forAllWindows(callback, traverseTopToBottom); |
| 3500 | } |
| 3501 | |
| 3502 | @Override |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3503 | boolean forAllActivities( |
| 3504 | Function<ActivityRecord, Boolean> callback, boolean traverseTopToBottom) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3505 | return callback.apply(this); |
| 3506 | } |
| 3507 | |
| 3508 | @Override |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 3509 | void forAllActivities(Consumer<ActivityRecord> callback, boolean traverseTopToBottom) { |
| 3510 | callback.accept(this); |
| 3511 | } |
| 3512 | |
| 3513 | @Override |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 3514 | ActivityRecord getActivity(Predicate<ActivityRecord> callback, boolean traverseTopToBottom, |
| 3515 | WindowContainer boundary) { |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 3516 | return callback.test(this) ? this : null; |
| 3517 | } |
| 3518 | |
| 3519 | @Override |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3520 | protected void setLayer(Transaction t, int layer) { |
| 3521 | if (!mSurfaceAnimator.hasLeash()) { |
| 3522 | t.setLayer(mSurfaceControl, layer); |
| 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | @Override |
| 3527 | protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) { |
| 3528 | if (!mSurfaceAnimator.hasLeash()) { |
| 3529 | t.setRelativeLayer(mSurfaceControl, relativeTo, layer); |
| 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | @Override |
| 3534 | protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) { |
| 3535 | if (!mSurfaceAnimator.hasLeash()) { |
| 3536 | t.reparent(mSurfaceControl, newParent); |
| 3537 | } |
| 3538 | } |
| 3539 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3540 | void logStartActivity(int tag, Task task) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 3541 | final Uri data = intent.getData(); |
| 3542 | final String strData = data != null ? data.toSafeString() : null; |
| 3543 | |
| 3544 | EventLog.writeEvent(tag, |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 3545 | mUserId, System.identityHashCode(this), task.mTaskId, |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 3546 | shortComponentName, intent.getAction(), |
| 3547 | intent.getType(), strData, intent.getFlags()); |
| 3548 | } |
| 3549 | |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 3550 | UriPermissionOwner getUriPermissionsLocked() { |
| 3551 | if (uriPermissions == null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3552 | uriPermissions = new UriPermissionOwner(mAtmService.mUgmInternal, this); |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 3553 | } |
| 3554 | return uriPermissions; |
| 3555 | } |
| 3556 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3557 | void addResultLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | int requestCode, int resultCode, |
| 3559 | Intent resultData) { |
| 3560 | ActivityResult r = new ActivityResult(from, resultWho, |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 3561 | requestCode, resultCode, resultData); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | if (results == null) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 3563 | results = new ArrayList<ResultInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3564 | } |
| 3565 | results.add(r); |
| 3566 | } |
| 3567 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3568 | void removeResultsLocked(ActivityRecord from, String resultWho, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | int requestCode) { |
| 3570 | if (results != null) { |
| 3571 | for (int i=results.size()-1; i>=0; i--) { |
| 3572 | ActivityResult r = (ActivityResult)results.get(i); |
| 3573 | if (r.mFrom != from) continue; |
| 3574 | if (r.mResultWho == null) { |
| 3575 | if (resultWho != null) continue; |
| 3576 | } else { |
| 3577 | if (!r.mResultWho.equals(resultWho)) continue; |
| 3578 | } |
| 3579 | if (r.mRequestCode != requestCode) continue; |
| 3580 | |
| 3581 | results.remove(i); |
| 3582 | } |
| 3583 | } |
| 3584 | } |
| 3585 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 3586 | void sendResult(int callingUid, String resultWho, int requestCode, int resultCode, |
| 3587 | Intent data) { |
| 3588 | if (callingUid > 0) { |
| 3589 | mAtmService.mUgmInternal.grantUriPermissionFromIntent(callingUid, packageName, |
| 3590 | data, getUriPermissionsLocked(), mUserId); |
| 3591 | } |
| 3592 | |
| 3593 | if (DEBUG_RESULTS) { |
| 3594 | Slog.v(TAG, "Send activity result to " + this |
| 3595 | + " : who=" + resultWho + " req=" + requestCode |
| 3596 | + " res=" + resultCode + " data=" + data); |
| 3597 | } |
| 3598 | if (isState(RESUMED) && attachedToProcess()) { |
| 3599 | try { |
| 3600 | final ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3601 | list.add(new ResultInfo(resultWho, requestCode, resultCode, data)); |
| 3602 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 3603 | ActivityResultItem.obtain(list)); |
| 3604 | return; |
| 3605 | } catch (Exception e) { |
| 3606 | Slog.w(TAG, "Exception thrown sending result to " + this, e); |
| 3607 | } |
| 3608 | } |
| 3609 | |
| 3610 | addResultLocked(null /* from */, resultWho, requestCode, resultCode, data); |
| 3611 | } |
| 3612 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3613 | private void addNewIntentLocked(ReferrerIntent intent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3614 | if (newIntents == null) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3615 | newIntents = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3616 | } |
| 3617 | newIntents.add(intent); |
| 3618 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 3619 | |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 3620 | final boolean isSleeping() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3621 | final ActivityStack stack = getActivityStack(); |
| 3622 | return stack != null ? stack.shouldSleepActivities() : mAtmService.isSleepingLocked(); |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3625 | /** |
| 3626 | * Deliver a new Intent to an existing activity, so that its onNewIntent() |
| 3627 | * method will be called at the proper time. |
| 3628 | */ |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3629 | final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) { |
Dianne Hackborn | 514074f | 2013-02-11 10:52:46 -0800 | [diff] [blame] | 3630 | // The activity now gets access to the data associated with this Intent. |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3631 | mAtmService.mUgmInternal.grantUriPermissionFromIntent(callingUid, packageName, |
| 3632 | intent, getUriPermissionsLocked(), mUserId); |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3633 | final ReferrerIntent rintent = new ReferrerIntent(intent, referrer); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3634 | boolean unsent = true; |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 3635 | final boolean isTopActivityWhileSleeping = isTopRunningActivity() && isSleeping(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3636 | |
| 3637 | // We want to immediately deliver the intent to the activity if: |
Wale Ogunwale | 03f7e9e | 2016-09-22 09:04:09 -0700 | [diff] [blame] | 3638 | // - It is currently resumed or paused. i.e. it is currently visible to the user and we want |
| 3639 | // 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] | 3640 | // - 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] | 3641 | if ((mState == RESUMED || mState == PAUSED || isTopActivityWhileSleeping) |
| 3642 | && attachedToProcess()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3643 | try { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3644 | ArrayList<ReferrerIntent> ar = new ArrayList<>(1); |
| 3645 | ar.add(rintent); |
Louis Chang | ea203cd | 2019-07-01 12:39:31 +0800 | [diff] [blame] | 3646 | // Making sure the client state is RESUMED after transaction completed and doing |
| 3647 | // so only if activity is currently RESUMED. Otherwise, client may have extra |
| 3648 | // life-cycle calls to RESUMED (and PAUSED later). |
Louis Chang | 92d1652 | 2019-02-27 12:56:18 +0800 | [diff] [blame] | 3649 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Louis Chang | ea203cd | 2019-07-01 12:39:31 +0800 | [diff] [blame] | 3650 | NewIntentItem.obtain(ar, mState == RESUMED)); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3651 | unsent = false; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 3652 | } catch (RemoteException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3653 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 3654 | } catch (NullPointerException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3655 | Slog.w(TAG, "Exception thrown sending new intent to " + this, e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3656 | } |
| 3657 | } |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3658 | if (unsent) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3659 | addNewIntentLocked(rintent); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3660 | } |
| 3661 | } |
| 3662 | |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 3663 | void updateOptionsLocked(ActivityOptions options) { |
| 3664 | if (options != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3665 | if (DEBUG_TRANSITION) Slog.i(TAG, "Update options for " + this); |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 3666 | if (pendingOptions != null) { |
| 3667 | pendingOptions.abort(); |
| 3668 | } |
| 3669 | pendingOptions = options; |
| 3670 | } |
| 3671 | } |
| 3672 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 3673 | void applyOptionsLocked() { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 3674 | if (pendingOptions != null |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 3675 | && pendingOptions.getAnimationType() != ANIM_SCENE_TRANSITION) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3676 | if (DEBUG_TRANSITION) Slog.i(TAG, "Applying options for " + this); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3677 | applyOptionsLocked(pendingOptions, intent); |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 3678 | if (task == null) { |
| 3679 | clearOptionsLocked(false /* withAbort */); |
| 3680 | } else { |
| 3681 | // This will clear the options for all the ActivityRecords for this Task. |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3682 | task.forAllActivities((r) -> { |
| 3683 | r.clearOptionsLocked(false /* withAbort */); |
| 3684 | }); |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 3685 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 3686 | } |
| 3687 | } |
| 3688 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3689 | /** |
| 3690 | * Apply override app transition base on options & animation type. |
| 3691 | */ |
| 3692 | void applyOptionsLocked(ActivityOptions pendingOptions, Intent intent) { |
| 3693 | final int animationType = pendingOptions.getAnimationType(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 3694 | final DisplayContent displayContent = getDisplayContent(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3695 | switch (animationType) { |
| 3696 | case ANIM_CUSTOM: |
| 3697 | displayContent.mAppTransition.overridePendingAppTransition( |
| 3698 | pendingOptions.getPackageName(), |
| 3699 | pendingOptions.getCustomEnterResId(), |
| 3700 | pendingOptions.getCustomExitResId(), |
| 3701 | pendingOptions.getOnAnimationStartListener()); |
| 3702 | break; |
| 3703 | case ANIM_CLIP_REVEAL: |
| 3704 | displayContent.mAppTransition.overridePendingAppTransitionClipReveal( |
| 3705 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 3706 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 3707 | if (intent.getSourceBounds() == null) { |
| 3708 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 3709 | pendingOptions.getStartY(), |
| 3710 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 3711 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 3712 | } |
| 3713 | break; |
| 3714 | case ANIM_SCALE_UP: |
| 3715 | displayContent.mAppTransition.overridePendingAppTransitionScaleUp( |
| 3716 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 3717 | pendingOptions.getWidth(), pendingOptions.getHeight()); |
| 3718 | if (intent.getSourceBounds() == null) { |
| 3719 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 3720 | pendingOptions.getStartY(), |
| 3721 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 3722 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 3723 | } |
| 3724 | break; |
| 3725 | case ANIM_THUMBNAIL_SCALE_UP: |
| 3726 | case ANIM_THUMBNAIL_SCALE_DOWN: |
| 3727 | final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP); |
| 3728 | final GraphicBuffer buffer = pendingOptions.getThumbnail(); |
| 3729 | displayContent.mAppTransition.overridePendingAppTransitionThumb(buffer, |
| 3730 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 3731 | pendingOptions.getOnAnimationStartListener(), |
| 3732 | scaleUp); |
| 3733 | if (intent.getSourceBounds() == null && buffer != null) { |
| 3734 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 3735 | pendingOptions.getStartY(), |
| 3736 | pendingOptions.getStartX() + buffer.getWidth(), |
| 3737 | pendingOptions.getStartY() + buffer.getHeight())); |
| 3738 | } |
| 3739 | break; |
| 3740 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 3741 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
| 3742 | final AppTransitionAnimationSpec[] specs = pendingOptions.getAnimSpecs(); |
| 3743 | final IAppTransitionAnimationSpecsFuture specsFuture = |
| 3744 | pendingOptions.getSpecsFuture(); |
| 3745 | if (specsFuture != null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3746 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumbFuture( |
| 3747 | specsFuture, pendingOptions.getOnAnimationStartListener(), |
| 3748 | animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP); |
| 3749 | } else if (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_DOWN |
| 3750 | && specs != null) { |
| 3751 | displayContent.mAppTransition.overridePendingAppTransitionMultiThumb( |
| 3752 | specs, pendingOptions.getOnAnimationStartListener(), |
| 3753 | pendingOptions.getAnimationFinishedListener(), false); |
| 3754 | } else { |
| 3755 | displayContent.mAppTransition.overridePendingAppTransitionAspectScaledThumb( |
| 3756 | pendingOptions.getThumbnail(), |
| 3757 | pendingOptions.getStartX(), pendingOptions.getStartY(), |
| 3758 | pendingOptions.getWidth(), pendingOptions.getHeight(), |
| 3759 | pendingOptions.getOnAnimationStartListener(), |
| 3760 | (animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP)); |
| 3761 | if (intent.getSourceBounds() == null) { |
| 3762 | intent.setSourceBounds(new Rect(pendingOptions.getStartX(), |
| 3763 | pendingOptions.getStartY(), |
| 3764 | pendingOptions.getStartX() + pendingOptions.getWidth(), |
| 3765 | pendingOptions.getStartY() + pendingOptions.getHeight())); |
| 3766 | } |
| 3767 | } |
| 3768 | break; |
| 3769 | case ANIM_OPEN_CROSS_PROFILE_APPS: |
| 3770 | displayContent.mAppTransition |
| 3771 | .overridePendingAppTransitionStartCrossProfileApps(); |
| 3772 | break; |
| 3773 | case ANIM_REMOTE_ANIMATION: |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3774 | displayContent.mAppTransition.overridePendingAppTransitionRemote( |
| 3775 | pendingOptions.getRemoteAnimationAdapter()); |
| 3776 | break; |
| 3777 | case ANIM_NONE: |
Louis Chang | 477e93e | 2019-04-24 18:35:20 +0800 | [diff] [blame] | 3778 | case ANIM_UNDEFINED: |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3779 | break; |
| 3780 | default: |
| 3781 | Slog.e(TAG_WM, "applyOptionsLocked: Unknown animationType=" + animationType); |
| 3782 | break; |
| 3783 | } |
| 3784 | } |
| 3785 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3786 | void clearAllDrawn() { |
| 3787 | allDrawn = false; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | /** |
| 3791 | * Returns whether the drawn window states of this {@link ActivityRecord} has considered every |
| 3792 | * child {@link WindowState}. A child is considered if it has been passed into |
| 3793 | * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine |
| 3794 | * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as |
| 3795 | * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered. |
| 3796 | * |
| 3797 | * @return {@code true} If all children have been considered, {@code false}. |
| 3798 | */ |
| 3799 | private boolean allDrawnStatesConsidered() { |
| 3800 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 3801 | final WindowState child = mChildren.get(i); |
| 3802 | if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) { |
| 3803 | return false; |
| 3804 | } |
| 3805 | } |
| 3806 | return true; |
| 3807 | } |
| 3808 | |
| 3809 | /** |
| 3810 | * Determines if the token has finished drawing. This should only be called from |
| 3811 | * {@link DisplayContent#applySurfaceChangesTransaction} |
| 3812 | */ |
| 3813 | void updateAllDrawn() { |
| 3814 | if (!allDrawn) { |
| 3815 | // Number of drawn windows can be less when a window is being relaunched, wait for |
| 3816 | // all windows to be launched and drawn for this token be considered all drawn. |
| 3817 | final int numInteresting = mNumInterestingWindows; |
| 3818 | |
| 3819 | // We must make sure that all present children have been considered (determined by |
| 3820 | // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been |
| 3821 | // drawn. |
| 3822 | if (numInteresting > 0 && allDrawnStatesConsidered() |
| 3823 | && mNumDrawnWindows >= numInteresting && !isRelaunching()) { |
| 3824 | if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this |
| 3825 | + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows); |
| 3826 | allDrawn = true; |
| 3827 | // Force an additional layout pass where |
| 3828 | // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked(). |
| 3829 | if (mDisplayContent != null) { |
| 3830 | mDisplayContent.setLayoutNeeded(); |
| 3831 | } |
| 3832 | mWmService.mH.obtainMessage(H.NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
| 3833 | |
| 3834 | // Notify the pinned stack upon all windows drawn. If there was an animation in |
| 3835 | // progress then this signal will resume that animation. |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3836 | final ActivityStack pinnedStack = mDisplayContent.getPinnedStack(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3837 | if (pinnedStack != null) { |
| 3838 | pinnedStack.onAllWindowsDrawn(); |
| 3839 | } |
| 3840 | } |
| 3841 | } |
| 3842 | } |
| 3843 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3844 | ActivityOptions getOptionsForTargetActivityLocked() { |
| 3845 | return pendingOptions != null ? pendingOptions.forTargetActivity() : null; |
| 3846 | } |
| 3847 | |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 3848 | void clearOptionsLocked() { |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 3849 | clearOptionsLocked(true /* withAbort */); |
| 3850 | } |
| 3851 | |
| 3852 | void clearOptionsLocked(boolean withAbort) { |
| 3853 | if (withAbort && pendingOptions != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3854 | pendingOptions.abort(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3855 | } |
chaviw | 82a0ba8 | 2018-03-15 14:26:29 -0700 | [diff] [blame] | 3856 | pendingOptions = null; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 3857 | } |
| 3858 | |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3859 | ActivityOptions takeOptionsLocked(boolean fromClient) { |
| 3860 | if (DEBUG_TRANSITION) Slog.i(TAG, "Taking options for " + this + " callers=" |
| 3861 | + Debug.getCallers(6)); |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 3862 | ActivityOptions opts = pendingOptions; |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3863 | |
| 3864 | // If we are trying to take activity options from the client, do not null it out if it's a |
| 3865 | // remote animation as the client doesn't need it ever. This is a workaround when client is |
| 3866 | // faster to take the options than we are to resume the next activity. |
| 3867 | // TODO (b/132432864): Fix the root cause of these transition preparing/applying options |
| 3868 | // timing somehow |
| 3869 | if (!fromClient || opts == null || opts.getRemoteAnimationAdapter() == null) { |
| 3870 | pendingOptions = null; |
| 3871 | } |
Dianne Hackborn | 9622ca4 | 2012-10-23 18:56:33 -0700 | [diff] [blame] | 3872 | return opts; |
| 3873 | } |
| 3874 | |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 3875 | boolean allowMoveToFront() { |
| 3876 | return pendingOptions == null || !pendingOptions.getAvoidMoveToFront(); |
| 3877 | } |
| 3878 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3879 | void removeUriPermissionsLocked() { |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 3880 | if (uriPermissions != null) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 3881 | uriPermissions.removeUriPermissions(); |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 3882 | uriPermissions = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3883 | } |
| 3884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | |
| 3886 | void pauseKeyDispatchingLocked() { |
| 3887 | if (!keysPaused) { |
| 3888 | keysPaused = true; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 3889 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 3890 | if (getDisplayContent() != null) { |
| 3891 | getDisplayContent().getInputMonitor().pauseDispatchingLw(this); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 3892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | void resumeKeyDispatchingLocked() { |
| 3897 | if (keysPaused) { |
| 3898 | keysPaused = false; |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 3899 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 3900 | if (getDisplayContent() != null) { |
| 3901 | getDisplayContent().getInputMonitor().resumeDispatchingLw(this); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 3902 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3903 | } |
| 3904 | } |
| 3905 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 3906 | private void updateTaskDescription(CharSequence description) { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 3907 | task.lastDescription = description; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 3910 | void setDeferHidingClient(boolean deferHidingClient) { |
| 3911 | if (mDeferHidingClient == deferHidingClient) { |
| 3912 | return; |
| 3913 | } |
| 3914 | mDeferHidingClient = deferHidingClient; |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 3915 | if (!mDeferHidingClient && !mVisibleRequested) { |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 3916 | // Hiding the client is no longer deferred and the app isn't visible still, go ahead and |
| 3917 | // update the visibility. |
| 3918 | setVisibility(false); |
| 3919 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 3920 | } |
| 3921 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3922 | @Override |
| 3923 | boolean isVisible() { |
| 3924 | // If the activity isn't hidden then it is considered visible and there is no need to check |
| 3925 | // its children windows to see if they are visible. |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 3926 | return mVisible; |
| 3927 | } |
| 3928 | |
| 3929 | void setVisible(boolean visible) { |
| 3930 | if (visible != mVisible) { |
| 3931 | mVisible = visible; |
| 3932 | scheduleAnimation(); |
| 3933 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3936 | /** |
| 3937 | * Set visibility on this {@link ActivityRecord} |
| 3938 | * |
| 3939 | * <p class="note"><strong>Note: </strong>This function might not update the visibility of |
| 3940 | * this {@link ActivityRecord} immediately. In case we are preparing an app transition, we |
| 3941 | * delay changing the visibility of this {@link ActivityRecord} until we execute that |
| 3942 | * transition.</p> |
| 3943 | * |
| 3944 | * @param visible {@code true} if the {@link ActivityRecord} should become visible, otherwise |
| 3945 | * this should become invisible. |
| 3946 | */ |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 3947 | void setVisibility(boolean visible) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 3948 | if (getParent() == null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3949 | Slog.w(TAG_WM, "Attempted to set visibility of non-existing app token: " |
| 3950 | + appToken); |
| 3951 | return; |
| 3952 | } |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 3953 | if (visible) { |
| 3954 | mDeferHidingClient = false; |
| 3955 | } |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 3956 | setVisibility(visible, mDeferHidingClient); |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 3957 | mAtmService.addWindowLayoutReasons( |
| 3958 | ActivityTaskManagerService.LAYOUT_REASON_VISIBILITY_CHANGED); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 3959 | mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3960 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 3961 | } |
| 3962 | |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 3963 | @VisibleForTesting |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3964 | void setVisibility(boolean visible, boolean deferHidingClient) { |
| 3965 | final AppTransition appTransition = getDisplayContent().mAppTransition; |
| 3966 | |
| 3967 | // Don't set visibility to false if we were already not visible. This prevents WM from |
| 3968 | // adding the app to the closing app list which doesn't make sense for something that is |
| 3969 | // already not visible. However, set visibility to true even if we are already visible. |
| 3970 | // This makes sure the app is added to the opening apps list so that the right |
| 3971 | // transition can be selected. |
| 3972 | // TODO: Probably a good idea to separate the concept of opening/closing apps from the |
| 3973 | // concept of setting visibility... |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 3974 | if (!visible && !mVisibleRequested) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3975 | |
| 3976 | if (!deferHidingClient && mLastDeferHidingClient) { |
| 3977 | // We previously deferred telling the client to hide itself when visibility was |
| 3978 | // initially set to false. Now we would like it to hide, so go ahead and set it. |
| 3979 | mLastDeferHidingClient = deferHidingClient; |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3980 | setClientVisible(false); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3981 | } |
| 3982 | return; |
| 3983 | } |
| 3984 | |
| 3985 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 3986 | "setAppVisibility(%s, visible=%b): %s visible=%b mVisibleRequested=%b Callers=%s", |
| 3987 | appToken, visible, appTransition, isVisible(), mVisibleRequested, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3988 | Debug.getCallers(6)); |
| 3989 | |
| 3990 | final DisplayContent displayContent = getDisplayContent(); |
| 3991 | displayContent.mOpeningApps.remove(this); |
| 3992 | displayContent.mClosingApps.remove(this); |
| 3993 | if (isInChangeTransition()) { |
| 3994 | clearChangeLeash(getPendingTransaction(), true /* cancel */); |
| 3995 | } |
| 3996 | displayContent.mChangingApps.remove(this); |
| 3997 | waitingToShow = false; |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 3998 | mVisibleRequested = visible; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3999 | mLastDeferHidingClient = deferHidingClient; |
| 4000 | |
| 4001 | if (!visible) { |
| 4002 | // If the app is dead while it was visible, we kept its dead window on screen. |
| 4003 | // Now that the app is going invisible, we can remove it. It will be restarted |
| 4004 | // if made visible again. |
| 4005 | removeDeadWindows(); |
| 4006 | } else { |
| 4007 | if (!appTransition.isTransitionSet() |
| 4008 | && appTransition.isReady()) { |
| 4009 | // Add the app mOpeningApps if transition is unset but ready. This means |
| 4010 | // we're doing a screen freeze, and the unfreeze will wait for all opening |
| 4011 | // apps to be ready. |
| 4012 | displayContent.mOpeningApps.add(this); |
| 4013 | } |
| 4014 | startingMoved = false; |
| 4015 | // If the token is currently hidden (should be the common case), or has been |
| 4016 | // stopped, then we need to set up to wait for its windows to be ready. |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 4017 | if (!isVisible() || mAppStopped) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4018 | clearAllDrawn(); |
| 4019 | |
| 4020 | // If the app was already visible, don't reset the waitingToShow state. |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 4021 | if (!isVisible()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4022 | waitingToShow = true; |
| 4023 | |
| 4024 | // If the client isn't hidden, we don't need to reset the drawing state. |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4025 | if (!isClientVisible()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4026 | // Let's reset the draw state in order to prevent the starting window to be |
| 4027 | // immediately dismissed when the app still has the surface. |
| 4028 | forAllWindows(w -> { |
| 4029 | if (w.mWinAnimator.mDrawState == HAS_DRAWN) { |
| 4030 | w.mWinAnimator.resetDrawState(); |
| 4031 | |
| 4032 | // Force add to mResizingWindows, so that we are guaranteed to get |
| 4033 | // another reportDrawn callback. |
| 4034 | w.resetLastContentInsets(); |
| 4035 | } |
| 4036 | }, true /* traverseTopToBottom */); |
| 4037 | } |
| 4038 | } |
| 4039 | } |
| 4040 | |
| 4041 | // In the case where we are making an app visible but holding off for a transition, |
| 4042 | // we still need to tell the client to make its windows visible so they get drawn. |
| 4043 | // Otherwise, we will wait on performing the transition until all windows have been |
| 4044 | // drawn, they never will be, and we are sad. |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4045 | setClientVisible(true); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4046 | |
| 4047 | requestUpdateWallpaperIfNeeded(); |
| 4048 | |
| 4049 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, "No longer Stopped: %s", this); |
| 4050 | mAppStopped = false; |
| 4051 | |
| 4052 | transferStartingWindowFromHiddenAboveTokenIfNeeded(); |
| 4053 | } |
| 4054 | |
| 4055 | // If we are preparing an app transition, then delay changing |
| 4056 | // the visibility of this token until we execute that transition. |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 4057 | // Note that we ignore display frozen since we want the opening / closing transition type |
| 4058 | // can be updated correctly even display frozen, and it's safe since in applyAnimation will |
| 4059 | // still check DC#okToAnimate again if the transition animation is fine to apply. |
| 4060 | if (okToAnimate(true /* ignoreFrozen */) && appTransition.isTransitionSet()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4061 | if (visible) { |
| 4062 | displayContent.mOpeningApps.add(this); |
| 4063 | mEnteringAnimation = true; |
| 4064 | } else { |
| 4065 | displayContent.mClosingApps.add(this); |
| 4066 | mEnteringAnimation = false; |
| 4067 | } |
| 4068 | if (appTransition.getAppTransition() == TRANSIT_TASK_OPEN_BEHIND) { |
| 4069 | // We're launchingBehind, add the launching activity to mOpeningApps. |
| 4070 | final WindowState win = getDisplayContent().findFocusedWindow(); |
| 4071 | if (win != null) { |
| 4072 | final ActivityRecord focusedActivity = win.mActivityRecord; |
| 4073 | if (focusedActivity != null) { |
| 4074 | ProtoLog.d(WM_DEBUG_APP_TRANSITIONS, |
| 4075 | "TRANSIT_TASK_OPEN_BEHIND, adding %s to mOpeningApps", |
| 4076 | focusedActivity); |
| 4077 | |
| 4078 | // Force animation to be loaded. |
| 4079 | displayContent.mOpeningApps.add(focusedActivity); |
| 4080 | } |
| 4081 | } |
| 4082 | } |
| 4083 | return; |
| 4084 | } |
| 4085 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4086 | commitVisibility(visible, true /* performLayout */); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4087 | updateReportedVisibilityLocked(); |
| 4088 | } |
| 4089 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4090 | @Override |
| 4091 | boolean applyAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, |
| 4092 | boolean isVoiceInteraction) { |
| 4093 | if (mUseTransferredAnimation) { |
| 4094 | return false; |
| 4095 | } |
| 4096 | return super.applyAnimation(lp, transit, enter, isVoiceInteraction); |
| 4097 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4098 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4099 | /** |
| 4100 | * Update visibility to this {@link ActivityRecord}. |
| 4101 | * |
| 4102 | * <p class="note"><strong>Note: </strong> Unlike {@link #setVisibility}, this immediately |
| 4103 | * updates the visibility without starting an app transition. Since this function may start |
| 4104 | * animation on {@link WindowState} depending on app transition animation status, an app |
| 4105 | * transition animation must be started before calling this function if necessary.</p> |
| 4106 | * |
| 4107 | * @param visible {@code true} if this {@link ActivityRecord} should become visible, otherwise |
| 4108 | * this should become invisible. |
| 4109 | * @param performLayout if {@code true}, perform surface placement after committing visibility. |
| 4110 | */ |
| 4111 | void commitVisibility(boolean visible, boolean performLayout) { |
| 4112 | // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4113 | // been set by the app now. |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 4114 | mVisibleSetFromTransferredStartingWindow = false; |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4115 | if (visible == isVisible()) { |
| 4116 | return; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4117 | } |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4118 | |
| 4119 | final int windowsCount = mChildren.size(); |
| 4120 | for (int i = 0; i < windowsCount; i++) { |
| 4121 | mChildren.get(i).onAppVisibilityChanged(visible, isAnimating(PARENTS)); |
| 4122 | } |
| 4123 | setVisible(visible); |
| 4124 | mVisibleRequested = visible; |
| 4125 | if (!visible) { |
| 4126 | stopFreezingScreen(true, true); |
| 4127 | } else { |
| 4128 | // If we are being set visible, and the starting window is not yet displayed, |
| 4129 | // then make sure it doesn't get displayed. |
| 4130 | if (startingWindow != null && !startingWindow.isDrawnLw()) { |
| 4131 | startingWindow.clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY); |
| 4132 | startingWindow.mLegacyPolicyVisibilityAfterAnim = false; |
| 4133 | } |
| 4134 | // We are becoming visible, so better freeze the screen with the windows that are |
| 4135 | // getting visible so we also wait for them. |
| 4136 | forAllWindows(mWmService::makeWindowFreezingScreenIfNeededLocked, true); |
| 4137 | } |
| 4138 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 4139 | "commitVisibility: %s: visible=%b mVisibleRequested=%b", this, |
| 4140 | isVisible(), mVisibleRequested); |
| 4141 | final DisplayContent displayContent = getDisplayContent(); |
| 4142 | displayContent.getInputMonitor().setUpdateInputWindowsNeededLw(); |
| 4143 | if (performLayout) { |
| 4144 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4145 | false /*updateInputWindows*/); |
| 4146 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
| 4147 | } |
| 4148 | displayContent.getInputMonitor().updateInputWindowsLw(false /*force*/); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4149 | mUseTransferredAnimation = false; |
| 4150 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4151 | postApplyAnimation(visible); |
| 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * Post process after applying an app transition animation. |
| 4156 | * |
| 4157 | * <p class="note"><strong>Note: </strong> This function must be called after the animations |
| 4158 | * have been applied and {@link #commitVisibility}.</p> |
| 4159 | * |
| 4160 | * @param visible {@code true} if this {@link ActivityRecord} has become visible, otherwise |
| 4161 | * this has become invisible. |
| 4162 | */ |
| 4163 | private void postApplyAnimation(boolean visible) { |
| 4164 | final boolean delayed = isAnimating(PARENTS | CHILDREN); |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4165 | if (!delayed) { |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4166 | // We aren't delayed anything, but exiting windows rely on the animation finished |
| 4167 | // callback being called in case the ActivityRecord was pretending to be delayed, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4168 | // which we might have done because we were in closing/opening apps list. |
| 4169 | onAnimationFinished(); |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4170 | if (visible) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4171 | // The token was made immediately visible, there will be no entrance animation. |
| 4172 | // We need to inform the client the enter animation was finished. |
| 4173 | mEnteringAnimation = true; |
| 4174 | mWmService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked( |
| 4175 | token); |
| 4176 | } |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4177 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4178 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4179 | // If we're becoming visible, immediately change client visibility as well. there seem |
| 4180 | // to be some edge cases where we change our visibility but client visibility never gets |
| 4181 | // updated. |
| 4182 | // If we're becoming invisible, update the client visibility if we are not running an |
| 4183 | // animation. Otherwise, we'll update client visibility in onAnimationFinished. |
| 4184 | if (visible || !isAnimating(PARENTS)) { |
| 4185 | setClientVisible(visible); |
| 4186 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4187 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4188 | final DisplayContent displayContent = getDisplayContent(); |
| 4189 | if (!displayContent.mClosingApps.contains(this) |
| 4190 | && !displayContent.mOpeningApps.contains(this)) { |
| 4191 | // The token is not closing nor opening, so even if there is an animation set, that |
| 4192 | // doesn't mean that it goes through the normal app transition cycle so we have |
| 4193 | // to inform the docked controller about visibility change. |
| 4194 | // TODO(multi-display): notify docked divider on all displays where visibility was |
| 4195 | // affected. |
| 4196 | displayContent.getDockedDividerController().notifyAppVisibilityChanged(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4197 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4198 | // Take the screenshot before possibly hiding the WSA, otherwise the screenshot |
| 4199 | // will not be taken. |
| 4200 | mWmService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible); |
| 4201 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4202 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4203 | // If we are hidden but there is no delay needed we immediately |
| 4204 | // apply the Surface transaction so that the ActivityManager |
| 4205 | // can have some guarantee on the Surface state following |
| 4206 | // setting the visibility. This captures cases like dismissing |
| 4207 | // the docked or pinned stack where there is no app transition. |
| 4208 | // |
| 4209 | // In the case of a "Null" animation, there will be |
| 4210 | // no animation but there will still be a transition set. |
| 4211 | // We still need to delay hiding the surface such that it |
| 4212 | // can be synchronized with showing the next surface in the transition. |
| 4213 | if (!isVisible() && !delayed && !displayContent.mAppTransition.isTransitionSet()) { |
| 4214 | SurfaceControl.openTransaction(); |
| 4215 | try { |
| 4216 | forAllWindows(win -> { |
| 4217 | win.mWinAnimator.hide("immediately hidden"); }, true); |
| 4218 | } finally { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4219 | SurfaceControl.closeTransaction(); |
| 4220 | } |
| 4221 | } |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4222 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4223 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4224 | /** |
| 4225 | * Check if visibility of this {@link ActivityRecord} should be updated as part of an app |
| 4226 | * transition. |
| 4227 | * |
| 4228 | * <p class="note><strong>Note:</strong> If the visibility of this {@link ActivityRecord} is |
Issei Suzuki | 0ae90d0 | 2019-10-18 17:39:15 +0200 | [diff] [blame] | 4229 | * already set to {@link #mVisible}, we don't need to update the visibility. So {@code false} is |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4230 | * returned.</p> |
| 4231 | * |
| 4232 | * @param visible {@code true} if this {@link ActivityRecord} should become visible, |
| 4233 | * {@code false} if this should become invisible. |
| 4234 | * @return {@code true} if visibility of this {@link ActivityRecord} should be updated, and |
| 4235 | * an app transition animation should be run. |
| 4236 | */ |
| 4237 | boolean shouldApplyAnimation(boolean visible) { |
| 4238 | // Allow for state update and animation to be applied if: |
Issei Suzuki | 0ae90d0 | 2019-10-18 17:39:15 +0200 | [diff] [blame] | 4239 | // * activity is transitioning visibility state |
| 4240 | // * or the activity was marked as hidden and is exiting before we had a chance to play the |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4241 | // transition animation |
Issei Suzuki | 0ae90d0 | 2019-10-18 17:39:15 +0200 | [diff] [blame] | 4242 | // * or this is an opening app and windows are being replaced (e.g. freeform window to |
| 4243 | // normal window). |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 4244 | return isVisible() != visible || (!isVisible() && mIsExiting) |
Issei Suzuki | 0ae90d0 | 2019-10-18 17:39:15 +0200 | [diff] [blame] | 4245 | || (visible && forAllWindows(WindowState::waitingForReplacement, true)); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4248 | /** |
| 4249 | * See {@link Activity#setDisablePreviewScreenshots}. |
| 4250 | */ |
| 4251 | void setDisablePreviewScreenshots(boolean disable) { |
| 4252 | mDisablePreviewScreenshots = disable; |
| 4253 | } |
| 4254 | |
| 4255 | /** |
| 4256 | * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is |
| 4257 | * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when |
| 4258 | * we can't take a snapshot for other reasons, for example, if we have a secure window. |
| 4259 | * |
| 4260 | * @return True if we need to generate an app theme snapshot, false if we'd like to take a real |
| 4261 | * screenshot. |
| 4262 | */ |
| 4263 | boolean shouldUseAppThemeSnapshot() { |
| 4264 | return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0, |
| 4265 | true /* topToBottom */); |
| 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * Sets whether the current launch can turn the screen on. |
| 4270 | * @see #currentLaunchCanTurnScreenOn() |
| 4271 | */ |
| 4272 | void setCurrentLaunchCanTurnScreenOn(boolean currentLaunchCanTurnScreenOn) { |
| 4273 | mCurrentLaunchCanTurnScreenOn = currentLaunchCanTurnScreenOn; |
| 4274 | } |
| 4275 | |
| 4276 | /** |
| 4277 | * Indicates whether the current launch can turn the screen on. This is to prevent multiple |
| 4278 | * relayouts from turning the screen back on. The screen should only turn on at most |
| 4279 | * once per activity resume. |
| 4280 | * <p> |
| 4281 | * Note this flag is only meaningful when {@link WindowManager.LayoutParams#FLAG_TURN_SCREEN_ON} |
| 4282 | * or {@link ActivityRecord#canTurnScreenOn} is set. |
| 4283 | * |
| 4284 | * @return {@code true} if the activity is ready to turn on the screen. |
| 4285 | */ |
| 4286 | boolean currentLaunchCanTurnScreenOn() { |
| 4287 | return mCurrentLaunchCanTurnScreenOn; |
| 4288 | } |
| 4289 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4290 | void setState(ActivityState state, String reason) { |
| 4291 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State movement: " + this + " from:" + getState() |
| 4292 | + " to:" + state + " reason:" + reason); |
Bryce Lee | 6ff1707 | 2018-02-28 07:26:17 -0800 | [diff] [blame] | 4293 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4294 | if (state == mState) { |
| 4295 | // No need to do anything if state doesn't change. |
| 4296 | if (DEBUG_STATES) Slog.v(TAG_STATES, "State unchanged from:" + state); |
| 4297 | return; |
| 4298 | } |
| 4299 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4300 | mState = state; |
| 4301 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4302 | if (task != null) { |
| 4303 | task.onActivityStateChanged(this, state, reason); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 4304 | } |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 4305 | |
Robert Carr | 9e1bf7c | 2018-05-31 15:39:07 -0700 | [diff] [blame] | 4306 | // The WindowManager interprets the app stopping signal as |
| 4307 | // an indication that the Surface will eventually be destroyed. |
| 4308 | // This however isn't necessarily true if we are going to sleep. |
| 4309 | if (state == STOPPING && !isSleeping()) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 4310 | if (getParent() == null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 4311 | Slog.w(TAG_WM, "Attempted to notify stopping on non-existing app token: " |
| 4312 | + appToken); |
| 4313 | return; |
| 4314 | } |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 4315 | detachChildren(); |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 4316 | } |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 4317 | |
| 4318 | if (state == RESUMED) { |
| 4319 | mAtmService.updateBatteryStats(this, true); |
| 4320 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_RESUMED); |
| 4321 | } else if (state == PAUSED) { |
| 4322 | mAtmService.updateBatteryStats(this, false); |
| 4323 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_PAUSED); |
| 4324 | } else if (state == STOPPED) { |
| 4325 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_STOPPED); |
| 4326 | } else if (state == DESTROYED) { |
| 4327 | mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_DESTROYED); |
| 4328 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | ActivityState getState() { |
| 4332 | return mState; |
| 4333 | } |
| 4334 | |
| 4335 | /** |
| 4336 | * Returns {@code true} if the Activity is in the specified state. |
| 4337 | */ |
| 4338 | boolean isState(ActivityState state) { |
| 4339 | return state == mState; |
| 4340 | } |
| 4341 | |
| 4342 | /** |
| 4343 | * Returns {@code true} if the Activity is in one of the specified states. |
| 4344 | */ |
| 4345 | boolean isState(ActivityState state1, ActivityState state2) { |
| 4346 | return state1 == mState || state2 == mState; |
| 4347 | } |
| 4348 | |
| 4349 | /** |
| 4350 | * Returns {@code true} if the Activity is in one of the specified states. |
| 4351 | */ |
| 4352 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3) { |
| 4353 | return state1 == mState || state2 == mState || state3 == mState; |
| 4354 | } |
| 4355 | |
| 4356 | /** |
| 4357 | * Returns {@code true} if the Activity is in one of the specified states. |
| 4358 | */ |
| 4359 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3, |
| 4360 | ActivityState state4) { |
| 4361 | return state1 == mState || state2 == mState || state3 == mState || state4 == mState; |
| 4362 | } |
| 4363 | |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 4364 | /** |
| 4365 | * Returns {@code true} if the Activity is in one of the specified states. |
| 4366 | */ |
| 4367 | boolean isState(ActivityState state1, ActivityState state2, ActivityState state3, |
| 4368 | ActivityState state4, ActivityState state5) { |
| 4369 | return state1 == mState || state2 == mState || state3 == mState || state4 == mState |
| 4370 | || state5 == mState; |
| 4371 | } |
| 4372 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4373 | void destroySurfaces() { |
| 4374 | destroySurfaces(false /*cleanupOnResume*/); |
| 4375 | } |
| 4376 | |
| 4377 | /** |
| 4378 | * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure |
| 4379 | * the client has finished with them. |
| 4380 | * |
| 4381 | * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If |
| 4382 | * set to true, destroy only surfaces of removed windows, and clear relevant flags of the |
| 4383 | * others so that they are ready to be reused. If set to false (common case), destroy all |
| 4384 | * surfaces that's eligible, if the app is already stopped. |
| 4385 | */ |
| 4386 | private void destroySurfaces(boolean cleanupOnResume) { |
| 4387 | boolean destroyedSomething = false; |
| 4388 | |
| 4389 | // Copying to a different list as multiple children can be removed. |
| 4390 | final ArrayList<WindowState> children = new ArrayList<>(mChildren); |
| 4391 | for (int i = children.size() - 1; i >= 0; i--) { |
| 4392 | final WindowState win = children.get(i); |
| 4393 | destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped); |
| 4394 | } |
| 4395 | if (destroyedSomething) { |
| 4396 | final DisplayContent dc = getDisplayContent(); |
| 4397 | dc.assignWindowLayers(true /*setLayoutNeeded*/); |
| 4398 | updateLetterboxSurface(null); |
| 4399 | } |
| 4400 | } |
| 4401 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 4402 | void notifyAppResumed(boolean wasStopped) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 4403 | if (getParent() == null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 4404 | Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " |
| 4405 | + appToken); |
| 4406 | return; |
| 4407 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4408 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, "notifyAppResumed: wasStopped=%b %s", |
| 4409 | wasStopped, this); |
| 4410 | mAppStopped = false; |
| 4411 | // Allow the window to turn the screen on once the app is resumed again. |
| 4412 | setCurrentLaunchCanTurnScreenOn(true); |
| 4413 | if (!wasStopped) { |
| 4414 | destroySurfaces(true /*cleanupOnResume*/); |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | /** |
| 4419 | * Notify that the app has stopped, and it is okay to destroy any surfaces which were |
| 4420 | * keeping alive in case they were still being used. |
| 4421 | */ |
| 4422 | void notifyAppStopped() { |
| 4423 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, "notifyAppStopped: %s", this); |
| 4424 | mAppStopped = true; |
| 4425 | // Reset the last saved PiP snap fraction on app stop. |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame] | 4426 | mDisplayContent.mPinnedStackControllerLocked.resetReentryBounds(mActivityComponent); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4427 | destroySurfaces(); |
| 4428 | // Remove any starting window that was added for this app if they are still around. |
| 4429 | removeStartingWindow(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4430 | } |
| 4431 | |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 4432 | /** |
| 4433 | * Suppress transition until the new activity becomes ready, otherwise the keyguard can appear |
| 4434 | * for a short amount of time before the new process with the new activity had the ability to |
| 4435 | * set its showWhenLocked flags. |
| 4436 | */ |
| 4437 | void notifyUnknownVisibilityLaunchedForKeyguardTransition() { |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 4438 | // No display activities never add a window, so there is no point in waiting them for |
| 4439 | // relayout. |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 4440 | if (noDisplay || !mStackSupervisor.getKeyguardController().isKeyguardLocked()) { |
| 4441 | return; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4442 | } |
| 4443 | |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 4444 | mDisplayContent.mUnknownAppVisibilityController.notifyLaunched(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4445 | } |
| 4446 | |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 4447 | /** @return {@code true} if this activity should be made visible. */ |
| 4448 | boolean shouldBeVisible(boolean behindFullscreenActivity, boolean ignoringKeyguard) { |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 4449 | // Check whether activity should be visible without Keyguard influence |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 4450 | visibleIgnoringKeyguard = (!behindFullscreenActivity || mLaunchTaskBehind) |
| 4451 | && okToShowLocked(); |
| 4452 | |
| 4453 | if (ignoringKeyguard) { |
| 4454 | return visibleIgnoringKeyguard; |
| 4455 | } |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 4456 | |
| 4457 | final ActivityStack stack = getActivityStack(); |
| 4458 | if (stack == null) { |
| 4459 | return false; |
| 4460 | } |
| 4461 | |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 4462 | // Whether the activity is on the sleeping display. |
| 4463 | // TODO(b/129750406): This should be applied for the default display, too. |
| 4464 | final boolean isDisplaySleeping = getDisplay().isSleeping() |
| 4465 | && getDisplayId() != DEFAULT_DISPLAY; |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 4466 | // Whether this activity is the top activity of this stack. |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 4467 | final boolean isTop = this == stack.getTopNonFinishingActivity(); |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 4468 | // Exclude the case where this is the top activity in a pinned stack. |
| 4469 | final boolean isTopNotPinnedStack = stack.isAttached() |
| 4470 | && stack.getDisplay().isTopNotPinnedStack(stack); |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 4471 | // Now check whether it's really visible depending on Keyguard state, and update |
| 4472 | // {@link ActivityStack} internal states. |
| 4473 | final boolean visibleIgnoringDisplayStatus = stack.checkKeyguardVisibility(this, |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 4474 | visibleIgnoringKeyguard, isTop && isTopNotPinnedStack); |
Issei Suzuki | 62356a2 | 2019-04-11 16:46:37 +0200 | [diff] [blame] | 4475 | return visibleIgnoringDisplayStatus && !isDisplaySleeping; |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | boolean shouldBeVisible() { |
| 4479 | final ActivityStack stack = getActivityStack(); |
| 4480 | if (stack == null) { |
| 4481 | return false; |
| 4482 | } |
| 4483 | |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 4484 | final boolean behindFullscreenActivity = stack.checkBehindFullscreenActivity( |
| 4485 | this, null /* handleBehindFullscreenActivity */); |
| 4486 | return shouldBeVisible(behindFullscreenActivity, false /* ignoringKeyguard */); |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 4487 | } |
| 4488 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 4489 | void makeVisibleIfNeeded(ActivityRecord starting, boolean reportToClient) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4490 | // 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] | 4491 | if (mState == RESUMED || this == starting) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4492 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4493 | "Not making visible, r=" + this + " state=" + mState + " starting=" + starting); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4494 | return; |
| 4495 | } |
| 4496 | |
| 4497 | // If this activity is paused, tell it to now show its window. |
| 4498 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 4499 | "Making visible and scheduling visibility: " + this); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4500 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4501 | try { |
| 4502 | if (stack.mTranslucentActivityWaiting != null) { |
| 4503 | updateOptionsLocked(returningOptions); |
| 4504 | stack.mUndrawnActivitiesBelowTopTranslucent.add(this); |
| 4505 | } |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4506 | setVisibility(true); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4507 | sleeping = false; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4508 | app.postPendingUiCleanMsg(true); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 4509 | if (reportToClient) { |
| 4510 | makeClientVisible(); |
| 4511 | } else { |
| 4512 | mClientVisibilityDeferred = true; |
| 4513 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4514 | // The activity may be waiting for stop, but that is no longer appropriate for it. |
| 4515 | mStackSupervisor.mStoppingActivities.remove(this); |
| 4516 | mStackSupervisor.mGoingToSleepActivities.remove(this); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 4517 | } catch (Exception e) { |
| 4518 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 4519 | Slog.w(TAG, "Exception thrown making visible: " + intent.getComponent(), e); |
| 4520 | } |
| 4521 | handleAlreadyVisible(); |
| 4522 | } |
Andrii Kulian | 0d595f3 | 2018-02-21 15:47:33 -0800 | [diff] [blame] | 4523 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 4524 | /** Send visibility change message to the client and pause if needed. */ |
| 4525 | void makeClientVisible() { |
| 4526 | mClientVisibilityDeferred = false; |
| 4527 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4528 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 4529 | WindowVisibilityItem.obtain(true /* showWindow */)); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4530 | makeActiveIfNeeded(null /* activeActivity*/); |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 4531 | if (isState(STOPPING, STOPPED)) { |
| 4532 | // Set state to STARTED in order to have consistent state with client while |
| 4533 | // making an non-active activity visible from stopped. |
| 4534 | setState(STARTED, "makeClientVisible"); |
Louis Chang | 3d119a9 | 2019-04-22 10:45:37 +0800 | [diff] [blame] | 4535 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4536 | } catch (Exception e) { |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 4537 | Slog.w(TAG, "Exception thrown sending visibility update: " + intent.getComponent(), e); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4538 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4541 | void makeInvisible() { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4542 | if (!mVisibleRequested) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4543 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + this); |
| 4544 | return; |
| 4545 | } |
| 4546 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 4547 | // keeping the screen frozen. |
| 4548 | if (DEBUG_VISIBILITY) { |
| 4549 | Slog.v(TAG_VISIBILITY, "Making invisible: " + this + ", state=" + getState()); |
| 4550 | } |
| 4551 | try { |
| 4552 | final boolean canEnterPictureInPicture = checkEnterPictureInPictureState( |
| 4553 | "makeInvisible", true /* beforeStopping */); |
| 4554 | // Defer telling the client it is hidden if it can enter Pip and isn't current paused, |
| 4555 | // stopped or stopping. This gives it a chance to enter Pip in onPause(). |
| 4556 | // TODO: There is still a question surrounding activities in multi-window mode that want |
| 4557 | // to enter Pip after they are paused, but are still visible. I they should be okay to |
| 4558 | // enter Pip in those cases, but not "auto-Pip" which is what this condition covers and |
| 4559 | // the current contract for "auto-Pip" is that the app should enter it before onPause |
| 4560 | // returns. Just need to confirm this reasoning makes sense. |
| 4561 | final boolean deferHidingClient = canEnterPictureInPicture |
| 4562 | && !isState(STOPPING, STOPPED, PAUSED); |
| 4563 | setDeferHidingClient(deferHidingClient); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4564 | setVisibility(false); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4565 | |
| 4566 | switch (getState()) { |
| 4567 | case STOPPING: |
| 4568 | case STOPPED: |
| 4569 | if (attachedToProcess()) { |
| 4570 | if (DEBUG_VISIBILITY) { |
| 4571 | Slog.v(TAG_VISIBILITY, "Scheduling invisibility: " + this); |
| 4572 | } |
| 4573 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), |
| 4574 | appToken, WindowVisibilityItem.obtain(false /* showWindow */)); |
| 4575 | } |
| 4576 | |
| 4577 | // Reset the flag indicating that an app can enter picture-in-picture once the |
| 4578 | // activity is hidden |
| 4579 | supportsEnterPipOnTaskSwitch = false; |
| 4580 | break; |
| 4581 | |
| 4582 | case INITIALIZING: |
| 4583 | case RESUMED: |
| 4584 | case PAUSING: |
| 4585 | case PAUSED: |
| 4586 | case STARTED: |
| 4587 | addToStopping(true /* scheduleIdle */, |
| 4588 | canEnterPictureInPicture /* idleDelayed */, "makeInvisible"); |
| 4589 | break; |
| 4590 | |
| 4591 | default: |
| 4592 | break; |
| 4593 | } |
| 4594 | } catch (Exception e) { |
| 4595 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 4596 | Slog.w(TAG, "Exception thrown making hidden: " + intent.getComponent(), e); |
| 4597 | } |
| 4598 | } |
| 4599 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4600 | /** |
| 4601 | * Make activity resumed or paused if needed. |
| 4602 | * @param activeActivity an activity that is resumed or just completed pause action. |
| 4603 | * We won't change the state of this activity. |
| 4604 | */ |
| 4605 | boolean makeActiveIfNeeded(ActivityRecord activeActivity) { |
| 4606 | if (shouldResumeActivity(activeActivity)) { |
| 4607 | if (DEBUG_VISIBILITY) { |
| 4608 | Slog.v("TAG_VISIBILITY", "Resume visible activity, " + this); |
| 4609 | } |
| 4610 | return getActivityStack().resumeTopActivityUncheckedLocked(activeActivity /* prev */, |
| 4611 | null /* options */); |
| 4612 | } else if (shouldPauseActivity(activeActivity)) { |
| 4613 | if (DEBUG_VISIBILITY) { |
| 4614 | Slog.v("TAG_VISIBILITY", "Pause visible activity, " + this); |
| 4615 | } |
| 4616 | // An activity must be in the {@link PAUSING} state for the system to validate |
| 4617 | // the move to {@link PAUSED}. |
| 4618 | setState(PAUSING, "makeVisibleIfNeeded"); |
| 4619 | try { |
| 4620 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 4621 | PauseActivityItem.obtain(finishing, false /* userLeaving */, |
| 4622 | configChangeFlags, false /* dontReport */)); |
| 4623 | } catch (Exception e) { |
| 4624 | Slog.w(TAG, "Exception thrown sending pause: " + intent.getComponent(), e); |
| 4625 | } |
| 4626 | } |
| 4627 | return false; |
| 4628 | } |
| 4629 | |
| 4630 | /** |
| 4631 | * Check if activity should be moved to PAUSED state. The activity: |
| 4632 | * - should be eligible to be made active (see {@link #shouldMakeActive(ActivityRecord)}) |
| 4633 | * - should be non-focusable |
| 4634 | * - should not be currently pausing or paused |
| 4635 | * @param activeActivity the activity that is active or just completed pause action. We won't |
| 4636 | * resume if this activity is active. |
| 4637 | */ |
wilsonshih | a96aac6 | 2019-11-18 14:53:34 +0800 | [diff] [blame] | 4638 | @VisibleForTesting |
| 4639 | boolean shouldPauseActivity(ActivityRecord activeActivity) { |
| 4640 | return shouldMakeActive(activeActivity) && !isFocusable() && !isState(PAUSING, PAUSED) |
| 4641 | // We will only allow pausing if results is null, otherwise it will cause this |
| 4642 | // activity to resume before getting result |
| 4643 | && (results == null); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | /** |
wilsonshih | b5d8f8b | 2019-10-23 13:01:40 +0800 | [diff] [blame] | 4647 | * Check if activity should be moved to RESUMED state. |
| 4648 | * See {@link #shouldBeResumed(ActivityRecord)} |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4649 | * @param activeActivity the activity that is active or just completed pause action. We won't |
| 4650 | * resume if this activity is active. |
| 4651 | */ |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 4652 | @VisibleForTesting |
| 4653 | boolean shouldResumeActivity(ActivityRecord activeActivity) { |
wilsonshih | b5d8f8b | 2019-10-23 13:01:40 +0800 | [diff] [blame] | 4654 | return shouldBeResumed(activeActivity) && !isState(RESUMED); |
| 4655 | } |
| 4656 | |
| 4657 | /** |
| 4658 | * Check if activity should be RESUMED now. The activity: |
| 4659 | * - should be eligible to be made active (see {@link #shouldMakeActive(ActivityRecord)}) |
| 4660 | * - should be focusable |
| 4661 | */ |
| 4662 | private boolean shouldBeResumed(ActivityRecord activeActivity) { |
| 4663 | return shouldMakeActive(activeActivity) && isFocusable() |
| 4664 | && getActivityStack().getVisibility(activeActivity) == STACK_VISIBILITY_VISIBLE |
| 4665 | && canResumeByCompat(); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | /** |
| 4669 | * Check if activity is eligible to be made active (resumed of paused). The activity: |
| 4670 | * - should be paused, stopped or stopping |
Andrii Kulian | 996df0d | 2019-01-24 17:04:36 -0800 | [diff] [blame] | 4671 | * - should not be the currently active one or launching behind other tasks |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4672 | * - should be either the topmost in task, or right below the top activity that is finishing |
| 4673 | * If all of these conditions are not met at the same time, the activity cannot be made active. |
| 4674 | */ |
Andrii Kulian | f219536 | 2019-01-31 18:20:11 -0800 | [diff] [blame] | 4675 | @VisibleForTesting |
| 4676 | boolean shouldMakeActive(ActivityRecord activeActivity) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4677 | // 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] | 4678 | // this when there is an activity waiting to become translucent as the extra binder |
| 4679 | // calls will lead to noticeable jank. A later call to |
Wale Ogunwale | 076c3b1 | 2019-11-20 12:17:22 -0800 | [diff] [blame] | 4680 | // ActivityStack#ensureActivitiesVisible will bring the activity to a proper |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4681 | // active state. |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 4682 | if (!isState(STARTED, RESUMED, PAUSED, STOPPED, STOPPING) |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4683 | || getActivityStack().mTranslucentActivityWaiting != null) { |
| 4684 | return false; |
| 4685 | } |
| 4686 | |
| 4687 | if (this == activeActivity) { |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 4688 | return false; |
| 4689 | } |
| 4690 | |
Andrii Kulian | f219536 | 2019-01-31 18:20:11 -0800 | [diff] [blame] | 4691 | if (!mStackSupervisor.readyToResume()) { |
| 4692 | // Making active is currently deferred (e.g. because an activity launch is in progress). |
| 4693 | return false; |
| 4694 | } |
| 4695 | |
Andrii Kulian | 996df0d | 2019-01-24 17:04:36 -0800 | [diff] [blame] | 4696 | if (this.mLaunchTaskBehind) { |
| 4697 | // This activity is being launched from behind, which means that it's not intended to be |
| 4698 | // presented to user right now, even if it's set to be visible. |
| 4699 | return false; |
| 4700 | } |
| 4701 | |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 4702 | // Check if position in task allows to become paused |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 4703 | if (!task.hasChild(this)) { |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 4704 | throw new IllegalStateException("Activity not found in its task"); |
| 4705 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 4706 | final ActivityRecord activityAbove = task.getActivityAbove(this); |
| 4707 | if (activityAbove == null) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4708 | // It's the topmost activity in the task - should become resumed now |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 4709 | return true; |
| 4710 | } |
| 4711 | // Check if activity above is finishing now and this one becomes the topmost in task. |
wilsonshih | a96aac6 | 2019-11-18 14:53:34 +0800 | [diff] [blame] | 4712 | if (activityAbove.finishing) { |
Andrii Kulian | 09e1afa | 2018-05-16 21:29:34 -0700 | [diff] [blame] | 4713 | return true; |
| 4714 | } |
| 4715 | return false; |
| 4716 | } |
| 4717 | |
Louis Chang | cfe4621 | 2019-07-30 10:34:18 +0800 | [diff] [blame] | 4718 | void handleAlreadyVisible() { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4719 | stopFreezingScreenLocked(false); |
| 4720 | try { |
| 4721 | if (returningOptions != null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4722 | app.getThread().scheduleOnNewActivityOptions(appToken, returningOptions.toBundle()); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4723 | } |
| 4724 | } catch(RemoteException e) { |
| 4725 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4726 | } |
| 4727 | |
| 4728 | static void activityResumedLocked(IBinder token) { |
| 4729 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4730 | 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] | 4731 | if (r == null) { |
| 4732 | // If an app reports resumed after a long delay, the record on server side might have |
| 4733 | // been removed (e.g. destroy timeout), so the token could be null. |
| 4734 | return; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4735 | } |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 4736 | r.setSavedState(null /* savedState */); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 4737 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4738 | final DisplayContent display = r.getDisplay(); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 4739 | if (display != null) { |
| 4740 | display.handleActivitySizeCompatModeIfNeeded(r); |
| 4741 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 4742 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 4743 | r.getDisplayContent().mUnknownAppVisibilityController.notifyAppResumedFinished(r); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | /** |
| 4747 | * Once we know that we have asked an application to put an activity in the resumed state |
| 4748 | * (either by launching it or explicitly telling it), this function updates the rest of our |
| 4749 | * state to match that fact. |
| 4750 | */ |
| 4751 | void completeResumeLocked() { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4752 | final boolean wasVisible = mVisibleRequested; |
| 4753 | setVisibility(true); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4754 | if (!wasVisible) { |
| 4755 | // Visibility has changed, so take a note of it so we call the TaskStackChangedListener |
| 4756 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
| 4757 | } |
| 4758 | idle = false; |
| 4759 | results = null; |
Louis Chang | 746c224 | 2019-10-08 16:30:44 +0800 | [diff] [blame] | 4760 | if (newIntents != null && newIntents.size() > 0) { |
| 4761 | mLastNewIntent = newIntents.get(newIntents.size() - 1); |
| 4762 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4763 | newIntents = null; |
| 4764 | stopped = false; |
| 4765 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4766 | if (isActivityTypeHome()) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 4767 | mStackSupervisor.updateHomeProcess(task.getBottomMostActivity().app); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | if (nowVisible) { |
Louis Chang | a59937a | 2019-03-20 17:17:22 +0800 | [diff] [blame] | 4771 | mStackSupervisor.stopWaitingForActivityVisible(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | // Schedule an idle timeout in case the app doesn't do it for us. |
| 4775 | mStackSupervisor.scheduleIdleTimeoutLocked(this); |
| 4776 | |
| 4777 | mStackSupervisor.reportResumedActivityLocked(this); |
| 4778 | |
| 4779 | resumeKeyDispatchingLocked(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4780 | final ActivityStack stack = getActivityStack(); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 4781 | mStackSupervisor.mNoAnimActivities.clear(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4782 | |
| 4783 | // Mark the point when the activity is resuming |
| 4784 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 4785 | // not after the onResume. But for subsequent starts, onResume is fine. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4786 | if (hasProcess()) { |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 4787 | cpuTimeAtResume = app.getCpuTime(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4788 | } else { |
| 4789 | cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 4790 | } |
| 4791 | |
| 4792 | returningOptions = null; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4793 | |
| 4794 | if (canTurnScreenOn()) { |
| 4795 | mStackSupervisor.wakeUp("turnScreenOnFlag"); |
| 4796 | } else { |
| 4797 | // If the screen is going to turn on because the caller explicitly requested it and |
| 4798 | // the keyguard is not showing don't attempt to sleep. Otherwise the Activity will |
| 4799 | // 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] | 4800 | stack.checkReadyForSleep(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4801 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4802 | } |
| 4803 | |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 4804 | void activityPaused(boolean timeout) { |
| 4805 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 4806 | "Activity paused: token=" + appToken + ", timeout=" + timeout); |
| 4807 | |
| 4808 | final ActivityStack stack = getStack(); |
| 4809 | |
| 4810 | if (stack != null) { |
| 4811 | removePauseTimeout(); |
| 4812 | |
| 4813 | if (stack.mPausingActivity == this) { |
| 4814 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + this |
| 4815 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
| 4816 | mAtmService.deferWindowLayout(); |
| 4817 | try { |
| 4818 | stack.completePauseLocked(true /* resumeNext */, null /* resumingActivity */); |
| 4819 | } finally { |
| 4820 | mAtmService.continueWindowLayout(); |
| 4821 | } |
| 4822 | return; |
| 4823 | } else { |
| 4824 | EventLogTags.writeWmFailedToPause(mUserId, System.identityHashCode(this), |
| 4825 | shortComponentName, stack.mPausingActivity != null |
| 4826 | ? stack.mPausingActivity.shortComponentName : "(none)"); |
| 4827 | if (isState(PAUSING)) { |
| 4828 | setState(PAUSED, "activityPausedLocked"); |
| 4829 | if (finishing) { |
| 4830 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 4831 | "Executing finish of failed to pause activity: " + this); |
| 4832 | completeFinishing("activityPausedLocked"); |
| 4833 | } |
| 4834 | } |
| 4835 | } |
| 4836 | } |
| 4837 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4838 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | /** |
| 4842 | * Schedule a pause timeout in case the app doesn't respond. We don't give it much time because |
| 4843 | * this directly impacts the responsiveness seen by the user. |
| 4844 | */ |
| 4845 | void schedulePauseTimeout() { |
| 4846 | pauseTime = SystemClock.uptimeMillis(); |
| 4847 | mAtmService.mH.postDelayed(mPauseTimeoutRunnable, PAUSE_TIMEOUT); |
| 4848 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
| 4849 | } |
| 4850 | |
| 4851 | private void removePauseTimeout() { |
| 4852 | mAtmService.mH.removeCallbacks(mPauseTimeoutRunnable); |
| 4853 | } |
| 4854 | |
| 4855 | private void removeDestroyTimeout() { |
| 4856 | mAtmService.mH.removeCallbacks(mDestroyTimeoutRunnable); |
| 4857 | } |
| 4858 | |
| 4859 | private void removeStopTimeout() { |
| 4860 | mAtmService.mH.removeCallbacks(mStopTimeoutRunnable); |
| 4861 | } |
| 4862 | |
| 4863 | void removeTimeouts() { |
| 4864 | mStackSupervisor.removeIdleTimeoutForActivity(this); |
| 4865 | removePauseTimeout(); |
| 4866 | removeStopTimeout(); |
| 4867 | removeDestroyTimeout(); |
| 4868 | finishLaunchTickingLocked(); |
| 4869 | } |
| 4870 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4871 | void stopIfPossible() { |
| 4872 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + this); |
| 4873 | final ActivityStack stack = getActivityStack(); |
| 4874 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 4875 | || (info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 4876 | if (!finishing) { |
| 4877 | if (!stack.shouldSleepActivities()) { |
| 4878 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + this); |
| 4879 | if (finishIfPossible("stop-no-history", false /* oomAdj */) |
| 4880 | != FINISH_RESULT_CANCELLED) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4881 | resumeKeyDispatchingLocked(); |
| 4882 | return; |
| 4883 | } |
| 4884 | } else { |
| 4885 | if (DEBUG_STATES) { |
| 4886 | Slog.d(TAG_STATES, "Not finishing noHistory " + this |
| 4887 | + " on stop because we're just sleeping"); |
| 4888 | } |
| 4889 | } |
| 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | if (!attachedToProcess()) { |
| 4894 | return; |
| 4895 | } |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4896 | resumeKeyDispatchingLocked(); |
| 4897 | try { |
| 4898 | stopped = false; |
| 4899 | if (DEBUG_STATES) { |
| 4900 | Slog.v(TAG_STATES, "Moving to STOPPING: " + this + " (stop requested)"); |
| 4901 | } |
| 4902 | setState(STOPPING, "stopIfPossible"); |
| 4903 | if (DEBUG_VISIBILITY) { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4904 | Slog.v(TAG_VISIBILITY, "Stopping visibleRequested=" |
| 4905 | + mVisibleRequested + " for " + this); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4906 | } |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4907 | if (!mVisibleRequested) { |
| 4908 | setVisibility(false); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4909 | } |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 4910 | EventLogTags.writeWmStopActivity( |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4911 | mUserId, System.identityHashCode(this), shortComponentName); |
| 4912 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4913 | StopActivityItem.obtain(mVisibleRequested, configChangeFlags)); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4914 | if (stack.shouldSleepOrShutDownActivities()) { |
| 4915 | setSleeping(true); |
| 4916 | } |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 4917 | mAtmService.mH.postDelayed(mStopTimeoutRunnable, STOP_TIMEOUT); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4918 | } catch (Exception e) { |
| 4919 | // Maybe just ignore exceptions here... if the process has crashed, our death |
| 4920 | // notification will clean things up. |
| 4921 | Slog.w(TAG, "Exception thrown during pause", e); |
| 4922 | // Just in case, assume it to be stopped. |
| 4923 | stopped = true; |
| 4924 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Stop failed; moving to STOPPED: " + this); |
| 4925 | setState(STOPPED, "stopIfPossible"); |
| 4926 | if (deferRelaunchUntilPaused) { |
| 4927 | destroyImmediately(true /* removeFromApp */, "stop-except"); |
| 4928 | } |
| 4929 | } |
| 4930 | } |
| 4931 | |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 4932 | void activityStopped(Bundle newIcicle, PersistableBundle newPersistentState, |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4933 | CharSequence description) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4934 | final ActivityStack stack = getActivityStack(); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 4935 | final boolean isStopping = mState == STOPPING; |
| 4936 | if (!isStopping && mState != RESTARTING_PROCESS) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4937 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 4938 | removeStopTimeout(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4939 | return; |
| 4940 | } |
| 4941 | if (newPersistentState != null) { |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 4942 | mPersistentState = newPersistentState; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4943 | mAtmService.notifyTaskPersisterLocked(task, false); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4944 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4945 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4946 | if (newIcicle != null) { |
| 4947 | // If icicle is null, this is happening due to a timeout, so we haven't really saved |
| 4948 | // the state. |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 4949 | setSavedState(newIcicle); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4950 | launchCount = 0; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 4951 | updateTaskDescription(description); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4952 | } |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 4953 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + mIcicle); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4954 | if (!stopped) { |
| 4955 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)"); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 4956 | removeStopTimeout(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4957 | stopped = true; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 4958 | if (isStopping) { |
| 4959 | setState(STOPPED, "activityStoppedLocked"); |
| 4960 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4961 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 4962 | notifyAppStopped(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4963 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4964 | if (finishing) { |
| 4965 | clearOptionsLocked(); |
| 4966 | } else { |
| 4967 | if (deferRelaunchUntilPaused) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4968 | destroyImmediately(true /* removeFromApp */, "stop-config"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4969 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4970 | } else { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4971 | mRootWindowContainer.updatePreviousProcess(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4972 | } |
| 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4977 | void addToStopping(boolean scheduleIdle, boolean idleDelayed, String reason) { |
| 4978 | if (!mStackSupervisor.mStoppingActivities.contains(this)) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 4979 | EventLogTags.writeWmAddToStopping(mUserId, System.identityHashCode(this), |
| 4980 | shortComponentName, reason); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 4981 | mStackSupervisor.mStoppingActivities.add(this); |
| 4982 | } |
| 4983 | |
| 4984 | final ActivityStack stack = getActivityStack(); |
| 4985 | // If we already have a few activities waiting to stop, then give up on things going idle |
| 4986 | // and start clearing them out. Or if r is the last of activity of the last task the stack |
| 4987 | // will be empty and must be cleared immediately. |
| 4988 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 4989 | || (isRootOfTask() && stack.getChildCount() <= 1); |
| 4990 | if (scheduleIdle || forceIdle) { |
| 4991 | if (DEBUG_PAUSE) { |
| 4992 | Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" + forceIdle |
| 4993 | + "immediate=" + !idleDelayed); |
| 4994 | } |
| 4995 | if (!idleDelayed) { |
| 4996 | mStackSupervisor.scheduleIdleLocked(); |
| 4997 | } else { |
| 4998 | mStackSupervisor.scheduleIdleTimeoutLocked(this); |
| 4999 | } |
| 5000 | } else { |
| 5001 | stack.checkReadyForSleep(); |
| 5002 | } |
| 5003 | } |
| 5004 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 5005 | void startLaunchTickingLocked() { |
Jeff Sharkey | 5ab0243 | 2017-06-27 11:01:36 -0600 | [diff] [blame] | 5006 | if (Build.IS_USER) { |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 5007 | return; |
| 5008 | } |
| 5009 | if (launchTickTime == 0) { |
| 5010 | launchTickTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 5011 | continueLaunchTicking(); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 5015 | private boolean continueLaunchTicking() { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5016 | if (launchTickTime == 0) { |
| 5017 | return false; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 5018 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5019 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5020 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5021 | if (stack == null) { |
| 5022 | return false; |
| 5023 | } |
| 5024 | |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 5025 | stack.removeLaunchTickMessages(); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 5026 | mAtmService.mH.postDelayed(mLaunchTickRunnable, LAUNCH_TICK); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5027 | return true; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 5028 | } |
| 5029 | |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 5030 | void removeLaunchTickRunnable() { |
| 5031 | mAtmService.mH.removeCallbacks(mLaunchTickRunnable); |
| 5032 | } |
| 5033 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 5034 | void finishLaunchTickingLocked() { |
| 5035 | launchTickTime = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5036 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 5037 | if (stack == null) { |
| 5038 | return; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5039 | } |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 5040 | stack.removeLaunchTickMessages(); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 5041 | } |
| 5042 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5043 | boolean mayFreezeScreenLocked() { |
| 5044 | return mayFreezeScreenLocked(app); |
| 5045 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5046 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5047 | private boolean mayFreezeScreenLocked(WindowProcessController app) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5048 | // Only freeze the screen if this activity is currently attached to |
| 5049 | // an application, and that application is not blocked or unresponding. |
| 5050 | // In any other case, we can't count on getting the screen unfrozen, |
| 5051 | // so it is best to leave as-is. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5052 | return hasProcess() && !app.isCrashing() && !app.isNotResponding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5053 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 5054 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5055 | void startFreezingScreenLocked(int configChanges) { |
| 5056 | startFreezingScreenLocked(app, configChanges); |
| 5057 | } |
| 5058 | |
| 5059 | void startFreezingScreenLocked(WindowProcessController app, int configChanges) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | if (mayFreezeScreenLocked(app)) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5061 | if (getParent() == null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5062 | Slog.w(TAG_WM, |
| 5063 | "Attempted to freeze screen with non-existing app token: " + appToken); |
| 5064 | return; |
| 5065 | } |
| 5066 | |
Evan Rosky | b1e75f7 | 2019-04-26 20:23:26 -0700 | [diff] [blame] | 5067 | // Window configuration changes only effect windows, so don't require a screen freeze. |
| 5068 | int freezableConfigChanges = configChanges & ~(CONFIG_WINDOW_CONFIGURATION); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5069 | if (freezableConfigChanges == 0 && okToDisplay()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 5070 | ProtoLog.v(WM_DEBUG_ORIENTATION, "Skipping set freeze of %s", appToken); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5071 | return; |
| 5072 | } |
| 5073 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5074 | startFreezingScreen(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5075 | } |
| 5076 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 5077 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5078 | void startFreezingScreen() { |
| 5079 | ProtoLog.i(WM_DEBUG_ORIENTATION, |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 5080 | "Set freezing of %s: visible=%b freezing=%b visibleRequested=%b. %s", |
| 5081 | appToken, isVisible(), mFreezingScreen, mVisibleRequested, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5082 | new RuntimeException().fillInStackTrace()); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 5083 | if (mVisibleRequested) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5084 | if (!mFreezingScreen) { |
| 5085 | mFreezingScreen = true; |
| 5086 | mWmService.registerAppFreezeListener(this); |
| 5087 | mWmService.mAppsFreezingScreen++; |
| 5088 | if (mWmService.mAppsFreezingScreen == 1) { |
| 5089 | mWmService.startFreezingDisplayLocked(0, 0, getDisplayContent()); |
| 5090 | mWmService.mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 5091 | mWmService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000); |
| 5092 | } |
| 5093 | } |
| 5094 | final int count = mChildren.size(); |
| 5095 | for (int i = 0; i < count; i++) { |
| 5096 | final WindowState w = mChildren.get(i); |
| 5097 | w.onStartFreezingScreen(); |
| 5098 | } |
| 5099 | } |
| 5100 | } |
| 5101 | |
| 5102 | boolean isFreezingScreen() { |
| 5103 | return mFreezingScreen; |
| 5104 | } |
| 5105 | |
| 5106 | @Override |
| 5107 | public void onAppFreezeTimeout() { |
| 5108 | Slog.w(TAG_WM, "Force clearing freeze: " + this); |
| 5109 | stopFreezingScreen(true, true); |
| 5110 | } |
| 5111 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5112 | void stopFreezingScreenLocked(boolean force) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5113 | if (force || frozenBeforeDestroy) { |
| 5114 | frozenBeforeDestroy = false; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5115 | if (getParent() == null) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5116 | return; |
| 5117 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 5118 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 5119 | "Clear freezing of %s: visible=%b freezing=%b", appToken, |
| 5120 | isVisible(), isFreezingScreen()); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5121 | stopFreezingScreen(true, force); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5122 | } |
| 5123 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 5124 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5125 | void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) { |
| 5126 | if (!mFreezingScreen) { |
| 5127 | return; |
| 5128 | } |
| 5129 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 5130 | "Clear freezing of %s force=%b", this, force); |
| 5131 | final int count = mChildren.size(); |
| 5132 | boolean unfrozeWindows = false; |
| 5133 | for (int i = 0; i < count; i++) { |
| 5134 | final WindowState w = mChildren.get(i); |
| 5135 | unfrozeWindows |= w.onStopFreezingScreen(); |
| 5136 | } |
| 5137 | if (force || unfrozeWindows) { |
| 5138 | ProtoLog.v(WM_DEBUG_ORIENTATION, "No longer freezing: %s", this); |
| 5139 | mFreezingScreen = false; |
| 5140 | mWmService.unregisterAppFreezeListener(this); |
| 5141 | mWmService.mAppsFreezingScreen--; |
| 5142 | mWmService.mLastFinishedFreezeSource = this; |
| 5143 | } |
| 5144 | if (unfreezeSurfaceNow) { |
| 5145 | if (unfrozeWindows) { |
| 5146 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
| 5147 | } |
| 5148 | mWmService.stopFreezingDisplayLocked(); |
| 5149 | } |
| 5150 | } |
| 5151 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5152 | void reportFullyDrawnLocked(boolean restoredFromBundle) { |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 5153 | final TransitionInfoSnapshot info = mStackSupervisor |
Yan Wang | d47f90b | 2019-10-03 19:17:15 -0700 | [diff] [blame] | 5154 | .getActivityMetricsLogger().logAppTransitionReportedDrawn(this, restoredFromBundle); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 5155 | if (info != null) { |
| 5156 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 5157 | info.windowsFullyDrawnDelayMs, info.getLaunchState()); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 5158 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 5159 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5160 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5161 | void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) { |
| 5162 | firstWindowDrawn = true; |
| 5163 | |
| 5164 | // We now have a good window to show, remove dead placeholders |
| 5165 | removeDeadWindows(); |
| 5166 | |
| 5167 | if (startingWindow != null) { |
| 5168 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Finish starting %s" |
| 5169 | + ": first real window is shown, no animation", win.mToken); |
| 5170 | // If this initial window is animating, stop it -- we will do an animation to reveal |
| 5171 | // it from behind the starting window, so there is no need for it to also be doing its |
| 5172 | // own stuff. |
| 5173 | win.cancelAnimation(); |
| 5174 | } |
| 5175 | removeStartingWindow(); |
| 5176 | updateReportedVisibilityLocked(); |
| 5177 | } |
| 5178 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5179 | /** Called when the windows associated app window container are drawn. */ |
Yan Wang | d47f90b | 2019-10-03 19:17:15 -0700 | [diff] [blame] | 5180 | void onWindowsDrawn(boolean drawn, long timestampNs) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5181 | mDrawn = drawn; |
| 5182 | if (!drawn) { |
| 5183 | return; |
| 5184 | } |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 5185 | final TransitionInfoSnapshot info = mStackSupervisor |
| 5186 | .getActivityMetricsLogger().notifyWindowsDrawn(this, timestampNs); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5187 | final int windowsDrawnDelayMs = info != null ? info.windowsDrawnDelayMs : INVALID_DELAY; |
| 5188 | final @LaunchState int launchState = info != null ? info.getLaunchState() : -1; |
| 5189 | mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this, |
| 5190 | windowsDrawnDelayMs, launchState); |
Riddle Hsu | c48c891 | 2019-10-31 13:34:27 +0800 | [diff] [blame] | 5191 | mStackSupervisor.stopWaitingForActivityVisible(this, windowsDrawnDelayMs); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5192 | finishLaunchTickingLocked(); |
| 5193 | if (task != null) { |
| 5194 | task.hasBeenVisible = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5195 | } |
| 5196 | } |
| 5197 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5198 | /** Called when the windows associated app window container are visible. */ |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5199 | void onWindowsVisible() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5200 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting visible in " + appToken); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5201 | mStackSupervisor.stopWaitingForActivityVisible(this); |
| 5202 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsVisibleLocked(): " + this); |
| 5203 | if (!nowVisible) { |
| 5204 | nowVisible = true; |
| 5205 | lastVisibleTime = SystemClock.uptimeMillis(); |
| 5206 | mAtmService.scheduleAppGcsLocked(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5207 | } |
| 5208 | } |
| 5209 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5210 | /** Called when the windows associated app window container are no longer visible. */ |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5211 | void onWindowsGone() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5212 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting gone in " + appToken); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5213 | if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + this); |
| 5214 | nowVisible = false; |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 5215 | } |
| 5216 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5217 | @Override |
| 5218 | void checkAppWindowsReadyToShow() { |
| 5219 | if (allDrawn == mLastAllDrawn) { |
| 5220 | return; |
| 5221 | } |
| 5222 | |
| 5223 | mLastAllDrawn = allDrawn; |
| 5224 | if (!allDrawn) { |
| 5225 | return; |
| 5226 | } |
| 5227 | |
| 5228 | // The token has now changed state to having all windows shown... what to do, what to do? |
| 5229 | if (mFreezingScreen) { |
| 5230 | showAllWindowsLocked(); |
| 5231 | stopFreezingScreen(false, true); |
| 5232 | ProtoLog.i(WM_DEBUG_ORIENTATION, |
| 5233 | "Setting mOrientationChangeComplete=true because wtoken %s " |
| 5234 | + "numInteresting=%d numDrawn=%d", |
| 5235 | this, mNumInterestingWindows, mNumDrawnWindows); |
| 5236 | // This will set mOrientationChangeComplete and cause a pass through layout. |
| 5237 | setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, |
| 5238 | "checkAppWindowsReadyToShow: freezingScreen"); |
| 5239 | } else { |
| 5240 | setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow"); |
| 5241 | |
| 5242 | // We can now show all of the drawn windows! |
| 5243 | if (!getDisplayContent().mOpeningApps.contains(this) && canShowWindows()) { |
| 5244 | showAllWindowsLocked(); |
| 5245 | } |
| 5246 | } |
| 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * This must be called while inside a transaction. |
| 5251 | */ |
| 5252 | void showAllWindowsLocked() { |
| 5253 | forAllWindows(windowState -> { |
| 5254 | if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState); |
| 5255 | windowState.performShowLocked(); |
| 5256 | }, false /* traverseTopToBottom */); |
| 5257 | } |
| 5258 | |
| 5259 | void updateReportedVisibilityLocked() { |
| 5260 | if (appToken == null) { |
| 5261 | return; |
| 5262 | } |
| 5263 | |
| 5264 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
| 5265 | final int count = mChildren.size(); |
| 5266 | |
| 5267 | mReportedVisibilityResults.reset(); |
| 5268 | |
| 5269 | for (int i = 0; i < count; i++) { |
| 5270 | final WindowState win = mChildren.get(i); |
| 5271 | win.updateReportedVisibility(mReportedVisibilityResults); |
| 5272 | } |
| 5273 | |
| 5274 | int numInteresting = mReportedVisibilityResults.numInteresting; |
| 5275 | int numVisible = mReportedVisibilityResults.numVisible; |
| 5276 | int numDrawn = mReportedVisibilityResults.numDrawn; |
| 5277 | boolean nowGone = mReportedVisibilityResults.nowGone; |
| 5278 | |
| 5279 | boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting; |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 5280 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && isVisible(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5281 | if (!nowGone) { |
| 5282 | // If the app is not yet gone, then it can only become visible/drawn. |
| 5283 | if (!nowDrawn) { |
| 5284 | nowDrawn = reportedDrawn; |
| 5285 | } |
| 5286 | if (!nowVisible) { |
| 5287 | nowVisible = reportedVisible; |
| 5288 | } |
| 5289 | } |
| 5290 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| 5291 | + numInteresting + " visible=" + numVisible); |
| 5292 | if (nowDrawn != reportedDrawn) { |
| 5293 | onWindowsDrawn(nowDrawn, SystemClock.elapsedRealtimeNanos()); |
| 5294 | reportedDrawn = nowDrawn; |
| 5295 | } |
| 5296 | if (nowVisible != reportedVisible) { |
| 5297 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 5298 | "Visibility changed in " + this + ": vis=" + nowVisible); |
| 5299 | reportedVisible = nowVisible; |
| 5300 | if (nowVisible) { |
| 5301 | onWindowsVisible(); |
| 5302 | } else { |
| 5303 | onWindowsGone(); |
| 5304 | } |
| 5305 | } |
| 5306 | } |
| 5307 | |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 5308 | boolean isClientVisible() { |
| 5309 | return mClientVisible; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5310 | } |
| 5311 | |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 5312 | void setClientVisible(boolean clientVisible) { |
| 5313 | if (mClientVisible == clientVisible || (!clientVisible && mDeferHidingClient)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5314 | return; |
| 5315 | } |
| 5316 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 5317 | "setClientVisible: %s clientVisible=%b Callers=%s", this, clientVisible, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5318 | Debug.getCallers(5)); |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 5319 | mClientVisible = clientVisible; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5320 | sendAppVisibilityToClients(); |
| 5321 | } |
| 5322 | |
| 5323 | /** |
| 5324 | * Updated this app token tracking states for interesting and drawn windows based on the window. |
| 5325 | * |
| 5326 | * @return Returns true if the input window is considered interesting and drawn while all the |
| 5327 | * windows in this app token where not considered drawn as of the last pass. |
| 5328 | */ |
| 5329 | boolean updateDrawnWindowStates(WindowState w) { |
| 5330 | w.setDrawnStateEvaluated(true /*evaluated*/); |
| 5331 | |
| 5332 | if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) { |
| 5333 | Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen() |
| 5334 | + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen); |
| 5335 | } |
| 5336 | |
| 5337 | if (allDrawn && !mFreezingScreen) { |
| 5338 | return false; |
| 5339 | } |
| 5340 | |
| 5341 | if (mLastTransactionSequence != mWmService.mTransactionSequence) { |
| 5342 | mLastTransactionSequence = mWmService.mTransactionSequence; |
| 5343 | mNumDrawnWindows = 0; |
| 5344 | startingDisplayed = false; |
| 5345 | |
| 5346 | // There is the main base application window, even if it is exiting, wait for it |
| 5347 | mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0; |
| 5348 | } |
| 5349 | |
| 5350 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 5351 | |
| 5352 | boolean isInterestingAndDrawn = false; |
| 5353 | |
| 5354 | if (!allDrawn && w.mightAffectAllDrawn()) { |
| 5355 | if (DEBUG_VISIBILITY || WM_DEBUG_ORIENTATION.isLogToLogcat()) { |
| 5356 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw() |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 5357 | + ", isAnimationSet=" + isAnimating(TRANSITION)); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5358 | if (!w.isDrawnLw()) { |
| 5359 | Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController |
| 5360 | + " pv=" + w.isVisibleByPolicy() |
| 5361 | + " mDrawState=" + winAnimator.drawStateToString() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 5362 | + " ph=" + w.isParentWindowHidden() + " th=" + mVisibleRequested |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 5363 | + " a=" + isAnimating(TRANSITION)); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | if (w != startingWindow) { |
| 5368 | if (w.isInteresting()) { |
| 5369 | // Add non-main window as interesting since the main app has already been added |
| 5370 | if (findMainWindow(false /* includeStartingApp */) != w) { |
| 5371 | mNumInterestingWindows++; |
| 5372 | } |
| 5373 | if (w.isDrawnLw()) { |
| 5374 | mNumDrawnWindows++; |
| 5375 | |
| 5376 | if (DEBUG_VISIBILITY || WM_DEBUG_ORIENTATION.isLogToLogcat()) { |
| 5377 | Slog.v(TAG, "tokenMayBeDrawn: " |
| 5378 | + this + " w=" + w + " numInteresting=" + mNumInterestingWindows |
| 5379 | + " freezingScreen=" + mFreezingScreen |
| 5380 | + " mAppFreezing=" + w.mAppFreezing); |
| 5381 | } |
| 5382 | |
| 5383 | isInterestingAndDrawn = true; |
| 5384 | } |
| 5385 | } |
| 5386 | } else if (w.isDrawnLw()) { |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 5387 | // The starting window for this container is drawn. |
| 5388 | mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn(this); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5389 | startingDisplayed = true; |
| 5390 | } |
| 5391 | } |
| 5392 | |
| 5393 | return isInterestingAndDrawn; |
| 5394 | } |
| 5395 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5396 | /** |
| 5397 | * Called when the key dispatching to a window associated with the app window container |
| 5398 | * timed-out. |
| 5399 | * |
| 5400 | * @param reason The reason for the key dispatching time out. |
| 5401 | * @param windowPid The pid of the window key dispatching timed out on. |
| 5402 | * @return True if input dispatching should be aborted. |
| 5403 | */ |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 5404 | public boolean keyDispatchingTimedOut(String reason, int windowPid) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5405 | ActivityRecord anrActivity; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5406 | WindowProcessController anrApp; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 5407 | boolean windowFromSameProcessAsActivity; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5408 | synchronized (mAtmService.mGlobalLock) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5409 | anrActivity = getWaitingHistoryRecordLocked(); |
| 5410 | anrApp = app; |
Brian Carlstrom | 7b0f2e8 | 2017-03-31 00:24:18 -0700 | [diff] [blame] | 5411 | windowFromSameProcessAsActivity = |
Vishnu Nair | 19479df | 2019-10-30 08:03:15 -0700 | [diff] [blame] | 5412 | !hasProcess() || app.getPid() == windowPid || windowPid == INVALID_PID; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5413 | } |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5414 | |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 5415 | if (windowFromSameProcessAsActivity) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5416 | return mAtmService.mAmInternal.inputDispatchingTimedOut(anrApp.mOwner, |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 5417 | anrActivity.shortComponentName, anrActivity.info.applicationInfo, |
| 5418 | shortComponentName, app, false, reason); |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 5419 | } else { |
| 5420 | // In this case another process added windows using this activity token. So, we call the |
| 5421 | // 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] | 5422 | return mAtmService.mAmInternal.inputDispatchingTimedOut( |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5423 | windowPid, false /* aboveSystem */, reason) < 0; |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 5424 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | private ActivityRecord getWaitingHistoryRecordLocked() { |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 5428 | // 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] | 5429 | // timeout should not be caused by this. |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 5430 | if (stopped) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5431 | final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 5432 | // Try to use the one which is closest to top. |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5433 | ActivityRecord r = stack.getResumedActivity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5434 | if (r == null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 5435 | r = stack.mPausingActivity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5436 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 5437 | if (r != null) { |
| 5438 | return r; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5439 | } |
| 5440 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 5441 | return this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 5444 | /** Checks whether the activity should be shown for current user. */ |
| 5445 | public boolean okToShowLocked() { |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 5446 | // We cannot show activities when the device is locked and the application is not |
| 5447 | // encryption aware. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5448 | if (!StorageManager.isUserKeyUnlocked(mUserId) |
Bryce Lee | 8558ec7 | 2017-08-17 15:37:26 -0700 | [diff] [blame] | 5449 | && !info.applicationInfo.isEncryptionAware()) { |
| 5450 | return false; |
| 5451 | } |
| 5452 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 5453 | return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0 |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5454 | || (mStackSupervisor.isCurrentProfileLocked(mUserId) |
| 5455 | && mAtmService.mAmInternal.isUserRunning(mUserId, 0 /* flags */)); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5458 | boolean canBeTopRunning() { |
| 5459 | return !finishing && okToShowLocked(); |
| 5460 | } |
| 5461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5462 | /** |
| 5463 | * This method will return true if the activity is either visible, is becoming visible, is |
| 5464 | * currently pausing, or is resumed. |
| 5465 | */ |
| 5466 | public boolean isInterestingToUserLocked() { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 5467 | return mVisibleRequested || nowVisible || mState == PAUSING || mState == RESUMED; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 5468 | } |
| 5469 | |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 5470 | void setSleeping(boolean _sleeping) { |
| 5471 | setSleeping(_sleeping, false); |
| 5472 | } |
| 5473 | |
| 5474 | void setSleeping(boolean _sleeping, boolean force) { |
| 5475 | if (!force && sleeping == _sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 5476 | return; |
| 5477 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5478 | if (attachedToProcess()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 5479 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5480 | app.getThread().scheduleSleeping(appToken, _sleeping); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 5481 | if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) { |
| 5482 | mStackSupervisor.mGoingToSleepActivities.add(this); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 5483 | } |
| 5484 | sleeping = _sleeping; |
| 5485 | } catch (RemoteException e) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 5486 | Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 5487 | } |
| 5488 | } |
| 5489 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 5490 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5491 | static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5492 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5493 | if (r == null || r.getParent() == null) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 5494 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5495 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5496 | final Task task = r.task; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5497 | if (onlyRoot && r.compareTo(task.getRootActivity( |
| 5498 | false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)) > 0) { |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 5499 | return INVALID_TASK_ID; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5500 | } |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 5501 | return task.mTaskId; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | static ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5505 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5506 | return (r != null) ? r.getActivityStack().isInStackLocked(r) : null; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 5509 | static ActivityStack getStackLocked(IBinder token) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5510 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 5511 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5512 | return r.getActivityStack(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5513 | } |
| 5514 | return null; |
| 5515 | } |
| 5516 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 5517 | /** |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 5518 | * @return display id to which this record is attached, |
| 5519 | * {@link android.view.Display#INVALID_DISPLAY} if not attached. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 5520 | */ |
| 5521 | int getDisplayId() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5522 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 5523 | if (stack == null) { |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 5524 | return INVALID_DISPLAY; |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 5525 | } |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 5526 | return stack.getDisplayId(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 5527 | } |
| 5528 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5529 | final boolean isDestroyable() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5530 | if (finishing || !hasProcess()) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5531 | // This would be redundant. |
| 5532 | return false; |
| 5533 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5534 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 5535 | if (isState(RESUMED) || stack == null || this == stack.mPausingActivity || !mHaveState |
| 5536 | || !stopped) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5537 | // We're not ready for this kind of thing. |
| 5538 | return false; |
| 5539 | } |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 5540 | if (mVisibleRequested) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5541 | // The user would notice this! |
| 5542 | return false; |
| 5543 | } |
| 5544 | return true; |
| 5545 | } |
| 5546 | |
Winson Chung | 3bad5cc0 | 2014-08-19 17:44:32 -0700 | [diff] [blame] | 5547 | private static String createImageFilename(long createTime, int taskId) { |
| 5548 | return String.valueOf(taskId) + ACTIVITY_ICON_SUFFIX + createTime + |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 5549 | IMAGE_EXTENSION; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 5550 | } |
| 5551 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 5552 | void setTaskDescription(TaskDescription _taskDescription) { |
| 5553 | Bitmap icon; |
| 5554 | if (_taskDescription.getIconFilename() == null && |
| 5555 | (icon = _taskDescription.getIcon()) != null) { |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 5556 | final String iconFilename = createImageFilename(createTime, task.mTaskId); |
| 5557 | final File iconFile = new File(TaskPersister.getUserImagesDir(task.mUserId), |
Winson Chung | c8408b8 | 2017-01-25 17:58:56 -0800 | [diff] [blame] | 5558 | iconFilename); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 5559 | final String iconFilePath = iconFile.getAbsolutePath(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5560 | mAtmService.getRecentTasks().saveImage(icon, iconFilePath); |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 5561 | _taskDescription.setIconFilename(iconFilePath); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 5562 | } |
| 5563 | taskDescription = _taskDescription; |
| 5564 | } |
| 5565 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5566 | void setVoiceSessionLocked(IVoiceInteractionSession session) { |
| 5567 | voiceSession = session; |
| 5568 | pendingVoiceInteractionStart = false; |
| 5569 | } |
| 5570 | |
| 5571 | void clearVoiceSessionLocked() { |
| 5572 | voiceSession = null; |
| 5573 | pendingVoiceInteractionStart = false; |
| 5574 | } |
| 5575 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 5576 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 5577 | showStartingWindow(prev, newTask, taskSwitch, false /* fromRecents */); |
| 5578 | } |
| 5579 | |
| 5580 | void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch, |
| 5581 | boolean fromRecents) { |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 5582 | if (mTaskOverlay) { |
| 5583 | // We don't show starting window for overlay activities. |
| 5584 | return; |
| 5585 | } |
Sunny Goyal | d85bed5 | 2018-09-25 12:01:01 -0700 | [diff] [blame] | 5586 | if (pendingOptions != null |
| 5587 | && pendingOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 5588 | // Don't show starting window when using shared element transition. |
| 5589 | return; |
| 5590 | } |
Wale Ogunwale | 19866e2 | 2017-04-19 06:05:13 -0700 | [diff] [blame] | 5591 | |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 5592 | final CompatibilityInfo compatInfo = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5593 | mAtmService.compatibilityInfoForPackageLocked(info.applicationInfo); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 5594 | final boolean shown = addStartingWindow(packageName, theme, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5595 | compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 5596 | prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(), |
Jorim Jaggi | 70aa4d1 | 2017-05-15 00:05:54 +0200 | [diff] [blame] | 5597 | allowTaskSnapshot(), |
Louis Chang | eadb22f | 2019-06-19 12:09:23 +0800 | [diff] [blame] | 5598 | mState.ordinal() >= STARTED.ordinal() && mState.ordinal() <= STOPPED.ordinal(), |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 5599 | fromRecents); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 5600 | if (shown) { |
| 5601 | mStartingWindowState = STARTING_WINDOW_SHOWN; |
| 5602 | } |
| 5603 | } |
| 5604 | |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 5605 | /** |
| 5606 | * If any activities below the top running one are in the INITIALIZING state and they have a |
| 5607 | * starting window displayed then remove that starting window. It is possible that the activity |
| 5608 | * in this state will never resumed in which case that starting window will be orphaned. |
| 5609 | * <p> |
| 5610 | * It should only be called if this activity is behind other fullscreen activity. |
| 5611 | */ |
| 5612 | void cancelInitializing() { |
| 5613 | if (mStartingWindowState == STARTING_WINDOW_SHOWN) { |
| 5614 | // Remove orphaned starting window. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5615 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, "Found orphaned starting window " + this); |
| 5616 | mStartingWindowState = STARTING_WINDOW_REMOVED; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 5617 | removeStartingWindow(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5618 | } |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 5619 | if (isState(INITIALIZING) && !shouldBeVisible( |
| 5620 | true /* behindFullscreenActivity */, true /* ignoringKeyguard */)) { |
| 5621 | // Remove the unknown visibility record because an invisible activity shouldn't block |
| 5622 | // the keyguard transition. |
| 5623 | mDisplayContent.mUnknownAppVisibilityController.appRemovedOrHidden(this); |
| 5624 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 5625 | } |
| 5626 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5627 | void postWindowRemoveStartingWindowCleanup(WindowState win) { |
| 5628 | // TODO: Something smells about the code below...Is there a better way? |
| 5629 | if (startingWindow == win) { |
| 5630 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Notify removed startingWindow %s", win); |
| 5631 | removeStartingWindow(); |
| 5632 | } else if (mChildren.size() == 0) { |
| 5633 | // If this is the last window and we had requested a starting transition window, |
| 5634 | // well there is no point now. |
| 5635 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Nulling last startingData"); |
| 5636 | mStartingData = null; |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 5637 | if (mVisibleSetFromTransferredStartingWindow) { |
| 5638 | // We set the visible state to true for the token from a transferred starting |
| 5639 | // window. We now reset it back to false since the starting window was the last |
| 5640 | // window in the token. |
| 5641 | setVisible(false); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5642 | } |
| 5643 | } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) { |
| 5644 | // If this is the last window except for a starting transition window, |
| 5645 | // we need to get rid of the starting transition. |
| 5646 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Last window, removing starting window %s", win); |
| 5647 | removeStartingWindow(); |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | void removeDeadWindows() { |
| 5652 | for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) { |
| 5653 | WindowState win = mChildren.get(winNdx); |
| 5654 | if (win.mAppDied) { |
| 5655 | ProtoLog.w(WM_DEBUG_ADD_REMOVE, |
| 5656 | "removeDeadWindows: %s", win); |
| 5657 | // Set mDestroying, we don't want any animation or delayed removal here. |
| 5658 | win.mDestroying = true; |
| 5659 | // Also removes child windows. |
| 5660 | win.removeIfPossible(); |
| 5661 | } |
| 5662 | } |
| 5663 | } |
| 5664 | |
| 5665 | boolean hasWindowsAlive() { |
| 5666 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 5667 | // No need to loop through child windows as the answer should be the same as that of the |
| 5668 | // parent window. |
| 5669 | if (!(mChildren.get(i)).mAppDied) { |
| 5670 | return true; |
| 5671 | } |
| 5672 | } |
| 5673 | return false; |
| 5674 | } |
| 5675 | |
| 5676 | void setWillReplaceWindows(boolean animate) { |
| 5677 | ProtoLog.d(WM_DEBUG_ADD_REMOVE, |
| 5678 | "Marking app token %s with replacing windows.", this); |
| 5679 | |
| 5680 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 5681 | final WindowState w = mChildren.get(i); |
| 5682 | w.setWillReplaceWindow(animate); |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | void setWillReplaceChildWindows() { |
| 5687 | ProtoLog.d(WM_DEBUG_ADD_REMOVE, "Marking app token %s" |
| 5688 | + " with replacing child windows.", this); |
| 5689 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 5690 | final WindowState w = mChildren.get(i); |
| 5691 | w.setWillReplaceChildWindows(); |
| 5692 | } |
| 5693 | } |
| 5694 | |
| 5695 | void clearWillReplaceWindows() { |
| 5696 | ProtoLog.d(WM_DEBUG_ADD_REMOVE, |
| 5697 | "Resetting app token %s of replacing window marks.", this); |
| 5698 | |
| 5699 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 5700 | final WindowState w = mChildren.get(i); |
| 5701 | w.clearWillReplaceWindow(); |
| 5702 | } |
| 5703 | } |
| 5704 | |
| 5705 | void requestUpdateWallpaperIfNeeded() { |
| 5706 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 5707 | final WindowState w = mChildren.get(i); |
| 5708 | w.requestUpdateWallpaperIfNeeded(); |
| 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | /** |
| 5713 | * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 5714 | * true and isn't fully transparent. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5715 | */ |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 5716 | WindowState getTopFullscreenOpaqueWindow() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5717 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 5718 | final WindowState win = mChildren.get(i); |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 5719 | if (win != null && win.mAttrs.isFullscreen() && !win.isFullyTransparent()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5720 | return win; |
| 5721 | } |
| 5722 | } |
| 5723 | return null; |
| 5724 | } |
| 5725 | |
| 5726 | WindowState findMainWindow() { |
| 5727 | return findMainWindow(true); |
| 5728 | } |
| 5729 | |
| 5730 | /** |
| 5731 | * Finds the main window that either has type base application or application starting if |
| 5732 | * requested. |
| 5733 | * |
| 5734 | * @param includeStartingApp Allow to search application-starting windows to also be returned. |
| 5735 | * @return The main window of type base application or application starting if requested. |
| 5736 | */ |
| 5737 | WindowState findMainWindow(boolean includeStartingApp) { |
| 5738 | WindowState candidate = null; |
| 5739 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
| 5740 | final WindowState win = mChildren.get(j); |
| 5741 | final int type = win.mAttrs.type; |
| 5742 | // No need to loop through child window as base application and starting types can't be |
| 5743 | // child windows. |
| 5744 | if (type == TYPE_BASE_APPLICATION |
| 5745 | || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) { |
| 5746 | // In cases where there are multiple windows, we prefer the non-exiting window. This |
| 5747 | // happens for example when replacing windows during an activity relaunch. When |
| 5748 | // constructing the animation, we want the new window, not the exiting one. |
| 5749 | if (win.mAnimatingExit) { |
| 5750 | candidate = win; |
| 5751 | } else { |
| 5752 | return win; |
| 5753 | } |
| 5754 | } |
| 5755 | } |
| 5756 | return candidate; |
| 5757 | } |
| 5758 | |
| 5759 | SurfaceControl getAppAnimationLayer() { |
| 5760 | return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME |
| 5761 | : needsZBoost() ? ANIMATION_LAYER_BOOSTED |
| 5762 | : ANIMATION_LAYER_STANDARD); |
| 5763 | } |
| 5764 | |
| 5765 | @Override |
| 5766 | boolean needsZBoost() { |
| 5767 | return mNeedsZBoost || super.needsZBoost(); |
| 5768 | } |
| 5769 | |
| 5770 | @Override |
| 5771 | public SurfaceControl getAnimationLeashParent() { |
| 5772 | // For transitions in the pinned stack (menu activity) we just let them occur as a child |
| 5773 | // of the pinned stack. |
| 5774 | // All normal app transitions take place in an animation layer which is below the pinned |
| 5775 | // stack but may be above the parent stacks of the given animating apps by default. When |
| 5776 | // a new hierarchical animation is enabled, we just let them occur as a child of the parent |
| 5777 | // stack, i.e. the hierarchy of the surfaces is unchanged. |
| 5778 | if (inPinnedWindowingMode()) { |
| 5779 | return getStack().getSurfaceControl(); |
| 5780 | } else if (WindowManagerService.sHierarchicalAnimations) { |
| 5781 | return super.getAnimationLeashParent(); |
| 5782 | } else { |
| 5783 | return getAppAnimationLayer(); |
| 5784 | } |
| 5785 | } |
| 5786 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5787 | @VisibleForTesting |
| 5788 | boolean shouldAnimate(int transit) { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 5789 | if (task != null && !task.shouldAnimate()) { |
| 5790 | return false; |
| 5791 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5792 | final boolean isSplitScreenPrimary = |
| 5793 | getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 5794 | final boolean allowSplitScreenPrimaryAnimation = transit != TRANSIT_WALLPAPER_OPEN; |
| 5795 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5796 | // We animate always if it's not split screen primary, and only some special cases in split |
| 5797 | // screen primary because it causes issues with stack clipping when we run an un-minimize |
| 5798 | // animation at the same time. |
| 5799 | return !isSplitScreenPrimary || allowSplitScreenPrimaryAnimation; |
| 5800 | } |
| 5801 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 5802 | @Override |
| 5803 | boolean isChangingAppTransition() { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5804 | return task != null ? task.isChangingAppTransition() : super.isChangingAppTransition(); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 5805 | } |
| 5806 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5807 | /** |
| 5808 | * Creates a layer to apply crop to an animation. |
| 5809 | */ |
| 5810 | private SurfaceControl createAnimationBoundsLayer(Transaction t) { |
| 5811 | ProtoLog.i(WM_DEBUG_APP_TRANSITIONS_ANIM, "Creating animation bounds layer"); |
| 5812 | final SurfaceControl.Builder builder = makeAnimationLeash() |
| 5813 | .setParent(getAnimationLeashParent()) |
| 5814 | .setName(getSurfaceControl() + " - animation-bounds"); |
| 5815 | final SurfaceControl boundsLayer = builder.build(); |
| 5816 | t.show(boundsLayer); |
| 5817 | return boundsLayer; |
| 5818 | } |
| 5819 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5820 | @Override |
| 5821 | public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) { |
| 5822 | return mAnimatingActivityRegistry != null |
| 5823 | && mAnimatingActivityRegistry.notifyAboutToFinish( |
| 5824 | this, endDeferFinishCallback); |
| 5825 | } |
| 5826 | |
| 5827 | private boolean shouldStartChangeTransition(int prevWinMode, int newWinMode) { |
| 5828 | if (mWmService.mDisableTransitionAnimation |
| 5829 | || !isVisible() |
| 5830 | || getDisplayContent().mAppTransition.isTransitionSet() |
| 5831 | || getSurfaceControl() == null) { |
| 5832 | return false; |
| 5833 | } |
| 5834 | // Only do an animation into and out-of freeform mode for now. Other mode |
| 5835 | // transition animations are currently handled by system-ui. |
| 5836 | return (prevWinMode == WINDOWING_MODE_FREEFORM) != (newWinMode == WINDOWING_MODE_FREEFORM); |
| 5837 | } |
| 5838 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 5839 | @Override |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5840 | boolean isWaitingForTransitionStart() { |
| 5841 | final DisplayContent dc = getDisplayContent(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5842 | return dc.mAppTransition.isTransitionSet() |
| 5843 | && (dc.mOpeningApps.contains(this) |
| 5844 | || dc.mClosingApps.contains(this) |
| 5845 | || dc.mChangingApps.contains(this)); |
| 5846 | } |
| 5847 | |
| 5848 | /** |
| 5849 | * Initializes a change transition. Because the app is visible already, there is a small period |
| 5850 | * of time where the user can see the app content/window update before the transition starts. |
| 5851 | * To prevent this, we immediately take a snapshot and place the app/snapshot into a leash which |
| 5852 | * "freezes" the location/crop until the transition starts. |
| 5853 | * <p> |
| 5854 | * Here's a walk-through of the process: |
| 5855 | * 1. Create a temporary leash ("interim-change-leash") and reparent the app to it. |
| 5856 | * 2. Set the temporary leash's position/crop to the current state. |
| 5857 | * 3. Create a snapshot and place that at the top of the leash to cover up content changes. |
| 5858 | * 4. Once the transition is ready, it will reparent the app to the animation leash. |
| 5859 | * 5. Detach the interim-change-leash. |
| 5860 | */ |
| 5861 | private void initializeChangeTransition(Rect startBounds) { |
| 5862 | mDisplayContent.prepareAppTransition(TRANSIT_TASK_CHANGE_WINDOWING_MODE, |
| 5863 | false /* alwaysKeepCurrent */, 0, false /* forceOverride */); |
| 5864 | mDisplayContent.mChangingApps.add(this); |
| 5865 | mTransitStartRect.set(startBounds); |
| 5866 | |
| 5867 | final SurfaceControl.Builder builder = makeAnimationLeash() |
| 5868 | .setParent(getAnimationLeashParent()) |
| 5869 | .setName(getSurfaceControl() + " - interim-change-leash"); |
| 5870 | mTransitChangeLeash = builder.build(); |
| 5871 | Transaction t = getPendingTransaction(); |
| 5872 | t.setWindowCrop(mTransitChangeLeash, startBounds.width(), startBounds.height()); |
| 5873 | t.setPosition(mTransitChangeLeash, startBounds.left, startBounds.top); |
| 5874 | t.show(mTransitChangeLeash); |
| 5875 | t.reparent(getSurfaceControl(), mTransitChangeLeash); |
| 5876 | onAnimationLeashCreated(t, mTransitChangeLeash); |
| 5877 | |
| 5878 | // Skip creating snapshot if this transition is controlled by a remote animator which |
| 5879 | // doesn't need it. |
| 5880 | ArraySet<Integer> activityTypes = new ArraySet<>(); |
| 5881 | activityTypes.add(getActivityType()); |
| 5882 | RemoteAnimationAdapter adapter = |
| 5883 | mDisplayContent.mAppTransitionController.getRemoteAnimationOverride( |
| 5884 | this, TRANSIT_TASK_CHANGE_WINDOWING_MODE, activityTypes); |
| 5885 | if (adapter != null && !adapter.getChangeNeedsSnapshot()) { |
| 5886 | return; |
| 5887 | } |
| 5888 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5889 | if (mThumbnail == null && task != null && !hasCommittedReparentToAnimationLeash()) { |
| 5890 | SurfaceControl.ScreenshotGraphicBuffer snapshot = |
| 5891 | mWmService.mTaskSnapshotController.createTaskSnapshot( |
| 5892 | task, 1 /* scaleFraction */); |
| 5893 | if (snapshot != null) { |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 5894 | mThumbnail = new WindowContainerThumbnail(mWmService.mSurfaceFactory, t, this, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5895 | snapshot.getGraphicBuffer(), true /* relative */); |
| 5896 | } |
| 5897 | } |
| 5898 | } |
| 5899 | |
| 5900 | @Override |
| 5901 | public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) { |
| 5902 | // The leash is parented to the animation layer. We need to preserve the z-order by using |
| 5903 | // the prefix order index, but we boost if necessary. |
| 5904 | int layer = 0; |
| 5905 | if (!inPinnedWindowingMode()) { |
| 5906 | layer = getPrefixOrderIndex(); |
| 5907 | } else { |
| 5908 | // Pinned stacks have animations take place within themselves rather than an animation |
| 5909 | // layer so we need to preserve the order relative to the stack (e.g. the order of our |
| 5910 | // task/parent). |
| 5911 | layer = getParent().getPrefixOrderIndex(); |
| 5912 | } |
| 5913 | |
| 5914 | if (mNeedsZBoost) { |
| 5915 | layer += Z_BOOST_BASE; |
| 5916 | } |
| 5917 | if (!mNeedsAnimationBoundsLayer) { |
| 5918 | t.setLayer(leash, layer); |
| 5919 | } |
| 5920 | |
| 5921 | final DisplayContent dc = getDisplayContent(); |
| 5922 | dc.assignStackOrdering(); |
| 5923 | |
| 5924 | if (leash == mTransitChangeLeash) { |
| 5925 | // This is a temporary state so skip any animation notifications |
| 5926 | return; |
| 5927 | } else if (mTransitChangeLeash != null) { |
| 5928 | // unparent mTransitChangeLeash for clean-up |
| 5929 | clearChangeLeash(t, false /* cancel */); |
| 5930 | } |
| 5931 | |
| 5932 | if (mAnimatingActivityRegistry != null) { |
| 5933 | mAnimatingActivityRegistry.notifyStarting(this); |
| 5934 | } |
| 5935 | |
| 5936 | // If the animation needs to be cropped then an animation bounds layer is created as a child |
| 5937 | // of the pinned stack or animation layer. The leash is then reparented to this new layer. |
| 5938 | if (mNeedsAnimationBoundsLayer) { |
| 5939 | mTmpRect.setEmpty(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5940 | if (getDisplayContent().mAppTransitionController.isTransitWithinTask( |
| 5941 | getTransit(), task)) { |
| 5942 | task.getBounds(mTmpRect); |
| 5943 | } else { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 5944 | final ActivityStack stack = getStack(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5945 | if (stack == null) { |
| 5946 | return; |
| 5947 | } |
| 5948 | // Set clip rect to stack bounds. |
| 5949 | stack.getBounds(mTmpRect); |
| 5950 | } |
| 5951 | mAnimationBoundsLayer = createAnimationBoundsLayer(t); |
| 5952 | |
| 5953 | // Crop to stack bounds. |
| 5954 | t.setWindowCrop(mAnimationBoundsLayer, mTmpRect); |
| 5955 | t.setLayer(mAnimationBoundsLayer, layer); |
| 5956 | |
| 5957 | // Reparent leash to animation bounds layer. |
| 5958 | t.reparent(leash, mAnimationBoundsLayer); |
| 5959 | } |
| 5960 | } |
| 5961 | |
| 5962 | @Override |
| 5963 | void prepareSurfaces() { |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 5964 | final boolean show = isVisible() || isAnimating(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5965 | |
| 5966 | if (mSurfaceControl != null) { |
| 5967 | if (show && !mLastSurfaceShowing) { |
| 5968 | getPendingTransaction().show(mSurfaceControl); |
| 5969 | } else if (!show && mLastSurfaceShowing) { |
| 5970 | getPendingTransaction().hide(mSurfaceControl); |
| 5971 | } |
| 5972 | } |
| 5973 | if (mThumbnail != null) { |
| 5974 | mThumbnail.setShowing(getPendingTransaction(), show); |
| 5975 | } |
| 5976 | mLastSurfaceShowing = show; |
| 5977 | super.prepareSurfaces(); |
| 5978 | } |
| 5979 | |
| 5980 | /** |
| 5981 | * @return Whether our {@link #getSurfaceControl} is currently showing. |
| 5982 | */ |
| 5983 | boolean isSurfaceShowing() { |
| 5984 | return mLastSurfaceShowing; |
| 5985 | } |
| 5986 | |
| 5987 | boolean isInChangeTransition() { |
| 5988 | return mTransitChangeLeash != null || AppTransition.isChangeTransit(mTransit); |
| 5989 | } |
| 5990 | |
| 5991 | void attachThumbnailAnimation() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 5992 | if (!isAnimating()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5993 | return; |
| 5994 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5995 | final GraphicBuffer thumbnailHeader = |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5996 | getDisplayContent().mAppTransition.getAppTransitionThumbnailHeader(task); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5997 | if (thumbnailHeader == null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5998 | ProtoLog.d(WM_DEBUG_APP_TRANSITIONS, "No thumbnail header bitmap for: %s", task); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5999 | return; |
| 6000 | } |
| 6001 | clearThumbnail(); |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 6002 | mThumbnail = new WindowContainerThumbnail(mWmService.mSurfaceFactory, |
| 6003 | getPendingTransaction(), this, thumbnailHeader); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6004 | mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader)); |
| 6005 | } |
| 6006 | |
| 6007 | /** |
| 6008 | * Attaches a surface with a thumbnail for the |
| 6009 | * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation. |
| 6010 | */ |
| 6011 | void attachCrossProfileAppsThumbnailAnimation() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 6012 | if (!isAnimating()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6013 | return; |
| 6014 | } |
| 6015 | clearThumbnail(); |
| 6016 | |
| 6017 | final WindowState win = findMainWindow(); |
| 6018 | if (win == null) { |
| 6019 | return; |
| 6020 | } |
| 6021 | final Rect frame = win.getFrameLw(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6022 | final int thumbnailDrawableRes = task.mUserId == mWmService.mCurrentUserId |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6023 | ? R.drawable.ic_account_circle |
| 6024 | : R.drawable.ic_corp_badge; |
| 6025 | final GraphicBuffer thumbnail = |
| 6026 | getDisplayContent().mAppTransition |
| 6027 | .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame); |
| 6028 | if (thumbnail == null) { |
| 6029 | return; |
| 6030 | } |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 6031 | mThumbnail = new WindowContainerThumbnail(mWmService.mSurfaceFactory, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6032 | getPendingTransaction(), this, thumbnail); |
| 6033 | final Animation animation = |
| 6034 | getDisplayContent().mAppTransition.createCrossProfileAppsThumbnailAnimationLocked( |
| 6035 | win.getFrameLw()); |
| 6036 | mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left, |
| 6037 | frame.top)); |
| 6038 | } |
| 6039 | |
| 6040 | private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) { |
| 6041 | final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo(); |
| 6042 | |
| 6043 | // If this is a multi-window scenario, we use the windows frame as |
| 6044 | // destination of the thumbnail header animation. If this is a full screen |
| 6045 | // window scenario, we use the whole display as the target. |
| 6046 | WindowState win = findMainWindow(); |
| 6047 | Rect appRect = win != null ? win.getContentFrameLw() : |
| 6048 | new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight); |
| 6049 | final Rect insets = win != null ? win.getContentInsets() : null; |
| 6050 | final Configuration displayConfig = mDisplayContent.getConfiguration(); |
| 6051 | return getDisplayContent().mAppTransition.createThumbnailAspectScaleAnimationLocked( |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6052 | appRect, insets, thumbnailHeader, task, displayConfig.uiMode, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6053 | displayConfig.orientation); |
| 6054 | } |
| 6055 | |
| 6056 | @Override |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6057 | public void onAnimationLeashLost(Transaction t) { |
| 6058 | super.onAnimationLeashLost(t); |
| 6059 | if (mAnimationBoundsLayer != null) { |
| 6060 | t.remove(mAnimationBoundsLayer); |
| 6061 | mAnimationBoundsLayer = null; |
| 6062 | } |
| 6063 | |
| 6064 | if (mAnimatingActivityRegistry != null) { |
| 6065 | mAnimatingActivityRegistry.notifyFinished(this); |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | @Override |
| 6070 | protected void onAnimationFinished() { |
| 6071 | super.onAnimationFinished(); |
| 6072 | |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 6073 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AR#onAnimationFinished"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6074 | mTransit = TRANSIT_UNSET; |
| 6075 | mTransitFlags = 0; |
| 6076 | mNeedsZBoost = false; |
| 6077 | mNeedsAnimationBoundsLayer = false; |
| 6078 | |
| 6079 | setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER, |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 6080 | "ActivityRecord"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6081 | |
| 6082 | clearThumbnail(); |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 6083 | setClientVisible(isVisible() || mVisibleRequested); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6084 | |
| 6085 | getDisplayContent().computeImeTargetIfNeeded(this); |
| 6086 | |
| 6087 | if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this |
| 6088 | + ": reportedVisible=" + reportedVisible |
| 6089 | + " okToDisplay=" + okToDisplay() |
| 6090 | + " okToAnimate=" + okToAnimate() |
| 6091 | + " startingDisplayed=" + startingDisplayed); |
| 6092 | |
| 6093 | // clean up thumbnail window |
| 6094 | if (mThumbnail != null) { |
| 6095 | mThumbnail.destroy(); |
| 6096 | mThumbnail = null; |
| 6097 | } |
| 6098 | |
| 6099 | // WindowState.onExitAnimationDone might modify the children list, so make a copy and then |
| 6100 | // traverse the copy. |
| 6101 | final ArrayList<WindowState> children = new ArrayList<>(mChildren); |
| 6102 | children.forEach(WindowState::onExitAnimationDone); |
| 6103 | |
| 6104 | getDisplayContent().mAppTransition.notifyAppTransitionFinishedLocked(token); |
| 6105 | scheduleAnimation(); |
| 6106 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6107 | if (mAtmService.mRootWindowContainer.allResumedActivitiesIdle() |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6108 | || mAtmService.mStackSupervisor.isStoppingNoHistoryActivity()) { |
| 6109 | // If all activities are already idle or there is an activity that must be |
| 6110 | // stopped immediately after visible, then we now need to make sure we perform |
| 6111 | // the full stop of this activity. This is because we won't do that while they are still |
| 6112 | // waiting for the animation to finish. |
| 6113 | if (mAtmService.mStackSupervisor.mStoppingActivities.contains(this)) { |
| 6114 | mAtmService.mStackSupervisor.scheduleIdleLocked(); |
| 6115 | } |
| 6116 | } else { |
| 6117 | // Instead of doing the full stop routine here, let's just hide any activities |
| 6118 | // we now can, and let them stop when the normal idle happens. |
| 6119 | mAtmService.mStackSupervisor.processStoppingActivitiesLocked(null /* idleActivity */, |
| 6120 | false /* remove */, true /* processPausingActivities */); |
| 6121 | } |
| 6122 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 6123 | } |
| 6124 | |
| 6125 | /** |
| 6126 | * @param cancel {@code true} if clearing the leash due to cancelling instead of transferring |
| 6127 | * to another leash. |
| 6128 | */ |
| 6129 | private void clearChangeLeash(Transaction t, boolean cancel) { |
| 6130 | if (mTransitChangeLeash == null) { |
| 6131 | return; |
| 6132 | } |
| 6133 | if (cancel) { |
| 6134 | clearThumbnail(); |
| 6135 | SurfaceControl sc = getSurfaceControl(); |
| 6136 | SurfaceControl parentSc = getParentSurfaceControl(); |
| 6137 | // Don't reparent if surface is getting destroyed |
| 6138 | if (parentSc != null && sc != null) { |
| 6139 | t.reparent(sc, getParentSurfaceControl()); |
| 6140 | } |
| 6141 | } |
| 6142 | t.hide(mTransitChangeLeash); |
| 6143 | t.remove(mTransitChangeLeash); |
| 6144 | mTransitChangeLeash = null; |
| 6145 | if (cancel) { |
| 6146 | onAnimationLeashLost(t); |
| 6147 | } |
| 6148 | } |
| 6149 | |
| 6150 | void clearAnimatingFlags() { |
| 6151 | boolean wallpaperMightChange = false; |
| 6152 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 6153 | final WindowState win = mChildren.get(i); |
| 6154 | wallpaperMightChange |= win.clearAnimatingFlags(); |
| 6155 | } |
| 6156 | if (wallpaperMightChange) { |
| 6157 | requestUpdateWallpaperIfNeeded(); |
| 6158 | } |
| 6159 | } |
| 6160 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6161 | @Override |
| 6162 | void cancelAnimation() { |
| 6163 | cancelAnimationOnly(); |
| 6164 | clearThumbnail(); |
| 6165 | clearChangeLeash(getPendingTransaction(), true /* cancel */); |
| 6166 | } |
| 6167 | |
| 6168 | /** |
| 6169 | * This only cancels the animation. It doesn't do other teardown like cleaning-up thumbnail |
| 6170 | * or interim leashes. |
| 6171 | * <p> |
| 6172 | * Used when canceling in preparation for starting a new animation. |
| 6173 | */ |
| 6174 | void cancelAnimationOnly() { |
| 6175 | super.cancelAnimation(); |
| 6176 | } |
| 6177 | |
| 6178 | @VisibleForTesting |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 6179 | WindowContainerThumbnail getThumbnail() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6180 | return mThumbnail; |
| 6181 | } |
| 6182 | |
| 6183 | private void clearThumbnail() { |
| 6184 | if (mThumbnail == null) { |
| 6185 | return; |
| 6186 | } |
| 6187 | mThumbnail.destroy(); |
| 6188 | mThumbnail = null; |
| 6189 | } |
| 6190 | |
| 6191 | public int getTransit() { |
| 6192 | return mTransit; |
| 6193 | } |
| 6194 | |
| 6195 | int getTransitFlags() { |
| 6196 | return mTransitFlags; |
| 6197 | } |
| 6198 | |
| 6199 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 6200 | mRemoteAnimationDefinition = definition; |
Winson Chung | 10fc25d | 2019-12-10 14:13:56 -0800 | [diff] [blame] | 6201 | if (definition != null) { |
| 6202 | definition.linkToDeath(this::unregisterRemoteAnimations); |
| 6203 | } |
| 6204 | } |
| 6205 | |
| 6206 | void unregisterRemoteAnimations() { |
| 6207 | mRemoteAnimationDefinition = null; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6208 | } |
| 6209 | |
| 6210 | RemoteAnimationDefinition getRemoteAnimationDefinition() { |
| 6211 | return mRemoteAnimationDefinition; |
| 6212 | } |
| 6213 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 6214 | void setRequestedOrientation(int requestedOrientation) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 6215 | setOrientation(requestedOrientation, mayFreezeScreenLocked()); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6216 | mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged( |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 6217 | task.mTaskId, requestedOrientation); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 6218 | } |
| 6219 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 6220 | private void setOrientation(int requestedOrientation, boolean freezeScreenIfNeeded) { |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 6221 | final IBinder binder = |
| 6222 | (freezeScreenIfNeeded && appToken != null) ? appToken.asBinder() : null; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 6223 | setOrientation(requestedOrientation, binder, this); |
Garfield Tan | 36a69ad | 2019-01-16 17:08:23 -0800 | [diff] [blame] | 6224 | |
| 6225 | // Push the new configuration to the requested app in case where it's not pushed, e.g. when |
| 6226 | // the request is handled at task level with letterbox. |
| 6227 | if (!getMergedOverrideConfiguration().equals( |
| 6228 | mLastReportedConfiguration.getMergedConfiguration())) { |
| 6229 | ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */); |
| 6230 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 6231 | } |
| 6232 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6233 | void reportDescendantOrientationChangeIfNeeded() { |
| 6234 | // Orientation request is exposed only when we're visible. Therefore visibility change |
| 6235 | // will change requested orientation. Notify upward the hierarchy ladder to adjust |
| 6236 | // configuration. This is important to cases where activities with incompatible |
| 6237 | // orientations launch, or user goes back from an activity of bi-orientation to an |
| 6238 | // activity with specified orientation. |
| 6239 | if (getRequestedOrientation() == SCREEN_ORIENTATION_UNSET) { |
| 6240 | return; |
| 6241 | } |
| 6242 | |
| 6243 | final IBinder freezeToken = mayFreezeScreenLocked() ? appToken : null; |
| 6244 | onDescendantOrientationChanged(freezeToken, this); |
| 6245 | } |
| 6246 | |
| 6247 | /** |
| 6248 | * We override because this class doesn't want its children affecting its reported orientation |
| 6249 | * in anyway. |
| 6250 | */ |
| 6251 | @Override |
| 6252 | int getOrientation(int candidate) { |
| 6253 | if (candidate == SCREEN_ORIENTATION_BEHIND) { |
| 6254 | // Allow app to specify orientation regardless of its visibility state if the current |
| 6255 | // candidate want us to use orientation behind. I.e. the visible app on-top of this one |
| 6256 | // wants us to use the orientation of the app behind it. |
| 6257 | return mOrientation; |
| 6258 | } |
| 6259 | |
Wale Ogunwale | 7a8889a | 2019-11-16 08:23:42 -0800 | [diff] [blame] | 6260 | // The {@link ActivityRecord} should only specify an orientation when it is not closing. |
| 6261 | // Allowing closing {@link ActivityRecord} to participate can lead to an Activity in another |
| 6262 | // task being started in the wrong orientation during the transition. |
| 6263 | if (!getDisplayContent().mClosingApps.contains(this) |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6264 | && (isVisible() || getDisplayContent().mOpeningApps.contains(this))) { |
| 6265 | return mOrientation; |
| 6266 | } |
| 6267 | |
| 6268 | return SCREEN_ORIENTATION_UNSET; |
| 6269 | } |
| 6270 | |
| 6271 | /** Returns the app's preferred orientation regardless of its currently visibility state. */ |
| 6272 | int getRequestedOrientation() { |
| 6273 | return mOrientation; |
| 6274 | } |
| 6275 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 6276 | /** |
| 6277 | * Set the last reported global configuration to the client. Should be called whenever a new |
| 6278 | * global configuration is sent to the client for this activity. |
| 6279 | */ |
| 6280 | void setLastReportedGlobalConfiguration(@NonNull Configuration config) { |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 6281 | mLastReportedConfiguration.setGlobalConfiguration(config); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6282 | } |
| 6283 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 6284 | /** |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 6285 | * Set the last reported configuration to the client. Should be called whenever |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 6286 | * a new merged configuration is sent to the client for this activity. |
| 6287 | */ |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 6288 | void setLastReportedConfiguration(@NonNull MergedConfiguration config) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 6289 | setLastReportedConfiguration(config.getGlobalConfiguration(), |
| 6290 | config.getOverrideConfiguration()); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 6291 | } |
| 6292 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 6293 | private void setLastReportedConfiguration(Configuration global, Configuration override) { |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 6294 | mLastReportedConfiguration.setConfiguration(global, override); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6295 | } |
| 6296 | |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6297 | /** |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6298 | * @return {@code true} if this activity is in size compatibility mode that uses the different |
| 6299 | * density or bounds from its parent. |
| 6300 | */ |
| 6301 | boolean inSizeCompatMode() { |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6302 | if (mCompatDisplayInsets == null || !shouldUseSizeCompatMode()) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6303 | return false; |
| 6304 | } |
Riddle Hsu | 359c84d | 2019-12-10 17:49:52 +0800 | [diff] [blame] | 6305 | final Rect appBounds = getConfiguration().windowConfiguration.getAppBounds(); |
| 6306 | if (appBounds == null) { |
| 6307 | // The app bounds hasn't been computed yet. |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6308 | return false; |
| 6309 | } |
| 6310 | |
| 6311 | final Configuration parentConfig = getParent().getConfiguration(); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6312 | // Although colorMode, screenLayout, smallestScreenWidthDp are also fixed, generally these |
| 6313 | // fields should be changed with density and bounds, so here only compares the most |
| 6314 | // significant field. |
Riddle Hsu | 359c84d | 2019-12-10 17:49:52 +0800 | [diff] [blame] | 6315 | if (parentConfig.densityDpi != getConfiguration().densityDpi) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6316 | return true; |
| 6317 | } |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6318 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6319 | final Rect parentAppBounds = parentConfig.windowConfiguration.getAppBounds(); |
Riddle Hsu | 359c84d | 2019-12-10 17:49:52 +0800 | [diff] [blame] | 6320 | final int appWidth = appBounds.width(); |
| 6321 | final int appHeight = appBounds.height(); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 6322 | final int parentAppWidth = parentAppBounds.width(); |
| 6323 | final int parentAppHeight = parentAppBounds.height(); |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 6324 | if (parentAppWidth == appWidth && parentAppHeight == appHeight) { |
| 6325 | // Matched the parent bounds. |
| 6326 | return false; |
| 6327 | } |
| 6328 | if (parentAppWidth > appWidth && parentAppHeight > appHeight) { |
| 6329 | // Both sides are smaller than the parent. |
| 6330 | return true; |
| 6331 | } |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 6332 | if (parentAppWidth < appWidth || parentAppHeight < appHeight) { |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6333 | // One side is larger than the parent. |
| 6334 | return true; |
| 6335 | } |
| 6336 | |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 6337 | // The rest of the condition is that only one side is smaller than the parent, but it still |
| 6338 | // needs to exclude the cases where the size is limited by the fixed aspect ratio. |
| 6339 | if (info.maxAspectRatio > 0) { |
Riddle Hsu | 359c84d | 2019-12-10 17:49:52 +0800 | [diff] [blame] | 6340 | final float aspectRatio = |
| 6341 | (float) Math.max(appWidth, appHeight) / Math.min(appWidth, appHeight); |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 6342 | if (aspectRatio >= info.maxAspectRatio) { |
| 6343 | // The current size has reached the max aspect ratio. |
| 6344 | return false; |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 6345 | } |
| 6346 | } |
Riddle Hsu | 9ad178510 | 2019-03-26 00:26:54 +0800 | [diff] [blame] | 6347 | if (info.minAspectRatio > 0) { |
| 6348 | // The activity should have at least the min aspect ratio, so this checks if the parent |
| 6349 | // still has available space to provide larger aspect ratio. |
| 6350 | final float parentAspectRatio = (0.5f + Math.max(parentAppWidth, parentAppHeight)) |
| 6351 | / Math.min(parentAppWidth, parentAppHeight); |
| 6352 | if (parentAspectRatio <= info.minAspectRatio) { |
| 6353 | // The long side has reached the parent. |
| 6354 | return false; |
| 6355 | } |
| 6356 | } |
| 6357 | return true; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6358 | } |
| 6359 | |
| 6360 | /** |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6361 | * Indicates the activity will keep the bounds and screen configuration when it was first |
| 6362 | * launched, no matter how its parent changes. |
| 6363 | * |
| 6364 | * @return {@code true} if this activity is declared as non-resizable and fixed orientation or |
| 6365 | * aspect ratio. |
| 6366 | */ |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6367 | boolean shouldUseSizeCompatMode() { |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6368 | return !isResizeable() && (info.isFixedOrientation() || info.hasFixedAspectRatio()) |
| 6369 | // The configuration of non-standard type should be enforced by system. |
| 6370 | && isActivityTypeStandard() |
| 6371 | && !mAtmService.mForceResizableActivities; |
| 6372 | } |
| 6373 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6374 | boolean hasSizeCompatBounds() { |
| 6375 | return mSizeCompatBounds != null; |
| 6376 | } |
| 6377 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6378 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6379 | private void updateSizeCompatMode() { |
| 6380 | if (mCompatDisplayInsets != null || !shouldUseSizeCompatMode()) { |
| 6381 | // The override configuration is set only once in size compatibility mode. |
| 6382 | return; |
| 6383 | } |
| 6384 | final Configuration parentConfig = getParent().getConfiguration(); |
| 6385 | if (!hasProcess() && !isConfigurationCompatible(parentConfig)) { |
| 6386 | // Don't compute when launching in fullscreen and the fixed orientation is not the |
| 6387 | // current orientation. It is more accurately to compute the override bounds from |
| 6388 | // the updated configuration after the fixed orientation is applied. |
| 6389 | return; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 6390 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6391 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6392 | Configuration overrideConfig = getRequestedOverrideConfiguration(); |
| 6393 | final Configuration fullConfig = getConfiguration(); |
| 6394 | |
| 6395 | // Ensure the screen related fields are set. It is used to prevent activity relaunch |
| 6396 | // when moving between displays. For screenWidthDp and screenWidthDp, because they |
| 6397 | // are relative to bounds and density, they will be calculated in |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6398 | // {@link Task#computeConfigResourceOverrides} and the result will also be |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6399 | // relatively fixed. |
| 6400 | overrideConfig.colorMode = fullConfig.colorMode; |
| 6401 | overrideConfig.densityDpi = fullConfig.densityDpi; |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6402 | // The smallest screen width is the short side of screen bounds. Because the bounds |
| 6403 | // and density won't be changed, smallestScreenWidthDp is also fixed. |
| 6404 | overrideConfig.smallestScreenWidthDp = fullConfig.smallestScreenWidthDp; |
| 6405 | if (info.isFixedOrientation()) { |
| 6406 | // lock rotation too. When in size-compat, onConfigurationChanged will watch for and |
| 6407 | // apply runtime rotation changes. |
| 6408 | overrideConfig.windowConfiguration.setRotation( |
| 6409 | fullConfig.windowConfiguration.getRotation()); |
| 6410 | } |
| 6411 | |
| 6412 | // The role of CompatDisplayInsets is like the override bounds. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6413 | final DisplayContent display = getDisplay(); |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6414 | if (display != null) { |
| 6415 | mCompatDisplayInsets = new CompatDisplayInsets(display.mDisplayContent, |
| 6416 | getWindowConfiguration().getBounds(), |
| 6417 | getWindowConfiguration().tasksAreFloating()); |
| 6418 | } |
| 6419 | } |
| 6420 | |
| 6421 | private void clearSizeCompatMode() { |
| 6422 | mCompatDisplayInsets = null; |
| 6423 | onRequestedOverrideConfigurationChanged(EMPTY); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6424 | } |
| 6425 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6426 | @Override |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6427 | public boolean matchParentBounds() { |
| 6428 | if (super.matchParentBounds()) { |
| 6429 | return true; |
| 6430 | } |
| 6431 | // An activity in size compatibility mode may have override bounds which equals to its |
| 6432 | // parent bounds, so the exact bounds should also be checked. |
| 6433 | final WindowContainer parent = getParent(); |
| 6434 | return parent == null || parent.getBounds().equals(getResolvedOverrideBounds()); |
| 6435 | } |
| 6436 | |
| 6437 | @Override |
| 6438 | float getSizeCompatScale() { |
| 6439 | return hasSizeCompatBounds() ? mSizeCompatScale : super.getSizeCompatScale(); |
| 6440 | } |
| 6441 | |
| 6442 | @Override |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6443 | void resolveOverrideConfiguration(Configuration newParentConfiguration) { |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6444 | Configuration resolvedConfig = getResolvedOverrideConfiguration(); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6445 | if (mCompatDisplayInsets != null) { |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6446 | resolveSizeCompatModeConfiguration(newParentConfiguration); |
| 6447 | } else { |
| 6448 | super.resolveOverrideConfiguration(newParentConfiguration); |
Garfield Tan | 966c041 | 2019-11-19 11:34:27 -0800 | [diff] [blame] | 6449 | // We ignore activities' requested orientation in multi-window modes. Task level may |
| 6450 | // take them into consideration when calculating bounds. |
| 6451 | if (getParent() != null && getParent().inMultiWindowMode()) { |
| 6452 | resolvedConfig.orientation = Configuration.ORIENTATION_UNDEFINED; |
| 6453 | } |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6454 | applyAspectRatio(resolvedConfig.windowConfiguration.getBounds(), |
| 6455 | newParentConfiguration.windowConfiguration.getAppBounds(), |
| 6456 | newParentConfiguration.windowConfiguration.getBounds()); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6457 | // If the activity has override bounds, the relative configuration (e.g. screen size, |
| 6458 | // layout) needs to be resolved according to the bounds. |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6459 | if (task != null && !resolvedConfig.windowConfiguration.getBounds().isEmpty()) { |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6460 | task.computeConfigResourceOverrides(getResolvedOverrideConfiguration(), |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 6461 | newParentConfiguration); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6462 | } |
| 6463 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6464 | |
| 6465 | // Assign configuration sequence number into hierarchy because there is a different way than |
| 6466 | // ensureActivityConfiguration() in this class that uses configuration in WindowState during |
| 6467 | // layout traversals. |
| 6468 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 6469 | getResolvedOverrideConfiguration().seq = mConfigurationSeq; |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6470 | } |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6471 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6472 | /** |
| 6473 | * Resolves consistent screen configuration for orientation and rotation changes without |
| 6474 | * inheriting the parent bounds. |
| 6475 | */ |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6476 | private void resolveSizeCompatModeConfiguration(Configuration newParentConfiguration) { |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6477 | super.resolveOverrideConfiguration(newParentConfiguration); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6478 | final Configuration resolvedConfig = getResolvedOverrideConfiguration(); |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6479 | final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds(); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6480 | |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6481 | Rect parentBounds = new Rect(newParentConfiguration.windowConfiguration.getBounds()); |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6482 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6483 | int orientation = getRequestedConfigurationOrientation(); |
| 6484 | if (orientation == ORIENTATION_UNDEFINED) { |
| 6485 | orientation = newParentConfiguration.orientation; |
| 6486 | } |
| 6487 | int rotation = resolvedConfig.windowConfiguration.getRotation(); |
| 6488 | if (rotation == ROTATION_UNDEFINED) { |
| 6489 | rotation = newParentConfiguration.windowConfiguration.getRotation(); |
| 6490 | } |
| 6491 | |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6492 | // Use compat insets to lock width and height. We should not use the parent width and height |
| 6493 | // because apps in compat mode should have a constant width and height. The compat insets |
| 6494 | // are locked when the app is first launched and are never changed after that, so we can |
| 6495 | // rely on them to contain the original and unchanging width and height of the app. |
| 6496 | final Rect compatDisplayBounds = mTmpBounds; |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6497 | mCompatDisplayInsets.getDisplayBoundsByRotation(compatDisplayBounds, rotation); |
| 6498 | final Rect containingAppBounds = new Rect(); |
| 6499 | mCompatDisplayInsets.getFrameByOrientation(containingAppBounds, orientation); |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6500 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6501 | // Center containingAppBounds horizontally and aligned to top of parent. Both |
| 6502 | // are usually the same unless the app was frozen with an orientation letterbox. |
| 6503 | int left = compatDisplayBounds.left + compatDisplayBounds.width() / 2 |
| 6504 | - containingAppBounds.width() / 2; |
| 6505 | resolvedBounds.set(left, compatDisplayBounds.top, left + containingAppBounds.width(), |
| 6506 | compatDisplayBounds.top + containingAppBounds.height()); |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6507 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6508 | if (rotation != ROTATION_UNDEFINED) { |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6509 | // Ensure the parent and container bounds won't overlap with insets. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6510 | Task.intersectWithInsetsIfFits(containingAppBounds, compatDisplayBounds, |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6511 | mCompatDisplayInsets.mNonDecorInsets[rotation]); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6512 | Task.intersectWithInsetsIfFits(parentBounds, compatDisplayBounds, |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6513 | mCompatDisplayInsets.mNonDecorInsets[rotation]); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6514 | } |
| 6515 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6516 | applyAspectRatio(resolvedBounds, containingAppBounds, compatDisplayBounds); |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6517 | |
| 6518 | // Center horizontally in parent and align to top of parent - this is a UX choice |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6519 | left = parentBounds.left + parentBounds.width() / 2 - resolvedBounds.width() / 2; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6520 | resolvedBounds.set(left, parentBounds.top, left + resolvedBounds.width(), |
| 6521 | parentBounds.top + resolvedBounds.height()); |
| 6522 | |
| 6523 | // We want to get as much of the app on the screen even if insets cover it. This is because |
| 6524 | // insets change but an app's bounds are more permanent after launch. After computing insets |
| 6525 | // and horizontally centering resolvedBounds, the resolvedBounds may end up outside parent |
| 6526 | // bounds. This is okay only if the resolvedBounds exceed their parent on the bottom and |
| 6527 | // right, because that is clipped when the final bounds are computed. To reach this state, |
| 6528 | // we first try and push the app as much inside the parent towards the top and left (the |
| 6529 | // min). The app may then end up outside the parent by going too far left and top, so we |
| 6530 | // push it back into the parent by taking the max with parent left and top. |
| 6531 | Rect fullParentBounds = newParentConfiguration.windowConfiguration.getBounds(); |
| 6532 | resolvedBounds.offsetTo(Math.max(fullParentBounds.left, |
| 6533 | Math.min(fullParentBounds.right - resolvedBounds.width(), resolvedBounds.left)), |
| 6534 | Math.max(fullParentBounds.top, |
| 6535 | Math.min(fullParentBounds.bottom - resolvedBounds.height(), |
| 6536 | resolvedBounds.top))); |
| 6537 | |
| 6538 | // Use resolvedBounds to compute other override configurations such as appBounds |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6539 | task.computeConfigResourceOverrides(resolvedConfig, newParentConfiguration, |
| 6540 | mCompatDisplayInsets); |
Riddle Hsu | ca92856 | 2019-11-22 01:04:14 +0800 | [diff] [blame] | 6541 | // Use current screen layout as source because the size of app is independent to parent. |
| 6542 | resolvedConfig.screenLayout = Task.computeScreenLayoutOverride( |
| 6543 | getConfiguration().screenLayout, resolvedConfig.screenWidthDp, |
| 6544 | resolvedConfig.screenHeightDp); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6545 | |
Riddle Hsu | 0416418 | 2019-03-07 18:03:27 +0800 | [diff] [blame] | 6546 | // Use parent orientation if it cannot be decided by bounds, so the activity can fit inside |
| 6547 | // the parent bounds appropriately. |
| 6548 | if (resolvedConfig.screenWidthDp == resolvedConfig.screenHeightDp) { |
| 6549 | resolvedConfig.orientation = newParentConfiguration.orientation; |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 6550 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | @Override |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6554 | public Rect getBounds() { |
| 6555 | if (mSizeCompatBounds != null) { |
| 6556 | return mSizeCompatBounds; |
| 6557 | } |
| 6558 | return super.getBounds(); |
| 6559 | } |
| 6560 | |
| 6561 | @Override |
| 6562 | Rect getDisplayedBounds() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6563 | if (task != null) { |
| 6564 | final Rect overrideDisplayedBounds = task.getOverrideDisplayedBounds(); |
| 6565 | if (!overrideDisplayedBounds.isEmpty()) { |
| 6566 | return overrideDisplayedBounds; |
| 6567 | } |
| 6568 | } |
| 6569 | return getBounds(); |
| 6570 | } |
| 6571 | |
| 6572 | @VisibleForTesting |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 6573 | @Override |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6574 | Rect getAnimationBounds(int appStackClipMode) { |
| 6575 | if (appStackClipMode == STACK_CLIP_BEFORE_ANIM && getStack() != null) { |
| 6576 | // Using the stack bounds here effectively applies the clipping before animation. |
| 6577 | return getStack().getBounds(); |
| 6578 | } |
| 6579 | // Use task-bounds if available so that activity-level letterbox (maxAspectRatio) is |
| 6580 | // included in the animation. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6581 | return task != null ? task.getBounds() : getBounds(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6582 | } |
| 6583 | |
| 6584 | /** |
| 6585 | * Calculates the scale and offset to horizontal center the size compatibility bounds into the |
| 6586 | * region which is available to application. |
| 6587 | */ |
| 6588 | private void calculateCompatBoundsTransformation(Configuration newParentConfig) { |
| 6589 | final Rect parentAppBounds = newParentConfig.windowConfiguration.getAppBounds(); |
| 6590 | final Rect parentBounds = newParentConfig.windowConfiguration.getBounds(); |
| 6591 | final Rect viewportBounds = parentAppBounds != null ? parentAppBounds : parentBounds; |
| 6592 | final Rect appBounds = getWindowConfiguration().getAppBounds(); |
| 6593 | final Rect contentBounds = appBounds != null ? appBounds : getResolvedOverrideBounds(); |
| 6594 | final float contentW = contentBounds.width(); |
| 6595 | final float contentH = contentBounds.height(); |
| 6596 | final float viewportW = viewportBounds.width(); |
| 6597 | final float viewportH = viewportBounds.height(); |
| 6598 | // Only allow to scale down. |
| 6599 | mSizeCompatScale = (contentW <= viewportW && contentH <= viewportH) |
| 6600 | ? 1 : Math.min(viewportW / contentW, viewportH / contentH); |
| 6601 | final int offsetX = (int) ((viewportW - contentW * mSizeCompatScale + 1) * 0.5f) |
| 6602 | + viewportBounds.left; |
| 6603 | |
| 6604 | if (mSizeCompatBounds == null) { |
| 6605 | mSizeCompatBounds = new Rect(); |
| 6606 | } |
| 6607 | mSizeCompatBounds.set(contentBounds); |
| 6608 | mSizeCompatBounds.offsetTo(0, 0); |
| 6609 | mSizeCompatBounds.scale(mSizeCompatScale); |
| 6610 | // Ensure to align the top with the parent. |
| 6611 | mSizeCompatBounds.top = parentBounds.top; |
| 6612 | // The decor inset is included in height. |
| 6613 | mSizeCompatBounds.bottom += viewportBounds.top; |
| 6614 | mSizeCompatBounds.left += offsetX; |
| 6615 | mSizeCompatBounds.right += offsetX; |
| 6616 | } |
| 6617 | |
| 6618 | @Override |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6619 | public void onConfigurationChanged(Configuration newParentConfig) { |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6620 | if (mCompatDisplayInsets != null) { |
| 6621 | Configuration overrideConfig = getRequestedOverrideConfiguration(); |
| 6622 | // Adapt to changes in orientation locking. The app is still non-resizable, but |
| 6623 | // it can change which orientation is fixed. If the fixed orientation changes, |
| 6624 | // update the rotation used on the "compat" display |
| 6625 | boolean wasFixedOrient = |
| 6626 | overrideConfig.windowConfiguration.getRotation() != ROTATION_UNDEFINED; |
| 6627 | int requestedOrient = getRequestedConfigurationOrientation(); |
| 6628 | if (requestedOrient != ORIENTATION_UNDEFINED |
| 6629 | && requestedOrient != getConfiguration().orientation |
| 6630 | // The task orientation depends on the top activity orientation, so it |
| 6631 | // should match. If it doesn't, just wait until it does. |
| 6632 | && requestedOrient == getParent().getConfiguration().orientation |
| 6633 | && (overrideConfig.windowConfiguration.getRotation() |
| 6634 | != getParent().getWindowConfiguration().getRotation())) { |
| 6635 | overrideConfig.windowConfiguration.setRotation( |
| 6636 | getParent().getWindowConfiguration().getRotation()); |
| 6637 | onRequestedOverrideConfigurationChanged(overrideConfig); |
| 6638 | return; |
| 6639 | } else if (wasFixedOrient && requestedOrient == ORIENTATION_UNDEFINED |
| 6640 | && (overrideConfig.windowConfiguration.getRotation() |
| 6641 | != ROTATION_UNDEFINED)) { |
| 6642 | overrideConfig.windowConfiguration.setRotation(ROTATION_UNDEFINED); |
| 6643 | onRequestedOverrideConfigurationChanged(overrideConfig); |
| 6644 | return; |
| 6645 | } |
| 6646 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6647 | final int prevWinMode = getWindowingMode(); |
| 6648 | mTmpPrevBounds.set(getBounds()); |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6649 | super.onConfigurationChanged(newParentConfig); |
| 6650 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6651 | final Rect overrideBounds = getResolvedOverrideBounds(); |
| 6652 | if (task != null && !overrideBounds.isEmpty() |
| 6653 | // If the changes come from change-listener, the incoming parent configuration is |
| 6654 | // still the old one. Make sure their orientations are the same to reduce computing |
| 6655 | // the compatibility bounds for the intermediate state. |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 6656 | && (task.getConfiguration().orientation == newParentConfig.orientation)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6657 | final Rect taskBounds = task.getBounds(); |
| 6658 | // Since we only center the activity horizontally, if only the fixed height is smaller |
| 6659 | // than its container, the override bounds don't need to take effect. |
| 6660 | if ((overrideBounds.width() != taskBounds.width() |
| 6661 | || overrideBounds.height() > taskBounds.height())) { |
| 6662 | calculateCompatBoundsTransformation(newParentConfig); |
| 6663 | updateSurfacePosition(); |
| 6664 | } else if (mSizeCompatBounds != null) { |
| 6665 | mSizeCompatBounds = null; |
| 6666 | mSizeCompatScale = 1f; |
| 6667 | updateSurfacePosition(); |
| 6668 | } |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6669 | } else if (overrideBounds.isEmpty()) { |
| 6670 | mSizeCompatBounds = null; |
| 6671 | mSizeCompatScale = 1f; |
| 6672 | updateSurfacePosition(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6673 | } |
| 6674 | |
Hongwei Wang | e75e191 | 2019-11-07 16:00:32 -0800 | [diff] [blame] | 6675 | final int newWinMode = getWindowingMode(); |
| 6676 | if ((prevWinMode != newWinMode) && (mDisplayContent != null) |
| 6677 | && shouldStartChangeTransition(prevWinMode, newWinMode)) { |
| 6678 | initializeChangeTransition(mTmpPrevBounds); |
| 6679 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6680 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6681 | // Configuration's equality doesn't consider seq so if only seq number changes in resolved |
| 6682 | // override configuration. Therefore ConfigurationContainer doesn't change merged override |
| 6683 | // configuration, but it's used to push configuration changes so explicitly update that. |
| 6684 | if (getMergedOverrideConfiguration().seq != getResolvedOverrideConfiguration().seq) { |
| 6685 | onMergedOverrideConfigurationChanged(); |
| 6686 | } |
| 6687 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6688 | final DisplayContent display = getDisplay(); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 6689 | if (display == null) { |
| 6690 | return; |
| 6691 | } |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 6692 | if (mVisibleRequested) { |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 6693 | // 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] | 6694 | display.handleActivitySizeCompatModeIfNeeded(this); |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6695 | } else if (mCompatDisplayInsets != null) { |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 6696 | // The override changes can only be obtained from display, because we don't have the |
| 6697 | // difference of full configuration in each hierarchy. |
Riddle Hsu | 7f704b5 | 2019-12-10 23:10:45 +0800 | [diff] [blame] | 6698 | final int displayChanges = display.getCurrentOverrideConfigurationChanges(); |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 6699 | final int orientationChanges = CONFIG_WINDOW_CONFIGURATION |
| 6700 | | CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION; |
| 6701 | final boolean hasNonOrienSizeChanged = hasResizeChange(displayChanges) |
| 6702 | // Filter out the case of simple orientation change. |
| 6703 | && (displayChanges & orientationChanges) != orientationChanges; |
| 6704 | // For background activity that uses size compatibility mode, if the size or density of |
| 6705 | // the display is changed, then reset the override configuration and kill the activity's |
| 6706 | // process if its process state is not important to user. |
| 6707 | if (hasNonOrienSizeChanged || (displayChanges & ActivityInfo.CONFIG_DENSITY) != 0) { |
| 6708 | restartProcessIfVisible(); |
| 6709 | } |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6710 | } |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 6711 | } |
| 6712 | |
Hongwei Wang | e75e191 | 2019-11-07 16:00:32 -0800 | [diff] [blame] | 6713 | void savePinnedStackBounds() { |
| 6714 | // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds |
| 6715 | // for the next re-entry into PiP (assuming the activity is not hidden or destroyed) |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 6716 | final ActivityStack pinnedStack = mDisplayContent.getPinnedStack(); |
Hongwei Wang | e75e191 | 2019-11-07 16:00:32 -0800 | [diff] [blame] | 6717 | if (pinnedStack == null) return; |
| 6718 | final Rect stackBounds; |
| 6719 | if (pinnedStack.lastAnimatingBoundsWasToFullscreen()) { |
| 6720 | // We are animating the bounds, use the pre-animation bounds to save the snap |
| 6721 | // fraction |
| 6722 | stackBounds = pinnedStack.mPreAnimationBounds; |
| 6723 | } else { |
| 6724 | // We skip the animation if the fullscreen configuration is not compatible, so |
| 6725 | // use the current bounds to calculate the saved snap fraction instead |
| 6726 | // (see PinnedActivityStack.skipResizeAnimation()) |
| 6727 | stackBounds = mTmpRect; |
| 6728 | pinnedStack.getBounds(stackBounds); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6729 | } |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame] | 6730 | mDisplayContent.mPinnedStackControllerLocked.saveReentryBounds( |
Hongwei Wang | e75e191 | 2019-11-07 16:00:32 -0800 | [diff] [blame] | 6731 | mActivityComponent, stackBounds); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 6732 | } |
| 6733 | |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 6734 | /** Returns true if the configuration is compatible with this activity. */ |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 6735 | boolean isConfigurationCompatible(Configuration config) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 6736 | final int orientation = getRequestedOrientation(); |
Wale Ogunwale | d4b1d1e | 2017-04-10 06:35:59 -0700 | [diff] [blame] | 6737 | if (isFixedOrientationPortrait(orientation) |
| 6738 | && config.orientation != ORIENTATION_PORTRAIT) { |
| 6739 | return false; |
| 6740 | } |
| 6741 | if (isFixedOrientationLandscape(orientation) |
| 6742 | && config.orientation != ORIENTATION_LANDSCAPE) { |
| 6743 | return false; |
| 6744 | } |
| 6745 | return true; |
| 6746 | } |
| 6747 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 6748 | /** |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 6749 | * Applies aspect ratio restrictions to outBounds. If no restrictions, then no change is |
| 6750 | * made to outBounds. |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 6751 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6752 | // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer. |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6753 | private void applyAspectRatio(Rect outBounds, Rect containingAppBounds, |
| 6754 | Rect containingBounds) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6755 | final float maxAspectRatio = info.maxAspectRatio; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6756 | final ActivityStack stack = getActivityStack(); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 6757 | final float minAspectRatio = info.minAspectRatio; |
| 6758 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6759 | if (task == null || stack == null || (inMultiWindowMode() && !shouldUseSizeCompatMode()) |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 6760 | || (maxAspectRatio == 0 && minAspectRatio == 0) |
Bryce Lee | e5ab450 | 2017-07-11 08:58:05 -0700 | [diff] [blame] | 6761 | || isInVrUiMode(getConfiguration())) { |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6762 | // We don't enforce aspect ratio if the activity task is in multiwindow unless it |
| 6763 | // is in size-compat mode. We also don't set it if we are in VR mode. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6764 | return; |
| 6765 | } |
| 6766 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6767 | final int containingAppWidth = containingAppBounds.width(); |
| 6768 | final int containingAppHeight = containingAppBounds.height(); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 6769 | final float containingRatio = Math.max(containingAppWidth, containingAppHeight) |
| 6770 | / (float) Math.min(containingAppWidth, containingAppHeight); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 6771 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 6772 | int activityWidth = containingAppWidth; |
| 6773 | int activityHeight = containingAppHeight; |
| 6774 | |
| 6775 | if (containingRatio > maxAspectRatio && maxAspectRatio != 0) { |
| 6776 | if (containingAppWidth < containingAppHeight) { |
| 6777 | // Width is the shorter side, so we use that to figure-out what the max. height |
| 6778 | // should be given the aspect ratio. |
| 6779 | activityHeight = (int) ((activityWidth * maxAspectRatio) + 0.5f); |
| 6780 | } else { |
| 6781 | // Height is the shorter side, so we use that to figure-out what the max. width |
| 6782 | // should be given the aspect ratio. |
| 6783 | activityWidth = (int) ((activityHeight * maxAspectRatio) + 0.5f); |
| 6784 | } |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 6785 | } else if (containingRatio < minAspectRatio) { |
| 6786 | boolean adjustWidth; |
| 6787 | switch (getRequestedConfigurationOrientation()) { |
| 6788 | case ORIENTATION_LANDSCAPE: |
| 6789 | // Width should be the longer side for this landscape app, so we use the width |
| 6790 | // to figure-out what the max. height should be given the aspect ratio. |
| 6791 | adjustWidth = false; |
| 6792 | break; |
| 6793 | case ORIENTATION_PORTRAIT: |
| 6794 | // Height should be the longer side for this portrait app, so we use the height |
| 6795 | // to figure-out what the max. width should be given the aspect ratio. |
| 6796 | adjustWidth = true; |
| 6797 | break; |
| 6798 | default: |
| 6799 | // This app doesn't have a preferred orientation, so we keep the length of the |
| 6800 | // longer side, and use it to figure-out the length of the shorter side. |
| 6801 | if (containingAppWidth < containingAppHeight) { |
| 6802 | // Width is the shorter side, so we use the height to figure-out what the |
| 6803 | // max. width should be given the aspect ratio. |
| 6804 | adjustWidth = true; |
| 6805 | } else { |
| 6806 | // Height is the shorter side, so we use the width to figure-out what the |
| 6807 | // max. height should be given the aspect ratio. |
| 6808 | adjustWidth = false; |
| 6809 | } |
| 6810 | break; |
| 6811 | } |
| 6812 | if (adjustWidth) { |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 6813 | activityWidth = (int) ((activityHeight / minAspectRatio) + 0.5f); |
| 6814 | } else { |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 6815 | activityHeight = (int) ((activityWidth / minAspectRatio) + 0.5f); |
| 6816 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6817 | } |
| 6818 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 6819 | if (containingAppWidth <= activityWidth && containingAppHeight <= activityHeight) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6820 | // The display matches or is less than the activity aspect ratio, so nothing else to do. |
| 6821 | return; |
| 6822 | } |
| 6823 | |
| 6824 | // Compute configuration based on max supported width and height. |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 6825 | // Also account for the left / top insets (e.g. from display cutouts), which will be clipped |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6826 | // away later in {@link Task#computeConfigResourceOverrides()}. Otherwise, the app |
Adrian Roos | 24be34d | 2018-05-28 18:55:38 +0200 | [diff] [blame] | 6827 | // bounds would end up too small. |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6828 | outBounds.set(containingBounds.left, containingBounds.top, |
| 6829 | activityWidth + containingAppBounds.left, |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 6830 | activityHeight + containingAppBounds.top); |
Andrii Kulian | 3a1619d | 2017-07-07 14:38:09 -0700 | [diff] [blame] | 6831 | } |
| 6832 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 6833 | /** |
| 6834 | * @return {@code true} if this activity was reparented to another display but |
| 6835 | * {@link #ensureActivityConfiguration} is not called. |
| 6836 | */ |
| 6837 | boolean shouldUpdateConfigForDisplayChanged() { |
| 6838 | return mLastReportedDisplayId != getDisplayId(); |
| 6839 | } |
| 6840 | |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 6841 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow) { |
| 6842 | return ensureActivityConfiguration(globalChanges, preserveWindow, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 6843 | false /* ignoreVisibility */); |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 6844 | } |
| 6845 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6846 | /** |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 6847 | * Make sure the given activity matches the current configuration. Ensures the HistoryRecord |
| 6848 | * is updated with the correct configuration and all other bookkeeping is handled. |
| 6849 | * |
| 6850 | * @param globalChanges The changes to the global configuration. |
| 6851 | * @param preserveWindow If the activity window should be preserved on screen if the activity |
| 6852 | * is relaunched. |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 6853 | * @param ignoreVisibility If we should try to relaunch the activity even if it is invisible |
| 6854 | * (stopped state). This is useful for the case where we know the |
| 6855 | * activity will be visible soon and we want to ensure its configuration |
| 6856 | * before we make it visible. |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 6857 | * @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] | 6858 | * can't or the app handles the specific configuration that is changing. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6859 | */ |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 6860 | boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 6861 | boolean ignoreVisibility) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6862 | final ActivityStack stack = getActivityStack(); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6863 | if (stack.mConfigWillChange) { |
| 6864 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6865 | "Skipping config check (will change): " + this); |
| 6866 | return true; |
| 6867 | } |
| 6868 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6869 | // We don't worry about activities that are finishing. |
| 6870 | if (finishing) { |
| 6871 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6872 | "Configuration doesn't matter in finishing " + this); |
| 6873 | stopFreezingScreenLocked(false); |
| 6874 | return true; |
| 6875 | } |
| 6876 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 6877 | if (!ignoreVisibility && (mState == STOPPING || mState == STOPPED || !shouldBeVisible())) { |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 6878 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 6879 | "Skipping config check invisible: " + this); |
Wale Ogunwale | 9b7a827 | 2017-04-10 08:05:41 -0700 | [diff] [blame] | 6880 | return true; |
| 6881 | } |
| 6882 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6883 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6884 | "Ensuring correct configuration: " + this); |
| 6885 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6886 | final int newDisplayId = getDisplayId(); |
| 6887 | final boolean displayChanged = mLastReportedDisplayId != newDisplayId; |
| 6888 | if (displayChanged) { |
| 6889 | mLastReportedDisplayId = newDisplayId; |
| 6890 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6891 | // TODO(b/36505427): Is there a better place to do this? |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 6892 | updateSizeCompatMode(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6893 | |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 6894 | // Short circuit: if the two full configurations are equal (the common case), then there is |
| 6895 | // nothing to do. We test the full configuration instead of the global and merged override |
| 6896 | // configurations because there are cases (like moving a task to the pinned stack) where |
| 6897 | // 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] | 6898 | mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration()); |
| 6899 | if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6900 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6901 | "Configuration & display unchanged in " + this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6902 | return true; |
| 6903 | } |
| 6904 | |
| 6905 | // Okay we now are going to make this activity have the new config. |
| 6906 | // 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] | 6907 | |
| 6908 | // Find changes between last reported merged configuration and the current one. This is used |
| 6909 | // 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] | 6910 | final int changes = getConfigurationChanges(mTmpConfig); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 6911 | |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 6912 | // Update last reported values. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6913 | final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration(); |
Bryce Lee | 8104e7a | 2017-08-17 09:16:03 -0700 | [diff] [blame] | 6914 | |
Andrii Kulian | beadacc | 2019-05-20 12:18:01 +0000 | [diff] [blame] | 6915 | setLastReportedConfiguration(mAtmService.getGlobalConfiguration(), newMergedOverrideConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6916 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 6917 | if (mState == INITIALIZING) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 6918 | // No need to relaunch or schedule new config for activity that hasn't been launched |
| 6919 | // yet. We do, however, return after applying the config to activity record, so that |
| 6920 | // it will use it for launch transaction. |
| 6921 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6922 | "Skipping config check for initializing activity: " + this); |
| 6923 | return true; |
| 6924 | } |
| 6925 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6926 | if (changes == 0 && !forceNewConfig) { |
| 6927 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6928 | "Configuration no differences in " + this); |
| 6929 | // There are no significant differences, so we won't relaunch but should still deliver |
| 6930 | // the new configuration to the client process. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6931 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6932 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6933 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 6934 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6935 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6936 | return true; |
| 6937 | } |
| 6938 | |
| 6939 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 6940 | "Configuration changes for " + this + ", allChanges=" |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6941 | + Configuration.configurationDiffToString(changes)); |
| 6942 | |
| 6943 | // If the activity isn't currently running, just leave the new configuration and it will |
| 6944 | // pick that up next time it starts. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6945 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6946 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6947 | "Configuration doesn't matter not running " + this); |
| 6948 | stopFreezingScreenLocked(false); |
| 6949 | forceNewConfig = false; |
| 6950 | return true; |
| 6951 | } |
| 6952 | |
| 6953 | // Figure out how to handle the changes between the configurations. |
| 6954 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6955 | "Checking to restart " + info.name + ": changed=0x" |
| 6956 | + Integer.toHexString(changes) + ", handles=0x" |
| 6957 | + Integer.toHexString(info.getRealConfigChanged()) |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 6958 | + ", mLastReportedConfiguration=" + mLastReportedConfiguration); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6959 | |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 6960 | if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6961 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 6962 | configChangeFlags |= changes; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 6963 | startFreezingScreenLocked(globalChanges); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6964 | forceNewConfig = false; |
| 6965 | preserveWindow &= isResizeOnlyChange(changes); |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 6966 | final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged()); |
| 6967 | if (hasResizeChange) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6968 | final boolean isDragResizing = task.isDragResizing(); |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 6969 | mRelaunchReason = isDragResizing ? RELAUNCH_REASON_FREE_RESIZE |
| 6970 | : RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
| 6971 | } else { |
| 6972 | mRelaunchReason = RELAUNCH_REASON_NONE; |
| 6973 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6974 | if (!attachedToProcess()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6975 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6976 | "Config is destroying non-running " + this); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 6977 | destroyImmediately(true /* removeFromApp */, "config"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 6978 | } else if (mState == PAUSING) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6979 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 6980 | // do anything now, but just flag that it needs to be restarted when done pausing. |
| 6981 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 6982 | "Config is skipping already pausing " + this); |
| 6983 | deferRelaunchUntilPaused = true; |
| 6984 | preserveWindowOnDeferredRelaunch = preserveWindow; |
| 6985 | return true; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6986 | } else { |
| 6987 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
wilsonshih | b5d8f8b | 2019-10-23 13:01:40 +0800 | [diff] [blame] | 6988 | "Config is relaunching " + this); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 6989 | if (DEBUG_STATES && !mVisibleRequested) { |
wilsonshih | b5d8f8b | 2019-10-23 13:01:40 +0800 | [diff] [blame] | 6990 | Slog.v(TAG_STATES, "Config is relaunching invisible activity " + this |
| 6991 | + " called by " + Debug.getCallers(4)); |
| 6992 | } |
| 6993 | relaunchActivityLocked(preserveWindow); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 6994 | } |
| 6995 | |
| 6996 | // All done... tell the caller we weren't able to keep this activity around. |
| 6997 | return false; |
| 6998 | } |
| 6999 | |
| 7000 | // 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] | 7001 | // NOTE: We only forward the override configuration as the system level configuration |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7002 | // changes is always sent to all processes when they happen so it can just use whatever |
| 7003 | // system level configuration it last got. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 7004 | if (displayChanged) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7005 | scheduleActivityMovedToDisplay(newDisplayId, newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 7006 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7007 | scheduleConfigurationChanged(newMergedOverrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 7008 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7009 | stopFreezingScreenLocked(false); |
| 7010 | |
| 7011 | return true; |
| 7012 | } |
| 7013 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7014 | /** |
| 7015 | * When assessing a configuration change, decide if the changes flags and the new configurations |
| 7016 | * should cause the Activity to relaunch. |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 7017 | * |
| 7018 | * @param changes the changes due to the given configuration. |
| 7019 | * @param changesConfig the configuration that was used to calculate the given changes via a |
| 7020 | * call to getConfigurationChanges. |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7021 | */ |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 7022 | private boolean shouldRelaunchLocked(int changes, Configuration changesConfig) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7023 | int configChanged = info.getRealConfigChanged(); |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 7024 | boolean onlyVrUiModeChanged = onlyVrUiModeChanged(changes, changesConfig); |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7025 | |
| 7026 | // Override for apps targeting pre-O sdks |
| 7027 | // If a device is in VR mode, and we're transitioning into VR ui mode, add ignore ui mode |
| 7028 | // to the config change. |
| 7029 | // For O and later, apps will be required to add configChanges="uimode" to their manifest. |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 7030 | if (info.applicationInfo.targetSdkVersion < O |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7031 | && requestedVrComponent != null |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 7032 | && onlyVrUiModeChanged) { |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7033 | configChanged |= CONFIG_UI_MODE; |
| 7034 | } |
| 7035 | |
| 7036 | return (changes&(~configChanged)) != 0; |
| 7037 | } |
| 7038 | |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 7039 | /** |
| 7040 | * Returns true if the configuration change is solely due to the UI mode switching into or out |
| 7041 | * of UI_MODE_TYPE_VR_HEADSET. |
| 7042 | */ |
| 7043 | private boolean onlyVrUiModeChanged(int changes, Configuration lastReportedConfig) { |
| 7044 | final Configuration currentConfig = getConfiguration(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7045 | return changes == CONFIG_UI_MODE && (isInVrUiMode(currentConfig) |
Ruben Brunk | f64af33 | 2017-03-22 22:03:25 -0700 | [diff] [blame] | 7046 | != isInVrUiMode(lastReportedConfig)); |
| 7047 | } |
| 7048 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7049 | private int getConfigurationChanges(Configuration lastReportedConfig) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7050 | // Determine what has changed. May be nothing, if this is a config that has come back from |
| 7051 | // the app after going idle. In that case we just want to leave the official config object |
| 7052 | // now in the activity and do nothing else. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7053 | final Configuration currentConfig = getConfiguration(); |
| 7054 | int changes = lastReportedConfig.diff(currentConfig); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7055 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 7056 | // the app. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7057 | if ((changes & CONFIG_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 7058 | final boolean crosses = crossesHorizontalSizeThreshold(lastReportedConfig.screenWidthDp, |
| 7059 | currentConfig.screenWidthDp) |
| 7060 | || crossesVerticalSizeThreshold(lastReportedConfig.screenHeightDp, |
| 7061 | currentConfig.screenHeightDp); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7062 | if (!crosses) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7063 | changes &= ~CONFIG_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7064 | } |
| 7065 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7066 | if ((changes & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Andrii Kulian | b43be0a | 2017-03-02 17:29:40 -0800 | [diff] [blame] | 7067 | final int oldSmallest = lastReportedConfig.smallestScreenWidthDp; |
| 7068 | final int newSmallest = currentConfig.smallestScreenWidthDp; |
| 7069 | if (!crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7070 | changes &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7071 | } |
| 7072 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 7073 | // We don't want window configuration to cause relaunches. |
| 7074 | if ((changes & CONFIG_WINDOW_CONFIGURATION) != 0) { |
| 7075 | changes &= ~CONFIG_WINDOW_CONFIGURATION; |
| 7076 | } |
Bryce Lee | 600dadd | 2017-07-25 10:48:42 -0700 | [diff] [blame] | 7077 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 7078 | return changes; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7079 | } |
| 7080 | |
| 7081 | private static boolean isResizeOnlyChange(int change) { |
| 7082 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 7083 | | CONFIG_SCREEN_LAYOUT)) == 0; |
| 7084 | } |
| 7085 | |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 7086 | private static boolean hasResizeChange(int change) { |
| 7087 | return (change & (CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 7088 | | CONFIG_SCREEN_LAYOUT)) != 0; |
| 7089 | } |
| 7090 | |
wilsonshih | b5d8f8b | 2019-10-23 13:01:40 +0800 | [diff] [blame] | 7091 | void relaunchActivityLocked(boolean preserveWindow) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 7092 | if (mAtmService.mSuppressResizeConfigChanges && preserveWindow) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7093 | configChangeFlags = 0; |
| 7094 | return; |
| 7095 | } |
| 7096 | |
wilsonshih | b5d8f8b | 2019-10-23 13:01:40 +0800 | [diff] [blame] | 7097 | final boolean andResume = shouldBeResumed(null /*activeActivity*/); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7098 | List<ResultInfo> pendingResults = null; |
| 7099 | List<ReferrerIntent> pendingNewIntents = null; |
| 7100 | if (andResume) { |
| 7101 | pendingResults = results; |
| 7102 | pendingNewIntents = newIntents; |
| 7103 | } |
| 7104 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 7105 | "Relaunching: " + this + " with results=" + pendingResults |
| 7106 | + " newIntents=" + pendingNewIntents + " andResume=" + andResume |
| 7107 | + " preserveWindow=" + preserveWindow); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 7108 | if (andResume) { |
| 7109 | EventLogTags.writeWmRelaunchResumeActivity(mUserId, System.identityHashCode(this), |
| 7110 | task.mTaskId, shortComponentName); |
| 7111 | } else { |
| 7112 | EventLogTags.writeWmRelaunchActivity(mUserId, System.identityHashCode(this), |
| 7113 | task.mTaskId, shortComponentName); |
| 7114 | } |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7115 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7116 | startFreezingScreenLocked(0); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7117 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7118 | try { |
| 7119 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 7120 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this |
| 7121 | + " callers=" + Debug.getCallers(6)); |
| 7122 | forceNewConfig = false; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7123 | startRelaunching(); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 7124 | final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(pendingResults, |
| 7125 | pendingNewIntents, configChangeFlags, |
Andrii Kulian | beadacc | 2019-05-20 12:18:01 +0000 | [diff] [blame] | 7126 | new MergedConfiguration(mAtmService.getGlobalConfiguration(), |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 7127 | getMergedOverrideConfiguration()), |
| 7128 | preserveWindow); |
| 7129 | final ActivityLifecycleItem lifecycleItem; |
| 7130 | if (andResume) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 7131 | lifecycleItem = ResumeActivityItem.obtain( |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 7132 | getDisplay().mDisplayContent.isNextTransitionForward()); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 7133 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 7134 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 7135 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 7136 | final ClientTransaction transaction = ClientTransaction.obtain(app.getThread(), appToken); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 7137 | transaction.addCallback(callbackItem); |
| 7138 | transaction.setLifecycleStateRequest(lifecycleItem); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 7139 | mAtmService.getLifecycleManager().scheduleTransaction(transaction); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7140 | // 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] | 7141 | // 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] | 7142 | // sleeping. |
| 7143 | } catch (RemoteException e) { |
| 7144 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
| 7145 | } |
| 7146 | |
| 7147 | if (andResume) { |
| 7148 | if (DEBUG_STATES) { |
| 7149 | Slog.d(TAG_STATES, "Resumed after relaunch " + this); |
| 7150 | } |
| 7151 | results = null; |
| 7152 | newIntents = null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 7153 | mAtmService.getAppWarningsLocked().onResumeActivity(this); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7154 | } else { |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 7155 | removePauseTimeout(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 7156 | setState(PAUSED, "relaunchActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 7157 | } |
| 7158 | |
| 7159 | configChangeFlags = 0; |
| 7160 | deferRelaunchUntilPaused = false; |
| 7161 | preserveWindowOnDeferredRelaunch = false; |
| 7162 | } |
| 7163 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 7164 | /** |
| 7165 | * Request the process of the activity to restart with its saved state (from |
| 7166 | * {@link android.app.Activity#onSaveInstanceState}) if possible. It also forces to recompute |
| 7167 | * the override configuration. Note if the activity is in background, the process will be killed |
| 7168 | * directly with keeping its record. |
| 7169 | */ |
| 7170 | void restartProcessIfVisible() { |
| 7171 | Slog.i(TAG, "Request to restart process of " + this); |
| 7172 | |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 7173 | // Reset the existing override configuration so it can be updated according to the latest |
| 7174 | // configuration. |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 7175 | clearSizeCompatMode(); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 7176 | if (mVisibleRequested) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 7177 | // Configuration will be ensured when becoming visible, so if it is already visible, |
| 7178 | // then the manual update is needed. |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 7179 | updateSizeCompatMode(); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 7180 | } |
| 7181 | |
| 7182 | if (!attachedToProcess()) { |
| 7183 | return; |
| 7184 | } |
| 7185 | |
| 7186 | // The restarting state avoids removing this record when process is died. |
| 7187 | setState(RESTARTING_PROCESS, "restartActivityProcess"); |
| 7188 | |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 7189 | if (!mVisibleRequested || mHaveState) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 7190 | // Kill its process immediately because the activity should be in background. |
| 7191 | // The activity state will be update to {@link #DESTROYED} in |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 7192 | // {@link ActivityStack#cleanUp} when handling process died. |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 7193 | mAtmService.mH.post(() -> { |
| 7194 | final WindowProcessController wpc; |
| 7195 | synchronized (mAtmService.mGlobalLock) { |
| 7196 | if (!hasProcess() |
| 7197 | || app.getReportedProcState() <= PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 7198 | return; |
| 7199 | } |
| 7200 | wpc = app; |
| 7201 | } |
| 7202 | mAtmService.mAmInternal.killProcess(wpc.mName, wpc.mUid, "resetConfig"); |
| 7203 | }); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 7204 | return; |
| 7205 | } |
| 7206 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7207 | if (getParent() != null) { |
| 7208 | startFreezingScreen(); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 7209 | } |
| 7210 | // The process will be killed until the activity reports stopped with saved state (see |
| 7211 | // {@link ActivityTaskManagerService.activityStopped}). |
| 7212 | try { |
| 7213 | mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken, |
| 7214 | StopActivityItem.obtain(false /* showWindow */, 0 /* configChanges */)); |
| 7215 | } catch (RemoteException e) { |
| 7216 | Slog.w(TAG, "Exception thrown during restart " + this, e); |
| 7217 | } |
| 7218 | mStackSupervisor.scheduleRestartTimeout(this); |
| 7219 | } |
| 7220 | |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 7221 | boolean isProcessRunning() { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 7222 | WindowProcessController proc = app; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 7223 | if (proc == null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 7224 | proc = mAtmService.mProcessNames.get(processName, info.applicationInfo.uid); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 7225 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 7226 | return proc != null && proc.hasThread(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 7227 | } |
| 7228 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 7229 | /** |
| 7230 | * @return Whether a task snapshot starting window may be shown. |
| 7231 | */ |
| 7232 | private boolean allowTaskSnapshot() { |
| 7233 | if (newIntents == null) { |
| 7234 | return true; |
| 7235 | } |
| 7236 | |
Louis Chang | 746c224 | 2019-10-08 16:30:44 +0800 | [diff] [blame] | 7237 | // Restrict task snapshot starting window to launcher start, or is same as the last |
| 7238 | // delivered intent, or there is no intent at all (eg. task being brought to front). If |
| 7239 | // the intent is something else, likely the app is going to show some specific page or |
| 7240 | // view, instead of what's left last time. |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 7241 | for (int i = newIntents.size() - 1; i >= 0; i--) { |
| 7242 | final Intent intent = newIntents.get(i); |
Louis Chang | 746c224 | 2019-10-08 16:30:44 +0800 | [diff] [blame] | 7243 | if (intent == null || ActivityRecord.isMainIntent(intent)) { |
| 7244 | continue; |
| 7245 | } |
| 7246 | |
| 7247 | final boolean sameIntent = mLastNewIntent != null ? mLastNewIntent.filterEquals(intent) |
| 7248 | : this.intent.filterEquals(intent); |
| 7249 | if (!sameIntent || intent.getExtras() != null) { |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 7250 | return false; |
| 7251 | } |
| 7252 | } |
| 7253 | return true; |
| 7254 | } |
| 7255 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 7256 | /** |
| 7257 | * Returns {@code true} if the associated activity has the no history flag set on it. |
| 7258 | * {@code false} otherwise. |
| 7259 | */ |
| 7260 | boolean isNoHistory() { |
| 7261 | return (intent.getFlags() & FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 7262 | || (info.flags & FLAG_NO_HISTORY) != 0; |
| 7263 | } |
| 7264 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7265 | void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException { |
| 7266 | out.attribute(null, ATTR_ID, String.valueOf(createTime)); |
| 7267 | out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid)); |
| 7268 | if (launchedFromPackage != null) { |
| 7269 | out.attribute(null, ATTR_LAUNCHEDFROMPACKAGE, launchedFromPackage); |
| 7270 | } |
| 7271 | if (resolvedType != null) { |
| 7272 | out.attribute(null, ATTR_RESOLVEDTYPE, resolvedType); |
| 7273 | } |
| 7274 | out.attribute(null, ATTR_COMPONENTSPECIFIED, String.valueOf(componentSpecified)); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 7275 | out.attribute(null, ATTR_USERID, String.valueOf(mUserId)); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 7276 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7277 | if (taskDescription != null) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 7278 | taskDescription.saveToXml(out); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7279 | } |
| 7280 | |
| 7281 | out.startTag(null, TAG_INTENT); |
| 7282 | intent.saveToXml(out); |
| 7283 | out.endTag(null, TAG_INTENT); |
| 7284 | |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 7285 | if (isPersistable() && mPersistentState != null) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7286 | out.startTag(null, TAG_PERSISTABLEBUNDLE); |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 7287 | mPersistentState.saveToXml(out); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7288 | out.endTag(null, TAG_PERSISTABLEBUNDLE); |
| 7289 | } |
| 7290 | } |
| 7291 | |
Stefan Kuhne | e88d1e5 | 2015-05-18 10:33:45 -0700 | [diff] [blame] | 7292 | static ActivityRecord restoreFromXml(XmlPullParser in, |
| 7293 | ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7294 | Intent intent = null; |
| 7295 | PersistableBundle persistentState = null; |
| 7296 | int launchedFromUid = 0; |
| 7297 | String launchedFromPackage = null; |
| 7298 | String resolvedType = null; |
| 7299 | boolean componentSpecified = false; |
| 7300 | int userId = 0; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7301 | long createTime = -1; |
| 7302 | final int outerDepth = in.getDepth(); |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 7303 | TaskDescription taskDescription = new TaskDescription(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7304 | |
| 7305 | for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) { |
| 7306 | final String attrName = in.getAttributeName(attrNdx); |
| 7307 | final String attrValue = in.getAttributeValue(attrNdx); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7308 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 7309 | "ActivityRecord: attribute name=" + attrName + " value=" + attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7310 | if (ATTR_ID.equals(attrName)) { |
Tobias Thierer | 28532d0 | 2016-04-21 14:52:10 +0100 | [diff] [blame] | 7311 | createTime = Long.parseLong(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7312 | } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 7313 | launchedFromUid = Integer.parseInt(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7314 | } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) { |
| 7315 | launchedFromPackage = attrValue; |
| 7316 | } else if (ATTR_RESOLVEDTYPE.equals(attrName)) { |
| 7317 | resolvedType = attrValue; |
| 7318 | } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) { |
Tobias Thierer | b0800dc | 2016-04-21 17:51:41 +0100 | [diff] [blame] | 7319 | componentSpecified = Boolean.parseBoolean(attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7320 | } else if (ATTR_USERID.equals(attrName)) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 7321 | userId = Integer.parseInt(attrValue); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7322 | } else if (attrName.startsWith(ATTR_TASKDESCRIPTION_PREFIX)) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 7323 | taskDescription.restoreFromXml(attrName, attrValue); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7324 | } else { |
| 7325 | Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName); |
| 7326 | } |
| 7327 | } |
| 7328 | |
| 7329 | int event; |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7330 | while (((event = in.next()) != END_DOCUMENT) && |
| 7331 | (event != END_TAG || in.getDepth() >= outerDepth)) { |
| 7332 | if (event == START_TAG) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7333 | final String name = in.getName(); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7334 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 7335 | Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7336 | if (TAG_INTENT.equals(name)) { |
| 7337 | intent = Intent.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7338 | if (DEBUG) |
Wale Ogunwale | 18795a2 | 2014-12-03 11:38:33 -0800 | [diff] [blame] | 7339 | Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7340 | } else if (TAG_PERSISTABLEBUNDLE.equals(name)) { |
| 7341 | persistentState = PersistableBundle.restoreFromXml(in); |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7342 | if (DEBUG) Slog.d(TaskPersister.TAG, |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7343 | "ActivityRecord: persistentState=" + persistentState); |
| 7344 | } else { |
| 7345 | Slog.w(TAG, "restoreActivity: unexpected name=" + name); |
| 7346 | XmlUtils.skipCurrentTag(in); |
| 7347 | } |
| 7348 | } |
| 7349 | } |
| 7350 | |
| 7351 | if (intent == null) { |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 7352 | throw new XmlPullParserException("restoreActivity error intent=" + intent); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7353 | } |
| 7354 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 7355 | final ActivityTaskManagerService service = stackSupervisor.mService; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7356 | final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 7357 | userId, Binder.getCallingUid()); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 7358 | if (aInfo == null) { |
Craig Mautner | 77b0426 | 2014-06-27 15:22:12 -0700 | [diff] [blame] | 7359 | throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent + |
| 7360 | " resolvedType=" + resolvedType); |
Craig Mautner | e0129b3 | 2014-05-25 16:41:09 -0700 | [diff] [blame] | 7361 | } |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 7362 | final ActivityRecord r = new ActivityRecord(service, null /* caller */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 7363 | 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 7364 | aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */, |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 7365 | 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */, |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 7366 | stackSupervisor, null /* options */, null /* sourceRecord */); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7367 | |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 7368 | r.mPersistentState = persistentState; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 7369 | r.taskDescription = taskDescription; |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 7370 | r.createTime = createTime; |
| 7371 | |
| 7372 | return r; |
| 7373 | } |
| 7374 | |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7375 | private static boolean isInVrUiMode(Configuration config) { |
Ruben Brunk | f53497c | 2017-03-27 20:26:17 -0700 | [diff] [blame] | 7376 | return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET; |
Zak Cohen | 90e711674 | 2017-01-29 12:59:23 -0800 | [diff] [blame] | 7377 | } |
| 7378 | |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 7379 | int getUid() { |
| 7380 | return info.applicationInfo.uid; |
| 7381 | } |
| 7382 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 7383 | boolean isUid(int uid) { |
| 7384 | return info.applicationInfo.uid == uid; |
| 7385 | } |
| 7386 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7387 | int getPid() { |
| 7388 | return app != null ? app.getPid() : 0; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 7389 | } |
| 7390 | |
| 7391 | /** |
| 7392 | * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7393 | * {@link ActivityRecord#getTurnScreenOnFlag} is set and checks whether the ActivityRecord |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7394 | * should be visible depending on Keyguard state |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 7395 | * |
| 7396 | * @return true if the screen can be turned on, false otherwise. |
| 7397 | */ |
| 7398 | boolean canTurnScreenOn() { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7399 | if (!getTurnScreenOnFlag()) { |
| 7400 | return false; |
| 7401 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 7402 | final ActivityStack stack = getActivityStack(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7403 | return stack != null && |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 7404 | stack.checkKeyguardVisibility(this, true /* shouldBeVisible */, true /* isTop */); |
| 7405 | } |
| 7406 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7407 | void setTurnScreenOn(boolean turnScreenOn) { |
| 7408 | mTurnScreenOn = turnScreenOn; |
| 7409 | } |
| 7410 | |
| 7411 | boolean getTurnScreenOnFlag() { |
| 7412 | return mTurnScreenOn; |
| 7413 | } |
| 7414 | |
Louis Chang | 77ce34d | 2019-01-03 15:45:12 +0800 | [diff] [blame] | 7415 | /** |
| 7416 | * Check if this activity is able to resume. For pre-Q apps, only the topmost activities of each |
| 7417 | * process are allowed to be resumed. |
| 7418 | * |
| 7419 | * @return true if this activity can be resumed. |
| 7420 | */ |
| 7421 | boolean canResumeByCompat() { |
| 7422 | return app == null || app.updateTopResumingActivityInProcessIfNeeded(this); |
| 7423 | } |
| 7424 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 7425 | boolean isTopRunningActivity() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7426 | return mRootWindowContainer.topRunningActivity() == this; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 7427 | } |
| 7428 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 7429 | /** |
| 7430 | * @return {@code true} if this is the resumed activity on its current display, {@code false} |
| 7431 | * otherwise. |
| 7432 | */ |
| 7433 | boolean isResumedActivityOnDisplay() { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 7434 | final DisplayContent display = getDisplay(); |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 7435 | return display != null && this == display.getResumedActivity(); |
| 7436 | } |
| 7437 | |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 7438 | |
| 7439 | /** |
| 7440 | * Check if this is the root of the task - first activity that is not finishing, starting from |
| 7441 | * the bottom of the task. If all activities are finishing - then this method will return |
| 7442 | * {@code true} if the activity is at the bottom. |
| 7443 | * |
| 7444 | * NOTE: This is different from 'effective root' - an activity that defines the task identity. |
| 7445 | */ |
| 7446 | boolean isRootOfTask() { |
| 7447 | if (task == null) { |
| 7448 | return false; |
| 7449 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 7450 | final ActivityRecord rootActivity = task.getRootActivity(true); |
| 7451 | return this == rootActivity; |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 7452 | } |
| 7453 | |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 7454 | void setTaskOverlay(boolean taskOverlay) { |
| 7455 | mTaskOverlay = taskOverlay; |
| 7456 | setAlwaysOnTop(mTaskOverlay); |
| 7457 | } |
| 7458 | |
| 7459 | boolean isTaskOverlay() { |
| 7460 | return mTaskOverlay; |
| 7461 | } |
| 7462 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 7463 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 7465 | if (stringName != null) { |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 7466 | return stringName + " t" + (task == null ? INVALID_TASK_ID : task.mTaskId) + |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7467 | (finishing ? " f}" : "") + (mIsExiting ? " mIsExiting=" : "") + "}"; |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 7468 | } |
| 7469 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 7470 | sb.append("ActivityRecord{"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 7471 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 7472 | sb.append(" u"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 7473 | sb.append(mUserId); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 7474 | sb.append(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7475 | sb.append(intent.getComponent().flattenToShortString()); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 7476 | stringName = sb.toString(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7477 | return stringName; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 7478 | } |
| 7479 | |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7480 | /** |
| 7481 | * Write all fields to an {@code ActivityRecordProto}. This assumes the |
| 7482 | * {@code ActivityRecordProto} is the outer-most proto data. |
| 7483 | */ |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7484 | void dumpDebug(ProtoOutputStream proto) { |
| 7485 | dumpDebug(proto, APP_WINDOW_TOKEN, WindowTraceLogLevel.ALL); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 7486 | writeIdentifierToProto(proto, IDENTIFIER); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 7487 | proto.write(STATE, mState.toString()); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 7488 | proto.write(VISIBLE_REQUESTED, mVisibleRequested); |
Andrii Kulian | 39f2744 | 2019-06-26 19:09:19 -0700 | [diff] [blame] | 7489 | proto.write(FRONT_OF_TASK, isRootOfTask()); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 7490 | if (hasProcess()) { |
| 7491 | proto.write(PROC_ID, app.getPid()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 7492 | } |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 7493 | proto.write(TRANSLUCENT, !occludesParent()); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 7494 | proto.write(VISIBLE, mVisible); |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7495 | } |
| 7496 | |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7497 | public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7498 | final long token = proto.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7499 | dumpDebug(proto); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 7500 | proto.end(token); |
| 7501 | } |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7502 | |
| 7503 | /** |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7504 | * Copied from old AppWindowToken. |
| 7505 | */ |
| 7506 | @Override |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7507 | public void dumpDebug(ProtoOutputStream proto, long fieldId, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7508 | @WindowTraceLogLevel int logLevel) { |
| 7509 | // Critical log level logs only visible elements to mitigate performance overheard |
| 7510 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 7511 | return; |
| 7512 | } |
| 7513 | |
| 7514 | final long token = proto.start(fieldId); |
| 7515 | writeNameToProto(proto, NAME); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7516 | super.dumpDebug(proto, WINDOW_TOKEN, logLevel); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7517 | proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing); |
| 7518 | proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart()); |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 7519 | proto.write(IS_ANIMATING, isAnimating()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7520 | if (mThumbnail != null){ |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7521 | mThumbnail.dumpDebug(proto, THUMBNAIL); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7522 | } |
| 7523 | proto.write(FILLS_PARENT, mOccludesParent); |
| 7524 | proto.write(APP_STOPPED, mAppStopped); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 7525 | proto.write(com.android.server.wm.AppWindowTokenProto.VISIBLE_REQUESTED, mVisibleRequested); |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 7526 | proto.write(CLIENT_VISIBLE, mClientVisible); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7527 | proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient); |
| 7528 | proto.write(REPORTED_DRAWN, reportedDrawn); |
| 7529 | proto.write(REPORTED_VISIBLE, reportedVisible); |
| 7530 | proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows); |
| 7531 | proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows); |
| 7532 | proto.write(ALL_DRAWN, allDrawn); |
| 7533 | proto.write(LAST_ALL_DRAWN, mLastAllDrawn); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7534 | if (startingWindow != null) { |
| 7535 | startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW); |
| 7536 | } |
| 7537 | proto.write(STARTING_DISPLAYED, startingDisplayed); |
| 7538 | proto.write(STARTING_MOVED, startingMoved); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 7539 | proto.write(VISIBLE_SET_FROM_TRANSFERRED_STARTING_WINDOW, |
| 7540 | mVisibleSetFromTransferredStartingWindow); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7541 | for (Rect bounds : mFrozenBounds) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7542 | bounds.dumpDebug(proto, FROZEN_BOUNDS); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7543 | } |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 7544 | proto.write(com.android.server.wm.AppWindowTokenProto.VISIBLE, mVisible); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7545 | proto.end(token); |
| 7546 | } |
| 7547 | |
| 7548 | void writeNameToProto(ProtoOutputStream proto, long fieldId) { |
| 7549 | if (appToken != null) { |
| 7550 | proto.write(fieldId, appToken.getName()); |
| 7551 | } |
| 7552 | } |
| 7553 | |
| 7554 | void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) { |
| 7555 | final long token = proto.start(fieldId); |
| 7556 | proto.write(HASH_CODE, System.identityHashCode(this)); |
| 7557 | proto.write(USER_ID, mUserId); |
| 7558 | proto.write(TITLE, intent.getComponent().flattenToShortString()); |
| 7559 | proto.end(token); |
| 7560 | } |
| 7561 | |
| 7562 | /** |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7563 | * The precomputed insets of the display in each rotation. This is used to make the size |
| 7564 | * compatibility mode activity compute the configuration without relying on its current display. |
| 7565 | */ |
| 7566 | static class CompatDisplayInsets { |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 7567 | private final int mDisplayWidth; |
| 7568 | private final int mDisplayHeight; |
| 7569 | private final int mWidth; |
| 7570 | private final int mHeight; |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7571 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 7572 | /** |
| 7573 | * The nonDecorInsets for each rotation. Includes the navigation bar and cutout insets. It |
| 7574 | * is used to compute the appBounds. |
| 7575 | */ |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7576 | final Rect[] mNonDecorInsets = new Rect[4]; |
| 7577 | /** |
| 7578 | * The stableInsets for each rotation. Includes the status bar inset and the |
| 7579 | * nonDecorInsets. It is used to compute {@link Configuration#screenWidthDp} and |
| 7580 | * {@link Configuration#screenHeightDp}. |
| 7581 | */ |
| 7582 | final Rect[] mStableInsets = new Rect[4]; |
| 7583 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 7584 | /** |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 7585 | * Sets bounds to {@link Task} bounds. For apps in freeform, the task bounds are the |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 7586 | * parent bounds from the app's perspective. No insets because within a window. |
| 7587 | */ |
| 7588 | CompatDisplayInsets(DisplayContent display, Rect activityBounds, boolean isFloating) { |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7589 | mDisplayWidth = display.mBaseDisplayWidth; |
| 7590 | mDisplayHeight = display.mBaseDisplayHeight; |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 7591 | mWidth = activityBounds.width(); |
| 7592 | mHeight = activityBounds.height(); |
| 7593 | if (isFloating) { |
| 7594 | Rect emptyRect = new Rect(); |
| 7595 | for (int rotation = 0; rotation < 4; rotation++) { |
| 7596 | mNonDecorInsets[rotation] = emptyRect; |
| 7597 | mStableInsets[rotation] = emptyRect; |
| 7598 | } |
| 7599 | return; |
| 7600 | } |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7601 | final DisplayPolicy policy = display.getDisplayPolicy(); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7602 | for (int rotation = 0; rotation < 4; rotation++) { |
| 7603 | mNonDecorInsets[rotation] = new Rect(); |
| 7604 | mStableInsets[rotation] = new Rect(); |
| 7605 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 7606 | final int dw = rotated ? mDisplayHeight : mDisplayWidth; |
| 7607 | final int dh = rotated ? mDisplayWidth : mDisplayHeight; |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 7608 | final DisplayCutout cutout = display.calculateDisplayCutoutForRotation(rotation) |
| 7609 | .getDisplayCutout(); |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7610 | policy.getNonDecorInsetsLw(rotation, dw, dh, cutout, mNonDecorInsets[rotation]); |
| 7611 | mStableInsets[rotation].set(mNonDecorInsets[rotation]); |
| 7612 | policy.convertNonDecorInsetsToStableInsets(mStableInsets[rotation], rotation); |
| 7613 | } |
| 7614 | } |
| 7615 | |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 7616 | void getDisplayBoundsByRotation(Rect outBounds, int rotation) { |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7617 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 7618 | final int dw = rotated ? mDisplayHeight : mDisplayWidth; |
| 7619 | final int dh = rotated ? mDisplayWidth : mDisplayHeight; |
| 7620 | outBounds.set(0, 0, dw, dh); |
| 7621 | } |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 7622 | |
Evan Rosky | 72f084d | 2019-09-11 17:05:16 -0700 | [diff] [blame] | 7623 | void getFrameByOrientation(Rect outBounds, int orientation) { |
| 7624 | final int longSide = Math.max(mWidth, mHeight); |
| 7625 | final int shortSide = Math.min(mWidth, mHeight); |
Riddle Hsu | 7482626 | 2019-04-17 14:57:42 +0800 | [diff] [blame] | 7626 | final boolean isLandscape = orientation == ORIENTATION_LANDSCAPE; |
| 7627 | outBounds.set(0, 0, isLandscape ? longSide : shortSide, |
| 7628 | isLandscape ? shortSide : longSide); |
| 7629 | } |
Riddle Hsu | 61987bc | 2019-04-03 13:08:47 +0800 | [diff] [blame] | 7630 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 7631 | |
| 7632 | private static class AppSaturationInfo { |
| 7633 | float[] mMatrix = new float[9]; |
| 7634 | float[] mTranslation = new float[3]; |
| 7635 | |
| 7636 | void setSaturation(@Size(9) float[] matrix, @Size(3) float[] translation) { |
| 7637 | System.arraycopy(matrix, 0, mMatrix, 0, mMatrix.length); |
| 7638 | System.arraycopy(translation, 0, mTranslation, 0, mTranslation.length); |
| 7639 | } |
| 7640 | } |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 7641 | |
| 7642 | @Override |
| 7643 | RemoteAnimationTarget createRemoteAnimationTarget( |
| 7644 | RemoteAnimationController.RemoteAnimationRecord record) { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 7645 | final WindowState mainWindow = findMainWindow(); |
| 7646 | if (task == null || mainWindow == null) { |
| 7647 | return null; |
| 7648 | } |
| 7649 | final Rect insets = new Rect(); |
| 7650 | mainWindow.getContentInsets(insets); |
| 7651 | InsetUtils.addInsets(insets, getLetterboxInsets()); |
| 7652 | return new RemoteAnimationTarget(task.mTaskId, record.getMode(), |
| 7653 | record.mAdapter.mCapturedLeash, !task.fillsParent(), |
| 7654 | mainWindow.mWinAnimator.mLastClipRect, insets, |
| 7655 | getPrefixOrderIndex(), record.mAdapter.mPosition, |
| 7656 | record.mAdapter.mStackBounds, task.getWindowConfiguration(), |
| 7657 | false /*isNotInRecents*/, |
| 7658 | record.mThumbnailAdapter != null ? record.mThumbnailAdapter.mCapturedLeash : null, |
| 7659 | record.mStartBounds); |
| 7660 | } |
| 7661 | |
| 7662 | @Override |
| 7663 | void getAnimationFrames(Rect outFrame, Rect outInsets, Rect outStableInsets, |
| 7664 | Rect outSurfaceInsets) { |
| 7665 | final WindowState win = findMainWindow(); |
| 7666 | if (win == null) { |
| 7667 | return; |
| 7668 | } |
| 7669 | win.getAnimationFrames(outFrame, outInsets, outStableInsets, outSurfaceInsets); |
| 7670 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7671 | } |