Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 20 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.ROTATION_UNDEFINED; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 194435b | 2019-12-23 12:56:51 -0800 | [diff] [blame] | 29 | import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 30 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 31 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 32 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 33 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | a77e146 | 2016-09-28 10:09:46 -0700 | [diff] [blame] | 34 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 35 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 36 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 37 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 38 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 39 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 40 | import static android.os.Build.VERSION_CODES.N; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 41 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 42 | import static android.util.DisplayMetrics.DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 43 | import static android.view.Display.DEFAULT_DISPLAY; |
| 44 | import static android.view.Display.FLAG_PRIVATE; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 45 | import static android.view.Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 46 | import static android.view.Display.INVALID_DISPLAY; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 47 | import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 48 | import static android.view.InsetsState.ITYPE_IME; |
| 49 | import static android.view.InsetsState.ITYPE_LEFT_GESTURES; |
| 50 | import static android.view.InsetsState.ITYPE_RIGHT_GESTURES; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 51 | import static android.view.Surface.ROTATION_0; |
| 52 | import static android.view.Surface.ROTATION_180; |
| 53 | import static android.view.Surface.ROTATION_270; |
| 54 | import static android.view.Surface.ROTATION_90; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 55 | import static android.view.View.GONE; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 56 | import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 57 | import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 58 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 59 | import static android.view.WindowManager.DOCKED_INVALID; |
| 60 | import static android.view.WindowManager.DOCKED_TOP; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 61 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 62 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 63 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 64 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 65 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 66 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 67 | import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 68 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 69 | import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 71 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 72 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 73 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 74 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 75 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 76 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 77 | import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 78 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 79 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 80 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 81 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 82 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 83 | import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 84 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 85 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 86 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 87 | import static com.android.server.am.ActivityDisplayProto.DISPLAY; |
| 88 | import static com.android.server.am.ActivityDisplayProto.FOCUSED_STACK_ID; |
| 89 | import static com.android.server.am.ActivityDisplayProto.RESUMED_ACTIVITY; |
| 90 | import static com.android.server.am.ActivityDisplayProto.SINGLE_TASK_INSTANCE; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 91 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 92 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 93 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 94 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 95 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 96 | import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE; |
| 97 | import static com.android.server.wm.ActivityStackSupervisor.TAG_TASKS; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 101 | import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 102 | import static com.android.server.wm.DisplayContentProto.APP_TRANSITION; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 103 | import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 104 | import static com.android.server.wm.DisplayContentProto.CHANGING_APPS; |
| 105 | import static com.android.server.wm.DisplayContentProto.CLOSING_APPS; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 106 | import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES; |
| 107 | import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO; |
| 108 | import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER; |
| 109 | import static com.android.server.wm.DisplayContentProto.DPI; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 110 | import static com.android.server.wm.DisplayContentProto.FOCUSED_APP; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 111 | import static com.android.server.wm.DisplayContentProto.ID; |
| 112 | import static com.android.server.wm.DisplayContentProto.IME_WINDOWS; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 113 | import static com.android.server.wm.DisplayContentProto.OPENING_APPS; |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 114 | import static com.android.server.wm.DisplayContentProto.OVERLAY_WINDOWS; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 115 | import static com.android.server.wm.DisplayContentProto.ROTATION; |
| 116 | import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION; |
| 117 | import static com.android.server.wm.DisplayContentProto.STACKS; |
| 118 | import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 119 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; |
| 120 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
| 121 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS; |
| 122 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; |
| 123 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; |
| 124 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_SCREEN_ON; |
| 125 | import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 126 | import static com.android.server.wm.RootWindowContainer.TAG_STATES; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 127 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 128 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 129 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 130 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 131 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 132 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 133 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 134 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 135 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 136 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 137 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 138 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 139 | import static com.android.server.wm.WindowManagerService.H.REPORT_FOCUS_CHANGE; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 140 | import static com.android.server.wm.WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 141 | import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 142 | import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 143 | import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 144 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 145 | import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 146 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 147 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
| 148 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS; |
| 149 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 150 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 151 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 152 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 153 | import static com.android.server.wm.WindowState.EXCLUSION_LEFT; |
| 154 | import static com.android.server.wm.WindowState.EXCLUSION_RIGHT; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 155 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 156 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 157 | import static com.android.server.wm.utils.RegionUtils.forEachRectReverse; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 158 | import static com.android.server.wm.utils.RegionUtils.rectListToRegion; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 159 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 160 | import android.animation.AnimationHandler; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 161 | import android.annotation.IntDef; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 162 | import android.annotation.NonNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 163 | import android.annotation.Nullable; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 164 | import android.app.ActivityManager; |
| 165 | import android.app.ActivityManagerInternal; |
| 166 | import android.app.ActivityOptions; |
| 167 | import android.app.WindowConfiguration; |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 168 | import android.content.Context; |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 169 | import android.content.Intent; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 170 | import android.content.pm.ActivityInfo; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 171 | import android.content.pm.ActivityInfo.ScreenOrientation; |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 172 | import android.content.pm.ApplicationInfo; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 173 | import android.content.res.CompatibilityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 174 | import android.content.res.Configuration; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 175 | import android.graphics.Bitmap; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 176 | import android.graphics.Insets; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 177 | import android.graphics.Matrix; |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 178 | import android.graphics.Point; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 179 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 180 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 181 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 182 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 183 | import android.hardware.display.DisplayManagerInternal; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 184 | import android.metrics.LogMaker; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 185 | import android.os.Binder; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 186 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 187 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 188 | import android.os.IBinder; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 189 | import android.os.Message; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 190 | import android.os.Process; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 191 | import android.os.RemoteCallbackList; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 192 | import android.os.RemoteException; |
| 193 | import android.os.SystemClock; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 194 | import android.os.Trace; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 195 | import android.os.UserHandle; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 196 | import android.provider.Settings; |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 197 | import android.util.ArraySet; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 198 | import android.util.DisplayMetrics; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 199 | import android.util.IntArray; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 200 | import android.util.Slog; |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 201 | import android.util.SparseArray; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 202 | import android.util.SparseBooleanArray; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 203 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 204 | import android.view.Display; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 205 | import android.view.DisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 206 | import android.view.DisplayInfo; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 207 | import android.view.Gravity; |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 208 | import android.view.IDisplayWindowInsetsController; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 209 | import android.view.ISystemGestureExclusionListener; |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 210 | import android.view.IWindow; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 211 | import android.view.InputChannel; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 212 | import android.view.InputDevice; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 213 | import android.view.InputWindowHandle; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 214 | import android.view.InsetsState.InternalInsetsType; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 215 | import android.view.MagnificationSpec; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 216 | import android.view.RemoteAnimationDefinition; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 217 | import android.view.Surface; |
| 218 | import android.view.SurfaceControl; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 219 | import android.view.SurfaceControl.Transaction; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 220 | import android.view.SurfaceSession; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 221 | import android.view.View; |
Tiger Huang | 41ae5e8 | 2020-01-17 18:17:20 +0800 | [diff] [blame] | 222 | import android.view.ViewRootImpl; |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 223 | import android.view.WindowInsets; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 224 | import android.view.WindowManager; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 225 | import android.view.WindowManagerPolicyConstants.PointerEventListener; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 226 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 227 | import com.android.internal.annotations.VisibleForTesting; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 228 | import com.android.internal.logging.MetricsLogger; |
| 229 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 230 | import com.android.internal.util.ToBooleanFunction; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 231 | import com.android.internal.util.function.TriConsumer; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 232 | import com.android.internal.util.function.pooled.PooledConsumer; |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 233 | import com.android.internal.util.function.pooled.PooledFunction; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 234 | import com.android.internal.util.function.pooled.PooledLambda; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 235 | import com.android.internal.util.function.pooled.PooledPredicate; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 236 | import com.android.server.policy.WindowManagerPolicy; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 237 | import com.android.server.protolog.common.ProtoLog; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 238 | import com.android.server.wm.utils.DisplayRotationUtil; |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 239 | import com.android.server.wm.utils.RotationCache; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 240 | import com.android.server.wm.utils.WmDisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 241 | |
| 242 | import java.io.PrintWriter; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 243 | import java.lang.annotation.Retention; |
| 244 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 245 | import java.util.ArrayList; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 246 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 247 | import java.util.HashMap; |
| 248 | import java.util.Iterator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 249 | import java.util.LinkedList; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 250 | import java.util.List; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 251 | import java.util.Objects; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 252 | import java.util.function.Consumer; |
| 253 | import java.util.function.Predicate; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 254 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 255 | /** |
| 256 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 257 | * particular Display. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 258 | */ |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 259 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 260 | implements WindowManagerPolicy.DisplayContentInfo { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 261 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 262 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 263 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 264 | /** The default scaling mode that scales content automatically. */ |
| 265 | static final int FORCE_SCALING_MODE_AUTO = 0; |
| 266 | /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */ |
| 267 | static final int FORCE_SCALING_MODE_DISABLED = 1; |
| 268 | |
| 269 | @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = { |
| 270 | FORCE_SCALING_MODE_AUTO, |
| 271 | FORCE_SCALING_MODE_DISABLED |
| 272 | }) |
| 273 | @Retention(RetentionPolicy.SOURCE) |
| 274 | @interface ForceScalingMode {} |
| 275 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 276 | ActivityTaskManagerService mAtmService; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 277 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 278 | /** Unique identifier of this display. */ |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 279 | final int mDisplayId; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 280 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 281 | /** |
| 282 | * Most surfaces will be a child of this window. There are some special layers and windows |
| 283 | * which are always on top of others and omitted from Screen-Magnification, for example the |
| 284 | * strict mode flash or the magnification overlay itself. Those layers will be children of |
| 285 | * {@link #mOverlayContainers} where mWindowContainers contains everything else. |
| 286 | */ |
| 287 | private final WindowContainers mWindowContainers = |
| 288 | new WindowContainers("mWindowContainers", mWmService); |
| 289 | |
| 290 | // Contains some special windows which are always on top of others and omitted from |
| 291 | // Screen-Magnification, for example the WindowMagnification windows. |
| 292 | private final NonAppWindowContainers mOverlayContainers = |
| 293 | new NonAppWindowContainers("mOverlayContainers", mWmService); |
| 294 | |
| 295 | /** The containers below are the only child containers {@link #mWindowContainers} can have. */ |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 296 | // Contains all window containers that are related to apps (Activities) |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 297 | private final TaskContainers mTaskContainers = new TaskContainers(mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 298 | // Contains all non-app window containers that should be displayed above the app containers |
| 299 | // (e.g. Status bar) |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 300 | private final AboveAppWindowContainers mAboveAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 301 | new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 302 | // Contains all non-app window containers that should be displayed below the app containers |
| 303 | // (e.g. Wallpaper). |
| 304 | private final NonAppWindowContainers mBelowAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 305 | new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 306 | // Contains all IME window containers. Note that the z-ordering of the IME windows will depend |
| 307 | // on the IME target. We mainly have this container grouping so we can keep track of all the IME |
Robert Carr | 9034d96 | 2018-01-04 18:27:42 -0800 | [diff] [blame] | 308 | // window containers together and move them in-sync if/when needed. We use a subclass of |
| 309 | // WindowContainer which is omitted from screen magnification, as the IME is never magnified. |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 310 | // TODO(display-area): is "no magnification" in the comment still true? |
| 311 | private final ImeContainer mImeWindowsContainers = new ImeContainer(mWmService); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 312 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 313 | private WindowState mTmpWindow; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 314 | private WindowState mTmpWindow2; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 315 | private boolean mUpdateImeTarget; |
| 316 | private boolean mTmpInitial; |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 317 | private int mMaxUiWidth; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 318 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 319 | final AppTransition mAppTransition; |
| 320 | final AppTransitionController mAppTransitionController; |
| 321 | boolean mSkipAppTransitionAnimation = false; |
| 322 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 323 | final ArraySet<ActivityRecord> mOpeningApps = new ArraySet<>(); |
| 324 | final ArraySet<ActivityRecord> mClosingApps = new ArraySet<>(); |
| 325 | final ArraySet<ActivityRecord> mChangingApps = new ArraySet<>(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 326 | final UnknownAppVisibilityController mUnknownAppVisibilityController; |
| 327 | BoundsAnimationController mBoundsAnimationController; |
| 328 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 329 | private MetricsLogger mMetricsLogger; |
| 330 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 331 | /** |
| 332 | * List of clients without a transtiton animation that we notify once we are done |
| 333 | * transitioning since they won't be notified through the app window animator. |
| 334 | */ |
| 335 | final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>(); |
| 336 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 337 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 338 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 339 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 340 | // Initial display metrics. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 341 | int mInitialDisplayWidth = 0; |
| 342 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 343 | int mInitialDisplayDensity = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 344 | |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 345 | DisplayCutout mInitialDisplayCutout; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 346 | private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 347 | = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 348 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 349 | /** |
| 350 | * Overridden display size. Initialized with {@link #mInitialDisplayWidth} |
| 351 | * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size". |
| 352 | * @see WindowManagerService#setForcedDisplaySize(int, int, int) |
| 353 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 354 | int mBaseDisplayWidth = 0; |
| 355 | int mBaseDisplayHeight = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 356 | /** |
| 357 | * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity} |
| 358 | * but can be set from Settings or via shell command "adb shell wm density". |
| 359 | * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int) |
| 360 | */ |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 361 | int mBaseDisplayDensity = 0; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 362 | |
| 363 | /** |
| 364 | * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling". |
| 365 | * @see WindowManagerService#setForcedDisplayScalingMode(int, int) |
| 366 | */ |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 367 | boolean mDisplayScalingDisabled; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 368 | final Display mDisplay; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 369 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 370 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 371 | private final DisplayPolicy mDisplayPolicy; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 372 | private final DisplayRotation mDisplayRotation; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 373 | DisplayFrames mDisplayFrames; |
| 374 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 375 | private final RemoteCallbackList<ISystemGestureExclusionListener> |
| 376 | mSystemGestureExclusionListeners = new RemoteCallbackList<>(); |
| 377 | private final Region mSystemGestureExclusion = new Region(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 378 | private boolean mSystemGestureExclusionWasRestricted = false; |
| 379 | private final Region mSystemGestureExclusionUnrestricted = new Region(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 380 | private int mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 381 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 382 | /** |
| 383 | * For default display it contains real metrics, empty for others. |
chaviw | 619da69 | 2019-06-10 15:39:40 -0700 | [diff] [blame] | 384 | * @see WindowManagerService#createWatermark() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 385 | */ |
| 386 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 387 | |
| 388 | /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */ |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 389 | private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 390 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 391 | /** |
| 392 | * Compat metrics computed based on {@link #mDisplayMetrics}. |
| 393 | * @see #updateDisplayAndOrientation(int) |
| 394 | */ |
| 395 | private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 396 | |
| 397 | /** The desired scaling factor for compatible apps. */ |
| 398 | float mCompatibleScreenScale; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 399 | |
Riddle Hsu | 7f704b5 | 2019-12-10 23:10:45 +0800 | [diff] [blame] | 400 | /** @see #getCurrentOverrideConfigurationChanges */ |
| 401 | private int mCurrentOverrideConfigurationChanges; |
| 402 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 403 | /** |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 404 | * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not |
| 405 | * occluded. |
| 406 | * |
| 407 | * @see NonAppWindowContainers#getOrientation() |
| 408 | */ |
| 409 | private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 410 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 411 | /** |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 412 | * The maximum aspect ratio (longerSide/shorterSide) that is treated as close-to-square. The |
| 413 | * orientation requests from apps would be ignored if the display is close-to-square. |
| 414 | */ |
| 415 | @VisibleForTesting |
| 416 | final float mCloseToSquareMaxAspectRatio; |
| 417 | |
| 418 | /** |
| 419 | * If this is true, we would not rotate the display for apps. The rotation would be either the |
| 420 | * sensor rotation or the user rotation, controlled by |
| 421 | * {@link WindowManagerPolicy.UserRotationMode}. |
| 422 | */ |
| 423 | private boolean mIgnoreRotationForApps; |
| 424 | |
| 425 | /** |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 426 | * Keep track of wallpaper visibility to notify changes. |
| 427 | */ |
| 428 | private boolean mLastWallpaperVisible = false; |
| 429 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 430 | private Rect mBaseDisplayRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 431 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 432 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 433 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 434 | int pendingLayoutChanges; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 435 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 436 | /** |
| 437 | * Used to gate application window layout until we have sent the complete configuration. |
| 438 | * TODO: There are still scenarios where we may be out of sync with the client. Ideally |
| 439 | * we want to replace this flag with a mechanism that will confirm the configuration |
| 440 | * applied by the client is the one expected by the system server. |
| 441 | */ |
| 442 | boolean mWaitingForConfig; |
| 443 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 444 | // TODO(multi-display): remove some of the usages. |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 445 | @VisibleForTesting |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 446 | boolean isDefaultDisplay; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 447 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 448 | /** |
| 449 | * Flag indicating whether WindowManager should override info for this display in |
| 450 | * DisplayManager. |
| 451 | */ |
| 452 | boolean mShouldOverrideDisplayConfiguration = true; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 453 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 454 | /** Window tokens that are in the process of exiting, but still on screen for animations. */ |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 455 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 456 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 457 | /** Detect user tapping outside of current focused task bounds .*/ |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 458 | @VisibleForTesting |
| 459 | final TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 460 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 461 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 462 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 463 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 464 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 465 | private final Rect mTmpRect = new Rect(); |
| 466 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 467 | private final RectF mTmpRectF = new RectF(); |
| 468 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 469 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 470 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 471 | /** Used for handing back size of display */ |
| 472 | private final Rect mTmpBounds = new Rect(); |
| 473 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 474 | private final Configuration mTmpConfiguration = new Configuration(); |
| 475 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 476 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 477 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 478 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 479 | final DockedStackDividerController mDividerControllerLocked; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 480 | final PinnedStackController mPinnedStackControllerLocked; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 481 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 482 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 483 | /** A collection of windows that provide tap exclude regions inside of them. */ |
| 484 | final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>(); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 485 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 486 | private final LinkedList<ActivityRecord> mTmpUpdateAllDrawn = new LinkedList(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 487 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 488 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 489 | new TaskForResizePointSearchResult(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 490 | private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState = |
| 491 | new ApplySurfaceChangesTransactionState(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 492 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 493 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 494 | // the display's direct children should be allowed. |
| 495 | private boolean mRemovingDisplay = false; |
| 496 | |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 497 | // {@code false} if this display is in the processing of being created. |
| 498 | private boolean mDisplayReady = false; |
| 499 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 500 | WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 501 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 502 | boolean mWallpaperMayChange = false; |
| 503 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 504 | private final SurfaceSession mSession = new SurfaceSession(); |
| 505 | |
| 506 | /** |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 507 | * Window that is currently interacting with the user. This window is responsible for receiving |
| 508 | * key events and pointer events from the user. |
| 509 | */ |
| 510 | WindowState mCurrentFocus = null; |
| 511 | |
| 512 | /** |
| 513 | * The last focused window that we've notified the client that the focus is changed. |
| 514 | */ |
| 515 | WindowState mLastFocus = null; |
| 516 | |
| 517 | /** |
| 518 | * Windows that have lost input focus and are waiting for the new focus window to be displayed |
| 519 | * before they are told about this. |
| 520 | */ |
| 521 | ArrayList<WindowState> mLosingFocus = new ArrayList<>(); |
| 522 | |
| 523 | /** |
| 524 | * The foreground app of this display. Windows below this app cannot be the focused window. If |
| 525 | * the user taps on the area outside of the task of the focused app, we will notify AM about the |
| 526 | * new task the user wants to interact with. |
| 527 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 528 | ActivityRecord mFocusedApp = null; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 529 | |
| 530 | /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 531 | final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>(); |
| 532 | |
| 533 | /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 534 | final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>(); |
| 535 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 536 | private ScreenRotationAnimation mScreenRotationAnimation; |
| 537 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 538 | /** |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 539 | * Sequence number for the current layout pass. |
| 540 | */ |
| 541 | int mLayoutSeq = 0; |
| 542 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 543 | /** |
| 544 | * Specifies the count to determine whether to defer updating the IME target until ready. |
| 545 | */ |
| 546 | private int mDeferUpdateImeTargetCount; |
| 547 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 548 | private MagnificationSpec mMagnificationSpec; |
| 549 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 550 | private InputMonitor mInputMonitor; |
| 551 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 552 | /** Caches the value whether told display manager that we have content. */ |
| 553 | private boolean mLastHasContent; |
| 554 | |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 555 | private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil(); |
| 556 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 557 | /** |
| 558 | * The input method window for this display. |
| 559 | */ |
| 560 | WindowState mInputMethodWindow; |
| 561 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 562 | /** |
| 563 | * This just indicates the window the input method is on top of, not |
| 564 | * necessarily the window its input is going to. |
| 565 | */ |
| 566 | WindowState mInputMethodTarget; |
| 567 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 568 | InsetsControlTarget mInputMethodControlTarget; |
| 569 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 570 | /** If true hold off on modifying the animation layer of mInputMethodTarget */ |
| 571 | boolean mInputMethodTargetWaitingAnim; |
| 572 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 573 | private final PointerEventDispatcher mPointerEventDispatcher; |
| 574 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 575 | private final InsetsStateController mInsetsStateController; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 576 | private final InsetsPolicy mInsetsPolicy; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 577 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 578 | /** @see #getParentWindow() */ |
| 579 | private WindowState mParentWindow; |
| 580 | |
| 581 | private Point mLocationInParentWindow = new Point(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 582 | private SurfaceControl mParentSurfaceControl; |
| 583 | private InputWindowHandle mPortalWindowHandle; |
| 584 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 585 | // Last systemUiVisibility we received from status bar. |
| 586 | private int mLastStatusBarVisibility = 0; |
| 587 | // Last systemUiVisibility we dispatched to windows. |
| 588 | private int mLastDispatchedSystemUiVisibility = 0; |
| 589 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 590 | private final ArrayList<ActivityStack> mTmpAlwaysOnTopStacks = new ArrayList<>(); |
| 591 | private final ArrayList<ActivityStack> mTmpNormalStacks = new ArrayList<>(); |
| 592 | private final ArrayList<ActivityStack> mTmpHomeStacks = new ArrayList<>(); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 593 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 594 | /** Corner radius that windows should have in order to match the display. */ |
| 595 | private final float mWindowCornerRadius; |
| 596 | |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 597 | private final SparseArray<ShellRoot> mShellRoots = new SparseArray<>(); |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 598 | RemoteInsetsControlTarget mRemoteInsetsControlTarget = null; |
| 599 | private final IBinder.DeathRecipient mRemoteInsetsDeath = |
| 600 | () -> { |
| 601 | synchronized (mWmService.mGlobalLock) { |
| 602 | mRemoteInsetsControlTarget = null; |
| 603 | } |
| 604 | }; |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 605 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 606 | private RootWindowContainer mRootWindowContainer; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 607 | |
| 608 | /** |
| 609 | * All of the stacks on this display. Order matters, topmost stack is in front of all other |
| 610 | * stacks, bottommost behind. Accessed directly by ActivityManager package classes. Any calls |
| 611 | * changing the list should also call {@link #onStackOrderChanged()}. |
| 612 | */ |
| 613 | private ArrayList<OnStackOrderChangedListener> mStackOrderChangedCallbacks = new ArrayList<>(); |
| 614 | |
| 615 | /** Array of all UIDs that are present on the display. */ |
| 616 | private IntArray mDisplayAccessUIDs = new IntArray(); |
| 617 | |
| 618 | /** All tokens used to put activities on this stack to sleep (including mOffToken) */ |
| 619 | final ArrayList<ActivityTaskManagerInternal.SleepToken> mAllSleepTokens = new ArrayList<>(); |
| 620 | /** The token acquired by ActivityStackSupervisor to put stacks on the display to sleep */ |
| 621 | ActivityTaskManagerInternal.SleepToken mOffToken; |
| 622 | |
| 623 | private boolean mSleeping; |
| 624 | |
| 625 | /** We started the process of removing the display from the system. */ |
| 626 | private boolean mRemoving; |
| 627 | |
| 628 | /** |
| 629 | * The display is removed from the system and we are just waiting for all activities on it to be |
| 630 | * finished before removing this object. |
| 631 | */ |
| 632 | private boolean mRemoved; |
| 633 | |
| 634 | /** The display can only contain one task. */ |
| 635 | private boolean mSingleTaskInstance; |
| 636 | |
| 637 | /** |
| 638 | * Non-null if the last size compatibility mode activity is using non-native screen |
| 639 | * configuration. The activity is not able to put in multi-window mode, so it exists only one |
| 640 | * per display. |
| 641 | */ |
| 642 | private ActivityRecord mLastCompatModeActivity; |
| 643 | |
| 644 | /** |
| 645 | * A focusable stack that is purposely to be positioned at the top. Although the stack may not |
| 646 | * have the topmost index, it is used as a preferred candidate to prevent being unable to resume |
| 647 | * target stack properly when there are other focusable always-on-top stacks. |
| 648 | */ |
| 649 | private ActivityStack mPreferredTopFocusableStack; |
| 650 | |
| 651 | /** |
| 652 | * If this is the same as {@link #getFocusedStack} then the activity on the top of the focused |
| 653 | * stack has been resumed. If stacks are changing position this will hold the old stack until |
| 654 | * the new stack becomes resumed after which it will be set to current focused stack. |
| 655 | */ |
| 656 | private ActivityStack mLastFocusedStack; |
| 657 | |
| 658 | // Used in updating the display size |
| 659 | private Point mTmpDisplaySize = new Point(); |
| 660 | |
| 661 | // Used in updating override configurations |
| 662 | private final Configuration mTempConfig = new Configuration(); |
| 663 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 664 | private final RootWindowContainer.FindTaskResult |
| 665 | mTmpFindTaskResult = new RootWindowContainer.FindTaskResult(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 666 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 667 | private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> { |
| 668 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 669 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 670 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 671 | if (activity == null || activity.canShowWindows()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 672 | if (w.performShowLocked()) { |
| 673 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 674 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 675 | mWmService.mWindowPlacerLocked.debugLayoutRepeats( |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 676 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 681 | }; |
| 682 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 683 | private final Consumer<WindowState> mScheduleToastTimeout = w -> { |
| 684 | final int lostFocusUid = mTmpWindow.mOwnerUid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 685 | final Handler handler = mWmService.mH; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 686 | if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) { |
| 687 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) { |
| 688 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), |
| 689 | w.mAttrs.hideTimeoutMilliseconds); |
| 690 | } |
| 691 | } |
| 692 | }; |
| 693 | |
| 694 | private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 695 | final ActivityRecord focusedApp = mFocusedApp; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 696 | ProtoLog.v(WM_DEBUG_FOCUS, "Looking for focus: %s, flags=%d, canReceive=%b", |
| 697 | w, w.mAttrs.flags, w.canReceiveKeys()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 698 | |
| 699 | if (!w.canReceiveKeys()) { |
| 700 | return false; |
| 701 | } |
| 702 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 703 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 704 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 705 | if (focusedApp == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 706 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 707 | "findFocusedWindow: focusedApp=null using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 708 | mTmpWindow = w; |
| 709 | return true; |
| 710 | } |
| 711 | |
| 712 | if (!focusedApp.windowsAreFocusable()) { |
| 713 | // Current focused app windows aren't focusable... |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 714 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: focusedApp windows not" |
| 715 | + " focusable using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 716 | mTmpWindow = w; |
| 717 | return true; |
| 718 | } |
| 719 | |
| 720 | // Descend through all of the app tokens and find the first that either matches |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 721 | // win.mActivityRecord (return win) or mFocusedApp (return null). |
| 722 | if (activity != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 723 | if (focusedApp.compareTo(activity) > 0) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 724 | // App stack below focused app stack. No focus for you!!! |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 725 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 726 | "findFocusedWindow: Reached focused app=%s", focusedApp); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 727 | mTmpWindow = null; |
| 728 | return true; |
| 729 | } |
| 730 | } |
| 731 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 732 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: Found new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 733 | mTmpWindow = w; |
| 734 | return true; |
| 735 | }; |
| 736 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 737 | private final Consumer<WindowState> mPerformLayout = w -> { |
| 738 | // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid |
| 739 | // wasting time and funky changes while a window is animating away. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 740 | final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 741 | || w.isGoneForLayoutLw(); |
| 742 | |
| 743 | if (DEBUG_LAYOUT && !w.mLayoutAttached) { |
| 744 | Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame |
| 745 | + " mLayoutAttached=" + w.mLayoutAttached |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 746 | + " config reported=" + w.isLastConfigReportedToClient()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 747 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 748 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 749 | + " mRelayoutCalled=" + w.mRelayoutCalled + " visible=" + w.mToken.isVisible() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 750 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 751 | + " parentHidden=" + w.isParentWindowHidden()); |
| 752 | else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 753 | + " mRelayoutCalled=" + w.mRelayoutCalled + " visible=" + w.mToken.isVisible() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 754 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 755 | + " parentHidden=" + w.isParentWindowHidden()); |
| 756 | } |
| 757 | |
| 758 | // If this view is GONE, then skip it -- keep the current frame, and let the caller know |
| 759 | // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows, |
| 760 | // since that means "perform layout as normal, just don't display"). |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 761 | if ((!gone || !w.mHaveFrame || w.mLayoutNeeded) && !w.mLayoutAttached) { |
| 762 | if (mTmpInitial) { |
| 763 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 764 | } |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 765 | if (w.mAttrs.type == TYPE_DREAM) { |
| 766 | // Don't layout windows behind a dream, so that if it does stuff like hide |
| 767 | // the status bar we won't get a bad transition when it goes away. |
| 768 | mTmpWindow = w; |
| 769 | } |
| 770 | w.mLayoutNeeded = false; |
| 771 | w.prelayout(); |
| 772 | final boolean firstLayout = !w.isLaidOut(); |
| 773 | getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames); |
| 774 | w.mLayoutSeq = mLayoutSeq; |
| 775 | |
Riddle Hsu | f64e134 | 2019-12-05 17:38:41 +0800 | [diff] [blame] | 776 | // If this is the first layout, we need to initialize the last frames and inset values, |
| 777 | // as otherwise we'd immediately cause an unnecessary resize. |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 778 | if (firstLayout) { |
Riddle Hsu | 12c0545 | 2020-01-09 00:39:52 +0800 | [diff] [blame] | 779 | // The client may compute its actual requested size according to the first layout, |
| 780 | // so we still request the window to resize if the current frame is empty. |
| 781 | if (!w.getFrameLw().isEmpty()) { |
| 782 | w.updateLastFrames(); |
| 783 | } |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 784 | w.updateLastInsetValues(); |
Riddle Hsu | f64e134 | 2019-12-05 17:38:41 +0800 | [diff] [blame] | 785 | w.updateLocationInParentDisplayIfNeeded(); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 786 | } |
| 787 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 788 | if (w.mActivityRecord != null) { |
| 789 | w.mActivityRecord.layoutLetterbox(w); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
| 793 | + " mContainingFrame=" + w.getContainingFrame() |
| 794 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 795 | } |
| 796 | }; |
| 797 | |
| 798 | private final Consumer<WindowState> mPerformLayoutAttached = w -> { |
| 799 | if (w.mLayoutAttached) { |
| 800 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame |
| 801 | + " mViewVisibility=" + w.mViewVisibility |
| 802 | + " mRelayoutCalled=" + w.mRelayoutCalled); |
| 803 | // If this view is GONE, then skip it -- keep the current frame, and let the caller |
| 804 | // know so they can ignore it if they want. (We do the normal layout for INVISIBLE |
| 805 | // windows, since that means "perform layout as normal, just don't display"). |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 806 | if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 807 | return; |
| 808 | } |
| 809 | if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame |
| 810 | || w.mLayoutNeeded) { |
| 811 | if (mTmpInitial) { |
| 812 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 813 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 814 | } |
| 815 | w.mLayoutNeeded = false; |
| 816 | w.prelayout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 817 | getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 818 | w.mLayoutSeq = mLayoutSeq; |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 819 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 820 | + " mContainingFrame=" + w.getContainingFrame() |
| 821 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 822 | } |
| 823 | } else if (w.mAttrs.type == TYPE_DREAM) { |
| 824 | // Don't layout windows behind a dream, so that if it does stuff like hide the |
| 825 | // status bar we won't get a bad transition when it goes away. |
| 826 | mTmpWindow = mTmpWindow2; |
| 827 | } |
| 828 | }; |
| 829 | |
| 830 | private final Predicate<WindowState> mComputeImeTargetPredicate = w -> { |
| 831 | if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w |
| 832 | + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| 833 | return w.canBeImeTarget(); |
| 834 | }; |
| 835 | |
| 836 | private final Consumer<WindowState> mApplyPostLayoutPolicy = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 837 | w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 838 | mInputMethodTarget); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 839 | |
| 840 | private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 841 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 842 | final boolean obscuredChanged = w.mObscured != |
| 843 | mTmpApplySurfaceChangesTransactionState.obscured; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 844 | final RootWindowContainer root = mWmService.mRoot; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 845 | |
| 846 | // Update effect. |
| 847 | w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 848 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 849 | if (!mTmpApplySurfaceChangesTransactionState.obscured) { |
| 850 | final boolean isDisplayed = w.isDisplayedLw(); |
| 851 | |
| 852 | if (isDisplayed && w.isObscuringDisplay()) { |
| 853 | // This window completely covers everything behind it, so we want to leave all |
| 854 | // of them as undimmed (for performance reasons). |
| 855 | root.mObscuringWindow = w; |
| 856 | mTmpApplySurfaceChangesTransactionState.obscured = true; |
| 857 | } |
| 858 | |
Arthur Hung | fbc8f41 | 2019-08-01 19:57:54 +0800 | [diff] [blame] | 859 | final boolean displayHasContent = root.handleNotObscuredLocked(w, |
| 860 | mTmpApplySurfaceChangesTransactionState.obscured, |
| 861 | mTmpApplySurfaceChangesTransactionState.syswin); |
| 862 | |
| 863 | if (!mTmpApplySurfaceChangesTransactionState.displayHasContent |
| 864 | && !getDisplayPolicy().isWindowExcludedFromContent(w)) { |
| 865 | mTmpApplySurfaceChangesTransactionState.displayHasContent |= displayHasContent; |
| 866 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 867 | |
| 868 | if (w.mHasSurface && isDisplayed) { |
| 869 | final int type = w.mAttrs.type; |
| 870 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 871 | || mWmService.mPolicy.isKeyguardShowing()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 872 | mTmpApplySurfaceChangesTransactionState.syswin = true; |
| 873 | } |
| 874 | if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0 |
| 875 | && w.mAttrs.preferredRefreshRate != 0) { |
| 876 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate |
| 877 | = w.mAttrs.preferredRefreshRate; |
| 878 | } |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 879 | |
| 880 | mTmpApplySurfaceChangesTransactionState.preferMinimalPostProcessing |
| 881 | |= w.mAttrs.preferMinimalPostProcessing; |
| 882 | |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 883 | final int preferredModeId = getDisplayPolicy().getRefreshRatePolicy() |
| 884 | .getPreferredModeId(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 885 | if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0 |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 886 | && preferredModeId != 0) { |
| 887 | mTmpApplySurfaceChangesTransactionState.preferredModeId = preferredModeId; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 892 | if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 893 | // This is the wallpaper target and its obscured state changed... make sure the |
| 894 | // current wallpaper's visibility has been updated accordingly. |
| 895 | mWallpaperController.updateWallpaperVisibility(); |
| 896 | } |
| 897 | |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 898 | w.handleWindowMovedIfNeeded(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 899 | |
| 900 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 901 | |
| 902 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 903 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 904 | |
| 905 | // Moved from updateWindowsAndWallpaperLocked(). |
| 906 | if (w.mHasSurface) { |
| 907 | // Take care of the window being ready to display. |
| 908 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 909 | if (isDefaultDisplay && committed) { |
| 910 | if (w.mAttrs.type == TYPE_DREAM) { |
| 911 | // HACK: When a dream is shown, it may at that point hide the lock screen. |
| 912 | // So we need to redo the layout to let the phone window manager make this |
| 913 | // happen. |
| 914 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 915 | if (DEBUG_LAYOUT_REPEATS) { |
| 916 | surfacePlacer.debugLayoutRepeats( |
| 917 | "dream and commitFinishDrawingLocked true", |
| 918 | pendingLayoutChanges); |
| 919 | } |
| 920 | } |
| 921 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 922 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 923 | "First draw done in potential wallpaper target " + w); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 924 | mWallpaperMayChange = true; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 925 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 926 | if (DEBUG_LAYOUT_REPEATS) { |
| 927 | surfacePlacer.debugLayoutRepeats( |
| 928 | "wallpaper and commitFinishDrawingLocked true", |
| 929 | pendingLayoutChanges); |
| 930 | } |
| 931 | } |
| 932 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 935 | final ActivityRecord activity = w.mActivityRecord; |
| 936 | if (activity != null) { |
| 937 | activity.updateLetterboxSurface(w); |
| 938 | final boolean updateAllDrawn = activity.updateDrawnWindowStates(w); |
| 939 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(activity)) { |
| 940 | mTmpUpdateAllDrawn.add(activity); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 944 | if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 945 | mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | w.updateResizingWindowIfNeeded(); |
| 949 | }; |
| 950 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 951 | /** |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 952 | * Create new {@link DisplayContent} instance, add itself to the root window container and |
| 953 | * initialize direct children. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 954 | * @param display May not be null. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 955 | * @param root {@link RootWindowContainer} |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 956 | */ |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 957 | DisplayContent(Display display, RootWindowContainer root) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 958 | super(root.mWindowManager); |
| 959 | if (mWmService.mRoot.getDisplayContent(display.getDisplayId()) != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 960 | throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 961 | + " already exists=" |
| 962 | + mWmService.mRoot.getDisplayContent(display.getDisplayId()) |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 963 | + " new=" + display); |
| 964 | } |
| 965 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 966 | mRootWindowContainer = root; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 967 | mAtmService = mWmService.mAtmService; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 968 | mDisplay = display; |
| 969 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 970 | mWallpaperController = new WallpaperController(mWmService, this); |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 971 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 972 | display.getMetrics(mDisplayMetrics); |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 973 | mSystemGestureExclusionLimit = mWmService.mConstants.mSystemGestureExclusionLimitDp |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 974 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 975 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 976 | mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo, |
| 977 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 978 | initializeDisplayBaseInfo(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 979 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 980 | mAppTransition = new AppTransition(mWmService.mContext, mWmService, this); |
| 981 | mAppTransition.registerListenerLocked(mWmService.mActivityManagerAppTransitionNotifier); |
| 982 | mAppTransitionController = new AppTransitionController(mWmService, this); |
| 983 | mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 984 | |
| 985 | AnimationHandler animationHandler = new AnimationHandler(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 986 | mBoundsAnimationController = new BoundsAnimationController(mWmService.mContext, |
Riddle Hsu | e459c63 | 2020-01-03 22:37:47 +0800 | [diff] [blame] | 987 | mAppTransition, mWmService.mAnimationHandler, animationHandler); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 988 | |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 989 | final InputChannel inputChannel = mWmService.mInputManager.monitorInput( |
| 990 | "PointerEventDispatcher" + mDisplayId, mDisplayId); |
| 991 | mPointerEventDispatcher = new PointerEventDispatcher(inputChannel); |
| 992 | |
| 993 | // Tap Listeners are supported for: |
| 994 | // 1. All physical displays (multi-display). |
| 995 | // 2. VirtualDisplays on VR, AA (and everything else). |
| 996 | mTapDetector = new TaskTapPointerEventListener(mWmService, this); |
| 997 | registerPointerEventListener(mTapDetector); |
| 998 | registerPointerEventListener(mWmService.mMousePositionTracker); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 999 | if (mWmService.mAtmService.getRecentTasks() != null) { |
| 1000 | registerPointerEventListener( |
| 1001 | mWmService.mAtmService.getRecentTasks().getInputListener()); |
| 1002 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 1003 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1004 | mDisplayPolicy = new DisplayPolicy(mWmService, this); |
| 1005 | mDisplayRotation = new DisplayRotation(mWmService, this); |
| 1006 | mCloseToSquareMaxAspectRatio = mWmService.mContext.getResources().getFloat( |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1007 | com.android.internal.R.dimen.config_closeToSquareDisplayMaxAspectRatio); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1008 | if (isDefaultDisplay) { |
| 1009 | // The policy may be invoked right after here, so it requires the necessary default |
| 1010 | // fields of this display content. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1011 | mWmService.mPolicy.setDefaultDisplay(this); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1012 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1013 | if (mWmService.mDisplayReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1014 | mDisplayPolicy.onConfigurationChanged(); |
| 1015 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1016 | if (mWmService.mSystemReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1017 | mDisplayPolicy.systemReady(); |
| 1018 | } |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 1019 | mWindowCornerRadius = mDisplayPolicy.getWindowCornerRadius(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1020 | mDividerControllerLocked = new DockedStackDividerController(mWmService, this); |
| 1021 | mPinnedStackControllerLocked = new PinnedStackController(mWmService, this); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1022 | |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 1023 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(mSession) |
| 1024 | .setOpaque(true) |
| 1025 | .setContainerLayer(); |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 1026 | mSurfaceControl = b.setName("Root").setContainerLayer().build(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1027 | |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 1028 | getPendingTransaction() |
| 1029 | .setLayer(mSurfaceControl, 0) |
| 1030 | .setLayerStack(mSurfaceControl, mDisplayId) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 1031 | .show(mSurfaceControl); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1032 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1033 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1034 | // These are the only direct children we should ever have and they are permanent. |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 1035 | super.addChild(mWindowContainers, null); |
| 1036 | super.addChild(mOverlayContainers, null); |
| 1037 | |
| 1038 | mWindowContainers.addChildren(); |
| 1039 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 1040 | // Sets the display content for the children. |
| 1041 | onDisplayChanged(this); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 1042 | |
Garfield Tan | fbd233a | 2019-12-26 12:39:25 -0800 | [diff] [blame] | 1043 | mInputMonitor = new InputMonitor(mWmService, this); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1044 | mInsetsStateController = new InsetsStateController(this); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 1045 | mInsetsPolicy = new InsetsPolicy(mInsetsStateController, this); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1046 | |
Garfield Tan | fbd233a | 2019-12-26 12:39:25 -0800 | [diff] [blame] | 1047 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Creating display=" + display); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1048 | |
| 1049 | mWmService.mDisplayWindowSettings.applySettingsToDisplayLocked(this); |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | boolean isReady() { |
| 1053 | // The display is ready when the system and the individual display are both ready. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1054 | return mWmService.mDisplayReady && mDisplayReady; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | int getDisplayId() { |
| 1058 | return mDisplayId; |
| 1059 | } |
| 1060 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 1061 | float getWindowCornerRadius() { |
| 1062 | return mWindowCornerRadius; |
| 1063 | } |
| 1064 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1065 | WindowToken getWindowToken(IBinder binder) { |
| 1066 | return mTokenMap.get(binder); |
| 1067 | } |
| 1068 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1069 | ActivityRecord getActivityRecord(IBinder binder) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1070 | final WindowToken token = getWindowToken(binder); |
| 1071 | if (token == null) { |
| 1072 | return null; |
| 1073 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1074 | return token.asActivityRecord(); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 1077 | void addWindowToken(IBinder binder, WindowToken token) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1078 | final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1079 | if (dc != null) { |
| 1080 | // We currently don't support adding a window token to the display if the display |
| 1081 | // already has the binder mapped to another token. If there is a use case for supporting |
| 1082 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 1083 | // the binder map to a list of window tokens. |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 1084 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 1085 | + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1086 | } |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 1087 | if (binder == null) { |
| 1088 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 1089 | + getName() + " binder is null"); |
| 1090 | } |
| 1091 | if (token == null) { |
| 1092 | throw new IllegalArgumentException("Can't map null token to display=" |
| 1093 | + getName() + " binder=" + binder); |
| 1094 | } |
| 1095 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1096 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1097 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1098 | if (token.asActivityRecord() == null) { |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 1099 | // Set displayContent for non-app token to prevent same token will add twice after |
| 1100 | // onDisplayChanged. |
| 1101 | // TODO: Check if it's fine that super.onDisplayChanged of WindowToken |
| 1102 | // (WindowsContainer#onDisplayChanged) may skipped when token.mDisplayContent assigned. |
| 1103 | token.mDisplayContent = this; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1104 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 1105 | // the parent container managing them (e.g. Tasks). |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1106 | switch (token.windowType) { |
| 1107 | case TYPE_WALLPAPER: |
| 1108 | mBelowAppWindowsContainers.addChild(token); |
| 1109 | break; |
| 1110 | case TYPE_INPUT_METHOD: |
| 1111 | case TYPE_INPUT_METHOD_DIALOG: |
| 1112 | mImeWindowsContainers.addChild(token); |
| 1113 | break; |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 1114 | case TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY: |
| 1115 | mOverlayContainers.addChild(token); |
| 1116 | break; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1117 | default: |
| 1118 | mAboveAppWindowsContainers.addChild(token); |
| 1119 | break; |
| 1120 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1121 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1125 | final WindowToken token = mTokenMap.remove(binder); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1126 | if (token != null && token.asActivityRecord() == null) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1127 | token.setExiting(); |
| 1128 | } |
| 1129 | return token; |
| 1130 | } |
| 1131 | |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 1132 | SurfaceControl addShellRoot(@NonNull IWindow client, int windowType) { |
| 1133 | ShellRoot root = mShellRoots.get(windowType); |
| 1134 | if (root != null) { |
| 1135 | if (root.getClient() == client) { |
| 1136 | return root.getSurfaceControl(); |
| 1137 | } |
| 1138 | root.clear(); |
| 1139 | mShellRoots.remove(windowType); |
| 1140 | } |
| 1141 | root = new ShellRoot(client, this, windowType); |
| 1142 | SurfaceControl rootLeash = root.getSurfaceControl(); |
| 1143 | if (rootLeash == null) { |
| 1144 | // Root didn't finish initializing, so don't add it. |
| 1145 | root.clear(); |
| 1146 | return null; |
| 1147 | } |
| 1148 | mShellRoots.put(windowType, root); |
| 1149 | SurfaceControl out = new SurfaceControl(); |
| 1150 | out.copyFrom(rootLeash); |
| 1151 | return out; |
| 1152 | } |
| 1153 | |
| 1154 | void removeShellRoot(int windowType) { |
| 1155 | ShellRoot root = mShellRoots.get(windowType); |
| 1156 | if (root == null) { |
| 1157 | return; |
| 1158 | } |
| 1159 | root.clear(); |
| 1160 | mShellRoots.remove(windowType); |
| 1161 | } |
| 1162 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 1163 | void setRemoteInsetsController(IDisplayWindowInsetsController controller) { |
| 1164 | if (mRemoteInsetsControlTarget != null) { |
| 1165 | mRemoteInsetsControlTarget.mRemoteInsetsController.asBinder().unlinkToDeath( |
| 1166 | mRemoteInsetsDeath, 0); |
| 1167 | mRemoteInsetsControlTarget = null; |
| 1168 | } |
| 1169 | if (controller != null) { |
| 1170 | try { |
| 1171 | controller.asBinder().linkToDeath(mRemoteInsetsDeath, 0); |
| 1172 | mRemoteInsetsControlTarget = new RemoteInsetsControlTarget(controller); |
| 1173 | } catch (RemoteException e) { |
| 1174 | return; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1179 | /** Changes the display the input window token is housed on to this one. */ |
| 1180 | void reParentWindowToken(WindowToken token) { |
| 1181 | final DisplayContent prevDc = token.getDisplayContent(); |
| 1182 | if (prevDc == this) { |
| 1183 | return; |
| 1184 | } |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1185 | if (prevDc != null) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1186 | if (prevDc.mTokenMap.remove(token.token) != null && token.asActivityRecord() == null) { |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1187 | // Removed the token from the map, but made sure it's not an app token before |
| 1188 | // removing from parent. |
| 1189 | token.getParent().removeChild(token); |
| 1190 | } |
lumark | 280cb21 | 2019-09-09 09:47:22 +0800 | [diff] [blame] | 1191 | if (token.hasChild(prevDc.mLastFocus)) { |
| 1192 | // If the reparent window token contains previous display's last focus window, means |
| 1193 | // it will end up to gain window focus on the target display, so it should not be |
| 1194 | // notified that it lost focus from the previous display. |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1195 | prevDc.mLastFocus = null; |
| 1196 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1197 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1198 | |
| 1199 | addWindowToken(token.token, token); |
RyanlwLin | 925e822 | 2019-08-30 15:08:48 +0800 | [diff] [blame] | 1200 | |
| 1201 | if (mWmService.mAccessibilityController != null) { |
| 1202 | final int prevDisplayId = prevDc != null ? prevDc.getDisplayId() : INVALID_DISPLAY; |
| 1203 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(prevDisplayId, |
| 1204 | getDisplayId()); |
| 1205 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1208 | void removeAppToken(IBinder binder) { |
| 1209 | final WindowToken token = removeWindowToken(binder); |
| 1210 | if (token == null) { |
| 1211 | Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder); |
| 1212 | return; |
| 1213 | } |
| 1214 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1215 | final ActivityRecord activity = token.asActivityRecord(); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1216 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1217 | if (activity == null) { |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1218 | Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token); |
| 1219 | return; |
| 1220 | } |
| 1221 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1222 | activity.onRemovedFromDisplay(); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1225 | @Override |
| 1226 | public Display getDisplay() { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 1227 | return mDisplay; |
| 1228 | } |
| 1229 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1230 | DisplayInfo getDisplayInfo() { |
| 1231 | return mDisplayInfo; |
| 1232 | } |
| 1233 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 1234 | DisplayMetrics getDisplayMetrics() { |
| 1235 | return mDisplayMetrics; |
| 1236 | } |
| 1237 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1238 | DisplayPolicy getDisplayPolicy() { |
| 1239 | return mDisplayPolicy; |
| 1240 | } |
| 1241 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1242 | @Override |
| 1243 | public DisplayRotation getDisplayRotation() { |
| 1244 | return mDisplayRotation; |
| 1245 | } |
| 1246 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 1247 | void setInsetProvider(@InternalInsetsType int type, WindowState win, |
| 1248 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider){ |
| 1249 | setInsetProvider(type, win, frameProvider, null /* imeFrameProvider */); |
| 1250 | } |
| 1251 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1252 | /** |
| 1253 | * Marks a window as providing insets for the rest of the windows in the system. |
| 1254 | * |
| 1255 | * @param type The type of inset this window provides. |
| 1256 | * @param win The window. |
| 1257 | * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of |
| 1258 | * the window should be taken. |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 1259 | * @param imeFrameProvider Function to compute the frame when dispatching insets to the IME, or |
| 1260 | * {@code null} if the normal frame should be taken. |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1261 | */ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1262 | void setInsetProvider(@InternalInsetsType int type, WindowState win, |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 1263 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider, |
| 1264 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> imeFrameProvider) { |
| 1265 | mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider, |
| 1266 | imeFrameProvider); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | InsetsStateController getInsetsStateController() { |
| 1270 | return mInsetsStateController; |
| 1271 | } |
| 1272 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 1273 | InsetsPolicy getInsetsPolicy() { |
| 1274 | return mInsetsPolicy; |
| 1275 | } |
| 1276 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1277 | @Surface.Rotation |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1278 | int getRotation() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1279 | return mDisplayRotation.getRotation(); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1280 | } |
| 1281 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1282 | @ScreenOrientation |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1283 | int getLastOrientation() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1284 | return mDisplayRotation.getLastOrientation(); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 1287 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 1288 | mAppTransitionController.registerRemoteAnimations(definition); |
| 1289 | } |
| 1290 | |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1291 | void reconfigureDisplayLocked() { |
| 1292 | if (!isReady()) { |
| 1293 | return; |
| 1294 | } |
| 1295 | configureDisplayPolicy(); |
| 1296 | setLayoutNeeded(); |
| 1297 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1298 | boolean configChanged = updateOrientation(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1299 | final Configuration currentDisplayConfig = getConfiguration(); |
| 1300 | mTmpConfiguration.setTo(currentDisplayConfig); |
| 1301 | computeScreenConfiguration(mTmpConfiguration); |
| 1302 | configChanged |= currentDisplayConfig.diff(mTmpConfiguration) != 0; |
| 1303 | |
| 1304 | if (configChanged) { |
| 1305 | mWaitingForConfig = true; |
| 1306 | mWmService.startFreezingDisplayLocked(0 /* exitAnim */, 0 /* enterAnim */, this); |
| 1307 | sendNewConfiguration(); |
| 1308 | } |
| 1309 | |
| 1310 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1313 | void sendNewConfiguration() { |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1314 | if (!isReady()) { |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1315 | return; |
| 1316 | } |
Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 1317 | if (mDisplayRotation.isWaitingForRemoteRotation()) { |
| 1318 | return; |
| 1319 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1320 | final boolean configUpdated = updateDisplayOverrideConfigurationLocked(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1321 | if (configUpdated) { |
| 1322 | return; |
| 1323 | } |
| 1324 | // Something changed (E.g. device rotation), but no configuration update is needed. |
| 1325 | // E.g. changing device rotation by 180 degrees. Go ahead and perform surface placement to |
| 1326 | // unfreeze the display since we froze it when the rotation was updated in |
| 1327 | // DisplayContent#updateRotationUnchecked. |
| 1328 | if (mWaitingForConfig) { |
| 1329 | mWaitingForConfig = false; |
| 1330 | mWmService.mLastFinishedFreezeSource = "config-unchanged"; |
| 1331 | setLayoutNeeded(); |
| 1332 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1336 | @Override |
| 1337 | boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, |
| 1338 | ConfigurationContainer requestingContainer) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1339 | final Configuration config = updateOrientation( |
| 1340 | getRequestedOverrideConfiguration(), freezeDisplayToken, false /* forceUpdate */); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1341 | // If display rotation class tells us that it doesn't consider app requested orientation, |
| 1342 | // this display won't rotate just because of an app changes its requested orientation. Thus |
| 1343 | // it indicates that this display chooses not to handle this request. |
| 1344 | final boolean handled = getDisplayRotation().respectAppRequestedOrientation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1345 | if (config == null) { |
| 1346 | return handled; |
| 1347 | } |
| 1348 | |
| 1349 | if (handled && requestingContainer instanceof ActivityRecord) { |
| 1350 | final ActivityRecord activityRecord = (ActivityRecord) requestingContainer; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1351 | final boolean kept = updateDisplayOverrideConfigurationLocked(config, activityRecord, |
| 1352 | false /* deferResume */, null /* result */); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1353 | activityRecord.frozenBeforeDestroy = true; |
| 1354 | if (!kept) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1355 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1356 | } |
| 1357 | } else { |
| 1358 | // We have a new configuration to push so we need to update ATMS for now. |
| 1359 | // TODO: Clean up display configuration push between ATMS and WMS after unification. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1360 | updateDisplayOverrideConfigurationLocked(config, null /* starting */, |
| 1361 | false /* deferResume */, null); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1362 | } |
| 1363 | return handled; |
| 1364 | } |
| 1365 | |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1366 | @Override |
| 1367 | boolean handlesOrientationChangeFromDescendant() { |
| 1368 | return getDisplayRotation().respectAppRequestedOrientation(); |
| 1369 | } |
| 1370 | |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1371 | /** |
| 1372 | * Determine the new desired orientation of this display. |
| 1373 | * |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1374 | * @see #getOrientation() |
| 1375 | * @return {@code true} if the orientation is changed and the caller should call |
| 1376 | * {@link #sendNewConfiguration} if the method returns {@code true}. |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1377 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1378 | boolean updateOrientation() { |
| 1379 | return mDisplayRotation.updateOrientation(getOrientation(), false /* forceUpdate */); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1380 | } |
| 1381 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1382 | /** |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1383 | * Update orientation of the display, returning a non-null new Configuration if it has |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1384 | * changed from the current orientation. If a non-null configuration is returned, someone must |
| 1385 | * call {@link WindowManagerService#setNewDisplayOverrideConfiguration(Configuration, |
| 1386 | * DisplayContent)} to tell the window manager it can unfreeze the screen. This will typically |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1387 | * be done by calling {@link #sendNewConfiguration}. |
| 1388 | * |
| 1389 | * @param currentConfig The current requested override configuration (it is usually set from |
| 1390 | * the last {@link #sendNewConfiguration}) of the display. It is used to |
| 1391 | * check if the configuration container has the latest state. |
| 1392 | * @param freezeDisplayToken Freeze the app window token if the orientation is changed. |
| 1393 | * @param forceUpdate See {@link DisplayRotation#updateRotationUnchecked(boolean)} |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1394 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1395 | Configuration updateOrientation(Configuration currentConfig, IBinder freezeDisplayToken, |
| 1396 | boolean forceUpdate) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1397 | if (!mDisplayReady) { |
| 1398 | return null; |
| 1399 | } |
| 1400 | |
| 1401 | Configuration config = null; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1402 | if (mDisplayRotation.updateOrientation(getOrientation(), forceUpdate)) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1403 | // If we changed the orientation but mOrientationChangeComplete is already true, |
| 1404 | // we used seamless rotation, and we don't need to freeze the screen. |
| 1405 | if (freezeDisplayToken != null && !mWmService.mRoot.mOrientationChangeComplete) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1406 | final ActivityRecord activity = getActivityRecord(freezeDisplayToken); |
| 1407 | if (activity != null) { |
| 1408 | activity.startFreezingScreen(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1409 | } |
| 1410 | } |
| 1411 | config = new Configuration(); |
| 1412 | computeScreenConfiguration(config); |
| 1413 | } else if (currentConfig != null) { |
| 1414 | // No obvious action we need to take, but if our current state mismatches the |
| 1415 | // activity manager's, update it, disregarding font scale, which should remain set |
| 1416 | // to the value of the previous configuration. |
| 1417 | // Here we're calling Configuration#unset() instead of setToDefaults() because we |
| 1418 | // need to keep override configs clear of non-empty values (e.g. fontSize). |
| 1419 | mTmpConfiguration.unset(); |
| 1420 | mTmpConfiguration.updateFrom(currentConfig); |
| 1421 | computeScreenConfiguration(mTmpConfiguration); |
| 1422 | if (currentConfig.diff(mTmpConfiguration) != 0) { |
| 1423 | mWaitingForConfig = true; |
| 1424 | setLayoutNeeded(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1425 | mDisplayRotation.prepareNormalRotationAnimation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1426 | config = new Configuration(mTmpConfiguration); |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | return config; |
| 1431 | } |
| 1432 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1433 | /** |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1434 | * Update rotation of the display. |
| 1435 | * |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1436 | * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1437 | * {@link #sendNewConfiguration} TO UNFREEZE THE SCREEN. |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1438 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1439 | boolean updateRotationUnchecked() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1440 | return mDisplayRotation.updateRotationUnchecked(false /* forceUpdate */); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked} |
| 1445 | * (if it returned {@code true}) to actually finish the rotation. |
| 1446 | * |
| 1447 | * @param oldRotation the rotation we are coming from. |
| 1448 | * @param rotation the rotation to apply. |
| 1449 | */ |
| 1450 | void applyRotationLocked(final int oldRotation, final int rotation) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1451 | mDisplayRotation.applyCurrentRotation(rotation); |
| 1452 | final boolean rotateSeamlessly = mDisplayRotation.isRotatingSeamlessly(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1453 | final Transaction transaction = getPendingTransaction(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 1454 | ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly |
| 1455 | ? null : getRotationAnimation(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1456 | // We need to update our screen size information to match the new rotation. If the rotation |
| 1457 | // has actually changed then this method will return true and, according to the comment at |
| 1458 | // the top of the method, the caller is obligated to call computeNewConfigurationLocked(). |
| 1459 | // By updating the Display info here it will be available to |
| 1460 | // #computeScreenConfiguration() later. |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1461 | updateDisplayAndOrientation(getConfiguration().uiMode, null /* outConfig */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1462 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1463 | // NOTE: We disable the rotation in the emulator because |
| 1464 | // it doesn't support hardware OpenGL emulation yet. |
Vadim Caen | ba4fd6c | 2019-08-05 16:45:46 +0200 | [diff] [blame] | 1465 | if (screenRotationAnimation != null && screenRotationAnimation.hasScreenshot()) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1466 | screenRotationAnimation.setRotation(transaction, rotation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1469 | forAllWindows(w -> { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1470 | w.seamlesslyRotateIfAllowed(transaction, oldRotation, rotation, rotateSeamlessly); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1471 | }, true /* traverseTopToBottom */); |
| 1472 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1473 | mWmService.mDisplayManagerInternal.performTraversal(transaction); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1474 | scheduleAnimation(); |
| 1475 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1476 | forAllWindows(w -> { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1477 | if (w.mHasSurface && !rotateSeamlessly) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1478 | ProtoLog.v(WM_DEBUG_ORIENTATION, "Set mOrientationChanging of %s", w); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1479 | w.setOrientationChanging(true); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1480 | mWmService.mRoot.mOrientationChangeComplete = false; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1481 | w.mLastFreezeDuration = 0; |
| 1482 | } |
| 1483 | w.mReportOrientationChanged = true; |
| 1484 | }, true /* traverseTopToBottom */); |
| 1485 | |
| 1486 | if (rotateSeamlessly) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1487 | mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT, |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1488 | this, SEAMLESS_ROTATION_TIMEOUT_DURATION); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1491 | for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1492 | final WindowManagerService.RotationWatcher rotationWatcher |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1493 | = mWmService.mRotationWatchers.get(i); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1494 | if (rotationWatcher.mDisplayId == mDisplayId) { |
| 1495 | try { |
| 1496 | rotationWatcher.mWatcher.onRotationChanged(rotation); |
| 1497 | } catch (RemoteException e) { |
| 1498 | // Ignore |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1503 | // Announce rotation only if we will not animate as we already have the |
| 1504 | // windows in final state. Otherwise, we make this call at the rotation end. |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1505 | if (screenRotationAnimation == null && mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1506 | mWmService.mAccessibilityController.onRotationChangedLocked(this); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1507 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1510 | void configureDisplayPolicy() { |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1511 | final int width = mBaseDisplayWidth; |
| 1512 | final int height = mBaseDisplayHeight; |
| 1513 | final int shortSize; |
| 1514 | final int longSize; |
| 1515 | if (width > height) { |
| 1516 | shortSize = height; |
| 1517 | longSize = width; |
| 1518 | } else { |
| 1519 | shortSize = width; |
| 1520 | longSize = height; |
| 1521 | } |
| 1522 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 1523 | final int shortSizeDp = shortSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
| 1524 | final int longSizeDp = longSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1525 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1526 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 1527 | mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1528 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1529 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 1530 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1531 | |
| 1532 | // Not much of use to rotate the display for apps since it's close to square. |
| 1533 | mIgnoreRotationForApps = isNonDecorDisplayCloseToSquare(Surface.ROTATION_0, width, height); |
| 1534 | } |
| 1535 | |
| 1536 | private boolean isNonDecorDisplayCloseToSquare(int rotation, int width, int height) { |
| 1537 | final DisplayCutout displayCutout = |
| 1538 | calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
| 1539 | final int uiMode = mWmService.mPolicy.getUiMode(); |
| 1540 | final int w = mDisplayPolicy.getNonDecorDisplayWidth( |
| 1541 | width, height, rotation, uiMode, displayCutout); |
| 1542 | final int h = mDisplayPolicy.getNonDecorDisplayHeight( |
| 1543 | width, height, rotation, uiMode, displayCutout); |
| 1544 | final float aspectRatio = Math.max(w, h) / (float) Math.min(w, h); |
| 1545 | return aspectRatio <= mCloseToSquareMaxAspectRatio; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1548 | /** |
| 1549 | * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config |
| 1550 | * changed. |
| 1551 | * Do not call if {@link WindowManagerService#mDisplayReady} == false. |
| 1552 | */ |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1553 | private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1554 | // Use the effective "visual" dimensions based on current rotation |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1555 | final int rotation = getRotation(); |
| 1556 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1557 | final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1558 | final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1559 | |
| 1560 | // Update application display metrics. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1561 | final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(rotation); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1562 | final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout(); |
| 1563 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1564 | final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1565 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1566 | final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1567 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1568 | mDisplayInfo.rotation = rotation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1569 | mDisplayInfo.logicalWidth = dw; |
| 1570 | mDisplayInfo.logicalHeight = dh; |
| 1571 | mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity; |
| 1572 | mDisplayInfo.appWidth = appWidth; |
| 1573 | mDisplayInfo.appHeight = appHeight; |
| 1574 | if (isDefaultDisplay) { |
| 1575 | mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics, |
| 1576 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
| 1577 | } |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1578 | mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1579 | mDisplayInfo.getAppMetrics(mDisplayMetrics); |
| 1580 | if (mDisplayScalingDisabled) { |
| 1581 | mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED; |
| 1582 | } else { |
| 1583 | mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED; |
| 1584 | } |
| 1585 | |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1586 | computeSizeRangesAndScreenLayout(mDisplayInfo, rotated, uiMode, dw, dh, |
| 1587 | mDisplayMetrics.density, outConfig); |
| 1588 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1589 | // We usually set the override info in DisplayManager so that we get consistent display |
| 1590 | // metrics values when displays are changing and don't send out new values until WM is aware |
| 1591 | // of them. However, we don't do this for displays that serve as containers for ActivityView |
| 1592 | // because we don't want letter-/pillar-boxing during resize. |
| 1593 | final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration |
| 1594 | ? mDisplayInfo : null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1595 | mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId, |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1596 | overrideDisplayInfo); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1597 | |
| 1598 | mBaseDisplayRect.set(0, 0, dw, dh); |
| 1599 | |
| 1600 | if (isDefaultDisplay) { |
| 1601 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics, |
| 1602 | mCompatDisplayMetrics); |
| 1603 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1604 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1605 | return mDisplayInfo; |
| 1606 | } |
| 1607 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1608 | WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) { |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1609 | return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation); |
| 1610 | } |
| 1611 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1612 | private WmDisplayCutout calculateDisplayCutoutForRotationUncached( |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1613 | DisplayCutout cutout, int rotation) { |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1614 | if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1615 | return WmDisplayCutout.NO_CUTOUT; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1616 | } |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1617 | if (rotation == ROTATION_0) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1618 | return WmDisplayCutout.computeSafeInsets( |
| 1619 | cutout, mInitialDisplayWidth, mInitialDisplayHeight); |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1620 | } |
Adrian Roos | bed538e | 2018-02-21 17:50:07 +0100 | [diff] [blame] | 1621 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1622 | final Rect[] newBounds = mRotationUtil.getRotatedBounds( |
| 1623 | WmDisplayCutout.computeSafeInsets( |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 1624 | cutout, mInitialDisplayWidth, mInitialDisplayHeight) |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1625 | .getDisplayCutout().getBoundingRectsAll(), |
| 1626 | rotation, mInitialDisplayWidth, mInitialDisplayHeight); |
| 1627 | return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds), |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1628 | rotated ? mInitialDisplayHeight : mInitialDisplayWidth, |
| 1629 | rotated ? mInitialDisplayWidth : mInitialDisplayHeight); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1632 | /** |
| 1633 | * Compute display configuration based on display properties and policy settings. |
| 1634 | * Do not call if mDisplayReady == false. |
| 1635 | */ |
| 1636 | void computeScreenConfiguration(Configuration config) { |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1637 | final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode, config); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1638 | calculateBounds(displayInfo, mTmpBounds); |
| 1639 | config.windowConfiguration.setBounds(mTmpBounds); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1640 | |
| 1641 | final int dw = displayInfo.logicalWidth; |
| 1642 | final int dh = displayInfo.logicalHeight; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 1643 | config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 1644 | config.windowConfiguration.setWindowingMode(getWindowingMode()); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 1645 | config.windowConfiguration.setDisplayWindowingMode(getWindowingMode()); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1646 | config.windowConfiguration.setRotation(displayInfo.rotation); |
Bryce Lee | c1f2f2a | 2017-06-22 15:29:42 -0700 | [diff] [blame] | 1647 | |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1648 | final float density = mDisplayMetrics.density; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1649 | config.screenWidthDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1650 | (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation, |
| 1651 | config.uiMode, displayInfo.displayCutout) / density); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1652 | config.screenHeightDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1653 | (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation, |
| 1654 | config.uiMode, displayInfo.displayCutout) / density); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1655 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1656 | mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1657 | displayInfo.displayCutout, mTmpRect); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1658 | final int leftInset = mTmpRect.left; |
| 1659 | final int topInset = mTmpRect.top; |
| 1660 | // appBounds at the root level should mirror the app screen size. |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1661 | config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */, |
| 1662 | leftInset + displayInfo.appWidth /* right */, |
| 1663 | topInset + displayInfo.appHeight /* bottom */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1664 | final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90 |
| 1665 | || displayInfo.rotation == Surface.ROTATION_270); |
| 1666 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1667 | config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) |
| 1668 | | ((displayInfo.flags & Display.FLAG_ROUND) != 0 |
| 1669 | ? Configuration.SCREENLAYOUT_ROUND_YES |
| 1670 | : Configuration.SCREENLAYOUT_ROUND_NO); |
| 1671 | |
| 1672 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 1673 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 1674 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1675 | dh, displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1676 | config.densityDpi = displayInfo.logicalDensityDpi; |
| 1677 | |
| 1678 | config.colorMode = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1679 | ((displayInfo.isHdr() && mWmService.hasHdrSupport()) |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1680 | ? Configuration.COLOR_MODE_HDR_YES |
| 1681 | : Configuration.COLOR_MODE_HDR_NO) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1682 | | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1683 | ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES |
| 1684 | : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO); |
| 1685 | |
| 1686 | // Update the configuration based on available input devices, lid switch, |
| 1687 | // and platform configuration. |
| 1688 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1689 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 1690 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 1691 | |
| 1692 | int keyboardPresence = 0; |
| 1693 | int navigationPresence = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1694 | final InputDevice[] devices = mWmService.mInputManager.getInputDevices(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1695 | final int len = devices != null ? devices.length : 0; |
| 1696 | for (int i = 0; i < len; i++) { |
| 1697 | InputDevice device = devices[i]; |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1698 | // Ignore virtual input device. |
| 1699 | if (device.isVirtual()) { |
| 1700 | continue; |
| 1701 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1702 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1703 | // Check if input device can dispatch events to current display. |
| 1704 | // If display type is virtual, will follow the default display. |
| 1705 | if (!mWmService.mInputManager.canDispatchToDisplay(device.getId(), |
| 1706 | displayInfo.type == Display.TYPE_VIRTUAL ? DEFAULT_DISPLAY : mDisplayId)) { |
| 1707 | continue; |
| 1708 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1709 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1710 | final int sources = device.getSources(); |
| 1711 | final int presenceFlag = device.isExternal() |
| 1712 | ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1713 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1714 | if (mWmService.mIsTouchDevice) { |
| 1715 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { |
| 1716 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1717 | } |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1718 | } else { |
| 1719 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1720 | } |
| 1721 | |
| 1722 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
| 1723 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 1724 | navigationPresence |= presenceFlag; |
| 1725 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
| 1726 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 1727 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1728 | navigationPresence |= presenceFlag; |
| 1729 | } |
| 1730 | |
| 1731 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 1732 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 1733 | keyboardPresence |= presenceFlag; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1734 | } |
| 1735 | } |
| 1736 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1737 | if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1738 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1739 | navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL; |
| 1740 | } |
| 1741 | |
| 1742 | // Determine whether a hard keyboard is available and enabled. |
| 1743 | // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device? |
| 1744 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1745 | if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) { |
| 1746 | mWmService.mHardKeyboardAvailable = hardKeyboardAvailable; |
| 1747 | mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 1748 | mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1751 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1752 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1753 | // Let the policy update hidden states. |
| 1754 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 1755 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 1756 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1757 | mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1761 | DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1762 | mTmpDisplayMetrics.setTo(mDisplayMetrics); |
| 1763 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 1764 | final int unrotDw, unrotDh; |
| 1765 | if (rotated) { |
| 1766 | unrotDw = dh; |
| 1767 | unrotDh = dw; |
| 1768 | } else { |
| 1769 | unrotDw = dw; |
| 1770 | unrotDh = dh; |
| 1771 | } |
| 1772 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1773 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1774 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1775 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1776 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1777 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1778 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1779 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1780 | return sw; |
| 1781 | } |
| 1782 | |
| 1783 | private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1784 | DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) { |
| 1785 | dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
| 1786 | displayCutout); |
| 1787 | dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
| 1788 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1789 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
| 1790 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
| 1791 | if (curSize == 0 || size < curSize) { |
| 1792 | curSize = size; |
| 1793 | } |
| 1794 | return curSize; |
| 1795 | } |
| 1796 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1797 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 1798 | int uiMode, int dw, int dh, float density, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1799 | |
| 1800 | // We need to determine the smallest width that will occur under normal |
| 1801 | // operation. To this, start with the base screen size and compute the |
| 1802 | // width under the different possible rotations. We need to un-rotate |
| 1803 | // the current screen dimensions before doing this. |
| 1804 | int unrotDw, unrotDh; |
| 1805 | if (rotated) { |
| 1806 | unrotDw = dh; |
| 1807 | unrotDh = dw; |
| 1808 | } else { |
| 1809 | unrotDw = dw; |
| 1810 | unrotDh = dh; |
| 1811 | } |
| 1812 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 1813 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 1814 | displayInfo.largestNominalAppWidth = 0; |
| 1815 | displayInfo.largestNominalAppHeight = 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1816 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh); |
| 1817 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw); |
| 1818 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh); |
| 1819 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw); |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1820 | |
| 1821 | if (outConfig == null) { |
| 1822 | return; |
| 1823 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1824 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
| 1825 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1826 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1827 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1828 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1829 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1830 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1831 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1832 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1833 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
| 1834 | outConfig.screenLayout = sl; |
| 1835 | } |
| 1836 | |
| 1837 | private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1838 | int uiMode, DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1839 | // Get the app screen size at this rotation. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1840 | int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout); |
| 1841 | int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1842 | |
| 1843 | // Compute the screen layout size class for this rotation. |
| 1844 | int longSize = w; |
| 1845 | int shortSize = h; |
| 1846 | if (longSize < shortSize) { |
| 1847 | int tmp = longSize; |
| 1848 | longSize = shortSize; |
| 1849 | shortSize = tmp; |
| 1850 | } |
| 1851 | longSize = (int)(longSize/density); |
| 1852 | shortSize = (int)(shortSize/density); |
| 1853 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
| 1854 | } |
| 1855 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1856 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1857 | int uiMode, int dw, int dh) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1858 | final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( |
| 1859 | rotation).getDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1860 | final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode, |
| 1861 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1862 | if (width < displayInfo.smallestNominalAppWidth) { |
| 1863 | displayInfo.smallestNominalAppWidth = width; |
| 1864 | } |
| 1865 | if (width > displayInfo.largestNominalAppWidth) { |
| 1866 | displayInfo.largestNominalAppWidth = width; |
| 1867 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1868 | final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode, |
| 1869 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1870 | if (height < displayInfo.smallestNominalAppHeight) { |
| 1871 | displayInfo.smallestNominalAppHeight = height; |
| 1872 | } |
| 1873 | if (height > displayInfo.largestNominalAppHeight) { |
| 1874 | displayInfo.largestNominalAppHeight = height; |
| 1875 | } |
| 1876 | } |
| 1877 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 1878 | /** |
| 1879 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 1880 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 1881 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 1882 | * This lowers the travel distance between invoking the menu panel and selecting |
| 1883 | * a menu option. |
| 1884 | * |
| 1885 | * This method helps control where that menu is placed. Its current implementation makes |
| 1886 | * assumptions about the menu key and its relationship to the screen based on whether |
| 1887 | * the device's natural orientation is portrait (width < height) or landscape. |
| 1888 | * |
| 1889 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 1890 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 1891 | * do not hold for the target device, this method should be changed to reflect that. |
| 1892 | * |
| 1893 | * @return A {@link Gravity} value for placing the options menu window. |
| 1894 | */ |
| 1895 | int getPreferredOptionsPanelGravity() { |
| 1896 | final int rotation = getRotation(); |
| 1897 | if (mInitialDisplayWidth < mInitialDisplayHeight) { |
| 1898 | // On devices with a natural orientation of portrait. |
| 1899 | switch (rotation) { |
| 1900 | default: |
| 1901 | case Surface.ROTATION_0: |
| 1902 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1903 | case Surface.ROTATION_90: |
| 1904 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1905 | case Surface.ROTATION_180: |
| 1906 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1907 | case Surface.ROTATION_270: |
| 1908 | return Gravity.START | Gravity.BOTTOM; |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | // On devices with a natural orientation of landscape. |
| 1913 | switch (rotation) { |
| 1914 | default: |
| 1915 | case Surface.ROTATION_0: |
| 1916 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1917 | case Surface.ROTATION_90: |
| 1918 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1919 | case Surface.ROTATION_180: |
| 1920 | return Gravity.START | Gravity.BOTTOM; |
| 1921 | case Surface.ROTATION_270: |
| 1922 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1923 | } |
| 1924 | } |
| 1925 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 1926 | DockedStackDividerController getDockedDividerController() { |
| 1927 | return mDividerControllerLocked; |
| 1928 | } |
| 1929 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1930 | PinnedStackController getPinnedStackController() { |
| 1931 | return mPinnedStackControllerLocked; |
| 1932 | } |
| 1933 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1934 | /** |
| 1935 | * Returns true if the specified UID has access to this display. |
| 1936 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1937 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1938 | return mDisplay.hasAccess(uid); |
| 1939 | } |
| 1940 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1941 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1942 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 1945 | ActivityStack getRootHomeTask() { |
| 1946 | return mTaskContainers.getRootHomeTask(); |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 1949 | /** @return The primary split-screen task, and {@code null} otherwise. */ |
| 1950 | ActivityStack getRootSplitScreenPrimaryTask() { |
| 1951 | return mTaskContainers.getRootSplitScreenPrimaryTask(); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1952 | } |
| 1953 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 1954 | boolean hasSplitScreenPrimaryTask() { |
| 1955 | return getRootSplitScreenPrimaryTask() != null; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 1958 | ActivityStack getRootPinnedTask() { |
| 1959 | return mTaskContainers.getRootPinnedTask(); |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 1962 | boolean hasPinnedTask() { |
| 1963 | return mTaskContainers.getRootPinnedTask() != null; |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1966 | /** |
| 1967 | * Returns the topmost stack on the display that is compatible with the input windowing mode. |
| 1968 | * Null is no compatible stack on the display. |
| 1969 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1970 | ActivityStack getTopStackInWindowingMode(int windowingMode) { |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1971 | return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED); |
| 1972 | } |
| 1973 | |
| 1974 | /** |
| 1975 | * Returns the topmost stack on the display that is compatible with the input windowing mode and |
| 1976 | * activity type. Null is no compatible stack on the display. |
| 1977 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1978 | ActivityStack getStack(int windowingMode, int activityType) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 1979 | return mTaskContainers.getStack(windowingMode, activityType); |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1982 | protected int getStackCount() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 1983 | return mTaskContainers.mChildren.size(); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | protected ActivityStack getStackAt(int index) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 1987 | return mTaskContainers.mChildren.get(index); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | int getIndexOf(ActivityStack stack) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 1991 | return mTaskContainers.getIndexOf(stack); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | void removeStack(ActivityStack stack) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 1995 | mTaskContainers.removeChild(stack); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1996 | } |
| 1997 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1998 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1999 | WindowList<ActivityStack> getStacks() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2000 | return mTaskContainers.mChildren; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2004 | ActivityStack getTopStack() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2005 | return mTaskContainers.getTopStack(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2008 | ArrayList<Task> getVisibleTasks() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2009 | return mTaskContainers.getVisibleTasks(); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2012 | SurfaceControl getSplitScreenDividerAnchor() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2013 | return mTaskContainers.getSplitScreenDividerAnchor(); |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2016 | void onStackWindowingModeChanged(ActivityStack stack) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2017 | mTaskContainers.onStackWindowingModeChanged(stack); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Riddle Hsu | 7f704b5 | 2019-12-10 23:10:45 +0800 | [diff] [blame] | 2020 | /** |
| 2021 | * The value is only valid in the scope {@link #onRequestedOverrideConfigurationChanged} of the |
| 2022 | * changing hierarchy and the {@link #onConfigurationChanged} of its children. |
| 2023 | * |
| 2024 | * @return The current changes ({@link android.content.pm.ActivityInfo.Config}) of requested |
| 2025 | * override configuration. |
| 2026 | */ |
| 2027 | int getCurrentOverrideConfigurationChanges() { |
| 2028 | return mCurrentOverrideConfigurationChanges; |
| 2029 | } |
| 2030 | |
| 2031 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 2032 | public void onConfigurationChanged(Configuration newParentConfig) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2033 | // update resources before cascade so that docked/pinned stacks use the correct info |
| 2034 | preOnConfigurationChanged(); |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2035 | final int lastOrientation = getConfiguration().orientation; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2036 | super.onConfigurationChanged(newParentConfig); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2037 | if (mDisplayPolicy != null) { |
| 2038 | mDisplayPolicy.onConfigurationChanged(); |
| 2039 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2040 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2041 | if (lastOrientation != getConfiguration().orientation) { |
| 2042 | getMetricsLogger().write( |
| 2043 | new LogMaker(MetricsEvent.ACTION_PHONE_ORIENTATION_CHANGED) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2044 | .setSubtype(getConfiguration().orientation) |
| 2045 | .addTaggedData(MetricsEvent.FIELD_DISPLAY_ID, getDisplayId())); |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2046 | } |
| 2047 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2048 | // If there was no pinned stack, we still need to notify the controller of the display info |
| 2049 | // update as a result of the config change. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 2050 | if (mPinnedStackControllerLocked != null && !hasPinnedTask()) { |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2051 | mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo()); |
| 2052 | } |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | /** |
| 2056 | * Updates the resources used by docked/pinned controllers. This needs to be called at the |
| 2057 | * beginning of a configuration update cascade since the metrics from these resources are used |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2058 | * for bounds calculations. |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2059 | */ |
| 2060 | void preOnConfigurationChanged() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2061 | final DockedStackDividerController dividerController = getDockedDividerController(); |
| 2062 | |
| 2063 | if (dividerController != null) { |
| 2064 | getDockedDividerController().onConfigurationChanged(); |
| 2065 | } |
| 2066 | |
| 2067 | final PinnedStackController pinnedStackController = getPinnedStackController(); |
| 2068 | |
| 2069 | if (pinnedStackController != null) { |
| 2070 | getPinnedStackController().onConfigurationChanged(); |
| 2071 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2072 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2073 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 2074 | @Override |
| 2075 | boolean fillsParent() { |
| 2076 | return true; |
| 2077 | } |
| 2078 | |
| 2079 | @Override |
| 2080 | boolean isVisible() { |
| 2081 | return true; |
| 2082 | } |
| 2083 | |
| 2084 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2085 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2086 | super.onAppTransitionDone(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2087 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 2090 | @Override |
| 2091 | public void setWindowingMode(int windowingMode) { |
| 2092 | super.setWindowingMode(windowingMode); |
| 2093 | super.setDisplayWindowingMode(windowingMode); |
| 2094 | } |
| 2095 | |
| 2096 | @Override |
| 2097 | void setDisplayWindowingMode(int windowingMode) { |
| 2098 | setWindowingMode(windowingMode); |
| 2099 | } |
| 2100 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2101 | boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2102 | return mImeWindowsContainers.forAllWindowForce(callback, traverseTopToBottom); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2103 | } |
| 2104 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2105 | /** |
| 2106 | * In the general case, the orientation is computed from the above app windows first. If none of |
| 2107 | * the above app windows specify orientation, the orientation is computed from the child window |
| 2108 | * container, e.g. {@link AppWindowToken#getOrientation(int)}. |
| 2109 | */ |
Vadim Caen | fc14c66 | 2020-01-20 16:00:31 +0100 | [diff] [blame] | 2110 | @ScreenOrientation |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 2111 | @Override |
| 2112 | int getOrientation() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2113 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2114 | |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 2115 | if (mIgnoreRotationForApps) { |
| 2116 | return SCREEN_ORIENTATION_USER; |
| 2117 | } |
| 2118 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2119 | if (mWmService.mDisplayFrozen) { |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 2120 | if (policy.isKeyguardLocked()) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2121 | // Use the last orientation the while the display is frozen with the keyguard |
| 2122 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 2123 | // window. We don't want to check the show when locked window directly though as |
| 2124 | // things aren't stable while the display is frozen, for example the window could be |
| 2125 | // momentarily unavailable due to activity relaunch. |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2126 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 2127 | "Display id=%d is frozen while keyguard locked, return %d", |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2128 | mDisplayId, getLastOrientation()); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2129 | return getLastOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2130 | } |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 2131 | } |
| 2132 | final int orientation = mAboveAppWindowsContainers.getOrientation(); |
| 2133 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 2134 | return orientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 2137 | // Top system windows are not requesting an orientation. Start searching from apps. |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2138 | return mTaskContainers.getOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2141 | void updateDisplayInfo() { |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2142 | // Check if display metrics changed and update base values if needed. |
| 2143 | updateBaseDisplayMetricsIfNeeded(); |
| 2144 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2145 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 2146 | mDisplay.getMetrics(mDisplayMetrics); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2147 | |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 2148 | onDisplayChanged(this); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2151 | @Override |
| 2152 | void onDisplayChanged(DisplayContent dc) { |
| 2153 | super.onDisplayChanged(dc); |
| 2154 | updateSystemGestureExclusionLimit(); |
| 2155 | } |
| 2156 | |
| 2157 | void updateSystemGestureExclusionLimit() { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 2158 | mSystemGestureExclusionLimit = mWmService.mConstants.mSystemGestureExclusionLimitDp |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2159 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
| 2160 | updateSystemGestureExclusion(); |
| 2161 | } |
| 2162 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2163 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2164 | final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2165 | if (displayManagerInternal != null) { |
| 2166 | // Bootstrap the default logical display from the display manager. |
| 2167 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 2168 | if (newDisplayInfo != null) { |
| 2169 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 2170 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2171 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2172 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2173 | updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight, |
| 2174 | mDisplayInfo.logicalDensityDpi); |
| 2175 | mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 2176 | mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 2177 | mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2178 | mInitialDisplayCutout = mDisplayInfo.displayCutout; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2181 | /** |
| 2182 | * If display metrics changed, overrides are not set and it's not just a rotation - update base |
| 2183 | * values. |
| 2184 | */ |
| 2185 | private void updateBaseDisplayMetricsIfNeeded() { |
| 2186 | // Get real display metrics without overrides from WM. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2187 | mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2188 | final int orientation = mDisplayInfo.rotation; |
| 2189 | final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
| 2190 | final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth; |
| 2191 | final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight; |
| 2192 | final int newDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2193 | final DisplayCutout newCutout = mDisplayInfo.displayCutout; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2194 | |
| 2195 | final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth |
| 2196 | || mInitialDisplayHeight != newHeight |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2197 | || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi |
| 2198 | || !Objects.equals(mInitialDisplayCutout, newCutout); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2199 | |
| 2200 | if (displayMetricsChanged) { |
| 2201 | // Check if display size or density is forced. |
| 2202 | final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth |
| 2203 | || mBaseDisplayHeight != mInitialDisplayHeight; |
| 2204 | final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity; |
| 2205 | |
| 2206 | // If there is an override set for base values - use it, otherwise use new values. |
| 2207 | updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth, |
| 2208 | isDisplaySizeForced ? mBaseDisplayHeight : newHeight, |
| 2209 | isDisplayDensityForced ? mBaseDisplayDensity : newDensity); |
| 2210 | |
| 2211 | // Real display metrics changed, so we should also update initial values. |
| 2212 | mInitialDisplayWidth = newWidth; |
| 2213 | mInitialDisplayHeight = newHeight; |
| 2214 | mInitialDisplayDensity = newDensity; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2215 | mInitialDisplayCutout = newCutout; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2216 | reconfigureDisplayLocked(); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2220 | /** Sets the maximum width the screen resolution can be */ |
| 2221 | void setMaxUiWidth(int width) { |
| 2222 | if (DEBUG_DISPLAY) { |
| 2223 | Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId()); |
| 2224 | } |
| 2225 | |
| 2226 | mMaxUiWidth = width; |
| 2227 | |
| 2228 | // Update existing metrics. |
| 2229 | updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity); |
| 2230 | } |
| 2231 | |
| 2232 | /** Update base (override) display metrics. */ |
| 2233 | void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) { |
| 2234 | mBaseDisplayWidth = baseWidth; |
| 2235 | mBaseDisplayHeight = baseHeight; |
| 2236 | mBaseDisplayDensity = baseDensity; |
| 2237 | |
| 2238 | if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) { |
| 2239 | mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth; |
| 2240 | mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth; |
| 2241 | mBaseDisplayWidth = mMaxUiWidth; |
| 2242 | |
| 2243 | if (DEBUG_DISPLAY) { |
| 2244 | Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x" |
| 2245 | + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity |
| 2246 | + " on display:" + getDisplayId()); |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2251 | |
| 2252 | updateBounds(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2255 | /** |
| 2256 | * Forces this display to use the specified density. |
| 2257 | * |
| 2258 | * @param density The density in DPI to use. If the value equals to initial density, the setting |
| 2259 | * will be cleared. |
| 2260 | * @param userId The target user to apply. Only meaningful when this is default display. If the |
| 2261 | * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings |
| 2262 | * so only need to configure display. |
| 2263 | */ |
| 2264 | void setForcedDensity(int density, int userId) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2265 | final boolean updateCurrent = userId == UserHandle.USER_CURRENT; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2266 | if (mWmService.mCurrentUserId == userId || updateCurrent) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2267 | mBaseDisplayDensity = density; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2268 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2269 | } |
| 2270 | if (updateCurrent) { |
| 2271 | // We are applying existing settings so no need to save it again. |
| 2272 | return; |
| 2273 | } |
| 2274 | |
| 2275 | if (density == mInitialDisplayDensity) { |
| 2276 | density = 0; |
| 2277 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2278 | mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */ |
| 2282 | void setForcedScalingMode(@ForceScalingMode int mode) { |
| 2283 | if (mode != FORCE_SCALING_MODE_DISABLED) { |
| 2284 | mode = FORCE_SCALING_MODE_AUTO; |
| 2285 | } |
| 2286 | |
| 2287 | mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO); |
| 2288 | Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto")); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2289 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2290 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2291 | mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /** If the given width and height equal to initial size, the setting will be cleared. */ |
| 2295 | void setForcedSize(int width, int height) { |
| 2296 | final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height; |
| 2297 | if (!clear) { |
| 2298 | // Set some sort of reasonable bounds on the size of the display that we will try |
| 2299 | // to emulate. |
| 2300 | final int minSize = 200; |
| 2301 | final int maxScale = 2; |
| 2302 | width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale); |
| 2303 | height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale); |
| 2304 | } |
| 2305 | |
| 2306 | Slog.i(TAG_WM, "Using new display size: " + width + "x" + height); |
| 2307 | updateBaseDisplayMetrics(width, height, mBaseDisplayDensity); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2308 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2309 | |
| 2310 | if (clear) { |
| 2311 | width = height = 0; |
| 2312 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2313 | mWmService.mDisplayWindowSettings.setForcedSize(this, width, height); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2314 | } |
| 2315 | |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 2316 | void getStableRect(Rect out) { |
| 2317 | out.set(mDisplayFrames.mStable); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 2318 | } |
| 2319 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2320 | void setStackOnDisplay(ActivityStack stack, int position) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2321 | if (DEBUG_STACK) Slog.d(TAG_WM, "Set stack=" + stack + " on displayId=" + mDisplayId); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2322 | mTaskContainers.addChild(stack, position); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2325 | void moveStackToDisplay(ActivityStack stack, boolean onTop) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2326 | stack.reparent(mTaskContainers, onTop ? POSITION_TOP: POSITION_BOTTOM); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2327 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2328 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2329 | @Override |
| 2330 | protected void addChild(DisplayChildWindowContainer child, |
| 2331 | Comparator<DisplayChildWindowContainer> comparator) { |
| 2332 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2333 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2334 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2335 | @Override |
| 2336 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 2337 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2338 | } |
| 2339 | |
| 2340 | @Override |
| 2341 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2342 | // Only allow removal of direct children from this display if the display is in the process |
| 2343 | // of been removed. |
| 2344 | if (mRemovingDisplay) { |
| 2345 | super.removeChild(child); |
| 2346 | return; |
| 2347 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2348 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2349 | } |
| 2350 | |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2351 | void positionDisplayAt(int position, boolean includingParents) { |
| 2352 | getParent().positionChildAt(position, this, includingParents); |
| 2353 | } |
| 2354 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2355 | @Override |
| 2356 | void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) { |
| 2357 | // Children of the display are statically ordered, so the real intention here is to perform |
| 2358 | // the operation on the display and not the static direct children. |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2359 | positionDisplayAt(position, includingParents); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2360 | } |
| 2361 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2362 | void positionStackAt(int position, ActivityStack child, boolean includingParents) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2363 | mTaskContainers.positionChildAt(position, child, includingParents); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 2364 | layoutAndAssignWindowLayersIfNeeded(); |
| 2365 | } |
| 2366 | |
Garfield Tan | 4f71c5a | 2018-10-10 10:12:02 -0700 | [diff] [blame] | 2367 | /** |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2368 | * Returns true if the input point is within an app window. |
| 2369 | */ |
| 2370 | boolean pointWithinAppWindow(int x, int y) { |
| 2371 | final int[] targetWindowType = {-1}; |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2372 | final PooledConsumer fn = PooledLambda.obtainConsumer((w, nonArg) -> { |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2373 | if (targetWindowType[0] != -1) { |
| 2374 | return; |
| 2375 | } |
| 2376 | |
| 2377 | if (w.isOnScreen() && w.isVisibleLw() && w.getFrameLw().contains(x, y)) { |
| 2378 | targetWindowType[0] = w.mAttrs.type; |
| 2379 | return; |
| 2380 | } |
| 2381 | }, PooledLambda.__(WindowState.class), mTmpRect); |
| 2382 | forAllWindows(fn, true /* traverseTopToBottom */); |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2383 | fn.recycle(); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2384 | return FIRST_APPLICATION_WINDOW <= targetWindowType[0] |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2385 | && targetWindowType[0] <= LAST_APPLICATION_WINDOW; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2389 | * Find the task whose outside touch area (for resizing) (x, y) falls within. |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 2390 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2391 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 2392 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2393 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2394 | return mTmpTaskForResizePointSearchResult.process(mTaskContainers, x, y, delta); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2397 | void updateTouchExcludeRegion() { |
| 2398 | final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2399 | if (focusedTask == null) { |
| 2400 | mTouchExcludeRegion.setEmpty(); |
| 2401 | } else { |
| 2402 | mTouchExcludeRegion.set(mBaseDisplayRect); |
| 2403 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2404 | mTmpRect.setEmpty(); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2405 | mTmpRect2.setEmpty(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2406 | |
| 2407 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2408 | DisplayContent::processTaskForTouchExcludeRegion, this, |
| 2409 | PooledLambda.__(Task.class), focusedTask, delta); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2410 | mTaskContainers.forAllTasks(c); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2411 | c.recycle(); |
| 2412 | |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2413 | // If we removed the focused task above, add it back and only leave its |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2414 | // outside touch area in the exclusion. TapDetector is not interested in |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2415 | // any touch inside the focused task itself. |
| 2416 | if (!mTmpRect2.isEmpty()) { |
| 2417 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 2418 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2419 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2420 | if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) { |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2421 | // If the input method is visible and the user is typing, we don't want these touch |
| 2422 | // events to be intercepted and used to change focus. This would likely cause a |
| 2423 | // disappearance of the input method. |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2424 | mInputMethodWindow.getTouchableRegion(mTmpRegion); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2425 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2426 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2427 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 2428 | final WindowState win = mTapExcludedWindows.get(i); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2429 | win.getTouchableRegion(mTmpRegion); |
| 2430 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 2431 | } |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2432 | amendWindowTapExcludeRegion(mTouchExcludeRegion); |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 2433 | // TODO(multi-display): Support docked stacks on secondary displays. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 2434 | if (mDisplayId == DEFAULT_DISPLAY && getRootSplitScreenPrimaryTask() != null) { |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2435 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 2436 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2437 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 2438 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2439 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2442 | private void processTaskForTouchExcludeRegion(Task task, Task focusedTask, int delta) { |
| 2443 | final ActivityRecord topVisibleActivity = task.getTopVisibleActivity(); |
| 2444 | |
| 2445 | if (topVisibleActivity == null || !topVisibleActivity.hasContentToDisplay()) { |
| 2446 | return; |
| 2447 | } |
| 2448 | |
| 2449 | // Exclusion region is the region that TapDetector doesn't care about. |
| 2450 | // Here we want to remove all non-focused tasks from the exclusion region. |
| 2451 | // We also remove the outside touch area for resizing for all freeform |
| 2452 | // tasks (including the focused). |
| 2453 | // We save the focused task region once we find it, and add it back at the end. |
| 2454 | // If the task is home stack and it is resizable in the minimized state, we want to |
| 2455 | // exclude the docked stack from touch so we need the entire screen area and not just a |
| 2456 | // small portion which the home stack currently is resized to. |
| 2457 | if (task.isActivityTypeHome() && task.getStack().isMinimizedDockAndHomeStackResizable()) { |
| 2458 | mDisplayContent.getBounds(mTmpRect); |
| 2459 | } else { |
| 2460 | task.getDimBounds(mTmpRect); |
| 2461 | } |
| 2462 | |
| 2463 | if (task == focusedTask) { |
| 2464 | // Add the focused task rect back into the exclude region once we are done |
| 2465 | // processing stacks. |
| 2466 | mTmpRect2.set(mTmpRect); |
| 2467 | } |
| 2468 | |
| 2469 | final boolean isFreeformed = task.inFreeformWindowingMode(); |
| 2470 | if (task != focusedTask || isFreeformed) { |
| 2471 | if (isFreeformed) { |
| 2472 | // If the task is freeformed, enlarge the area to account for outside |
| 2473 | // touch area for resize. |
| 2474 | mTmpRect.inset(-delta, -delta); |
| 2475 | // Intersect with display content rect. If we have system decor (status bar/ |
| 2476 | // navigation bar), we want to exclude that from the tap detection. |
| 2477 | // Otherwise, if the app is partially placed under some system button (eg. |
| 2478 | // Recents, Home), pressing that button would cause a full series of |
| 2479 | // unwanted transfer focus/resume/pause, before we could go home. |
| 2480 | mTmpRect.intersect(mDisplayFrames.mContent); |
| 2481 | } |
| 2482 | mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE); |
| 2483 | } |
| 2484 | } |
| 2485 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2486 | /** |
| 2487 | * Union the region with all the tap exclude region provided by windows on this display. |
| 2488 | * |
| 2489 | * @param inOutRegion The region to be amended. |
| 2490 | */ |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2491 | private void amendWindowTapExcludeRegion(Region inOutRegion) { |
chaviw | aa0d74e | 2019-12-26 14:13:40 -0800 | [diff] [blame] | 2492 | final Region region = Region.obtain(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2493 | for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) { |
| 2494 | final WindowState win = mTapExcludeProvidingWindows.valueAt(i); |
chaviw | aa0d74e | 2019-12-26 14:13:40 -0800 | [diff] [blame] | 2495 | win.getTapExcludeRegion(region); |
| 2496 | inOutRegion.op(region, Op.UNION); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2497 | } |
chaviw | aa0d74e | 2019-12-26 14:13:40 -0800 | [diff] [blame] | 2498 | region.recycle(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2499 | } |
| 2500 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2501 | @Override |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2502 | void switchUser(int userId) { |
| 2503 | super.switchUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2504 | mWmService.mWindowsChanged = true; |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2505 | mDisplayPolicy.switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2508 | @Override |
| 2509 | void removeIfPossible() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2510 | if (isAnimating(TRANSITION | PARENTS)) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2511 | mDeferredRemoval = true; |
| 2512 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2513 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2514 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2517 | @Override |
| 2518 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2519 | mRemovingDisplay = true; |
| 2520 | try { |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 2521 | if (mParentWindow != null) { |
| 2522 | mParentWindow.removeEmbeddedDisplayContent(this); |
| 2523 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2524 | // Clear all transitions & screen frozen states when removing display. |
| 2525 | mOpeningApps.clear(); |
| 2526 | mClosingApps.clear(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 2527 | mChangingApps.clear(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2528 | mUnknownAppVisibilityController.clear(); |
| 2529 | mAppTransition.removeAppTransitionTimeoutCallbacks(); |
| 2530 | handleAnimatingStoppedAndTransition(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2531 | mWmService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2532 | super.removeImmediately(); |
| 2533 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2534 | mPointerEventDispatcher.dispose(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2535 | setRotationAnimation(null); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2536 | mWmService.mAnimator.removeDisplayLocked(mDisplayId); |
Jorim Jaggi | ae962e6 | 2018-12-27 17:23:48 +0100 | [diff] [blame] | 2537 | mInputMonitor.onDisplayRemoved(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2538 | mWmService.mDisplayNotificationController.dispatchDisplayRemoved(this); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2539 | } finally { |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 2540 | mDisplayReady = false; |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2541 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2542 | } |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 2543 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2544 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2545 | } |
| 2546 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2547 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2548 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2549 | boolean checkCompleteDeferredRemoval() { |
Riddle Hsu | 793442c5 | 2019-11-05 01:04:55 +0800 | [diff] [blame] | 2550 | boolean stillDeferringRemoval = false; |
| 2551 | |
| 2552 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 2553 | final DisplayChildWindowContainer child = getChildAt(i); |
| 2554 | stillDeferringRemoval |= child.checkCompleteDeferredRemoval(); |
| 2555 | if (getChildCount() == 0) { |
| 2556 | // If this display is pending to be removed because it contains an activity with |
| 2557 | // {@link ActivityRecord#mIsExiting} is true, this display may be removed when |
| 2558 | // completing the removal of the last activity from |
| 2559 | // {@link ActivityRecord#checkCompleteDeferredRemoval}. |
| 2560 | return false; |
| 2561 | } |
| 2562 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2563 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2564 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2565 | removeImmediately(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2566 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2567 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2568 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2569 | } |
| 2570 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 2571 | /** @return 'true' if removal of this display content is deferred due to active animation. */ |
| 2572 | boolean isRemovalDeferred() { |
| 2573 | return mDeferredRemoval; |
| 2574 | } |
| 2575 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2576 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 2577 | float dividerAnimationTarget) { |
| 2578 | boolean updated = false; |
| 2579 | |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2580 | for (int i = mTaskContainers.getChildCount() - 1; i >= 0; --i) { |
| 2581 | final ActivityStack stack = mTaskContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2582 | if (stack == null || !stack.isAdjustedForIme()) { |
| 2583 | continue; |
| 2584 | } |
| 2585 | |
| 2586 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 2587 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2588 | updated = true; |
| 2589 | } else { |
| 2590 | mDividerControllerLocked.mLastAnimationProgress = |
| 2591 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 2592 | mDividerControllerLocked.mLastDividerProgress = |
| 2593 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 2594 | updated |= stack.updateAdjustForIme( |
| 2595 | mDividerControllerLocked.mLastAnimationProgress, |
| 2596 | mDividerControllerLocked.mLastDividerProgress, |
| 2597 | false /* force */); |
| 2598 | } |
| 2599 | if (interpolatedValue >= 1f) { |
| 2600 | stack.endImeAdjustAnimation(); |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | return updated; |
| 2605 | } |
| 2606 | |
| 2607 | boolean clearImeAdjustAnimation() { |
| 2608 | boolean changed = false; |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2609 | for (int i = mTaskContainers.getChildCount() - 1; i >= 0; --i) { |
| 2610 | final ActivityStack stack = mTaskContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2611 | if (stack != null && stack.isAdjustedForIme()) { |
| 2612 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2613 | changed = true; |
| 2614 | } |
| 2615 | } |
| 2616 | return changed; |
| 2617 | } |
| 2618 | |
| 2619 | void beginImeAdjustAnimation() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2620 | for (int i = mTaskContainers.getChildCount() - 1; i >= 0; --i) { |
| 2621 | final ActivityStack stack = mTaskContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2622 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 2623 | stack.beginImeAdjustAnimation(); |
| 2624 | } |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | void adjustForImeIfNeeded() { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2629 | final WindowState imeWin = mInputMethodWindow; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2630 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 2631 | && !mDividerControllerLocked.isImeHideRequested(); |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 2632 | final ActivityStack dockedStack = getRootSplitScreenPrimaryTask(); |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2633 | final boolean dockVisible = dockedStack != null; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2634 | final Task topDockedTask = dockVisible ? dockedStack.getTask((t) -> true): null; |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2635 | final ActivityStack imeTargetStack = mWmService.getImeFocusStackLocked(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2636 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 2637 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 2638 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 2639 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2640 | final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2641 | final boolean imeHeightChanged = imeVisible && |
| 2642 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 2643 | |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2644 | // This includes a case where the docked stack is unminimizing and IME is visible for the |
| 2645 | // bottom side stack. The condition prevents adjusting the override task bounds for IME to |
| 2646 | // the minimized docked stack bounds. |
| 2647 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock() |
| 2648 | || (topDockedTask != null && imeOnBottom && !dockedStack.isAdjustedForIme() |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2649 | && dockedStack.getBounds().height() < topDockedTask.getBounds().height()); |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2650 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2651 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 2652 | // or both. There are three possible cases: |
| 2653 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 2654 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 2655 | // - If IME is not visible, divider is not moved and is normal width. |
| 2656 | |
| 2657 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2658 | for (int i = mTaskContainers.getChildCount() - 1; i >= 0; --i) { |
| 2659 | final ActivityStack stack = mTaskContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2660 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2661 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom) |
| 2662 | && stack.inSplitScreenWindowingMode()) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2663 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 2664 | } else { |
| 2665 | stack.resetAdjustedForIme(false); |
| 2666 | } |
| 2667 | } |
| 2668 | mDividerControllerLocked.setAdjustedForIme( |
| 2669 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 2670 | } else { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2671 | for (int i = mTaskContainers.getChildCount() - 1; i >= 0; --i) { |
| 2672 | final ActivityStack stack = mTaskContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2673 | stack.resetAdjustedForIme(!dockVisible); |
| 2674 | } |
| 2675 | mDividerControllerLocked.setAdjustedForIme( |
| 2676 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 2677 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2678 | mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2682 | for (int stackNdx = mTaskContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2683 | final ActivityStack stack = mTaskContainers.getChildAt(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2684 | stack.prepareFreezingTaskBounds(); |
| 2685 | } |
| 2686 | } |
| 2687 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2688 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2689 | getBounds(mTmpRect, newRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2690 | rotateBounds(mTmpRect, oldRotation, newRotation, bounds); |
| 2691 | } |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2692 | |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2693 | void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2694 | // Compute a transform matrix to undo the coordinate space transformation, |
| 2695 | // and present the window at the same physical position it previously occupied. |
| 2696 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2697 | createRotationMatrix( |
| 2698 | deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2699 | |
| 2700 | mTmpRectF.set(bounds); |
| 2701 | mTmpMatrix.mapRect(mTmpRectF); |
| 2702 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 2705 | static int deltaRotation(int oldRotation, int newRotation) { |
| 2706 | int delta = newRotation - oldRotation; |
| 2707 | if (delta < 0) delta += 4; |
| 2708 | return delta; |
| 2709 | } |
| 2710 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2711 | public void setRotationAnimation(ScreenRotationAnimation screenRotationAnimation) { |
| 2712 | if (mScreenRotationAnimation != null) { |
| 2713 | mScreenRotationAnimation.kill(); |
| 2714 | } |
| 2715 | mScreenRotationAnimation = screenRotationAnimation; |
| 2716 | } |
| 2717 | |
| 2718 | public ScreenRotationAnimation getRotationAnimation() { |
| 2719 | return mScreenRotationAnimation; |
| 2720 | } |
| 2721 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2722 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2723 | Matrix outMatrix) { |
| 2724 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 2725 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 2726 | displayHeight, outMatrix); |
| 2727 | } |
| 2728 | |
| 2729 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 2730 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 2731 | switch (rotation) { |
| 2732 | case ROTATION_0: |
| 2733 | outMatrix.reset(); |
| 2734 | break; |
| 2735 | case ROTATION_270: |
| 2736 | outMatrix.setRotate(270, 0, 0); |
| 2737 | outMatrix.postTranslate(0, displayHeight); |
| 2738 | outMatrix.postTranslate(rectTop, 0); |
| 2739 | break; |
| 2740 | case ROTATION_180: |
| 2741 | outMatrix.reset(); |
| 2742 | break; |
| 2743 | case ROTATION_90: |
| 2744 | outMatrix.setRotate(90, 0, 0); |
| 2745 | outMatrix.postTranslate(displayWidth, 0); |
| 2746 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 2747 | break; |
| 2748 | } |
| 2749 | } |
| 2750 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2751 | public void dumpDebug(ProtoOutputStream proto, long fieldId, |
| 2752 | @WindowTraceLogLevel int logLevel) { |
| 2753 | final long token = proto.start(fieldId); |
| 2754 | dumpDebugInner(proto, DISPLAY, logLevel); |
| 2755 | proto.write(com.android.server.am.ActivityDisplayProto.ID, mDisplayId); |
| 2756 | proto.write(SINGLE_TASK_INSTANCE, mSingleTaskInstance); |
| 2757 | final ActivityStack focusedStack = getFocusedStack(); |
| 2758 | if (focusedStack != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2759 | proto.write(FOCUSED_STACK_ID, focusedStack.getRootTaskId()); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2760 | final ActivityRecord focusedActivity = focusedStack.getDisplay().getResumedActivity(); |
| 2761 | if (focusedActivity != null) { |
| 2762 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 2763 | } |
| 2764 | } else { |
| 2765 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 2766 | } |
| 2767 | for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2768 | final ActivityStack stack = getStackAt(stackNdx); |
| 2769 | stack.dumpDebug(proto, com.android.server.am.ActivityDisplayProto.STACKS, logLevel); |
| 2770 | } |
| 2771 | proto.end(token); |
| 2772 | } |
| 2773 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 2774 | // TODO(proto-merge): Remove once protos for ActivityDisplay and DisplayContent are merged. |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2775 | public void dumpDebugInner(ProtoOutputStream proto, long fieldId, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2776 | @WindowTraceLogLevel int logLevel) { |
| 2777 | // Critical log level logs only visible elements to mitigate performance overheard |
| 2778 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 2779 | return; |
| 2780 | } |
| 2781 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2782 | final long token = proto.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2783 | super.dumpDebug(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2784 | proto.write(ID, mDisplayId); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2785 | for (int stackNdx = mTaskContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2786 | final ActivityStack stack = mTaskContainers.getChildAt(stackNdx); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2787 | stack.dumpDebugInnerStackOnly(proto, STACKS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2788 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2789 | mDividerControllerLocked.dumpDebug(proto, DOCKED_STACK_DIVIDER_CONTROLLER); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2790 | for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2791 | final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2792 | windowToken.dumpDebug(proto, ABOVE_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2793 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2794 | for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2795 | final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2796 | windowToken.dumpDebug(proto, BELOW_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2797 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2798 | for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2799 | final WindowToken windowToken = mImeWindowsContainers.getChildAt(i); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2800 | windowToken.dumpDebug(proto, IME_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2801 | } |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2802 | for (int i = mOverlayContainers.getChildCount() - 1; i >= 0; --i) { |
| 2803 | final WindowToken windowToken = mOverlayContainers.getChildAt(i); |
| 2804 | windowToken.dumpDebug(proto, OVERLAY_WINDOWS, logLevel); |
| 2805 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2806 | proto.write(DPI, mBaseDisplayDensity); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2807 | mDisplayInfo.dumpDebug(proto, DISPLAY_INFO); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2808 | proto.write(ROTATION, getRotation()); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2809 | final ScreenRotationAnimation screenRotationAnimation = getRotationAnimation(); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2810 | if (screenRotationAnimation != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2811 | screenRotationAnimation.dumpDebug(proto, SCREEN_ROTATION_ANIMATION); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2812 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2813 | mDisplayFrames.dumpDebug(proto, DISPLAY_FRAMES); |
| 2814 | mAppTransition.dumpDebug(proto, APP_TRANSITION); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2815 | if (mFocusedApp != null) { |
| 2816 | mFocusedApp.writeNameToProto(proto, FOCUSED_APP); |
| 2817 | } |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2818 | for (int i = mOpeningApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2819 | mOpeningApps.valueAt(i).writeIdentifierToProto(proto, OPENING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2820 | } |
| 2821 | for (int i = mClosingApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2822 | mClosingApps.valueAt(i).writeIdentifierToProto(proto, CLOSING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2823 | } |
| 2824 | for (int i = mChangingApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2825 | mChangingApps.valueAt(i).writeIdentifierToProto(proto, CHANGING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2826 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2827 | proto.end(token); |
| 2828 | } |
| 2829 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2830 | @Override |
| 2831 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 2832 | super.dump(pw, prefix, dumpAll); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2833 | pw.print(prefix); |
| 2834 | pw.println("Display: mDisplayId=" + mDisplayId + " stacks=" + getStackCount() + ( |
| 2835 | mSingleTaskInstance ? " mSingleTaskInstance" : "")); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2836 | final String subPrefix = " " + prefix; |
| 2837 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2838 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 2839 | pw.print("dpi"); |
| 2840 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 2841 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 2842 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 2843 | pw.print(" base="); |
| 2844 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 2845 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 2846 | } |
| 2847 | if (mDisplayScalingDisabled) { |
| 2848 | pw.println(" noscale"); |
| 2849 | } |
| 2850 | pw.print(" cur="); |
| 2851 | pw.print(mDisplayInfo.logicalWidth); |
| 2852 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 2853 | pw.print(" app="); |
| 2854 | pw.print(mDisplayInfo.appWidth); |
| 2855 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 2856 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 2857 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 2858 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 2859 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
| 2860 | pw.print(subPrefix + "deferred=" + mDeferredRemoval |
| 2861 | + " mLayoutNeeded=" + mLayoutNeeded); |
| 2862 | pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2863 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2864 | pw.println(); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2865 | pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq); |
| 2866 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2867 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 2868 | if (mLastFocus != mCurrentFocus) { |
| 2869 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 2870 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2871 | if (mPreferredTopFocusableStack != null) { |
| 2872 | pw.println(prefix + "mPreferredTopFocusableStack=" + mPreferredTopFocusableStack); |
| 2873 | } |
| 2874 | if (mLastFocusedStack != null) { |
| 2875 | pw.println(prefix + "mLastFocusedStack=" + mLastFocusedStack); |
| 2876 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2877 | if (mLosingFocus.size() > 0) { |
| 2878 | pw.println(); |
| 2879 | pw.println(" Windows losing focus:"); |
| 2880 | for (int i = mLosingFocus.size() - 1; i >= 0; i--) { |
| 2881 | final WindowState w = mLosingFocus.get(i); |
| 2882 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 2883 | pw.print(w); |
| 2884 | if (dumpAll) { |
| 2885 | pw.println(":"); |
| 2886 | w.dump(pw, " ", true); |
| 2887 | } else { |
| 2888 | pw.println(); |
| 2889 | } |
| 2890 | } |
| 2891 | } |
| 2892 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2893 | if (mLastStatusBarVisibility != 0) { |
| 2894 | pw.print(" mLastStatusBarVisibility=0x"); |
| 2895 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 2896 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2897 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2898 | pw.println(); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 2899 | mWallpaperController.dump(pw, " "); |
| 2900 | |
| 2901 | pw.println(); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 2902 | pw.print("mSystemGestureExclusion="); |
| 2903 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() > 0) { |
| 2904 | pw.println(mSystemGestureExclusion); |
| 2905 | } else { |
| 2906 | pw.println("<no lstnrs>"); |
| 2907 | } |
| 2908 | |
| 2909 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2910 | pw.println(prefix + "Application tokens in top down Z order:"); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2911 | for (int stackNdx = mTaskContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2912 | final ActivityStack stack = mTaskContainers.getChildAt(stackNdx); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2913 | stack.dump(pw, prefix + " ", dumpAll); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2914 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2915 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2916 | pw.println(); |
| 2917 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2918 | pw.println(); |
| 2919 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2920 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2921 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2922 | pw.print(" Exiting #"); pw.print(i); |
| 2923 | pw.print(' '); pw.print(token); |
| 2924 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2925 | token.dump(pw, " ", dumpAll); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2926 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2927 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 2928 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2929 | final ScreenRotationAnimation rotationAnimation = getRotationAnimation(); |
| 2930 | if (rotationAnimation != null) { |
| 2931 | pw.print(subPrefix); |
| 2932 | pw.println(" mScreenRotationAnimation:"); |
| 2933 | rotationAnimation.printTo(" ", pw); |
| 2934 | } else if (dumpAll) { |
| 2935 | pw.print(subPrefix); |
| 2936 | pw.println(" no ScreenRotationAnimation "); |
| 2937 | } |
| 2938 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 2939 | pw.println(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2940 | |
| 2941 | // Dump stack references |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 2942 | final ActivityStack homeStack = getRootHomeTask(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2943 | if (homeStack != null) { |
| 2944 | pw.println(prefix + "homeStack=" + homeStack.getName()); |
| 2945 | } |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 2946 | final ActivityStack pinnedStack = getRootPinnedTask(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2947 | if (pinnedStack != null) { |
| 2948 | pw.println(prefix + "pinnedStack=" + pinnedStack.getName()); |
| 2949 | } |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 2950 | final ActivityStack splitScreenPrimaryStack = getRootSplitScreenPrimaryTask(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2951 | if (splitScreenPrimaryStack != null) { |
| 2952 | pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName()); |
| 2953 | } |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 2954 | final ActivityStack recentsStack = |
| 2955 | getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2956 | if (recentsStack != null) { |
| 2957 | pw.println(prefix + "recentsStack=" + recentsStack.getName()); |
| 2958 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2959 | |
| 2960 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2961 | mDividerControllerLocked.dump(prefix, pw); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2962 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2963 | mPinnedStackControllerLocked.dump(prefix, pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2964 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2965 | pw.println(); |
| 2966 | mDisplayFrames.dump(prefix, pw); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2967 | pw.println(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2968 | mDisplayPolicy.dump(prefix, pw); |
| 2969 | pw.println(); |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2970 | mDisplayRotation.dump(prefix, pw); |
| 2971 | pw.println(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2972 | mInputMonitor.dump(pw, " "); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 2973 | pw.println(); |
| 2974 | mInsetsStateController.dump(prefix, pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2975 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2976 | |
| 2977 | @Override |
| 2978 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2979 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2983 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2984 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2985 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2986 | /** Returns true if the stack in the windowing mode is visible. */ |
| 2987 | boolean isStackVisible(int windowingMode) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2988 | final ActivityStack stack = getTopStackInWindowingMode(windowingMode); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2989 | return stack != null && stack.isVisible(); |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 2990 | } |
| 2991 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2992 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2993 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2994 | final int x = (int) xf; |
| 2995 | final int y = (int) yf; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2996 | final WindowState touchedWin = getWindow(w -> { |
| 2997 | final int flags = w.mAttrs.flags; |
| 2998 | if (!w.isVisibleLw()) { |
| 2999 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3000 | } |
| 3001 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3002 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3003 | } |
| 3004 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3005 | w.getVisibleBounds(mTmpRect); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3006 | if (!mTmpRect.contains(x, y)) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3007 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3008 | } |
| 3009 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3010 | w.getTouchableRegion(mTmpRegion); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3011 | |
| 3012 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3013 | return mTmpRegion.contains(x, y) || touchFlags == 0; |
| 3014 | }); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3015 | |
| 3016 | return touchedWin; |
| 3017 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 3018 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3019 | boolean canAddToastWindowForUid(int uid) { |
| 3020 | // We allow one toast window per UID being shown at a time. |
Svet Ganov | daca8ee | 2017-01-21 17:40:40 -0800 | [diff] [blame] | 3021 | // Also if the app is focused adding more than one toast at |
| 3022 | // a time for better backwards compatibility. |
| 3023 | final WindowState focusedWindowForUid = getWindow(w -> |
| 3024 | w.mOwnerUid == uid && w.isFocused()); |
| 3025 | if (focusedWindowForUid != null) { |
| 3026 | return true; |
| 3027 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3028 | final WindowState win = getWindow(w -> |
| 3029 | w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3030 | && !w.mWindowRemovalAllowed); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3031 | return win == null; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3034 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3035 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 3036 | return; |
| 3037 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3038 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3039 | // Used to communicate the old focus to the callback method. |
| 3040 | mTmpWindow = oldFocus; |
| 3041 | |
| 3042 | forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3043 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3044 | |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3045 | /** |
| 3046 | * Looking for the focused window on this display if the top focused display hasn't been |
| 3047 | * found yet (topFocusedDisplayId is INVALID_DISPLAY) or per-display focused was allowed. |
| 3048 | * |
| 3049 | * @param topFocusedDisplayId Id of the top focused display. |
| 3050 | * @return The focused window or null if there isn't any or no need to seek. |
| 3051 | */ |
| 3052 | WindowState findFocusedWindowIfNeeded(int topFocusedDisplayId) { |
| 3053 | return (mWmService.mPerDisplayFocusEnabled || topFocusedDisplayId == INVALID_DISPLAY) |
| 3054 | ? findFocusedWindow() : null; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3055 | } |
| 3056 | |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3057 | WindowState findFocusedWindow() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3058 | mTmpWindow = null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3059 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3060 | forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3061 | |
| 3062 | if (mTmpWindow == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3063 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: No focusable windows."); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3064 | return null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3065 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3066 | return mTmpWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3069 | /** |
| 3070 | * Update the focused window and make some adjustments if the focus has changed. |
| 3071 | * |
| 3072 | * @param mode Indicates the situation we are in. Possible modes are: |
| 3073 | * {@link WindowManagerService#UPDATE_FOCUS_NORMAL}, |
| 3074 | * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES}, |
| 3075 | * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES}, |
| 3076 | * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS} |
| 3077 | * @param updateInputWindows Whether to sync the window information to the input module. |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3078 | * @param topFocusedDisplayId Display id of current top focused display. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3079 | * @return {@code true} if the focused window has changed. |
| 3080 | */ |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3081 | boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, |
| 3082 | int topFocusedDisplayId) { |
| 3083 | WindowState newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3084 | if (mCurrentFocus == newFocus) { |
| 3085 | return false; |
| 3086 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3087 | boolean imWindowChanged = false; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3088 | final WindowState imWindow = mInputMethodWindow; |
| 3089 | if (imWindow != null) { |
| 3090 | final WindowState prevTarget = mInputMethodTarget; |
| 3091 | final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/); |
| 3092 | imWindowChanged = prevTarget != newTarget; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3093 | |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3094 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS |
| 3095 | && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 3096 | assignWindowLayers(false /* setLayoutNeeded */); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | if (imWindowChanged) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3101 | mWmService.mWindowsChanged = true; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3102 | setLayoutNeeded(); |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3103 | newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3104 | } |
| 3105 | if (mCurrentFocus != newFocus) { |
| 3106 | mWmService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3107 | } |
| 3108 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3109 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "Changing focus from %s to %s displayId=%d Callers=%s", |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3110 | mCurrentFocus, newFocus, getDisplayId(), Debug.getCallers(4)); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3111 | final WindowState oldFocus = mCurrentFocus; |
| 3112 | mCurrentFocus = newFocus; |
| 3113 | mLosingFocus.remove(newFocus); |
| 3114 | |
| 3115 | if (newFocus != null) { |
| 3116 | mWinAddedSinceNullFocus.clear(); |
| 3117 | mWinRemovedSinceNullFocus.clear(); |
| 3118 | |
| 3119 | if (newFocus.canReceiveKeys()) { |
| 3120 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 3121 | // This is to protect against bugs if someone pauses dispatching but |
| 3122 | // forgets to resume. |
| 3123 | newFocus.mToken.paused = false; |
| 3124 | } |
| 3125 | } |
| 3126 | |
Vishnu Nair | f6ef1c7 | 2020-01-23 16:28:33 -0800 | [diff] [blame] | 3127 | onWindowFocusChanged(oldFocus, newFocus); |
| 3128 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3129 | int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3130 | |
| 3131 | if (imWindowChanged && oldFocus != mInputMethodWindow) { |
| 3132 | // Focus of the input method window changed. Perform layout if needed. |
| 3133 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3134 | performLayout(true /*initial*/, updateInputWindows); |
| 3135 | focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT; |
| 3136 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 3137 | // Client will do the layout, but we need to assign layers |
| 3138 | // for handleNewWindowLocked() below. |
| 3139 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3144 | // The change in focus caused us to need to do a layout. Okay. |
| 3145 | setLayoutNeeded(); |
| 3146 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3147 | performLayout(true /*initial*/, updateInputWindows); |
| 3148 | } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3149 | mWmService.mRoot.performSurfacePlacement(false); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 3154 | // If we defer assigning layers, then the caller is responsible for doing this part. |
| 3155 | getInputMonitor().setInputFocusLw(newFocus, updateInputWindows); |
| 3156 | } |
| 3157 | |
| 3158 | adjustForImeIfNeeded(); |
| 3159 | |
| 3160 | // We may need to schedule some toast windows to be removed. The toasts for an app that |
| 3161 | // does not have input focus are removed within a timeout to prevent apps to redress |
| 3162 | // other apps' UI. |
| 3163 | scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus); |
| 3164 | |
| 3165 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3166 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 3167 | } |
| 3168 | return true; |
| 3169 | } |
| 3170 | |
Vishnu Nair | f6ef1c7 | 2020-01-23 16:28:33 -0800 | [diff] [blame] | 3171 | private static void onWindowFocusChanged(WindowState oldFocus, WindowState newFocus) { |
| 3172 | final Task focusedTask = newFocus != null ? newFocus.getTask() : null; |
| 3173 | final Task unfocusedTask = oldFocus != null ? oldFocus.getTask() : null; |
| 3174 | if (focusedTask == unfocusedTask) { |
| 3175 | return; |
| 3176 | } |
| 3177 | if (focusedTask != null) { |
| 3178 | focusedTask.onWindowFocusChanged(true /* hasFocus */); |
| 3179 | } |
| 3180 | if (unfocusedTask != null) { |
| 3181 | unfocusedTask.onWindowFocusChanged(false /* hasFocus */); |
| 3182 | } |
| 3183 | } |
| 3184 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3185 | /** |
| 3186 | * Set the new focused app to this display. |
| 3187 | * |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3188 | * @param newFocus the new focused {@link ActivityRecord}. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3189 | * @return true if the focused app is changed. |
| 3190 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3191 | boolean setFocusedApp(ActivityRecord newFocus) { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3192 | if (newFocus != null) { |
| 3193 | final DisplayContent appDisplay = newFocus.getDisplayContent(); |
| 3194 | if (appDisplay != this) { |
| 3195 | throw new IllegalStateException(newFocus + " is not on " + getName() |
| 3196 | + " but " + ((appDisplay != null) ? appDisplay.getName() : "none")); |
| 3197 | } |
| 3198 | } |
| 3199 | if (mFocusedApp == newFocus) { |
| 3200 | return false; |
| 3201 | } |
| 3202 | mFocusedApp = newFocus; |
| 3203 | getInputMonitor().setFocusedAppLw(newFocus); |
| 3204 | updateTouchExcludeRegion(); |
| 3205 | return true; |
| 3206 | } |
| 3207 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3208 | /** Updates the layer assignment of windows on this display. */ |
| 3209 | void assignWindowLayers(boolean setLayoutNeeded) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3210 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers"); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3211 | assignChildLayers(getPendingTransaction()); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3212 | if (setLayoutNeeded) { |
| 3213 | setLayoutNeeded(); |
| 3214 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3215 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3216 | // We accumlate the layer changes in-to "getPendingTransaction()" but we defer |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3217 | // the application of this transaction until the animation pass triggers |
| 3218 | // prepareSurfaces. This allows us to synchronize Z-ordering changes with |
| 3219 | // the hiding and showing of surfaces. |
| 3220 | scheduleAnimation(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3221 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3224 | // TODO: This should probably be called any time a visual change is made to the hierarchy like |
| 3225 | // moving containers or resizing them. Need to investigate the best way to have it automatically |
| 3226 | // happen so we don't run into issues with programmers forgetting to do it. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3227 | void layoutAndAssignWindowLayersIfNeeded() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3228 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3229 | setLayoutNeeded(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3230 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3231 | if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3232 | false /*updateInputWindows*/)) { |
| 3233 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3234 | } |
| 3235 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3236 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3237 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3238 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3241 | /** Returns true if a leaked surface was destroyed */ |
| 3242 | boolean destroyLeakedSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3243 | // Used to indicate that a surface was leaked. |
| 3244 | mTmpWindow = null; |
| 3245 | forAllWindows(w -> { |
| 3246 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3247 | if (wsa.mSurfaceController == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3248 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3249 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3250 | if (!mWmService.mSessions.contains(wsa.mSession)) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3251 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3252 | + w + " surface=" + wsa.mSurfaceController |
| 3253 | + " token=" + w.mToken |
| 3254 | + " pid=" + w.mSession.mPid |
| 3255 | + " uid=" + w.mSession.mUid); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3256 | wsa.destroySurface(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3257 | mWmService.mForceRemoves.add(w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3258 | mTmpWindow = w; |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3259 | } else if (w.mActivityRecord != null && !w.mActivityRecord.isClientVisible()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3260 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3261 | + w + " surface=" + wsa.mSurfaceController |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3262 | + " token=" + w.mActivityRecord); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3263 | ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE LEAK DESTROY: %s", w); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3264 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3265 | mTmpWindow = w; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3266 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3267 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3268 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3269 | return mTmpWindow != null; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3272 | boolean hasAlertWindowSurfaces() { |
| 3273 | for (int i = mWmService.mSessions.size() - 1; i >= 0; --i) { |
| 3274 | if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces(this)) { |
| 3275 | return true; |
| 3276 | } |
| 3277 | } |
| 3278 | return false; |
| 3279 | } |
| 3280 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3281 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3282 | * Set input method window for the display. |
| 3283 | * @param win Set when window added or Null when destroyed. |
| 3284 | */ |
| 3285 | void setInputMethodWindowLocked(WindowState win) { |
| 3286 | mInputMethodWindow = win; |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3287 | // Update display configuration for IME process. |
| 3288 | if (mInputMethodWindow != null) { |
| 3289 | final int imePid = mInputMethodWindow.mSession.mPid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3290 | mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid, |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3291 | mInputMethodWindow.getDisplayId()); |
| 3292 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3293 | computeImeTarget(true /* updateImeTarget */); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3294 | mInsetsStateController.getSourceProvider(ITYPE_IME).setWindow(win, |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 3295 | null /* frameProvider */, null /* imeFrameProvider */); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | /** |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3299 | * Determine and return the window that should be the IME target. |
| 3300 | * @param updateImeTarget If true the system IME target will be updated to match what we found. |
| 3301 | * @return The window that should be used as the IME target or null if there isn't any. |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3302 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3303 | WindowState computeImeTarget(boolean updateImeTarget) { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3304 | if (mInputMethodWindow == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3305 | // There isn't an IME so there shouldn't be a target...That was easy! |
| 3306 | if (updateImeTarget) { |
| 3307 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3308 | + mInputMethodTarget + " to null since mInputMethodWindow is null"); |
| 3309 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3310 | } |
| 3311 | return null; |
| 3312 | } |
| 3313 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3314 | final WindowState curTarget = mInputMethodTarget; |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 3315 | if (!canUpdateImeTarget()) { |
| 3316 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target"); |
| 3317 | return curTarget; |
| 3318 | } |
| 3319 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3320 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 3321 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 3322 | // IME/target. For now only look for input windows on the main screen. |
Wale Ogunwale | 8e44f6c | 2017-03-09 15:25:10 -0800 | [diff] [blame] | 3323 | mUpdateImeTarget = updateImeTarget; |
| 3324 | WindowState target = getWindow(mComputeImeTargetPredicate); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3325 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3326 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3327 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 3328 | // to be on top of it, but it is not -really- where input will go. So look down below |
| 3329 | // for a real window to target... |
| 3330 | if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3331 | final ActivityRecord activity = target.mActivityRecord; |
| 3332 | if (activity != null) { |
| 3333 | final WindowState betterTarget = activity.getImeTargetBelowWindow(target); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3334 | if (betterTarget != null) { |
| 3335 | target = betterTarget; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3336 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3340 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM, |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3341 | "Proposed new IME target: " + target + " for display: " + getDisplayId()); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3342 | |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3343 | // Now, a special case -- if the last target's window is in the process of exiting, but |
Tarandeep Singh | 2d0aca4 | 2019-03-28 14:08:58 -0700 | [diff] [blame] | 3344 | // not removed, keep on the last target to avoid IME flicker. |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3345 | if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw() |
Tarandeep Singh | 2d0aca4 | 2019-03-28 14:08:58 -0700 | [diff] [blame] | 3346 | && curTarget.isClosing()) { |
| 3347 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Not changing target till current window is" |
| 3348 | + " closing and not removed"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3349 | return curTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3352 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target |
| 3353 | + " updateImeTarget=" + updateImeTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3354 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3355 | if (target == null) { |
| 3356 | if (updateImeTarget) { |
| 3357 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 3358 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" |
| 3359 | + Debug.getCallers(4) : "")); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3360 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | return null; |
| 3364 | } |
| 3365 | |
| 3366 | if (updateImeTarget) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3367 | ActivityRecord activity = curTarget == null ? null : curTarget.mActivityRecord; |
| 3368 | if (activity != null) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3369 | |
| 3370 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 3371 | // to look at all windows below the current target that are in this app, finding the |
| 3372 | // highest visible one in layering. |
| 3373 | WindowState highestTarget = null; |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 3374 | if (activity.isAnimating(PARENTS | TRANSITION)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3375 | highestTarget = activity.getHighestAnimLayerWindow(curTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | if (highestTarget != null) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3379 | if (DEBUG_INPUT_METHOD) { |
| 3380 | Slog.v(TAG_WM, mAppTransition + " " + highestTarget + " animating=" |
| 3381 | + highestTarget.isAnimating(TRANSITION | PARENTS)); |
| 3382 | } |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3383 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3384 | if (mAppTransition.isTransitionSet()) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3385 | // If we are currently setting up for an animation, hold everything until we |
| 3386 | // can find out what will happen. |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3387 | setInputMethodTarget(highestTarget, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3388 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3392 | |
| 3393 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 3394 | + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3395 | setInputMethodTarget(target, false); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3396 | } |
| 3397 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3398 | return target; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3401 | /** |
| 3402 | * Calling {@link #computeImeTarget(boolean)} to update the input method target window in |
| 3403 | * the candidate app window token if needed. |
| 3404 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3405 | void computeImeTargetIfNeeded(ActivityRecord candidate) { |
| 3406 | if (mInputMethodTarget != null && mInputMethodTarget.mActivityRecord == candidate) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3407 | computeImeTarget(true /* updateImeTarget */); |
| 3408 | } |
| 3409 | } |
| 3410 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 3411 | boolean isImeAttachedToApp() { |
| 3412 | return (mInputMethodTarget != null && mInputMethodTarget.mActivityRecord != null |
| 3413 | && mInputMethodTarget.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 3414 | // An activity with override bounds should be letterboxed inside its parent bounds, |
| 3415 | // so it doesn't fill the screen. |
| 3416 | && mInputMethodTarget.mActivityRecord.matchParentBounds()); |
| 3417 | } |
| 3418 | |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3419 | private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3420 | if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3421 | return; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3424 | mInputMethodTarget = target; |
| 3425 | mInputMethodTargetWaitingAnim = targetWaitingAnim; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3426 | assignWindowLayers(false /* setLayoutNeeded */); |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 3427 | mInputMethodControlTarget = computeImeControlTarget(); |
| 3428 | mInsetsStateController.onImeTargetChanged(mInputMethodControlTarget); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3429 | updateImeParent(); |
| 3430 | } |
| 3431 | |
| 3432 | private void updateImeParent() { |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 3433 | // Force attaching IME to the display when magnifying, or it would be magnified with |
| 3434 | // target app together. |
| 3435 | final boolean shouldAttachToDisplay = (mMagnificationSpec != null); |
| 3436 | final SurfaceControl newParent = |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3437 | shouldAttachToDisplay ? mWindowContainers.getSurfaceControl() : computeImeParent(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3438 | if (newParent != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3439 | getPendingTransaction().reparent(mImeWindowsContainers.mSurfaceControl, newParent); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3440 | scheduleAnimation(); |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | /** |
| 3445 | * Computes the window the IME should be attached to. |
| 3446 | */ |
| 3447 | @VisibleForTesting |
| 3448 | SurfaceControl computeImeParent() { |
| 3449 | |
| 3450 | // Attach it to app if the target is part of an app and such app is covering the entire |
| 3451 | // screen. If it's not covering the entire screen the IME might extend beyond the apps |
| 3452 | // bounds. |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 3453 | if (isImeAttachedToApp()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3454 | return mInputMethodTarget.mActivityRecord.getSurfaceControl(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | // Otherwise, we just attach it to the display. |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3458 | return mWindowContainers.getSurfaceControl(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3459 | } |
| 3460 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 3461 | /** |
| 3462 | * Computes which control-target the IME should be attached to. |
| 3463 | */ |
| 3464 | @VisibleForTesting |
| 3465 | InsetsControlTarget computeImeControlTarget() { |
| 3466 | if (!isImeAttachedToApp() && mRemoteInsetsControlTarget != null) { |
| 3467 | return mRemoteInsetsControlTarget; |
| 3468 | } |
| 3469 | |
| 3470 | // Otherwise, we just use the ime target |
| 3471 | return mInputMethodTarget; |
| 3472 | } |
| 3473 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3474 | void setLayoutNeeded() { |
| 3475 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3476 | mLayoutNeeded = true; |
| 3477 | } |
| 3478 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3479 | private void clearLayoutNeeded() { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3480 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3481 | mLayoutNeeded = false; |
| 3482 | } |
| 3483 | |
| 3484 | boolean isLayoutNeeded() { |
| 3485 | return mLayoutNeeded; |
| 3486 | } |
| 3487 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3488 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 3489 | if (mTokenMap.isEmpty()) { |
| 3490 | return; |
| 3491 | } |
| 3492 | pw.println(" Display #" + mDisplayId); |
| 3493 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 3494 | while (it.hasNext()) { |
| 3495 | final WindowToken token = it.next(); |
| 3496 | pw.print(" "); |
| 3497 | pw.print(token); |
| 3498 | if (dumpAll) { |
| 3499 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3500 | token.dump(pw, " ", dumpAll); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3501 | } else { |
| 3502 | pw.println(); |
| 3503 | } |
| 3504 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3505 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3506 | if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty() || !mChangingApps.isEmpty()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3507 | pw.println(); |
| 3508 | if (mOpeningApps.size() > 0) { |
| 3509 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 3510 | } |
| 3511 | if (mClosingApps.size() > 0) { |
| 3512 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 3513 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3514 | if (mChangingApps.size() > 0) { |
| 3515 | pw.print(" mChangingApps="); pw.println(mChangingApps); |
| 3516 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | mUnknownAppVisibilityController.dump(pw, " "); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3522 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3523 | final int[] index = new int[1]; |
| 3524 | forAllWindows(w -> { |
| 3525 | final WindowStateAnimator wAnim = w.mWinAnimator; |
| 3526 | pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim); |
| 3527 | index[0] = index[0] + 1; |
| 3528 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3531 | /** |
| 3532 | * Starts the Keyguard exit animation on all windows that don't belong to an app token. |
| 3533 | */ |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3534 | void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade, |
| 3535 | boolean subtle) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3536 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3537 | forAllWindows(w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3538 | if (w.mActivityRecord == null && policy.canBeHiddenByKeyguardLw(w) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 3539 | && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) { |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3540 | w.startAnimation(policy.createHiddenByKeyguardExit( |
| 3541 | onWallpaper, goingToShade, subtle)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3542 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3543 | }, true /* traverseTopToBottom */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3544 | } |
| 3545 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3546 | /** @return {@code true} if there is window to wait before enabling the screen. */ |
| 3547 | boolean shouldWaitForSystemDecorWindowsOnBoot() { |
| 3548 | if (!isDefaultDisplay && !supportsSystemDecorations()) { |
| 3549 | // Nothing to wait because the secondary display doesn't support system decorations, |
| 3550 | // there is no wallpaper, keyguard (status bar) or application (home) window to show |
| 3551 | // during booting. |
| 3552 | return false; |
| 3553 | } |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3554 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3555 | final SparseBooleanArray drawnWindowTypes = new SparseBooleanArray(); |
| 3556 | // Presuppose keyguard is drawn because if its window isn't attached, we don't know if it |
| 3557 | // wants to be shown or hidden, then it should not delay enabling the screen. |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3558 | drawnWindowTypes.put(TYPE_NOTIFICATION_SHADE, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3559 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3560 | final WindowState visibleNotDrawnWindow = getWindow(w -> { |
| 3561 | if (w.mViewVisibility == View.VISIBLE && !w.mObscured && !w.isDrawnLw()) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3562 | return true; |
| 3563 | } |
| 3564 | if (w.isDrawnLw()) { |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3565 | final int type = w.mAttrs.type; |
| 3566 | if (type == TYPE_BOOT_PROGRESS || type == TYPE_BASE_APPLICATION |
| 3567 | || type == TYPE_WALLPAPER) { |
| 3568 | drawnWindowTypes.put(type, true); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3569 | } else if (type == TYPE_NOTIFICATION_SHADE) { |
| 3570 | drawnWindowTypes.put(TYPE_NOTIFICATION_SHADE, |
| 3571 | mWmService.mPolicy.isKeyguardDrawnLw()); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3572 | } |
| 3573 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3574 | return false; |
| 3575 | }); |
| 3576 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3577 | if (visibleNotDrawnWindow != null) { |
| 3578 | // Wait for the visible window to be drawn. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3579 | return true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3582 | // if the wallpaper service is disabled on the device, we're never going to have |
| 3583 | // wallpaper, don't bother waiting for it |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3584 | boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean( |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3585 | com.android.internal.R.bool.config_enableWallpaperService) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3586 | && mWmService.mContext.getResources().getBoolean( |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3587 | com.android.internal.R.bool.config_checkWallpaperAtBoot) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3588 | && !mWmService.mOnlyCore; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3589 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3590 | final boolean haveBootMsg = drawnWindowTypes.get(TYPE_BOOT_PROGRESS); |
| 3591 | final boolean haveApp = drawnWindowTypes.get(TYPE_BASE_APPLICATION); |
| 3592 | final boolean haveWallpaper = drawnWindowTypes.get(TYPE_WALLPAPER); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3593 | final boolean haveKeyguard = drawnWindowTypes.get(TYPE_NOTIFICATION_SHADE); |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3594 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3595 | ProtoLog.i(WM_DEBUG_SCREEN_ON, |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3596 | "******** booted=%b msg=%b haveBoot=%b haveApp=%b haveWall=%b " |
| 3597 | + "wallEnabled=%b haveKeyguard=%b", |
| 3598 | mWmService.mSystemBooted, mWmService.mShowingBootMessages, haveBootMsg, |
| 3599 | haveApp, haveWallpaper, wallpaperEnabled, haveKeyguard); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3600 | |
| 3601 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 3602 | // message is actually displayed. |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3603 | if (!mWmService.mSystemBooted && !haveBootMsg) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3604 | return true; |
| 3605 | } |
| 3606 | |
| 3607 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 3608 | // we have the application and wallpaper. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3609 | if (mWmService.mSystemBooted |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3610 | && ((!haveApp && !haveKeyguard) || (wallpaperEnabled && !haveWallpaper))) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3611 | return true; |
| 3612 | } |
| 3613 | |
| 3614 | return false; |
| 3615 | } |
| 3616 | |
Jorim Jaggi | 8f52087 | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3617 | void updateWindowsForAnimator() { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3618 | forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3621 | boolean isInputMethodClientFocus(int uid, int pid) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3622 | final WindowState imFocus = computeImeTarget(false /* updateImeTarget */); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3623 | if (imFocus == null) { |
| 3624 | return false; |
| 3625 | } |
| 3626 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3627 | if (DEBUG_INPUT_METHOD) { |
| 3628 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3629 | Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId); |
| 3630 | Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3631 | } |
| 3632 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3633 | if (DEBUG_INPUT_METHOD) { |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3634 | Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid |
| 3635 | + "/" + imFocus.mSession.mPid); |
| 3636 | Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3639 | return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | boolean hasSecureWindowOnScreen() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3643 | final WindowState win = getWindow( |
| 3644 | w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0); |
| 3645 | return win != null; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3648 | void hideTransientBars() { |
| 3649 | // TODO(b/118118435): Remove this after migration |
| 3650 | final int transientFlags = View.STATUS_BAR_TRANSIENT | View.NAVIGATION_BAR_TRANSIENT; |
| 3651 | statusBarVisibilityChanged(mLastStatusBarVisibility & ~transientFlags); |
| 3652 | |
| 3653 | getInsetsPolicy().hideTransient(); |
| 3654 | } |
| 3655 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3656 | void statusBarVisibilityChanged(int visibility) { |
| 3657 | mLastStatusBarVisibility = visibility; |
| 3658 | visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility); |
| 3659 | updateStatusBarVisibilityLocked(visibility); |
| 3660 | } |
| 3661 | |
| 3662 | private boolean updateStatusBarVisibilityLocked(int visibility) { |
| 3663 | if (mLastDispatchedSystemUiVisibility == visibility) { |
| 3664 | return false; |
| 3665 | } |
| 3666 | final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility) |
| 3667 | // We are only interested in differences of one of the |
| 3668 | // clearable flags... |
| 3669 | & View.SYSTEM_UI_CLEARABLE_FLAGS |
| 3670 | // ...if it has actually been cleared. |
| 3671 | & ~visibility; |
| 3672 | |
| 3673 | mLastDispatchedSystemUiVisibility = visibility; |
| 3674 | if (isDefaultDisplay) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3675 | mWmService.mInputManager.setSystemUiVisibility(visibility); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3676 | } |
| 3677 | updateSystemUiVisibility(visibility, globalDiff); |
| 3678 | return true; |
| 3679 | } |
| 3680 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3681 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3682 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3683 | try { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3684 | final int curValue = w.mSystemUiVisibility; |
| 3685 | final int diff = (curValue ^ visibility) & globalDiff; |
| 3686 | final int newValue = (curValue & ~diff) | (visibility & diff); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3687 | if (newValue != curValue) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3688 | w.mSeq++; |
| 3689 | w.mSystemUiVisibility = newValue; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3690 | } |
Tiger Huang | 41ae5e8 | 2020-01-17 18:17:20 +0800 | [diff] [blame] | 3691 | if ((newValue != curValue || w.mAttrs.hasSystemUiListeners) |
| 3692 | && ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3693 | w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3694 | visibility, newValue, diff); |
| 3695 | } |
| 3696 | } catch (RemoteException e) { |
| 3697 | // so sorry |
| 3698 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3699 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3702 | void reevaluateStatusBarVisibility() { |
| 3703 | int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 3704 | if (updateStatusBarVisibilityLocked(visibility)) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3705 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3706 | } |
| 3707 | } |
| 3708 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3709 | void onWindowFreezeTimeout() { |
| 3710 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3711 | mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3712 | |
| 3713 | forAllWindows(w -> { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3714 | if (!w.getOrientationChanging()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3715 | return; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3716 | } |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 3717 | w.orientationChangeTimedOut(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3718 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3719 | - mWmService.mDisplayFreezeTime); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3720 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3721 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3722 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3723 | } |
| 3724 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3725 | // TODO: Super crazy long method that should be broken down... |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3726 | void applySurfaceChangesTransaction(boolean recoveringMemory) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3727 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3728 | |
| 3729 | mTmpUpdateAllDrawn.clear(); |
| 3730 | |
| 3731 | int repeats = 0; |
| 3732 | do { |
| 3733 | repeats++; |
| 3734 | if (repeats > 6) { |
| 3735 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 3736 | clearLayoutNeeded(); |
| 3737 | break; |
| 3738 | } |
| 3739 | |
| 3740 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner", |
| 3741 | pendingLayoutChanges); |
| 3742 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 3743 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 3744 | mWallpaperController.adjustWallpaperWindows(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 3747 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3748 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3749 | if (updateOrientation()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3750 | setLayoutNeeded(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 3751 | sendNewConfiguration(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3752 | } |
| 3753 | } |
| 3754 | |
| 3755 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3756 | setLayoutNeeded(); |
| 3757 | } |
| 3758 | |
| 3759 | // FIRST LOOP: Perform a layout, if needed. |
| 3760 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 3761 | performLayout(repeats == 1, false /* updateInputWindows */); |
| 3762 | } else { |
| 3763 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 3764 | } |
| 3765 | |
| 3766 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating. |
| 3767 | pendingLayoutChanges = 0; |
| 3768 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3769 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyPostLayoutPolicy"); |
| 3770 | try { |
| 3771 | mDisplayPolicy.beginPostLayoutPolicyLw(); |
| 3772 | forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */); |
| 3773 | pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw(); |
| 3774 | } finally { |
| 3775 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3776 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3777 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 3778 | "after finishPostLayoutPolicyLw", pendingLayoutChanges); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3779 | mInsetsStateController.onPostLayout(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3780 | } while (pendingLayoutChanges != 0); |
| 3781 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3782 | mTmpApplySurfaceChangesTransactionState.reset(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3783 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3784 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyWindowSurfaceChanges"); |
| 3785 | try { |
| 3786 | forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */); |
| 3787 | } finally { |
| 3788 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3789 | } |
Jorim Jaggi | 6b0f846 | 2018-01-05 17:23:47 +0100 | [diff] [blame] | 3790 | prepareSurfaces(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3791 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3792 | mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3793 | mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId, |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3794 | mLastHasContent, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3795 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate, |
| 3796 | mTmpApplySurfaceChangesTransactionState.preferredModeId, |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 3797 | mTmpApplySurfaceChangesTransactionState.preferMinimalPostProcessing, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3798 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 3799 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3800 | final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible(); |
| 3801 | if (wallpaperVisible != mLastWallpaperVisible) { |
| 3802 | mLastWallpaperVisible = wallpaperVisible; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3803 | mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3806 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3807 | final ActivityRecord activity = mTmpUpdateAllDrawn.removeLast(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3808 | // See if any windows have been drawn, so they (and others associated with them) |
| 3809 | // can now be shown. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3810 | activity.updateAllDrawn(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3811 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3814 | private void updateBounds() { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3815 | calculateBounds(mDisplayInfo, mTmpBounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3816 | setBounds(mTmpBounds); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3817 | if (mPortalWindowHandle != null && mParentSurfaceControl != null) { |
| 3818 | mPortalWindowHandle.touchableRegion.getBounds(mTmpRect); |
| 3819 | if (!mTmpBounds.equals(mTmpRect)) { |
| 3820 | mPortalWindowHandle.touchableRegion.set(mTmpBounds); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3821 | getPendingTransaction().setInputWindowInfo( |
| 3822 | mParentSurfaceControl, mPortalWindowHandle); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3823 | } |
| 3824 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | // Determines the current display bounds based on the current state |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3828 | private void calculateBounds(DisplayInfo displayInfo, Rect out) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3829 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3830 | final int rotation = displayInfo.rotation; |
| 3831 | boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3832 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 3833 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3834 | int width = displayInfo.logicalWidth; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3835 | int left = (physWidth - width) / 2; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3836 | int height = displayInfo.logicalHeight; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3837 | int top = (physHeight - height) / 2; |
| 3838 | out.set(left, top, left + width, top + height); |
| 3839 | } |
| 3840 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3841 | private void getBounds(Rect out, int orientation) { |
| 3842 | getBounds(out); |
| 3843 | |
| 3844 | // Rotate the Rect if needed. |
| 3845 | final int currentRotation = mDisplayInfo.rotation; |
| 3846 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 3847 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 3848 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 3849 | mTmpRectF.set(out); |
| 3850 | mTmpMatrix.mapRect(mTmpRectF); |
| 3851 | mTmpRectF.round(out); |
| 3852 | } |
| 3853 | } |
| 3854 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 3855 | /** @returns the orientation of the display when it's rotation is ROTATION_0. */ |
| 3856 | int getNaturalOrientation() { |
| 3857 | return mBaseDisplayWidth < mBaseDisplayHeight |
| 3858 | ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
| 3859 | } |
| 3860 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3861 | void performLayout(boolean initial, boolean updateInputWindows) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3862 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "performLayout"); |
| 3863 | try { |
| 3864 | performLayoutNoTrace(initial, updateInputWindows); |
| 3865 | } finally { |
| 3866 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | private void performLayoutNoTrace(boolean initial, boolean updateInputWindows) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3871 | if (!isLayoutNeeded()) { |
| 3872 | return; |
| 3873 | } |
| 3874 | clearLayoutNeeded(); |
| 3875 | |
| 3876 | final int dw = mDisplayInfo.logicalWidth; |
| 3877 | final int dh = mDisplayInfo.logicalHeight; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3878 | if (DEBUG_LAYOUT) { |
| 3879 | Slog.v(TAG, "-------------------------------------"); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3880 | Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw |
| 3881 | + " dh=" + dh); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 3884 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 3885 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3886 | // TODO: Not sure if we really need to set the rotation here since we are updating from |
| 3887 | // the display info above... |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3888 | mDisplayFrames.mRotation = getRotation(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3889 | mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3890 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3891 | int seq = mLayoutSeq + 1; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3892 | if (seq < 0) seq = 0; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3893 | mLayoutSeq = seq; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3894 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3895 | // Used to indicate that we have processed the dream window and all additional windows are |
| 3896 | // behind it. |
| 3897 | mTmpWindow = null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3898 | mTmpInitial = initial; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3899 | |
| 3900 | // First perform layout of any root windows (not attached to another window). |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3901 | forAllWindows(mPerformLayout, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3902 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3903 | // Used to indicate that we have processed the dream window and all additional attached |
| 3904 | // windows are behind it. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3905 | mTmpWindow2 = mTmpWindow; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3906 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3907 | |
| 3908 | // Now perform layout of attached windows, which usually depend on the position of the |
| 3909 | // window they are attached to. XXX does not deal with windows that are attached to windows |
| 3910 | // that are themselves attached. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3911 | forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3912 | |
| 3913 | // Window frames may have changed. Tell the input dispatcher about it. |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3914 | mInputMonitor.layoutInputConsumers(dw, dh); |
| 3915 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3916 | if (updateInputWindows) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3917 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3920 | mWmService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | /** |
| 3924 | * Takes a snapshot of the display. In landscape mode this grabs the whole screen. |
| 3925 | * In portrait mode, it grabs the full screenshot. |
| 3926 | * |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3927 | * @param config of the output bitmap |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3928 | */ |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3929 | Bitmap screenshotDisplayLocked(Bitmap.Config config) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3930 | if (!mWmService.mPolicy.isScreenOn()) { |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3931 | if (DEBUG_SCREENSHOT) { |
| 3932 | Slog.i(TAG_WM, "Attempted to take screenshot while display was off."); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3933 | } |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3934 | return null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3935 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3936 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3937 | int dw = mDisplayInfo.logicalWidth; |
| 3938 | int dh = mDisplayInfo.logicalHeight; |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3939 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3940 | if (dw <= 0 || dh <= 0) { |
| 3941 | return null; |
| 3942 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3943 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3944 | final Rect frame = new Rect(0, 0, dw, dh); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3945 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3946 | // The screenshot API does not apply the current screen rotation. |
| 3947 | int rot = mDisplay.getRotation(); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3948 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3949 | if (rot == ROTATION_90 || rot == ROTATION_270) { |
| 3950 | rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 3951 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3952 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3953 | // SurfaceFlinger is not aware of orientation, so convert our logical |
| 3954 | // crop to SurfaceFlinger's portrait orientation. |
| 3955 | convertCropForSurfaceFlinger(frame, rot, dw, dh); |
| 3956 | |
| 3957 | final ScreenRotationAnimation screenRotationAnimation = |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 3958 | mWmService.mRoot.getDisplayContent(DEFAULT_DISPLAY).getRotationAnimation(); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3959 | final boolean inRotation = screenRotationAnimation != null && |
| 3960 | screenRotationAnimation.isAnimating(); |
| 3961 | if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating"); |
| 3962 | |
| 3963 | // TODO(b/68392460): We should screenshot Task controls directly |
| 3964 | // but it's difficult at the moment as the Task doesn't have the |
| 3965 | // correct size set. |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 3966 | final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3967 | if (bitmap == null) { |
| 3968 | Slog.w(TAG_WM, "Failed to take screenshot"); |
| 3969 | return null; |
| 3970 | } |
| 3971 | |
| 3972 | // Create a copy of the screenshot that is immutable and backed in ashmem. |
| 3973 | // This greatly reduces the overhead of passing the bitmap between processes. |
| 3974 | final Bitmap ret = bitmap.createAshmemBitmap(config); |
| 3975 | bitmap.recycle(); |
| 3976 | return ret; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | // TODO: Can this use createRotationMatrix()? |
| 3980 | private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) { |
| 3981 | if (rot == Surface.ROTATION_90) { |
| 3982 | final int tmp = crop.top; |
| 3983 | crop.top = dw - crop.right; |
| 3984 | crop.right = crop.bottom; |
| 3985 | crop.bottom = dw - crop.left; |
| 3986 | crop.left = tmp; |
| 3987 | } else if (rot == Surface.ROTATION_180) { |
| 3988 | int tmp = crop.top; |
| 3989 | crop.top = dh - crop.bottom; |
| 3990 | crop.bottom = dh - tmp; |
| 3991 | tmp = crop.right; |
| 3992 | crop.right = dw - crop.left; |
| 3993 | crop.left = dw - tmp; |
| 3994 | } else if (rot == Surface.ROTATION_270) { |
| 3995 | final int tmp = crop.top; |
| 3996 | crop.top = crop.left; |
| 3997 | crop.left = dh - crop.bottom; |
| 3998 | crop.bottom = crop.right; |
| 3999 | crop.right = dh - tmp; |
| 4000 | } |
| 4001 | } |
| 4002 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4003 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 4004 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 4005 | mExitingTokens.get(i).hasVisible = hasVisible; |
| 4006 | } |
| 4007 | |
| 4008 | // Initialize state of exiting applications. |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4009 | mTaskContainers.setExitingTokensHasVisible(hasVisible); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | void removeExistingTokensIfPossible() { |
| 4013 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 4014 | final WindowToken token = mExitingTokens.get(i); |
| 4015 | if (!token.hasVisible) { |
| 4016 | mExitingTokens.remove(i); |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | // Time to remove any exiting applications? |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4021 | mTaskContainers.removeExistingAppTokensIfPossible(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4022 | } |
| 4023 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4024 | @Override |
| 4025 | void onDescendantOverrideConfigurationChanged() { |
| 4026 | setLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4027 | mWmService.requestTraversal(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4030 | boolean okToDisplay() { |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 4031 | return okToDisplay(false); |
| 4032 | } |
| 4033 | |
| 4034 | boolean okToDisplay(boolean ignoreFrozen) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4035 | if (mDisplayId == DEFAULT_DISPLAY) { |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 4036 | return (!mWmService.mDisplayFrozen || ignoreFrozen) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4037 | && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4038 | } |
| 4039 | return mDisplayInfo.state == Display.STATE_ON; |
| 4040 | } |
| 4041 | |
| 4042 | boolean okToAnimate() { |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 4043 | return okToAnimate(false); |
| 4044 | } |
| 4045 | |
| 4046 | boolean okToAnimate(boolean ignoreFrozen) { |
| 4047 | return okToDisplay(ignoreFrozen) && |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4048 | (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4049 | } |
| 4050 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4051 | static final class TaskForResizePointSearchResult { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 4052 | private Task taskForResize; |
| 4053 | private int x; |
| 4054 | private int y; |
| 4055 | private int delta; |
| 4056 | private Rect mTmpRect = new Rect(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4057 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 4058 | Task process(WindowContainer root, int x, int y, int delta) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4059 | taskForResize = null; |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 4060 | this.x = x; |
| 4061 | this.y = y; |
| 4062 | this.delta = delta; |
| 4063 | mTmpRect.setEmpty(); |
| 4064 | |
| 4065 | final PooledFunction f = PooledLambda.obtainFunction( |
| 4066 | TaskForResizePointSearchResult::processTask, this, PooledLambda.__(Task.class)); |
| 4067 | root.forAllTasks(f); |
| 4068 | f.recycle(); |
| 4069 | |
| 4070 | return taskForResize; |
| 4071 | } |
| 4072 | |
| 4073 | private boolean processTask(Task task) { |
| 4074 | if (!task.getStack().getWindowConfiguration().canResizeTask()) { |
| 4075 | return true; |
| 4076 | } |
| 4077 | |
| 4078 | if (task.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { |
| 4079 | return true; |
| 4080 | } |
| 4081 | |
| 4082 | // We need to use the task's dim bounds (which is derived from the visible bounds of |
| 4083 | // its apps windows) for any touch-related tests. Can't use the task's original |
| 4084 | // bounds because it might be adjusted to fit the content frame. One example is when |
| 4085 | // the task is put to top-left quadrant, the actual visible area would not start at |
| 4086 | // (0,0) after it's adjusted for the status bar. |
| 4087 | task.getDimBounds(mTmpRect); |
| 4088 | mTmpRect.inset(-delta, -delta); |
| 4089 | if (mTmpRect.contains(x, y)) { |
| 4090 | mTmpRect.inset(delta, delta); |
| 4091 | |
| 4092 | if (!mTmpRect.contains(x, y)) { |
| 4093 | taskForResize = task; |
| 4094 | return true; |
| 4095 | } |
| 4096 | // User touched inside the task. No need to look further, |
| 4097 | // focus transfer will be handled in ACTION_UP. |
| 4098 | return true; |
| 4099 | } |
| 4100 | |
| 4101 | return false; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4102 | } |
| 4103 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4104 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4105 | private static final class ApplySurfaceChangesTransactionState { |
| 4106 | boolean displayHasContent; |
| 4107 | boolean obscured; |
| 4108 | boolean syswin; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 4109 | boolean preferMinimalPostProcessing; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4110 | float preferredRefreshRate; |
| 4111 | int preferredModeId; |
| 4112 | |
| 4113 | void reset() { |
| 4114 | displayHasContent = false; |
| 4115 | obscured = false; |
| 4116 | syswin = false; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 4117 | preferMinimalPostProcessing = false; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4118 | preferredRefreshRate = 0; |
| 4119 | preferredModeId = 0; |
| 4120 | } |
| 4121 | } |
| 4122 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4123 | /** |
| 4124 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 4125 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 4126 | * homogeneous children type which is currently required by sub-classes of |
| 4127 | * {@link WindowContainer} class. |
| 4128 | */ |
| 4129 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 4130 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4131 | DisplayChildWindowContainer(WindowManagerService service) { |
| 4132 | super(service); |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4133 | // TODO(display-area): move to ConfigurationContainer? |
| 4134 | mOrientation = SCREEN_ORIENTATION_UNSET; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4135 | } |
| 4136 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4137 | @Override |
| 4138 | boolean fillsParent() { |
| 4139 | return true; |
| 4140 | } |
| 4141 | |
| 4142 | @Override |
| 4143 | boolean isVisible() { |
| 4144 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4145 | } |
| 4146 | } |
| 4147 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4148 | /** |
| 4149 | * Window container class that contains all containers on this display relating to Apps. |
| 4150 | * I.e Activities. |
| 4151 | */ |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4152 | private final class TaskContainers extends DisplayChildWindowContainer<ActivityStack> { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4153 | /** |
| 4154 | * A control placed at the appropriate level for transitions to occur. |
| 4155 | */ |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4156 | SurfaceControl mAppAnimationLayer = null; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4157 | SurfaceControl mBoostedAppAnimationLayer = null; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4158 | SurfaceControl mHomeAppAnimationLayer = null; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4159 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4160 | /** |
| 4161 | * Given that the split-screen divider does not have an AppWindowToken, it |
| 4162 | * will have to live inside of a "NonAppWindowContainer", in particular |
| 4163 | * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order |
| 4164 | * it will need to be interleaved with some of our children, appearing on top of |
| 4165 | * both docked stacks but underneath any assistant stacks. |
| 4166 | * |
| 4167 | * To solve this problem we have this anchor control, which will always exist so |
| 4168 | * we can always assign it the correct value in our {@link #assignChildLayers}. |
| 4169 | * Likewise since it always exists, {@link AboveAppWindowContainers} can always |
| 4170 | * assign the divider a layer relative to it. This way we prevent linking lifecycle |
| 4171 | * events between the two containers. |
| 4172 | */ |
| 4173 | SurfaceControl mSplitScreenDividerAnchor = null; |
| 4174 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4175 | // Cached reference to some special tasks we tend to get a lot so we don't need to loop |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4176 | // through the list to find them. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4177 | private ActivityStack mRootHomeTask = null; |
| 4178 | private ActivityStack mRootPinnedTask = null; |
| 4179 | private ActivityStack mRootSplitScreenPrimaryTask = null; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4180 | |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4181 | TaskContainers(WindowManagerService service) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4182 | super(service); |
| 4183 | } |
| 4184 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4185 | /** |
| 4186 | * Returns the topmost stack on the display that is compatible with the input windowing mode |
| 4187 | * and activity type. Null is no compatible stack on the display. |
| 4188 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4189 | ActivityStack getStack(int windowingMode, int activityType) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4190 | if (activityType == ACTIVITY_TYPE_HOME) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4191 | return mRootHomeTask; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4192 | } |
| 4193 | if (windowingMode == WINDOWING_MODE_PINNED) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4194 | return mRootPinnedTask; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4195 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4196 | return mRootSplitScreenPrimaryTask; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4197 | } |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4198 | for (int i = mTaskContainers.getChildCount() - 1; i >= 0; --i) { |
| 4199 | final ActivityStack stack = mTaskContainers.getChildAt(i); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4200 | if (activityType == ACTIVITY_TYPE_UNDEFINED |
| 4201 | && windowingMode == stack.getWindowingMode()) { |
| 4202 | // Passing in undefined type means we want to match the topmost stack with the |
| 4203 | // windowing mode. |
| 4204 | return stack; |
| 4205 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4206 | if (stack.isCompatible(windowingMode, activityType)) { |
| 4207 | return stack; |
| 4208 | } |
| 4209 | } |
| 4210 | return null; |
| 4211 | } |
| 4212 | |
| 4213 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4214 | ActivityStack getTopStack() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4215 | return mTaskContainers.getChildCount() > 0 |
| 4216 | ? mTaskContainers.getChildAt(mTaskContainers.getChildCount() - 1) : null; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4217 | } |
| 4218 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4219 | int getIndexOf(ActivityStack stack) { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4220 | return mTaskContainers.mChildren.indexOf(stack); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4221 | } |
| 4222 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4223 | ActivityStack getRootHomeTask() { |
| 4224 | if (mRootHomeTask == null && mDisplayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4225 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
| 4226 | } |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4227 | return mRootHomeTask; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4230 | ActivityStack getRootPinnedTask() { |
| 4231 | return mRootPinnedTask; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4232 | } |
| 4233 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4234 | ActivityStack getRootSplitScreenPrimaryTask() { |
| 4235 | return mRootSplitScreenPrimaryTask; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4236 | } |
| 4237 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 4238 | ArrayList<Task> getVisibleTasks() { |
| 4239 | final ArrayList<Task> visibleTasks = new ArrayList<>(); |
| 4240 | forAllTasks(task -> { |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4241 | if (!task.isRootTask() && task.isVisible()) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 4242 | visibleTasks.add(task); |
| 4243 | } |
| 4244 | }); |
| 4245 | return visibleTasks; |
| 4246 | } |
| 4247 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4248 | void onStackWindowingModeChanged(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4249 | removeStackReferenceIfNeeded(stack); |
| 4250 | addStackReferenceIfNeeded(stack); |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4251 | if (stack == mRootPinnedTask && getTopStack() != stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4252 | // Looks like this stack changed windowing mode to pinned. Move it to the top. |
| 4253 | positionChildAt(POSITION_TOP, stack, false /* includingParents */); |
| 4254 | } |
| 4255 | } |
| 4256 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4257 | private void addStackReferenceIfNeeded(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4258 | if (stack.isActivityTypeHome()) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4259 | if (mRootHomeTask != null) { |
| 4260 | if (!stack.isDescendantOf(mRootHomeTask)) { |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4261 | throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack=" |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4262 | + mRootHomeTask + " already exist on display=" + this |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4263 | + " stack=" + stack); |
| 4264 | } |
| 4265 | } else { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4266 | mRootHomeTask = stack; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4267 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4268 | } |
| 4269 | final int windowingMode = stack.getWindowingMode(); |
| 4270 | if (windowingMode == WINDOWING_MODE_PINNED) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4271 | if (mRootPinnedTask != null) { |
| 4272 | if (!stack.isDescendantOf(mRootPinnedTask)) { |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4273 | throw new IllegalArgumentException( |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4274 | "addStackReferenceIfNeeded: pinned stack=" + mRootPinnedTask |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4275 | + " already exist on display=" + this + " stack=" + stack); |
| 4276 | } |
| 4277 | } else { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4278 | mRootPinnedTask = stack; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4279 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4280 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4281 | if (mRootSplitScreenPrimaryTask != null) { |
| 4282 | if (!stack.isDescendantOf(mRootSplitScreenPrimaryTask)) { |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4283 | throw new IllegalArgumentException("addStackReferenceIfNeeded:" |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4284 | + " split-screen-primary" + " stack=" + mRootSplitScreenPrimaryTask |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4285 | + " already exist on display=" + this + " stack=" + stack); |
| 4286 | } |
| 4287 | } else { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4288 | mRootSplitScreenPrimaryTask = stack; |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4289 | mDisplayContent.onSplitScreenModeActivated(); |
| 4290 | mDividerControllerLocked.notifyDockedStackExistsChanged(true); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4291 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4292 | } |
| 4293 | } |
| 4294 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4295 | void removeStackReferenceIfNeeded(ActivityStack stack) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4296 | if (stack == mRootHomeTask) { |
| 4297 | mRootHomeTask = null; |
| 4298 | } else if (stack == mRootPinnedTask) { |
| 4299 | mRootPinnedTask = null; |
| 4300 | } else if (stack == mRootSplitScreenPrimaryTask) { |
| 4301 | mRootSplitScreenPrimaryTask = null; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4302 | mDisplayContent.onSplitScreenModeDismissed(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4303 | // Re-set the split-screen create mode whenever the split-screen stack is removed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4304 | mWmService.setDockedStackCreateStateLocked( |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4305 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 4306 | mDividerControllerLocked.notifyDockedStackExistsChanged(false); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4307 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4310 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4311 | void addChild(ActivityStack stack, int position) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4312 | addStackReferenceIfNeeded(stack); |
| 4313 | position = findPositionForStack(position, stack, true /* adding */); |
| 4314 | |
| 4315 | super.addChild(stack, position); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4316 | |
| 4317 | // The reparenting case is handled in WindowContainer. |
| 4318 | if (!stack.mReparenting) { |
| 4319 | setLayoutNeeded(); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4320 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4323 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4324 | protected void removeChild(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4325 | super.removeChild(stack); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4326 | mDisplayContent.onStackRemoved(stack); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4327 | removeStackReferenceIfNeeded(stack); |
| 4328 | } |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 4329 | |
| 4330 | @Override |
| 4331 | boolean isOnTop() { |
| 4332 | // Considered always on top |
| 4333 | return true; |
| 4334 | } |
| 4335 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4336 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4337 | void positionChildAt(int position, ActivityStack child, boolean includingParents) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4338 | final boolean moveToTop = (position == POSITION_TOP || position == getChildCount()); |
| 4339 | final boolean moveToBottom = (position == POSITION_BOTTOM || position == 0); |
| 4340 | if (child.getWindowConfiguration().isAlwaysOnTop() && !moveToTop) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4341 | // This stack is always-on-top, override the default behavior. |
| 4342 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom"); |
| 4343 | |
| 4344 | // Moving to its current position, as we must call super but we don't want to |
| 4345 | // perform any meaningful action. |
| 4346 | final int currentPosition = mChildren.indexOf(child); |
| 4347 | super.positionChildAt(currentPosition, child, false /* includingParents */); |
| 4348 | return; |
| 4349 | } |
lumark | d0b5c8f | 2019-09-29 11:30:37 +0800 | [diff] [blame] | 4350 | // We don't allow untrusted display to top when task stack moves to top, |
| 4351 | // until user tapping this display to change display position as top intentionally. |
| 4352 | if (isUntrustedVirtualDisplay() && !getParent().isOnTop()) { |
| 4353 | includingParents = false; |
| 4354 | } |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4355 | final int targetPosition = findPositionForStack(position, child, false /* adding */); |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4356 | super.positionChildAt(targetPosition, child, false /* includingParents */); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4357 | |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4358 | if (includingParents && (moveToTop || moveToBottom)) { |
| 4359 | // The DisplayContent children do not re-order, but we still want to move the |
| 4360 | // display of this stack container because the intention of positioning is to have |
| 4361 | // higher z-order to gain focus. |
| 4362 | positionDisplayAt(moveToTop ? POSITION_TOP : POSITION_BOTTOM, |
| 4363 | true /* includingParents */); |
Riddle Hsu | 2f6e174 | 2018-08-23 22:44:36 +0800 | [diff] [blame] | 4364 | } |
| 4365 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4366 | setLayoutNeeded(); |
| 4367 | } |
| 4368 | |
| 4369 | /** |
| 4370 | * When stack is added or repositioned, find a proper position for it. |
| 4371 | * This will make sure that pinned stack always stays on top. |
| 4372 | * @param requestedPosition Position requested by caller. |
| 4373 | * @param stack Stack to be added or positioned. |
| 4374 | * @param adding Flag indicates whether we're adding a new stack or positioning an existing. |
| 4375 | * @return The proper position for the stack. |
| 4376 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4377 | private int findPositionForStack(int requestedPosition, ActivityStack stack, |
| 4378 | boolean adding) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4379 | if (stack.inPinnedWindowingMode()) { |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4380 | return POSITION_TOP; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4381 | } |
| 4382 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4383 | final int topChildPosition = mChildren.size() - 1; |
| 4384 | int belowAlwaysOnTopPosition = POSITION_BOTTOM; |
| 4385 | for (int i = topChildPosition; i >= 0; --i) { |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4386 | // Since a stack could be repositioned while being one of the child, return |
| 4387 | // current index if that's the same stack we are positioning and it is always on |
| 4388 | // top. |
| 4389 | final boolean sameStack = getStacks().get(i) == stack; |
| 4390 | if ((sameStack && stack.isAlwaysOnTop()) |
| 4391 | || (!sameStack && !getStacks().get(i).isAlwaysOnTop())) { |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4392 | belowAlwaysOnTopPosition = i; |
| 4393 | break; |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | // The max possible position we can insert the stack at. |
| 4398 | int maxPosition = POSITION_TOP; |
| 4399 | // The min possible position we can insert the stack at. |
| 4400 | int minPosition = POSITION_BOTTOM; |
| 4401 | |
| 4402 | if (stack.isAlwaysOnTop()) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4403 | if (hasPinnedTask()) { |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4404 | // Always-on-top stacks go below the pinned stack. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4405 | maxPosition = getStacks().indexOf(mRootPinnedTask) - 1; |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4406 | } |
| 4407 | // Always-on-top stacks need to be above all other stacks. |
| 4408 | minPosition = belowAlwaysOnTopPosition != |
| 4409 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition; |
| 4410 | } else { |
| 4411 | // Other stacks need to be below the always-on-top stacks. |
| 4412 | maxPosition = belowAlwaysOnTopPosition != |
Arthur Hung | 928d8dc | 2018-07-18 15:38:05 +0800 | [diff] [blame] | 4413 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0; |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4414 | } |
| 4415 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4416 | // Cap the requested position to something reasonable for the previous position check |
| 4417 | // below. |
| 4418 | if (requestedPosition == POSITION_TOP) { |
| 4419 | requestedPosition = mChildren.size(); |
| 4420 | } else if (requestedPosition == POSITION_BOTTOM) { |
| 4421 | requestedPosition = 0; |
| 4422 | } |
| 4423 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4424 | int targetPosition = requestedPosition; |
| 4425 | targetPosition = Math.min(targetPosition, maxPosition); |
| 4426 | targetPosition = Math.max(targetPosition, minPosition); |
| 4427 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4428 | int prevPosition = getStacks().indexOf(stack); |
| 4429 | // The positions we calculated above (maxPosition, minPosition) do not take into |
| 4430 | // consideration the following edge cases. |
| 4431 | // 1) We need to adjust the position depending on the value "adding". |
| 4432 | // 2) When we are moving a stack to another position, we also need to adjust the |
| 4433 | // position depending on whether the stack is moving to a higher or lower position. |
| 4434 | if ((targetPosition != requestedPosition) && |
| 4435 | (adding || targetPosition < prevPosition)) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4436 | targetPosition++; |
| 4437 | } |
| 4438 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4439 | return targetPosition; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4443 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 4444 | boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4445 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4446 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4447 | return true; |
| 4448 | } |
| 4449 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4450 | return true; |
| 4451 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4452 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4453 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4454 | return true; |
| 4455 | } |
| 4456 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4457 | return true; |
| 4458 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4459 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4460 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4463 | private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback, |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4464 | boolean traverseTopToBottom) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4465 | // For legacy reasons we process the TaskStack.mExitingActivities first here before the |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4466 | // app tokens. |
| 4467 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 4468 | // in-order. |
| 4469 | if (traverseTopToBottom) { |
| 4470 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4471 | final List<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4472 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4473 | if (activities.get(j).forAllWindowsUnchecked(callback, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4474 | traverseTopToBottom)) { |
| 4475 | return true; |
| 4476 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4477 | } |
| 4478 | } |
| 4479 | } else { |
| 4480 | final int count = mChildren.size(); |
| 4481 | for (int i = 0; i < count; ++i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4482 | final List<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4483 | final int appTokensCount = activities.size(); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4484 | for (int j = 0; j < appTokensCount; j++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4485 | if (activities.get(j).forAllWindowsUnchecked(callback, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4486 | traverseTopToBottom)) { |
| 4487 | return true; |
| 4488 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4489 | } |
| 4490 | } |
| 4491 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4492 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4495 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 4496 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4497 | final ArrayList<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4498 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4499 | activities.get(j).hasVisible = hasVisible; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4500 | } |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | void removeExistingAppTokensIfPossible() { |
| 4505 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4506 | final ArrayList<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4507 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4508 | final ActivityRecord activity = activities.get(j); |
| 4509 | if (!activity.hasVisible && !mClosingApps.contains(activity) |
| 4510 | && (!activity.mIsExiting || activity.isEmpty())) { |
| 4511 | // Make sure there is no animation running on this activity, so any windows |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4512 | // associated with it will be removed as soon as their animations are |
| 4513 | // complete. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 4514 | cancelAnimation(); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4515 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4516 | "performLayout: Activity exiting now removed %s", activity); |
| 4517 | activity.removeIfPossible(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4518 | } |
| 4519 | } |
| 4520 | } |
| 4521 | } |
| 4522 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4523 | @Override |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4524 | int getOrientation(int candidate) { |
Garfield Tan | 98eead3 | 2019-11-18 13:24:53 -0800 | [diff] [blame] | 4525 | if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4526 | // Apps and their containers are not allowed to specify an orientation while the |
Garfield Tan | 98eead3 | 2019-11-18 13:24:53 -0800 | [diff] [blame] | 4527 | // docked stack is visible...except for the home stack if the docked stack is |
| 4528 | // minimized and it actually set something and the bounds is different from the |
| 4529 | // display. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4530 | if (mRootHomeTask != null && mRootHomeTask.isVisible() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4531 | && mDividerControllerLocked.isMinimizedDock() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4532 | && !(mDividerControllerLocked.isHomeStackResizable() |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4533 | && mRootHomeTask.matchParentBounds())) { |
| 4534 | final int orientation = mRootHomeTask.getOrientation(); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4535 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 4536 | return orientation; |
| 4537 | } |
| 4538 | } |
| 4539 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 4540 | } |
| 4541 | |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4542 | final int orientation = super.getOrientation(candidate); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4543 | if (orientation != SCREEN_ORIENTATION_UNSET |
| 4544 | && orientation != SCREEN_ORIENTATION_BEHIND) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4545 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4546 | "App is requesting an orientation, return %d for display id=%d", |
| 4547 | orientation, mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4548 | return orientation; |
| 4549 | } |
| 4550 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4551 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4552 | "No app is requesting an orientation, return %d for display id=%d", |
| 4553 | getLastOrientation(), mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4554 | // The next app has not been requested to be visible, so we keep the current orientation |
| 4555 | // to prevent freezing/unfreezing the display too early. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 4556 | return getLastOrientation(); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4557 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4558 | |
| 4559 | @Override |
| 4560 | void assignChildLayers(SurfaceControl.Transaction t) { |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4561 | assignStackOrdering(t); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4562 | |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4563 | for (int i = 0; i < mChildren.size(); i++) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4564 | final ActivityStack s = mChildren.get(i); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4565 | s.assignChildLayers(t); |
| 4566 | } |
| 4567 | } |
| 4568 | |
| 4569 | void assignStackOrdering(SurfaceControl.Transaction t) { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4570 | if (getParent() == null) { |
| 4571 | return; |
| 4572 | } |
| 4573 | mTmpAlwaysOnTopStacks.clear(); |
| 4574 | mTmpHomeStacks.clear(); |
| 4575 | mTmpNormalStacks.clear(); |
| 4576 | for (int i = 0; i < mChildren.size(); ++i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4577 | final ActivityStack s = mChildren.get(i); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4578 | if (s.isAlwaysOnTop()) { |
| 4579 | mTmpAlwaysOnTopStacks.add(s); |
| 4580 | } else if (s.isActivityTypeHome()) { |
| 4581 | mTmpHomeStacks.add(s); |
| 4582 | } else { |
| 4583 | mTmpNormalStacks.add(s); |
| 4584 | } |
| 4585 | } |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4586 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4587 | int layer = 0; |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4588 | // Place home stacks to the bottom. |
| 4589 | for (int i = 0; i < mTmpHomeStacks.size(); i++) { |
| 4590 | mTmpHomeStacks.get(i).assignLayer(t, layer++); |
| 4591 | } |
| 4592 | // The home animation layer is between the home stacks and the normal stacks. |
| 4593 | final int layerForHomeAnimationLayer = layer++; |
| 4594 | int layerForSplitScreenDividerAnchor = layer++; |
| 4595 | int layerForAnimationLayer = layer++; |
| 4596 | for (int i = 0; i < mTmpNormalStacks.size(); i++) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4597 | final ActivityStack s = mTmpNormalStacks.get(i); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4598 | s.assignLayer(t, layer++); |
| 4599 | if (s.inSplitScreenWindowingMode()) { |
| 4600 | // The split screen divider anchor is located above the split screen window. |
| 4601 | layerForSplitScreenDividerAnchor = layer++; |
| 4602 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4603 | if (s.isTaskAnimating() || s.isAppTransitioning()) { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4604 | // The animation layer is located above the highest animating stack and no |
| 4605 | // higher. |
| 4606 | layerForAnimationLayer = layer++; |
| 4607 | } |
| 4608 | } |
| 4609 | // The boosted animation layer is between the normal stacks and the always on top |
| 4610 | // stacks. |
| 4611 | final int layerForBoostedAnimationLayer = layer++; |
| 4612 | for (int i = 0; i < mTmpAlwaysOnTopStacks.size(); i++) { |
| 4613 | mTmpAlwaysOnTopStacks.get(i).assignLayer(t, layer++); |
| 4614 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4615 | |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4616 | t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer); |
| 4617 | t.setLayer(mAppAnimationLayer, layerForAnimationLayer); |
| 4618 | t.setLayer(mSplitScreenDividerAnchor, layerForSplitScreenDividerAnchor); |
| 4619 | t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | @Override |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4623 | SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) { |
| 4624 | switch (animationLayer) { |
| 4625 | case ANIMATION_LAYER_BOOSTED: |
| 4626 | return mBoostedAppAnimationLayer; |
| 4627 | case ANIMATION_LAYER_HOME: |
| 4628 | return mHomeAppAnimationLayer; |
| 4629 | case ANIMATION_LAYER_STANDARD: |
| 4630 | default: |
| 4631 | return mAppAnimationLayer; |
| 4632 | } |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4633 | } |
| 4634 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4635 | SurfaceControl getSplitScreenDividerAnchor() { |
| 4636 | return mSplitScreenDividerAnchor; |
| 4637 | } |
| 4638 | |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4639 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4640 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4641 | if (getParent() != null) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4642 | super.onParentChanged(newParent, oldParent, () -> { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4643 | mAppAnimationLayer = makeChildSurface(null) |
| 4644 | .setName("animationLayer") |
| 4645 | .build(); |
| 4646 | mBoostedAppAnimationLayer = makeChildSurface(null) |
| 4647 | .setName("boostedAnimationLayer") |
| 4648 | .build(); |
| 4649 | mHomeAppAnimationLayer = makeChildSurface(null) |
| 4650 | .setName("homeAnimationLayer") |
| 4651 | .build(); |
| 4652 | mSplitScreenDividerAnchor = makeChildSurface(null) |
| 4653 | .setName("splitScreenDividerAnchor") |
| 4654 | .build(); |
| 4655 | getPendingTransaction() |
| 4656 | .show(mAppAnimationLayer) |
| 4657 | .show(mBoostedAppAnimationLayer) |
| 4658 | .show(mHomeAppAnimationLayer) |
| 4659 | .show(mSplitScreenDividerAnchor); |
| 4660 | }); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4661 | } else { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4662 | super.onParentChanged(newParent, oldParent); |
Vishnu Nair | 3319739 | 2019-08-30 10:29:37 -0700 | [diff] [blame] | 4663 | mWmService.mTransactionFactory.get() |
chaviw | 9f6171e | 2019-06-07 16:33:50 -0700 | [diff] [blame] | 4664 | .remove(mAppAnimationLayer) |
| 4665 | .remove(mBoostedAppAnimationLayer) |
| 4666 | .remove(mHomeAppAnimationLayer) |
| 4667 | .remove(mSplitScreenDividerAnchor) |
| 4668 | .apply(); |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4669 | mAppAnimationLayer = null; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4670 | mBoostedAppAnimationLayer = null; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4671 | mHomeAppAnimationLayer = null; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4672 | mSplitScreenDividerAnchor = null; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4673 | } |
| 4674 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4675 | } |
| 4676 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4677 | private final class AboveAppWindowContainers extends NonAppWindowContainers { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4678 | AboveAppWindowContainers(String name, WindowManagerService service) { |
| 4679 | super(name, service); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4680 | } |
| 4681 | |
Robert Carr | b950603 | 2018-02-13 13:54:00 -0800 | [diff] [blame] | 4682 | @Override |
| 4683 | void assignChildLayers(SurfaceControl.Transaction t) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4684 | boolean needAssignIme = mImeWindowsContainers.getSurfaceControl() != null; |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4685 | for (int j = 0; j < mChildren.size(); ++j) { |
| 4686 | final WindowToken wt = mChildren.get(j); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4687 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4688 | wt.assignLayer(t, j); |
| 4689 | wt.assignChildLayers(t); |
| 4690 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4691 | int layer = mWmService.mPolicy.getWindowLayerFromTypeLw( |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4692 | wt.windowType, wt.mOwnerCanManageAppTokens); |
Robert Carr | b8e78fa | 2017-11-28 13:07:58 -0800 | [diff] [blame] | 4693 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4694 | if (needAssignIme && layer >= mWmService.mPolicy.getWindowLayerFromTypeLw( |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4695 | TYPE_INPUT_METHOD_DIALOG, true)) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4696 | mImeWindowsContainers.assignRelativeLayer(t, wt.getSurfaceControl(), -1); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4697 | needAssignIme = false; |
| 4698 | } |
| 4699 | } |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4703 | private class WindowContainers extends DisplayChildWindowContainer<WindowContainer> { |
| 4704 | private final String mName; |
| 4705 | |
| 4706 | WindowContainers(String name, WindowManagerService service) { |
| 4707 | super(service); |
| 4708 | mName = name; |
| 4709 | } |
| 4710 | |
| 4711 | @Override |
| 4712 | void assignChildLayers(SurfaceControl.Transaction t) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4713 | mImeWindowsContainers.setNeedsLayer(); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4714 | mBelowAppWindowsContainers.assignLayer(t, 0); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4715 | mTaskContainers.assignLayer(t, 1); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4716 | mAboveAppWindowsContainers.assignLayer(t, 2); |
| 4717 | |
| 4718 | final WindowState imeTarget = mInputMethodTarget; |
| 4719 | boolean needAssignIme = true; |
| 4720 | |
| 4721 | // In the case where we have an IME target that is not in split-screen mode IME |
| 4722 | // assignment is easy. We just need the IME to go directly above the target. This way |
| 4723 | // children of the target will naturally go above the IME and everyone is happy. |
| 4724 | // |
| 4725 | // In the case of split-screen windowing mode, we need to elevate the IME above the |
| 4726 | // docked divider while keeping the app itself below the docked divider, so instead |
| 4727 | // we use relative layering of the IME targets child windows, and place the IME in |
| 4728 | // the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}). |
| 4729 | // |
| 4730 | // In the case the IME target is animating, the animation Z order may be different |
| 4731 | // than the WindowContainer Z order, so it's difficult to be sure we have the correct |
| 4732 | // IME target. In this case we just layer the IME over all transitions by placing it |
| 4733 | // in the above applications layer. |
| 4734 | // |
| 4735 | // In the case where we have no IME target we assign it where its base layer would |
| 4736 | // place it in the AboveAppWindowContainers. |
| 4737 | // |
| 4738 | // Keep IME window in mAboveAppWindowsContainers as long as app's starting window |
| 4739 | // exists so it get's layered above the starting window. |
| 4740 | if (imeTarget != null && !(imeTarget.mActivityRecord != null |
| 4741 | && imeTarget.mActivityRecord.hasStartingWindow()) && ( |
Robert Carr | 599d83c | 2020-01-24 14:45:14 -0800 | [diff] [blame] | 4742 | !(imeTarget.inMultiWindowMode() |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4743 | || imeTarget.mToken.isAppTransitioning()) && ( |
| 4744 | imeTarget.getSurfaceControl() != null))) { |
| 4745 | mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(), |
| 4746 | // TODO: We need to use an extra level on the app surface to ensure |
| 4747 | // this is always above SurfaceView but always below attached window. |
| 4748 | 1); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | // Above we have assigned layers to our children, now we ask them to assign |
| 4752 | // layers to their children. |
| 4753 | mBelowAppWindowsContainers.assignChildLayers(t); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4754 | mTaskContainers.assignChildLayers(t); |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4755 | mAboveAppWindowsContainers.assignChildLayers(t); |
| 4756 | mImeWindowsContainers.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4757 | mImeWindowsContainers.assignChildLayers(t); |
| 4758 | } |
| 4759 | |
| 4760 | @Override |
| 4761 | String getName() { |
| 4762 | return mName; |
| 4763 | } |
| 4764 | |
| 4765 | void addChildren() { |
| 4766 | addChild(mBelowAppWindowsContainers, null); |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 4767 | addChild(mTaskContainers, null); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4768 | addChild(mAboveAppWindowsContainers, null); |
| 4769 | addChild(mImeWindowsContainers, null); |
| 4770 | } |
| 4771 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4772 | @Override |
| 4773 | void positionChildAt(int position, WindowContainer child, boolean includingParents) { |
| 4774 | // Children of the WindowContainers are statically ordered, so the real intention here |
| 4775 | // is to perform the operation on the display and not the static direct children. |
| 4776 | getParent().positionChildAt(position, this, includingParents); |
| 4777 | } |
| 4778 | } |
| 4779 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4780 | /** |
| 4781 | * Window container class that contains all containers on this display that are not related to |
| 4782 | * Apps. E.g. status bar. |
| 4783 | */ |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4784 | private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4785 | /** |
| 4786 | * Compares two child window tokens returns -1 if the first is lesser than the second in |
| 4787 | * terms of z-order and 1 otherwise. |
| 4788 | */ |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4789 | private final Comparator<WindowToken> mWindowComparator = (token1, token2) -> |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4790 | // Tokens with higher base layer are z-ordered on-top. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4791 | mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4792 | token1.mOwnerCanManageAppTokens) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4793 | < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4794 | token2.mOwnerCanManageAppTokens) ? -1 : 1; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4795 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4796 | private final Predicate<WindowState> mGetOrientingWindow = w -> { |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4797 | final WindowManagerPolicy policy = mWmService.mPolicy; |
| 4798 | if (policy.isKeyguardHostWindow(w.mAttrs)) { |
| 4799 | if (mWmService.mKeyguardGoingAway) { |
| 4800 | return false; |
| 4801 | } |
| 4802 | // Consider unoccluding only when all unknown visibilities have been |
| 4803 | // resolved, as otherwise we just may be starting another occluding activity. |
| 4804 | final boolean isUnoccluding = |
| 4805 | mDisplayContent.mAppTransition.getAppTransition() |
| 4806 | == TRANSIT_KEYGUARD_UNOCCLUDE |
| 4807 | && mDisplayContent.mUnknownAppVisibilityController.allResolved(); |
| 4808 | // If keyguard is showing, or we're unoccluding, force the keyguard's orientation, |
| 4809 | // even if SystemUI hasn't updated the attrs yet. |
| 4810 | if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) { |
| 4811 | return true; |
| 4812 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4813 | } |
| 4814 | final int req = w.mAttrs.screenOrientation; |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4815 | if (req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4816 | || req == SCREEN_ORIENTATION_UNSET) { |
| 4817 | return false; |
| 4818 | } |
| 4819 | return true; |
| 4820 | }; |
| 4821 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4822 | private final String mName; |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4823 | private final Dimmer mDimmer = new Dimmer(this); |
| 4824 | private final Rect mTmpDimBoundsRect = new Rect(); |
| 4825 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4826 | NonAppWindowContainers(String name, WindowManagerService service) { |
| 4827 | super(service); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4828 | mName = name; |
| 4829 | } |
| 4830 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 4831 | @Override |
| 4832 | boolean hasActivity() { |
| 4833 | // I am a non-app-window-container :P |
| 4834 | return false; |
| 4835 | } |
| 4836 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4837 | void addChild(WindowToken token) { |
| 4838 | addChild(token, mWindowComparator); |
| 4839 | } |
| 4840 | |
| 4841 | @Override |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4842 | int getOrientation(int candidate) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4843 | // Find a window requesting orientation. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4844 | final WindowState win = getWindow(mGetOrientingWindow); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4845 | |
| 4846 | if (win != null) { |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4847 | int req = win.mAttrs.screenOrientation; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4848 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 4849 | "%s forcing orientation to %d for display id=%d", win, req, |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4850 | mDisplayId); |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4851 | if (mWmService.mPolicy.isKeyguardHostWindow(win.mAttrs)) { |
| 4852 | // SystemUI controls the Keyguard orientation asynchronously, and mAttrs may be |
| 4853 | // stale. We record / use the last known override. |
| 4854 | if (req != SCREEN_ORIENTATION_UNSET && req != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 4855 | mDisplayContent.mLastKeyguardForcedOrientation = req; |
| 4856 | } else { |
| 4857 | req = mDisplayContent.mLastKeyguardForcedOrientation; |
| 4858 | } |
| 4859 | } |
| 4860 | return req; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4861 | } |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4862 | return candidate; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | @Override |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4866 | String getName() { |
| 4867 | return mName; |
| 4868 | } |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4869 | |
| 4870 | @Override |
| 4871 | Dimmer getDimmer() { |
| 4872 | return mDimmer; |
| 4873 | } |
| 4874 | |
| 4875 | @Override |
| 4876 | void prepareSurfaces() { |
| 4877 | mDimmer.resetDimStates(); |
| 4878 | super.prepareSurfaces(); |
| 4879 | getBounds(mTmpDimBoundsRect); |
| 4880 | |
| 4881 | if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) { |
| 4882 | scheduleAnimation(); |
| 4883 | } |
| 4884 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4885 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 4886 | |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4887 | /** |
| 4888 | * Container for IME windows. |
| 4889 | * |
| 4890 | * This has some special behaviors: |
| 4891 | * - layers assignment is ignored except if setNeedsLayer() has been called before (and no |
| 4892 | * layer has been assigned since), to facilitate assigning the layer from the IME target, or |
| 4893 | * fall back if there is no target. |
| 4894 | * - the container doesn't always participate in window traversal, according to |
| 4895 | * {@link #skipImeWindowsDuringTraversal()} |
| 4896 | */ |
| 4897 | private class ImeContainer extends NonAppWindowContainers { |
| 4898 | boolean mNeedsLayer = false; |
| 4899 | |
| 4900 | ImeContainer(WindowManagerService wms) { |
| 4901 | super("ImeContainer", wms); |
| 4902 | } |
| 4903 | |
| 4904 | public void setNeedsLayer() { |
| 4905 | mNeedsLayer = true; |
| 4906 | } |
| 4907 | |
| 4908 | @Override |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4909 | int getOrientation(int candidate) { |
| 4910 | // IME does not participate in orientation. |
| 4911 | return candidate; |
| 4912 | } |
| 4913 | |
| 4914 | @Override |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4915 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 4916 | boolean traverseTopToBottom) { |
| 4917 | final DisplayContent dc = mDisplayContent; |
| 4918 | if (skipImeWindowsDuringTraversal(dc)) { |
| 4919 | return false; |
| 4920 | } |
| 4921 | return super.forAllWindows(callback, traverseTopToBottom); |
| 4922 | } |
| 4923 | |
| 4924 | private boolean skipImeWindowsDuringTraversal(DisplayContent dc) { |
| 4925 | // We skip IME windows so they're processed just above their target, except |
| 4926 | // in split-screen mode where we process the IME containers above the docked divider. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4927 | return dc.mInputMethodTarget != null && !dc.hasSplitScreenPrimaryTask(); |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4928 | } |
| 4929 | |
| 4930 | /** Like {@link #forAllWindows}, but ignores {@link #skipImeWindowsDuringTraversal} */ |
| 4931 | boolean forAllWindowForce(ToBooleanFunction<WindowState> callback, |
| 4932 | boolean traverseTopToBottom) { |
| 4933 | return super.forAllWindows(callback, traverseTopToBottom); |
| 4934 | } |
| 4935 | |
| 4936 | @Override |
| 4937 | void assignLayer(Transaction t, int layer) { |
| 4938 | if (!mNeedsLayer) { |
| 4939 | return; |
| 4940 | } |
| 4941 | super.assignLayer(t, layer); |
| 4942 | mNeedsLayer = false; |
| 4943 | } |
| 4944 | |
| 4945 | @Override |
| 4946 | void assignRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) { |
| 4947 | if (!mNeedsLayer) { |
| 4948 | return; |
| 4949 | } |
| 4950 | super.assignRelativeLayer(t, relativeTo, layer); |
| 4951 | mNeedsLayer = false; |
| 4952 | } |
| 4953 | } |
| 4954 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4955 | @Override |
| 4956 | SurfaceSession getSession() { |
| 4957 | return mSession; |
| 4958 | } |
| 4959 | |
| 4960 | @Override |
| 4961 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4962 | SurfaceSession s = child != null ? child.getSession() : getSession(); |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 4963 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s).setContainerLayer(); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4964 | if (child == null) { |
| 4965 | return b; |
| 4966 | } |
| 4967 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4968 | return b.setName(child.getName()) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4969 | .setParent(mSurfaceControl); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | /** |
| 4973 | * The makeSurface variants are for use by the window-container |
| 4974 | * hierarchy. makeOverlay here is a function for various non windowing |
| 4975 | * overlays like the ScreenRotation screenshot, the Strict Mode Flash |
| 4976 | * and other potpourii. |
| 4977 | */ |
| 4978 | SurfaceControl.Builder makeOverlay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4979 | return mWmService.makeSurfaceBuilder(mSession) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4980 | .setParent(mOverlayContainers.getSurfaceControl()); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4981 | } |
| 4982 | |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4983 | /** |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4984 | * Reparents the given surface to {@link #mOverlayContainers}' SurfaceControl. |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4985 | */ |
| 4986 | void reparentToOverlay(Transaction transaction, SurfaceControl surface) { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4987 | transaction.reparent(surface, mOverlayContainers.getSurfaceControl()); |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4988 | } |
| 4989 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4990 | void applyMagnificationSpec(MagnificationSpec spec) { |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4991 | if (spec.scale != 1.0) { |
| 4992 | mMagnificationSpec = spec; |
| 4993 | } else { |
| 4994 | mMagnificationSpec = null; |
| 4995 | } |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 4996 | // Re-parent IME's SurfaceControl when MagnificationSpec changed. |
| 4997 | updateImeParent(); |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4998 | |
Robert Carr | 7603dea | 2019-07-17 13:16:21 -0700 | [diff] [blame] | 4999 | if (spec.scale != 1.0) { |
| 5000 | applyMagnificationSpec(getPendingTransaction(), spec); |
| 5001 | } else { |
| 5002 | clearMagnificationSpec(getPendingTransaction()); |
| 5003 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 5004 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 5007 | void reapplyMagnificationSpec() { |
| 5008 | if (mMagnificationSpec != null) { |
| 5009 | applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec); |
| 5010 | } |
| 5011 | } |
| 5012 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5013 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 5014 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5015 | // Since we are the top of the SurfaceControl hierarchy here |
| 5016 | // we create the root surfaces explicitly rather than chaining |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 5017 | // up as the default implementation in onParentChanged does. So we |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5018 | // explicitly do NOT call super here. |
Garfield Tan | fbd233a | 2019-12-26 12:39:25 -0800 | [diff] [blame] | 5019 | |
| 5020 | if (!isReady()) { |
| 5021 | // TODO(b/62541591): evaluate whether this is the best spot to declare the |
| 5022 | // {@link DisplayContent} ready for use. |
| 5023 | mDisplayReady = true; |
| 5024 | |
| 5025 | mWmService.mAnimator.addDisplayLocked(mDisplayId); |
| 5026 | |
| 5027 | if (mWmService.mDisplayManagerInternal != null) { |
| 5028 | mWmService.mDisplayManagerInternal |
| 5029 | .setDisplayInfoOverrideFromWindowManager(mDisplayId, getDisplayInfo()); |
| 5030 | configureDisplayPolicy(); |
| 5031 | } |
| 5032 | |
| 5033 | reconfigureDisplayLocked(); |
| 5034 | onRequestedOverrideConfigurationChanged(getRequestedOverrideConfiguration()); |
| 5035 | mWmService.mDisplayNotificationController.dispatchDisplayAdded(this); |
| 5036 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | @Override |
| 5040 | void assignChildLayers(SurfaceControl.Transaction t) { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 5041 | mWindowContainers.assignLayer(t, 0); |
| 5042 | mOverlayContainers.assignLayer(t, 1); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5043 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 5044 | mWindowContainers.assignChildLayers(t); |
| 5045 | mOverlayContainers.assignChildLayers(t); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | /** |
| 5049 | * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine |
| 5050 | * that the IME target is one of the docked applications. We'd like the docked divider to be |
| 5051 | * above both of the applications, and we'd like the IME to be above the docked divider. |
| 5052 | * However we need child windows of the applications to be above the IME (Text drag handles). |
| 5053 | * This is a non-strictly hierarcical layering and we need to break out of the Z ordering |
| 5054 | * somehow. We do this by relatively ordering children of the target to the IME in cooperation |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 5055 | * with {@link WindowState#assignLayer} |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5056 | */ |
| 5057 | void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 5058 | mImeWindowsContainers.setNeedsLayer(); |
Robert Carr | bb5de66 | 2018-04-26 13:29:51 -0700 | [diff] [blame] | 5059 | child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | @Override |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 5063 | void prepareSurfaces() { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 5064 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareSurfaces"); |
| 5065 | try { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 5066 | final Transaction transaction = getPendingTransaction(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 5067 | super.prepareSurfaces(); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 5068 | |
| 5069 | // TODO: Once we totally eliminate global transaction we will pass transaction in here |
| 5070 | // rather than merging to global. |
| 5071 | SurfaceControl.mergeToGlobalTransaction(transaction); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 5072 | } finally { |
| 5073 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 5074 | } |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 5075 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 5076 | |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 5077 | void assignStackOrdering() { |
Wale Ogunwale | c17e5cf | 2020-01-21 10:04:46 -0800 | [diff] [blame] | 5078 | mTaskContainers.assignStackOrdering(getPendingTransaction()); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 5079 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 5080 | |
| 5081 | /** |
| 5082 | * Increment the deferral count to determine whether to update the IME target. |
| 5083 | */ |
| 5084 | void deferUpdateImeTarget() { |
| 5085 | mDeferUpdateImeTargetCount++; |
| 5086 | } |
| 5087 | |
| 5088 | /** |
| 5089 | * Decrement the deferral count to determine whether to update the IME target. If the count |
| 5090 | * reaches 0, a new ime target will get computed. |
| 5091 | */ |
| 5092 | void continueUpdateImeTarget() { |
| 5093 | if (mDeferUpdateImeTargetCount == 0) { |
| 5094 | return; |
| 5095 | } |
| 5096 | |
| 5097 | mDeferUpdateImeTargetCount--; |
| 5098 | if (mDeferUpdateImeTargetCount == 0) { |
| 5099 | computeImeTarget(true /* updateImeTarget */); |
| 5100 | } |
| 5101 | } |
| 5102 | |
| 5103 | /** |
| 5104 | * @return Whether a new IME target should be computed. |
| 5105 | */ |
| 5106 | private boolean canUpdateImeTarget() { |
| 5107 | return mDeferUpdateImeTargetCount == 0; |
| 5108 | } |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 5109 | |
| 5110 | InputMonitor getInputMonitor() { |
| 5111 | return mInputMonitor; |
| 5112 | } |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 5113 | |
| 5114 | /** |
| 5115 | * @return Cached value whether we told display manager that we have content. |
| 5116 | */ |
| 5117 | boolean getLastHasContent() { |
| 5118 | return mLastHasContent; |
| 5119 | } |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 5120 | |
| 5121 | void registerPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 5122 | mPointerEventDispatcher.registerInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | void unregisterPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 5126 | mPointerEventDispatcher.unregisterInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 5127 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5128 | |
| 5129 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5130 | boolean alwaysKeepCurrent) { |
| 5131 | prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */); |
| 5132 | } |
| 5133 | |
| 5134 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5135 | boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags, |
| 5136 | boolean forceOverride) { |
| 5137 | final boolean prepared = mAppTransition.prepareAppTransitionLocked( |
| 5138 | transit, alwaysKeepCurrent, flags, forceOverride); |
| 5139 | if (prepared && okToAnimate()) { |
| 5140 | mSkipAppTransitionAnimation = false; |
| 5141 | } |
| 5142 | } |
| 5143 | |
| 5144 | void executeAppTransition() { |
| 5145 | if (mAppTransition.isTransitionSet()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 5146 | ProtoLog.w(WM_DEBUG_APP_TRANSITIONS, |
| 5147 | "Execute app transition: %s, displayId: %d Callers=%s", |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 5148 | mAppTransition, mDisplayId, Debug.getCallers(5)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5149 | mAppTransition.setReady(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5150 | mWmService.mWindowPlacerLocked.requestTraversal(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5151 | } |
| 5152 | } |
| 5153 | |
| 5154 | /** |
| 5155 | * Update pendingLayoutChanges after app transition has finished. |
| 5156 | */ |
| 5157 | void handleAnimatingStoppedAndTransition() { |
| 5158 | int changes = 0; |
| 5159 | |
| 5160 | mAppTransition.setIdle(); |
| 5161 | |
| 5162 | for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) { |
| 5163 | final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i); |
| 5164 | mAppTransition.notifyAppTransitionFinishedLocked(token); |
| 5165 | } |
| 5166 | mNoAnimationNotifyOnTransitionFinished.clear(); |
| 5167 | |
| 5168 | mWallpaperController.hideDeferredWallpapersIfNeeded(); |
| 5169 | |
| 5170 | onAppTransitionDone(); |
| 5171 | |
| 5172 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5173 | if (DEBUG_WALLPAPER_LIGHT) { |
| 5174 | Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout"); |
| 5175 | } |
| 5176 | computeImeTarget(true /* updateImeTarget */); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 5177 | mWallpaperMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5178 | // Since the window list has been rebuilt, focus might have to be recomputed since the |
| 5179 | // actual order of windows might have changed again. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5180 | mWmService.mFocusMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5181 | |
| 5182 | pendingLayoutChanges |= changes; |
| 5183 | } |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 5184 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5185 | /** Check if pending app transition is for activity / task launch. */ |
| 5186 | boolean isNextTransitionForward() { |
| 5187 | final int transit = mAppTransition.getAppTransition(); |
| 5188 | return transit == TRANSIT_ACTIVITY_OPEN |
| 5189 | || transit == TRANSIT_TASK_OPEN |
| 5190 | || transit == TRANSIT_TASK_TO_FRONT; |
| 5191 | } |
| 5192 | |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 5193 | /** |
| 5194 | * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS |
| 5195 | */ |
| 5196 | boolean supportsSystemDecorations() { |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 5197 | return (mWmService.mDisplayWindowSettings.shouldShowSystemDecorsLocked(this) |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 5198 | || (mDisplay.getFlags() & FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0 |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 5199 | || (mWmService.mForceDesktopModeOnExternalDisplays && !isUntrustedVirtualDisplay())) |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 5200 | // VR virtual display will be used to run and render 2D app within a VR experience. |
| 5201 | && mDisplayId != mWmService.mVr2dDisplayId; |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 5202 | } |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5203 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5204 | /** |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 5205 | * @return {@code true} if the display is non-system created virtual display. |
| 5206 | */ |
| 5207 | boolean isUntrustedVirtualDisplay() { |
| 5208 | return mDisplay.getType() == Display.TYPE_VIRTUAL |
| 5209 | && mDisplay.getOwnerUid() != Process.SYSTEM_UID; |
| 5210 | } |
| 5211 | |
| 5212 | /** |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 5213 | * Re-parent the DisplayContent's top surface, {@link #mSurfaceControl} to the specified |
| 5214 | * SurfaceControl. |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5215 | * |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5216 | * @param win The window which owns the SurfaceControl. This indicates the z-order of the |
| 5217 | * windows of this display against the windows on the parent display. |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5218 | * @param sc The new SurfaceControl, where the DisplayContent's surfaces will be re-parented to. |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5219 | */ |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5220 | void reparentDisplayContent(WindowState win, SurfaceControl sc) { |
| 5221 | mParentWindow = win; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5222 | mParentWindow.addEmbeddedDisplayContent(this); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5223 | mParentSurfaceControl = sc; |
| 5224 | if (mPortalWindowHandle == null) { |
| 5225 | mPortalWindowHandle = createPortalWindowHandle(sc.toString()); |
| 5226 | } |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 5227 | getPendingTransaction().setInputWindowInfo(sc, mPortalWindowHandle) |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 5228 | .reparent(mSurfaceControl, sc); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5229 | } |
| 5230 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5231 | /** |
| 5232 | * Get the window which owns the surface that this DisplayContent is re-parented to. |
| 5233 | * |
| 5234 | * @return the parent window. |
| 5235 | */ |
| 5236 | WindowState getParentWindow() { |
| 5237 | return mParentWindow; |
| 5238 | } |
| 5239 | |
| 5240 | /** |
| 5241 | * Update the location of this display in the parent window. This enables windows in this |
| 5242 | * display to compute the global transformation matrix. |
| 5243 | * |
| 5244 | * @param win The parent window of this display. |
| 5245 | * @param x The x coordinate in the parent window. |
| 5246 | * @param y The y coordinate in the parent window. |
| 5247 | */ |
| 5248 | void updateLocation(WindowState win, int x, int y) { |
| 5249 | if (mParentWindow != win) { |
| 5250 | throw new IllegalArgumentException( |
| 5251 | "The given window is not the parent window of this display."); |
| 5252 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5253 | if (!mLocationInParentWindow.equals(x, y)) { |
| 5254 | mLocationInParentWindow.set(x, y); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5255 | if (mWmService.mAccessibilityController != null) { |
Jacky Kao | f93252b | 2019-07-18 15:19:52 +0800 | [diff] [blame] | 5256 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(mDisplayId); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5257 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5258 | notifyLocationInParentDisplayChanged(); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5259 | } |
| 5260 | } |
| 5261 | |
| 5262 | Point getLocationInParentWindow() { |
| 5263 | return mLocationInParentWindow; |
| 5264 | } |
| 5265 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5266 | Point getLocationInParentDisplay() { |
| 5267 | final Point location = new Point(); |
| 5268 | if (mParentWindow != null) { |
| 5269 | // LocationInParentWindow indicates the offset to (0,0) of window, but what we need is |
| 5270 | // the offset to (0,0) of display. |
| 5271 | DisplayContent dc = this; |
| 5272 | do { |
| 5273 | final WindowState displayParent = dc.getParentWindow(); |
| 5274 | location.x += displayParent.getFrameLw().left |
| 5275 | + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f); |
| 5276 | location.y += displayParent.getFrameLw().top |
| 5277 | + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f); |
| 5278 | dc = displayParent.getDisplayContent(); |
| 5279 | } while (dc != null && dc.getParentWindow() != null); |
| 5280 | } |
| 5281 | return location; |
| 5282 | } |
| 5283 | |
| 5284 | void notifyLocationInParentDisplayChanged() { |
| 5285 | forAllWindows(w -> { |
| 5286 | w.updateLocationInParentDisplayIfNeeded(); |
| 5287 | }, false /* traverseTopToBottom */); |
| 5288 | } |
| 5289 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 5290 | @VisibleForTesting |
| 5291 | SurfaceControl getWindowingLayer() { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 5292 | return mWindowContainers.getSurfaceControl(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 5293 | } |
| 5294 | |
Vadim Caen | f847426 | 2019-08-12 17:52:01 +0200 | [diff] [blame] | 5295 | SurfaceControl getOverlayLayer() { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 5296 | return mOverlayContainers.getSurfaceControl(); |
Vadim Caen | f847426 | 2019-08-12 17:52:01 +0200 | [diff] [blame] | 5297 | } |
| 5298 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5299 | /** |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5300 | * Updates the display's system gesture exclusion. |
| 5301 | * |
| 5302 | * @return true, if the exclusion changed. |
| 5303 | */ |
| 5304 | boolean updateSystemGestureExclusion() { |
| 5305 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 0) { |
| 5306 | // No one's interested anyways. |
| 5307 | return false; |
| 5308 | } |
| 5309 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5310 | final Region systemGestureExclusion = Region.obtain(); |
| 5311 | mSystemGestureExclusionWasRestricted = calculateSystemGestureExclusion( |
| 5312 | systemGestureExclusion, mSystemGestureExclusionUnrestricted); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5313 | try { |
| 5314 | if (mSystemGestureExclusion.equals(systemGestureExclusion)) { |
| 5315 | return false; |
| 5316 | } |
| 5317 | mSystemGestureExclusion.set(systemGestureExclusion); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5318 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5319 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5320 | for (int i = mSystemGestureExclusionListeners.beginBroadcast() - 1; i >= 0; --i) { |
| 5321 | try { |
| 5322 | mSystemGestureExclusionListeners.getBroadcastItem(i) |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5323 | .onSystemGestureExclusionChanged(mDisplayId, systemGestureExclusion, |
| 5324 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5325 | } catch (RemoteException e) { |
| 5326 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener", e); |
| 5327 | } |
| 5328 | } |
| 5329 | mSystemGestureExclusionListeners.finishBroadcast(); |
| 5330 | return true; |
| 5331 | } finally { |
| 5332 | systemGestureExclusion.recycle(); |
| 5333 | } |
| 5334 | } |
| 5335 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5336 | /** |
| 5337 | * Calculates the system gesture exclusion. |
| 5338 | * |
| 5339 | * @param outExclusion will be set to the gesture exclusion region |
| 5340 | * @param outExclusionUnrestricted will be set to the gesture exclusion region without |
| 5341 | * any restrictions applied. |
| 5342 | * @return whether any restrictions were applied, i.e. outExclusion and outExclusionUnrestricted |
| 5343 | * differ. |
| 5344 | */ |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5345 | @VisibleForTesting |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5346 | boolean calculateSystemGestureExclusion(Region outExclusion, @Nullable |
| 5347 | Region outExclusionUnrestricted) { |
| 5348 | outExclusion.setEmpty(); |
| 5349 | if (outExclusionUnrestricted != null) { |
| 5350 | outExclusionUnrestricted.setEmpty(); |
| 5351 | } |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5352 | final Region unhandled = Region.obtain(); |
| 5353 | unhandled.set(0, 0, mDisplayFrames.mDisplayWidth, mDisplayFrames.mDisplayHeight); |
| 5354 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 5355 | final Rect leftEdge = mInsetsStateController.getSourceProvider(ITYPE_LEFT_GESTURES) |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5356 | .getSource().getFrame(); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 5357 | final Rect rightEdge = mInsetsStateController.getSourceProvider(ITYPE_RIGHT_GESTURES) |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5358 | .getSource().getFrame(); |
| 5359 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5360 | final Region touchableRegion = Region.obtain(); |
| 5361 | final Region local = Region.obtain(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5362 | final int[] remainingLeftRight = |
| 5363 | {mSystemGestureExclusionLimit, mSystemGestureExclusionLimit}; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5364 | |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5365 | // Traverse all windows top down to assemble the gesture exclusion rects. |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5366 | // For each window, we only take the rects that fall within its touchable region. |
| 5367 | forAllWindows(w -> { |
| 5368 | if (w.cantReceiveTouchInput() || !w.isVisible() |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5369 | || (w.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 |
| 5370 | || unhandled.isEmpty()) { |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5371 | return; |
| 5372 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5373 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5374 | // Get the touchable region of the window, and intersect with where the screen is still |
| 5375 | // touchable, i.e. touchable regions on top are not covering it yet. |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5376 | w.getEffectiveTouchableRegion(touchableRegion); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5377 | touchableRegion.op(unhandled, Op.INTERSECT); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5378 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5379 | if (w.isImplicitlyExcludingAllSystemGestures()) { |
| 5380 | local.set(touchableRegion); |
| 5381 | } else { |
| 5382 | rectListToRegion(w.getSystemGestureExclusion(), local); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5383 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5384 | // Transform to display coordinates |
| 5385 | local.scale(w.mGlobalScale); |
| 5386 | final Rect frame = w.getWindowFrames().mFrame; |
| 5387 | local.translate(frame.left, frame.top); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5388 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5389 | // A window can only exclude system gestures where it is actually touchable |
| 5390 | local.op(touchableRegion, Op.INTERSECT); |
| 5391 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5392 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5393 | // Apply restriction if necessary. |
| 5394 | if (needsGestureExclusionRestrictions(w, mLastDispatchedSystemUiVisibility)) { |
| 5395 | |
| 5396 | // Processes the region along the left edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5397 | remainingLeftRight[0] = addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5398 | remainingLeftRight[0], w, EXCLUSION_LEFT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5399 | |
| 5400 | // Processes the region along the right edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5401 | remainingLeftRight[1] = addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5402 | remainingLeftRight[1], w, EXCLUSION_RIGHT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5403 | |
| 5404 | // Adds the middle (unrestricted area) |
| 5405 | final Region middle = Region.obtain(local); |
| 5406 | middle.op(leftEdge, Op.DIFFERENCE); |
| 5407 | middle.op(rightEdge, Op.DIFFERENCE); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5408 | outExclusion.op(middle, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5409 | middle.recycle(); |
| 5410 | } else { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5411 | boolean loggable = needsGestureExclusionRestrictions(w, 0 /* lastSysUiVis */); |
| 5412 | if (loggable) { |
| 5413 | addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5414 | Integer.MAX_VALUE, w, EXCLUSION_LEFT); |
| 5415 | addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5416 | Integer.MAX_VALUE, w, EXCLUSION_RIGHT); |
| 5417 | } |
| 5418 | outExclusion.op(local, Op.UNION); |
| 5419 | } |
| 5420 | if (outExclusionUnrestricted != null) { |
| 5421 | outExclusionUnrestricted.op(local, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5422 | } |
| 5423 | unhandled.op(touchableRegion, Op.DIFFERENCE); |
| 5424 | }, true /* topToBottom */); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5425 | local.recycle(); |
| 5426 | touchableRegion.recycle(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5427 | unhandled.recycle(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5428 | return remainingLeftRight[0] < mSystemGestureExclusionLimit |
| 5429 | || remainingLeftRight[1] < mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5430 | } |
| 5431 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5432 | /** |
| 5433 | * @return Whether gesture exclusion area should be restricted from the window depending on the |
| 5434 | * current SystemUI visibility flags. |
| 5435 | */ |
| 5436 | private static boolean needsGestureExclusionRestrictions(WindowState win, int sysUiVisibility) { |
| 5437 | final int type = win.mAttrs.type; |
| 5438 | final int stickyHideNavFlags = |
| 5439 | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 5440 | final boolean stickyHideNav = |
| 5441 | (sysUiVisibility & stickyHideNavFlags) == stickyHideNavFlags; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 5442 | return !stickyHideNav && type != TYPE_INPUT_METHOD && type != TYPE_NOTIFICATION_SHADE |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5443 | && win.getActivityType() != ACTIVITY_TYPE_HOME; |
| 5444 | } |
| 5445 | |
| 5446 | /** |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5447 | * @return Whether gesture exclusion area should be logged for the given window |
| 5448 | */ |
| 5449 | static boolean logsGestureExclusionRestrictions(WindowState win) { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 5450 | if (win.mWmService.mConstants.mSystemGestureExclusionLogDebounceTimeoutMillis <= 0) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5451 | return false; |
| 5452 | } |
| 5453 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 5454 | final int type = attrs.type; |
| 5455 | return type != TYPE_WALLPAPER |
| 5456 | && type != TYPE_APPLICATION_STARTING |
| 5457 | && type != TYPE_NAVIGATION_BAR |
| 5458 | && (attrs.flags & FLAG_NOT_TOUCHABLE) == 0 |
| 5459 | && needsGestureExclusionRestrictions(win, 0 /* sysUiVisibility */) |
| 5460 | && win.getDisplayContent().mDisplayPolicy.hasSideGestures(); |
| 5461 | } |
| 5462 | |
| 5463 | /** |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5464 | * Adds a local gesture exclusion area to the global area while applying a limit per edge. |
| 5465 | * |
| 5466 | * @param local The gesture exclusion area to add. |
| 5467 | * @param global The destination. |
| 5468 | * @param edge Only processes the part in that region. |
| 5469 | * @param limit How much limit in pixels we have. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5470 | * @param win The WindowState that is being processed |
| 5471 | * @param side The side that is being processed, either {@link WindowState#EXCLUSION_LEFT} or |
| 5472 | * {@link WindowState#EXCLUSION_RIGHT} |
| 5473 | * @return How much of the limit is remaining. |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5474 | */ |
| 5475 | private static int addToGlobalAndConsumeLimit(Region local, Region global, Rect edge, |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5476 | int limit, WindowState win, int side) { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5477 | final Region r = Region.obtain(local); |
| 5478 | r.op(edge, Op.INTERSECT); |
| 5479 | |
| 5480 | final int[] remaining = {limit}; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5481 | final int[] requestedExclusion = {0}; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5482 | forEachRectReverse(r, rect -> { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5483 | if (remaining[0] <= 0) { |
| 5484 | return; |
| 5485 | } |
| 5486 | final int height = rect.height(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5487 | requestedExclusion[0] += height; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5488 | if (height > remaining[0]) { |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5489 | rect.top = rect.bottom - remaining[0]; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5490 | } |
| 5491 | remaining[0] -= height; |
| 5492 | global.op(rect, Op.UNION); |
| 5493 | }); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5494 | |
| 5495 | final int grantedExclusion = limit - remaining[0]; |
| 5496 | win.setLastExclusionHeights(side, requestedExclusion[0], grantedExclusion); |
| 5497 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5498 | r.recycle(); |
| 5499 | return remaining[0]; |
| 5500 | } |
| 5501 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5502 | void registerSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5503 | mSystemGestureExclusionListeners.register(listener); |
| 5504 | final boolean changed; |
| 5505 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 1) { |
| 5506 | changed = updateSystemGestureExclusion(); |
| 5507 | } else { |
| 5508 | changed = false; |
| 5509 | } |
| 5510 | |
| 5511 | if (!changed) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5512 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5513 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5514 | // If updateSystemGestureExclusion changed the exclusion, it will already have |
| 5515 | // notified the listener. Otherwise, we'll do it here. |
| 5516 | try { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5517 | listener.onSystemGestureExclusionChanged(mDisplayId, mSystemGestureExclusion, |
| 5518 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5519 | } catch (RemoteException e) { |
| 5520 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener during register", e); |
| 5521 | } |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | void unregisterSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5526 | mSystemGestureExclusionListeners.unregister(listener); |
| 5527 | } |
| 5528 | |
| 5529 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5530 | * Create a portal window handle for input. This window transports any touch to the display |
| 5531 | * indicated by {@link InputWindowHandle#portalToDisplayId} if the touch hits this window. |
| 5532 | * |
| 5533 | * @param name The name of the portal window handle. |
| 5534 | * @return the new portal window handle. |
| 5535 | */ |
| 5536 | private InputWindowHandle createPortalWindowHandle(String name) { |
| 5537 | // Let surface flinger to set the display ID of this input window handle because we don't |
| 5538 | // know which display the parent surface control is on. |
| 5539 | final InputWindowHandle portalWindowHandle = new InputWindowHandle( |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 5540 | null /* inputApplicationHandle */, INVALID_DISPLAY); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5541 | portalWindowHandle.name = name; |
| 5542 | portalWindowHandle.token = new Binder(); |
| 5543 | portalWindowHandle.layoutParamsFlags = |
| 5544 | FLAG_SPLIT_TOUCH | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL; |
| 5545 | getBounds(mTmpBounds); |
| 5546 | portalWindowHandle.touchableRegion.set(mTmpBounds); |
| 5547 | portalWindowHandle.scaleFactor = 1f; |
| 5548 | portalWindowHandle.ownerPid = Process.myPid(); |
| 5549 | portalWindowHandle.ownerUid = Process.myUid(); |
| 5550 | portalWindowHandle.portalToDisplayId = mDisplayId; |
| 5551 | return portalWindowHandle; |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5552 | } |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 5553 | |
| 5554 | /** |
| 5555 | * @see IWindowManager#setForwardedInsets |
| 5556 | */ |
| 5557 | public void setForwardedInsets(Insets insets) { |
| 5558 | if (insets == null) { |
| 5559 | insets = Insets.NONE; |
| 5560 | } |
| 5561 | if (mDisplayPolicy.getForwardedInsets().equals(insets)) { |
| 5562 | return; |
| 5563 | } |
| 5564 | mDisplayPolicy.setForwardedInsets(insets); |
| 5565 | setLayoutNeeded(); |
| 5566 | mWmService.mWindowPlacerLocked.requestTraversal(); |
| 5567 | } |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 5568 | |
| 5569 | protected MetricsLogger getMetricsLogger() { |
| 5570 | if (mMetricsLogger == null) { |
| 5571 | mMetricsLogger = new MetricsLogger(); |
| 5572 | } |
| 5573 | return mMetricsLogger; |
| 5574 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5575 | |
| 5576 | void onDisplayChanged() { |
| 5577 | // The window policy is responsible for stopping activities on the default display. |
| 5578 | final int displayId = mDisplay.getDisplayId(); |
| 5579 | if (displayId != DEFAULT_DISPLAY) { |
| 5580 | final int displayState = mDisplay.getState(); |
| 5581 | if (displayState == Display.STATE_OFF && mOffToken == null) { |
| 5582 | mOffToken = mAtmService.acquireSleepToken("Display-off", displayId); |
| 5583 | } else if (displayState == Display.STATE_ON && mOffToken != null) { |
| 5584 | mOffToken.release(); |
| 5585 | mOffToken = null; |
| 5586 | } |
| 5587 | } |
| 5588 | |
| 5589 | mDisplay.getRealSize(mTmpDisplaySize); |
| 5590 | setBounds(0, 0, mTmpDisplaySize.x, mTmpDisplaySize.y); |
| 5591 | updateDisplayInfo(); |
| 5592 | mWmService.requestTraversal(); |
| 5593 | } |
| 5594 | |
| 5595 | void addStack(ActivityStack stack, int position) { |
| 5596 | setStackOnDisplay(stack, position); |
| 5597 | positionStackAt(stack, position); |
| 5598 | mAtmService.updateSleepIfNeededLocked(); |
| 5599 | } |
| 5600 | |
| 5601 | void onStackRemoved(ActivityStack stack) { |
| 5602 | if (ActivityTaskManagerDebugConfig.DEBUG_STACK) { |
| 5603 | Slog.v(TAG_STACK, "removeStack: detaching " + stack + " from displayId=" + mDisplayId); |
| 5604 | } |
| 5605 | if (mPreferredTopFocusableStack == stack) { |
| 5606 | mPreferredTopFocusableStack = null; |
| 5607 | } |
| 5608 | releaseSelfIfNeeded(); |
| 5609 | mAtmService.updateSleepIfNeededLocked(); |
| 5610 | onStackOrderChanged(stack); |
| 5611 | } |
| 5612 | |
| 5613 | void positionStackAtTop(ActivityStack stack, boolean includingParents) { |
| 5614 | positionStackAtTop(stack, includingParents, null /* updateLastFocusedStackReason */); |
| 5615 | } |
| 5616 | |
| 5617 | void positionStackAtTop(ActivityStack stack, boolean includingParents, |
| 5618 | String updateLastFocusedStackReason) { |
| 5619 | positionStackAt(stack, getStackCount(), includingParents, updateLastFocusedStackReason); |
| 5620 | } |
| 5621 | |
| 5622 | void positionStackAtBottom(ActivityStack stack) { |
| 5623 | positionStackAtBottom(stack, null /* updateLastFocusedStackReason */); |
| 5624 | } |
| 5625 | |
| 5626 | void positionStackAtBottom(ActivityStack stack, String updateLastFocusedStackReason) { |
| 5627 | positionStackAt(stack, 0, false /* includingParents */, updateLastFocusedStackReason); |
| 5628 | } |
| 5629 | |
| 5630 | private void positionStackAt(ActivityStack stack, int position) { |
| 5631 | positionStackAt(stack, position, false /* includingParents */, |
| 5632 | null /* updateLastFocusedStackReason */); |
| 5633 | } |
| 5634 | |
| 5635 | private void positionStackAt(ActivityStack stack, int position, boolean includingParents, |
| 5636 | String updateLastFocusedStackReason) { |
| 5637 | // TODO: Keep in sync with WindowContainer.positionChildAt(), once we change that to adjust |
| 5638 | // the position internally, also update the logic here |
| 5639 | final ActivityStack prevFocusedStack = updateLastFocusedStackReason != null |
| 5640 | ? getFocusedStack() : null; |
| 5641 | final boolean wasContained = getIndexOf(stack) >= 0; |
| 5642 | if (mSingleTaskInstance && getStackCount() == 1 && !wasContained) { |
| 5643 | throw new IllegalStateException( |
| 5644 | "positionStackAt: Can only have one task on display=" + this); |
| 5645 | } |
| 5646 | |
| 5647 | // Since positionChildAt() is called during the creation process of pinned stacks, |
| 5648 | // ActivityStack#getStack() can be null. |
| 5649 | positionStackAt(position, stack, includingParents); |
| 5650 | |
| 5651 | // The insert position may be adjusted to non-top when there is always-on-top stack. Since |
| 5652 | // the original position is preferred to be top, the stack should have higher priority when |
| 5653 | // we are looking for top focusable stack. The condition {@code wasContained} restricts the |
| 5654 | // preferred stack is set only when moving an existing stack to top instead of adding a new |
| 5655 | // stack that may be too early (e.g. in the middle of launching or reparenting). |
| 5656 | if (wasContained && position >= getStackCount() - 1 && stack.isFocusableAndVisible()) { |
| 5657 | mPreferredTopFocusableStack = stack; |
| 5658 | } else if (mPreferredTopFocusableStack == stack) { |
| 5659 | mPreferredTopFocusableStack = null; |
| 5660 | } |
| 5661 | |
| 5662 | if (updateLastFocusedStackReason != null) { |
| 5663 | final ActivityStack currentFocusedStack = getFocusedStack(); |
| 5664 | if (currentFocusedStack != prevFocusedStack) { |
| 5665 | mLastFocusedStack = prevFocusedStack; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5666 | EventLogTags.writeWmFocusedStack(mRootWindowContainer.mCurrentUser, mDisplayId, |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 5667 | currentFocusedStack == null ? -1 : currentFocusedStack.getRootTaskId(), |
| 5668 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getRootTaskId(), |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5669 | updateLastFocusedStackReason); |
| 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | onStackOrderChanged(stack); |
| 5674 | } |
| 5675 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 5676 | ActivityStack getStack(int rootTaskId) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5677 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 5678 | final ActivityStack stack = getStackAt(i); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 5679 | if (stack.getRootTaskId() == rootTaskId) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5680 | return stack; |
| 5681 | } |
| 5682 | } |
| 5683 | return null; |
| 5684 | } |
| 5685 | |
| 5686 | boolean alwaysCreateStack(int windowingMode, int activityType) { |
| 5687 | // Always create a stack for fullscreen, freeform, and split-screen-secondary windowing |
| 5688 | // modes so that we can manage visual ordering and return types correctly. |
| 5689 | return activityType == ACTIVITY_TYPE_STANDARD |
| 5690 | && (windowingMode == WINDOWING_MODE_FULLSCREEN |
| 5691 | || windowingMode == WINDOWING_MODE_FREEFORM |
| 5692 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 5693 | } |
| 5694 | |
| 5695 | /** |
| 5696 | * Returns an existing stack compatible with the windowing mode and activity type or creates one |
| 5697 | * if a compatible stack doesn't exist. |
| 5698 | * @see #getStack(int, int) |
| 5699 | * @see #createStack(int, int, boolean) |
| 5700 | */ |
| 5701 | ActivityStack getOrCreateStack(int windowingMode, int activityType, |
| 5702 | boolean onTop) { |
| 5703 | if (!alwaysCreateStack(windowingMode, activityType)) { |
| 5704 | ActivityStack stack = getStack(windowingMode, activityType); |
| 5705 | if (stack != null) { |
| 5706 | return stack; |
| 5707 | } |
| 5708 | } |
| 5709 | return createStack(windowingMode, activityType, onTop); |
| 5710 | } |
| 5711 | |
| 5712 | /** |
| 5713 | * Returns an existing stack compatible with the input params or creates one |
| 5714 | * if a compatible stack doesn't exist. |
| 5715 | * @see #getOrCreateStack(int, int, boolean) |
| 5716 | */ |
| 5717 | ActivityStack getOrCreateStack(@Nullable ActivityRecord r, |
| 5718 | @Nullable ActivityOptions options, @Nullable Task candidateTask, int activityType, |
| 5719 | boolean onTop) { |
| 5720 | // First preference is the windowing mode in the activity options if set. |
| 5721 | int windowingMode = (options != null) |
| 5722 | ? options.getLaunchWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 5723 | // Validate that our desired windowingMode will work under the current conditions. |
| 5724 | // UNDEFINED windowing mode is a valid result and means that the new stack will inherit |
| 5725 | // it's display's windowing mode. |
| 5726 | windowingMode = validateWindowingMode(windowingMode, r, candidateTask, activityType); |
| 5727 | return getOrCreateStack(windowingMode, activityType, onTop); |
| 5728 | } |
| 5729 | |
| 5730 | @VisibleForTesting |
| 5731 | int getNextStackId() { |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 5732 | return mAtmService.mStackSupervisor.getNextTaskIdForUser(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5733 | } |
| 5734 | |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 5735 | ActivityStack createStack(int windowingMode, int activityType, boolean onTop) { |
| 5736 | return createStack(windowingMode, activityType, onTop, null /*info*/, null /*intent*/); |
| 5737 | } |
| 5738 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5739 | /** |
| 5740 | * Creates a stack matching the input windowing mode and activity type on this display. |
| 5741 | * @param windowingMode The windowing mode the stack should be created in. If |
| 5742 | * {@link WindowConfiguration#WINDOWING_MODE_UNDEFINED} then the stack will |
| 5743 | * inherit its parent's windowing mode. |
| 5744 | * @param activityType The activityType the stack should be created in. If |
| 5745 | * {@link WindowConfiguration#ACTIVITY_TYPE_UNDEFINED} then the stack will |
| 5746 | * be created in {@link WindowConfiguration#ACTIVITY_TYPE_STANDARD}. |
| 5747 | * @param onTop If true the stack will be created at the top of the display, else at the bottom. |
| 5748 | * @return The newly created stack. |
| 5749 | */ |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 5750 | ActivityStack createStack(int windowingMode, int activityType, boolean onTop, ActivityInfo info, |
| 5751 | Intent intent) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5752 | if (mSingleTaskInstance && getStackCount() > 0) { |
| 5753 | // Create stack on default display instead since this display can only contain 1 stack. |
| 5754 | // TODO: Kinda a hack, but better that having the decision at each call point. Hoping |
| 5755 | // this goes away once ActivityView is no longer using virtual displays. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5756 | return mRootWindowContainer.getDefaultDisplay().createStack( |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 5757 | windowingMode, activityType, onTop, info, intent); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | if (activityType == ACTIVITY_TYPE_UNDEFINED) { |
| 5761 | // Can't have an undefined stack type yet...so re-map to standard. Anyone that wants |
| 5762 | // anything else should be passing it in anyways... |
| 5763 | activityType = ACTIVITY_TYPE_STANDARD; |
| 5764 | } |
| 5765 | |
| 5766 | if (activityType != ACTIVITY_TYPE_STANDARD) { |
| 5767 | // For now there can be only one stack of a particular non-standard activity type on a |
| 5768 | // display. So, get that ignoring whatever windowing mode it is currently in. |
| 5769 | ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
| 5770 | if (stack != null) { |
| 5771 | throw new IllegalArgumentException("Stack=" + stack + " of activityType=" |
| 5772 | + activityType + " already on display=" + this + ". Can't have multiple."); |
| 5773 | } |
| 5774 | } |
| 5775 | |
| 5776 | if (!isWindowingModeSupported(windowingMode, mAtmService.mSupportsMultiWindow, |
| 5777 | mAtmService.mSupportsSplitScreenMultiWindow, |
| 5778 | mAtmService.mSupportsFreeformWindowManagement, |
| 5779 | mAtmService.mSupportsPictureInPicture, activityType)) { |
| 5780 | throw new IllegalArgumentException("Can't create stack for unsupported windowingMode=" |
| 5781 | + windowingMode); |
| 5782 | } |
| 5783 | |
| 5784 | final int stackId = getNextStackId(); |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 5785 | return createStackUnchecked(windowingMode, activityType, stackId, onTop, info, intent); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | @VisibleForTesting |
| 5789 | ActivityStack createStackUnchecked(int windowingMode, int activityType, |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 5790 | int stackId, boolean onTop, ActivityInfo info, Intent intent) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5791 | if (windowingMode == WINDOWING_MODE_PINNED && activityType != ACTIVITY_TYPE_STANDARD) { |
| 5792 | throw new IllegalArgumentException("Stack with windowing mode cannot with non standard " |
| 5793 | + "activity type."); |
| 5794 | } |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 5795 | if (info == null) { |
| 5796 | info = new ActivityInfo(); |
| 5797 | info.applicationInfo = new ApplicationInfo(); |
| 5798 | } |
| 5799 | |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 5800 | final ActivityStack stack = new ActivityStack(this, stackId, |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 5801 | mRootWindowContainer.mStackSupervisor, activityType, info, intent); |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 5802 | addStack(stack, onTop ? POSITION_TOP : POSITION_BOTTOM); |
| 5803 | stack.setWindowingMode(windowingMode, false /* animate */, false /* showRecents */, |
| 5804 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 5805 | true /* creating */); |
| 5806 | |
| 5807 | return stack; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | /** |
| 5811 | * Get the preferred focusable stack in priority. If the preferred stack does not exist, find a |
| 5812 | * focusable and visible stack from the top of stacks in this display. |
| 5813 | */ |
| 5814 | ActivityStack getFocusedStack() { |
| 5815 | if (mPreferredTopFocusableStack != null) { |
| 5816 | return mPreferredTopFocusableStack; |
| 5817 | } |
| 5818 | |
| 5819 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 5820 | final ActivityStack stack = getStackAt(i); |
| 5821 | if (stack.isFocusableAndVisible()) { |
| 5822 | return stack; |
| 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | return null; |
| 5827 | } |
| 5828 | |
| 5829 | ActivityStack getNextFocusableStack(ActivityStack currentFocus, boolean ignoreCurrent) { |
| 5830 | final int currentWindowingMode = currentFocus != null |
| 5831 | ? currentFocus.getWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 5832 | |
| 5833 | ActivityStack candidate = null; |
| 5834 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 5835 | final ActivityStack stack = getStackAt(i); |
| 5836 | if (ignoreCurrent && stack == currentFocus) { |
| 5837 | continue; |
| 5838 | } |
| 5839 | if (!stack.isFocusableAndVisible()) { |
| 5840 | continue; |
| 5841 | } |
| 5842 | |
| 5843 | if (currentWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 5844 | && candidate == null && stack.inSplitScreenPrimaryWindowingMode()) { |
| 5845 | // If the currently focused stack is in split-screen secondary we save off the |
| 5846 | // top primary split-screen stack as a candidate for focus because we might |
| 5847 | // prefer focus to move to an other stack to avoid primary split-screen stack |
| 5848 | // overlapping with a fullscreen stack when a fullscreen stack is higher in z |
| 5849 | // than the next split-screen stack. Assistant stack, I am looking at you... |
| 5850 | // We only move the focus to the primary-split screen stack if there isn't a |
| 5851 | // better alternative. |
| 5852 | candidate = stack; |
| 5853 | continue; |
| 5854 | } |
| 5855 | if (candidate != null && stack.inSplitScreenSecondaryWindowingMode()) { |
| 5856 | // Use the candidate stack since we are now at the secondary split-screen. |
| 5857 | return candidate; |
| 5858 | } |
| 5859 | return stack; |
| 5860 | } |
| 5861 | return candidate; |
| 5862 | } |
| 5863 | |
| 5864 | ActivityRecord getResumedActivity() { |
| 5865 | final ActivityStack focusedStack = getFocusedStack(); |
| 5866 | if (focusedStack == null) { |
| 5867 | return null; |
| 5868 | } |
| 5869 | // TODO(b/111541062): Move this into ActivityStack#getResumedActivity() |
| 5870 | // Check if the focused stack has the resumed activity |
| 5871 | ActivityRecord resumedActivity = focusedStack.getResumedActivity(); |
| 5872 | if (resumedActivity == null || resumedActivity.app == null) { |
| 5873 | // If there is no registered resumed activity in the stack or it is not running - |
| 5874 | // try to use previously resumed one. |
| 5875 | resumedActivity = focusedStack.mPausingActivity; |
| 5876 | if (resumedActivity == null || resumedActivity.app == null) { |
| 5877 | // If previously resumed activity doesn't work either - find the topmost running |
| 5878 | // activity that can be focused. |
| 5879 | resumedActivity = focusedStack.topRunningActivity(true /* focusableOnly */); |
| 5880 | } |
| 5881 | } |
| 5882 | return resumedActivity; |
| 5883 | } |
| 5884 | |
| 5885 | ActivityStack getLastFocusedStack() { |
| 5886 | return mLastFocusedStack; |
| 5887 | } |
| 5888 | |
| 5889 | boolean allResumedActivitiesComplete() { |
| 5890 | for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { |
| 5891 | final ActivityRecord r = getStackAt(stackNdx).getResumedActivity(); |
| 5892 | if (r != null && !r.isState(RESUMED)) { |
| 5893 | return false; |
| 5894 | } |
| 5895 | } |
| 5896 | final ActivityStack currentFocusedStack = getFocusedStack(); |
| 5897 | if (ActivityTaskManagerDebugConfig.DEBUG_STACK) { |
| 5898 | Slog.d(TAG_STACK, "allResumedActivitiesComplete: mLastFocusedStack changing from=" |
| 5899 | + mLastFocusedStack + " to=" + currentFocusedStack); |
| 5900 | } |
| 5901 | mLastFocusedStack = currentFocusedStack; |
| 5902 | return true; |
| 5903 | } |
| 5904 | |
| 5905 | /** |
| 5906 | * Pause all activities in either all of the stacks or just the back stacks. This is done before |
| 5907 | * resuming a new activity and to make sure that previously active activities are |
| 5908 | * paused in stacks that are no longer visible or in pinned windowing mode. This does not |
| 5909 | * pause activities in visible stacks, so if an activity is launched within the same stack/task, |
| 5910 | * then we should explicitly pause that stack's top activity. |
| 5911 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
| 5912 | * @param resuming The resuming activity. |
| 5913 | * @return {@code true} if any activity was paused as a result of this call. |
| 5914 | */ |
| 5915 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming) { |
| 5916 | boolean someActivityPaused = false; |
| 5917 | for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { |
| 5918 | final ActivityStack stack = getStackAt(stackNdx); |
| 5919 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 5920 | if (resumedActivity != null |
| 5921 | && (stack.getVisibility(resuming) != STACK_VISIBILITY_VISIBLE |
Evan Rosky | 226de13 | 2020-01-03 18:00:29 -0800 | [diff] [blame] | 5922 | || !stack.isTopActivityFocusable())) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5923 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack |
| 5924 | + " mResumedActivity=" + resumedActivity); |
| 5925 | someActivityPaused |= stack.startPausingLocked(userLeaving, false /* uiSleeping*/, |
| 5926 | resuming); |
| 5927 | } |
| 5928 | } |
| 5929 | return someActivityPaused; |
| 5930 | } |
| 5931 | |
| 5932 | /** |
| 5933 | * Find task for putting the Activity in. |
| 5934 | */ |
| 5935 | void findTaskLocked(final ActivityRecord r, final boolean isPreferredDisplay, |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5936 | RootWindowContainer.FindTaskResult result) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5937 | mTmpFindTaskResult.clear(); |
| 5938 | for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { |
| 5939 | final ActivityStack stack = getStackAt(stackNdx); |
| 5940 | if (!r.hasCompatibleActivityType(stack)) { |
| 5941 | if (DEBUG_TASKS) { |
| 5942 | Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " + stack); |
| 5943 | } |
| 5944 | continue; |
| 5945 | } |
| 5946 | |
| 5947 | mTmpFindTaskResult.process(r, stack); |
| 5948 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 5949 | // we should keep looking after finding an affinity match to see if there is a |
| 5950 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 5951 | // to target a display which isn't the source of the intent, so skip any affinity |
| 5952 | // matches not on the specified display. |
| 5953 | if (mTmpFindTaskResult.mRecord != null) { |
| 5954 | if (mTmpFindTaskResult.mIdealMatch) { |
| 5955 | result.setTo(mTmpFindTaskResult); |
| 5956 | return; |
| 5957 | } else if (isPreferredDisplay) { |
| 5958 | // Note: since the traversing through the stacks is top down, the floating |
| 5959 | // tasks should always have lower priority than any affinity-matching tasks |
| 5960 | // in the fullscreen stacks |
| 5961 | result.setTo(mTmpFindTaskResult); |
| 5962 | } |
| 5963 | } |
| 5964 | } |
| 5965 | } |
| 5966 | |
| 5967 | /** |
| 5968 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 5969 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 5970 | */ |
| 5971 | void removeStacksInWindowingModes(int... windowingModes) { |
| 5972 | if (windowingModes == null || windowingModes.length == 0) { |
| 5973 | return; |
| 5974 | } |
| 5975 | |
| 5976 | // Collect the stacks that are necessary to be removed instead of performing the removal |
| 5977 | // by looping mStacks, so that we don't miss any stacks after the stack size changed or |
| 5978 | // stacks reordered. |
| 5979 | final ArrayList<ActivityStack> stacks = new ArrayList<>(); |
| 5980 | for (int j = windowingModes.length - 1; j >= 0; --j) { |
| 5981 | final int windowingMode = windowingModes[j]; |
| 5982 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 5983 | final ActivityStack stack = getStackAt(i); |
| 5984 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 5985 | continue; |
| 5986 | } |
| 5987 | if (stack.getWindowingMode() != windowingMode) { |
| 5988 | continue; |
| 5989 | } |
| 5990 | stacks.add(stack); |
| 5991 | } |
| 5992 | } |
| 5993 | |
| 5994 | for (int i = stacks.size() - 1; i >= 0; --i) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5995 | mRootWindowContainer.mStackSupervisor.removeStack(stacks.get(i)); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5996 | } |
| 5997 | } |
| 5998 | |
| 5999 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 6000 | if (activityTypes == null || activityTypes.length == 0) { |
| 6001 | return; |
| 6002 | } |
| 6003 | |
| 6004 | // Collect the stacks that are necessary to be removed instead of performing the removal |
| 6005 | // by looping mStacks, so that we don't miss any stacks after the stack size changed or |
| 6006 | // stacks reordered. |
| 6007 | final ArrayList<ActivityStack> stacks = new ArrayList<>(); |
| 6008 | for (int j = activityTypes.length - 1; j >= 0; --j) { |
| 6009 | final int activityType = activityTypes[j]; |
| 6010 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 6011 | final ActivityStack stack = getStackAt(i); |
| 6012 | if (stack.getActivityType() == activityType) { |
| 6013 | stacks.add(stack); |
| 6014 | } |
| 6015 | } |
| 6016 | } |
| 6017 | |
| 6018 | for (int i = stacks.size() - 1; i >= 0; --i) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6019 | mRootWindowContainer.mStackSupervisor.removeStack(stacks.get(i)); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6020 | } |
| 6021 | } |
| 6022 | |
| 6023 | void onSplitScreenModeDismissed() { |
| 6024 | mAtmService.deferWindowLayout(); |
| 6025 | try { |
| 6026 | // Adjust the windowing mode of any stack in secondary split-screen to fullscreen. |
| 6027 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 6028 | final ActivityStack otherStack = getStackAt(i); |
| 6029 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 6030 | continue; |
| 6031 | } |
| 6032 | otherStack.setWindowingMode(WINDOWING_MODE_UNDEFINED, false /* animate */, |
| 6033 | false /* showRecents */, false /* enteringSplitScreenMode */, |
| 6034 | true /* deferEnsuringVisibility */, false /* creating */); |
| 6035 | } |
| 6036 | } finally { |
| 6037 | final ActivityStack topFullscreenStack = |
| 6038 | getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 6039 | final ActivityStack homeStack = getRootHomeTask(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6040 | if (topFullscreenStack != null && homeStack != null && !isTopStack(homeStack)) { |
| 6041 | // Whenever split-screen is dismissed we want the home stack directly behind the |
| 6042 | // current top fullscreen stack so it shows up when the top stack is finished. |
| 6043 | // TODO: Would be better to use ActivityDisplay.positionChildAt() for this, however |
| 6044 | // ActivityDisplay doesn't have a direct controller to WM side yet. We can switch |
| 6045 | // once we have that. |
| 6046 | homeStack.moveToFront("onSplitScreenModeDismissed"); |
| 6047 | topFullscreenStack.moveToFront("onSplitScreenModeDismissed"); |
| 6048 | } |
| 6049 | mAtmService.continueWindowLayout(); |
| 6050 | } |
| 6051 | } |
| 6052 | |
| 6053 | void onSplitScreenModeActivated() { |
| 6054 | mAtmService.deferWindowLayout(); |
| 6055 | try { |
| 6056 | // Adjust the windowing mode of any affected by split-screen to split-screen secondary. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 6057 | final ActivityStack splitScreenPrimaryStack = getRootSplitScreenPrimaryTask(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6058 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 6059 | final ActivityStack otherStack = getStackAt(i); |
| 6060 | if (otherStack == splitScreenPrimaryStack |
| 6061 | || !otherStack.affectedBySplitScreenResize()) { |
| 6062 | continue; |
| 6063 | } |
| 6064 | otherStack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, |
| 6065 | false /* animate */, false /* showRecents */, |
| 6066 | true /* enteringSplitScreenMode */, true /* deferEnsuringVisibility */, |
| 6067 | false /* creating */); |
| 6068 | } |
| 6069 | } finally { |
| 6070 | mAtmService.continueWindowLayout(); |
| 6071 | } |
| 6072 | } |
| 6073 | |
| 6074 | /** |
| 6075 | * Returns true if the {@param windowingMode} is supported based on other parameters passed in. |
| 6076 | * @param windowingMode The windowing mode we are checking support for. |
| 6077 | * @param supportsMultiWindow If we should consider support for multi-window mode in general. |
| 6078 | * @param supportsSplitScreen If we should consider support for split-screen multi-window. |
| 6079 | * @param supportsFreeform If we should consider support for freeform multi-window. |
| 6080 | * @param supportsPip If we should consider support for picture-in-picture mutli-window. |
| 6081 | * @param activityType The activity type under consideration. |
| 6082 | * @return true if the windowing mode is supported. |
| 6083 | */ |
| 6084 | private boolean isWindowingModeSupported(int windowingMode, boolean supportsMultiWindow, |
| 6085 | boolean supportsSplitScreen, boolean supportsFreeform, boolean supportsPip, |
| 6086 | int activityType) { |
| 6087 | |
| 6088 | if (windowingMode == WINDOWING_MODE_UNDEFINED |
| 6089 | || windowingMode == WINDOWING_MODE_FULLSCREEN) { |
| 6090 | return true; |
| 6091 | } |
| 6092 | if (!supportsMultiWindow) { |
| 6093 | return false; |
| 6094 | } |
| 6095 | |
Wale Ogunwale | 194435b | 2019-12-23 12:56:51 -0800 | [diff] [blame] | 6096 | if (windowingMode == WINDOWING_MODE_MULTI_WINDOW) { |
| 6097 | return true; |
| 6098 | } |
| 6099 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6100 | final int displayWindowingMode = getWindowingMode(); |
| 6101 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 6102 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
| 6103 | return supportsSplitScreen |
| 6104 | && WindowConfiguration.supportSplitScreenWindowingMode(activityType) |
| 6105 | // Freeform windows and split-screen windows don't mix well, so prevent |
| 6106 | // split windowing modes on freeform displays. |
| 6107 | && displayWindowingMode != WINDOWING_MODE_FREEFORM; |
| 6108 | } |
| 6109 | |
| 6110 | if (!supportsFreeform && windowingMode == WINDOWING_MODE_FREEFORM) { |
| 6111 | return false; |
| 6112 | } |
| 6113 | |
| 6114 | if (!supportsPip && windowingMode == WINDOWING_MODE_PINNED) { |
| 6115 | return false; |
| 6116 | } |
| 6117 | return true; |
| 6118 | } |
| 6119 | |
| 6120 | /** |
| 6121 | * Resolves the windowing mode that an {@link ActivityRecord} would be in if started on this |
| 6122 | * display with the provided parameters. |
| 6123 | * |
| 6124 | * @param r The ActivityRecord in question. |
| 6125 | * @param options Options to start with. |
| 6126 | * @param task The task within-which the activity would start. |
| 6127 | * @param activityType The type of activity to start. |
| 6128 | * @return The resolved (not UNDEFINED) windowing-mode that the activity would be in. |
| 6129 | */ |
| 6130 | int resolveWindowingMode(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
| 6131 | @Nullable Task task, int activityType) { |
| 6132 | |
| 6133 | // First preference if the windowing mode in the activity options if set. |
| 6134 | int windowingMode = (options != null) |
| 6135 | ? options.getLaunchWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 6136 | |
| 6137 | // If windowing mode is unset, then next preference is the candidate task, then the |
| 6138 | // activity record. |
| 6139 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 6140 | if (task != null) { |
| 6141 | windowingMode = task.getWindowingMode(); |
| 6142 | } |
| 6143 | if (windowingMode == WINDOWING_MODE_UNDEFINED && r != null) { |
| 6144 | windowingMode = r.getWindowingMode(); |
| 6145 | } |
| 6146 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 6147 | // Use the display's windowing mode. |
| 6148 | windowingMode = getWindowingMode(); |
| 6149 | } |
| 6150 | } |
| 6151 | windowingMode = validateWindowingMode(windowingMode, r, task, activityType); |
| 6152 | return windowingMode != WINDOWING_MODE_UNDEFINED |
| 6153 | ? windowingMode : WINDOWING_MODE_FULLSCREEN; |
| 6154 | } |
| 6155 | |
| 6156 | /** |
| 6157 | * Check that the requested windowing-mode is appropriate for the specified task and/or activity |
| 6158 | * on this display. |
| 6159 | * |
| 6160 | * @param windowingMode The windowing-mode to validate. |
| 6161 | * @param r The {@link ActivityRecord} to check against. |
| 6162 | * @param task The {@link Task} to check against. |
| 6163 | * @param activityType An activity type. |
| 6164 | * @return The provided windowingMode or the closest valid mode which is appropriate. |
| 6165 | */ |
| 6166 | int validateWindowingMode(int windowingMode, @Nullable ActivityRecord r, @Nullable Task task, |
| 6167 | int activityType) { |
| 6168 | // Make sure the windowing mode we are trying to use makes sense for what is supported. |
| 6169 | boolean supportsMultiWindow = mAtmService.mSupportsMultiWindow; |
| 6170 | boolean supportsSplitScreen = mAtmService.mSupportsSplitScreenMultiWindow; |
| 6171 | boolean supportsFreeform = mAtmService.mSupportsFreeformWindowManagement; |
| 6172 | boolean supportsPip = mAtmService.mSupportsPictureInPicture; |
| 6173 | if (supportsMultiWindow) { |
| 6174 | if (task != null) { |
| 6175 | supportsMultiWindow = task.isResizeable(); |
| 6176 | supportsSplitScreen = task.supportsSplitScreenWindowingMode(); |
| 6177 | // TODO: Do we need to check for freeform and Pip support here? |
| 6178 | } else if (r != null) { |
| 6179 | supportsMultiWindow = r.isResizeable(); |
| 6180 | supportsSplitScreen = r.supportsSplitScreenWindowingMode(); |
| 6181 | supportsFreeform = r.supportsFreeform(); |
| 6182 | supportsPip = r.supportsPictureInPicture(); |
| 6183 | } |
| 6184 | } |
| 6185 | |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 6186 | final boolean inSplitScreenMode = hasSplitScreenPrimaryTask(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6187 | if (!inSplitScreenMode |
| 6188 | && windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY) { |
| 6189 | // Switch to the display's windowing mode if we are not in split-screen mode and we are |
| 6190 | // trying to launch in split-screen secondary. |
| 6191 | windowingMode = WINDOWING_MODE_UNDEFINED; |
| 6192 | } else if (inSplitScreenMode && (windowingMode == WINDOWING_MODE_FULLSCREEN |
| 6193 | || windowingMode == WINDOWING_MODE_UNDEFINED) |
| 6194 | && supportsSplitScreen) { |
| 6195 | windowingMode = WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 6196 | } |
| 6197 | |
| 6198 | if (windowingMode != WINDOWING_MODE_UNDEFINED |
| 6199 | && isWindowingModeSupported(windowingMode, supportsMultiWindow, supportsSplitScreen, |
| 6200 | supportsFreeform, supportsPip, activityType)) { |
| 6201 | return windowingMode; |
| 6202 | } |
| 6203 | return WINDOWING_MODE_UNDEFINED; |
| 6204 | } |
| 6205 | |
| 6206 | boolean isTopStack(ActivityStack stack) { |
| 6207 | return stack == getTopStack(); |
| 6208 | } |
| 6209 | |
| 6210 | boolean isTopNotPinnedStack(ActivityStack stack) { |
| 6211 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 6212 | final ActivityStack current = getStackAt(i); |
| 6213 | if (!current.inPinnedWindowingMode()) { |
| 6214 | return current == stack; |
| 6215 | } |
| 6216 | } |
| 6217 | return false; |
| 6218 | } |
| 6219 | |
| 6220 | ActivityRecord topRunningActivity() { |
| 6221 | return topRunningActivity(false /* considerKeyguardState */); |
| 6222 | } |
| 6223 | |
| 6224 | /** |
| 6225 | * Returns the top running activity in the focused stack. In the case the focused stack has no |
| 6226 | * such activity, the next focusable stack on this display is returned. |
| 6227 | * |
| 6228 | * @param considerKeyguardState Indicates whether the locked state should be considered. if |
| 6229 | * {@code true} and the keyguard is locked, only activities that |
| 6230 | * can be shown on top of the keyguard will be considered. |
| 6231 | * @return The top running activity. {@code null} if none is available. |
| 6232 | */ |
| 6233 | ActivityRecord topRunningActivity(boolean considerKeyguardState) { |
| 6234 | ActivityRecord topRunning = null; |
| 6235 | final ActivityStack focusedStack = getFocusedStack(); |
| 6236 | if (focusedStack != null) { |
| 6237 | topRunning = focusedStack.topRunningActivity(); |
| 6238 | } |
| 6239 | |
| 6240 | // Look in other focusable stacks. |
| 6241 | if (topRunning == null) { |
| 6242 | for (int i = getStackCount() - 1; i >= 0; --i) { |
| 6243 | final ActivityStack stack = getStackAt(i); |
| 6244 | // Only consider focusable stacks other than the current focused one. |
Evan Rosky | 226de13 | 2020-01-03 18:00:29 -0800 | [diff] [blame] | 6245 | if (stack == focusedStack || !stack.isTopActivityFocusable()) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6246 | continue; |
| 6247 | } |
| 6248 | topRunning = stack.topRunningActivity(); |
| 6249 | if (topRunning != null) { |
| 6250 | break; |
| 6251 | } |
| 6252 | } |
| 6253 | } |
| 6254 | |
| 6255 | // This activity can be considered the top running activity if we are not considering |
| 6256 | // the locked state, the keyguard isn't locked, or we can show when locked. |
| 6257 | if (topRunning != null && considerKeyguardState |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6258 | && mRootWindowContainer.mStackSupervisor.getKeyguardController() |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6259 | .isKeyguardLocked() |
| 6260 | && !topRunning.canShowWhenLocked()) { |
| 6261 | return null; |
| 6262 | } |
| 6263 | |
| 6264 | return topRunning; |
| 6265 | } |
| 6266 | |
| 6267 | boolean updateDisplayOverrideConfigurationLocked() { |
| 6268 | Configuration values = new Configuration(); |
| 6269 | computeScreenConfiguration(values); |
| 6270 | |
| 6271 | mAtmService.mH.sendMessage(PooledLambda.obtainMessage( |
| 6272 | ActivityManagerInternal::updateOomLevelsForDisplay, mAtmService.mAmInternal, |
| 6273 | mDisplayId)); |
| 6274 | |
| 6275 | Settings.System.clearConfiguration(values); |
| 6276 | updateDisplayOverrideConfigurationLocked(values, null /* starting */, |
| 6277 | false /* deferResume */, mAtmService.mTmpUpdateConfigurationResult); |
| 6278 | return mAtmService.mTmpUpdateConfigurationResult.changes != 0; |
| 6279 | } |
| 6280 | |
| 6281 | /** |
| 6282 | * Updates override configuration specific for the selected display. If no config is provided, |
| 6283 | * new one will be computed in WM based on current display info. |
| 6284 | */ |
| 6285 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, |
| 6286 | ActivityRecord starting, boolean deferResume, |
| 6287 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 6288 | |
| 6289 | int changes = 0; |
| 6290 | boolean kept = true; |
| 6291 | |
| 6292 | mAtmService.deferWindowLayout(); |
| 6293 | try { |
| 6294 | if (values != null) { |
| 6295 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 6296 | // Override configuration of the default display duplicates global config, so |
| 6297 | // we're calling global config update instead for default display. It will also |
| 6298 | // apply the correct override config. |
| 6299 | changes = mAtmService.updateGlobalConfigurationLocked(values, |
| 6300 | false /* initLocale */, false /* persistent */, |
| 6301 | UserHandle.USER_NULL /* userId */, deferResume); |
| 6302 | } else { |
| 6303 | changes = performDisplayOverrideConfigUpdate(values, deferResume); |
| 6304 | } |
| 6305 | } |
| 6306 | |
| 6307 | kept = mAtmService.ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 6308 | } finally { |
| 6309 | mAtmService.continueWindowLayout(); |
| 6310 | } |
| 6311 | |
| 6312 | if (result != null) { |
| 6313 | result.changes = changes; |
| 6314 | result.activityRelaunched = !kept; |
| 6315 | } |
| 6316 | return kept; |
| 6317 | } |
| 6318 | |
| 6319 | int performDisplayOverrideConfigUpdate(Configuration values, boolean deferResume) { |
| 6320 | mTempConfig.setTo(getRequestedOverrideConfiguration()); |
| 6321 | final int changes = mTempConfig.updateFrom(values); |
| 6322 | if (changes != 0) { |
| 6323 | Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " |
| 6324 | + mTempConfig + " for displayId=" + mDisplayId); |
| 6325 | onRequestedOverrideConfigurationChanged(mTempConfig); |
| 6326 | |
| 6327 | final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; |
| 6328 | if (isDensityChange && mDisplayId == DEFAULT_DISPLAY) { |
| 6329 | mAtmService.mAppWarnings.onDensityChanged(); |
| 6330 | |
| 6331 | // Post message to start process to avoid possible deadlock of calling into AMS with |
| 6332 | // the ATMS lock held. |
| 6333 | final Message msg = PooledLambda.obtainMessage( |
| 6334 | ActivityManagerInternal::killAllBackgroundProcessesExcept, |
| 6335 | mAtmService.mAmInternal, N, |
| 6336 | ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); |
| 6337 | mAtmService.mH.sendMessage(msg); |
| 6338 | } |
| 6339 | mWmService.mDisplayNotificationController.dispatchDisplayChanged( |
| 6340 | this, getConfiguration()); |
| 6341 | } |
| 6342 | return changes; |
| 6343 | } |
| 6344 | |
| 6345 | @Override |
| 6346 | public void onRequestedOverrideConfigurationChanged(Configuration overrideConfiguration) { |
| 6347 | final int currRotation = |
| 6348 | getRequestedOverrideConfiguration().windowConfiguration.getRotation(); |
| 6349 | if (currRotation != ROTATION_UNDEFINED |
| 6350 | && currRotation != overrideConfiguration.windowConfiguration.getRotation()) { |
| 6351 | applyRotationLocked(currRotation, |
| 6352 | overrideConfiguration.windowConfiguration.getRotation()); |
| 6353 | } |
| 6354 | mCurrentOverrideConfigurationChanges = |
| 6355 | getRequestedOverrideConfiguration().diff(overrideConfiguration); |
| 6356 | super.onRequestedOverrideConfigurationChanged(overrideConfiguration); |
| 6357 | mCurrentOverrideConfigurationChanges = 0; |
| 6358 | mWmService.setNewDisplayOverrideConfiguration(overrideConfiguration, this); |
| 6359 | mAtmService.addWindowLayoutReasons( |
| 6360 | ActivityTaskManagerService.LAYOUT_REASON_CONFIG_CHANGED); |
| 6361 | } |
| 6362 | |
| 6363 | /** Checks whether the given activity is in size compatibility mode and notifies the change. */ |
| 6364 | void handleActivitySizeCompatModeIfNeeded(ActivityRecord r) { |
| 6365 | if (!r.isState(RESUMED) || r.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 6366 | // The callback is only interested in the foreground changes of fullscreen activity. |
| 6367 | return; |
| 6368 | } |
| 6369 | if (!r.inSizeCompatMode()) { |
| 6370 | if (mLastCompatModeActivity != null) { |
| 6371 | mAtmService.getTaskChangeNotificationController() |
| 6372 | .notifySizeCompatModeActivityChanged(mDisplayId, null /* activityToken */); |
| 6373 | } |
| 6374 | mLastCompatModeActivity = null; |
| 6375 | return; |
| 6376 | } |
| 6377 | if (mLastCompatModeActivity == r) { |
| 6378 | return; |
| 6379 | } |
| 6380 | mLastCompatModeActivity = r; |
| 6381 | mAtmService.getTaskChangeNotificationController() |
| 6382 | .notifySizeCompatModeActivityChanged(mDisplayId, r.appToken); |
| 6383 | } |
| 6384 | |
| 6385 | boolean isUidPresent(int uid) { |
| 6386 | final PooledPredicate p = PooledLambda.obtainPredicate( |
| 6387 | ActivityRecord::isUid, PooledLambda.__(ActivityRecord.class), uid); |
| 6388 | final boolean isUidPresent = mDisplayContent.getActivity(p) != null; |
| 6389 | p.recycle(); |
| 6390 | return isUidPresent; |
| 6391 | } |
| 6392 | |
| 6393 | /** |
| 6394 | * @see #mRemoved |
| 6395 | */ |
| 6396 | boolean isRemoved() { |
| 6397 | return mRemoved; |
| 6398 | } |
| 6399 | |
| 6400 | /** |
| 6401 | * @see #mRemoving |
| 6402 | */ |
| 6403 | boolean isRemoving() { |
| 6404 | return mRemoving; |
| 6405 | } |
| 6406 | |
| 6407 | void remove() { |
| 6408 | mRemoving = true; |
| 6409 | final boolean destroyContentOnRemoval = shouldDestroyContentOnRemove(); |
| 6410 | ActivityStack lastReparentedStack = null; |
| 6411 | mPreferredTopFocusableStack = null; |
| 6412 | |
| 6413 | // Stacks could be reparented from the removed display to other display. While |
| 6414 | // reparenting the last stack of the removed display, the remove display is ready to be |
| 6415 | // released (no more ActivityStack). But, we cannot release it at that moment or the |
| 6416 | // related WindowContainer will also be removed. So, we set display as removed after |
| 6417 | // reparenting stack finished. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6418 | final DisplayContent toDisplay = mRootWindowContainer.getDefaultDisplay(); |
| 6419 | mRootWindowContainer.mStackSupervisor.beginDeferResume(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6420 | try { |
| 6421 | int numStacks = getStackCount(); |
| 6422 | // Keep the order from bottom to top. |
| 6423 | for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { |
| 6424 | final ActivityStack stack = getStackAt(stackNdx); |
| 6425 | // Always finish non-standard type stacks. |
| 6426 | if (destroyContentOnRemoval || !stack.isActivityTypeStandardOrUndefined()) { |
| 6427 | stack.finishAllActivitiesImmediately(); |
| 6428 | } else { |
| 6429 | // If default display is in split-window mode, set windowing mode of the stack |
| 6430 | // to split-screen secondary. Otherwise, set the windowing mode to undefined by |
| 6431 | // default to let stack inherited the windowing mode from the new display. |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 6432 | final int windowingMode = toDisplay.hasSplitScreenPrimaryTask() |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6433 | ? WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 6434 | : WINDOWING_MODE_UNDEFINED; |
| 6435 | stack.reparent(toDisplay, true /* onTop */); |
| 6436 | stack.setWindowingMode(windowingMode); |
| 6437 | lastReparentedStack = stack; |
| 6438 | } |
| 6439 | // Stacks may be removed from this display. Ensure each stack will be processed and |
| 6440 | // the loop will end. |
| 6441 | stackNdx -= numStacks - getStackCount(); |
| 6442 | numStacks = getStackCount(); |
| 6443 | } |
| 6444 | } finally { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6445 | mRootWindowContainer.mStackSupervisor.endDeferResume(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6446 | } |
| 6447 | mRemoved = true; |
| 6448 | |
| 6449 | // Only update focus/visibility for the last one because there may be many stacks are |
| 6450 | // reparented and the intermediate states are unnecessary. |
| 6451 | if (lastReparentedStack != null) { |
| 6452 | lastReparentedStack.postReparent(); |
| 6453 | } |
| 6454 | releaseSelfIfNeeded(); |
| 6455 | |
| 6456 | if (!mAllSleepTokens.isEmpty()) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6457 | mRootWindowContainer.mSleepTokens.removeAll(mAllSleepTokens); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6458 | mAllSleepTokens.clear(); |
| 6459 | mAtmService.updateSleepIfNeededLocked(); |
| 6460 | } |
| 6461 | } |
| 6462 | |
| 6463 | private void releaseSelfIfNeeded() { |
| 6464 | if (!mRemoved) { |
| 6465 | return; |
| 6466 | } |
| 6467 | |
| 6468 | final ActivityStack stack = getStackCount() == 1 ? getStackAt(0) : null; |
| 6469 | if (stack != null && stack.isActivityTypeHome() && !stack.hasChild()) { |
| 6470 | // Release this display if an empty home stack is the only thing left. |
| 6471 | // Since it is the last stack, this display will be released along with the stack |
| 6472 | // removal. |
| 6473 | stack.removeIfPossible(); |
| 6474 | } else if (getTopStack() == null) { |
| 6475 | removeIfPossible(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6476 | mRootWindowContainer.mStackSupervisor |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6477 | .getKeyguardController().onDisplayRemoved(mDisplayId); |
| 6478 | } |
| 6479 | } |
| 6480 | |
| 6481 | /** Update and get all UIDs that are present on the display and have access to it. */ |
| 6482 | IntArray getPresentUIDs() { |
| 6483 | mDisplayAccessUIDs.clear(); |
| 6484 | final PooledConsumer c = PooledLambda.obtainConsumer(DisplayContent::addActivityUid, |
| 6485 | PooledLambda.__(ActivityRecord.class), mDisplayAccessUIDs); |
| 6486 | mDisplayContent.forAllActivities(c); |
| 6487 | c.recycle(); |
| 6488 | return mDisplayAccessUIDs; |
| 6489 | } |
| 6490 | |
| 6491 | private static void addActivityUid(ActivityRecord r, IntArray uids) { |
| 6492 | uids.add(r.getUid()); |
| 6493 | } |
| 6494 | |
| 6495 | @VisibleForTesting |
| 6496 | boolean shouldDestroyContentOnRemove() { |
| 6497 | return mDisplay.getRemoveMode() == REMOVE_MODE_DESTROY_CONTENT; |
| 6498 | } |
| 6499 | |
| 6500 | boolean shouldSleep() { |
| 6501 | return (getStackCount() == 0 || !mAllSleepTokens.isEmpty()) |
| 6502 | && (mAtmService.mRunningVoice == null); |
| 6503 | } |
| 6504 | |
| 6505 | void setFocusedApp(ActivityRecord r, boolean moveFocusNow) { |
| 6506 | final ActivityRecord newFocus; |
| 6507 | final IBinder token = r.appToken; |
| 6508 | if (token == null) { |
| 6509 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "Clearing focused app, displayId=%d", |
| 6510 | mDisplayId); |
| 6511 | newFocus = null; |
| 6512 | } else { |
| 6513 | newFocus = mWmService.mRoot.getActivityRecord(token); |
| 6514 | if (newFocus == null) { |
| 6515 | Slog.w(TAG_WM, "Attempted to set focus to non-existing app token: " + token |
| 6516 | + ", displayId=" + mDisplayId); |
| 6517 | } |
| 6518 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 6519 | "Set focused app to: %s moveFocusNow=%b displayId=%d", newFocus, |
| 6520 | moveFocusNow, mDisplayId); |
| 6521 | } |
| 6522 | |
| 6523 | final boolean changed = setFocusedApp(newFocus); |
| 6524 | if (moveFocusNow && changed) { |
| 6525 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 6526 | true /*updateInputWindows*/); |
| 6527 | } |
| 6528 | } |
| 6529 | |
| 6530 | /** |
| 6531 | * @return the stack currently above the {@param stack}. Can be null if the {@param stack} is |
| 6532 | * already top-most. |
| 6533 | */ |
| 6534 | ActivityStack getStackAbove(ActivityStack stack) { |
| 6535 | final int stackIndex = getIndexOf(stack) + 1; |
| 6536 | return (stackIndex < getStackCount()) ? getStackAt(stackIndex) : null; |
| 6537 | } |
| 6538 | |
| 6539 | /** |
| 6540 | * Adjusts the {@param stack} behind the last visible stack in the display if necessary. |
| 6541 | * Generally used in conjunction with {@link #moveStackBehindStack}. |
| 6542 | */ |
| 6543 | void moveStackBehindBottomMostVisibleStack(ActivityStack stack) { |
| 6544 | if (stack.shouldBeVisible(null)) { |
| 6545 | // Skip if the stack is already visible |
| 6546 | return; |
| 6547 | } |
| 6548 | |
| 6549 | // Move the stack to the bottom to not affect the following visibility checks |
| 6550 | positionStackAtBottom(stack); |
| 6551 | |
| 6552 | // Find the next position where the stack should be placed |
| 6553 | final int numStacks = getStackCount(); |
| 6554 | for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { |
| 6555 | final ActivityStack s = getStackAt(stackNdx); |
| 6556 | if (s == stack) { |
| 6557 | continue; |
| 6558 | } |
| 6559 | final int winMode = s.getWindowingMode(); |
| 6560 | final boolean isValidWindowingMode = winMode == WINDOWING_MODE_FULLSCREEN |
| 6561 | || winMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 6562 | if (s.shouldBeVisible(null) && isValidWindowingMode) { |
| 6563 | // Move the provided stack to behind this stack |
| 6564 | positionStackAt(stack, Math.max(0, stackNdx - 1)); |
| 6565 | break; |
| 6566 | } |
| 6567 | } |
| 6568 | } |
| 6569 | |
| 6570 | /** |
| 6571 | * Moves the {@param stack} behind the given {@param behindStack} if possible. If |
| 6572 | * {@param behindStack} is not currently in the display, then then the stack is moved to the |
| 6573 | * back. Generally used in conjunction with {@link #moveStackBehindBottomMostVisibleStack}. |
| 6574 | */ |
| 6575 | void moveStackBehindStack(ActivityStack stack, ActivityStack behindStack) { |
| 6576 | if (behindStack == null || behindStack == stack) { |
| 6577 | return; |
| 6578 | } |
| 6579 | |
| 6580 | // Note that positionChildAt will first remove the given stack before inserting into the |
| 6581 | // list, so we need to adjust the insertion index to account for the removed index |
| 6582 | // TODO: Remove this logic when WindowContainer.positionChildAt() is updated to adjust the |
| 6583 | // position internally |
| 6584 | final int stackIndex = getIndexOf(stack); |
| 6585 | final int behindStackIndex = getIndexOf(behindStack); |
| 6586 | final int insertIndex = stackIndex <= behindStackIndex |
| 6587 | ? behindStackIndex - 1 : behindStackIndex; |
| 6588 | positionStackAt(stack, Math.max(0, insertIndex)); |
| 6589 | } |
| 6590 | |
| 6591 | void ensureActivitiesVisible(ActivityRecord starting, int configChanges, |
| 6592 | boolean preserveWindows, boolean notifyClients) { |
| 6593 | for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) { |
| 6594 | final ActivityStack stack = getStackAt(stackNdx); |
| 6595 | stack.ensureActivitiesVisible(starting, configChanges, preserveWindows, |
| 6596 | notifyClients); |
| 6597 | } |
| 6598 | } |
| 6599 | |
| 6600 | void moveHomeStackToFront(String reason) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 6601 | final ActivityStack homeStack = getRootHomeTask(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6602 | if (homeStack != null) { |
| 6603 | homeStack.moveToFront(reason); |
| 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | /** |
| 6608 | * Moves the focusable home activity to top. If there is no such activity, the home stack will |
| 6609 | * still move to top. |
| 6610 | */ |
| 6611 | void moveHomeActivityToTop(String reason) { |
| 6612 | final ActivityRecord top = getHomeActivity(); |
| 6613 | if (top == null) { |
| 6614 | moveHomeStackToFront(reason); |
| 6615 | return; |
| 6616 | } |
| 6617 | top.moveFocusableActivityToTop(reason); |
| 6618 | } |
| 6619 | |
| 6620 | @Nullable |
| 6621 | ActivityRecord getHomeActivity() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6622 | return getHomeActivityForUser(mRootWindowContainer.mCurrentUser); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6623 | } |
| 6624 | |
| 6625 | @Nullable |
| 6626 | ActivityRecord getHomeActivityForUser(int userId) { |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 6627 | final ActivityStack homeStack = getRootHomeTask(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6628 | if (homeStack == null) { |
| 6629 | return null; |
| 6630 | } |
| 6631 | |
| 6632 | final PooledPredicate p = PooledLambda.obtainPredicate( |
| 6633 | DisplayContent::isHomeActivityForUser, PooledLambda.__(ActivityRecord.class), |
| 6634 | userId); |
| 6635 | final ActivityRecord r = homeStack.getActivity(p); |
| 6636 | p.recycle(); |
| 6637 | return r; |
| 6638 | } |
| 6639 | |
| 6640 | private static boolean isHomeActivityForUser(ActivityRecord r, int userId) { |
| 6641 | return r.isActivityTypeHome() && (userId == UserHandle.USER_ALL || r.mUserId == userId); |
| 6642 | } |
| 6643 | |
| 6644 | boolean isSleeping() { |
| 6645 | return mSleeping; |
| 6646 | } |
| 6647 | |
| 6648 | void setIsSleeping(boolean asleep) { |
| 6649 | mSleeping = asleep; |
| 6650 | } |
| 6651 | |
| 6652 | /** |
| 6653 | * Adds a listener to be notified whenever the stack order in the display changes. Currently |
| 6654 | * only used by the {@link RecentsAnimation} to determine whether to interrupt and cancel the |
| 6655 | * current animation when the system state changes. |
| 6656 | */ |
| 6657 | void registerStackOrderChangedListener(OnStackOrderChangedListener listener) { |
| 6658 | if (!mStackOrderChangedCallbacks.contains(listener)) { |
| 6659 | mStackOrderChangedCallbacks.add(listener); |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | /** |
| 6664 | * Removes a previously registered stack order change listener. |
| 6665 | */ |
| 6666 | void unregisterStackOrderChangedListener(OnStackOrderChangedListener listener) { |
| 6667 | mStackOrderChangedCallbacks.remove(listener); |
| 6668 | } |
| 6669 | |
| 6670 | /** |
| 6671 | * Notifies of a stack order change |
| 6672 | * @param stack The stack which triggered the order change |
| 6673 | */ |
| 6674 | private void onStackOrderChanged(ActivityStack stack) { |
| 6675 | for (int i = mStackOrderChangedCallbacks.size() - 1; i >= 0; i--) { |
| 6676 | mStackOrderChangedCallbacks.get(i).onStackOrderChanged(stack); |
| 6677 | } |
| 6678 | } |
| 6679 | |
| 6680 | void setDisplayToSingleTaskInstance() { |
| 6681 | final int childCount = getStackCount(); |
| 6682 | if (childCount > 1) { |
| 6683 | throw new IllegalArgumentException("Display already has multiple stacks. display=" |
| 6684 | + this); |
| 6685 | } |
| 6686 | if (childCount > 0) { |
| 6687 | final ActivityStack stack = getStackAt(0); |
| 6688 | if (stack.getChildCount() > 1) { |
| 6689 | throw new IllegalArgumentException("Display stack already has multiple tasks." |
| 6690 | + " display=" + this + " stack=" + stack); |
| 6691 | } |
| 6692 | } |
| 6693 | |
| 6694 | mSingleTaskInstance = true; |
| 6695 | } |
| 6696 | |
| 6697 | /** Returns true if the display can only contain one task */ |
| 6698 | boolean isSingleTaskInstance() { |
| 6699 | return mSingleTaskInstance; |
| 6700 | } |
| 6701 | |
| 6702 | @VisibleForTesting |
| 6703 | void removeAllTasks() { |
| 6704 | forAllTasks((t) -> { t.getStack().removeChild(t, "removeAllTasks"); }); |
| 6705 | } |
| 6706 | |
| 6707 | /** |
| 6708 | * Callback for when the order of the stacks in the display changes. |
| 6709 | */ |
| 6710 | interface OnStackOrderChangedListener { |
| 6711 | void onStackOrderChanged(ActivityStack stack); |
| 6712 | } |
| 6713 | |
| 6714 | public void dumpStacks(PrintWriter pw) { |
| 6715 | for (int i = getStackCount() - 1; i >= 0; --i) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 6716 | pw.print(getStackAt(i).getRootTaskId()); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6717 | if (i > 0) { |
| 6718 | pw.print(","); |
| 6719 | } |
| 6720 | } |
| 6721 | } |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 6722 | |
| 6723 | /** |
| 6724 | * Similar to {@link RootWindowContainer#isAnyNonToastWindowVisibleForUid(int)}, but |
| 6725 | * used for pid. |
| 6726 | */ |
| 6727 | boolean isAnyNonToastWindowVisibleForPid(int pid) { |
| 6728 | final PooledPredicate p = PooledLambda.obtainPredicate( |
| 6729 | WindowState::isNonToastWindowVisibleForPid, |
| 6730 | PooledLambda.__(WindowState.class), pid); |
| 6731 | |
| 6732 | final WindowState w = getWindow(p); |
| 6733 | p.recycle(); |
| 6734 | return w != null; |
| 6735 | } |
| 6736 | |
| 6737 | Context getDisplayUiContext() { |
| 6738 | return mDisplayPolicy.getSystemUiContext(); |
| 6739 | } |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 6740 | |
| 6741 | class RemoteInsetsControlTarget implements InsetsControlTarget { |
| 6742 | private final IDisplayWindowInsetsController mRemoteInsetsController; |
| 6743 | |
| 6744 | RemoteInsetsControlTarget(IDisplayWindowInsetsController controller) { |
| 6745 | mRemoteInsetsController = controller; |
| 6746 | } |
| 6747 | |
| 6748 | void notifyInsetsChanged() { |
| 6749 | try { |
| 6750 | mRemoteInsetsController.insetsChanged( |
| 6751 | getInsetsStateController().getRawInsetsState()); |
| 6752 | } catch (RemoteException e) { |
| 6753 | Slog.w(TAG, "Failed to deliver inset state change", e); |
| 6754 | } |
| 6755 | } |
| 6756 | |
| 6757 | @Override |
| 6758 | public void notifyInsetsControlChanged() { |
| 6759 | final InsetsStateController stateController = getInsetsStateController(); |
| 6760 | try { |
| 6761 | mRemoteInsetsController.insetsControlChanged(stateController.getRawInsetsState(), |
| 6762 | stateController.getControlsForDispatch(this)); |
| 6763 | } catch (RemoteException e) { |
| 6764 | Slog.w(TAG, "Failed to deliver inset state change", e); |
| 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | @Override |
| 6769 | public void showInsets(@WindowInsets.Type.InsetsType int types, boolean fromIme) { |
| 6770 | try { |
| 6771 | mRemoteInsetsController.showInsets(types, fromIme); |
| 6772 | } catch (RemoteException e) { |
| 6773 | Slog.w(TAG, "Failed to deliver showInsets", e); |
| 6774 | } |
| 6775 | } |
| 6776 | |
| 6777 | @Override |
| 6778 | public void hideInsets(@WindowInsets.Type.InsetsType int types, boolean fromIme) { |
| 6779 | try { |
| 6780 | mRemoteInsetsController.hideInsets(types, fromIme); |
| 6781 | } catch (RemoteException e) { |
| 6782 | Slog.w(TAG, "Failed to deliver showInsets", e); |
| 6783 | } |
| 6784 | } |
| 6785 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6786 | } |