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 | |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Galia Peycheva | 70b5571 | 2020-03-16 18:31:34 +0100 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM; |
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; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.ROTATION_UNDEFINED; |
| 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 194435b | 2019-12-23 12:56:51 -0800 | [diff] [blame] | 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; |
Evan Rosky | 688c838 | 2020-04-03 17:27:08 -0700 | [diff] [blame] | 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 29 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 30 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 31 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 32 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 33 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 34 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 35 | import static android.os.Build.VERSION_CODES.N; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 36 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 37 | import static android.util.DisplayMetrics.DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 38 | import static android.view.Display.DEFAULT_DISPLAY; |
| 39 | import static android.view.Display.FLAG_PRIVATE; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 40 | import static android.view.Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 41 | import static android.view.Display.INVALID_DISPLAY; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 42 | import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 43 | import static android.view.InsetsState.ITYPE_IME; |
| 44 | import static android.view.InsetsState.ITYPE_LEFT_GESTURES; |
| 45 | import static android.view.InsetsState.ITYPE_RIGHT_GESTURES; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 46 | import static android.view.Surface.ROTATION_0; |
| 47 | import static android.view.Surface.ROTATION_180; |
| 48 | import static android.view.Surface.ROTATION_270; |
| 49 | import static android.view.Surface.ROTATION_90; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 50 | import static android.view.View.GONE; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 51 | import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 52 | import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 53 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 54 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 55 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 56 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 57 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 58 | import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 59 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 60 | import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 61 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 62 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 63 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 64 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 65 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 66 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 67 | import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 68 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 69 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 71 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 72 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 73 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 74 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 75 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 76 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 77 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 78 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 79 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 80 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 81 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 82 | import static com.android.server.wm.DisplayContentProto.APP_TRANSITION; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 83 | import static com.android.server.wm.DisplayContentProto.CLOSING_APPS; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 84 | import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES; |
| 85 | import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO; |
Vishnu Nair | dddc9f5 | 2020-03-09 09:37:27 -0700 | [diff] [blame] | 86 | import static com.android.server.wm.DisplayContentProto.DISPLAY_READY; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 87 | import static com.android.server.wm.DisplayContentProto.DPI; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 88 | import static com.android.server.wm.DisplayContentProto.FOCUSED_APP; |
Vadim Caen | a0fa966 | 2020-01-27 15:00:01 +0100 | [diff] [blame] | 89 | import static com.android.server.wm.DisplayContentProto.FOCUSED_ROOT_TASK_ID; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 90 | import static com.android.server.wm.DisplayContentProto.ID; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 91 | import static com.android.server.wm.DisplayContentProto.OPENING_APPS; |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 92 | import static com.android.server.wm.DisplayContentProto.OVERLAY_WINDOWS; |
Vadim Caen | a0fa966 | 2020-01-27 15:00:01 +0100 | [diff] [blame] | 93 | import static com.android.server.wm.DisplayContentProto.RESUMED_ACTIVITY; |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 94 | import static com.android.server.wm.DisplayContentProto.ROOT_DISPLAY_AREA; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 95 | import static com.android.server.wm.DisplayContentProto.ROTATION; |
| 96 | import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION; |
Vadim Caen | a0fa966 | 2020-01-27 15:00:01 +0100 | [diff] [blame] | 97 | import static com.android.server.wm.DisplayContentProto.SINGLE_TASK_INSTANCE; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 98 | import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 99 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
| 100 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS; |
| 101 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; |
| 102 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; |
| 103 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_SCREEN_ON; |
| 104 | import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 105 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 106 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Vishnu Nair | dddc9f5 | 2020-03-09 09:37:27 -0700 | [diff] [blame] | 107 | import static com.android.server.wm.WindowContainerChildProto.DISPLAY_CONTENT; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 108 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 109 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 110 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 111 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 112 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 113 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 114 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 115 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 116 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 117 | import static com.android.server.wm.WindowManagerService.H.REPORT_FOCUS_CHANGE; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 118 | 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] | 119 | import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS; |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 120 | import static com.android.server.wm.WindowManagerService.H.UPDATE_MULTI_WINDOW_STACKS; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 121 | import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 122 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 123 | import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 124 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 125 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
| 126 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS; |
| 127 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 128 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 129 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 130 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 131 | import static com.android.server.wm.WindowState.EXCLUSION_LEFT; |
| 132 | import static com.android.server.wm.WindowState.EXCLUSION_RIGHT; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 133 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 134 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 135 | import static com.android.server.wm.utils.RegionUtils.forEachRectReverse; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 136 | import static com.android.server.wm.utils.RegionUtils.rectListToRegion; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 137 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 138 | import android.annotation.IntDef; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 139 | import android.annotation.NonNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 140 | import android.annotation.Nullable; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 141 | import android.app.ActivityManager; |
| 142 | import android.app.ActivityManagerInternal; |
Jorim Jaggi | cc57cb7 | 2020-04-09 14:54:13 +0200 | [diff] [blame] | 143 | import android.app.WindowConfiguration; |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 144 | import android.content.Context; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 145 | import android.content.pm.ActivityInfo; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 146 | import android.content.pm.ActivityInfo.ScreenOrientation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 147 | import android.content.res.CompatibilityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 148 | import android.content.res.Configuration; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 149 | import android.graphics.Bitmap; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 150 | import android.graphics.Insets; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 151 | import android.graphics.Matrix; |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 152 | import android.graphics.Point; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 153 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 154 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 155 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 156 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 157 | import android.hardware.display.DisplayManagerInternal; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 158 | import android.metrics.LogMaker; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 159 | import android.os.Binder; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 160 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 161 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 162 | import android.os.IBinder; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 163 | import android.os.Message; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 164 | import android.os.Process; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 165 | import android.os.RemoteCallbackList; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 166 | import android.os.RemoteException; |
| 167 | import android.os.SystemClock; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 168 | import android.os.Trace; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 169 | import android.os.UserHandle; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 170 | import android.provider.Settings; |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 171 | import android.util.ArraySet; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 172 | import android.util.DisplayMetrics; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 173 | import android.util.IntArray; |
shawnlin | 21e3f02 | 2020-01-21 16:36:13 +0800 | [diff] [blame] | 174 | import android.util.RotationUtils; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 175 | import android.util.Slog; |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 176 | import android.util.SparseArray; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 177 | import android.util.SparseBooleanArray; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 178 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 179 | import android.view.Display; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 180 | import android.view.DisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 181 | import android.view.DisplayInfo; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 182 | import android.view.Gravity; |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 183 | import android.view.IDisplayWindowInsetsController; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 184 | import android.view.ISystemGestureExclusionListener; |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 185 | import android.view.IWindow; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 186 | import android.view.InputChannel; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 187 | import android.view.InputDevice; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 188 | import android.view.InputWindowHandle; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 189 | import android.view.InsetsState.InternalInsetsType; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 190 | import android.view.MagnificationSpec; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 191 | import android.view.RemoteAnimationDefinition; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 192 | import android.view.Surface; |
| 193 | import android.view.SurfaceControl; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 194 | import android.view.SurfaceControl.Transaction; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 195 | import android.view.SurfaceSession; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 196 | import android.view.View; |
Tiger Huang | 41ae5e8 | 2020-01-17 18:17:20 +0800 | [diff] [blame] | 197 | import android.view.ViewRootImpl; |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 198 | import android.view.WindowInsets; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 199 | import android.view.WindowManager; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 200 | import android.view.WindowManagerPolicyConstants.PointerEventListener; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 201 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 202 | import com.android.internal.annotations.VisibleForTesting; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 203 | import com.android.internal.logging.MetricsLogger; |
| 204 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 205 | import com.android.internal.util.ToBooleanFunction; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 206 | import com.android.internal.util.function.TriConsumer; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 207 | import com.android.internal.util.function.pooled.PooledConsumer; |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 208 | import com.android.internal.util.function.pooled.PooledFunction; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 209 | import com.android.internal.util.function.pooled.PooledLambda; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 210 | import com.android.internal.util.function.pooled.PooledPredicate; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 211 | import com.android.server.policy.WindowManagerPolicy; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 212 | import com.android.server.protolog.common.ProtoLog; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 213 | import com.android.server.wm.utils.DisplayRotationUtil; |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 214 | import com.android.server.wm.utils.RotationCache; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 215 | import com.android.server.wm.utils.WmDisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 216 | |
| 217 | import java.io.PrintWriter; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 218 | import java.lang.annotation.Retention; |
| 219 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 220 | import java.util.ArrayList; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 221 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 222 | import java.util.HashMap; |
| 223 | import java.util.Iterator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 224 | import java.util.LinkedList; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 225 | import java.util.List; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 226 | import java.util.Objects; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 227 | import java.util.function.Consumer; |
| 228 | import java.util.function.Predicate; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 229 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 230 | /** |
| 231 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 232 | * particular Display. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 233 | */ |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 234 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 235 | implements WindowManagerPolicy.DisplayContentInfo { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 236 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 237 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 238 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 239 | /** The default scaling mode that scales content automatically. */ |
| 240 | static final int FORCE_SCALING_MODE_AUTO = 0; |
| 241 | /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */ |
| 242 | static final int FORCE_SCALING_MODE_DISABLED = 1; |
| 243 | |
| 244 | @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = { |
| 245 | FORCE_SCALING_MODE_AUTO, |
| 246 | FORCE_SCALING_MODE_DISABLED |
| 247 | }) |
| 248 | @Retention(RetentionPolicy.SOURCE) |
| 249 | @interface ForceScalingMode {} |
| 250 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 251 | ActivityTaskManagerService mAtmService; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 252 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 253 | /** Unique identifier of this display. */ |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 254 | final int mDisplayId; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 255 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 256 | /** |
| 257 | * Most surfaces will be a child of this window. There are some special layers and windows |
| 258 | * which are always on top of others and omitted from Screen-Magnification, for example the |
| 259 | * strict mode flash or the magnification overlay itself. Those layers will be children of |
| 260 | * {@link #mOverlayContainers} where mWindowContainers contains everything else. |
| 261 | */ |
| 262 | private final WindowContainers mWindowContainers = |
| 263 | new WindowContainers("mWindowContainers", mWmService); |
| 264 | |
| 265 | // Contains some special windows which are always on top of others and omitted from |
| 266 | // Screen-Magnification, for example the WindowMagnification windows. |
| 267 | private final NonAppWindowContainers mOverlayContainers = |
| 268 | new NonAppWindowContainers("mOverlayContainers", mWmService); |
| 269 | |
| 270 | /** The containers below are the only child containers {@link #mWindowContainers} can have. */ |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 271 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 272 | // Contains all IME window containers. Note that the z-ordering of the IME windows will depend |
| 273 | // 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] | 274 | // window containers together and move them in-sync if/when needed. We use a subclass of |
| 275 | // 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] | 276 | // TODO(display-area): is "no magnification" in the comment still true? |
| 277 | private final ImeContainer mImeWindowsContainers = new ImeContainer(mWmService); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 278 | |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 279 | private final DisplayArea.Root mRootDisplayArea = new DisplayArea.Root(mWmService); |
| 280 | |
Chris Li | c5a937ce | 2020-04-29 23:43:52 -0700 | [diff] [blame] | 281 | @VisibleForTesting |
| 282 | final DisplayAreaPolicy mDisplayAreaPolicy; |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 283 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 284 | private WindowState mTmpWindow; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 285 | private WindowState mTmpWindow2; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 286 | private boolean mUpdateImeTarget; |
| 287 | private boolean mTmpInitial; |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 288 | private int mMaxUiWidth; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 289 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 290 | final AppTransition mAppTransition; |
| 291 | final AppTransitionController mAppTransitionController; |
| 292 | boolean mSkipAppTransitionAnimation = false; |
| 293 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 294 | final ArraySet<ActivityRecord> mOpeningApps = new ArraySet<>(); |
| 295 | final ArraySet<ActivityRecord> mClosingApps = new ArraySet<>(); |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 296 | final ArraySet<WindowContainer> mChangingContainers = new ArraySet<>(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 297 | final UnknownAppVisibilityController mUnknownAppVisibilityController; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 298 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 299 | private MetricsLogger mMetricsLogger; |
| 300 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 301 | /** |
| 302 | * List of clients without a transtiton animation that we notify once we are done |
| 303 | * transitioning since they won't be notified through the app window animator. |
| 304 | */ |
| 305 | final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>(); |
| 306 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 307 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 308 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 309 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 310 | // Initial display metrics. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 311 | int mInitialDisplayWidth = 0; |
| 312 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 313 | int mInitialDisplayDensity = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 314 | |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 315 | DisplayCutout mInitialDisplayCutout; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 316 | private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 317 | = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 318 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 319 | /** |
| 320 | * Overridden display size. Initialized with {@link #mInitialDisplayWidth} |
| 321 | * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size". |
| 322 | * @see WindowManagerService#setForcedDisplaySize(int, int, int) |
| 323 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 324 | int mBaseDisplayWidth = 0; |
| 325 | int mBaseDisplayHeight = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 326 | /** |
| 327 | * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity} |
| 328 | * but can be set from Settings or via shell command "adb shell wm density". |
| 329 | * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int) |
| 330 | */ |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 331 | int mBaseDisplayDensity = 0; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling". |
| 335 | * @see WindowManagerService#setForcedDisplayScalingMode(int, int) |
| 336 | */ |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 337 | boolean mDisplayScalingDisabled; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 338 | final Display mDisplay; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 339 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 340 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 341 | private final DisplayPolicy mDisplayPolicy; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 342 | private final DisplayRotation mDisplayRotation; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 343 | DisplayFrames mDisplayFrames; |
| 344 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 345 | private final RemoteCallbackList<ISystemGestureExclusionListener> |
| 346 | mSystemGestureExclusionListeners = new RemoteCallbackList<>(); |
| 347 | private final Region mSystemGestureExclusion = new Region(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 348 | private boolean mSystemGestureExclusionWasRestricted = false; |
| 349 | private final Region mSystemGestureExclusionUnrestricted = new Region(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 350 | private int mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 351 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 352 | /** |
| 353 | * For default display it contains real metrics, empty for others. |
chaviw | 619da69 | 2019-06-10 15:39:40 -0700 | [diff] [blame] | 354 | * @see WindowManagerService#createWatermark() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 355 | */ |
| 356 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 357 | |
Mark Hong | 0db3411 | 2020-01-10 10:20:45 -0800 | [diff] [blame] | 358 | /** @see #computeCompatSmallestWidth(boolean, int, int, int) */ |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 359 | private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 360 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 361 | /** |
| 362 | * Compat metrics computed based on {@link #mDisplayMetrics}. |
| 363 | * @see #updateDisplayAndOrientation(int) |
| 364 | */ |
| 365 | private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 366 | |
| 367 | /** The desired scaling factor for compatible apps. */ |
| 368 | float mCompatibleScreenScale; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 369 | |
Riddle Hsu | 7f704b5 | 2019-12-10 23:10:45 +0800 | [diff] [blame] | 370 | /** @see #getCurrentOverrideConfigurationChanges */ |
| 371 | private int mCurrentOverrideConfigurationChanges; |
| 372 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 373 | /** |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 374 | * The maximum aspect ratio (longerSide/shorterSide) that is treated as close-to-square. The |
| 375 | * orientation requests from apps would be ignored if the display is close-to-square. |
| 376 | */ |
| 377 | @VisibleForTesting |
| 378 | final float mCloseToSquareMaxAspectRatio; |
| 379 | |
| 380 | /** |
| 381 | * If this is true, we would not rotate the display for apps. The rotation would be either the |
| 382 | * sensor rotation or the user rotation, controlled by |
| 383 | * {@link WindowManagerPolicy.UserRotationMode}. |
| 384 | */ |
| 385 | private boolean mIgnoreRotationForApps; |
| 386 | |
| 387 | /** |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 388 | * Keep track of wallpaper visibility to notify changes. |
| 389 | */ |
| 390 | private boolean mLastWallpaperVisible = false; |
| 391 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 392 | private Rect mBaseDisplayRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 393 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 394 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 395 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 396 | int pendingLayoutChanges; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 397 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 398 | /** |
| 399 | * Used to gate application window layout until we have sent the complete configuration. |
| 400 | * TODO: There are still scenarios where we may be out of sync with the client. Ideally |
| 401 | * we want to replace this flag with a mechanism that will confirm the configuration |
| 402 | * applied by the client is the one expected by the system server. |
| 403 | */ |
| 404 | boolean mWaitingForConfig; |
| 405 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 406 | // TODO(multi-display): remove some of the usages. |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 407 | @VisibleForTesting |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 408 | boolean isDefaultDisplay; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 409 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 410 | /** |
| 411 | * Flag indicating whether WindowManager should override info for this display in |
| 412 | * DisplayManager. |
| 413 | */ |
| 414 | boolean mShouldOverrideDisplayConfiguration = true; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 415 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 416 | /** 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] | 417 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 418 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 419 | /** Detect user tapping outside of current focused task bounds .*/ |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 420 | @VisibleForTesting |
| 421 | final TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 422 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 423 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 424 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 425 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 426 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 427 | private final Rect mTmpRect = new Rect(); |
| 428 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 429 | private final RectF mTmpRectF = new RectF(); |
| 430 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 431 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 432 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 433 | /** Used for handing back size of display */ |
| 434 | private final Rect mTmpBounds = new Rect(); |
| 435 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 436 | private final Configuration mTmpConfiguration = new Configuration(); |
| 437 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 438 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 439 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 440 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 441 | final DockedStackDividerController mDividerControllerLocked; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 442 | final PinnedStackController mPinnedStackControllerLocked; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 443 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 444 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 445 | /** A collection of windows that provide tap exclude regions inside of them. */ |
| 446 | final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>(); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 447 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 448 | private final LinkedList<ActivityRecord> mTmpUpdateAllDrawn = new LinkedList(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 449 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 450 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 451 | new TaskForResizePointSearchResult(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 452 | private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState = |
| 453 | new ApplySurfaceChangesTransactionState(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 454 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 455 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 456 | // the display's direct children should be allowed. |
| 457 | private boolean mRemovingDisplay = false; |
| 458 | |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 459 | // {@code false} if this display is in the processing of being created. |
| 460 | private boolean mDisplayReady = false; |
| 461 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 462 | WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 463 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 464 | boolean mWallpaperMayChange = false; |
| 465 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 466 | private final SurfaceSession mSession = new SurfaceSession(); |
| 467 | |
| 468 | /** |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 469 | * Window that is currently interacting with the user. This window is responsible for receiving |
| 470 | * key events and pointer events from the user. |
| 471 | */ |
| 472 | WindowState mCurrentFocus = null; |
| 473 | |
| 474 | /** |
| 475 | * The last focused window that we've notified the client that the focus is changed. |
| 476 | */ |
| 477 | WindowState mLastFocus = null; |
| 478 | |
| 479 | /** |
| 480 | * Windows that have lost input focus and are waiting for the new focus window to be displayed |
| 481 | * before they are told about this. |
| 482 | */ |
| 483 | ArrayList<WindowState> mLosingFocus = new ArrayList<>(); |
| 484 | |
| 485 | /** |
| 486 | * The foreground app of this display. Windows below this app cannot be the focused window. If |
| 487 | * the user taps on the area outside of the task of the focused app, we will notify AM about the |
| 488 | * new task the user wants to interact with. |
| 489 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 490 | ActivityRecord mFocusedApp = null; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 491 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 492 | /** |
| 493 | * The launching activity which is using fixed rotation transformation. |
| 494 | * |
| 495 | * @see #handleTopActivityLaunchingInDifferentOrientation |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 496 | * @see #setFixedRotationLaunchingApp |
Riddle Hsu | d16620e | 2020-04-06 20:48:06 +0800 | [diff] [blame] | 497 | * @see DisplayRotation#shouldRotateSeamlessly |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 498 | */ |
| 499 | ActivityRecord mFixedRotationLaunchingApp; |
| 500 | |
Vadim Caen | dca5b93 | 2020-04-23 18:26:50 +0200 | [diff] [blame] | 501 | FixedRotationAnimationController mFixedRotationAnimationController; |
| 502 | |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 503 | final FixedRotationTransitionListener mFixedRotationTransitionListener = |
| 504 | new FixedRotationTransitionListener(); |
| 505 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 506 | /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 507 | final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>(); |
| 508 | |
| 509 | /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 510 | final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>(); |
| 511 | |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 512 | /** Windows whose client's insets states are not up-to-date. */ |
| 513 | final ArrayList<WindowState> mWinInsetsChanged = new ArrayList<>(); |
| 514 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 515 | private ScreenRotationAnimation mScreenRotationAnimation; |
| 516 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 517 | /** |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 518 | * Sequence number for the current layout pass. |
| 519 | */ |
| 520 | int mLayoutSeq = 0; |
| 521 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 522 | /** |
| 523 | * Specifies the count to determine whether to defer updating the IME target until ready. |
| 524 | */ |
| 525 | private int mDeferUpdateImeTargetCount; |
| 526 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 527 | private MagnificationSpec mMagnificationSpec; |
| 528 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 529 | private InputMonitor mInputMonitor; |
| 530 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 531 | /** Caches the value whether told display manager that we have content. */ |
| 532 | private boolean mLastHasContent; |
| 533 | |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 534 | private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil(); |
| 535 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 536 | /** |
| 537 | * The input method window for this display. |
| 538 | */ |
| 539 | WindowState mInputMethodWindow; |
| 540 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 541 | /** |
| 542 | * This just indicates the window the input method is on top of, not |
| 543 | * necessarily the window its input is going to. |
| 544 | */ |
| 545 | WindowState mInputMethodTarget; |
| 546 | |
Tiger Huang | fdec32c | 2020-04-10 02:07:30 +0800 | [diff] [blame] | 547 | /** |
| 548 | * The window which receives input from the input method. This is also a candidate of the |
| 549 | * input method control target. |
| 550 | */ |
| 551 | WindowState mInputMethodInputTarget; |
| 552 | |
| 553 | /** |
| 554 | * This controls the visibility and animation of the input method window. |
| 555 | */ |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 556 | InsetsControlTarget mInputMethodControlTarget; |
| 557 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 558 | /** If true hold off on modifying the animation layer of mInputMethodTarget */ |
| 559 | boolean mInputMethodTargetWaitingAnim; |
| 560 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 561 | private final PointerEventDispatcher mPointerEventDispatcher; |
| 562 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 563 | private final InsetsStateController mInsetsStateController; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 564 | private final InsetsPolicy mInsetsPolicy; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 565 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 566 | /** @see #getParentWindow() */ |
| 567 | private WindowState mParentWindow; |
| 568 | |
| 569 | private Point mLocationInParentWindow = new Point(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 570 | private SurfaceControl mParentSurfaceControl; |
| 571 | private InputWindowHandle mPortalWindowHandle; |
| 572 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 573 | // Last systemUiVisibility we received from status bar. |
| 574 | private int mLastStatusBarVisibility = 0; |
| 575 | // Last systemUiVisibility we dispatched to windows. |
| 576 | private int mLastDispatchedSystemUiVisibility = 0; |
| 577 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 578 | /** Corner radius that windows should have in order to match the display. */ |
| 579 | private final float mWindowCornerRadius; |
| 580 | |
Evan Rosky | 2ffddde | 2020-04-16 19:14:56 -0700 | [diff] [blame] | 581 | final SparseArray<ShellRoot> mShellRoots = new SparseArray<>(); |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 582 | RemoteInsetsControlTarget mRemoteInsetsControlTarget = null; |
| 583 | private final IBinder.DeathRecipient mRemoteInsetsDeath = |
| 584 | () -> { |
| 585 | synchronized (mWmService.mGlobalLock) { |
| 586 | mRemoteInsetsControlTarget = null; |
| 587 | } |
| 588 | }; |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 589 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 590 | private RootWindowContainer mRootWindowContainer; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 591 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 592 | /** Array of all UIDs that are present on the display. */ |
| 593 | private IntArray mDisplayAccessUIDs = new IntArray(); |
| 594 | |
| 595 | /** All tokens used to put activities on this stack to sleep (including mOffToken) */ |
| 596 | final ArrayList<ActivityTaskManagerInternal.SleepToken> mAllSleepTokens = new ArrayList<>(); |
| 597 | /** The token acquired by ActivityStackSupervisor to put stacks on the display to sleep */ |
| 598 | ActivityTaskManagerInternal.SleepToken mOffToken; |
| 599 | |
| 600 | private boolean mSleeping; |
| 601 | |
| 602 | /** We started the process of removing the display from the system. */ |
| 603 | private boolean mRemoving; |
| 604 | |
| 605 | /** |
| 606 | * The display is removed from the system and we are just waiting for all activities on it to be |
| 607 | * finished before removing this object. |
| 608 | */ |
| 609 | private boolean mRemoved; |
| 610 | |
| 611 | /** The display can only contain one task. */ |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 612 | boolean mSingleTaskInstance; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 613 | |
| 614 | /** |
| 615 | * Non-null if the last size compatibility mode activity is using non-native screen |
| 616 | * configuration. The activity is not able to put in multi-window mode, so it exists only one |
| 617 | * per display. |
| 618 | */ |
| 619 | private ActivityRecord mLastCompatModeActivity; |
| 620 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 621 | // Used in updating the display size |
| 622 | private Point mTmpDisplaySize = new Point(); |
| 623 | |
| 624 | // Used in updating override configurations |
| 625 | private final Configuration mTempConfig = new Configuration(); |
| 626 | |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 627 | // Used in performing layout |
| 628 | private boolean mTmpWindowsBehindIme; |
| 629 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 630 | private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> { |
| 631 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 632 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 633 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 634 | if (activity == null || activity.canShowWindows()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 635 | if (w.performShowLocked()) { |
| 636 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 637 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 638 | mWmService.mWindowPlacerLocked.debugLayoutRepeats( |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 639 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 644 | }; |
| 645 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 646 | private final Consumer<WindowState> mScheduleToastTimeout = w -> { |
| 647 | final int lostFocusUid = mTmpWindow.mOwnerUid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 648 | final Handler handler = mWmService.mH; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 649 | if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) { |
| 650 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) { |
| 651 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), |
| 652 | w.mAttrs.hideTimeoutMilliseconds); |
| 653 | } |
| 654 | } |
| 655 | }; |
| 656 | |
| 657 | private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 658 | final ActivityRecord focusedApp = mFocusedApp; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 659 | ProtoLog.v(WM_DEBUG_FOCUS, "Looking for focus: %s, flags=%d, canReceive=%b", |
| 660 | w, w.mAttrs.flags, w.canReceiveKeys()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 661 | |
| 662 | if (!w.canReceiveKeys()) { |
| 663 | return false; |
| 664 | } |
| 665 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 666 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 667 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 668 | if (focusedApp == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 669 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 670 | "findFocusedWindow: focusedApp=null using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 671 | mTmpWindow = w; |
| 672 | return true; |
| 673 | } |
| 674 | |
| 675 | if (!focusedApp.windowsAreFocusable()) { |
| 676 | // Current focused app windows aren't focusable... |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 677 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: focusedApp windows not" |
| 678 | + " focusable using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 679 | mTmpWindow = w; |
| 680 | return true; |
| 681 | } |
| 682 | |
| 683 | // 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] | 684 | // win.mActivityRecord (return win) or mFocusedApp (return null). |
| 685 | if (activity != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 686 | if (focusedApp.compareTo(activity) > 0) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 687 | // App stack below focused app stack. No focus for you!!! |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 688 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 689 | "findFocusedWindow: Reached focused app=%s", focusedApp); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 690 | mTmpWindow = null; |
| 691 | return true; |
| 692 | } |
| 693 | } |
| 694 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 695 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: Found new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 696 | mTmpWindow = w; |
| 697 | return true; |
| 698 | }; |
| 699 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 700 | private final Consumer<WindowState> mPerformLayout = w -> { |
| 701 | // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid |
| 702 | // wasting time and funky changes while a window is animating away. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 703 | final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 704 | || w.isGoneForLayoutLw(); |
| 705 | |
| 706 | if (DEBUG_LAYOUT && !w.mLayoutAttached) { |
| 707 | Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame |
| 708 | + " mLayoutAttached=" + w.mLayoutAttached |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 709 | + " config reported=" + w.isLastConfigReportedToClient()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 710 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 711 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 712 | + " mRelayoutCalled=" + w.mRelayoutCalled + " visible=" + w.mToken.isVisible() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 713 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 714 | + " parentHidden=" + w.isParentWindowHidden()); |
| 715 | else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 716 | + " mRelayoutCalled=" + w.mRelayoutCalled + " visible=" + w.mToken.isVisible() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 717 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 718 | + " parentHidden=" + w.isParentWindowHidden()); |
| 719 | } |
| 720 | |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 721 | // Sets mBehindIme for each window. Windows behind IME can get IME insets. |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 722 | if (w.mBehindIme != mTmpWindowsBehindIme) { |
| 723 | w.mBehindIme = mTmpWindowsBehindIme; |
| 724 | mWinInsetsChanged.add(w); |
| 725 | } |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 726 | if (w == mInputMethodWindow) { |
| 727 | mTmpWindowsBehindIme = true; |
| 728 | } |
| 729 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 730 | // If this view is GONE, then skip it -- keep the current frame, and let the caller know |
| 731 | // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows, |
| 732 | // since that means "perform layout as normal, just don't display"). |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 733 | if ((!gone || !w.mHaveFrame || w.mLayoutNeeded) && !w.mLayoutAttached) { |
| 734 | if (mTmpInitial) { |
| 735 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 736 | } |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 737 | w.mLayoutNeeded = false; |
| 738 | w.prelayout(); |
| 739 | final boolean firstLayout = !w.isLaidOut(); |
| 740 | getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames); |
| 741 | w.mLayoutSeq = mLayoutSeq; |
| 742 | |
Riddle Hsu | f64e134 | 2019-12-05 17:38:41 +0800 | [diff] [blame] | 743 | // If this is the first layout, we need to initialize the last frames and inset values, |
| 744 | // as otherwise we'd immediately cause an unnecessary resize. |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 745 | if (firstLayout) { |
Riddle Hsu | 12c0545 | 2020-01-09 00:39:52 +0800 | [diff] [blame] | 746 | // The client may compute its actual requested size according to the first layout, |
| 747 | // so we still request the window to resize if the current frame is empty. |
| 748 | if (!w.getFrameLw().isEmpty()) { |
| 749 | w.updateLastFrames(); |
| 750 | } |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 751 | w.updateLastInsetValues(); |
Riddle Hsu | f64e134 | 2019-12-05 17:38:41 +0800 | [diff] [blame] | 752 | w.updateLocationInParentDisplayIfNeeded(); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 753 | } |
| 754 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 755 | if (w.mActivityRecord != null) { |
| 756 | w.mActivityRecord.layoutLetterbox(w); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
| 760 | + " mContainingFrame=" + w.getContainingFrame() |
| 761 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 762 | } |
| 763 | }; |
| 764 | |
| 765 | private final Consumer<WindowState> mPerformLayoutAttached = w -> { |
| 766 | if (w.mLayoutAttached) { |
| 767 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame |
| 768 | + " mViewVisibility=" + w.mViewVisibility |
| 769 | + " mRelayoutCalled=" + w.mRelayoutCalled); |
| 770 | // If this view is GONE, then skip it -- keep the current frame, and let the caller |
| 771 | // know so they can ignore it if they want. (We do the normal layout for INVISIBLE |
| 772 | // windows, since that means "perform layout as normal, just don't display"). |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 773 | if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame |
| 777 | || w.mLayoutNeeded) { |
| 778 | if (mTmpInitial) { |
| 779 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 780 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 781 | } |
| 782 | w.mLayoutNeeded = false; |
| 783 | w.prelayout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 784 | getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 785 | w.mLayoutSeq = mLayoutSeq; |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 786 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 787 | + " mContainingFrame=" + w.getContainingFrame() |
| 788 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 789 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 790 | } |
| 791 | }; |
| 792 | |
| 793 | private final Predicate<WindowState> mComputeImeTargetPredicate = w -> { |
| 794 | if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w |
| 795 | + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| 796 | return w.canBeImeTarget(); |
| 797 | }; |
| 798 | |
| 799 | private final Consumer<WindowState> mApplyPostLayoutPolicy = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 800 | w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 801 | mInputMethodTarget); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 802 | |
| 803 | private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 804 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 805 | final boolean obscuredChanged = w.mObscured != |
| 806 | mTmpApplySurfaceChangesTransactionState.obscured; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 807 | final RootWindowContainer root = mWmService.mRoot; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 808 | |
| 809 | // Update effect. |
| 810 | w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 811 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 812 | if (!mTmpApplySurfaceChangesTransactionState.obscured) { |
| 813 | final boolean isDisplayed = w.isDisplayedLw(); |
| 814 | |
| 815 | if (isDisplayed && w.isObscuringDisplay()) { |
| 816 | // This window completely covers everything behind it, so we want to leave all |
| 817 | // of them as undimmed (for performance reasons). |
| 818 | root.mObscuringWindow = w; |
| 819 | mTmpApplySurfaceChangesTransactionState.obscured = true; |
| 820 | } |
| 821 | |
Arthur Hung | fbc8f41 | 2019-08-01 19:57:54 +0800 | [diff] [blame] | 822 | final boolean displayHasContent = root.handleNotObscuredLocked(w, |
| 823 | mTmpApplySurfaceChangesTransactionState.obscured, |
| 824 | mTmpApplySurfaceChangesTransactionState.syswin); |
| 825 | |
| 826 | if (!mTmpApplySurfaceChangesTransactionState.displayHasContent |
| 827 | && !getDisplayPolicy().isWindowExcludedFromContent(w)) { |
| 828 | mTmpApplySurfaceChangesTransactionState.displayHasContent |= displayHasContent; |
| 829 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 830 | |
| 831 | if (w.mHasSurface && isDisplayed) { |
| 832 | final int type = w.mAttrs.type; |
Santos Cordon | c6a2552 | 2020-03-25 18:01:13 +0000 | [diff] [blame] | 833 | if (type == TYPE_SYSTEM_DIALOG |
| 834 | || type == TYPE_SYSTEM_ERROR |
| 835 | || (type == TYPE_NOTIFICATION_SHADE |
| 836 | && mWmService.mPolicy.isKeyguardShowing())) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 837 | mTmpApplySurfaceChangesTransactionState.syswin = true; |
| 838 | } |
| 839 | if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0 |
| 840 | && w.mAttrs.preferredRefreshRate != 0) { |
| 841 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate |
| 842 | = w.mAttrs.preferredRefreshRate; |
| 843 | } |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 844 | |
| 845 | mTmpApplySurfaceChangesTransactionState.preferMinimalPostProcessing |
| 846 | |= w.mAttrs.preferMinimalPostProcessing; |
| 847 | |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 848 | final int preferredModeId = getDisplayPolicy().getRefreshRatePolicy() |
| 849 | .getPreferredModeId(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 850 | if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0 |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 851 | && preferredModeId != 0) { |
| 852 | mTmpApplySurfaceChangesTransactionState.preferredModeId = preferredModeId; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 857 | if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 858 | // This is the wallpaper target and its obscured state changed... make sure the |
| 859 | // current wallpaper's visibility has been updated accordingly. |
| 860 | mWallpaperController.updateWallpaperVisibility(); |
| 861 | } |
| 862 | |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 863 | w.handleWindowMovedIfNeeded(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 864 | |
| 865 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 866 | |
| 867 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 868 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 869 | |
| 870 | // Moved from updateWindowsAndWallpaperLocked(). |
| 871 | if (w.mHasSurface) { |
| 872 | // Take care of the window being ready to display. |
| 873 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 874 | if (isDefaultDisplay && committed) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 875 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 876 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 877 | "First draw done in potential wallpaper target " + w); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 878 | mWallpaperMayChange = true; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 879 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 880 | if (DEBUG_LAYOUT_REPEATS) { |
| 881 | surfacePlacer.debugLayoutRepeats( |
| 882 | "wallpaper and commitFinishDrawingLocked true", |
| 883 | pendingLayoutChanges); |
| 884 | } |
| 885 | } |
| 886 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 887 | } |
| 888 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 889 | final ActivityRecord activity = w.mActivityRecord; |
| 890 | if (activity != null) { |
| 891 | activity.updateLetterboxSurface(w); |
| 892 | final boolean updateAllDrawn = activity.updateDrawnWindowStates(w); |
| 893 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(activity)) { |
| 894 | mTmpUpdateAllDrawn.add(activity); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 898 | if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 899 | mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | w.updateResizingWindowIfNeeded(); |
| 903 | }; |
| 904 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 905 | /** |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 906 | * Create new {@link DisplayContent} instance, add itself to the root window container and |
| 907 | * initialize direct children. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 908 | * @param display May not be null. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 909 | * @param root {@link RootWindowContainer} |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 910 | */ |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 911 | DisplayContent(Display display, RootWindowContainer root) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 912 | super(root.mWindowManager); |
| 913 | if (mWmService.mRoot.getDisplayContent(display.getDisplayId()) != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 914 | throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 915 | + " already exists=" |
| 916 | + mWmService.mRoot.getDisplayContent(display.getDisplayId()) |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 917 | + " new=" + display); |
| 918 | } |
| 919 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 920 | mRootWindowContainer = root; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 921 | mAtmService = mWmService.mAtmService; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 922 | mDisplay = display; |
| 923 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 924 | mWallpaperController = new WallpaperController(mWmService, this); |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 925 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 926 | display.getMetrics(mDisplayMetrics); |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 927 | mSystemGestureExclusionLimit = mWmService.mConstants.mSystemGestureExclusionLimitDp |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 928 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 929 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 930 | mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo, |
| 931 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 932 | initializeDisplayBaseInfo(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 933 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 934 | mAppTransition = new AppTransition(mWmService.mContext, mWmService, this); |
| 935 | mAppTransition.registerListenerLocked(mWmService.mActivityManagerAppTransitionNotifier); |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 936 | mAppTransition.registerListenerLocked(mFixedRotationTransitionListener); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 937 | mAppTransitionController = new AppTransitionController(mWmService, this); |
| 938 | mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 939 | |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 940 | final InputChannel inputChannel = mWmService.mInputManager.monitorInput( |
| 941 | "PointerEventDispatcher" + mDisplayId, mDisplayId); |
| 942 | mPointerEventDispatcher = new PointerEventDispatcher(inputChannel); |
| 943 | |
| 944 | // Tap Listeners are supported for: |
| 945 | // 1. All physical displays (multi-display). |
| 946 | // 2. VirtualDisplays on VR, AA (and everything else). |
| 947 | mTapDetector = new TaskTapPointerEventListener(mWmService, this); |
| 948 | registerPointerEventListener(mTapDetector); |
| 949 | registerPointerEventListener(mWmService.mMousePositionTracker); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 950 | if (mWmService.mAtmService.getRecentTasks() != null) { |
| 951 | registerPointerEventListener( |
| 952 | mWmService.mAtmService.getRecentTasks().getInputListener()); |
| 953 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 954 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 955 | mDisplayPolicy = new DisplayPolicy(mWmService, this); |
| 956 | mDisplayRotation = new DisplayRotation(mWmService, this); |
| 957 | mCloseToSquareMaxAspectRatio = mWmService.mContext.getResources().getFloat( |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 958 | com.android.internal.R.dimen.config_closeToSquareDisplayMaxAspectRatio); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 959 | if (isDefaultDisplay) { |
| 960 | // The policy may be invoked right after here, so it requires the necessary default |
| 961 | // fields of this display content. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 962 | mWmService.mPolicy.setDefaultDisplay(this); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 963 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 964 | if (mWmService.mDisplayReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 965 | mDisplayPolicy.onConfigurationChanged(); |
| 966 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 967 | if (mWmService.mSystemReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 968 | mDisplayPolicy.systemReady(); |
| 969 | } |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 970 | mWindowCornerRadius = mDisplayPolicy.getWindowCornerRadius(); |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 971 | mDividerControllerLocked = new DockedStackDividerController(this); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 972 | mPinnedStackControllerLocked = new PinnedStackController(mWmService, this); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 973 | |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 974 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(mSession) |
| 975 | .setOpaque(true) |
| 976 | .setContainerLayer(); |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 977 | mSurfaceControl = b.setName("Root").setContainerLayer().build(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 978 | |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 979 | getPendingTransaction() |
| 980 | .setLayer(mSurfaceControl, 0) |
| 981 | .setLayerStack(mSurfaceControl, mDisplayId) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 982 | .show(mSurfaceControl); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 983 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 984 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 985 | // 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] | 986 | super.addChild(mWindowContainers, null); |
| 987 | super.addChild(mOverlayContainers, null); |
| 988 | |
Adrian Roos | 639ce07 | 2020-02-06 16:45:18 -0800 | [diff] [blame] | 989 | mDisplayAreaPolicy = mWmService.mDisplayAreaPolicyProvider.instantiate( |
Andrii Kulian | 44b3c56 | 2020-04-01 12:49:56 -0700 | [diff] [blame] | 990 | mWmService, this, mRootDisplayArea, mImeWindowsContainers); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 991 | mWindowContainers.addChildren(); |
| 992 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 993 | // Sets the display content for the children. |
| 994 | onDisplayChanged(this); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 995 | |
Garfield Tan | fbd233a | 2019-12-26 12:39:25 -0800 | [diff] [blame] | 996 | mInputMonitor = new InputMonitor(mWmService, this); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 997 | mInsetsStateController = new InsetsStateController(this); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 998 | mInsetsPolicy = new InsetsPolicy(mInsetsStateController, this); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 999 | |
Garfield Tan | fbd233a | 2019-12-26 12:39:25 -0800 | [diff] [blame] | 1000 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Creating display=" + display); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1001 | |
| 1002 | mWmService.mDisplayWindowSettings.applySettingsToDisplayLocked(this); |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | boolean isReady() { |
| 1006 | // 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] | 1007 | return mWmService.mDisplayReady && mDisplayReady; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | int getDisplayId() { |
| 1011 | return mDisplayId; |
| 1012 | } |
| 1013 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 1014 | float getWindowCornerRadius() { |
| 1015 | return mWindowCornerRadius; |
| 1016 | } |
| 1017 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1018 | WindowToken getWindowToken(IBinder binder) { |
| 1019 | return mTokenMap.get(binder); |
| 1020 | } |
| 1021 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1022 | ActivityRecord getActivityRecord(IBinder binder) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1023 | final WindowToken token = getWindowToken(binder); |
| 1024 | if (token == null) { |
| 1025 | return null; |
| 1026 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1027 | return token.asActivityRecord(); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 1030 | void addWindowToken(IBinder binder, WindowToken token) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1031 | final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1032 | if (dc != null) { |
| 1033 | // We currently don't support adding a window token to the display if the display |
| 1034 | // already has the binder mapped to another token. If there is a use case for supporting |
| 1035 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 1036 | // the binder map to a list of window tokens. |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 1037 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 1038 | + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1039 | } |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 1040 | if (binder == null) { |
| 1041 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 1042 | + getName() + " binder is null"); |
| 1043 | } |
| 1044 | if (token == null) { |
| 1045 | throw new IllegalArgumentException("Can't map null token to display=" |
| 1046 | + getName() + " binder=" + binder); |
| 1047 | } |
| 1048 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1049 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1050 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1051 | if (token.asActivityRecord() == null) { |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 1052 | // Set displayContent for non-app token to prevent same token will add twice after |
| 1053 | // onDisplayChanged. |
| 1054 | // TODO: Check if it's fine that super.onDisplayChanged of WindowToken |
| 1055 | // (WindowsContainer#onDisplayChanged) may skipped when token.mDisplayContent assigned. |
| 1056 | token.mDisplayContent = this; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1057 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 1058 | // the parent container managing them (e.g. Tasks). |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1059 | switch (token.windowType) { |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1060 | case TYPE_INPUT_METHOD: |
| 1061 | case TYPE_INPUT_METHOD_DIALOG: |
| 1062 | mImeWindowsContainers.addChild(token); |
| 1063 | break; |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 1064 | case TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY: |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 1065 | // TODO(display-area): Migrate to DisplayArea |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 1066 | mOverlayContainers.addChild(token); |
| 1067 | break; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1068 | default: |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 1069 | mDisplayAreaPolicy.addWindow(token); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1070 | break; |
| 1071 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1072 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1076 | final WindowToken token = mTokenMap.remove(binder); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1077 | if (token != null && token.asActivityRecord() == null) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1078 | token.setExiting(); |
| 1079 | } |
| 1080 | return token; |
| 1081 | } |
| 1082 | |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 1083 | SurfaceControl addShellRoot(@NonNull IWindow client, int windowType) { |
| 1084 | ShellRoot root = mShellRoots.get(windowType); |
| 1085 | if (root != null) { |
| 1086 | if (root.getClient() == client) { |
| 1087 | return root.getSurfaceControl(); |
| 1088 | } |
| 1089 | root.clear(); |
| 1090 | mShellRoots.remove(windowType); |
| 1091 | } |
| 1092 | root = new ShellRoot(client, this, windowType); |
| 1093 | SurfaceControl rootLeash = root.getSurfaceControl(); |
| 1094 | if (rootLeash == null) { |
| 1095 | // Root didn't finish initializing, so don't add it. |
| 1096 | root.clear(); |
| 1097 | return null; |
| 1098 | } |
| 1099 | mShellRoots.put(windowType, root); |
Jorim Jaggi | ee54070 | 2020-04-02 21:40:52 +0200 | [diff] [blame] | 1100 | SurfaceControl out = new SurfaceControl(rootLeash); |
Evan Rosky | 22b6bbd | 2019-09-26 14:29:57 -0700 | [diff] [blame] | 1101 | return out; |
| 1102 | } |
| 1103 | |
| 1104 | void removeShellRoot(int windowType) { |
| 1105 | ShellRoot root = mShellRoots.get(windowType); |
| 1106 | if (root == null) { |
| 1107 | return; |
| 1108 | } |
| 1109 | root.clear(); |
| 1110 | mShellRoots.remove(windowType); |
| 1111 | } |
| 1112 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 1113 | void setRemoteInsetsController(IDisplayWindowInsetsController controller) { |
| 1114 | if (mRemoteInsetsControlTarget != null) { |
| 1115 | mRemoteInsetsControlTarget.mRemoteInsetsController.asBinder().unlinkToDeath( |
| 1116 | mRemoteInsetsDeath, 0); |
| 1117 | mRemoteInsetsControlTarget = null; |
| 1118 | } |
| 1119 | if (controller != null) { |
| 1120 | try { |
| 1121 | controller.asBinder().linkToDeath(mRemoteInsetsDeath, 0); |
| 1122 | mRemoteInsetsControlTarget = new RemoteInsetsControlTarget(controller); |
| 1123 | } catch (RemoteException e) { |
| 1124 | return; |
| 1125 | } |
| 1126 | } |
| 1127 | } |
| 1128 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1129 | /** Changes the display the input window token is housed on to this one. */ |
| 1130 | void reParentWindowToken(WindowToken token) { |
| 1131 | final DisplayContent prevDc = token.getDisplayContent(); |
| 1132 | if (prevDc == this) { |
| 1133 | return; |
| 1134 | } |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1135 | if (prevDc != null) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1136 | if (prevDc.mTokenMap.remove(token.token) != null && token.asActivityRecord() == null) { |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1137 | // Removed the token from the map, but made sure it's not an app token before |
| 1138 | // removing from parent. |
| 1139 | token.getParent().removeChild(token); |
| 1140 | } |
lumark | 280cb21 | 2019-09-09 09:47:22 +0800 | [diff] [blame] | 1141 | if (token.hasChild(prevDc.mLastFocus)) { |
| 1142 | // If the reparent window token contains previous display's last focus window, means |
| 1143 | // it will end up to gain window focus on the target display, so it should not be |
| 1144 | // notified that it lost focus from the previous display. |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1145 | prevDc.mLastFocus = null; |
| 1146 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1147 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1148 | |
| 1149 | addWindowToken(token.token, token); |
RyanlwLin | 925e822 | 2019-08-30 15:08:48 +0800 | [diff] [blame] | 1150 | |
| 1151 | if (mWmService.mAccessibilityController != null) { |
| 1152 | final int prevDisplayId = prevDc != null ? prevDc.getDisplayId() : INVALID_DISPLAY; |
| 1153 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(prevDisplayId, |
| 1154 | getDisplayId()); |
| 1155 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1158 | void removeAppToken(IBinder binder) { |
| 1159 | final WindowToken token = removeWindowToken(binder); |
| 1160 | if (token == null) { |
| 1161 | Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder); |
| 1162 | return; |
| 1163 | } |
| 1164 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1165 | final ActivityRecord activity = token.asActivityRecord(); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1166 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1167 | if (activity == null) { |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1168 | Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token); |
| 1169 | return; |
| 1170 | } |
| 1171 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1172 | activity.onRemovedFromDisplay(); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1175 | @Override |
| 1176 | public Display getDisplay() { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 1177 | return mDisplay; |
| 1178 | } |
| 1179 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1180 | DisplayInfo getDisplayInfo() { |
| 1181 | return mDisplayInfo; |
| 1182 | } |
| 1183 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 1184 | DisplayMetrics getDisplayMetrics() { |
| 1185 | return mDisplayMetrics; |
| 1186 | } |
| 1187 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1188 | DisplayPolicy getDisplayPolicy() { |
| 1189 | return mDisplayPolicy; |
| 1190 | } |
| 1191 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1192 | @Override |
| 1193 | public DisplayRotation getDisplayRotation() { |
| 1194 | return mDisplayRotation; |
| 1195 | } |
| 1196 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 1197 | void setInsetProvider(@InternalInsetsType int type, WindowState win, |
| 1198 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider){ |
| 1199 | setInsetProvider(type, win, frameProvider, null /* imeFrameProvider */); |
| 1200 | } |
| 1201 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1202 | /** |
| 1203 | * Marks a window as providing insets for the rest of the windows in the system. |
| 1204 | * |
| 1205 | * @param type The type of inset this window provides. |
| 1206 | * @param win The window. |
| 1207 | * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of |
| 1208 | * the window should be taken. |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 1209 | * @param imeFrameProvider Function to compute the frame when dispatching insets to the IME, or |
| 1210 | * {@code null} if the normal frame should be taken. |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1211 | */ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1212 | void setInsetProvider(@InternalInsetsType int type, WindowState win, |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 1213 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider, |
| 1214 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> imeFrameProvider) { |
| 1215 | mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider, |
| 1216 | imeFrameProvider); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | InsetsStateController getInsetsStateController() { |
| 1220 | return mInsetsStateController; |
| 1221 | } |
| 1222 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 1223 | InsetsPolicy getInsetsPolicy() { |
| 1224 | return mInsetsPolicy; |
| 1225 | } |
| 1226 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1227 | @Surface.Rotation |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1228 | int getRotation() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1229 | return mDisplayRotation.getRotation(); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1232 | @ScreenOrientation |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1233 | int getLastOrientation() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1234 | return mDisplayRotation.getLastOrientation(); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 1237 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 1238 | mAppTransitionController.registerRemoteAnimations(definition); |
| 1239 | } |
| 1240 | |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1241 | void reconfigureDisplayLocked() { |
| 1242 | if (!isReady()) { |
| 1243 | return; |
| 1244 | } |
| 1245 | configureDisplayPolicy(); |
| 1246 | setLayoutNeeded(); |
| 1247 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1248 | boolean configChanged = updateOrientation(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1249 | final Configuration currentDisplayConfig = getConfiguration(); |
| 1250 | mTmpConfiguration.setTo(currentDisplayConfig); |
| 1251 | computeScreenConfiguration(mTmpConfiguration); |
| 1252 | configChanged |= currentDisplayConfig.diff(mTmpConfiguration) != 0; |
| 1253 | |
| 1254 | if (configChanged) { |
| 1255 | mWaitingForConfig = true; |
Riddle Hsu | d16620e | 2020-04-06 20:48:06 +0800 | [diff] [blame] | 1256 | mWmService.startFreezingDisplay(0 /* exitAnim */, 0 /* enterAnim */, this); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1257 | sendNewConfiguration(); |
| 1258 | } |
| 1259 | |
| 1260 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1261 | } |
| 1262 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1263 | void sendNewConfiguration() { |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1264 | if (!isReady()) { |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1265 | return; |
| 1266 | } |
Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 1267 | if (mDisplayRotation.isWaitingForRemoteRotation()) { |
| 1268 | return; |
| 1269 | } |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1270 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1271 | final boolean configUpdated = updateDisplayOverrideConfigurationLocked(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1272 | if (configUpdated) { |
| 1273 | return; |
| 1274 | } |
Riddle Hsu | b40f966 | 2020-04-25 01:58:23 +0800 | [diff] [blame] | 1275 | |
| 1276 | // The display configuration doesn't change. If there is a launching transformed app, that |
| 1277 | // means its request to change display configuration has been discarded, then it should |
| 1278 | // respect to the current configuration of display. |
| 1279 | clearFixedRotationLaunchingApp(); |
| 1280 | |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1281 | // Something changed (E.g. device rotation), but no configuration update is needed. |
| 1282 | // E.g. changing device rotation by 180 degrees. Go ahead and perform surface placement to |
| 1283 | // unfreeze the display since we froze it when the rotation was updated in |
| 1284 | // DisplayContent#updateRotationUnchecked. |
| 1285 | if (mWaitingForConfig) { |
| 1286 | mWaitingForConfig = false; |
| 1287 | mWmService.mLastFinishedFreezeSource = "config-unchanged"; |
| 1288 | setLayoutNeeded(); |
| 1289 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1293 | @Override |
| 1294 | boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, |
| 1295 | ConfigurationContainer requestingContainer) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1296 | final Configuration config = updateOrientation( |
| 1297 | getRequestedOverrideConfiguration(), freezeDisplayToken, false /* forceUpdate */); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1298 | // If display rotation class tells us that it doesn't consider app requested orientation, |
| 1299 | // this display won't rotate just because of an app changes its requested orientation. Thus |
| 1300 | // it indicates that this display chooses not to handle this request. |
| 1301 | final boolean handled = getDisplayRotation().respectAppRequestedOrientation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1302 | if (config == null) { |
| 1303 | return handled; |
| 1304 | } |
| 1305 | |
| 1306 | if (handled && requestingContainer instanceof ActivityRecord) { |
| 1307 | final ActivityRecord activityRecord = (ActivityRecord) requestingContainer; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1308 | final boolean kept = updateDisplayOverrideConfigurationLocked(config, activityRecord, |
| 1309 | false /* deferResume */, null /* result */); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1310 | activityRecord.frozenBeforeDestroy = true; |
| 1311 | if (!kept) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1312 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1313 | } |
| 1314 | } else { |
| 1315 | // We have a new configuration to push so we need to update ATMS for now. |
| 1316 | // TODO: Clean up display configuration push between ATMS and WMS after unification. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 1317 | updateDisplayOverrideConfigurationLocked(config, null /* starting */, |
| 1318 | false /* deferResume */, null); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1319 | } |
| 1320 | return handled; |
| 1321 | } |
| 1322 | |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1323 | @Override |
| 1324 | boolean handlesOrientationChangeFromDescendant() { |
| 1325 | return getDisplayRotation().respectAppRequestedOrientation(); |
| 1326 | } |
| 1327 | |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1328 | /** |
| 1329 | * Determine the new desired orientation of this display. |
| 1330 | * |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1331 | * @see #getOrientation() |
| 1332 | * @return {@code true} if the orientation is changed and the caller should call |
| 1333 | * {@link #sendNewConfiguration} if the method returns {@code true}. |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1334 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1335 | boolean updateOrientation() { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1336 | return updateOrientation(false /* forceUpdate */); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1337 | } |
| 1338 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1339 | /** |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1340 | * 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] | 1341 | * changed from the current orientation. If a non-null configuration is returned, someone must |
| 1342 | * call {@link WindowManagerService#setNewDisplayOverrideConfiguration(Configuration, |
| 1343 | * 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] | 1344 | * be done by calling {@link #sendNewConfiguration}. |
| 1345 | * |
| 1346 | * @param currentConfig The current requested override configuration (it is usually set from |
| 1347 | * the last {@link #sendNewConfiguration}) of the display. It is used to |
| 1348 | * check if the configuration container has the latest state. |
| 1349 | * @param freezeDisplayToken Freeze the app window token if the orientation is changed. |
| 1350 | * @param forceUpdate See {@link DisplayRotation#updateRotationUnchecked(boolean)} |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1351 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1352 | Configuration updateOrientation(Configuration currentConfig, IBinder freezeDisplayToken, |
| 1353 | boolean forceUpdate) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1354 | if (!mDisplayReady) { |
| 1355 | return null; |
| 1356 | } |
| 1357 | |
| 1358 | Configuration config = null; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1359 | if (updateOrientation(forceUpdate)) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1360 | // If we changed the orientation but mOrientationChangeComplete is already true, |
| 1361 | // we used seamless rotation, and we don't need to freeze the screen. |
| 1362 | if (freezeDisplayToken != null && !mWmService.mRoot.mOrientationChangeComplete) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1363 | final ActivityRecord activity = getActivityRecord(freezeDisplayToken); |
| 1364 | if (activity != null) { |
| 1365 | activity.startFreezingScreen(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | config = new Configuration(); |
| 1369 | computeScreenConfiguration(config); |
| 1370 | } else if (currentConfig != null) { |
| 1371 | // No obvious action we need to take, but if our current state mismatches the |
| 1372 | // activity manager's, update it, disregarding font scale, which should remain set |
| 1373 | // to the value of the previous configuration. |
| 1374 | // Here we're calling Configuration#unset() instead of setToDefaults() because we |
| 1375 | // need to keep override configs clear of non-empty values (e.g. fontSize). |
| 1376 | mTmpConfiguration.unset(); |
| 1377 | mTmpConfiguration.updateFrom(currentConfig); |
| 1378 | computeScreenConfiguration(mTmpConfiguration); |
| 1379 | if (currentConfig.diff(mTmpConfiguration) != 0) { |
| 1380 | mWaitingForConfig = true; |
| 1381 | setLayoutNeeded(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1382 | mDisplayRotation.prepareNormalRotationAnimation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1383 | config = new Configuration(mTmpConfiguration); |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | return config; |
| 1388 | } |
| 1389 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1390 | private boolean updateOrientation(boolean forceUpdate) { |
| 1391 | final int orientation = getOrientation(); |
| 1392 | // The last orientation source is valid only after getOrientation. |
| 1393 | final WindowContainer orientationSource = getLastOrientationSource(); |
| 1394 | final ActivityRecord r = |
| 1395 | orientationSource != null ? orientationSource.asActivityRecord() : null; |
Riddle Hsu | db94bfd | 2020-05-13 01:50:17 +0800 | [diff] [blame] | 1396 | if (r != null) { |
Garfield Tan | afa0de8 | 2020-03-03 16:07:07 -0800 | [diff] [blame] | 1397 | final Task task = r.getTask(); |
Riddle Hsu | db94bfd | 2020-05-13 01:50:17 +0800 | [diff] [blame] | 1398 | if (task != null && orientation != task.mLastReportedRequestedOrientation) { |
| 1399 | task.mLastReportedRequestedOrientation = orientation; |
| 1400 | mAtmService.getTaskChangeNotificationController() |
| 1401 | .notifyTaskRequestedOrientationChanged(task.mTaskId, orientation); |
| 1402 | } |
| 1403 | // Currently there is no use case from non-activity. |
| 1404 | if (handleTopActivityLaunchingInDifferentOrientation(r, true /* checkOpening */)) { |
| 1405 | // Display orientation should be deferred until the top fixed rotation is finished. |
| 1406 | return false; |
| 1407 | } |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1408 | } |
| 1409 | return mDisplayRotation.updateOrientation(orientation, forceUpdate); |
| 1410 | } |
| 1411 | |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 1412 | /** |
| 1413 | * Returns a valid rotation if the activity can use different orientation than the display. |
| 1414 | * Otherwise {@link #ROTATION_UNDEFINED}. |
| 1415 | */ |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1416 | @Surface.Rotation |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 1417 | int rotationForActivityInDifferentOrientation(@NonNull ActivityRecord r) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1418 | if (!mWmService.mIsFixedRotationTransformEnabled) { |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 1419 | return ROTATION_UNDEFINED; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1420 | } |
| 1421 | if (r.inMultiWindowMode() |
| 1422 | || r.getRequestedConfigurationOrientation() == getConfiguration().orientation) { |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 1423 | return ROTATION_UNDEFINED; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1424 | } |
| 1425 | final int currentRotation = getRotation(); |
| 1426 | final int rotation = mDisplayRotation.rotationForOrientation(r.getRequestedOrientation(), |
| 1427 | currentRotation); |
| 1428 | if (rotation == currentRotation) { |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 1429 | return ROTATION_UNDEFINED; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1430 | } |
| 1431 | return rotation; |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * We need to keep display rotation fixed for a while when the activity in different orientation |
| 1436 | * is launching until the launch animation is done to avoid showing the previous activity |
| 1437 | * inadvertently in a wrong orientation. |
| 1438 | * |
Riddle Hsu | db94bfd | 2020-05-13 01:50:17 +0800 | [diff] [blame] | 1439 | * @param r The launching activity which may change display orientation. |
| 1440 | * @param checkOpening Whether to check if the activity is animating by transition. Set to |
| 1441 | * {@code true} if the caller is not sure whether the activity is launching. |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1442 | * @return {@code true} if the fixed rotation is started. |
| 1443 | */ |
Riddle Hsu | db94bfd | 2020-05-13 01:50:17 +0800 | [diff] [blame] | 1444 | boolean handleTopActivityLaunchingInDifferentOrientation(@NonNull ActivityRecord r, |
| 1445 | boolean checkOpening) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1446 | if (!mWmService.mIsFixedRotationTransformEnabled) { |
| 1447 | return false; |
| 1448 | } |
| 1449 | if (r.isFinishingFixedRotationTransform()) { |
| 1450 | return false; |
| 1451 | } |
| 1452 | if (r.hasFixedRotationTransform()) { |
| 1453 | // It has been set and not yet finished. |
| 1454 | return true; |
| 1455 | } |
Riddle Hsu | db94bfd | 2020-05-13 01:50:17 +0800 | [diff] [blame] | 1456 | if (checkOpening) { |
| 1457 | if (!mAppTransition.isTransitionSet() && !mOpeningApps.contains(r)) { |
| 1458 | // Apply normal rotation animation in case of the activity set different requested |
| 1459 | // orientation without activity switch. |
| 1460 | return false; |
| 1461 | } |
| 1462 | } else if (r != topRunningActivity()) { |
| 1463 | // If the transition has not started yet, the activity must be the top. |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1464 | return false; |
| 1465 | } |
| 1466 | final int rotation = rotationForActivityInDifferentOrientation(r); |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 1467 | if (rotation == ROTATION_UNDEFINED) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1468 | return false; |
| 1469 | } |
| 1470 | if (!r.getParent().matchParentBounds()) { |
| 1471 | // Because the fixed rotated configuration applies to activity directly, if its parent |
| 1472 | // has it own policy for bounds, the activity bounds based on parent is unknown. |
| 1473 | return false; |
| 1474 | } |
| 1475 | |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 1476 | setFixedRotationLaunchingApp(r, rotation); |
| 1477 | return true; |
| 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * Sets the provided record to {@link mFixedRotationLaunchingApp} if possible to apply fixed |
| 1482 | * rotation transform to it and indicate that the display may be rotated after it is launched. |
| 1483 | */ |
| 1484 | void setFixedRotationLaunchingApp(@NonNull ActivityRecord r, @Surface.Rotation int rotation) { |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 1485 | final WindowToken prevRotatedLaunchingApp = mFixedRotationLaunchingApp; |
| 1486 | if (prevRotatedLaunchingApp != null |
| 1487 | && prevRotatedLaunchingApp.getWindowConfiguration().getRotation() == rotation |
| 1488 | // It is animating so we can expect there will have a transition callback. |
| 1489 | && prevRotatedLaunchingApp.isAnimating(TRANSITION | PARENTS)) { |
| 1490 | // It may be the case that multiple activities launch consecutively. Because their |
| 1491 | // rotation are the same, the transformed state can be shared to avoid duplicating |
| 1492 | // the heavy operations. This also benefits that the states of multiple activities |
| 1493 | // are handled together. |
| 1494 | r.linkFixedRotationTransform(prevRotatedLaunchingApp); |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 1495 | return; |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 1496 | } |
| 1497 | |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 1498 | if (!r.hasFixedRotationTransform()) { |
| 1499 | startFixedRotationTransform(r, rotation); |
| 1500 | } |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 1501 | mFixedRotationLaunchingApp = r; |
| 1502 | if (prevRotatedLaunchingApp != null) { |
| 1503 | prevRotatedLaunchingApp.finishFixedRotationTransform(); |
| 1504 | } |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1505 | } |
| 1506 | |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 1507 | /** |
| 1508 | * Continue updating the orientation change of display if it was deferred by a top activity |
| 1509 | * launched in a different orientation. |
| 1510 | */ |
| 1511 | void continueUpdateOrientationForDiffOrienLaunchingApp() { |
| 1512 | if (mFixedRotationLaunchingApp == null) { |
| 1513 | return; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1514 | } |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 1515 | // Update directly because the app which will change the orientation of display is ready. |
| 1516 | if (mDisplayRotation.updateOrientation(getOrientation(), false /* forceUpdate */)) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1517 | sendNewConfiguration(); |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 1518 | return; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1519 | } |
Riddle Hsu | 742313e | 2020-05-05 17:20:32 +0800 | [diff] [blame] | 1520 | if (mDisplayRotation.isWaitingForRemoteRotation()) { |
| 1521 | // There is pending rotation change to apply. |
| 1522 | return; |
| 1523 | } |
Riddle Hsu | b40f966 | 2020-04-25 01:58:23 +0800 | [diff] [blame] | 1524 | // The orientation of display is not changed. |
| 1525 | clearFixedRotationLaunchingApp(); |
| 1526 | } |
| 1527 | |
| 1528 | /** |
| 1529 | * Clears the {@link mFixedRotationLaunchingApp} without applying rotation to display. It is |
| 1530 | * used when the display won't rotate (e.g. the orientation from sensor has updated again before |
| 1531 | * applying rotation to display) but the launching app has been transformed. So the record need |
| 1532 | * to be cleared and restored to stop using seamless rotation and rotated configuration. |
| 1533 | */ |
| 1534 | private void clearFixedRotationLaunchingApp() { |
| 1535 | if (mFixedRotationLaunchingApp == null) { |
| 1536 | return; |
| 1537 | } |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 1538 | mFixedRotationLaunchingApp.finishFixedRotationTransform(); |
Riddle Hsu | d16620e | 2020-04-06 20:48:06 +0800 | [diff] [blame] | 1539 | mFixedRotationLaunchingApp = null; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | private void startFixedRotationTransform(WindowToken token, int rotation) { |
Vadim Caen | dca5b93 | 2020-04-23 18:26:50 +0200 | [diff] [blame] | 1543 | if (mFixedRotationAnimationController == null) { |
| 1544 | mFixedRotationAnimationController = new FixedRotationAnimationController( |
| 1545 | this); |
| 1546 | } |
| 1547 | mFixedRotationAnimationController.hide(rotation); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1548 | mTmpConfiguration.unset(); |
| 1549 | final DisplayInfo info = computeScreenConfiguration(mTmpConfiguration, rotation); |
| 1550 | final WmDisplayCutout cutout = calculateDisplayCutoutForRotation(rotation); |
| 1551 | final DisplayFrames displayFrames = new DisplayFrames(mDisplayId, info, cutout); |
| 1552 | token.applyFixedRotationTransform(info, displayFrames, mTmpConfiguration); |
| 1553 | } |
| 1554 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1555 | /** |
Vadim Caen | a0fa966 | 2020-01-27 15:00:01 +0100 | [diff] [blame] | 1556 | * If the provided {@link ActivityRecord} can be displayed in an orientation different from the |
| 1557 | * display's, it will be rotated to match its requested orientation. |
| 1558 | * |
| 1559 | * @see #rotationForActivityInDifferentOrientation(ActivityRecord). |
| 1560 | * @see WindowToken#applyFixedRotationTransform(DisplayInfo, DisplayFrames, Configuration) |
| 1561 | */ |
| 1562 | void rotateInDifferentOrientationIfNeeded(ActivityRecord activityRecord) { |
| 1563 | int rotation = rotationForActivityInDifferentOrientation(activityRecord); |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 1564 | if (rotation != ROTATION_UNDEFINED) { |
Vadim Caen | a0fa966 | 2020-01-27 15:00:01 +0100 | [diff] [blame] | 1565 | startFixedRotationTransform(activityRecord, rotation); |
| 1566 | } |
| 1567 | } |
| 1568 | |
Vadim Caen | dca5b93 | 2020-04-23 18:26:50 +0200 | [diff] [blame] | 1569 | void finishFixedRotationAnimation() { |
| 1570 | if (mFixedRotationAnimationController != null |
| 1571 | && mFixedRotationAnimationController.show()) { |
| 1572 | mFixedRotationAnimationController = null; |
| 1573 | } |
| 1574 | } |
| 1575 | |
Vadim Caen | a0fa966 | 2020-01-27 15:00:01 +0100 | [diff] [blame] | 1576 | /** |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1577 | * Update rotation of the display. |
| 1578 | * |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1579 | * @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] | 1580 | * {@link #sendNewConfiguration} TO UNFREEZE THE SCREEN. |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1581 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1582 | boolean updateRotationUnchecked() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1583 | return mDisplayRotation.updateRotationUnchecked(false /* forceUpdate */); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked} |
| 1588 | * (if it returned {@code true}) to actually finish the rotation. |
| 1589 | * |
| 1590 | * @param oldRotation the rotation we are coming from. |
| 1591 | * @param rotation the rotation to apply. |
| 1592 | */ |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 1593 | private void applyRotation(final int oldRotation, final int rotation) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1594 | mDisplayRotation.applyCurrentRotation(rotation); |
| 1595 | final boolean rotateSeamlessly = mDisplayRotation.isRotatingSeamlessly(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1596 | final Transaction transaction = getPendingTransaction(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 1597 | ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly |
| 1598 | ? null : getRotationAnimation(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1599 | // We need to update our screen size information to match the new rotation. If the rotation |
| 1600 | // has actually changed then this method will return true and, according to the comment at |
| 1601 | // the top of the method, the caller is obligated to call computeNewConfigurationLocked(). |
| 1602 | // By updating the Display info here it will be available to |
| 1603 | // #computeScreenConfiguration() later. |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1604 | updateDisplayAndOrientation(getConfiguration().uiMode, null /* outConfig */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1605 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1606 | // NOTE: We disable the rotation in the emulator because |
| 1607 | // it doesn't support hardware OpenGL emulation yet. |
Vadim Caen | ba4fd6c | 2019-08-05 16:45:46 +0200 | [diff] [blame] | 1608 | if (screenRotationAnimation != null && screenRotationAnimation.hasScreenshot()) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1609 | screenRotationAnimation.setRotation(transaction, rotation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1612 | forAllWindows(w -> { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1613 | w.seamlesslyRotateIfAllowed(transaction, oldRotation, rotation, rotateSeamlessly); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1614 | }, true /* traverseTopToBottom */); |
| 1615 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1616 | mWmService.mDisplayManagerInternal.performTraversal(transaction); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1617 | scheduleAnimation(); |
| 1618 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1619 | forAllWindows(w -> { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1620 | if (w.mHasSurface && !rotateSeamlessly) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1621 | ProtoLog.v(WM_DEBUG_ORIENTATION, "Set mOrientationChanging of %s", w); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1622 | w.setOrientationChanging(true); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1623 | mWmService.mRoot.mOrientationChangeComplete = false; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1624 | w.mLastFreezeDuration = 0; |
| 1625 | } |
| 1626 | w.mReportOrientationChanged = true; |
| 1627 | }, true /* traverseTopToBottom */); |
| 1628 | |
| 1629 | if (rotateSeamlessly) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1630 | mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT, |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1631 | this, SEAMLESS_ROTATION_TIMEOUT_DURATION); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1634 | for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1635 | final WindowManagerService.RotationWatcher rotationWatcher |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1636 | = mWmService.mRotationWatchers.get(i); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1637 | if (rotationWatcher.mDisplayId == mDisplayId) { |
| 1638 | try { |
| 1639 | rotationWatcher.mWatcher.onRotationChanged(rotation); |
| 1640 | } catch (RemoteException e) { |
| 1641 | // Ignore |
| 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | |
chaviw | afc54cf | 2020-05-05 09:54:53 -0700 | [diff] [blame] | 1646 | if (mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1647 | mWmService.mAccessibilityController.onRotationChangedLocked(this); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1648 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1651 | void configureDisplayPolicy() { |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1652 | final int width = mBaseDisplayWidth; |
| 1653 | final int height = mBaseDisplayHeight; |
| 1654 | final int shortSize; |
| 1655 | final int longSize; |
| 1656 | if (width > height) { |
| 1657 | shortSize = height; |
| 1658 | longSize = width; |
| 1659 | } else { |
| 1660 | shortSize = width; |
| 1661 | longSize = height; |
| 1662 | } |
| 1663 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 1664 | final int shortSizeDp = shortSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
| 1665 | final int longSizeDp = longSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1666 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1667 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 1668 | mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1669 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1670 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 1671 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1672 | |
| 1673 | // Not much of use to rotate the display for apps since it's close to square. |
| 1674 | mIgnoreRotationForApps = isNonDecorDisplayCloseToSquare(Surface.ROTATION_0, width, height); |
| 1675 | } |
| 1676 | |
Riddle Hsu | e47501b | 2020-02-18 12:45:41 +0800 | [diff] [blame] | 1677 | /** @return {@code true} if the orientation requested from application will be ignored. */ |
| 1678 | boolean ignoreRotationForApps() { |
| 1679 | return mIgnoreRotationForApps; |
| 1680 | } |
| 1681 | |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1682 | private boolean isNonDecorDisplayCloseToSquare(int rotation, int width, int height) { |
| 1683 | final DisplayCutout displayCutout = |
| 1684 | calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
| 1685 | final int uiMode = mWmService.mPolicy.getUiMode(); |
| 1686 | final int w = mDisplayPolicy.getNonDecorDisplayWidth( |
| 1687 | width, height, rotation, uiMode, displayCutout); |
| 1688 | final int h = mDisplayPolicy.getNonDecorDisplayHeight( |
| 1689 | width, height, rotation, uiMode, displayCutout); |
| 1690 | final float aspectRatio = Math.max(w, h) / (float) Math.min(w, h); |
| 1691 | return aspectRatio <= mCloseToSquareMaxAspectRatio; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1694 | /** |
| 1695 | * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config |
| 1696 | * changed. |
| 1697 | * Do not call if {@link WindowManagerService#mDisplayReady} == false. |
| 1698 | */ |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1699 | private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1700 | // Use the effective "visual" dimensions based on current rotation |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1701 | final int rotation = getRotation(); |
| 1702 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1703 | final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1704 | final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1705 | |
| 1706 | // Update application display metrics. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1707 | final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(rotation); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1708 | final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout(); |
| 1709 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1710 | final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1711 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1712 | final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1713 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1714 | mDisplayInfo.rotation = rotation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1715 | mDisplayInfo.logicalWidth = dw; |
| 1716 | mDisplayInfo.logicalHeight = dh; |
| 1717 | mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity; |
| 1718 | mDisplayInfo.appWidth = appWidth; |
| 1719 | mDisplayInfo.appHeight = appHeight; |
| 1720 | if (isDefaultDisplay) { |
| 1721 | mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics, |
| 1722 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
| 1723 | } |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1724 | mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1725 | mDisplayInfo.getAppMetrics(mDisplayMetrics); |
| 1726 | if (mDisplayScalingDisabled) { |
| 1727 | mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED; |
| 1728 | } else { |
| 1729 | mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED; |
| 1730 | } |
| 1731 | |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1732 | computeSizeRangesAndScreenLayout(mDisplayInfo, rotated, uiMode, dw, dh, |
| 1733 | mDisplayMetrics.density, outConfig); |
| 1734 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1735 | // We usually set the override info in DisplayManager so that we get consistent display |
| 1736 | // metrics values when displays are changing and don't send out new values until WM is aware |
| 1737 | // of them. However, we don't do this for displays that serve as containers for ActivityView |
| 1738 | // because we don't want letter-/pillar-boxing during resize. |
| 1739 | final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration |
| 1740 | ? mDisplayInfo : null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1741 | mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId, |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1742 | overrideDisplayInfo); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1743 | |
| 1744 | mBaseDisplayRect.set(0, 0, dw, dh); |
| 1745 | |
| 1746 | if (isDefaultDisplay) { |
| 1747 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics, |
| 1748 | mCompatDisplayMetrics); |
| 1749 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1750 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1751 | return mDisplayInfo; |
| 1752 | } |
| 1753 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1754 | WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) { |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1755 | return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation); |
| 1756 | } |
| 1757 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1758 | private WmDisplayCutout calculateDisplayCutoutForRotationUncached( |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1759 | DisplayCutout cutout, int rotation) { |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1760 | if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1761 | return WmDisplayCutout.NO_CUTOUT; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1762 | } |
shawnlin | 21e3f02 | 2020-01-21 16:36:13 +0800 | [diff] [blame] | 1763 | final Insets waterfallInsets = |
| 1764 | RotationUtils.rotateInsets(cutout.getWaterfallInsets(), rotation); |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1765 | if (rotation == ROTATION_0) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1766 | return WmDisplayCutout.computeSafeInsets( |
| 1767 | cutout, mInitialDisplayWidth, mInitialDisplayHeight); |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1768 | } |
Adrian Roos | bed538e | 2018-02-21 17:50:07 +0100 | [diff] [blame] | 1769 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1770 | final Rect[] newBounds = mRotationUtil.getRotatedBounds( |
shawnlin | 21e3f02 | 2020-01-21 16:36:13 +0800 | [diff] [blame] | 1771 | cutout.getBoundingRectsAll(), |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1772 | rotation, mInitialDisplayWidth, mInitialDisplayHeight); |
shawnlin | 21e3f02 | 2020-01-21 16:36:13 +0800 | [diff] [blame] | 1773 | return WmDisplayCutout.computeSafeInsets( |
| 1774 | DisplayCutout.fromBoundsAndWaterfall(newBounds, waterfallInsets), |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1775 | rotated ? mInitialDisplayHeight : mInitialDisplayWidth, |
| 1776 | rotated ? mInitialDisplayWidth : mInitialDisplayHeight); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1777 | } |
| 1778 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1779 | /** |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1780 | * Compute display info and configuration according to the given rotation without changing |
| 1781 | * current display. |
| 1782 | */ |
| 1783 | DisplayInfo computeScreenConfiguration(Configuration outConfig, int rotation) { |
| 1784 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 1785 | final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1786 | final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
| 1787 | outConfig.windowConfiguration.getBounds().set(0, 0, dw, dh); |
| 1788 | |
| 1789 | final int uiMode = getConfiguration().uiMode; |
| 1790 | final DisplayCutout displayCutout = |
| 1791 | calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
| 1792 | computeScreenAppConfiguration(outConfig, dw, dh, rotation, uiMode, displayCutout); |
| 1793 | |
| 1794 | final DisplayInfo displayInfo = new DisplayInfo(mDisplayInfo); |
| 1795 | displayInfo.rotation = rotation; |
| 1796 | displayInfo.logicalWidth = dw; |
| 1797 | displayInfo.logicalHeight = dh; |
| 1798 | final Rect appBounds = outConfig.windowConfiguration.getAppBounds(); |
| 1799 | displayInfo.appWidth = appBounds.width(); |
| 1800 | displayInfo.appHeight = appBounds.height(); |
| 1801 | displayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout; |
| 1802 | computeSizeRangesAndScreenLayout(displayInfo, rotated, uiMode, dw, dh, |
| 1803 | mDisplayMetrics.density, outConfig); |
| 1804 | return displayInfo; |
| 1805 | } |
| 1806 | |
| 1807 | /** Compute configuration related to application without changing current display. */ |
| 1808 | private void computeScreenAppConfiguration(Configuration outConfig, int dw, int dh, |
| 1809 | int rotation, int uiMode, DisplayCutout displayCutout) { |
| 1810 | final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
| 1811 | displayCutout); |
| 1812 | final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
| 1813 | displayCutout); |
| 1814 | mDisplayPolicy.getNonDecorInsetsLw(rotation, dw, dh, displayCutout, mTmpRect); |
| 1815 | final int leftInset = mTmpRect.left; |
| 1816 | final int topInset = mTmpRect.top; |
| 1817 | // AppBounds at the root level should mirror the app screen size. |
| 1818 | outConfig.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */, |
| 1819 | leftInset + appWidth /* right */, topInset + appHeight /* bottom */); |
| 1820 | outConfig.windowConfiguration.setRotation(rotation); |
| 1821 | outConfig.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
| 1822 | |
| 1823 | final float density = mDisplayMetrics.density; |
| 1824 | outConfig.screenWidthDp = (int) (mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, |
| 1825 | uiMode, displayCutout) / density); |
| 1826 | outConfig.screenHeightDp = (int) (mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, |
| 1827 | uiMode, displayCutout) / density); |
| 1828 | outConfig.compatScreenWidthDp = (int) (outConfig.screenWidthDp / mCompatibleScreenScale); |
| 1829 | outConfig.compatScreenHeightDp = (int) (outConfig.screenHeightDp / mCompatibleScreenScale); |
| 1830 | |
| 1831 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 1832 | outConfig.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, uiMode, dw, |
Mark Hong | 0db3411 | 2020-01-10 10:20:45 -0800 | [diff] [blame] | 1833 | dh); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /** |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1837 | * Compute display configuration based on display properties and policy settings. |
| 1838 | * Do not call if mDisplayReady == false. |
| 1839 | */ |
| 1840 | void computeScreenConfiguration(Configuration config) { |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1841 | final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode, config); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1842 | calculateBounds(displayInfo, mTmpBounds); |
| 1843 | config.windowConfiguration.setBounds(mTmpBounds); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1844 | config.windowConfiguration.setWindowingMode(getWindowingMode()); |
| 1845 | config.windowConfiguration.setDisplayWindowingMode(getWindowingMode()); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1846 | |
| 1847 | final int dw = displayInfo.logicalWidth; |
| 1848 | final int dh = displayInfo.logicalHeight; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1849 | computeScreenAppConfiguration(config, dw, dh, displayInfo.rotation, config.uiMode, |
| 1850 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1851 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1852 | config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) |
| 1853 | | ((displayInfo.flags & Display.FLAG_ROUND) != 0 |
| 1854 | ? Configuration.SCREENLAYOUT_ROUND_YES |
| 1855 | : Configuration.SCREENLAYOUT_ROUND_NO); |
| 1856 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1857 | config.densityDpi = displayInfo.logicalDensityDpi; |
| 1858 | |
| 1859 | config.colorMode = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1860 | ((displayInfo.isHdr() && mWmService.hasHdrSupport()) |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1861 | ? Configuration.COLOR_MODE_HDR_YES |
| 1862 | : Configuration.COLOR_MODE_HDR_NO) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1863 | | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1864 | ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES |
| 1865 | : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO); |
| 1866 | |
| 1867 | // Update the configuration based on available input devices, lid switch, |
| 1868 | // and platform configuration. |
| 1869 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1870 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 1871 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 1872 | |
| 1873 | int keyboardPresence = 0; |
| 1874 | int navigationPresence = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1875 | final InputDevice[] devices = mWmService.mInputManager.getInputDevices(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1876 | final int len = devices != null ? devices.length : 0; |
| 1877 | for (int i = 0; i < len; i++) { |
| 1878 | InputDevice device = devices[i]; |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1879 | // Ignore virtual input device. |
| 1880 | if (device.isVirtual()) { |
| 1881 | continue; |
| 1882 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1883 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1884 | // Check if input device can dispatch events to current display. |
| 1885 | // If display type is virtual, will follow the default display. |
| 1886 | if (!mWmService.mInputManager.canDispatchToDisplay(device.getId(), |
| 1887 | displayInfo.type == Display.TYPE_VIRTUAL ? DEFAULT_DISPLAY : mDisplayId)) { |
| 1888 | continue; |
| 1889 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1890 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1891 | final int sources = device.getSources(); |
| 1892 | final int presenceFlag = device.isExternal() |
| 1893 | ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1894 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1895 | if (mWmService.mIsTouchDevice) { |
| 1896 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { |
| 1897 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1898 | } |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1899 | } else { |
| 1900 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1901 | } |
| 1902 | |
| 1903 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
| 1904 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 1905 | navigationPresence |= presenceFlag; |
| 1906 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
| 1907 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 1908 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1909 | navigationPresence |= presenceFlag; |
| 1910 | } |
| 1911 | |
| 1912 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 1913 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 1914 | keyboardPresence |= presenceFlag; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1915 | } |
| 1916 | } |
| 1917 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1918 | if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1919 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1920 | navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL; |
| 1921 | } |
| 1922 | |
| 1923 | // Determine whether a hard keyboard is available and enabled. |
| 1924 | // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device? |
| 1925 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1926 | if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) { |
| 1927 | mWmService.mHardKeyboardAvailable = hardKeyboardAvailable; |
| 1928 | mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 1929 | mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1932 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1933 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1934 | // Let the policy update hidden states. |
| 1935 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 1936 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 1937 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1938 | mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Mark Hong | 0db3411 | 2020-01-10 10:20:45 -0800 | [diff] [blame] | 1941 | private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1942 | mTmpDisplayMetrics.setTo(mDisplayMetrics); |
| 1943 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 1944 | final int unrotDw, unrotDh; |
| 1945 | if (rotated) { |
| 1946 | unrotDw = dh; |
| 1947 | unrotDh = dw; |
| 1948 | } else { |
| 1949 | unrotDw = dw; |
| 1950 | unrotDh = dh; |
| 1951 | } |
Mark Hong | 0db3411 | 2020-01-10 10:20:45 -0800 | [diff] [blame] | 1952 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, |
| 1953 | unrotDh); |
| 1954 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, |
| 1955 | unrotDw); |
| 1956 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, |
| 1957 | unrotDh); |
| 1958 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, |
| 1959 | unrotDw); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1960 | return sw; |
| 1961 | } |
| 1962 | |
| 1963 | private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode, |
Mark Hong | 0db3411 | 2020-01-10 10:20:45 -0800 | [diff] [blame] | 1964 | DisplayMetrics dm, int dw, int dh) { |
| 1965 | final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( |
| 1966 | rotation).getDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1967 | dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
| 1968 | displayCutout); |
| 1969 | dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
| 1970 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1971 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
| 1972 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
| 1973 | if (curSize == 0 || size < curSize) { |
| 1974 | curSize = size; |
| 1975 | } |
| 1976 | return curSize; |
| 1977 | } |
| 1978 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1979 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 1980 | int uiMode, int dw, int dh, float density, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1981 | |
| 1982 | // We need to determine the smallest width that will occur under normal |
| 1983 | // operation. To this, start with the base screen size and compute the |
| 1984 | // width under the different possible rotations. We need to un-rotate |
| 1985 | // the current screen dimensions before doing this. |
| 1986 | int unrotDw, unrotDh; |
| 1987 | if (rotated) { |
| 1988 | unrotDw = dh; |
| 1989 | unrotDh = dw; |
| 1990 | } else { |
| 1991 | unrotDw = dw; |
| 1992 | unrotDh = dh; |
| 1993 | } |
| 1994 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 1995 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 1996 | displayInfo.largestNominalAppWidth = 0; |
| 1997 | displayInfo.largestNominalAppHeight = 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1998 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh); |
| 1999 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw); |
| 2000 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh); |
| 2001 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw); |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 2002 | |
| 2003 | if (outConfig == null) { |
| 2004 | return; |
| 2005 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 2006 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
Mark Hong | 0db3411 | 2020-01-10 10:20:45 -0800 | [diff] [blame] | 2007 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode); |
| 2008 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode); |
| 2009 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode); |
| 2010 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 2011 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
| 2012 | outConfig.screenLayout = sl; |
| 2013 | } |
| 2014 | |
| 2015 | private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh, |
Mark Hong | 0db3411 | 2020-01-10 10:20:45 -0800 | [diff] [blame] | 2016 | int uiMode) { |
| 2017 | // Get the display cutout at this rotation. |
| 2018 | final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( |
| 2019 | rotation).getDisplayCutout(); |
| 2020 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 2021 | // Get the app screen size at this rotation. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2022 | int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout); |
| 2023 | int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 2024 | |
| 2025 | // Compute the screen layout size class for this rotation. |
| 2026 | int longSize = w; |
| 2027 | int shortSize = h; |
| 2028 | if (longSize < shortSize) { |
| 2029 | int tmp = longSize; |
| 2030 | longSize = shortSize; |
| 2031 | shortSize = tmp; |
| 2032 | } |
| 2033 | longSize = (int)(longSize/density); |
| 2034 | shortSize = (int)(shortSize/density); |
| 2035 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
| 2036 | } |
| 2037 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2038 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 2039 | int uiMode, int dw, int dh) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 2040 | final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( |
| 2041 | rotation).getDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2042 | final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode, |
| 2043 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 2044 | if (width < displayInfo.smallestNominalAppWidth) { |
| 2045 | displayInfo.smallestNominalAppWidth = width; |
| 2046 | } |
| 2047 | if (width > displayInfo.largestNominalAppWidth) { |
| 2048 | displayInfo.largestNominalAppWidth = width; |
| 2049 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2050 | final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode, |
| 2051 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 2052 | if (height < displayInfo.smallestNominalAppHeight) { |
| 2053 | displayInfo.smallestNominalAppHeight = height; |
| 2054 | } |
| 2055 | if (height > displayInfo.largestNominalAppHeight) { |
| 2056 | displayInfo.largestNominalAppHeight = height; |
| 2057 | } |
| 2058 | } |
| 2059 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 2060 | /** |
| 2061 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 2062 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 2063 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 2064 | * This lowers the travel distance between invoking the menu panel and selecting |
| 2065 | * a menu option. |
| 2066 | * |
| 2067 | * This method helps control where that menu is placed. Its current implementation makes |
| 2068 | * assumptions about the menu key and its relationship to the screen based on whether |
| 2069 | * the device's natural orientation is portrait (width < height) or landscape. |
| 2070 | * |
| 2071 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 2072 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 2073 | * do not hold for the target device, this method should be changed to reflect that. |
| 2074 | * |
| 2075 | * @return A {@link Gravity} value for placing the options menu window. |
| 2076 | */ |
| 2077 | int getPreferredOptionsPanelGravity() { |
| 2078 | final int rotation = getRotation(); |
| 2079 | if (mInitialDisplayWidth < mInitialDisplayHeight) { |
| 2080 | // On devices with a natural orientation of portrait. |
| 2081 | switch (rotation) { |
| 2082 | default: |
| 2083 | case Surface.ROTATION_0: |
| 2084 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 2085 | case Surface.ROTATION_90: |
| 2086 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 2087 | case Surface.ROTATION_180: |
| 2088 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 2089 | case Surface.ROTATION_270: |
| 2090 | return Gravity.START | Gravity.BOTTOM; |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | // On devices with a natural orientation of landscape. |
| 2095 | switch (rotation) { |
| 2096 | default: |
| 2097 | case Surface.ROTATION_0: |
| 2098 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 2099 | case Surface.ROTATION_90: |
| 2100 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 2101 | case Surface.ROTATION_180: |
| 2102 | return Gravity.START | Gravity.BOTTOM; |
| 2103 | case Surface.ROTATION_270: |
| 2104 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 2105 | } |
| 2106 | } |
| 2107 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 2108 | DockedStackDividerController getDockedDividerController() { |
| 2109 | return mDividerControllerLocked; |
| 2110 | } |
| 2111 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2112 | PinnedStackController getPinnedStackController() { |
| 2113 | return mPinnedStackControllerLocked; |
| 2114 | } |
| 2115 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 2116 | /** |
| 2117 | * Returns true if the specified UID has access to this display. |
| 2118 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 2119 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 2120 | return mDisplay.hasAccess(uid); |
| 2121 | } |
| 2122 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 2123 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2124 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 2127 | /** |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 2128 | * Returns the topmost stack on the display that is compatible with the input windowing mode and |
| 2129 | * activity type. Null is no compatible stack on the display. |
| 2130 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2131 | ActivityStack getStack(int windowingMode, int activityType) { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2132 | for (int tdaNdx = getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 2133 | final ActivityStack stack = getTaskDisplayAreaAt(tdaNdx) |
| 2134 | .getStack(windowingMode, activityType); |
| 2135 | if (stack != null) { |
| 2136 | return stack; |
| 2137 | } |
| 2138 | } |
| 2139 | return null; |
| 2140 | } |
| 2141 | |
| 2142 | protected int getTaskDisplayAreaCount() { |
Andrii Kulian | 44b3c56 | 2020-04-01 12:49:56 -0700 | [diff] [blame] | 2143 | return mDisplayAreaPolicy.getTaskDisplayAreaCount(); |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | protected TaskDisplayArea getTaskDisplayAreaAt(int index) { |
Andrii Kulian | 44b3c56 | 2020-04-01 12:49:56 -0700 | [diff] [blame] | 2147 | return mDisplayAreaPolicy.getTaskDisplayAreaAt(index); |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | ActivityStack getStack(int rootTaskId) { |
| 2151 | for (int tdaNdx = getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 2152 | final ActivityStack stack = getTaskDisplayAreaAt(tdaNdx).getStack(rootTaskId); |
| 2153 | if (stack != null) { |
| 2154 | return stack; |
| 2155 | } |
| 2156 | } |
| 2157 | return null; |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 2160 | protected int getStackCount() { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2161 | int totalStackCount = 0; |
| 2162 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 2163 | totalStackCount += getTaskDisplayAreaAt(i).getStackCount(); |
| 2164 | } |
| 2165 | return totalStackCount; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 2166 | } |
| 2167 | |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 2168 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2169 | ActivityStack getTopStack() { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2170 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 2171 | final ActivityStack stack = getTaskDisplayAreaAt(i).getTopStack(); |
| 2172 | if (stack != null) { |
| 2173 | return stack; |
| 2174 | } |
| 2175 | } |
| 2176 | return null; |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Riddle Hsu | 7f704b5 | 2019-12-10 23:10:45 +0800 | [diff] [blame] | 2179 | /** |
| 2180 | * The value is only valid in the scope {@link #onRequestedOverrideConfigurationChanged} of the |
| 2181 | * changing hierarchy and the {@link #onConfigurationChanged} of its children. |
| 2182 | * |
| 2183 | * @return The current changes ({@link android.content.pm.ActivityInfo.Config}) of requested |
| 2184 | * override configuration. |
| 2185 | */ |
| 2186 | int getCurrentOverrideConfigurationChanges() { |
| 2187 | return mCurrentOverrideConfigurationChanges; |
| 2188 | } |
| 2189 | |
| 2190 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 2191 | public void onConfigurationChanged(Configuration newParentConfig) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2192 | // update resources before cascade so that docked/pinned stacks use the correct info |
| 2193 | preOnConfigurationChanged(); |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2194 | final int lastOrientation = getConfiguration().orientation; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2195 | super.onConfigurationChanged(newParentConfig); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2196 | if (mDisplayPolicy != null) { |
| 2197 | mDisplayPolicy.onConfigurationChanged(); |
| 2198 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2199 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2200 | if (lastOrientation != getConfiguration().orientation) { |
| 2201 | getMetricsLogger().write( |
| 2202 | new LogMaker(MetricsEvent.ACTION_PHONE_ORIENTATION_CHANGED) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2203 | .setSubtype(getConfiguration().orientation) |
| 2204 | .addTaggedData(MetricsEvent.FIELD_DISPLAY_ID, getDisplayId())); |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2205 | } |
| 2206 | |
Winson Chung | d1674cd | 2020-03-11 22:26:56 -0700 | [diff] [blame] | 2207 | if (mPinnedStackControllerLocked != null) { |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2208 | mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo()); |
| 2209 | } |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | /** |
| 2213 | * Updates the resources used by docked/pinned controllers. This needs to be called at the |
| 2214 | * 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] | 2215 | * for bounds calculations. |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2216 | */ |
| 2217 | void preOnConfigurationChanged() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2218 | final PinnedStackController pinnedStackController = getPinnedStackController(); |
| 2219 | |
| 2220 | if (pinnedStackController != null) { |
| 2221 | getPinnedStackController().onConfigurationChanged(); |
| 2222 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2223 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2224 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 2225 | @Override |
| 2226 | boolean fillsParent() { |
| 2227 | return true; |
| 2228 | } |
| 2229 | |
| 2230 | @Override |
| 2231 | boolean isVisible() { |
| 2232 | return true; |
| 2233 | } |
| 2234 | |
| 2235 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2236 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2237 | super.onAppTransitionDone(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2238 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 2241 | @Override |
| 2242 | public void setWindowingMode(int windowingMode) { |
| 2243 | super.setWindowingMode(windowingMode); |
| 2244 | super.setDisplayWindowingMode(windowingMode); |
| 2245 | } |
| 2246 | |
| 2247 | @Override |
| 2248 | void setDisplayWindowingMode(int windowingMode) { |
| 2249 | setWindowingMode(windowingMode); |
| 2250 | } |
| 2251 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2252 | boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2253 | return mImeWindowsContainers.forAllWindowForce(callback, traverseTopToBottom); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2254 | } |
| 2255 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2256 | /** |
| 2257 | * In the general case, the orientation is computed from the above app windows first. If none of |
| 2258 | * the above app windows specify orientation, the orientation is computed from the child window |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 2259 | * container, e.g. {@link ActivityRecord#getOrientation(int)}. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2260 | */ |
Vadim Caen | fc14c66 | 2020-01-20 16:00:31 +0100 | [diff] [blame] | 2261 | @ScreenOrientation |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 2262 | @Override |
| 2263 | int getOrientation() { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 2264 | mLastOrientationSource = null; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2265 | |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 2266 | if (mIgnoreRotationForApps) { |
| 2267 | return SCREEN_ORIENTATION_USER; |
| 2268 | } |
| 2269 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2270 | if (mWmService.mDisplayFrozen) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 2271 | if (mWmService.mPolicy.isKeyguardLocked()) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2272 | // Use the last orientation the while the display is frozen with the keyguard |
| 2273 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 2274 | // window. We don't want to check the show when locked window directly though as |
| 2275 | // things aren't stable while the display is frozen, for example the window could be |
| 2276 | // momentarily unavailable due to activity relaunch. |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2277 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 2278 | "Display id=%d is frozen while keyguard locked, return %d", |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2279 | mDisplayId, getLastOrientation()); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2280 | return getLastOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2281 | } |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 2282 | } |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 2283 | final int rootOrientation = mRootDisplayArea.getOrientation(); |
| 2284 | mLastOrientationSource = mRootDisplayArea.getLastOrientationSource(); |
| 2285 | return rootOrientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2288 | void updateDisplayInfo() { |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2289 | // Check if display metrics changed and update base values if needed. |
| 2290 | updateBaseDisplayMetricsIfNeeded(); |
| 2291 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2292 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 2293 | mDisplay.getMetrics(mDisplayMetrics); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2294 | |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 2295 | onDisplayChanged(this); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2298 | @Override |
| 2299 | void onDisplayChanged(DisplayContent dc) { |
| 2300 | super.onDisplayChanged(dc); |
| 2301 | updateSystemGestureExclusionLimit(); |
| 2302 | } |
| 2303 | |
| 2304 | void updateSystemGestureExclusionLimit() { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 2305 | mSystemGestureExclusionLimit = mWmService.mConstants.mSystemGestureExclusionLimitDp |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2306 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
| 2307 | updateSystemGestureExclusion(); |
| 2308 | } |
| 2309 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2310 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2311 | final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2312 | if (displayManagerInternal != null) { |
| 2313 | // Bootstrap the default logical display from the display manager. |
| 2314 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 2315 | if (newDisplayInfo != null) { |
| 2316 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 2317 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2318 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2319 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2320 | updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight, |
| 2321 | mDisplayInfo.logicalDensityDpi); |
| 2322 | mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 2323 | mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 2324 | mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2325 | mInitialDisplayCutout = mDisplayInfo.displayCutout; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2326 | } |
| 2327 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2328 | /** |
| 2329 | * If display metrics changed, overrides are not set and it's not just a rotation - update base |
| 2330 | * values. |
| 2331 | */ |
| 2332 | private void updateBaseDisplayMetricsIfNeeded() { |
| 2333 | // Get real display metrics without overrides from WM. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2334 | mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2335 | final int orientation = mDisplayInfo.rotation; |
| 2336 | final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
| 2337 | final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth; |
| 2338 | final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight; |
| 2339 | final int newDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2340 | final DisplayCutout newCutout = mDisplayInfo.displayCutout; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2341 | |
| 2342 | final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth |
| 2343 | || mInitialDisplayHeight != newHeight |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2344 | || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi |
| 2345 | || !Objects.equals(mInitialDisplayCutout, newCutout); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2346 | |
| 2347 | if (displayMetricsChanged) { |
| 2348 | // Check if display size or density is forced. |
| 2349 | final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth |
| 2350 | || mBaseDisplayHeight != mInitialDisplayHeight; |
| 2351 | final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity; |
| 2352 | |
| 2353 | // If there is an override set for base values - use it, otherwise use new values. |
| 2354 | updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth, |
| 2355 | isDisplaySizeForced ? mBaseDisplayHeight : newHeight, |
| 2356 | isDisplayDensityForced ? mBaseDisplayDensity : newDensity); |
| 2357 | |
| 2358 | // Real display metrics changed, so we should also update initial values. |
| 2359 | mInitialDisplayWidth = newWidth; |
| 2360 | mInitialDisplayHeight = newHeight; |
| 2361 | mInitialDisplayDensity = newDensity; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2362 | mInitialDisplayCutout = newCutout; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2363 | reconfigureDisplayLocked(); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2364 | } |
| 2365 | } |
| 2366 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2367 | /** Sets the maximum width the screen resolution can be */ |
| 2368 | void setMaxUiWidth(int width) { |
| 2369 | if (DEBUG_DISPLAY) { |
| 2370 | Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId()); |
| 2371 | } |
| 2372 | |
| 2373 | mMaxUiWidth = width; |
| 2374 | |
| 2375 | // Update existing metrics. |
| 2376 | updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity); |
| 2377 | } |
| 2378 | |
| 2379 | /** Update base (override) display metrics. */ |
| 2380 | void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) { |
| 2381 | mBaseDisplayWidth = baseWidth; |
| 2382 | mBaseDisplayHeight = baseHeight; |
| 2383 | mBaseDisplayDensity = baseDensity; |
| 2384 | |
| 2385 | if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) { |
| 2386 | mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth; |
| 2387 | mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth; |
| 2388 | mBaseDisplayWidth = mMaxUiWidth; |
| 2389 | |
| 2390 | if (DEBUG_DISPLAY) { |
| 2391 | Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x" |
| 2392 | + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity |
| 2393 | + " on display:" + getDisplayId()); |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2398 | |
| 2399 | updateBounds(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2402 | /** |
| 2403 | * Forces this display to use the specified density. |
| 2404 | * |
| 2405 | * @param density The density in DPI to use. If the value equals to initial density, the setting |
| 2406 | * will be cleared. |
| 2407 | * @param userId The target user to apply. Only meaningful when this is default display. If the |
| 2408 | * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings |
| 2409 | * so only need to configure display. |
| 2410 | */ |
| 2411 | void setForcedDensity(int density, int userId) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2412 | final boolean updateCurrent = userId == UserHandle.USER_CURRENT; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2413 | if (mWmService.mCurrentUserId == userId || updateCurrent) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2414 | mBaseDisplayDensity = density; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2415 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2416 | } |
| 2417 | if (updateCurrent) { |
| 2418 | // We are applying existing settings so no need to save it again. |
| 2419 | return; |
| 2420 | } |
| 2421 | |
| 2422 | if (density == mInitialDisplayDensity) { |
| 2423 | density = 0; |
| 2424 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2425 | mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */ |
| 2429 | void setForcedScalingMode(@ForceScalingMode int mode) { |
| 2430 | if (mode != FORCE_SCALING_MODE_DISABLED) { |
| 2431 | mode = FORCE_SCALING_MODE_AUTO; |
| 2432 | } |
| 2433 | |
| 2434 | mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO); |
| 2435 | Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto")); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2436 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2437 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2438 | mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | /** If the given width and height equal to initial size, the setting will be cleared. */ |
| 2442 | void setForcedSize(int width, int height) { |
| 2443 | final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height; |
| 2444 | if (!clear) { |
| 2445 | // Set some sort of reasonable bounds on the size of the display that we will try |
| 2446 | // to emulate. |
| 2447 | final int minSize = 200; |
| 2448 | final int maxScale = 2; |
| 2449 | width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale); |
| 2450 | height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale); |
| 2451 | } |
| 2452 | |
| 2453 | Slog.i(TAG_WM, "Using new display size: " + width + "x" + height); |
| 2454 | updateBaseDisplayMetrics(width, height, mBaseDisplayDensity); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2455 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2456 | |
| 2457 | if (clear) { |
| 2458 | width = height = 0; |
| 2459 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2460 | mWmService.mDisplayWindowSettings.setForcedSize(this, width, height); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2461 | } |
| 2462 | |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 2463 | void getStableRect(Rect out) { |
| 2464 | out.set(mDisplayFrames.mStable); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 2465 | } |
| 2466 | |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2467 | /** |
| 2468 | * Get the default display area on the display dedicated to app windows. This one should be used |
| 2469 | * only as a fallback location for activity launches when no target display area is specified, |
| 2470 | * or for cases when multi-instance is not supported yet (like Split-screen, PiP or Recents). |
| 2471 | */ |
| 2472 | TaskDisplayArea getDefaultTaskDisplayArea() { |
Andrii Kulian | 44b3c56 | 2020-04-01 12:49:56 -0700 | [diff] [blame] | 2473 | return mDisplayAreaPolicy.getTaskDisplayAreaAt(0); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2474 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2475 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2476 | @Override |
| 2477 | protected void addChild(DisplayChildWindowContainer child, |
| 2478 | Comparator<DisplayChildWindowContainer> comparator) { |
| 2479 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2480 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2481 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2482 | @Override |
| 2483 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 2484 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2485 | } |
| 2486 | |
| 2487 | @Override |
| 2488 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2489 | // Only allow removal of direct children from this display if the display is in the process |
| 2490 | // of been removed. |
| 2491 | if (mRemovingDisplay) { |
| 2492 | super.removeChild(child); |
| 2493 | return; |
| 2494 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2495 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2496 | } |
| 2497 | |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2498 | void positionDisplayAt(int position, boolean includingParents) { |
| 2499 | getParent().positionChildAt(position, this, includingParents); |
| 2500 | } |
| 2501 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2502 | @Override |
| 2503 | void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) { |
| 2504 | // Children of the display are statically ordered, so the real intention here is to perform |
| 2505 | // the operation on the display and not the static direct children. |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 2506 | positionDisplayAt(position, includingParents); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2507 | } |
| 2508 | |
Garfield Tan | 4f71c5a | 2018-10-10 10:12:02 -0700 | [diff] [blame] | 2509 | /** |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2510 | * Returns true if the input point is within an app window. |
| 2511 | */ |
| 2512 | boolean pointWithinAppWindow(int x, int y) { |
| 2513 | final int[] targetWindowType = {-1}; |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2514 | final PooledConsumer fn = PooledLambda.obtainConsumer((w, nonArg) -> { |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2515 | if (targetWindowType[0] != -1) { |
| 2516 | return; |
| 2517 | } |
| 2518 | |
| 2519 | if (w.isOnScreen() && w.isVisibleLw() && w.getFrameLw().contains(x, y)) { |
| 2520 | targetWindowType[0] = w.mAttrs.type; |
| 2521 | return; |
| 2522 | } |
| 2523 | }, PooledLambda.__(WindowState.class), mTmpRect); |
| 2524 | forAllWindows(fn, true /* traverseTopToBottom */); |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2525 | fn.recycle(); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2526 | return FIRST_APPLICATION_WINDOW <= targetWindowType[0] |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2527 | && targetWindowType[0] <= LAST_APPLICATION_WINDOW; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2531 | * 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] | 2532 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2533 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 2534 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2535 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2536 | return mTmpTaskForResizePointSearchResult.process(getDefaultTaskDisplayArea(), x, y, delta); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2539 | void updateTouchExcludeRegion() { |
| 2540 | final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2541 | if (focusedTask == null) { |
| 2542 | mTouchExcludeRegion.setEmpty(); |
| 2543 | } else { |
| 2544 | mTouchExcludeRegion.set(mBaseDisplayRect); |
| 2545 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2546 | mTmpRect.setEmpty(); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2547 | mTmpRect2.setEmpty(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2548 | |
| 2549 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2550 | DisplayContent::processTaskForTouchExcludeRegion, this, |
| 2551 | PooledLambda.__(Task.class), focusedTask, delta); |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2552 | forAllTasks(c); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2553 | c.recycle(); |
| 2554 | |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2555 | // 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] | 2556 | // outside touch area in the exclusion. TapDetector is not interested in |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2557 | // any touch inside the focused task itself. |
| 2558 | if (!mTmpRect2.isEmpty()) { |
| 2559 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 2560 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2561 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2562 | if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) { |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2563 | // If the input method is visible and the user is typing, we don't want these touch |
| 2564 | // events to be intercepted and used to change focus. This would likely cause a |
| 2565 | // disappearance of the input method. |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2566 | mInputMethodWindow.getTouchableRegion(mTmpRegion); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2567 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2568 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2569 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 2570 | final WindowState win = mTapExcludedWindows.get(i); |
arthurhung | a28da95 | 2020-04-29 17:45:53 +0800 | [diff] [blame] | 2571 | if (!win.isVisibleLw()) { |
| 2572 | continue; |
| 2573 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2574 | win.getTouchableRegion(mTmpRegion); |
| 2575 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 2576 | } |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2577 | amendWindowTapExcludeRegion(mTouchExcludeRegion); |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2578 | // TODO(multi-display): Support docked stacks on secondary displays & task containers. |
| 2579 | if (mDisplayId == DEFAULT_DISPLAY |
| 2580 | && getDefaultTaskDisplayArea().isSplitScreenModeActivated()) { |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2581 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 2582 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2583 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 2584 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2585 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2588 | private void processTaskForTouchExcludeRegion(Task task, Task focusedTask, int delta) { |
| 2589 | final ActivityRecord topVisibleActivity = task.getTopVisibleActivity(); |
| 2590 | |
| 2591 | if (topVisibleActivity == null || !topVisibleActivity.hasContentToDisplay()) { |
| 2592 | return; |
| 2593 | } |
| 2594 | |
| 2595 | // Exclusion region is the region that TapDetector doesn't care about. |
| 2596 | // Here we want to remove all non-focused tasks from the exclusion region. |
| 2597 | // We also remove the outside touch area for resizing for all freeform |
| 2598 | // tasks (including the focused). |
| 2599 | // We save the focused task region once we find it, and add it back at the end. |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2600 | // If the task is home stack and it is resizable and visible (top of its root task), we want |
| 2601 | // to exclude the docked stack from touch so we need the entire screen area and not just a |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2602 | // small portion which the home stack currently is resized to. |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2603 | if (task.isActivityTypeHome() && task.isVisible() && task.isResizeable()) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2604 | mDisplayContent.getBounds(mTmpRect); |
| 2605 | } else { |
| 2606 | task.getDimBounds(mTmpRect); |
| 2607 | } |
| 2608 | |
| 2609 | if (task == focusedTask) { |
| 2610 | // Add the focused task rect back into the exclude region once we are done |
| 2611 | // processing stacks. |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2612 | // NOTE: this *looks* like a no-op, but this usage of mTmpRect2 is expected by |
| 2613 | // updateTouchExcludeRegion. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2614 | mTmpRect2.set(mTmpRect); |
| 2615 | } |
| 2616 | |
| 2617 | final boolean isFreeformed = task.inFreeformWindowingMode(); |
| 2618 | if (task != focusedTask || isFreeformed) { |
| 2619 | if (isFreeformed) { |
| 2620 | // If the task is freeformed, enlarge the area to account for outside |
| 2621 | // touch area for resize. |
| 2622 | mTmpRect.inset(-delta, -delta); |
| 2623 | // Intersect with display content rect. If we have system decor (status bar/ |
| 2624 | // navigation bar), we want to exclude that from the tap detection. |
| 2625 | // Otherwise, if the app is partially placed under some system button (eg. |
| 2626 | // Recents, Home), pressing that button would cause a full series of |
| 2627 | // unwanted transfer focus/resume/pause, before we could go home. |
| 2628 | mTmpRect.intersect(mDisplayFrames.mContent); |
| 2629 | } |
| 2630 | mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE); |
| 2631 | } |
| 2632 | } |
| 2633 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2634 | /** |
| 2635 | * Union the region with all the tap exclude region provided by windows on this display. |
| 2636 | * |
| 2637 | * @param inOutRegion The region to be amended. |
| 2638 | */ |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2639 | private void amendWindowTapExcludeRegion(Region inOutRegion) { |
chaviw | aa0d74e | 2019-12-26 14:13:40 -0800 | [diff] [blame] | 2640 | final Region region = Region.obtain(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2641 | for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) { |
| 2642 | final WindowState win = mTapExcludeProvidingWindows.valueAt(i); |
chaviw | aa0d74e | 2019-12-26 14:13:40 -0800 | [diff] [blame] | 2643 | win.getTapExcludeRegion(region); |
| 2644 | inOutRegion.op(region, Op.UNION); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2645 | } |
chaviw | aa0d74e | 2019-12-26 14:13:40 -0800 | [diff] [blame] | 2646 | region.recycle(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2647 | } |
| 2648 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2649 | @Override |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2650 | void switchUser(int userId) { |
| 2651 | super.switchUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2652 | mWmService.mWindowsChanged = true; |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2653 | mDisplayPolicy.switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2656 | @Override |
| 2657 | void removeIfPossible() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2658 | if (isAnimating(TRANSITION | PARENTS)) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2659 | mDeferredRemoval = true; |
| 2660 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2661 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2662 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2663 | } |
| 2664 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2665 | @Override |
| 2666 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2667 | mRemovingDisplay = true; |
| 2668 | try { |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 2669 | if (mParentWindow != null) { |
| 2670 | mParentWindow.removeEmbeddedDisplayContent(this); |
| 2671 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2672 | // Clear all transitions & screen frozen states when removing display. |
| 2673 | mOpeningApps.clear(); |
| 2674 | mClosingApps.clear(); |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 2675 | mChangingContainers.clear(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2676 | mUnknownAppVisibilityController.clear(); |
| 2677 | mAppTransition.removeAppTransitionTimeoutCallbacks(); |
| 2678 | handleAnimatingStoppedAndTransition(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2679 | mWmService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2680 | super.removeImmediately(); |
| 2681 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2682 | mPointerEventDispatcher.dispose(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2683 | setRotationAnimation(null); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2684 | mWmService.mAnimator.removeDisplayLocked(mDisplayId); |
Jorim Jaggi | ae962e6 | 2018-12-27 17:23:48 +0100 | [diff] [blame] | 2685 | mInputMonitor.onDisplayRemoved(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2686 | mWmService.mDisplayNotificationController.dispatchDisplayRemoved(this); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2687 | } finally { |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 2688 | mDisplayReady = false; |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2689 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2690 | } |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 2691 | |
chaviw | b9c44aa | 2020-02-19 16:00:08 -0800 | [diff] [blame] | 2692 | // Apply the pending transaction here since we may not be able to reach the DisplayContent |
| 2693 | // on the next traversal if it's removed from RootWindowContainer child list. |
| 2694 | getPendingTransaction().apply(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2695 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2696 | } |
| 2697 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2698 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2699 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2700 | boolean checkCompleteDeferredRemoval() { |
Riddle Hsu | 793442c5 | 2019-11-05 01:04:55 +0800 | [diff] [blame] | 2701 | boolean stillDeferringRemoval = false; |
| 2702 | |
| 2703 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 2704 | final DisplayChildWindowContainer child = getChildAt(i); |
| 2705 | stillDeferringRemoval |= child.checkCompleteDeferredRemoval(); |
| 2706 | if (getChildCount() == 0) { |
| 2707 | // If this display is pending to be removed because it contains an activity with |
| 2708 | // {@link ActivityRecord#mIsExiting} is true, this display may be removed when |
| 2709 | // completing the removal of the last activity from |
| 2710 | // {@link ActivityRecord#checkCompleteDeferredRemoval}. |
| 2711 | return false; |
| 2712 | } |
| 2713 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2714 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2715 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2716 | removeImmediately(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2717 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2718 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2719 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2720 | } |
| 2721 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 2722 | /** @return 'true' if removal of this display content is deferred due to active animation. */ |
| 2723 | boolean isRemovalDeferred() { |
| 2724 | return mDeferredRemoval; |
| 2725 | } |
| 2726 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2727 | void adjustForImeIfNeeded() { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2728 | final WindowState imeWin = mInputMethodWindow; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2729 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() |
| 2730 | && imeWin.isDisplayedLw(); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2731 | final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight(); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2732 | mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | void prepareFreezingTaskBounds() { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2736 | for (int tdaNdx = getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 2737 | getTaskDisplayAreaAt(tdaNdx).prepareFreezingTaskBounds(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2738 | } |
| 2739 | } |
| 2740 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2741 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2742 | getBounds(mTmpRect, newRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2743 | rotateBounds(mTmpRect, oldRotation, newRotation, bounds); |
| 2744 | } |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2745 | |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2746 | void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2747 | // Compute a transform matrix to undo the coordinate space transformation, |
| 2748 | // and present the window at the same physical position it previously occupied. |
| 2749 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2750 | createRotationMatrix( |
| 2751 | deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2752 | |
| 2753 | mTmpRectF.set(bounds); |
| 2754 | mTmpMatrix.mapRect(mTmpRectF); |
| 2755 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 2758 | static int deltaRotation(int oldRotation, int newRotation) { |
| 2759 | int delta = newRotation - oldRotation; |
| 2760 | if (delta < 0) delta += 4; |
| 2761 | return delta; |
| 2762 | } |
| 2763 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2764 | public void setRotationAnimation(ScreenRotationAnimation screenRotationAnimation) { |
| 2765 | if (mScreenRotationAnimation != null) { |
| 2766 | mScreenRotationAnimation.kill(); |
| 2767 | } |
| 2768 | mScreenRotationAnimation = screenRotationAnimation; |
| 2769 | } |
| 2770 | |
| 2771 | public ScreenRotationAnimation getRotationAnimation() { |
| 2772 | return mScreenRotationAnimation; |
| 2773 | } |
| 2774 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2775 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2776 | Matrix outMatrix) { |
| 2777 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 2778 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 2779 | displayHeight, outMatrix); |
| 2780 | } |
| 2781 | |
| 2782 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 2783 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 2784 | switch (rotation) { |
| 2785 | case ROTATION_0: |
| 2786 | outMatrix.reset(); |
| 2787 | break; |
| 2788 | case ROTATION_270: |
| 2789 | outMatrix.setRotate(270, 0, 0); |
| 2790 | outMatrix.postTranslate(0, displayHeight); |
| 2791 | outMatrix.postTranslate(rectTop, 0); |
| 2792 | break; |
| 2793 | case ROTATION_180: |
| 2794 | outMatrix.reset(); |
| 2795 | break; |
| 2796 | case ROTATION_90: |
| 2797 | outMatrix.setRotate(90, 0, 0); |
| 2798 | outMatrix.postTranslate(displayWidth, 0); |
| 2799 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 2800 | break; |
| 2801 | } |
| 2802 | } |
| 2803 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2804 | public void dumpDebug(ProtoOutputStream proto, long fieldId, |
| 2805 | @WindowTraceLogLevel int logLevel) { |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2806 | // Critical log level logs only visible elements to mitigate performance overheard |
| 2807 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 2808 | return; |
| 2809 | } |
| 2810 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2811 | final long token = proto.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2812 | super.dumpDebug(proto, WINDOW_CONTAINER, logLevel); |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 2813 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2814 | proto.write(ID, mDisplayId); |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 2815 | mRootDisplayArea.dumpDebug(proto, ROOT_DISPLAY_AREA, logLevel); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2816 | for (int i = mOverlayContainers.getChildCount() - 1; i >= 0; --i) { |
| 2817 | final WindowToken windowToken = mOverlayContainers.getChildAt(i); |
| 2818 | windowToken.dumpDebug(proto, OVERLAY_WINDOWS, logLevel); |
| 2819 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2820 | proto.write(DPI, mBaseDisplayDensity); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2821 | mDisplayInfo.dumpDebug(proto, DISPLAY_INFO); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2822 | proto.write(ROTATION, getRotation()); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2823 | final ScreenRotationAnimation screenRotationAnimation = getRotationAnimation(); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2824 | if (screenRotationAnimation != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2825 | screenRotationAnimation.dumpDebug(proto, SCREEN_ROTATION_ANIMATION); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2826 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2827 | mDisplayFrames.dumpDebug(proto, DISPLAY_FRAMES); |
| 2828 | mAppTransition.dumpDebug(proto, APP_TRANSITION); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2829 | if (mFocusedApp != null) { |
| 2830 | mFocusedApp.writeNameToProto(proto, FOCUSED_APP); |
| 2831 | } |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2832 | for (int i = mOpeningApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2833 | mOpeningApps.valueAt(i).writeIdentifierToProto(proto, OPENING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2834 | } |
| 2835 | for (int i = mClosingApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2836 | mClosingApps.valueAt(i).writeIdentifierToProto(proto, CLOSING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2837 | } |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 2838 | |
| 2839 | proto.write(SINGLE_TASK_INSTANCE, mSingleTaskInstance); |
| 2840 | final ActivityStack focusedStack = getFocusedStack(); |
| 2841 | if (focusedStack != null) { |
| 2842 | proto.write(FOCUSED_ROOT_TASK_ID, focusedStack.getRootTaskId()); |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2843 | final ActivityRecord focusedActivity = focusedStack.getDisplayArea() |
| 2844 | .getFocusedActivity(); |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 2845 | if (focusedActivity != null) { |
| 2846 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 2847 | } |
| 2848 | } else { |
| 2849 | proto.write(FOCUSED_ROOT_TASK_ID, INVALID_TASK_ID); |
| 2850 | } |
Vishnu Nair | dddc9f5 | 2020-03-09 09:37:27 -0700 | [diff] [blame] | 2851 | proto.write(DISPLAY_READY, isReady()); |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 2852 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2853 | proto.end(token); |
| 2854 | } |
| 2855 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2856 | @Override |
Vishnu Nair | dddc9f5 | 2020-03-09 09:37:27 -0700 | [diff] [blame] | 2857 | long getProtoFieldId() { |
| 2858 | return DISPLAY_CONTENT; |
| 2859 | } |
| 2860 | |
| 2861 | @Override |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2862 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 2863 | super.dump(pw, prefix, dumpAll); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2864 | pw.print(prefix); |
| 2865 | pw.println("Display: mDisplayId=" + mDisplayId + " stacks=" + getStackCount() + ( |
| 2866 | mSingleTaskInstance ? " mSingleTaskInstance" : "")); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2867 | final String subPrefix = " " + prefix; |
| 2868 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 2869 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 2870 | pw.print("dpi"); |
| 2871 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 2872 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 2873 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 2874 | pw.print(" base="); |
| 2875 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 2876 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 2877 | } |
| 2878 | if (mDisplayScalingDisabled) { |
| 2879 | pw.println(" noscale"); |
| 2880 | } |
| 2881 | pw.print(" cur="); |
| 2882 | pw.print(mDisplayInfo.logicalWidth); |
| 2883 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 2884 | pw.print(" app="); |
| 2885 | pw.print(mDisplayInfo.appWidth); |
| 2886 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 2887 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 2888 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 2889 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 2890 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
| 2891 | pw.print(subPrefix + "deferred=" + mDeferredRemoval |
| 2892 | + " mLayoutNeeded=" + mLayoutNeeded); |
| 2893 | pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2894 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2895 | pw.println(); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2896 | pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq); |
| 2897 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2898 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 2899 | if (mLastFocus != mCurrentFocus) { |
| 2900 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 2901 | } |
| 2902 | if (mLosingFocus.size() > 0) { |
| 2903 | pw.println(); |
| 2904 | pw.println(" Windows losing focus:"); |
| 2905 | for (int i = mLosingFocus.size() - 1; i >= 0; i--) { |
| 2906 | final WindowState w = mLosingFocus.get(i); |
| 2907 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 2908 | pw.print(w); |
| 2909 | if (dumpAll) { |
| 2910 | pw.println(":"); |
| 2911 | w.dump(pw, " ", true); |
| 2912 | } else { |
| 2913 | pw.println(); |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2918 | if (mLastStatusBarVisibility != 0) { |
| 2919 | pw.print(" mLastStatusBarVisibility=0x"); |
| 2920 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 2921 | } |
Riddle Hsu | b40f966 | 2020-04-25 01:58:23 +0800 | [diff] [blame] | 2922 | if (mFixedRotationLaunchingApp != null) { |
| 2923 | pw.println(" mFixedRotationLaunchingApp=" + mFixedRotationLaunchingApp); |
| 2924 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2925 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2926 | pw.println(); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 2927 | mWallpaperController.dump(pw, " "); |
| 2928 | |
| 2929 | pw.println(); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 2930 | pw.print("mSystemGestureExclusion="); |
| 2931 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() > 0) { |
| 2932 | pw.println(mSystemGestureExclusion); |
| 2933 | } else { |
| 2934 | pw.println("<no lstnrs>"); |
| 2935 | } |
| 2936 | |
| 2937 | pw.println(); |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 2938 | pw.println(prefix + "Task display areas in top down Z order:"); |
| 2939 | for (int tdaNdx = getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 2940 | getTaskDisplayAreaAt(tdaNdx).dump(pw, prefix + " ", dumpAll); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2941 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2942 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2943 | pw.println(); |
| 2944 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2945 | pw.println(); |
| 2946 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2947 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2948 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2949 | pw.print(" Exiting #"); pw.print(i); |
| 2950 | pw.print(' '); pw.print(token); |
| 2951 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2952 | token.dump(pw, " ", dumpAll); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2953 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2954 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 2955 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2956 | final ScreenRotationAnimation rotationAnimation = getRotationAnimation(); |
| 2957 | if (rotationAnimation != null) { |
| 2958 | pw.print(subPrefix); |
| 2959 | pw.println(" mScreenRotationAnimation:"); |
| 2960 | rotationAnimation.printTo(" ", pw); |
| 2961 | } else if (dumpAll) { |
| 2962 | pw.print(subPrefix); |
| 2963 | pw.println(" no ScreenRotationAnimation "); |
| 2964 | } |
| 2965 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 2966 | pw.println(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2967 | |
| 2968 | // Dump stack references |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2969 | final ActivityStack homeStack = getDefaultTaskDisplayArea().getRootHomeTask(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2970 | if (homeStack != null) { |
| 2971 | pw.println(prefix + "homeStack=" + homeStack.getName()); |
| 2972 | } |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2973 | final ActivityStack pinnedStack = getDefaultTaskDisplayArea().getRootPinnedTask(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2974 | if (pinnedStack != null) { |
| 2975 | pw.println(prefix + "pinnedStack=" + pinnedStack.getName()); |
| 2976 | } |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2977 | final ActivityStack splitScreenPrimaryStack = getDefaultTaskDisplayArea() |
| 2978 | .getRootSplitScreenPrimaryTask(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2979 | if (splitScreenPrimaryStack != null) { |
| 2980 | pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName()); |
| 2981 | } |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 2982 | // TODO: Support recents on non-default task containers |
| 2983 | final ActivityStack recentsStack = getDefaultTaskDisplayArea().getStack( |
| 2984 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2985 | if (recentsStack != null) { |
| 2986 | pw.println(prefix + "recentsStack=" + recentsStack.getName()); |
| 2987 | } |
Galia Peycheva | 70b5571 | 2020-03-16 18:31:34 +0100 | [diff] [blame] | 2988 | final ActivityStack dreamStack = |
| 2989 | getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_DREAM); |
| 2990 | if (dreamStack != null) { |
| 2991 | pw.println(prefix + "dreamStack=" + dreamStack.getName()); |
| 2992 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2993 | |
| 2994 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2995 | mPinnedStackControllerLocked.dump(prefix, pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2996 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2997 | pw.println(); |
| 2998 | mDisplayFrames.dump(prefix, pw); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2999 | pw.println(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 3000 | mDisplayPolicy.dump(prefix, pw); |
| 3001 | pw.println(); |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 3002 | mDisplayRotation.dump(prefix, pw); |
| 3003 | pw.println(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3004 | mInputMonitor.dump(pw, " "); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3005 | pw.println(); |
| 3006 | mInsetsStateController.dump(prefix, pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3007 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3008 | |
| 3009 | @Override |
| 3010 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3011 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3015 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3016 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 3017 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3018 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3019 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3020 | final int x = (int) xf; |
| 3021 | final int y = (int) yf; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3022 | final WindowState touchedWin = getWindow(w -> { |
| 3023 | final int flags = w.mAttrs.flags; |
| 3024 | if (!w.isVisibleLw()) { |
| 3025 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3026 | } |
| 3027 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3028 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3029 | } |
| 3030 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3031 | w.getVisibleBounds(mTmpRect); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3032 | if (!mTmpRect.contains(x, y)) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3033 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3034 | } |
| 3035 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3036 | w.getTouchableRegion(mTmpRegion); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3037 | |
| 3038 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3039 | return mTmpRegion.contains(x, y) || touchFlags == 0; |
| 3040 | }); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 3041 | |
| 3042 | return touchedWin; |
| 3043 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 3044 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3045 | boolean canAddToastWindowForUid(int uid) { |
| 3046 | // We allow one toast window per UID being shown at a time. |
Svet Ganov | daca8ee | 2017-01-21 17:40:40 -0800 | [diff] [blame] | 3047 | // Also if the app is focused adding more than one toast at |
| 3048 | // a time for better backwards compatibility. |
| 3049 | final WindowState focusedWindowForUid = getWindow(w -> |
| 3050 | w.mOwnerUid == uid && w.isFocused()); |
| 3051 | if (focusedWindowForUid != null) { |
| 3052 | return true; |
| 3053 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3054 | final WindowState win = getWindow(w -> |
| 3055 | w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3056 | && !w.mWindowRemovalAllowed); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3057 | return win == null; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3060 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3061 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 3062 | return; |
| 3063 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3064 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3065 | // Used to communicate the old focus to the callback method. |
| 3066 | mTmpWindow = oldFocus; |
| 3067 | |
| 3068 | forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3069 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3070 | |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3071 | /** |
| 3072 | * Looking for the focused window on this display if the top focused display hasn't been |
| 3073 | * found yet (topFocusedDisplayId is INVALID_DISPLAY) or per-display focused was allowed. |
| 3074 | * |
| 3075 | * @param topFocusedDisplayId Id of the top focused display. |
| 3076 | * @return The focused window or null if there isn't any or no need to seek. |
| 3077 | */ |
| 3078 | WindowState findFocusedWindowIfNeeded(int topFocusedDisplayId) { |
| 3079 | return (mWmService.mPerDisplayFocusEnabled || topFocusedDisplayId == INVALID_DISPLAY) |
| 3080 | ? findFocusedWindow() : null; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3081 | } |
| 3082 | |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3083 | WindowState findFocusedWindow() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3084 | mTmpWindow = null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3085 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3086 | forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3087 | |
| 3088 | if (mTmpWindow == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3089 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: No focusable windows."); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3090 | return null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3091 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3092 | return mTmpWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3095 | /** |
| 3096 | * Update the focused window and make some adjustments if the focus has changed. |
| 3097 | * |
| 3098 | * @param mode Indicates the situation we are in. Possible modes are: |
| 3099 | * {@link WindowManagerService#UPDATE_FOCUS_NORMAL}, |
| 3100 | * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES}, |
| 3101 | * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES}, |
| 3102 | * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS} |
| 3103 | * @param updateInputWindows Whether to sync the window information to the input module. |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3104 | * @param topFocusedDisplayId Display id of current top focused display. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3105 | * @return {@code true} if the focused window has changed. |
| 3106 | */ |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3107 | boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, |
| 3108 | int topFocusedDisplayId) { |
| 3109 | WindowState newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3110 | if (mCurrentFocus == newFocus) { |
| 3111 | return false; |
| 3112 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3113 | boolean imWindowChanged = false; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3114 | final WindowState imWindow = mInputMethodWindow; |
| 3115 | if (imWindow != null) { |
| 3116 | final WindowState prevTarget = mInputMethodTarget; |
| 3117 | final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/); |
| 3118 | imWindowChanged = prevTarget != newTarget; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3119 | |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3120 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS |
| 3121 | && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 3122 | assignWindowLayers(false /* setLayoutNeeded */); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | if (imWindowChanged) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3127 | mWmService.mWindowsChanged = true; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3128 | setLayoutNeeded(); |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3129 | newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3130 | } |
| 3131 | if (mCurrentFocus != newFocus) { |
| 3132 | mWmService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3133 | } |
| 3134 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3135 | 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] | 3136 | mCurrentFocus, newFocus, getDisplayId(), Debug.getCallers(4)); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3137 | final WindowState oldFocus = mCurrentFocus; |
| 3138 | mCurrentFocus = newFocus; |
| 3139 | mLosingFocus.remove(newFocus); |
| 3140 | |
| 3141 | if (newFocus != null) { |
| 3142 | mWinAddedSinceNullFocus.clear(); |
| 3143 | mWinRemovedSinceNullFocus.clear(); |
| 3144 | |
| 3145 | if (newFocus.canReceiveKeys()) { |
| 3146 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 3147 | // This is to protect against bugs if someone pauses dispatching but |
| 3148 | // forgets to resume. |
| 3149 | newFocus.mToken.paused = false; |
| 3150 | } |
| 3151 | } |
| 3152 | |
Vishnu Nair | f6ef1c7 | 2020-01-23 16:28:33 -0800 | [diff] [blame] | 3153 | onWindowFocusChanged(oldFocus, newFocus); |
| 3154 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3155 | int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3156 | |
| 3157 | if (imWindowChanged && oldFocus != mInputMethodWindow) { |
| 3158 | // Focus of the input method window changed. Perform layout if needed. |
| 3159 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3160 | performLayout(true /*initial*/, updateInputWindows); |
| 3161 | focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT; |
| 3162 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 3163 | // Client will do the layout, but we need to assign layers |
| 3164 | // for handleNewWindowLocked() below. |
| 3165 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3170 | // The change in focus caused us to need to do a layout. Okay. |
| 3171 | setLayoutNeeded(); |
| 3172 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3173 | performLayout(true /*initial*/, updateInputWindows); |
| 3174 | } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) { |
Riddle Hsu | 72d6dc3 | 2020-03-25 22:58:00 +0800 | [diff] [blame] | 3175 | mWmService.mRoot.performSurfacePlacement(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 3180 | // If we defer assigning layers, then the caller is responsible for doing this part. |
| 3181 | getInputMonitor().setInputFocusLw(newFocus, updateInputWindows); |
| 3182 | } |
| 3183 | |
| 3184 | adjustForImeIfNeeded(); |
| 3185 | |
| 3186 | // We may need to schedule some toast windows to be removed. The toasts for an app that |
| 3187 | // does not have input focus are removed within a timeout to prevent apps to redress |
| 3188 | // other apps' UI. |
| 3189 | scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus); |
| 3190 | |
| 3191 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3192 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 3193 | } |
| 3194 | return true; |
| 3195 | } |
| 3196 | |
Vishnu Nair | f6ef1c7 | 2020-01-23 16:28:33 -0800 | [diff] [blame] | 3197 | private static void onWindowFocusChanged(WindowState oldFocus, WindowState newFocus) { |
| 3198 | final Task focusedTask = newFocus != null ? newFocus.getTask() : null; |
| 3199 | final Task unfocusedTask = oldFocus != null ? oldFocus.getTask() : null; |
| 3200 | if (focusedTask == unfocusedTask) { |
| 3201 | return; |
| 3202 | } |
| 3203 | if (focusedTask != null) { |
| 3204 | focusedTask.onWindowFocusChanged(true /* hasFocus */); |
| 3205 | } |
| 3206 | if (unfocusedTask != null) { |
| 3207 | unfocusedTask.onWindowFocusChanged(false /* hasFocus */); |
| 3208 | } |
| 3209 | } |
| 3210 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3211 | /** |
| 3212 | * Set the new focused app to this display. |
| 3213 | * |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3214 | * @param newFocus the new focused {@link ActivityRecord}. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3215 | * @return true if the focused app is changed. |
| 3216 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3217 | boolean setFocusedApp(ActivityRecord newFocus) { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3218 | if (newFocus != null) { |
| 3219 | final DisplayContent appDisplay = newFocus.getDisplayContent(); |
| 3220 | if (appDisplay != this) { |
| 3221 | throw new IllegalStateException(newFocus + " is not on " + getName() |
| 3222 | + " but " + ((appDisplay != null) ? appDisplay.getName() : "none")); |
| 3223 | } |
| 3224 | } |
| 3225 | if (mFocusedApp == newFocus) { |
| 3226 | return false; |
| 3227 | } |
| 3228 | mFocusedApp = newFocus; |
| 3229 | getInputMonitor().setFocusedAppLw(newFocus); |
| 3230 | updateTouchExcludeRegion(); |
| 3231 | return true; |
| 3232 | } |
| 3233 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3234 | /** Updates the layer assignment of windows on this display. */ |
| 3235 | void assignWindowLayers(boolean setLayoutNeeded) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3236 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers"); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3237 | assignChildLayers(getPendingTransaction()); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3238 | if (setLayoutNeeded) { |
| 3239 | setLayoutNeeded(); |
| 3240 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3241 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3242 | // We accumlate the layer changes in-to "getPendingTransaction()" but we defer |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3243 | // the application of this transaction until the animation pass triggers |
| 3244 | // prepareSurfaces. This allows us to synchronize Z-ordering changes with |
| 3245 | // the hiding and showing of surfaces. |
| 3246 | scheduleAnimation(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3247 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3250 | // TODO: This should probably be called any time a visual change is made to the hierarchy like |
| 3251 | // moving containers or resizing them. Need to investigate the best way to have it automatically |
| 3252 | // 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] | 3253 | void layoutAndAssignWindowLayersIfNeeded() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3254 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3255 | setLayoutNeeded(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3256 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3257 | if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3258 | false /*updateInputWindows*/)) { |
| 3259 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3260 | } |
| 3261 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3262 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3263 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3264 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3267 | /** Returns true if a leaked surface was destroyed */ |
| 3268 | boolean destroyLeakedSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3269 | // Used to indicate that a surface was leaked. |
| 3270 | mTmpWindow = null; |
| 3271 | forAllWindows(w -> { |
| 3272 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3273 | if (wsa.mSurfaceController == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3274 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3275 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3276 | if (!mWmService.mSessions.contains(wsa.mSession)) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3277 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3278 | + w + " surface=" + wsa.mSurfaceController |
| 3279 | + " token=" + w.mToken |
| 3280 | + " pid=" + w.mSession.mPid |
| 3281 | + " uid=" + w.mSession.mUid); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3282 | wsa.destroySurface(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3283 | mWmService.mForceRemoves.add(w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3284 | mTmpWindow = w; |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3285 | } else if (w.mActivityRecord != null && !w.mActivityRecord.isClientVisible()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3286 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3287 | + w + " surface=" + wsa.mSurfaceController |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3288 | + " token=" + w.mActivityRecord); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3289 | ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE LEAK DESTROY: %s", w); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3290 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3291 | mTmpWindow = w; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3292 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3293 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3294 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3295 | return mTmpWindow != null; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3298 | boolean hasAlertWindowSurfaces() { |
| 3299 | for (int i = mWmService.mSessions.size() - 1; i >= 0; --i) { |
| 3300 | if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces(this)) { |
| 3301 | return true; |
| 3302 | } |
| 3303 | } |
| 3304 | return false; |
| 3305 | } |
| 3306 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3307 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3308 | * Set input method window for the display. |
| 3309 | * @param win Set when window added or Null when destroyed. |
| 3310 | */ |
| 3311 | void setInputMethodWindowLocked(WindowState win) { |
| 3312 | mInputMethodWindow = win; |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3313 | // Update display configuration for IME process. |
| 3314 | if (mInputMethodWindow != null) { |
| 3315 | final int imePid = mInputMethodWindow.mSession.mPid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3316 | mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid, |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3317 | mInputMethodWindow.getDisplayId()); |
| 3318 | } |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3319 | mInsetsStateController.getSourceProvider(ITYPE_IME).setWindow(win, |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 3320 | null /* frameProvider */, null /* imeFrameProvider */); |
Tiger Huang | aa3b19d | 2020-02-14 21:26:00 +0800 | [diff] [blame] | 3321 | computeImeTarget(true /* updateImeTarget */); |
Tiger Huang | fdec32c | 2020-04-10 02:07:30 +0800 | [diff] [blame] | 3322 | updateImeControlTarget(); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | /** |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3326 | * Determine and return the window that should be the IME target. |
| 3327 | * @param updateImeTarget If true the system IME target will be updated to match what we found. |
| 3328 | * @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] | 3329 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3330 | WindowState computeImeTarget(boolean updateImeTarget) { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3331 | if (mInputMethodWindow == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3332 | // There isn't an IME so there shouldn't be a target...That was easy! |
| 3333 | if (updateImeTarget) { |
| 3334 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3335 | + mInputMethodTarget + " to null since mInputMethodWindow is null"); |
| 3336 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3337 | } |
| 3338 | return null; |
| 3339 | } |
| 3340 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3341 | final WindowState curTarget = mInputMethodTarget; |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 3342 | if (!canUpdateImeTarget()) { |
| 3343 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target"); |
| 3344 | return curTarget; |
| 3345 | } |
| 3346 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3347 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 3348 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 3349 | // 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] | 3350 | mUpdateImeTarget = updateImeTarget; |
| 3351 | WindowState target = getWindow(mComputeImeTargetPredicate); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3352 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3353 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3354 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 3355 | // to be on top of it, but it is not -really- where input will go. So look down below |
| 3356 | // for a real window to target... |
| 3357 | if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3358 | final ActivityRecord activity = target.mActivityRecord; |
| 3359 | if (activity != null) { |
| 3360 | final WindowState betterTarget = activity.getImeTargetBelowWindow(target); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3361 | if (betterTarget != null) { |
| 3362 | target = betterTarget; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3363 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3364 | } |
| 3365 | } |
| 3366 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3367 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM, |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3368 | "Proposed new IME target: " + target + " for display: " + getDisplayId()); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3369 | |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3370 | // 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] | 3371 | // not removed, keep on the last target to avoid IME flicker. |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3372 | if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw() |
Tarandeep Singh | 2d0aca4 | 2019-03-28 14:08:58 -0700 | [diff] [blame] | 3373 | && curTarget.isClosing()) { |
| 3374 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Not changing target till current window is" |
| 3375 | + " closing and not removed"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3376 | return curTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3377 | } |
| 3378 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3379 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target |
| 3380 | + " updateImeTarget=" + updateImeTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3381 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3382 | if (target == null) { |
| 3383 | if (updateImeTarget) { |
| 3384 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 3385 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" |
| 3386 | + Debug.getCallers(4) : "")); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3387 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | return null; |
| 3391 | } |
| 3392 | |
| 3393 | if (updateImeTarget) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3394 | ActivityRecord activity = curTarget == null ? null : curTarget.mActivityRecord; |
| 3395 | if (activity != null) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3396 | |
| 3397 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 3398 | // to look at all windows below the current target that are in this app, finding the |
| 3399 | // highest visible one in layering. |
| 3400 | WindowState highestTarget = null; |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 3401 | if (activity.isAnimating(PARENTS | TRANSITION)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3402 | highestTarget = activity.getHighestAnimLayerWindow(curTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | if (highestTarget != null) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3406 | if (DEBUG_INPUT_METHOD) { |
| 3407 | Slog.v(TAG_WM, mAppTransition + " " + highestTarget + " animating=" |
| 3408 | + highestTarget.isAnimating(TRANSITION | PARENTS)); |
| 3409 | } |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3410 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3411 | if (mAppTransition.isTransitionSet()) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3412 | // If we are currently setting up for an animation, hold everything until we |
| 3413 | // can find out what will happen. |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3414 | setInputMethodTarget(highestTarget, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3415 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3416 | } |
| 3417 | } |
| 3418 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3419 | |
| 3420 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 3421 | + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3422 | setInputMethodTarget(target, false); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3425 | return target; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3426 | } |
| 3427 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3428 | /** |
| 3429 | * Calling {@link #computeImeTarget(boolean)} to update the input method target window in |
| 3430 | * the candidate app window token if needed. |
| 3431 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3432 | void computeImeTargetIfNeeded(ActivityRecord candidate) { |
| 3433 | if (mInputMethodTarget != null && mInputMethodTarget.mActivityRecord == candidate) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3434 | computeImeTarget(true /* updateImeTarget */); |
| 3435 | } |
| 3436 | } |
| 3437 | |
Jorim Jaggi | cc57cb7 | 2020-04-09 14:54:13 +0200 | [diff] [blame] | 3438 | private boolean isImeControlledByApp() { |
| 3439 | return mInputMethodTarget != null && !WindowConfiguration.isSplitScreenWindowingMode( |
| 3440 | mInputMethodTarget.getWindowingMode()); |
| 3441 | } |
| 3442 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 3443 | boolean isImeAttachedToApp() { |
Jorim Jaggi | cc57cb7 | 2020-04-09 14:54:13 +0200 | [diff] [blame] | 3444 | return isImeControlledByApp() |
| 3445 | && mInputMethodTarget.mActivityRecord != null |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 3446 | && mInputMethodTarget.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 3447 | // An activity with override bounds should be letterboxed inside its parent bounds, |
| 3448 | // so it doesn't fill the screen. |
Jorim Jaggi | cc57cb7 | 2020-04-09 14:54:13 +0200 | [diff] [blame] | 3449 | && mInputMethodTarget.mActivityRecord.matchParentBounds(); |
Tarandeep Singh | 1e5b1a8 | 2020-01-24 16:03:05 -0800 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | /** |
| 3453 | * Finds the window which can host IME if IME target cannot host it. |
| 3454 | * e.g. IME target cannot host IME when it's display has a parent display OR when display |
| 3455 | * doesn't support IME/system decorations. |
| 3456 | * |
| 3457 | * @param target current IME target. |
| 3458 | * @return {@link WindowState} that can host IME. |
Tarandeep Singh | 1e5b1a8 | 2020-01-24 16:03:05 -0800 | [diff] [blame] | 3459 | */ |
| 3460 | WindowState getImeHostOrFallback(WindowState target) { |
| 3461 | if (target != null && target.getDisplayContent().canShowIme()) { |
| 3462 | return target; |
| 3463 | } |
Jorim Jaggi | 001b341 | 2020-02-17 17:52:06 +0100 | [diff] [blame] | 3464 | return getImeFallback(); |
| 3465 | } |
| 3466 | |
| 3467 | WindowState getImeFallback() { |
Tarandeep Singh | 1e5b1a8 | 2020-01-24 16:03:05 -0800 | [diff] [blame] | 3468 | |
| 3469 | // host is in non-default display that doesn't support system decor, default to |
| 3470 | // default display's StatusBar to control IME. |
| 3471 | // TODO: (b/148234093)find a better host OR control IME animation/visibility directly |
| 3472 | // because it won't work when statusbar isn't available. |
| 3473 | return mWmService.getDefaultDisplayContentLocked().getDisplayPolicy().getStatusBar(); |
| 3474 | } |
| 3475 | |
| 3476 | boolean canShowIme() { |
| 3477 | if (isUntrustedVirtualDisplay()) { |
| 3478 | return false; |
| 3479 | } |
| 3480 | return mWmService.mDisplayWindowSettings.shouldShowImeLocked(this) |
| 3481 | || mWmService.mForceDesktopModeOnExternalDisplays; |
| 3482 | } |
| 3483 | |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3484 | private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3485 | if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3486 | return; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3487 | } |
| 3488 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3489 | mInputMethodTarget = target; |
| 3490 | mInputMethodTargetWaitingAnim = targetWaitingAnim; |
Jorim Jaggi | 62ea2cf | 2020-04-16 00:22:28 +0200 | [diff] [blame] | 3491 | assignWindowLayers(true /* setLayoutNeeded */); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3492 | updateImeParent(); |
Tiger Huang | fdec32c | 2020-04-10 02:07:30 +0800 | [diff] [blame] | 3493 | updateImeControlTarget(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3494 | } |
| 3495 | |
Tarandeep Singh | a659018 | 2020-01-24 16:05:18 -0800 | [diff] [blame] | 3496 | /** |
Tiger Huang | fdec32c | 2020-04-10 02:07:30 +0800 | [diff] [blame] | 3497 | * The IME input target is the window which receives input from IME. It is also a candidate |
| 3498 | * which controls the visibility and animation of the input method window. |
Tarandeep Singh | a659018 | 2020-01-24 16:05:18 -0800 | [diff] [blame] | 3499 | */ |
Tiger Huang | fdec32c | 2020-04-10 02:07:30 +0800 | [diff] [blame] | 3500 | void setInputMethodInputTarget(WindowState target) { |
| 3501 | if (mInputMethodInputTarget != target) { |
| 3502 | mInputMethodInputTarget = target; |
| 3503 | updateImeControlTarget(); |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | private void updateImeControlTarget() { |
Jorim Jaggi | cc57cb7 | 2020-04-09 14:54:13 +0200 | [diff] [blame] | 3508 | mInputMethodControlTarget = computeImeControlTarget(); |
Tarandeep Singh | a659018 | 2020-01-24 16:05:18 -0800 | [diff] [blame] | 3509 | mInsetsStateController.onImeControlTargetChanged(mInputMethodControlTarget); |
| 3510 | } |
| 3511 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3512 | private void updateImeParent() { |
Adrian Roos | 329cbd0 | 2020-04-14 15:42:41 +0200 | [diff] [blame] | 3513 | final SurfaceControl newParent = computeImeParent(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3514 | if (newParent != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3515 | getPendingTransaction().reparent(mImeWindowsContainers.mSurfaceControl, newParent); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3516 | scheduleAnimation(); |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | /** |
Jorim Jaggi | cc57cb7 | 2020-04-09 14:54:13 +0200 | [diff] [blame] | 3521 | * Computes the window where we hand IME control to. |
| 3522 | */ |
| 3523 | @VisibleForTesting |
| 3524 | InsetsControlTarget computeImeControlTarget() { |
| 3525 | if (!isImeControlledByApp() && mRemoteInsetsControlTarget != null) { |
| 3526 | return mRemoteInsetsControlTarget; |
| 3527 | } else { |
| 3528 | // Otherwise, we just use the ime target as received from IME. |
| 3529 | return mInputMethodInputTarget; |
| 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | /** |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3534 | * Computes the window the IME should be attached to. |
| 3535 | */ |
| 3536 | @VisibleForTesting |
| 3537 | SurfaceControl computeImeParent() { |
Adrian Roos | 329cbd0 | 2020-04-14 15:42:41 +0200 | [diff] [blame] | 3538 | // Force attaching IME to the display when magnifying, or it would be magnified with |
| 3539 | // target app together. |
| 3540 | final boolean allowAttachToApp = (mMagnificationSpec == null); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3541 | |
| 3542 | // Attach it to app if the target is part of an app and such app is covering the entire |
| 3543 | // screen. If it's not covering the entire screen the IME might extend beyond the apps |
| 3544 | // bounds. |
Adrian Roos | 329cbd0 | 2020-04-14 15:42:41 +0200 | [diff] [blame] | 3545 | if (allowAttachToApp && isImeAttachedToApp()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3546 | return mInputMethodTarget.mActivityRecord.getSurfaceControl(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
Adrian Roos | 329cbd0 | 2020-04-14 15:42:41 +0200 | [diff] [blame] | 3549 | // Otherwise, we just attach it to where the display area policy put it. |
| 3550 | return mImeWindowsContainers.getParent().getSurfaceControl(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3553 | void setLayoutNeeded() { |
| 3554 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3555 | mLayoutNeeded = true; |
| 3556 | } |
| 3557 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3558 | private void clearLayoutNeeded() { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3559 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3560 | mLayoutNeeded = false; |
| 3561 | } |
| 3562 | |
| 3563 | boolean isLayoutNeeded() { |
| 3564 | return mLayoutNeeded; |
| 3565 | } |
| 3566 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3567 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 3568 | if (mTokenMap.isEmpty()) { |
| 3569 | return; |
| 3570 | } |
| 3571 | pw.println(" Display #" + mDisplayId); |
| 3572 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 3573 | while (it.hasNext()) { |
| 3574 | final WindowToken token = it.next(); |
| 3575 | pw.print(" "); |
| 3576 | pw.print(token); |
| 3577 | if (dumpAll) { |
| 3578 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3579 | token.dump(pw, " ", dumpAll); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3580 | } else { |
| 3581 | pw.println(); |
| 3582 | } |
| 3583 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3584 | |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 3585 | if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty() || !mChangingContainers.isEmpty()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3586 | pw.println(); |
| 3587 | if (mOpeningApps.size() > 0) { |
| 3588 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 3589 | } |
| 3590 | if (mClosingApps.size() > 0) { |
| 3591 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 3592 | } |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 3593 | if (mChangingContainers.size() > 0) { |
| 3594 | pw.print(" mChangingApps="); pw.println(mChangingContainers); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3595 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | mUnknownAppVisibilityController.dump(pw, " "); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3601 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3602 | final int[] index = new int[1]; |
| 3603 | forAllWindows(w -> { |
| 3604 | final WindowStateAnimator wAnim = w.mWinAnimator; |
| 3605 | pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim); |
| 3606 | index[0] = index[0] + 1; |
| 3607 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3610 | /** |
| 3611 | * Starts the Keyguard exit animation on all windows that don't belong to an app token. |
| 3612 | */ |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3613 | void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade, |
| 3614 | boolean subtle) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3615 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3616 | forAllWindows(w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3617 | if (w.mActivityRecord == null && policy.canBeHiddenByKeyguardLw(w) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 3618 | && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) { |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3619 | w.startAnimation(policy.createHiddenByKeyguardExit( |
| 3620 | onWallpaper, goingToShade, subtle)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3621 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3622 | }, true /* traverseTopToBottom */); |
Evan Rosky | 0ad8d2c | 2020-03-16 12:09:58 -0700 | [diff] [blame] | 3623 | for (int i = mShellRoots.size() - 1; i >= 0; --i) { |
| 3624 | mShellRoots.valueAt(i).startAnimation(policy.createHiddenByKeyguardExit( |
| 3625 | onWallpaper, goingToShade, subtle)); |
| 3626 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3627 | } |
| 3628 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3629 | /** @return {@code true} if there is window to wait before enabling the screen. */ |
| 3630 | boolean shouldWaitForSystemDecorWindowsOnBoot() { |
| 3631 | if (!isDefaultDisplay && !supportsSystemDecorations()) { |
| 3632 | // Nothing to wait because the secondary display doesn't support system decorations, |
| 3633 | // there is no wallpaper, keyguard (status bar) or application (home) window to show |
| 3634 | // during booting. |
| 3635 | return false; |
| 3636 | } |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3637 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3638 | final SparseBooleanArray drawnWindowTypes = new SparseBooleanArray(); |
| 3639 | // Presuppose keyguard is drawn because if its window isn't attached, we don't know if it |
| 3640 | // 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] | 3641 | drawnWindowTypes.put(TYPE_NOTIFICATION_SHADE, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3642 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3643 | final WindowState visibleNotDrawnWindow = getWindow(w -> { |
Lais Andrade | 57283fb | 2020-04-21 18:58:15 +0000 | [diff] [blame] | 3644 | boolean isVisible = w.mViewVisibility == View.VISIBLE && !w.mObscured; |
| 3645 | boolean hasDrawn = w.isDrawnLw() && w.hasDrawnLw(); |
| 3646 | if (isVisible && !hasDrawn) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3647 | return true; |
| 3648 | } |
Lais Andrade | 57283fb | 2020-04-21 18:58:15 +0000 | [diff] [blame] | 3649 | if (hasDrawn) { |
| 3650 | switch (w.mAttrs.type) { |
| 3651 | case TYPE_BOOT_PROGRESS: |
| 3652 | case TYPE_BASE_APPLICATION: |
| 3653 | case TYPE_WALLPAPER: |
| 3654 | drawnWindowTypes.put(w.mAttrs.type, true); |
| 3655 | break; |
| 3656 | case TYPE_NOTIFICATION_SHADE: |
| 3657 | drawnWindowTypes.put(TYPE_NOTIFICATION_SHADE, |
| 3658 | mWmService.mPolicy.isKeyguardDrawnLw()); |
| 3659 | break; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3660 | } |
| 3661 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3662 | return false; |
| 3663 | }); |
| 3664 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3665 | if (visibleNotDrawnWindow != null) { |
| 3666 | // Wait for the visible window to be drawn. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3667 | return true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3670 | // if the wallpaper service is disabled on the device, we're never going to have |
| 3671 | // wallpaper, don't bother waiting for it |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3672 | boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean( |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3673 | com.android.internal.R.bool.config_enableWallpaperService) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3674 | && mWmService.mContext.getResources().getBoolean( |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3675 | com.android.internal.R.bool.config_checkWallpaperAtBoot) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3676 | && !mWmService.mOnlyCore; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3677 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3678 | final boolean haveBootMsg = drawnWindowTypes.get(TYPE_BOOT_PROGRESS); |
| 3679 | final boolean haveApp = drawnWindowTypes.get(TYPE_BASE_APPLICATION); |
| 3680 | final boolean haveWallpaper = drawnWindowTypes.get(TYPE_WALLPAPER); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 3681 | final boolean haveKeyguard = drawnWindowTypes.get(TYPE_NOTIFICATION_SHADE); |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3682 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3683 | ProtoLog.i(WM_DEBUG_SCREEN_ON, |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3684 | "******** booted=%b msg=%b haveBoot=%b haveApp=%b haveWall=%b " |
| 3685 | + "wallEnabled=%b haveKeyguard=%b", |
| 3686 | mWmService.mSystemBooted, mWmService.mShowingBootMessages, haveBootMsg, |
| 3687 | haveApp, haveWallpaper, wallpaperEnabled, haveKeyguard); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3688 | |
| 3689 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 3690 | // message is actually displayed. |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3691 | if (!mWmService.mSystemBooted && !haveBootMsg) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3692 | return true; |
| 3693 | } |
| 3694 | |
| 3695 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 3696 | // we have the application and wallpaper. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3697 | if (mWmService.mSystemBooted |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3698 | && ((!haveApp && !haveKeyguard) || (wallpaperEnabled && !haveWallpaper))) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3699 | return true; |
| 3700 | } |
| 3701 | |
| 3702 | return false; |
| 3703 | } |
| 3704 | |
Jorim Jaggi | 8f52087 | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3705 | void updateWindowsForAnimator() { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3706 | forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3709 | boolean isInputMethodClientFocus(int uid, int pid) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3710 | final WindowState imFocus = computeImeTarget(false /* updateImeTarget */); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3711 | if (imFocus == null) { |
| 3712 | return false; |
| 3713 | } |
| 3714 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3715 | if (DEBUG_INPUT_METHOD) { |
| 3716 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3717 | Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId); |
| 3718 | Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3719 | } |
| 3720 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3721 | if (DEBUG_INPUT_METHOD) { |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3722 | Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid |
| 3723 | + "/" + imFocus.mSession.mPid); |
| 3724 | Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3725 | } |
| 3726 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3727 | return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | boolean hasSecureWindowOnScreen() { |
Winson Chung | 0026f65 | 2020-05-08 11:35:11 -0700 | [diff] [blame] | 3731 | final WindowState win = getWindow(w -> w.isOnScreen() && mWmService.isSecureLocked(w)); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3732 | return win != null; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3733 | } |
| 3734 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3735 | void hideTransientBars() { |
| 3736 | // TODO(b/118118435): Remove this after migration |
| 3737 | final int transientFlags = View.STATUS_BAR_TRANSIENT | View.NAVIGATION_BAR_TRANSIENT; |
| 3738 | statusBarVisibilityChanged(mLastStatusBarVisibility & ~transientFlags); |
| 3739 | |
| 3740 | getInsetsPolicy().hideTransient(); |
| 3741 | } |
| 3742 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3743 | void statusBarVisibilityChanged(int visibility) { |
| 3744 | mLastStatusBarVisibility = visibility; |
| 3745 | visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility); |
| 3746 | updateStatusBarVisibilityLocked(visibility); |
| 3747 | } |
| 3748 | |
| 3749 | private boolean updateStatusBarVisibilityLocked(int visibility) { |
| 3750 | if (mLastDispatchedSystemUiVisibility == visibility) { |
| 3751 | return false; |
| 3752 | } |
| 3753 | final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility) |
| 3754 | // We are only interested in differences of one of the |
| 3755 | // clearable flags... |
| 3756 | & View.SYSTEM_UI_CLEARABLE_FLAGS |
| 3757 | // ...if it has actually been cleared. |
| 3758 | & ~visibility; |
| 3759 | |
| 3760 | mLastDispatchedSystemUiVisibility = visibility; |
| 3761 | if (isDefaultDisplay) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3762 | mWmService.mInputManager.setSystemUiVisibility(visibility); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3763 | } |
| 3764 | updateSystemUiVisibility(visibility, globalDiff); |
| 3765 | return true; |
| 3766 | } |
| 3767 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3768 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3769 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3770 | try { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3771 | final int curValue = w.mSystemUiVisibility; |
| 3772 | final int diff = (curValue ^ visibility) & globalDiff; |
| 3773 | final int newValue = (curValue & ~diff) | (visibility & diff); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3774 | if (newValue != curValue) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3775 | w.mSeq++; |
| 3776 | w.mSystemUiVisibility = newValue; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3777 | } |
Tiger Huang | 41ae5e8 | 2020-01-17 18:17:20 +0800 | [diff] [blame] | 3778 | if ((newValue != curValue || w.mAttrs.hasSystemUiListeners) |
| 3779 | && ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3780 | w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3781 | visibility, newValue, diff); |
| 3782 | } |
| 3783 | } catch (RemoteException e) { |
| 3784 | // so sorry |
| 3785 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3786 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3789 | void reevaluateStatusBarVisibility() { |
| 3790 | int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 3791 | if (updateStatusBarVisibilityLocked(visibility)) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3792 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3793 | } |
| 3794 | } |
| 3795 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3796 | void onWindowFreezeTimeout() { |
| 3797 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3798 | mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3799 | |
| 3800 | forAllWindows(w -> { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3801 | if (!w.getOrientationChanging()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3802 | return; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3803 | } |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 3804 | w.orientationChangeTimedOut(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3805 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3806 | - mWmService.mDisplayFreezeTime); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3807 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3808 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3809 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3812 | // TODO: Super crazy long method that should be broken down... |
Riddle Hsu | 72d6dc3 | 2020-03-25 22:58:00 +0800 | [diff] [blame] | 3813 | void applySurfaceChangesTransaction() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3814 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3815 | |
| 3816 | mTmpUpdateAllDrawn.clear(); |
| 3817 | |
| 3818 | int repeats = 0; |
| 3819 | do { |
| 3820 | repeats++; |
| 3821 | if (repeats > 6) { |
| 3822 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 3823 | clearLayoutNeeded(); |
| 3824 | break; |
| 3825 | } |
| 3826 | |
| 3827 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner", |
| 3828 | pendingLayoutChanges); |
| 3829 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 3830 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 3831 | mWallpaperController.adjustWallpaperWindows(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 3834 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3835 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3836 | if (updateOrientation()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3837 | setLayoutNeeded(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 3838 | sendNewConfiguration(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3839 | } |
| 3840 | } |
| 3841 | |
| 3842 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3843 | setLayoutNeeded(); |
| 3844 | } |
| 3845 | |
| 3846 | // FIRST LOOP: Perform a layout, if needed. |
| 3847 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 3848 | performLayout(repeats == 1, false /* updateInputWindows */); |
| 3849 | } else { |
| 3850 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 3851 | } |
| 3852 | |
| 3853 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating. |
| 3854 | pendingLayoutChanges = 0; |
| 3855 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3856 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyPostLayoutPolicy"); |
| 3857 | try { |
| 3858 | mDisplayPolicy.beginPostLayoutPolicyLw(); |
| 3859 | forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */); |
| 3860 | pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw(); |
| 3861 | } finally { |
| 3862 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3863 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3864 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 3865 | "after finishPostLayoutPolicyLw", pendingLayoutChanges); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 3866 | mInsetsStateController.onPostLayout(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3867 | } while (pendingLayoutChanges != 0); |
| 3868 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3869 | mTmpApplySurfaceChangesTransactionState.reset(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3870 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3871 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyWindowSurfaceChanges"); |
| 3872 | try { |
| 3873 | forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */); |
| 3874 | } finally { |
| 3875 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3876 | } |
Jorim Jaggi | 6b0f846 | 2018-01-05 17:23:47 +0100 | [diff] [blame] | 3877 | prepareSurfaces(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3878 | |
Tiger Huang | aa3b19d | 2020-02-14 21:26:00 +0800 | [diff] [blame] | 3879 | // This should be called after the insets have been dispatched to clients and we have |
| 3880 | // committed finish drawing windows. |
| 3881 | mInsetsStateController.getImeSourceProvider().checkShowImePostLayout(); |
| 3882 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3883 | mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3884 | mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId, |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3885 | mLastHasContent, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3886 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate, |
| 3887 | mTmpApplySurfaceChangesTransactionState.preferredModeId, |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 3888 | mTmpApplySurfaceChangesTransactionState.preferMinimalPostProcessing, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3889 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 3890 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3891 | final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible(); |
| 3892 | if (wallpaperVisible != mLastWallpaperVisible) { |
| 3893 | mLastWallpaperVisible = wallpaperVisible; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3894 | mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3897 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3898 | final ActivityRecord activity = mTmpUpdateAllDrawn.removeLast(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3899 | // See if any windows have been drawn, so they (and others associated with them) |
| 3900 | // can now be shown. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3901 | activity.updateAllDrawn(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3902 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3903 | } |
| 3904 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3905 | private void updateBounds() { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3906 | calculateBounds(mDisplayInfo, mTmpBounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3907 | setBounds(mTmpBounds); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3908 | if (mPortalWindowHandle != null && mParentSurfaceControl != null) { |
| 3909 | mPortalWindowHandle.touchableRegion.getBounds(mTmpRect); |
| 3910 | if (!mTmpBounds.equals(mTmpRect)) { |
| 3911 | mPortalWindowHandle.touchableRegion.set(mTmpBounds); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3912 | getPendingTransaction().setInputWindowInfo( |
| 3913 | mParentSurfaceControl, mPortalWindowHandle); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3914 | } |
| 3915 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | // Determines the current display bounds based on the current state |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3919 | private void calculateBounds(DisplayInfo displayInfo, Rect out) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3920 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3921 | final int rotation = displayInfo.rotation; |
| 3922 | boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3923 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 3924 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3925 | int width = displayInfo.logicalWidth; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3926 | int left = (physWidth - width) / 2; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3927 | int height = displayInfo.logicalHeight; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3928 | int top = (physHeight - height) / 2; |
| 3929 | out.set(left, top, left + width, top + height); |
| 3930 | } |
| 3931 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3932 | private void getBounds(Rect out, int orientation) { |
| 3933 | getBounds(out); |
| 3934 | |
| 3935 | // Rotate the Rect if needed. |
| 3936 | final int currentRotation = mDisplayInfo.rotation; |
| 3937 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 3938 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 3939 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 3940 | mTmpRectF.set(out); |
| 3941 | mTmpMatrix.mapRect(mTmpRectF); |
| 3942 | mTmpRectF.round(out); |
| 3943 | } |
| 3944 | } |
| 3945 | |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 3946 | /** @return the orientation of the display when it's rotation is ROTATION_0. */ |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 3947 | int getNaturalOrientation() { |
| 3948 | return mBaseDisplayWidth < mBaseDisplayHeight |
| 3949 | ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
| 3950 | } |
| 3951 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3952 | void performLayout(boolean initial, boolean updateInputWindows) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3953 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "performLayout"); |
| 3954 | try { |
| 3955 | performLayoutNoTrace(initial, updateInputWindows); |
| 3956 | } finally { |
| 3957 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | private void performLayoutNoTrace(boolean initial, boolean updateInputWindows) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3962 | if (!isLayoutNeeded()) { |
| 3963 | return; |
| 3964 | } |
| 3965 | clearLayoutNeeded(); |
| 3966 | |
| 3967 | final int dw = mDisplayInfo.logicalWidth; |
| 3968 | final int dh = mDisplayInfo.logicalHeight; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3969 | if (DEBUG_LAYOUT) { |
| 3970 | Slog.v(TAG, "-------------------------------------"); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3971 | Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw |
| 3972 | + " dh=" + dh); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3973 | } |
| 3974 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 3975 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 3976 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3977 | // TODO: Not sure if we really need to set the rotation here since we are updating from |
| 3978 | // the display info above... |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3979 | mDisplayFrames.mRotation = getRotation(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3980 | mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3981 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3982 | int seq = mLayoutSeq + 1; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3983 | if (seq < 0) seq = 0; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3984 | mLayoutSeq = seq; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3985 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3986 | // Used to indicate that we have processed the dream window and all additional windows are |
| 3987 | // behind it. |
| 3988 | mTmpWindow = null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3989 | mTmpInitial = initial; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3990 | |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 3991 | // Used to indicate that we have processed the IME window. |
| 3992 | mTmpWindowsBehindIme = false; |
| 3993 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3994 | // First perform layout of any root windows (not attached to another window). |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3995 | forAllWindows(mPerformLayout, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3996 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3997 | // Used to indicate that we have processed the dream window and all additional attached |
| 3998 | // windows are behind it. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3999 | mTmpWindow2 = mTmpWindow; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4000 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4001 | |
| 4002 | // Now perform layout of attached windows, which usually depend on the position of the |
| 4003 | // window they are attached to. XXX does not deal with windows that are attached to windows |
| 4004 | // that are themselves attached. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4005 | forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4006 | |
| 4007 | // Window frames may have changed. Tell the input dispatcher about it. |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 4008 | mInputMonitor.layoutInputConsumers(dw, dh); |
| 4009 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4010 | if (updateInputWindows) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 4011 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4014 | mWmService.mH.sendEmptyMessage(UPDATE_MULTI_WINDOW_STACKS); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * Takes a snapshot of the display. In landscape mode this grabs the whole screen. |
| 4019 | * In portrait mode, it grabs the full screenshot. |
| 4020 | * |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4021 | * @param config of the output bitmap |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4022 | */ |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4023 | Bitmap screenshotDisplayLocked(Bitmap.Config config) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4024 | if (!mWmService.mPolicy.isScreenOn()) { |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4025 | if (DEBUG_SCREENSHOT) { |
| 4026 | Slog.i(TAG_WM, "Attempted to take screenshot while display was off."); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4027 | } |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4028 | return null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4029 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 4030 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4031 | int dw = mDisplayInfo.logicalWidth; |
| 4032 | int dh = mDisplayInfo.logicalHeight; |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 4033 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4034 | if (dw <= 0 || dh <= 0) { |
| 4035 | return null; |
| 4036 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 4037 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4038 | final Rect frame = new Rect(0, 0, dw, dh); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 4039 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4040 | // The screenshot API does not apply the current screen rotation. |
| 4041 | int rot = mDisplay.getRotation(); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 4042 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4043 | if (rot == ROTATION_90 || rot == ROTATION_270) { |
| 4044 | rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 4045 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 4046 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4047 | // SurfaceFlinger is not aware of orientation, so convert our logical |
| 4048 | // crop to SurfaceFlinger's portrait orientation. |
| 4049 | convertCropForSurfaceFlinger(frame, rot, dw, dh); |
| 4050 | |
| 4051 | final ScreenRotationAnimation screenRotationAnimation = |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 4052 | mWmService.mRoot.getDisplayContent(DEFAULT_DISPLAY).getRotationAnimation(); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4053 | final boolean inRotation = screenRotationAnimation != null && |
| 4054 | screenRotationAnimation.isAnimating(); |
| 4055 | if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating"); |
| 4056 | |
| 4057 | // TODO(b/68392460): We should screenshot Task controls directly |
| 4058 | // but it's difficult at the moment as the Task doesn't have the |
| 4059 | // correct size set. |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 4060 | final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 4061 | if (bitmap == null) { |
| 4062 | Slog.w(TAG_WM, "Failed to take screenshot"); |
| 4063 | return null; |
| 4064 | } |
| 4065 | |
| 4066 | // Create a copy of the screenshot that is immutable and backed in ashmem. |
| 4067 | // This greatly reduces the overhead of passing the bitmap between processes. |
| 4068 | final Bitmap ret = bitmap.createAshmemBitmap(config); |
| 4069 | bitmap.recycle(); |
| 4070 | return ret; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | // TODO: Can this use createRotationMatrix()? |
| 4074 | private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) { |
| 4075 | if (rot == Surface.ROTATION_90) { |
| 4076 | final int tmp = crop.top; |
| 4077 | crop.top = dw - crop.right; |
| 4078 | crop.right = crop.bottom; |
| 4079 | crop.bottom = dw - crop.left; |
| 4080 | crop.left = tmp; |
| 4081 | } else if (rot == Surface.ROTATION_180) { |
| 4082 | int tmp = crop.top; |
| 4083 | crop.top = dh - crop.bottom; |
| 4084 | crop.bottom = dh - tmp; |
| 4085 | tmp = crop.right; |
| 4086 | crop.right = dw - crop.left; |
| 4087 | crop.left = dw - tmp; |
| 4088 | } else if (rot == Surface.ROTATION_270) { |
| 4089 | final int tmp = crop.top; |
| 4090 | crop.top = crop.left; |
| 4091 | crop.left = dh - crop.bottom; |
| 4092 | crop.bottom = crop.right; |
| 4093 | crop.right = dh - tmp; |
| 4094 | } |
| 4095 | } |
| 4096 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4097 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 4098 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 4099 | mExitingTokens.get(i).hasVisible = hasVisible; |
| 4100 | } |
| 4101 | |
| 4102 | // Initialize state of exiting applications. |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 4103 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 4104 | getTaskDisplayAreaAt(i).setExitingTokensHasVisible(hasVisible); |
| 4105 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | void removeExistingTokensIfPossible() { |
| 4109 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 4110 | final WindowToken token = mExitingTokens.get(i); |
| 4111 | if (!token.hasVisible) { |
| 4112 | mExitingTokens.remove(i); |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | // Time to remove any exiting applications? |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 4117 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 4118 | getTaskDisplayAreaAt(i).removeExistingAppTokensIfPossible(); |
| 4119 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4120 | } |
| 4121 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4122 | @Override |
| 4123 | void onDescendantOverrideConfigurationChanged() { |
| 4124 | setLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4125 | mWmService.requestTraversal(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4126 | } |
| 4127 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4128 | boolean okToDisplay() { |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 4129 | return okToDisplay(false); |
| 4130 | } |
| 4131 | |
| 4132 | boolean okToDisplay(boolean ignoreFrozen) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4133 | if (mDisplayId == DEFAULT_DISPLAY) { |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 4134 | return (!mWmService.mDisplayFrozen || ignoreFrozen) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4135 | && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4136 | } |
| 4137 | return mDisplayInfo.state == Display.STATE_ON; |
| 4138 | } |
| 4139 | |
| 4140 | boolean okToAnimate() { |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 4141 | return okToAnimate(false); |
| 4142 | } |
| 4143 | |
| 4144 | boolean okToAnimate(boolean ignoreFrozen) { |
| 4145 | return okToDisplay(ignoreFrozen) && |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4146 | (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4147 | } |
| 4148 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4149 | static final class TaskForResizePointSearchResult { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 4150 | private Task taskForResize; |
| 4151 | private int x; |
| 4152 | private int y; |
| 4153 | private int delta; |
| 4154 | private Rect mTmpRect = new Rect(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4155 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 4156 | Task process(WindowContainer root, int x, int y, int delta) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4157 | taskForResize = null; |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 4158 | this.x = x; |
| 4159 | this.y = y; |
| 4160 | this.delta = delta; |
| 4161 | mTmpRect.setEmpty(); |
| 4162 | |
| 4163 | final PooledFunction f = PooledLambda.obtainFunction( |
| 4164 | TaskForResizePointSearchResult::processTask, this, PooledLambda.__(Task.class)); |
| 4165 | root.forAllTasks(f); |
| 4166 | f.recycle(); |
| 4167 | |
| 4168 | return taskForResize; |
| 4169 | } |
| 4170 | |
| 4171 | private boolean processTask(Task task) { |
| 4172 | if (!task.getStack().getWindowConfiguration().canResizeTask()) { |
| 4173 | return true; |
| 4174 | } |
| 4175 | |
| 4176 | if (task.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { |
| 4177 | return true; |
| 4178 | } |
| 4179 | |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 4180 | if (task.isOrganized()) { |
| 4181 | return true; |
| 4182 | } |
| 4183 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 4184 | // We need to use the task's dim bounds (which is derived from the visible bounds of |
| 4185 | // its apps windows) for any touch-related tests. Can't use the task's original |
| 4186 | // bounds because it might be adjusted to fit the content frame. One example is when |
| 4187 | // the task is put to top-left quadrant, the actual visible area would not start at |
| 4188 | // (0,0) after it's adjusted for the status bar. |
| 4189 | task.getDimBounds(mTmpRect); |
| 4190 | mTmpRect.inset(-delta, -delta); |
| 4191 | if (mTmpRect.contains(x, y)) { |
| 4192 | mTmpRect.inset(delta, delta); |
| 4193 | |
| 4194 | if (!mTmpRect.contains(x, y)) { |
| 4195 | taskForResize = task; |
| 4196 | return true; |
| 4197 | } |
| 4198 | // User touched inside the task. No need to look further, |
| 4199 | // focus transfer will be handled in ACTION_UP. |
| 4200 | return true; |
| 4201 | } |
| 4202 | |
| 4203 | return false; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4204 | } |
| 4205 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4206 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4207 | private static final class ApplySurfaceChangesTransactionState { |
| 4208 | boolean displayHasContent; |
| 4209 | boolean obscured; |
| 4210 | boolean syswin; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 4211 | boolean preferMinimalPostProcessing; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4212 | float preferredRefreshRate; |
| 4213 | int preferredModeId; |
| 4214 | |
| 4215 | void reset() { |
| 4216 | displayHasContent = false; |
| 4217 | obscured = false; |
| 4218 | syswin = false; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 4219 | preferMinimalPostProcessing = false; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4220 | preferredRefreshRate = 0; |
| 4221 | preferredModeId = 0; |
| 4222 | } |
| 4223 | } |
| 4224 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4225 | /** |
| 4226 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 4227 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 4228 | * homogeneous children type which is currently required by sub-classes of |
| 4229 | * {@link WindowContainer} class. |
| 4230 | */ |
| 4231 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 4232 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4233 | DisplayChildWindowContainer(WindowManagerService service) { |
| 4234 | super(service); |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4235 | // TODO(display-area): move to ConfigurationContainer? |
| 4236 | mOrientation = SCREEN_ORIENTATION_UNSET; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4237 | } |
| 4238 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4239 | @Override |
| 4240 | boolean fillsParent() { |
| 4241 | return true; |
| 4242 | } |
| 4243 | |
| 4244 | @Override |
| 4245 | boolean isVisible() { |
| 4246 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4247 | } |
| 4248 | } |
| 4249 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4250 | private class WindowContainers extends DisplayChildWindowContainer<WindowContainer> { |
| 4251 | private final String mName; |
| 4252 | |
| 4253 | WindowContainers(String name, WindowManagerService service) { |
| 4254 | super(service); |
| 4255 | mName = name; |
| 4256 | } |
| 4257 | |
| 4258 | @Override |
| 4259 | void assignChildLayers(SurfaceControl.Transaction t) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4260 | mImeWindowsContainers.setNeedsLayer(); |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 4261 | |
| 4262 | mRootDisplayArea.assignLayer(t, 0); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4263 | |
| 4264 | final WindowState imeTarget = mInputMethodTarget; |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4265 | // In the case where we have an IME target that is not in split-screen mode IME |
| 4266 | // assignment is easy. We just need the IME to go directly above the target. This way |
| 4267 | // children of the target will naturally go above the IME and everyone is happy. |
| 4268 | // |
| 4269 | // In the case of split-screen windowing mode, we need to elevate the IME above the |
| 4270 | // docked divider while keeping the app itself below the docked divider, so instead |
| 4271 | // we use relative layering of the IME targets child windows, and place the IME in |
| 4272 | // the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}). |
| 4273 | // |
| 4274 | // In the case the IME target is animating, the animation Z order may be different |
| 4275 | // than the WindowContainer Z order, so it's difficult to be sure we have the correct |
| 4276 | // IME target. In this case we just layer the IME over all transitions by placing it |
| 4277 | // in the above applications layer. |
| 4278 | // |
| 4279 | // In the case where we have no IME target we assign it where its base layer would |
| 4280 | // place it in the AboveAppWindowContainers. |
| 4281 | // |
| 4282 | // Keep IME window in mAboveAppWindowsContainers as long as app's starting window |
| 4283 | // exists so it get's layered above the starting window. |
| 4284 | if (imeTarget != null && !(imeTarget.mActivityRecord != null |
| 4285 | && imeTarget.mActivityRecord.hasStartingWindow()) && ( |
Robert Carr | 599d83c | 2020-01-24 14:45:14 -0800 | [diff] [blame] | 4286 | !(imeTarget.inMultiWindowMode() |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4287 | || imeTarget.mToken.isAppTransitioning()) && ( |
| 4288 | imeTarget.getSurfaceControl() != null))) { |
| 4289 | mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(), |
| 4290 | // TODO: We need to use an extra level on the app surface to ensure |
| 4291 | // this is always above SurfaceView but always below attached window. |
| 4292 | 1); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | // Above we have assigned layers to our children, now we ask them to assign |
| 4296 | // layers to their children. |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 4297 | mRootDisplayArea.assignChildLayers(t); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | @Override |
| 4301 | String getName() { |
| 4302 | return mName; |
| 4303 | } |
| 4304 | |
| 4305 | void addChildren() { |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 4306 | addChild(mRootDisplayArea, 0); |
| 4307 | mDisplayAreaPolicy.attachDisplayAreas(); |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4308 | } |
| 4309 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4310 | @Override |
| 4311 | void positionChildAt(int position, WindowContainer child, boolean includingParents) { |
| 4312 | // Children of the WindowContainers are statically ordered, so the real intention here |
| 4313 | // is to perform the operation on the display and not the static direct children. |
| 4314 | getParent().positionChildAt(position, this, includingParents); |
| 4315 | } |
| 4316 | } |
| 4317 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4318 | /** |
| 4319 | * Window container class that contains all containers on this display that are not related to |
| 4320 | * Apps. E.g. status bar. |
| 4321 | */ |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4322 | private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4323 | /** |
| 4324 | * Compares two child window tokens returns -1 if the first is lesser than the second in |
| 4325 | * terms of z-order and 1 otherwise. |
| 4326 | */ |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4327 | private final Comparator<WindowToken> mWindowComparator = (token1, token2) -> |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4328 | // Tokens with higher base layer are z-ordered on-top. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4329 | mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4330 | token1.mOwnerCanManageAppTokens) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4331 | < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4332 | token2.mOwnerCanManageAppTokens) ? -1 : 1; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4333 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4334 | private final String mName; |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4335 | private final Dimmer mDimmer = new Dimmer(this); |
| 4336 | private final Rect mTmpDimBoundsRect = new Rect(); |
| 4337 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4338 | NonAppWindowContainers(String name, WindowManagerService service) { |
| 4339 | super(service); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4340 | mName = name; |
| 4341 | } |
| 4342 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 4343 | @Override |
| 4344 | boolean hasActivity() { |
| 4345 | // I am a non-app-window-container :P |
| 4346 | return false; |
| 4347 | } |
| 4348 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4349 | void addChild(WindowToken token) { |
| 4350 | addChild(token, mWindowComparator); |
| 4351 | } |
| 4352 | |
| 4353 | @Override |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4354 | int getOrientation(int candidate) { |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 4355 | ProtoLog.w(WM_DEBUG_ORIENTATION, "NonAppWindowContainer cannot set orientation: %s", |
| 4356 | this); |
| 4357 | return SCREEN_ORIENTATION_UNSET; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | @Override |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4361 | String getName() { |
| 4362 | return mName; |
| 4363 | } |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4364 | |
| 4365 | @Override |
| 4366 | Dimmer getDimmer() { |
| 4367 | return mDimmer; |
| 4368 | } |
| 4369 | |
| 4370 | @Override |
| 4371 | void prepareSurfaces() { |
| 4372 | mDimmer.resetDimStates(); |
| 4373 | super.prepareSurfaces(); |
| 4374 | getBounds(mTmpDimBoundsRect); |
| 4375 | |
| 4376 | if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) { |
| 4377 | scheduleAnimation(); |
| 4378 | } |
| 4379 | } |
Arthur Hung | 9698646 | 2020-03-10 18:34:56 +0800 | [diff] [blame] | 4380 | |
| 4381 | @Override |
| 4382 | boolean shouldMagnify() { |
| 4383 | // Omitted from Screen-Magnification |
| 4384 | return false; |
| 4385 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4386 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 4387 | |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4388 | /** |
| 4389 | * Container for IME windows. |
| 4390 | * |
| 4391 | * This has some special behaviors: |
| 4392 | * - layers assignment is ignored except if setNeedsLayer() has been called before (and no |
| 4393 | * layer has been assigned since), to facilitate assigning the layer from the IME target, or |
| 4394 | * fall back if there is no target. |
| 4395 | * - the container doesn't always participate in window traversal, according to |
| 4396 | * {@link #skipImeWindowsDuringTraversal()} |
| 4397 | */ |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 4398 | private static class ImeContainer extends DisplayArea.Tokens { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4399 | boolean mNeedsLayer = false; |
| 4400 | |
| 4401 | ImeContainer(WindowManagerService wms) { |
Adrian Roos | 22a20a8 | 2019-10-23 19:05:33 +0200 | [diff] [blame] | 4402 | super(wms, Type.ABOVE_TASKS, "ImeContainer"); |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | public void setNeedsLayer() { |
| 4406 | mNeedsLayer = true; |
| 4407 | } |
| 4408 | |
| 4409 | @Override |
Adrian Roos | 0384f12 | 2020-01-10 19:39:43 +0100 | [diff] [blame] | 4410 | int getOrientation(int candidate) { |
| 4411 | // IME does not participate in orientation. |
| 4412 | return candidate; |
| 4413 | } |
| 4414 | |
| 4415 | @Override |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4416 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 4417 | boolean traverseTopToBottom) { |
| 4418 | final DisplayContent dc = mDisplayContent; |
| 4419 | if (skipImeWindowsDuringTraversal(dc)) { |
| 4420 | return false; |
| 4421 | } |
| 4422 | return super.forAllWindows(callback, traverseTopToBottom); |
| 4423 | } |
| 4424 | |
| 4425 | private boolean skipImeWindowsDuringTraversal(DisplayContent dc) { |
| 4426 | // We skip IME windows so they're processed just above their target, except |
| 4427 | // in split-screen mode where we process the IME containers above the docked divider. |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 4428 | return dc.mInputMethodTarget != null |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 4429 | && !dc.getDefaultTaskDisplayArea().isSplitScreenModeActivated(); |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | /** Like {@link #forAllWindows}, but ignores {@link #skipImeWindowsDuringTraversal} */ |
| 4433 | boolean forAllWindowForce(ToBooleanFunction<WindowState> callback, |
| 4434 | boolean traverseTopToBottom) { |
| 4435 | return super.forAllWindows(callback, traverseTopToBottom); |
| 4436 | } |
| 4437 | |
| 4438 | @Override |
| 4439 | void assignLayer(Transaction t, int layer) { |
| 4440 | if (!mNeedsLayer) { |
| 4441 | return; |
| 4442 | } |
| 4443 | super.assignLayer(t, layer); |
| 4444 | mNeedsLayer = false; |
| 4445 | } |
| 4446 | |
| 4447 | @Override |
| 4448 | void assignRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) { |
| 4449 | if (!mNeedsLayer) { |
| 4450 | return; |
| 4451 | } |
| 4452 | super.assignRelativeLayer(t, relativeTo, layer); |
| 4453 | mNeedsLayer = false; |
| 4454 | } |
| 4455 | } |
| 4456 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4457 | @Override |
| 4458 | SurfaceSession getSession() { |
| 4459 | return mSession; |
| 4460 | } |
| 4461 | |
| 4462 | @Override |
| 4463 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4464 | SurfaceSession s = child != null ? child.getSession() : getSession(); |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 4465 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s).setContainerLayer(); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4466 | if (child == null) { |
| 4467 | return b; |
| 4468 | } |
| 4469 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4470 | return b.setName(child.getName()) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4471 | .setParent(mSurfaceControl); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * The makeSurface variants are for use by the window-container |
| 4476 | * hierarchy. makeOverlay here is a function for various non windowing |
| 4477 | * overlays like the ScreenRotation screenshot, the Strict Mode Flash |
| 4478 | * and other potpourii. |
| 4479 | */ |
| 4480 | SurfaceControl.Builder makeOverlay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4481 | return mWmService.makeSurfaceBuilder(mSession) |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4482 | .setParent(mOverlayContainers.getSurfaceControl()); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4485 | /** |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4486 | * Reparents the given surface to {@link #mOverlayContainers}' SurfaceControl. |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4487 | */ |
| 4488 | void reparentToOverlay(Transaction transaction, SurfaceControl surface) { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4489 | transaction.reparent(surface, mOverlayContainers.getSurfaceControl()); |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4490 | } |
| 4491 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4492 | void applyMagnificationSpec(MagnificationSpec spec) { |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4493 | if (spec.scale != 1.0) { |
| 4494 | mMagnificationSpec = spec; |
| 4495 | } else { |
| 4496 | mMagnificationSpec = null; |
| 4497 | } |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 4498 | // Re-parent IME's SurfaceControl when MagnificationSpec changed. |
| 4499 | updateImeParent(); |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4500 | |
Robert Carr | 7603dea | 2019-07-17 13:16:21 -0700 | [diff] [blame] | 4501 | if (spec.scale != 1.0) { |
| 4502 | applyMagnificationSpec(getPendingTransaction(), spec); |
| 4503 | } else { |
| 4504 | clearMagnificationSpec(getPendingTransaction()); |
| 4505 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4506 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4509 | void reapplyMagnificationSpec() { |
| 4510 | if (mMagnificationSpec != null) { |
| 4511 | applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec); |
| 4512 | } |
| 4513 | } |
| 4514 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4515 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4516 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4517 | // Since we are the top of the SurfaceControl hierarchy here |
| 4518 | // we create the root surfaces explicitly rather than chaining |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 4519 | // up as the default implementation in onParentChanged does. So we |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4520 | // explicitly do NOT call super here. |
Garfield Tan | fbd233a | 2019-12-26 12:39:25 -0800 | [diff] [blame] | 4521 | |
| 4522 | if (!isReady()) { |
| 4523 | // TODO(b/62541591): evaluate whether this is the best spot to declare the |
| 4524 | // {@link DisplayContent} ready for use. |
| 4525 | mDisplayReady = true; |
| 4526 | |
| 4527 | mWmService.mAnimator.addDisplayLocked(mDisplayId); |
| 4528 | |
| 4529 | if (mWmService.mDisplayManagerInternal != null) { |
| 4530 | mWmService.mDisplayManagerInternal |
| 4531 | .setDisplayInfoOverrideFromWindowManager(mDisplayId, getDisplayInfo()); |
| 4532 | configureDisplayPolicy(); |
| 4533 | } |
| 4534 | |
| 4535 | reconfigureDisplayLocked(); |
| 4536 | onRequestedOverrideConfigurationChanged(getRequestedOverrideConfiguration()); |
| 4537 | mWmService.mDisplayNotificationController.dispatchDisplayAdded(this); |
| 4538 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | @Override |
| 4542 | void assignChildLayers(SurfaceControl.Transaction t) { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4543 | mWindowContainers.assignLayer(t, 0); |
| 4544 | mOverlayContainers.assignLayer(t, 1); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4545 | |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4546 | mWindowContainers.assignChildLayers(t); |
| 4547 | mOverlayContainers.assignChildLayers(t); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | /** |
| 4551 | * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine |
| 4552 | * that the IME target is one of the docked applications. We'd like the docked divider to be |
| 4553 | * above both of the applications, and we'd like the IME to be above the docked divider. |
| 4554 | * However we need child windows of the applications to be above the IME (Text drag handles). |
| 4555 | * This is a non-strictly hierarcical layering and we need to break out of the Z ordering |
| 4556 | * 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] | 4557 | * with {@link WindowState#assignLayer} |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4558 | */ |
| 4559 | void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) { |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 4560 | mImeWindowsContainers.setNeedsLayer(); |
Robert Carr | bb5de66 | 2018-04-26 13:29:51 -0700 | [diff] [blame] | 4561 | child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | @Override |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4565 | void prepareSurfaces() { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4566 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareSurfaces"); |
| 4567 | try { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4568 | final Transaction transaction = getPendingTransaction(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4569 | super.prepareSurfaces(); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4570 | |
| 4571 | // TODO: Once we totally eliminate global transaction we will pass transaction in here |
| 4572 | // rather than merging to global. |
| 4573 | SurfaceControl.mergeToGlobalTransaction(transaction); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4574 | } finally { |
| 4575 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 4576 | } |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4577 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4578 | |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4579 | void assignStackOrdering() { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 4580 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 4581 | getTaskDisplayAreaAt(i).assignStackOrdering(getPendingTransaction()); |
| 4582 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4583 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4584 | |
| 4585 | /** |
| 4586 | * Increment the deferral count to determine whether to update the IME target. |
| 4587 | */ |
| 4588 | void deferUpdateImeTarget() { |
| 4589 | mDeferUpdateImeTargetCount++; |
| 4590 | } |
| 4591 | |
| 4592 | /** |
| 4593 | * Decrement the deferral count to determine whether to update the IME target. If the count |
| 4594 | * reaches 0, a new ime target will get computed. |
| 4595 | */ |
| 4596 | void continueUpdateImeTarget() { |
| 4597 | if (mDeferUpdateImeTargetCount == 0) { |
| 4598 | return; |
| 4599 | } |
| 4600 | |
| 4601 | mDeferUpdateImeTargetCount--; |
| 4602 | if (mDeferUpdateImeTargetCount == 0) { |
| 4603 | computeImeTarget(true /* updateImeTarget */); |
| 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | /** |
| 4608 | * @return Whether a new IME target should be computed. |
| 4609 | */ |
| 4610 | private boolean canUpdateImeTarget() { |
| 4611 | return mDeferUpdateImeTargetCount == 0; |
| 4612 | } |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 4613 | |
| 4614 | InputMonitor getInputMonitor() { |
| 4615 | return mInputMonitor; |
| 4616 | } |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 4617 | |
| 4618 | /** |
| 4619 | * @return Cached value whether we told display manager that we have content. |
| 4620 | */ |
| 4621 | boolean getLastHasContent() { |
| 4622 | return mLastHasContent; |
| 4623 | } |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4624 | |
| 4625 | void registerPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4626 | mPointerEventDispatcher.registerInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | void unregisterPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4630 | mPointerEventDispatcher.unregisterInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4631 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4632 | |
| 4633 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4634 | boolean alwaysKeepCurrent) { |
| 4635 | prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */); |
| 4636 | } |
| 4637 | |
| 4638 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4639 | boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags, |
| 4640 | boolean forceOverride) { |
| 4641 | final boolean prepared = mAppTransition.prepareAppTransitionLocked( |
| 4642 | transit, alwaysKeepCurrent, flags, forceOverride); |
| 4643 | if (prepared && okToAnimate()) { |
| 4644 | mSkipAppTransitionAnimation = false; |
| 4645 | } |
| 4646 | } |
| 4647 | |
| 4648 | void executeAppTransition() { |
| 4649 | if (mAppTransition.isTransitionSet()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4650 | ProtoLog.w(WM_DEBUG_APP_TRANSITIONS, |
| 4651 | "Execute app transition: %s, displayId: %d Callers=%s", |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4652 | mAppTransition, mDisplayId, Debug.getCallers(5)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4653 | mAppTransition.setReady(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4654 | mWmService.mWindowPlacerLocked.requestTraversal(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | /** |
| 4659 | * Update pendingLayoutChanges after app transition has finished. |
| 4660 | */ |
| 4661 | void handleAnimatingStoppedAndTransition() { |
| 4662 | int changes = 0; |
| 4663 | |
| 4664 | mAppTransition.setIdle(); |
| 4665 | |
| 4666 | for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) { |
| 4667 | final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i); |
| 4668 | mAppTransition.notifyAppTransitionFinishedLocked(token); |
| 4669 | } |
| 4670 | mNoAnimationNotifyOnTransitionFinished.clear(); |
| 4671 | |
| 4672 | mWallpaperController.hideDeferredWallpapersIfNeeded(); |
| 4673 | |
| 4674 | onAppTransitionDone(); |
| 4675 | |
| 4676 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4677 | if (DEBUG_WALLPAPER_LIGHT) { |
| 4678 | Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout"); |
| 4679 | } |
| 4680 | computeImeTarget(true /* updateImeTarget */); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 4681 | mWallpaperMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4682 | // Since the window list has been rebuilt, focus might have to be recomputed since the |
| 4683 | // actual order of windows might have changed again. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4684 | mWmService.mFocusMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4685 | |
| 4686 | pendingLayoutChanges |= changes; |
| 4687 | } |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4688 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4689 | /** Check if pending app transition is for activity / task launch. */ |
| 4690 | boolean isNextTransitionForward() { |
| 4691 | final int transit = mAppTransition.getAppTransition(); |
| 4692 | return transit == TRANSIT_ACTIVITY_OPEN |
| 4693 | || transit == TRANSIT_TASK_OPEN |
| 4694 | || transit == TRANSIT_TASK_TO_FRONT; |
| 4695 | } |
| 4696 | |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4697 | /** |
| 4698 | * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS |
| 4699 | */ |
| 4700 | boolean supportsSystemDecorations() { |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 4701 | return (mWmService.mDisplayWindowSettings.shouldShowSystemDecorsLocked(this) |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 4702 | || (mDisplay.getFlags() & FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0 |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 4703 | || (mWmService.mForceDesktopModeOnExternalDisplays && !isUntrustedVirtualDisplay())) |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 4704 | // VR virtual display will be used to run and render 2D app within a VR experience. |
| 4705 | && mDisplayId != mWmService.mVr2dDisplayId; |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4706 | } |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4707 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4708 | /** |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 4709 | * @return {@code true} if the display is non-system created virtual display. |
| 4710 | */ |
| 4711 | boolean isUntrustedVirtualDisplay() { |
| 4712 | return mDisplay.getType() == Display.TYPE_VIRTUAL |
| 4713 | && mDisplay.getOwnerUid() != Process.SYSTEM_UID; |
| 4714 | } |
| 4715 | |
| 4716 | /** |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4717 | * Re-parent the DisplayContent's top surface, {@link #mSurfaceControl} to the specified |
| 4718 | * SurfaceControl. |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4719 | * |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4720 | * @param win The window which owns the SurfaceControl. This indicates the z-order of the |
| 4721 | * windows of this display against the windows on the parent display. |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4722 | * @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] | 4723 | */ |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4724 | void reparentDisplayContent(WindowState win, SurfaceControl sc) { |
| 4725 | mParentWindow = win; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4726 | mParentWindow.addEmbeddedDisplayContent(this); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4727 | mParentSurfaceControl = sc; |
| 4728 | if (mPortalWindowHandle == null) { |
| 4729 | mPortalWindowHandle = createPortalWindowHandle(sc.toString()); |
| 4730 | } |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4731 | getPendingTransaction().setInputWindowInfo(sc, mPortalWindowHandle) |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 4732 | .reparent(mSurfaceControl, sc); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4733 | } |
| 4734 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4735 | /** |
| 4736 | * Get the window which owns the surface that this DisplayContent is re-parented to. |
| 4737 | * |
| 4738 | * @return the parent window. |
| 4739 | */ |
| 4740 | WindowState getParentWindow() { |
| 4741 | return mParentWindow; |
| 4742 | } |
| 4743 | |
| 4744 | /** |
| 4745 | * Update the location of this display in the parent window. This enables windows in this |
| 4746 | * display to compute the global transformation matrix. |
| 4747 | * |
| 4748 | * @param win The parent window of this display. |
| 4749 | * @param x The x coordinate in the parent window. |
| 4750 | * @param y The y coordinate in the parent window. |
| 4751 | */ |
| 4752 | void updateLocation(WindowState win, int x, int y) { |
| 4753 | if (mParentWindow != win) { |
| 4754 | throw new IllegalArgumentException( |
| 4755 | "The given window is not the parent window of this display."); |
| 4756 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4757 | if (!mLocationInParentWindow.equals(x, y)) { |
| 4758 | mLocationInParentWindow.set(x, y); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4759 | if (mWmService.mAccessibilityController != null) { |
Jacky Kao | f93252b | 2019-07-18 15:19:52 +0800 | [diff] [blame] | 4760 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(mDisplayId); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4761 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4762 | notifyLocationInParentDisplayChanged(); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | |
| 4766 | Point getLocationInParentWindow() { |
| 4767 | return mLocationInParentWindow; |
| 4768 | } |
| 4769 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4770 | Point getLocationInParentDisplay() { |
| 4771 | final Point location = new Point(); |
| 4772 | if (mParentWindow != null) { |
| 4773 | // LocationInParentWindow indicates the offset to (0,0) of window, but what we need is |
| 4774 | // the offset to (0,0) of display. |
| 4775 | DisplayContent dc = this; |
| 4776 | do { |
| 4777 | final WindowState displayParent = dc.getParentWindow(); |
| 4778 | location.x += displayParent.getFrameLw().left |
| 4779 | + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f); |
| 4780 | location.y += displayParent.getFrameLw().top |
| 4781 | + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f); |
| 4782 | dc = displayParent.getDisplayContent(); |
| 4783 | } while (dc != null && dc.getParentWindow() != null); |
| 4784 | } |
| 4785 | return location; |
| 4786 | } |
| 4787 | |
| 4788 | void notifyLocationInParentDisplayChanged() { |
| 4789 | forAllWindows(w -> { |
| 4790 | w.updateLocationInParentDisplayIfNeeded(); |
| 4791 | }, false /* traverseTopToBottom */); |
| 4792 | } |
| 4793 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 4794 | @VisibleForTesting |
| 4795 | SurfaceControl getWindowingLayer() { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4796 | return mWindowContainers.getSurfaceControl(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 4797 | } |
| 4798 | |
Adrian Roos | 329cbd0 | 2020-04-14 15:42:41 +0200 | [diff] [blame] | 4799 | @VisibleForTesting |
| 4800 | WindowContainer<?> getImeContainer() { |
| 4801 | return mImeWindowsContainers; |
| 4802 | } |
| 4803 | |
Vadim Caen | f847426 | 2019-08-12 17:52:01 +0200 | [diff] [blame] | 4804 | SurfaceControl getOverlayLayer() { |
chaviw | 8065f44 | 2019-11-18 13:20:58 -0800 | [diff] [blame] | 4805 | return mOverlayContainers.getSurfaceControl(); |
Vadim Caen | f847426 | 2019-08-12 17:52:01 +0200 | [diff] [blame] | 4806 | } |
| 4807 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4808 | /** |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4809 | * Updates the display's system gesture exclusion. |
| 4810 | * |
| 4811 | * @return true, if the exclusion changed. |
| 4812 | */ |
| 4813 | boolean updateSystemGestureExclusion() { |
| 4814 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 0) { |
| 4815 | // No one's interested anyways. |
| 4816 | return false; |
| 4817 | } |
| 4818 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4819 | final Region systemGestureExclusion = Region.obtain(); |
| 4820 | mSystemGestureExclusionWasRestricted = calculateSystemGestureExclusion( |
| 4821 | systemGestureExclusion, mSystemGestureExclusionUnrestricted); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4822 | try { |
| 4823 | if (mSystemGestureExclusion.equals(systemGestureExclusion)) { |
| 4824 | return false; |
| 4825 | } |
| 4826 | mSystemGestureExclusion.set(systemGestureExclusion); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4827 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 4828 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4829 | for (int i = mSystemGestureExclusionListeners.beginBroadcast() - 1; i >= 0; --i) { |
| 4830 | try { |
| 4831 | mSystemGestureExclusionListeners.getBroadcastItem(i) |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4832 | .onSystemGestureExclusionChanged(mDisplayId, systemGestureExclusion, |
| 4833 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4834 | } catch (RemoteException e) { |
| 4835 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener", e); |
| 4836 | } |
| 4837 | } |
| 4838 | mSystemGestureExclusionListeners.finishBroadcast(); |
| 4839 | return true; |
| 4840 | } finally { |
| 4841 | systemGestureExclusion.recycle(); |
| 4842 | } |
| 4843 | } |
| 4844 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4845 | /** |
| 4846 | * Calculates the system gesture exclusion. |
| 4847 | * |
| 4848 | * @param outExclusion will be set to the gesture exclusion region |
| 4849 | * @param outExclusionUnrestricted will be set to the gesture exclusion region without |
| 4850 | * any restrictions applied. |
| 4851 | * @return whether any restrictions were applied, i.e. outExclusion and outExclusionUnrestricted |
| 4852 | * differ. |
| 4853 | */ |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4854 | @VisibleForTesting |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4855 | boolean calculateSystemGestureExclusion(Region outExclusion, @Nullable |
| 4856 | Region outExclusionUnrestricted) { |
| 4857 | outExclusion.setEmpty(); |
| 4858 | if (outExclusionUnrestricted != null) { |
| 4859 | outExclusionUnrestricted.setEmpty(); |
| 4860 | } |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4861 | final Region unhandled = Region.obtain(); |
| 4862 | unhandled.set(0, 0, mDisplayFrames.mDisplayWidth, mDisplayFrames.mDisplayHeight); |
| 4863 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 4864 | final Rect leftEdge = mInsetsStateController.getSourceProvider(ITYPE_LEFT_GESTURES) |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4865 | .getSource().getFrame(); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 4866 | final Rect rightEdge = mInsetsStateController.getSourceProvider(ITYPE_RIGHT_GESTURES) |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4867 | .getSource().getFrame(); |
| 4868 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4869 | final Region touchableRegion = Region.obtain(); |
| 4870 | final Region local = Region.obtain(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4871 | final int[] remainingLeftRight = |
| 4872 | {mSystemGestureExclusionLimit, mSystemGestureExclusionLimit}; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4873 | |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 4874 | // Traverse all windows top down to assemble the gesture exclusion rects. |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4875 | // For each window, we only take the rects that fall within its touchable region. |
| 4876 | forAllWindows(w -> { |
| 4877 | if (w.cantReceiveTouchInput() || !w.isVisible() |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4878 | || (w.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 |
| 4879 | || unhandled.isEmpty()) { |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4880 | return; |
| 4881 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4882 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4883 | // Get the touchable region of the window, and intersect with where the screen is still |
| 4884 | // touchable, i.e. touchable regions on top are not covering it yet. |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 4885 | w.getEffectiveTouchableRegion(touchableRegion); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4886 | touchableRegion.op(unhandled, Op.INTERSECT); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4887 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 4888 | if (w.isImplicitlyExcludingAllSystemGestures()) { |
| 4889 | local.set(touchableRegion); |
| 4890 | } else { |
| 4891 | rectListToRegion(w.getSystemGestureExclusion(), local); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4892 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 4893 | // Transform to display coordinates |
| 4894 | local.scale(w.mGlobalScale); |
| 4895 | final Rect frame = w.getWindowFrames().mFrame; |
| 4896 | local.translate(frame.left, frame.top); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4897 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 4898 | // A window can only exclude system gestures where it is actually touchable |
| 4899 | local.op(touchableRegion, Op.INTERSECT); |
| 4900 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4901 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4902 | // Apply restriction if necessary. |
| 4903 | if (needsGestureExclusionRestrictions(w, mLastDispatchedSystemUiVisibility)) { |
| 4904 | |
| 4905 | // Processes the region along the left edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4906 | remainingLeftRight[0] = addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 4907 | remainingLeftRight[0], w, EXCLUSION_LEFT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4908 | |
| 4909 | // Processes the region along the right edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4910 | remainingLeftRight[1] = addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 4911 | remainingLeftRight[1], w, EXCLUSION_RIGHT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4912 | |
| 4913 | // Adds the middle (unrestricted area) |
| 4914 | final Region middle = Region.obtain(local); |
| 4915 | middle.op(leftEdge, Op.DIFFERENCE); |
| 4916 | middle.op(rightEdge, Op.DIFFERENCE); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4917 | outExclusion.op(middle, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4918 | middle.recycle(); |
| 4919 | } else { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4920 | boolean loggable = needsGestureExclusionRestrictions(w, 0 /* lastSysUiVis */); |
| 4921 | if (loggable) { |
| 4922 | addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 4923 | Integer.MAX_VALUE, w, EXCLUSION_LEFT); |
| 4924 | addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 4925 | Integer.MAX_VALUE, w, EXCLUSION_RIGHT); |
| 4926 | } |
| 4927 | outExclusion.op(local, Op.UNION); |
| 4928 | } |
| 4929 | if (outExclusionUnrestricted != null) { |
| 4930 | outExclusionUnrestricted.op(local, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4931 | } |
| 4932 | unhandled.op(touchableRegion, Op.DIFFERENCE); |
| 4933 | }, true /* topToBottom */); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4934 | local.recycle(); |
| 4935 | touchableRegion.recycle(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4936 | unhandled.recycle(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4937 | return remainingLeftRight[0] < mSystemGestureExclusionLimit |
| 4938 | || remainingLeftRight[1] < mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4939 | } |
| 4940 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4941 | /** |
| 4942 | * @return Whether gesture exclusion area should be restricted from the window depending on the |
| 4943 | * current SystemUI visibility flags. |
| 4944 | */ |
| 4945 | private static boolean needsGestureExclusionRestrictions(WindowState win, int sysUiVisibility) { |
| 4946 | final int type = win.mAttrs.type; |
| 4947 | final int stickyHideNavFlags = |
| 4948 | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 4949 | final boolean stickyHideNav = |
| 4950 | (sysUiVisibility & stickyHideNavFlags) == stickyHideNavFlags; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 4951 | return !stickyHideNav && type != TYPE_INPUT_METHOD && type != TYPE_NOTIFICATION_SHADE |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4952 | && win.getActivityType() != ACTIVITY_TYPE_HOME; |
| 4953 | } |
| 4954 | |
| 4955 | /** |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4956 | * @return Whether gesture exclusion area should be logged for the given window |
| 4957 | */ |
| 4958 | static boolean logsGestureExclusionRestrictions(WindowState win) { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 4959 | if (win.mWmService.mConstants.mSystemGestureExclusionLogDebounceTimeoutMillis <= 0) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4960 | return false; |
| 4961 | } |
| 4962 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 4963 | final int type = attrs.type; |
| 4964 | return type != TYPE_WALLPAPER |
| 4965 | && type != TYPE_APPLICATION_STARTING |
| 4966 | && type != TYPE_NAVIGATION_BAR |
| 4967 | && (attrs.flags & FLAG_NOT_TOUCHABLE) == 0 |
| 4968 | && needsGestureExclusionRestrictions(win, 0 /* sysUiVisibility */) |
| 4969 | && win.getDisplayContent().mDisplayPolicy.hasSideGestures(); |
| 4970 | } |
| 4971 | |
| 4972 | /** |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4973 | * Adds a local gesture exclusion area to the global area while applying a limit per edge. |
| 4974 | * |
| 4975 | * @param local The gesture exclusion area to add. |
| 4976 | * @param global The destination. |
| 4977 | * @param edge Only processes the part in that region. |
| 4978 | * @param limit How much limit in pixels we have. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4979 | * @param win The WindowState that is being processed |
| 4980 | * @param side The side that is being processed, either {@link WindowState#EXCLUSION_LEFT} or |
| 4981 | * {@link WindowState#EXCLUSION_RIGHT} |
| 4982 | * @return How much of the limit is remaining. |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4983 | */ |
| 4984 | private static int addToGlobalAndConsumeLimit(Region local, Region global, Rect edge, |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4985 | int limit, WindowState win, int side) { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4986 | final Region r = Region.obtain(local); |
| 4987 | r.op(edge, Op.INTERSECT); |
| 4988 | |
| 4989 | final int[] remaining = {limit}; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4990 | final int[] requestedExclusion = {0}; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 4991 | forEachRectReverse(r, rect -> { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4992 | if (remaining[0] <= 0) { |
| 4993 | return; |
| 4994 | } |
| 4995 | final int height = rect.height(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4996 | requestedExclusion[0] += height; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4997 | if (height > remaining[0]) { |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 4998 | rect.top = rect.bottom - remaining[0]; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4999 | } |
| 5000 | remaining[0] -= height; |
| 5001 | global.op(rect, Op.UNION); |
| 5002 | }); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5003 | |
| 5004 | final int grantedExclusion = limit - remaining[0]; |
| 5005 | win.setLastExclusionHeights(side, requestedExclusion[0], grantedExclusion); |
| 5006 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5007 | r.recycle(); |
| 5008 | return remaining[0]; |
| 5009 | } |
| 5010 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5011 | void registerSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5012 | mSystemGestureExclusionListeners.register(listener); |
| 5013 | final boolean changed; |
| 5014 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 1) { |
| 5015 | changed = updateSystemGestureExclusion(); |
| 5016 | } else { |
| 5017 | changed = false; |
| 5018 | } |
| 5019 | |
| 5020 | if (!changed) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5021 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5022 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5023 | // If updateSystemGestureExclusion changed the exclusion, it will already have |
| 5024 | // notified the listener. Otherwise, we'll do it here. |
| 5025 | try { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5026 | listener.onSystemGestureExclusionChanged(mDisplayId, mSystemGestureExclusion, |
| 5027 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5028 | } catch (RemoteException e) { |
| 5029 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener during register", e); |
| 5030 | } |
| 5031 | } |
| 5032 | } |
| 5033 | |
| 5034 | void unregisterSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5035 | mSystemGestureExclusionListeners.unregister(listener); |
| 5036 | } |
| 5037 | |
| 5038 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5039 | * Create a portal window handle for input. This window transports any touch to the display |
| 5040 | * indicated by {@link InputWindowHandle#portalToDisplayId} if the touch hits this window. |
| 5041 | * |
| 5042 | * @param name The name of the portal window handle. |
| 5043 | * @return the new portal window handle. |
| 5044 | */ |
| 5045 | private InputWindowHandle createPortalWindowHandle(String name) { |
| 5046 | // Let surface flinger to set the display ID of this input window handle because we don't |
| 5047 | // know which display the parent surface control is on. |
| 5048 | final InputWindowHandle portalWindowHandle = new InputWindowHandle( |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 5049 | null /* inputApplicationHandle */, INVALID_DISPLAY); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5050 | portalWindowHandle.name = name; |
| 5051 | portalWindowHandle.token = new Binder(); |
| 5052 | portalWindowHandle.layoutParamsFlags = |
| 5053 | FLAG_SPLIT_TOUCH | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL; |
| 5054 | getBounds(mTmpBounds); |
| 5055 | portalWindowHandle.touchableRegion.set(mTmpBounds); |
| 5056 | portalWindowHandle.scaleFactor = 1f; |
| 5057 | portalWindowHandle.ownerPid = Process.myPid(); |
| 5058 | portalWindowHandle.ownerUid = Process.myUid(); |
| 5059 | portalWindowHandle.portalToDisplayId = mDisplayId; |
| 5060 | return portalWindowHandle; |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5061 | } |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 5062 | |
| 5063 | /** |
| 5064 | * @see IWindowManager#setForwardedInsets |
| 5065 | */ |
| 5066 | public void setForwardedInsets(Insets insets) { |
| 5067 | if (insets == null) { |
| 5068 | insets = Insets.NONE; |
| 5069 | } |
| 5070 | if (mDisplayPolicy.getForwardedInsets().equals(insets)) { |
| 5071 | return; |
| 5072 | } |
| 5073 | mDisplayPolicy.setForwardedInsets(insets); |
| 5074 | setLayoutNeeded(); |
| 5075 | mWmService.mWindowPlacerLocked.requestTraversal(); |
| 5076 | } |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 5077 | |
| 5078 | protected MetricsLogger getMetricsLogger() { |
| 5079 | if (mMetricsLogger == null) { |
| 5080 | mMetricsLogger = new MetricsLogger(); |
| 5081 | } |
| 5082 | return mMetricsLogger; |
| 5083 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5084 | |
| 5085 | void onDisplayChanged() { |
Jorim Jaggi | 7c579cd | 2020-03-25 18:42:49 +0100 | [diff] [blame] | 5086 | mDisplay.getRealSize(mTmpDisplaySize); |
| 5087 | setBounds(0, 0, mTmpDisplaySize.x, mTmpDisplaySize.y); |
| 5088 | updateDisplayInfo(); |
| 5089 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5090 | // The window policy is responsible for stopping activities on the default display. |
| 5091 | final int displayId = mDisplay.getDisplayId(); |
| 5092 | if (displayId != DEFAULT_DISPLAY) { |
| 5093 | final int displayState = mDisplay.getState(); |
| 5094 | if (displayState == Display.STATE_OFF && mOffToken == null) { |
| 5095 | mOffToken = mAtmService.acquireSleepToken("Display-off", displayId); |
| 5096 | } else if (displayState == Display.STATE_ON && mOffToken != null) { |
| 5097 | mOffToken.release(); |
| 5098 | mOffToken = null; |
| 5099 | } |
| 5100 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5101 | mWmService.requestTraversal(); |
| 5102 | } |
| 5103 | |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 5104 | static boolean alwaysCreateStack(int windowingMode, int activityType) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5105 | // Always create a stack for fullscreen, freeform, and split-screen-secondary windowing |
| 5106 | // modes so that we can manage visual ordering and return types correctly. |
| 5107 | return activityType == ACTIVITY_TYPE_STANDARD |
| 5108 | && (windowingMode == WINDOWING_MODE_FULLSCREEN |
| 5109 | || windowingMode == WINDOWING_MODE_FREEFORM |
Evan Rosky | 688c838 | 2020-04-03 17:27:08 -0700 | [diff] [blame] | 5110 | || windowingMode == WINDOWING_MODE_PINNED |
Robert Carr | cb1dde6 | 2020-02-06 13:53:46 -0800 | [diff] [blame] | 5111 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 5112 | || windowingMode == WINDOWING_MODE_MULTI_WINDOW); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5113 | } |
| 5114 | |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5115 | @Nullable |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5116 | ActivityStack getFocusedStack() { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5117 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 5118 | final ActivityStack stack = getTaskDisplayAreaAt(i).getFocusedStack(); |
| 5119 | if (stack != null) { |
| 5120 | return stack; |
| 5121 | } |
| 5122 | } |
| 5123 | return null; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | /** |
| 5127 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 5128 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 5129 | */ |
| 5130 | void removeStacksInWindowingModes(int... windowingModes) { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5131 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 5132 | getTaskDisplayAreaAt(i).removeStacksInWindowingModes(windowingModes); |
| 5133 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | void removeStacksWithActivityTypes(int... activityTypes) { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5137 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 5138 | getTaskDisplayAreaAt(i).removeStacksWithActivityTypes(activityTypes); |
| 5139 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | ActivityRecord topRunningActivity() { |
| 5143 | return topRunningActivity(false /* considerKeyguardState */); |
| 5144 | } |
| 5145 | |
| 5146 | /** |
| 5147 | * Returns the top running activity in the focused stack. In the case the focused stack has no |
| 5148 | * such activity, the next focusable stack on this display is returned. |
| 5149 | * |
| 5150 | * @param considerKeyguardState Indicates whether the locked state should be considered. if |
| 5151 | * {@code true} and the keyguard is locked, only activities that |
| 5152 | * can be shown on top of the keyguard will be considered. |
| 5153 | * @return The top running activity. {@code null} if none is available. |
| 5154 | */ |
| 5155 | ActivityRecord topRunningActivity(boolean considerKeyguardState) { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5156 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 5157 | final ActivityRecord activity = getTaskDisplayAreaAt(i) |
| 5158 | .topRunningActivity(considerKeyguardState); |
| 5159 | if (activity != null) { |
| 5160 | return activity; |
| 5161 | } |
| 5162 | } |
| 5163 | return null; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | boolean updateDisplayOverrideConfigurationLocked() { |
| 5167 | Configuration values = new Configuration(); |
| 5168 | computeScreenConfiguration(values); |
| 5169 | |
| 5170 | mAtmService.mH.sendMessage(PooledLambda.obtainMessage( |
| 5171 | ActivityManagerInternal::updateOomLevelsForDisplay, mAtmService.mAmInternal, |
| 5172 | mDisplayId)); |
| 5173 | |
| 5174 | Settings.System.clearConfiguration(values); |
| 5175 | updateDisplayOverrideConfigurationLocked(values, null /* starting */, |
| 5176 | false /* deferResume */, mAtmService.mTmpUpdateConfigurationResult); |
| 5177 | return mAtmService.mTmpUpdateConfigurationResult.changes != 0; |
| 5178 | } |
| 5179 | |
| 5180 | /** |
| 5181 | * Updates override configuration specific for the selected display. If no config is provided, |
| 5182 | * new one will be computed in WM based on current display info. |
| 5183 | */ |
| 5184 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, |
| 5185 | ActivityRecord starting, boolean deferResume, |
| 5186 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5187 | |
| 5188 | int changes = 0; |
| 5189 | boolean kept = true; |
| 5190 | |
| 5191 | mAtmService.deferWindowLayout(); |
| 5192 | try { |
| 5193 | if (values != null) { |
| 5194 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 5195 | // Override configuration of the default display duplicates global config, so |
| 5196 | // we're calling global config update instead for default display. It will also |
| 5197 | // apply the correct override config. |
| 5198 | changes = mAtmService.updateGlobalConfigurationLocked(values, |
| 5199 | false /* initLocale */, false /* persistent */, |
| 5200 | UserHandle.USER_NULL /* userId */, deferResume); |
| 5201 | } else { |
| 5202 | changes = performDisplayOverrideConfigUpdate(values, deferResume); |
| 5203 | } |
| 5204 | } |
| 5205 | |
| 5206 | kept = mAtmService.ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5207 | } finally { |
| 5208 | mAtmService.continueWindowLayout(); |
| 5209 | } |
| 5210 | |
| 5211 | if (result != null) { |
| 5212 | result.changes = changes; |
| 5213 | result.activityRelaunched = !kept; |
| 5214 | } |
| 5215 | return kept; |
| 5216 | } |
| 5217 | |
| 5218 | int performDisplayOverrideConfigUpdate(Configuration values, boolean deferResume) { |
| 5219 | mTempConfig.setTo(getRequestedOverrideConfiguration()); |
| 5220 | final int changes = mTempConfig.updateFrom(values); |
| 5221 | if (changes != 0) { |
| 5222 | Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " |
| 5223 | + mTempConfig + " for displayId=" + mDisplayId); |
| 5224 | onRequestedOverrideConfigurationChanged(mTempConfig); |
| 5225 | |
| 5226 | final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; |
| 5227 | if (isDensityChange && mDisplayId == DEFAULT_DISPLAY) { |
| 5228 | mAtmService.mAppWarnings.onDensityChanged(); |
| 5229 | |
| 5230 | // Post message to start process to avoid possible deadlock of calling into AMS with |
| 5231 | // the ATMS lock held. |
| 5232 | final Message msg = PooledLambda.obtainMessage( |
| 5233 | ActivityManagerInternal::killAllBackgroundProcessesExcept, |
| 5234 | mAtmService.mAmInternal, N, |
| 5235 | ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); |
| 5236 | mAtmService.mH.sendMessage(msg); |
| 5237 | } |
| 5238 | mWmService.mDisplayNotificationController.dispatchDisplayChanged( |
| 5239 | this, getConfiguration()); |
| 5240 | } |
| 5241 | return changes; |
| 5242 | } |
| 5243 | |
| 5244 | @Override |
| 5245 | public void onRequestedOverrideConfigurationChanged(Configuration overrideConfiguration) { |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 5246 | final Configuration currOverrideConfig = getRequestedOverrideConfiguration(); |
| 5247 | final int currRotation = currOverrideConfig.windowConfiguration.getRotation(); |
| 5248 | final int overrideRotation = overrideConfiguration.windowConfiguration.getRotation(); |
| 5249 | if (currRotation != ROTATION_UNDEFINED && currRotation != overrideRotation) { |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 5250 | applyRotationAndFinishFixedRotation(currRotation, overrideRotation); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5251 | } |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 5252 | mCurrentOverrideConfigurationChanges = currOverrideConfig.diff(overrideConfiguration); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5253 | super.onRequestedOverrideConfigurationChanged(overrideConfiguration); |
| 5254 | mCurrentOverrideConfigurationChanges = 0; |
| 5255 | mWmService.setNewDisplayOverrideConfiguration(overrideConfiguration, this); |
| 5256 | mAtmService.addWindowLayoutReasons( |
| 5257 | ActivityTaskManagerService.LAYOUT_REASON_CONFIG_CHANGED); |
| 5258 | } |
| 5259 | |
Riddle Hsu | fc246d1 | 2020-03-20 18:28:11 +0800 | [diff] [blame] | 5260 | /** |
| 5261 | * If the launching rotated activity ({@link #mFixedRotationLaunchingApp}) is null, it simply |
| 5262 | * applies the rotation to display. Otherwise because the activity has shown as rotated, the |
| 5263 | * fixed rotation transform also needs to be cleared to make sure the rotated activity fits |
| 5264 | * the display naturally. |
| 5265 | */ |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 5266 | private void applyRotationAndFinishFixedRotation(int oldRotation, int newRotation) { |
Riddle Hsu | 3691c1f | 2020-05-05 21:27:04 +0800 | [diff] [blame] | 5267 | final WindowToken rotatedLaunchingApp = mFixedRotationLaunchingApp; |
| 5268 | if (rotatedLaunchingApp == null) { |
Riddle Hsu | fc246d1 | 2020-03-20 18:28:11 +0800 | [diff] [blame] | 5269 | applyRotation(oldRotation, newRotation); |
| 5270 | return; |
| 5271 | } |
| 5272 | |
Riddle Hsu | 3691c1f | 2020-05-05 21:27:04 +0800 | [diff] [blame] | 5273 | rotatedLaunchingApp.finishFixedRotationTransform( |
Riddle Hsu | fc246d1 | 2020-03-20 18:28:11 +0800 | [diff] [blame] | 5274 | () -> applyRotation(oldRotation, newRotation)); |
| 5275 | mFixedRotationLaunchingApp = null; |
| 5276 | } |
| 5277 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5278 | /** Checks whether the given activity is in size compatibility mode and notifies the change. */ |
| 5279 | void handleActivitySizeCompatModeIfNeeded(ActivityRecord r) { |
| 5280 | if (!r.isState(RESUMED) || r.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 5281 | // The callback is only interested in the foreground changes of fullscreen activity. |
| 5282 | return; |
| 5283 | } |
| 5284 | if (!r.inSizeCompatMode()) { |
| 5285 | if (mLastCompatModeActivity != null) { |
| 5286 | mAtmService.getTaskChangeNotificationController() |
| 5287 | .notifySizeCompatModeActivityChanged(mDisplayId, null /* activityToken */); |
| 5288 | } |
| 5289 | mLastCompatModeActivity = null; |
| 5290 | return; |
| 5291 | } |
| 5292 | if (mLastCompatModeActivity == r) { |
| 5293 | return; |
| 5294 | } |
| 5295 | mLastCompatModeActivity = r; |
| 5296 | mAtmService.getTaskChangeNotificationController() |
| 5297 | .notifySizeCompatModeActivityChanged(mDisplayId, r.appToken); |
| 5298 | } |
| 5299 | |
| 5300 | boolean isUidPresent(int uid) { |
| 5301 | final PooledPredicate p = PooledLambda.obtainPredicate( |
| 5302 | ActivityRecord::isUid, PooledLambda.__(ActivityRecord.class), uid); |
| 5303 | final boolean isUidPresent = mDisplayContent.getActivity(p) != null; |
| 5304 | p.recycle(); |
| 5305 | return isUidPresent; |
| 5306 | } |
| 5307 | |
| 5308 | /** |
| 5309 | * @see #mRemoved |
| 5310 | */ |
| 5311 | boolean isRemoved() { |
| 5312 | return mRemoved; |
| 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * @see #mRemoving |
| 5317 | */ |
| 5318 | boolean isRemoving() { |
| 5319 | return mRemoving; |
| 5320 | } |
| 5321 | |
| 5322 | void remove() { |
| 5323 | mRemoving = true; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5324 | ActivityStack lastReparentedStack = null; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5325 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5326 | mRootWindowContainer.mStackSupervisor.beginDeferResume(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5327 | try { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5328 | int numTaskContainers = getTaskDisplayAreaCount(); |
| 5329 | for (int tdaNdx = 0; tdaNdx < numTaskContainers; tdaNdx++) { |
| 5330 | final ActivityStack lastReparentedStackFromArea = getTaskDisplayAreaAt(tdaNdx) |
| 5331 | .remove(); |
| 5332 | if (lastReparentedStackFromArea != null) { |
| 5333 | lastReparentedStack = lastReparentedStackFromArea; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5334 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5335 | } |
| 5336 | } finally { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5337 | mRootWindowContainer.mStackSupervisor.endDeferResume(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5338 | } |
| 5339 | mRemoved = true; |
| 5340 | |
| 5341 | // Only update focus/visibility for the last one because there may be many stacks are |
| 5342 | // reparented and the intermediate states are unnecessary. |
| 5343 | if (lastReparentedStack != null) { |
| 5344 | lastReparentedStack.postReparent(); |
| 5345 | } |
| 5346 | releaseSelfIfNeeded(); |
Mehdi Alizadeh | f2b28e9 | 2019-12-05 20:13:49 -0800 | [diff] [blame] | 5347 | mDisplayPolicy.release(); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5348 | |
| 5349 | if (!mAllSleepTokens.isEmpty()) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5350 | mRootWindowContainer.mSleepTokens.removeAll(mAllSleepTokens); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5351 | mAllSleepTokens.clear(); |
| 5352 | mAtmService.updateSleepIfNeededLocked(); |
| 5353 | } |
| 5354 | } |
| 5355 | |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 5356 | void releaseSelfIfNeeded() { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5357 | if (!mRemoved) { |
| 5358 | return; |
| 5359 | } |
| 5360 | |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5361 | // Check if all task display areas have only the empty home stacks left. |
| 5362 | boolean onlyEmptyHomeStacksLeft = true; |
| 5363 | for (int tdaNdx = getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 5364 | final TaskDisplayArea taskDisplayArea = getTaskDisplayAreaAt(tdaNdx); |
| 5365 | if (taskDisplayArea.getStackCount() != 1) { |
| 5366 | onlyEmptyHomeStacksLeft = false; |
| 5367 | break; |
| 5368 | } |
| 5369 | final ActivityStack stack = taskDisplayArea.getStackAt(0); |
| 5370 | if (!stack.isActivityTypeHome() || stack.hasChild()) { |
| 5371 | onlyEmptyHomeStacksLeft = false; |
| 5372 | break; |
| 5373 | } |
| 5374 | } |
| 5375 | if (onlyEmptyHomeStacksLeft) { |
| 5376 | // Release this display if only empty home stack(s) are left. This display will be |
| 5377 | // released along with the stack(s) removal. |
| 5378 | for (int tdaNdx = getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 5379 | final ActivityStack s = getTaskDisplayAreaAt(tdaNdx).getStackAt(0); |
| 5380 | s.removeIfPossible(); |
| 5381 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5382 | } else if (getTopStack() == null) { |
| 5383 | removeIfPossible(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5384 | mRootWindowContainer.mStackSupervisor |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5385 | .getKeyguardController().onDisplayRemoved(mDisplayId); |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | /** Update and get all UIDs that are present on the display and have access to it. */ |
| 5390 | IntArray getPresentUIDs() { |
| 5391 | mDisplayAccessUIDs.clear(); |
| 5392 | final PooledConsumer c = PooledLambda.obtainConsumer(DisplayContent::addActivityUid, |
| 5393 | PooledLambda.__(ActivityRecord.class), mDisplayAccessUIDs); |
| 5394 | mDisplayContent.forAllActivities(c); |
| 5395 | c.recycle(); |
| 5396 | return mDisplayAccessUIDs; |
| 5397 | } |
| 5398 | |
| 5399 | private static void addActivityUid(ActivityRecord r, IntArray uids) { |
| 5400 | uids.add(r.getUid()); |
| 5401 | } |
| 5402 | |
| 5403 | @VisibleForTesting |
| 5404 | boolean shouldDestroyContentOnRemove() { |
| 5405 | return mDisplay.getRemoveMode() == REMOVE_MODE_DESTROY_CONTENT; |
| 5406 | } |
| 5407 | |
| 5408 | boolean shouldSleep() { |
| 5409 | return (getStackCount() == 0 || !mAllSleepTokens.isEmpty()) |
| 5410 | && (mAtmService.mRunningVoice == null); |
| 5411 | } |
| 5412 | |
| 5413 | void setFocusedApp(ActivityRecord r, boolean moveFocusNow) { |
| 5414 | final ActivityRecord newFocus; |
| 5415 | final IBinder token = r.appToken; |
| 5416 | if (token == null) { |
| 5417 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "Clearing focused app, displayId=%d", |
| 5418 | mDisplayId); |
| 5419 | newFocus = null; |
| 5420 | } else { |
| 5421 | newFocus = mWmService.mRoot.getActivityRecord(token); |
| 5422 | if (newFocus == null) { |
| 5423 | Slog.w(TAG_WM, "Attempted to set focus to non-existing app token: " + token |
| 5424 | + ", displayId=" + mDisplayId); |
| 5425 | } |
| 5426 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 5427 | "Set focused app to: %s moveFocusNow=%b displayId=%d", newFocus, |
| 5428 | moveFocusNow, mDisplayId); |
| 5429 | } |
| 5430 | |
| 5431 | final boolean changed = setFocusedApp(newFocus); |
| 5432 | if (moveFocusNow && changed) { |
| 5433 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 5434 | true /*updateInputWindows*/); |
| 5435 | } |
| 5436 | } |
| 5437 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5438 | void ensureActivitiesVisible(ActivityRecord starting, int configChanges, |
| 5439 | boolean preserveWindows, boolean notifyClients) { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5440 | for (int i = getTaskDisplayAreaCount() - 1; i >= 0; --i) { |
| 5441 | getTaskDisplayAreaAt(i).ensureActivitiesVisible(starting, configChanges, |
| 5442 | preserveWindows, notifyClients); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5443 | } |
| 5444 | } |
| 5445 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5446 | boolean isSleeping() { |
| 5447 | return mSleeping; |
| 5448 | } |
| 5449 | |
| 5450 | void setIsSleeping(boolean asleep) { |
| 5451 | mSleeping = asleep; |
| 5452 | } |
| 5453 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5454 | void setDisplayToSingleTaskInstance() { |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5455 | final int taskDisplayAreaCount = getTaskDisplayAreaCount(); |
| 5456 | if (taskDisplayAreaCount > 1) { |
| 5457 | throw new IllegalArgumentException( |
| 5458 | "Display already has multiple task display areas. display=" + this); |
| 5459 | } |
| 5460 | final int stackCount = getDefaultTaskDisplayArea().getStackCount(); |
| 5461 | if (stackCount > 1) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5462 | throw new IllegalArgumentException("Display already has multiple stacks. display=" |
| 5463 | + this); |
| 5464 | } |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 5465 | if (stackCount > 0) { |
| 5466 | final ActivityStack stack = getDefaultTaskDisplayArea().getStackAt(0); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5467 | if (stack.getChildCount() > 1) { |
| 5468 | throw new IllegalArgumentException("Display stack already has multiple tasks." |
| 5469 | + " display=" + this + " stack=" + stack); |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | mSingleTaskInstance = true; |
| 5474 | } |
| 5475 | |
| 5476 | /** Returns true if the display can only contain one task */ |
| 5477 | boolean isSingleTaskInstance() { |
| 5478 | return mSingleTaskInstance; |
| 5479 | } |
| 5480 | |
| 5481 | @VisibleForTesting |
| 5482 | void removeAllTasks() { |
| 5483 | forAllTasks((t) -> { t.getStack().removeChild(t, "removeAllTasks"); }); |
| 5484 | } |
| 5485 | |
| 5486 | /** |
Charles Chen | 173ae78 | 2019-11-11 20:39:02 +0800 | [diff] [blame] | 5487 | * Similar to {@link RootWindowContainer#isAnyNonToastWindowVisibleForUid(int)}, but |
| 5488 | * used for pid. |
| 5489 | */ |
| 5490 | boolean isAnyNonToastWindowVisibleForPid(int pid) { |
| 5491 | final PooledPredicate p = PooledLambda.obtainPredicate( |
| 5492 | WindowState::isNonToastWindowVisibleForPid, |
| 5493 | PooledLambda.__(WindowState.class), pid); |
| 5494 | |
| 5495 | final WindowState w = getWindow(p); |
| 5496 | p.recycle(); |
| 5497 | return w != null; |
| 5498 | } |
| 5499 | |
| 5500 | Context getDisplayUiContext() { |
| 5501 | return mDisplayPolicy.getSystemUiContext(); |
| 5502 | } |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 5503 | |
chaviw | 945f730 | 2020-02-24 14:35:33 -0800 | [diff] [blame] | 5504 | Point getDisplayPosition() { |
| 5505 | return mWmService.mDisplayManagerInternal.getDisplayPosition(getDisplayId()); |
| 5506 | } |
| 5507 | |
Mark Renouf | a927929 | 2020-04-17 12:22:50 -0400 | [diff] [blame] | 5508 | /** |
| 5509 | * Locates the appropriate target window for scroll capture. The search progresses top to |
| 5510 | * bottom. |
| 5511 | * If {@code searchBehind} is non-null, the search will only consider windows behind this one. |
| 5512 | * If a valid taskId is specified, the target window must belong to the given task. |
| 5513 | * |
| 5514 | * @param searchBehind a window used to filter the search to windows behind it, or null to begin |
| 5515 | * the search at the top window of the display |
| 5516 | * @param taskId specifies the id of a task the result must belong to or |
| 5517 | * {@link android.app.ActivityTaskManager#INVALID_TASK_ID INVALID_TASK_ID} |
| 5518 | * to match any window |
| 5519 | * @return the located window or null if none could be found matching criteria |
| 5520 | */ |
| 5521 | @Nullable |
| 5522 | WindowState findScrollCaptureTargetWindow(@Nullable WindowState searchBehind, int taskId) { |
| 5523 | return getWindow(new Predicate<WindowState>() { |
| 5524 | boolean behindTopWindow = (searchBehind == null); // optional filter |
| 5525 | @Override |
| 5526 | public boolean test(WindowState nextWindow) { |
| 5527 | // Skip through all windows until we pass topWindow (if specified) |
| 5528 | if (!behindTopWindow) { |
| 5529 | if (nextWindow == searchBehind) { |
| 5530 | behindTopWindow = true; |
| 5531 | } |
| 5532 | return false; /* continue */ |
| 5533 | } |
| 5534 | if (taskId != INVALID_TASK_ID) { |
| 5535 | Task task = nextWindow.getTask(); |
| 5536 | if (task == null || !task.isTaskId(taskId)) { |
| 5537 | return false; /* continue */ |
| 5538 | } |
| 5539 | } |
| 5540 | if (!nextWindow.canReceiveKeys()) { |
| 5541 | return false; /* continue */ |
| 5542 | } |
| 5543 | return true; /* stop */ |
| 5544 | } |
| 5545 | }); |
| 5546 | } |
| 5547 | |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 5548 | /** The entry for proceeding to handle {@link #mFixedRotationLaunchingApp}. */ |
| 5549 | class FixedRotationTransitionListener extends WindowManagerInternal.AppTransitionListener { |
| 5550 | |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 5551 | /** |
| 5552 | * The animating activity which shows the recents task list. It is set between |
| 5553 | * {@link RecentsAnimationController#initialize} and |
Riddle Hsu | 70a920c | 2020-05-05 17:20:32 +0800 | [diff] [blame] | 5554 | * {@link RecentsAnimationController#cleanupAnimation}. |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 5555 | */ |
| 5556 | private ActivityRecord mAnimatingRecents; |
| 5557 | |
| 5558 | /** |
| 5559 | * If the recents activity has a fixed orientation which is different from the current top |
| 5560 | * activity, it will be rotated before being shown so we avoid a screen rotation animation |
| 5561 | * when showing the Recents view. |
| 5562 | */ |
| 5563 | void onStartRecentsAnimation(@NonNull ActivityRecord r) { |
| 5564 | mAnimatingRecents = r; |
| 5565 | rotateInDifferentOrientationIfNeeded(r); |
| 5566 | if (r.hasFixedRotationTransform()) { |
| 5567 | // Set the record so we can recognize it to continue to update display orientation |
| 5568 | // if the recents activity becomes the top later. |
| 5569 | setFixedRotationLaunchingApp(r, r.getWindowConfiguration().getRotation()); |
| 5570 | } |
| 5571 | } |
| 5572 | |
| 5573 | /** |
| 5574 | * If {@link #mAnimatingRecents} still has fixed rotation, it should be moved to top so we |
| 5575 | * don't clear {@link #mFixedRotationLaunchingApp} that will be handled by transition. |
| 5576 | */ |
Riddle Hsu | 70a920c | 2020-05-05 17:20:32 +0800 | [diff] [blame] | 5577 | void onFinishRecentsAnimation(boolean moveRecentsToBack) { |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 5578 | final ActivityRecord animatingRecents = mAnimatingRecents; |
| 5579 | mAnimatingRecents = null; |
Riddle Hsu | 70a920c | 2020-05-05 17:20:32 +0800 | [diff] [blame] | 5580 | if (!moveRecentsToBack) { |
| 5581 | // The recents activity will be the top, such as staying at recents list or |
| 5582 | // returning to home (if home and recents are the same activity). |
| 5583 | return; |
| 5584 | } |
| 5585 | |
| 5586 | if (animatingRecents != null && animatingRecents == mFixedRotationLaunchingApp) { |
| 5587 | // Because it won't affect display orientation, just finish the transform. |
| 5588 | animatingRecents.finishFixedRotationTransform(); |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 5589 | mFixedRotationLaunchingApp = null; |
Riddle Hsu | 70a920c | 2020-05-05 17:20:32 +0800 | [diff] [blame] | 5590 | } else { |
| 5591 | // If there is already a launching activity that is not the recents, before its |
| 5592 | // transition is completed, the recents animation may be started. So if the recents |
| 5593 | // activity won't be the top, the display orientation should be updated according |
| 5594 | // to the current top activity. |
| 5595 | continueUpdateOrientationForDiffOrienLaunchingApp(); |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 5596 | } |
| 5597 | } |
| 5598 | |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 5599 | @Override |
| 5600 | public void onAppTransitionFinishedLocked(IBinder token) { |
| 5601 | final ActivityRecord r = getActivityRecord(token); |
Riddle Hsu | cbc5d27 | 2020-04-24 23:26:46 +0800 | [diff] [blame] | 5602 | // Ignore the animating recents so the fixed rotation transform won't be switched twice |
| 5603 | // by finishing the recents animation and moving it to top. That also avoids flickering |
| 5604 | // due to wait for previous activity to be paused if it supports PiP that ignores the |
| 5605 | // effect of resume-while-pausing. |
| 5606 | if (r == null || r == mAnimatingRecents) { |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 5607 | return; |
| 5608 | } |
| 5609 | if (mFixedRotationLaunchingApp != null |
| 5610 | && mFixedRotationLaunchingApp.hasFixedRotationTransform(r)) { |
| 5611 | continueUpdateOrientationForDiffOrienLaunchingApp(); |
| 5612 | } else { |
| 5613 | r.finishFixedRotationTransform(); |
| 5614 | } |
| 5615 | } |
| 5616 | |
| 5617 | @Override |
| 5618 | public void onAppTransitionCancelledLocked(int transit) { |
| 5619 | continueUpdateOrientationForDiffOrienLaunchingApp(); |
| 5620 | } |
| 5621 | |
| 5622 | @Override |
| 5623 | public void onAppTransitionTimeoutLocked() { |
| 5624 | continueUpdateOrientationForDiffOrienLaunchingApp(); |
| 5625 | } |
| 5626 | } |
| 5627 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 5628 | class RemoteInsetsControlTarget implements InsetsControlTarget { |
| 5629 | private final IDisplayWindowInsetsController mRemoteInsetsController; |
| 5630 | |
| 5631 | RemoteInsetsControlTarget(IDisplayWindowInsetsController controller) { |
| 5632 | mRemoteInsetsController = controller; |
| 5633 | } |
| 5634 | |
| 5635 | void notifyInsetsChanged() { |
| 5636 | try { |
| 5637 | mRemoteInsetsController.insetsChanged( |
| 5638 | getInsetsStateController().getRawInsetsState()); |
| 5639 | } catch (RemoteException e) { |
| 5640 | Slog.w(TAG, "Failed to deliver inset state change", e); |
| 5641 | } |
| 5642 | } |
| 5643 | |
| 5644 | @Override |
| 5645 | public void notifyInsetsControlChanged() { |
| 5646 | final InsetsStateController stateController = getInsetsStateController(); |
| 5647 | try { |
| 5648 | mRemoteInsetsController.insetsControlChanged(stateController.getRawInsetsState(), |
| 5649 | stateController.getControlsForDispatch(this)); |
| 5650 | } catch (RemoteException e) { |
| 5651 | Slog.w(TAG, "Failed to deliver inset state change", e); |
| 5652 | } |
| 5653 | } |
| 5654 | |
| 5655 | @Override |
| 5656 | public void showInsets(@WindowInsets.Type.InsetsType int types, boolean fromIme) { |
| 5657 | try { |
| 5658 | mRemoteInsetsController.showInsets(types, fromIme); |
| 5659 | } catch (RemoteException e) { |
| 5660 | Slog.w(TAG, "Failed to deliver showInsets", e); |
| 5661 | } |
| 5662 | } |
| 5663 | |
| 5664 | @Override |
| 5665 | public void hideInsets(@WindowInsets.Type.InsetsType int types, boolean fromIme) { |
| 5666 | try { |
| 5667 | mRemoteInsetsController.hideInsets(types, fromIme); |
| 5668 | } catch (RemoteException e) { |
| 5669 | Slog.w(TAG, "Failed to deliver showInsets", e); |
| 5670 | } |
| 5671 | } |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 5672 | |
| 5673 | @Override |
| 5674 | public boolean isClientControlled() { |
| 5675 | return false; |
| 5676 | } |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 5677 | } |
Charles Chen | 2622d3e | 2020-04-15 14:28:13 +0800 | [diff] [blame] | 5678 | |
| 5679 | /** |
| 5680 | * Returns the number of window tokens without surface on this display. A {@link WindowToken} |
| 5681 | * won't have its {@link SurfaceControl} until a window is added to a {@link WindowToken}. |
| 5682 | * The purpose of this method is to accumulate non-window containing {@link WindowToken}s and |
| 5683 | * limit the usage if the count exceeds a number. |
| 5684 | * |
| 5685 | * @param callingUid app calling uid |
| 5686 | * @return the number of window tokens without surface on this display |
| 5687 | * @see WindowToken#addWindow(WindowState) |
| 5688 | */ |
| 5689 | int getWindowTokensWithoutSurfaceCount(int callingUid) { |
| 5690 | List<WindowToken> tokens = new ArrayList<>(mTokenMap.values()); |
| 5691 | int count = 0; |
| 5692 | for (int i = tokens.size() - 1; i >= 0; i--) { |
| 5693 | final WindowToken token = tokens.get(i); |
| 5694 | if (callingUid != token.getOwnerUid()) { |
| 5695 | continue; |
| 5696 | } |
| 5697 | // Skip if token is an Activity |
| 5698 | if (token.asActivityRecord() != null) { |
| 5699 | continue; |
| 5700 | } |
| 5701 | if (token.mSurfaceControl != null) { |
| 5702 | continue; |
| 5703 | } |
| 5704 | count++; |
| 5705 | } |
| 5706 | return count; |
| 5707 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5708 | } |