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 | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | a77e146 | 2016-09-28 10:09:46 -0700 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 27 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 28 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 29 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 30 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 31 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 32 | import static android.util.DisplayMetrics.DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 33 | import static android.view.Display.DEFAULT_DISPLAY; |
| 34 | import static android.view.Display.FLAG_PRIVATE; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 35 | import static android.view.Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 36 | import static android.view.Display.INVALID_DISPLAY; |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 37 | import static android.view.InsetsState.TYPE_IME; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 38 | import static android.view.InsetsState.TYPE_LEFT_GESTURES; |
| 39 | import static android.view.InsetsState.TYPE_RIGHT_GESTURES; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 40 | import static android.view.Surface.ROTATION_0; |
| 41 | import static android.view.Surface.ROTATION_180; |
| 42 | import static android.view.Surface.ROTATION_270; |
| 43 | import static android.view.Surface.ROTATION_90; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 44 | import static android.view.View.GONE; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 45 | import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 46 | import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 47 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 48 | import static android.view.WindowManager.DOCKED_INVALID; |
| 49 | import static android.view.WindowManager.DOCKED_TOP; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 50 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 51 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 52 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 53 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 54 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 55 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 56 | import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 57 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 58 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE; |
| 59 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 60 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
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; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 64 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 65 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 66 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 67 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 68 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 69 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 71 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 72 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 73 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 74 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 75 | import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 76 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 77 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 78 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 79 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 80 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 81 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 82 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 83 | import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 84 | import static com.android.server.wm.DisplayContentProto.APP_TRANSITION; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 85 | import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 86 | import static com.android.server.wm.DisplayContentProto.CHANGING_APPS; |
| 87 | import static com.android.server.wm.DisplayContentProto.CLOSING_APPS; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 88 | import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES; |
| 89 | import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO; |
| 90 | import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER; |
| 91 | import static com.android.server.wm.DisplayContentProto.DPI; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 92 | import static com.android.server.wm.DisplayContentProto.FOCUSED_APP; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 93 | import static com.android.server.wm.DisplayContentProto.ID; |
| 94 | import static com.android.server.wm.DisplayContentProto.IME_WINDOWS; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 95 | import static com.android.server.wm.DisplayContentProto.OPENING_APPS; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 96 | import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER; |
| 97 | import static com.android.server.wm.DisplayContentProto.ROTATION; |
| 98 | import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION; |
| 99 | import static com.android.server.wm.DisplayContentProto.STACKS; |
| 100 | import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 101 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; |
| 102 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
| 103 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS; |
| 104 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; |
| 105 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; |
| 106 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_SCREEN_ON; |
| 107 | import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 108 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 109 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 110 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 111 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 112 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 113 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 114 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 115 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 116 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 117 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 118 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 119 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 120 | import static com.android.server.wm.WindowManagerService.H.REPORT_FOCUS_CHANGE; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 121 | 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] | 122 | import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 123 | import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 124 | import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 125 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 126 | import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 127 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
| 128 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS; |
| 129 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 130 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 131 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 132 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 133 | import static com.android.server.wm.WindowState.EXCLUSION_LEFT; |
| 134 | import static com.android.server.wm.WindowState.EXCLUSION_RIGHT; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 135 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 136 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 137 | import static com.android.server.wm.utils.RegionUtils.forEachRectReverse; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 138 | import static com.android.server.wm.utils.RegionUtils.rectListToRegion; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 139 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 140 | import android.animation.AnimationHandler; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 141 | import android.annotation.CallSuper; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 142 | import android.annotation.IntDef; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 143 | import android.annotation.NonNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 144 | import android.annotation.Nullable; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 145 | import android.content.pm.ActivityInfo.ScreenOrientation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 146 | import android.content.res.CompatibilityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 147 | import android.content.res.Configuration; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 148 | import android.graphics.Bitmap; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 149 | import android.graphics.Insets; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 150 | import android.graphics.Matrix; |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 151 | import android.graphics.Point; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 152 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 153 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 154 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 155 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 156 | import android.hardware.display.DisplayManagerInternal; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 157 | import android.metrics.LogMaker; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 158 | import android.os.Binder; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 159 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 160 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 161 | import android.os.IBinder; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 162 | import android.os.Process; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 163 | import android.os.RemoteCallbackList; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 164 | import android.os.RemoteException; |
| 165 | import android.os.SystemClock; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 166 | import android.os.Trace; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 167 | import android.os.UserHandle; |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 168 | import android.util.ArraySet; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 169 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 170 | import android.util.Slog; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 171 | import android.util.SparseBooleanArray; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 172 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 173 | import android.view.Display; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 174 | import android.view.DisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 175 | import android.view.DisplayInfo; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 176 | import android.view.Gravity; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 177 | import android.view.ISystemGestureExclusionListener; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 178 | import android.view.InputChannel; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 179 | import android.view.InputDevice; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 180 | import android.view.InputWindowHandle; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 181 | import android.view.InsetsState.InternalInsetType; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 182 | import android.view.MagnificationSpec; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 183 | import android.view.RemoteAnimationDefinition; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 184 | import android.view.Surface; |
| 185 | import android.view.SurfaceControl; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 186 | import android.view.SurfaceControl.Transaction; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 187 | import android.view.SurfaceSession; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 188 | import android.view.View; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 189 | import android.view.WindowManager; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 190 | import android.view.WindowManagerPolicyConstants.PointerEventListener; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 191 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 192 | import com.android.internal.annotations.VisibleForTesting; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 193 | import com.android.internal.logging.MetricsLogger; |
| 194 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 195 | import com.android.internal.util.ToBooleanFunction; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 196 | import com.android.internal.util.function.TriConsumer; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 197 | import com.android.internal.util.function.pooled.PooledConsumer; |
| 198 | import com.android.internal.util.function.pooled.PooledLambda; |
Winson Chung | 6ba767a | 2018-12-13 18:20:11 -0800 | [diff] [blame] | 199 | import com.android.server.AnimationThread; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 200 | import com.android.server.policy.WindowManagerPolicy; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 201 | import com.android.server.protolog.common.ProtoLog; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 202 | import com.android.server.wm.utils.DisplayRotationUtil; |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 203 | import com.android.server.wm.utils.RotationCache; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 204 | import com.android.server.wm.utils.WmDisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 205 | |
| 206 | import java.io.PrintWriter; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 207 | import java.lang.annotation.Retention; |
| 208 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 209 | import java.util.ArrayList; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 210 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 211 | import java.util.HashMap; |
| 212 | import java.util.Iterator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 213 | import java.util.LinkedList; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 214 | import java.util.List; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 215 | import java.util.Objects; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 216 | import java.util.function.Consumer; |
| 217 | import java.util.function.Predicate; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 218 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 219 | /** |
| 220 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 221 | * particular Display. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 222 | */ |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 223 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> |
Riddle Hsu | 6b76cd3 | 2019-10-08 00:37:19 +0800 | [diff] [blame] | 224 | implements WindowManagerPolicy.DisplayContentInfo, ConfigurationContainerListener { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 225 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 226 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 227 | /** The default scaling mode that scales content automatically. */ |
| 228 | static final int FORCE_SCALING_MODE_AUTO = 0; |
| 229 | /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */ |
| 230 | static final int FORCE_SCALING_MODE_DISABLED = 1; |
| 231 | |
| 232 | @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = { |
| 233 | FORCE_SCALING_MODE_AUTO, |
| 234 | FORCE_SCALING_MODE_DISABLED |
| 235 | }) |
| 236 | @Retention(RetentionPolicy.SOURCE) |
| 237 | @interface ForceScalingMode {} |
| 238 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 239 | /** Unique identifier of this stack. */ |
| 240 | private final int mDisplayId; |
| 241 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 242 | // TODO: Remove once unification is complete. |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 243 | ActivityDisplay mActivityDisplay; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 244 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 245 | /** The containers below are the only child containers the display can have. */ |
| 246 | // Contains all window containers that are related to apps (Activities) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 247 | private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 248 | // Contains all non-app window containers that should be displayed above the app containers |
| 249 | // (e.g. Status bar) |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 250 | private final AboveAppWindowContainers mAboveAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 251 | new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 252 | // Contains all non-app window containers that should be displayed below the app containers |
| 253 | // (e.g. Wallpaper). |
| 254 | private final NonAppWindowContainers mBelowAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 255 | new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 256 | // Contains all IME window containers. Note that the z-ordering of the IME windows will depend |
| 257 | // 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] | 258 | // window containers together and move them in-sync if/when needed. We use a subclass of |
| 259 | // WindowContainer which is omitted from screen magnification, as the IME is never magnified. |
Eugene Susla | 25a2495 | 2019-04-08 13:57:44 -0700 | [diff] [blame] | 260 | private final NonAppWindowContainers mImeWindowsContainers = |
| 261 | new NonAppWindowContainers("mImeWindowsContainers", mWmService); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 262 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 263 | private WindowState mTmpWindow; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 264 | private WindowState mTmpWindow2; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 265 | private boolean mTmpRecoveringMemory; |
| 266 | private boolean mUpdateImeTarget; |
| 267 | private boolean mTmpInitial; |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 268 | private int mMaxUiWidth; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 269 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 270 | final AppTransition mAppTransition; |
| 271 | final AppTransitionController mAppTransitionController; |
| 272 | boolean mSkipAppTransitionAnimation = false; |
| 273 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 274 | final ArraySet<ActivityRecord> mOpeningApps = new ArraySet<>(); |
| 275 | final ArraySet<ActivityRecord> mClosingApps = new ArraySet<>(); |
| 276 | final ArraySet<ActivityRecord> mChangingApps = new ArraySet<>(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 277 | final UnknownAppVisibilityController mUnknownAppVisibilityController; |
| 278 | BoundsAnimationController mBoundsAnimationController; |
| 279 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 280 | private MetricsLogger mMetricsLogger; |
| 281 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 282 | /** |
| 283 | * List of clients without a transtiton animation that we notify once we are done |
| 284 | * transitioning since they won't be notified through the app window animator. |
| 285 | */ |
| 286 | final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>(); |
| 287 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 288 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 289 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 290 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 291 | // Initial display metrics. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 292 | int mInitialDisplayWidth = 0; |
| 293 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 294 | int mInitialDisplayDensity = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 295 | |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 296 | DisplayCutout mInitialDisplayCutout; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 297 | private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 298 | = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 299 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 300 | /** |
| 301 | * Overridden display size. Initialized with {@link #mInitialDisplayWidth} |
| 302 | * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size". |
| 303 | * @see WindowManagerService#setForcedDisplaySize(int, int, int) |
| 304 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 305 | int mBaseDisplayWidth = 0; |
| 306 | int mBaseDisplayHeight = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 307 | /** |
| 308 | * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity} |
| 309 | * but can be set from Settings or via shell command "adb shell wm density". |
| 310 | * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int) |
| 311 | */ |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 312 | int mBaseDisplayDensity = 0; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 313 | |
| 314 | /** |
| 315 | * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling". |
| 316 | * @see WindowManagerService#setForcedDisplayScalingMode(int, int) |
| 317 | */ |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 318 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 319 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 320 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 321 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 322 | private final DisplayPolicy mDisplayPolicy; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 323 | private final DisplayRotation mDisplayRotation; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 324 | DisplayFrames mDisplayFrames; |
| 325 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 326 | private final RemoteCallbackList<ISystemGestureExclusionListener> |
| 327 | mSystemGestureExclusionListeners = new RemoteCallbackList<>(); |
| 328 | private final Region mSystemGestureExclusion = new Region(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 329 | private boolean mSystemGestureExclusionWasRestricted = false; |
| 330 | private final Region mSystemGestureExclusionUnrestricted = new Region(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 331 | private int mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 332 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 333 | /** |
| 334 | * For default display it contains real metrics, empty for others. |
chaviw | 619da69 | 2019-06-10 15:39:40 -0700 | [diff] [blame] | 335 | * @see WindowManagerService#createWatermark() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 336 | */ |
| 337 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 338 | |
| 339 | /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */ |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 340 | private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 341 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 342 | /** |
| 343 | * Compat metrics computed based on {@link #mDisplayMetrics}. |
| 344 | * @see #updateDisplayAndOrientation(int) |
| 345 | */ |
| 346 | private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 347 | |
| 348 | /** The desired scaling factor for compatible apps. */ |
| 349 | float mCompatibleScreenScale; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 350 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 351 | /** |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 352 | * Orientation forced by some window. If there is no visible window that specifies orientation |
| 353 | * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}. |
| 354 | * |
| 355 | * @see NonAppWindowContainers#getOrientation() |
| 356 | */ |
| 357 | private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 358 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 359 | /** |
| 360 | * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not |
| 361 | * occluded. |
| 362 | * |
| 363 | * @see NonAppWindowContainers#getOrientation() |
| 364 | */ |
| 365 | private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 366 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 367 | /** |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 368 | * The maximum aspect ratio (longerSide/shorterSide) that is treated as close-to-square. The |
| 369 | * orientation requests from apps would be ignored if the display is close-to-square. |
| 370 | */ |
| 371 | @VisibleForTesting |
| 372 | final float mCloseToSquareMaxAspectRatio; |
| 373 | |
| 374 | /** |
| 375 | * If this is true, we would not rotate the display for apps. The rotation would be either the |
| 376 | * sensor rotation or the user rotation, controlled by |
| 377 | * {@link WindowManagerPolicy.UserRotationMode}. |
| 378 | */ |
| 379 | private boolean mIgnoreRotationForApps; |
| 380 | |
| 381 | /** |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 382 | * Keep track of wallpaper visibility to notify changes. |
| 383 | */ |
| 384 | private boolean mLastWallpaperVisible = false; |
| 385 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 386 | private Rect mBaseDisplayRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 387 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 388 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 389 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 390 | int pendingLayoutChanges; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 391 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 392 | /** |
| 393 | * Used to gate application window layout until we have sent the complete configuration. |
| 394 | * TODO: There are still scenarios where we may be out of sync with the client. Ideally |
| 395 | * we want to replace this flag with a mechanism that will confirm the configuration |
| 396 | * applied by the client is the one expected by the system server. |
| 397 | */ |
| 398 | boolean mWaitingForConfig; |
| 399 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 400 | // TODO(multi-display): remove some of the usages. |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 401 | @VisibleForTesting |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 402 | boolean isDefaultDisplay; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 403 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 404 | /** |
| 405 | * Flag indicating whether WindowManager should override info for this display in |
| 406 | * DisplayManager. |
| 407 | */ |
| 408 | boolean mShouldOverrideDisplayConfiguration = true; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 409 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 410 | /** 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] | 411 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 412 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 413 | /** Detect user tapping outside of current focused task bounds .*/ |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 414 | @VisibleForTesting |
| 415 | final TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 416 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 417 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 418 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 419 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 420 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 421 | private final Rect mTmpRect = new Rect(); |
| 422 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 423 | private final RectF mTmpRectF = new RectF(); |
| 424 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 425 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 426 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 427 | /** Used for handing back size of display */ |
| 428 | private final Rect mTmpBounds = new Rect(); |
| 429 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 430 | private final Configuration mTmpConfiguration = new Configuration(); |
| 431 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 432 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 433 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 434 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 435 | final DockedStackDividerController mDividerControllerLocked; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 436 | final PinnedStackController mPinnedStackControllerLocked; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 437 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 438 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 439 | /** A collection of windows that provide tap exclude regions inside of them. */ |
| 440 | final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>(); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 441 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 442 | private final LinkedList<ActivityRecord> mTmpUpdateAllDrawn = new LinkedList(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 443 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 444 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 445 | new TaskForResizePointSearchResult(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 446 | private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState = |
| 447 | new ApplySurfaceChangesTransactionState(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 448 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 449 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 450 | // the display's direct children should be allowed. |
| 451 | private boolean mRemovingDisplay = false; |
| 452 | |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 453 | // {@code false} if this display is in the processing of being created. |
| 454 | private boolean mDisplayReady = false; |
| 455 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 456 | WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 457 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 458 | boolean mWallpaperMayChange = false; |
| 459 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 460 | private final SurfaceSession mSession = new SurfaceSession(); |
| 461 | |
| 462 | /** |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 463 | * Window that is currently interacting with the user. This window is responsible for receiving |
| 464 | * key events and pointer events from the user. |
| 465 | */ |
| 466 | WindowState mCurrentFocus = null; |
| 467 | |
| 468 | /** |
| 469 | * The last focused window that we've notified the client that the focus is changed. |
| 470 | */ |
| 471 | WindowState mLastFocus = null; |
| 472 | |
| 473 | /** |
| 474 | * Windows that have lost input focus and are waiting for the new focus window to be displayed |
| 475 | * before they are told about this. |
| 476 | */ |
| 477 | ArrayList<WindowState> mLosingFocus = new ArrayList<>(); |
| 478 | |
| 479 | /** |
| 480 | * The foreground app of this display. Windows below this app cannot be the focused window. If |
| 481 | * the user taps on the area outside of the task of the focused app, we will notify AM about the |
| 482 | * new task the user wants to interact with. |
| 483 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 484 | ActivityRecord mFocusedApp = null; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 485 | |
| 486 | /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 487 | final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>(); |
| 488 | |
| 489 | /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 490 | final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>(); |
| 491 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 492 | private ScreenRotationAnimation mScreenRotationAnimation; |
| 493 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 494 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 495 | * We organize all top-level Surfaces in to the following layers. |
| 496 | * mOverlayLayer contains a few Surfaces which are always on top of others |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 497 | * and omitted from Screen-Magnification, for example the strict mode flash or |
| 498 | * the magnification overlay itself. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 499 | * {@link #mWindowingLayer} contains everything else. |
| 500 | */ |
| 501 | private SurfaceControl mOverlayLayer; |
| 502 | |
| 503 | /** |
| 504 | * See {@link #mOverlayLayer} |
| 505 | */ |
| 506 | private SurfaceControl mWindowingLayer; |
| 507 | |
| 508 | /** |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 509 | * Sequence number for the current layout pass. |
| 510 | */ |
| 511 | int mLayoutSeq = 0; |
| 512 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 513 | /** |
| 514 | * Specifies the count to determine whether to defer updating the IME target until ready. |
| 515 | */ |
| 516 | private int mDeferUpdateImeTargetCount; |
| 517 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 518 | private MagnificationSpec mMagnificationSpec; |
| 519 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 520 | private InputMonitor mInputMonitor; |
| 521 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 522 | /** Caches the value whether told display manager that we have content. */ |
| 523 | private boolean mLastHasContent; |
| 524 | |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 525 | private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil(); |
| 526 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 527 | /** |
| 528 | * The input method window for this display. |
| 529 | */ |
| 530 | WindowState mInputMethodWindow; |
| 531 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 532 | /** |
| 533 | * This just indicates the window the input method is on top of, not |
| 534 | * necessarily the window its input is going to. |
| 535 | */ |
| 536 | WindowState mInputMethodTarget; |
| 537 | |
| 538 | /** If true hold off on modifying the animation layer of mInputMethodTarget */ |
| 539 | boolean mInputMethodTargetWaitingAnim; |
| 540 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 541 | private final PointerEventDispatcher mPointerEventDispatcher; |
| 542 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 543 | private final InsetsStateController mInsetsStateController; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 544 | private final InsetsPolicy mInsetsPolicy; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 545 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 546 | /** @see #getParentWindow() */ |
| 547 | private WindowState mParentWindow; |
| 548 | |
| 549 | private Point mLocationInParentWindow = new Point(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 550 | private SurfaceControl mParentSurfaceControl; |
| 551 | private InputWindowHandle mPortalWindowHandle; |
| 552 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 553 | // Last systemUiVisibility we received from status bar. |
| 554 | private int mLastStatusBarVisibility = 0; |
| 555 | // Last systemUiVisibility we dispatched to windows. |
| 556 | private int mLastDispatchedSystemUiVisibility = 0; |
| 557 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 558 | private final ArrayList<ActivityStack> mTmpAlwaysOnTopStacks = new ArrayList<>(); |
| 559 | private final ArrayList<ActivityStack> mTmpNormalStacks = new ArrayList<>(); |
| 560 | private final ArrayList<ActivityStack> mTmpHomeStacks = new ArrayList<>(); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 561 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 562 | /** Corner radius that windows should have in order to match the display. */ |
| 563 | private final float mWindowCornerRadius; |
| 564 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 565 | private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> { |
| 566 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 567 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 568 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 569 | if (activity == null || activity.canShowWindows()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 570 | if (w.performShowLocked()) { |
| 571 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 572 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 573 | mWmService.mWindowPlacerLocked.debugLayoutRepeats( |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 574 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 579 | }; |
| 580 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 581 | private final Consumer<WindowState> mScheduleToastTimeout = w -> { |
| 582 | final int lostFocusUid = mTmpWindow.mOwnerUid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 583 | final Handler handler = mWmService.mH; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 584 | if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) { |
| 585 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) { |
| 586 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), |
| 587 | w.mAttrs.hideTimeoutMilliseconds); |
| 588 | } |
| 589 | } |
| 590 | }; |
| 591 | |
| 592 | private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 593 | final ActivityRecord focusedApp = mFocusedApp; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 594 | ProtoLog.v(WM_DEBUG_FOCUS, "Looking for focus: %s, flags=%d, canReceive=%b", |
| 595 | w, w.mAttrs.flags, w.canReceiveKeys()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 596 | |
| 597 | if (!w.canReceiveKeys()) { |
| 598 | return false; |
| 599 | } |
| 600 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 601 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 602 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 603 | if (focusedApp == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 604 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 605 | "findFocusedWindow: focusedApp=null using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 606 | mTmpWindow = w; |
| 607 | return true; |
| 608 | } |
| 609 | |
| 610 | if (!focusedApp.windowsAreFocusable()) { |
| 611 | // Current focused app windows aren't focusable... |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 612 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: focusedApp windows not" |
| 613 | + " focusable using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 614 | mTmpWindow = w; |
| 615 | return true; |
| 616 | } |
| 617 | |
| 618 | // 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] | 619 | // win.mActivityRecord (return win) or mFocusedApp (return null). |
| 620 | if (activity != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 621 | if (focusedApp.compareTo(activity) > 0) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 622 | // App stack below focused app stack. No focus for you!!! |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 623 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 624 | "findFocusedWindow: Reached focused app=%s", focusedApp); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 625 | mTmpWindow = null; |
| 626 | return true; |
| 627 | } |
| 628 | } |
| 629 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 630 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: Found new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 631 | mTmpWindow = w; |
| 632 | return true; |
| 633 | }; |
| 634 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 635 | private final Consumer<WindowState> mPerformLayout = w -> { |
| 636 | // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid |
| 637 | // wasting time and funky changes while a window is animating away. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 638 | final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 639 | || w.isGoneForLayoutLw(); |
| 640 | |
| 641 | if (DEBUG_LAYOUT && !w.mLayoutAttached) { |
| 642 | Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame |
| 643 | + " mLayoutAttached=" + w.mLayoutAttached |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 644 | + " config reported=" + w.isLastConfigReportedToClient()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 645 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 646 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 647 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 648 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 649 | + " parentHidden=" + w.isParentWindowHidden()); |
| 650 | else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 651 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 652 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 653 | + " parentHidden=" + w.isParentWindowHidden()); |
| 654 | } |
| 655 | |
| 656 | // If this view is GONE, then skip it -- keep the current frame, and let the caller know |
| 657 | // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows, |
| 658 | // since that means "perform layout as normal, just don't display"). |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 659 | if ((!gone || !w.mHaveFrame || w.mLayoutNeeded) && !w.mLayoutAttached) { |
| 660 | if (mTmpInitial) { |
| 661 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 662 | } |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 663 | if (w.mAttrs.type == TYPE_DREAM) { |
| 664 | // Don't layout windows behind a dream, so that if it does stuff like hide |
| 665 | // the status bar we won't get a bad transition when it goes away. |
| 666 | mTmpWindow = w; |
| 667 | } |
| 668 | w.mLayoutNeeded = false; |
| 669 | w.prelayout(); |
| 670 | final boolean firstLayout = !w.isLaidOut(); |
| 671 | getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames); |
| 672 | w.mLayoutSeq = mLayoutSeq; |
| 673 | |
| 674 | // If this is the first layout, we need to initialize the last inset values as |
| 675 | // otherwise we'd immediately cause an unnecessary resize. |
| 676 | if (firstLayout) { |
| 677 | w.updateLastInsetValues(); |
| 678 | } |
| 679 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 680 | if (w.mActivityRecord != null) { |
| 681 | w.mActivityRecord.layoutLetterbox(w); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
| 685 | + " mContainingFrame=" + w.getContainingFrame() |
| 686 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 687 | } |
| 688 | }; |
| 689 | |
| 690 | private final Consumer<WindowState> mPerformLayoutAttached = w -> { |
| 691 | if (w.mLayoutAttached) { |
| 692 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame |
| 693 | + " mViewVisibility=" + w.mViewVisibility |
| 694 | + " mRelayoutCalled=" + w.mRelayoutCalled); |
| 695 | // If this view is GONE, then skip it -- keep the current frame, and let the caller |
| 696 | // know so they can ignore it if they want. (We do the normal layout for INVISIBLE |
| 697 | // windows, since that means "perform layout as normal, just don't display"). |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 698 | if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame |
| 702 | || w.mLayoutNeeded) { |
| 703 | if (mTmpInitial) { |
| 704 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 705 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 706 | } |
| 707 | w.mLayoutNeeded = false; |
| 708 | w.prelayout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 709 | getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 710 | w.mLayoutSeq = mLayoutSeq; |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 711 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 712 | + " mContainingFrame=" + w.getContainingFrame() |
| 713 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 714 | } |
| 715 | } else if (w.mAttrs.type == TYPE_DREAM) { |
| 716 | // Don't layout windows behind a dream, so that if it does stuff like hide the |
| 717 | // status bar we won't get a bad transition when it goes away. |
| 718 | mTmpWindow = mTmpWindow2; |
| 719 | } |
| 720 | }; |
| 721 | |
| 722 | private final Predicate<WindowState> mComputeImeTargetPredicate = w -> { |
| 723 | if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w |
| 724 | + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| 725 | return w.canBeImeTarget(); |
| 726 | }; |
| 727 | |
| 728 | private final Consumer<WindowState> mApplyPostLayoutPolicy = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 729 | w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 730 | mInputMethodTarget); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 731 | |
| 732 | private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 733 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 734 | final boolean obscuredChanged = w.mObscured != |
| 735 | mTmpApplySurfaceChangesTransactionState.obscured; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 736 | final RootWindowContainer root = mWmService.mRoot; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 737 | |
| 738 | // Update effect. |
| 739 | w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured; |
| 740 | if (!mTmpApplySurfaceChangesTransactionState.obscured) { |
| 741 | final boolean isDisplayed = w.isDisplayedLw(); |
| 742 | |
| 743 | if (isDisplayed && w.isObscuringDisplay()) { |
| 744 | // This window completely covers everything behind it, so we want to leave all |
| 745 | // of them as undimmed (for performance reasons). |
| 746 | root.mObscuringWindow = w; |
| 747 | mTmpApplySurfaceChangesTransactionState.obscured = true; |
| 748 | } |
| 749 | |
Arthur Hung | fbc8f41 | 2019-08-01 19:57:54 +0800 | [diff] [blame] | 750 | final boolean displayHasContent = root.handleNotObscuredLocked(w, |
| 751 | mTmpApplySurfaceChangesTransactionState.obscured, |
| 752 | mTmpApplySurfaceChangesTransactionState.syswin); |
| 753 | |
| 754 | if (!mTmpApplySurfaceChangesTransactionState.displayHasContent |
| 755 | && !getDisplayPolicy().isWindowExcludedFromContent(w)) { |
| 756 | mTmpApplySurfaceChangesTransactionState.displayHasContent |= displayHasContent; |
| 757 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 758 | |
| 759 | if (w.mHasSurface && isDisplayed) { |
| 760 | final int type = w.mAttrs.type; |
| 761 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
| 762 | || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 763 | mTmpApplySurfaceChangesTransactionState.syswin = true; |
| 764 | } |
| 765 | if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0 |
| 766 | && w.mAttrs.preferredRefreshRate != 0) { |
| 767 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate |
| 768 | = w.mAttrs.preferredRefreshRate; |
| 769 | } |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 770 | final int preferredModeId = getDisplayPolicy().getRefreshRatePolicy() |
| 771 | .getPreferredModeId(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 772 | if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0 |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 773 | && preferredModeId != 0) { |
| 774 | mTmpApplySurfaceChangesTransactionState.preferredModeId = preferredModeId; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | } |
| 778 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 779 | if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 780 | // This is the wallpaper target and its obscured state changed... make sure the |
| 781 | // current wallpaper's visibility has been updated accordingly. |
| 782 | mWallpaperController.updateWallpaperVisibility(); |
| 783 | } |
| 784 | |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 785 | w.handleWindowMovedIfNeeded(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 786 | |
| 787 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 788 | |
| 789 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 790 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 791 | |
| 792 | // Moved from updateWindowsAndWallpaperLocked(). |
| 793 | if (w.mHasSurface) { |
| 794 | // Take care of the window being ready to display. |
| 795 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 796 | if (isDefaultDisplay && committed) { |
| 797 | if (w.mAttrs.type == TYPE_DREAM) { |
| 798 | // HACK: When a dream is shown, it may at that point hide the lock screen. |
| 799 | // So we need to redo the layout to let the phone window manager make this |
| 800 | // happen. |
| 801 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 802 | if (DEBUG_LAYOUT_REPEATS) { |
| 803 | surfacePlacer.debugLayoutRepeats( |
| 804 | "dream and commitFinishDrawingLocked true", |
| 805 | pendingLayoutChanges); |
| 806 | } |
| 807 | } |
| 808 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 809 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 810 | "First draw done in potential wallpaper target " + w); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 811 | mWallpaperMayChange = true; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 812 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 813 | if (DEBUG_LAYOUT_REPEATS) { |
| 814 | surfacePlacer.debugLayoutRepeats( |
| 815 | "wallpaper and commitFinishDrawingLocked true", |
| 816 | pendingLayoutChanges); |
| 817 | } |
| 818 | } |
| 819 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 820 | } |
| 821 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 822 | final ActivityRecord activity = w.mActivityRecord; |
| 823 | if (activity != null) { |
| 824 | activity.updateLetterboxSurface(w); |
| 825 | final boolean updateAllDrawn = activity.updateDrawnWindowStates(w); |
| 826 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(activity)) { |
| 827 | mTmpUpdateAllDrawn.add(activity); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 831 | if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 832 | mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | w.updateResizingWindowIfNeeded(); |
| 836 | }; |
| 837 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 838 | /** |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 839 | * Create new {@link DisplayContent} instance, add itself to the root window container and |
| 840 | * initialize direct children. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 841 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 842 | * @param service You know. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 843 | * @param activityDisplay The ActivityDisplay for the display container. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 844 | */ |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 845 | DisplayContent(Display display, WindowManagerService service, |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 846 | ActivityDisplay activityDisplay) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 847 | super(service); |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 848 | mActivityDisplay = activityDisplay; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 849 | if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) { |
| 850 | throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() |
| 851 | + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId()) |
| 852 | + " new=" + display); |
| 853 | } |
| 854 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 855 | mDisplay = display; |
| 856 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 857 | mWallpaperController = new WallpaperController(mWmService, this); |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 858 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 859 | display.getMetrics(mDisplayMetrics); |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 860 | mSystemGestureExclusionLimit = mWmService.mConstants.mSystemGestureExclusionLimitDp |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 861 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 862 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 863 | mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo, |
| 864 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 865 | initializeDisplayBaseInfo(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 866 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 867 | mAppTransition = new AppTransition(service.mContext, service, this); |
| 868 | mAppTransition.registerListenerLocked(service.mActivityManagerAppTransitionNotifier); |
| 869 | mAppTransitionController = new AppTransitionController(service, this); |
| 870 | mUnknownAppVisibilityController = new UnknownAppVisibilityController(service, this); |
| 871 | |
| 872 | AnimationHandler animationHandler = new AnimationHandler(); |
| 873 | mBoundsAnimationController = new BoundsAnimationController(service.mContext, |
Winson Chung | 6ba767a | 2018-12-13 18:20:11 -0800 | [diff] [blame] | 874 | mAppTransition, AnimationThread.getHandler(), animationHandler); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 875 | |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 876 | final InputChannel inputChannel = mWmService.mInputManager.monitorInput( |
| 877 | "PointerEventDispatcher" + mDisplayId, mDisplayId); |
| 878 | mPointerEventDispatcher = new PointerEventDispatcher(inputChannel); |
| 879 | |
| 880 | // Tap Listeners are supported for: |
| 881 | // 1. All physical displays (multi-display). |
| 882 | // 2. VirtualDisplays on VR, AA (and everything else). |
| 883 | mTapDetector = new TaskTapPointerEventListener(mWmService, this); |
| 884 | registerPointerEventListener(mTapDetector); |
| 885 | registerPointerEventListener(mWmService.mMousePositionTracker); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 886 | if (mWmService.mAtmService.getRecentTasks() != null) { |
| 887 | registerPointerEventListener( |
| 888 | mWmService.mAtmService.getRecentTasks().getInputListener()); |
| 889 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 890 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 891 | mDisplayPolicy = new DisplayPolicy(service, this); |
| 892 | mDisplayRotation = new DisplayRotation(service, this); |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 893 | mCloseToSquareMaxAspectRatio = service.mContext.getResources().getFloat( |
| 894 | com.android.internal.R.dimen.config_closeToSquareDisplayMaxAspectRatio); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 895 | if (isDefaultDisplay) { |
| 896 | // The policy may be invoked right after here, so it requires the necessary default |
| 897 | // fields of this display content. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 898 | mWmService.mPolicy.setDefaultDisplay(this); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 899 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 900 | if (mWmService.mDisplayReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 901 | mDisplayPolicy.onConfigurationChanged(); |
| 902 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 903 | if (mWmService.mSystemReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 904 | mDisplayPolicy.systemReady(); |
| 905 | } |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 906 | mWindowCornerRadius = mDisplayPolicy.getWindowCornerRadius(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 907 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
| 908 | mPinnedStackControllerLocked = new PinnedStackController(service, this); |
| 909 | |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 910 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(mSession) |
| 911 | .setOpaque(true) |
| 912 | .setContainerLayer(); |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 913 | mSurfaceControl = b.setName("Root").setContainerLayer().build(); |
| 914 | mWindowingLayer = b.setName("Display Windows").setParent(mSurfaceControl).build(); |
| 915 | mOverlayLayer = b.setName("Display Overlays").setParent(mSurfaceControl).build(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 916 | |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 917 | getPendingTransaction() |
| 918 | .setLayer(mSurfaceControl, 0) |
| 919 | .setLayerStack(mSurfaceControl, mDisplayId) |
| 920 | .show(mSurfaceControl) |
| 921 | .setLayer(mWindowingLayer, 0) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 922 | .show(mWindowingLayer) |
| 923 | .setLayer(mOverlayLayer, 1) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 924 | .show(mOverlayLayer); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 925 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 926 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 927 | // These are the only direct children we should ever have and they are permanent. |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 928 | super.addChild(mBelowAppWindowsContainers, null); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 929 | super.addChild(mTaskStackContainers, null); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 930 | super.addChild(mAboveAppWindowsContainers, null); |
| 931 | super.addChild(mImeWindowsContainers, null); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 932 | // Sets the display content for the children. |
| 933 | onDisplayChanged(this); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 934 | |
| 935 | // Add itself as a child to the root container. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 936 | mWmService.mRoot.addChild(this, null); |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 937 | |
| 938 | // TODO(b/62541591): evaluate whether this is the best spot to declare the |
| 939 | // {@link DisplayContent} ready for use. |
| 940 | mDisplayReady = true; |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 941 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 942 | mWmService.mAnimator.addDisplayLocked(mDisplayId); |
Arthur Hung | 39134b2 | 2018-08-14 11:58:28 +0800 | [diff] [blame] | 943 | mInputMonitor = new InputMonitor(service, mDisplayId); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 944 | mInsetsStateController = new InsetsStateController(this); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 945 | mInsetsPolicy = new InsetsPolicy(mInsetsStateController, this); |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | boolean isReady() { |
| 949 | // 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] | 950 | return mWmService.mDisplayReady && mDisplayReady; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | int getDisplayId() { |
| 954 | return mDisplayId; |
| 955 | } |
| 956 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 957 | float getWindowCornerRadius() { |
| 958 | return mWindowCornerRadius; |
| 959 | } |
| 960 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 961 | WindowToken getWindowToken(IBinder binder) { |
| 962 | return mTokenMap.get(binder); |
| 963 | } |
| 964 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 965 | ActivityRecord getActivityRecord(IBinder binder) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 966 | final WindowToken token = getWindowToken(binder); |
| 967 | if (token == null) { |
| 968 | return null; |
| 969 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 970 | return token.asActivityRecord(); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 973 | private void addWindowToken(IBinder binder, WindowToken token) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 974 | final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 975 | if (dc != null) { |
| 976 | // We currently don't support adding a window token to the display if the display |
| 977 | // already has the binder mapped to another token. If there is a use case for supporting |
| 978 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 979 | // the binder map to a list of window tokens. |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 980 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 981 | + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 982 | } |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 983 | if (binder == null) { |
| 984 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 985 | + getName() + " binder is null"); |
| 986 | } |
| 987 | if (token == null) { |
| 988 | throw new IllegalArgumentException("Can't map null token to display=" |
| 989 | + getName() + " binder=" + binder); |
| 990 | } |
| 991 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 992 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 993 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 994 | if (token.asActivityRecord() == null) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 995 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 996 | // the parent container managing them (e.g. Tasks). |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 997 | switch (token.windowType) { |
| 998 | case TYPE_WALLPAPER: |
| 999 | mBelowAppWindowsContainers.addChild(token); |
| 1000 | break; |
| 1001 | case TYPE_INPUT_METHOD: |
| 1002 | case TYPE_INPUT_METHOD_DIALOG: |
| 1003 | mImeWindowsContainers.addChild(token); |
| 1004 | break; |
| 1005 | default: |
| 1006 | mAboveAppWindowsContainers.addChild(token); |
| 1007 | break; |
| 1008 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1009 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1013 | final WindowToken token = mTokenMap.remove(binder); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1014 | if (token != null && token.asActivityRecord() == null) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1015 | token.setExiting(); |
| 1016 | } |
| 1017 | return token; |
| 1018 | } |
| 1019 | |
| 1020 | /** Changes the display the input window token is housed on to this one. */ |
| 1021 | void reParentWindowToken(WindowToken token) { |
| 1022 | final DisplayContent prevDc = token.getDisplayContent(); |
| 1023 | if (prevDc == this) { |
| 1024 | return; |
| 1025 | } |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1026 | if (prevDc != null) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1027 | if (prevDc.mTokenMap.remove(token.token) != null && token.asActivityRecord() == null) { |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1028 | // Removed the token from the map, but made sure it's not an app token before |
| 1029 | // removing from parent. |
| 1030 | token.getParent().removeChild(token); |
| 1031 | } |
lumark | 280cb21 | 2019-09-09 09:47:22 +0800 | [diff] [blame] | 1032 | if (token.hasChild(prevDc.mLastFocus)) { |
| 1033 | // If the reparent window token contains previous display's last focus window, means |
| 1034 | // it will end up to gain window focus on the target display, so it should not be |
| 1035 | // notified that it lost focus from the previous display. |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1036 | prevDc.mLastFocus = null; |
| 1037 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1038 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1039 | |
| 1040 | addWindowToken(token.token, token); |
RyanlwLin | 925e822 | 2019-08-30 15:08:48 +0800 | [diff] [blame] | 1041 | |
| 1042 | if (mWmService.mAccessibilityController != null) { |
| 1043 | final int prevDisplayId = prevDc != null ? prevDc.getDisplayId() : INVALID_DISPLAY; |
| 1044 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(prevDisplayId, |
| 1045 | getDisplayId()); |
| 1046 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1049 | void removeAppToken(IBinder binder) { |
| 1050 | final WindowToken token = removeWindowToken(binder); |
| 1051 | if (token == null) { |
| 1052 | Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder); |
| 1053 | return; |
| 1054 | } |
| 1055 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1056 | final ActivityRecord activity = token.asActivityRecord(); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1057 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1058 | if (activity == null) { |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1059 | Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token); |
| 1060 | return; |
| 1061 | } |
| 1062 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1063 | activity.onRemovedFromDisplay(); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1066 | @Override |
| 1067 | public Display getDisplay() { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 1068 | return mDisplay; |
| 1069 | } |
| 1070 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1071 | DisplayInfo getDisplayInfo() { |
| 1072 | return mDisplayInfo; |
| 1073 | } |
| 1074 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 1075 | DisplayMetrics getDisplayMetrics() { |
| 1076 | return mDisplayMetrics; |
| 1077 | } |
| 1078 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1079 | DisplayPolicy getDisplayPolicy() { |
| 1080 | return mDisplayPolicy; |
| 1081 | } |
| 1082 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1083 | @Override |
| 1084 | public DisplayRotation getDisplayRotation() { |
| 1085 | return mDisplayRotation; |
| 1086 | } |
| 1087 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1088 | /** |
| 1089 | * Marks a window as providing insets for the rest of the windows in the system. |
| 1090 | * |
| 1091 | * @param type The type of inset this window provides. |
| 1092 | * @param win The window. |
| 1093 | * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of |
| 1094 | * the window should be taken. |
| 1095 | */ |
| 1096 | void setInsetProvider(@InternalInsetType int type, WindowState win, |
| 1097 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider) { |
| 1098 | mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider); |
| 1099 | } |
| 1100 | |
| 1101 | InsetsStateController getInsetsStateController() { |
| 1102 | return mInsetsStateController; |
| 1103 | } |
| 1104 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 1105 | InsetsPolicy getInsetsPolicy() { |
| 1106 | return mInsetsPolicy; |
| 1107 | } |
| 1108 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1109 | @Surface.Rotation |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1110 | int getRotation() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1111 | return mDisplayRotation.getRotation(); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1112 | } |
| 1113 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1114 | @ScreenOrientation |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1115 | int getLastOrientation() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1116 | return mDisplayRotation.getLastOrientation(); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1119 | @ScreenOrientation |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1120 | int getLastWindowForcedOrientation() { |
| 1121 | return mLastWindowForcedOrientation; |
| 1122 | } |
| 1123 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 1124 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 1125 | mAppTransitionController.registerRemoteAnimations(definition); |
| 1126 | } |
| 1127 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1128 | /** |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1129 | * The display content may have configuration set from {@link #DisplayWindowSettings}. This |
| 1130 | * callback let the owner of container know there is existing configuration to prevent the |
| 1131 | * values from being replaced by the initializing {@link #ActivityDisplay}. |
| 1132 | */ |
| 1133 | void initializeDisplayOverrideConfiguration() { |
Riddle Hsu | 6b76cd3 | 2019-10-08 00:37:19 +0800 | [diff] [blame] | 1134 | if (mActivityDisplay == null) { |
| 1135 | return; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1136 | } |
Riddle Hsu | 6b76cd3 | 2019-10-08 00:37:19 +0800 | [diff] [blame] | 1137 | mActivityDisplay.onRequestedOverrideConfigurationChanged( |
| 1138 | getResolvedOverrideConfiguration()); |
| 1139 | mActivityDisplay.registerConfigurationChangeListener(this); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1140 | } |
| 1141 | |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1142 | void reconfigureDisplayLocked() { |
| 1143 | if (!isReady()) { |
| 1144 | return; |
| 1145 | } |
| 1146 | configureDisplayPolicy(); |
| 1147 | setLayoutNeeded(); |
| 1148 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1149 | boolean configChanged = updateOrientation(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1150 | final Configuration currentDisplayConfig = getConfiguration(); |
| 1151 | mTmpConfiguration.setTo(currentDisplayConfig); |
| 1152 | computeScreenConfiguration(mTmpConfiguration); |
| 1153 | configChanged |= currentDisplayConfig.diff(mTmpConfiguration) != 0; |
| 1154 | |
| 1155 | if (configChanged) { |
| 1156 | mWaitingForConfig = true; |
| 1157 | mWmService.startFreezingDisplayLocked(0 /* exitAnim */, 0 /* enterAnim */, this); |
| 1158 | sendNewConfiguration(); |
| 1159 | } |
| 1160 | |
| 1161 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1164 | void sendNewConfiguration() { |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 1165 | if (!isReady() || mActivityDisplay == null) { |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1166 | return; |
| 1167 | } |
Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 1168 | if (mDisplayRotation.isWaitingForRemoteRotation()) { |
| 1169 | return; |
| 1170 | } |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 1171 | final boolean configUpdated = mActivityDisplay.updateDisplayOverrideConfigurationLocked(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1172 | if (configUpdated) { |
| 1173 | return; |
| 1174 | } |
| 1175 | // Something changed (E.g. device rotation), but no configuration update is needed. |
| 1176 | // E.g. changing device rotation by 180 degrees. Go ahead and perform surface placement to |
| 1177 | // unfreeze the display since we froze it when the rotation was updated in |
| 1178 | // DisplayContent#updateRotationUnchecked. |
| 1179 | if (mWaitingForConfig) { |
| 1180 | mWaitingForConfig = false; |
| 1181 | mWmService.mLastFinishedFreezeSource = "config-unchanged"; |
| 1182 | setLayoutNeeded(); |
| 1183 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1187 | @Override |
| 1188 | boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, |
| 1189 | ConfigurationContainer requestingContainer) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1190 | final Configuration config = updateOrientation( |
| 1191 | getRequestedOverrideConfiguration(), freezeDisplayToken, false /* forceUpdate */); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1192 | // If display rotation class tells us that it doesn't consider app requested orientation, |
| 1193 | // this display won't rotate just because of an app changes its requested orientation. Thus |
| 1194 | // it indicates that this display chooses not to handle this request. |
| 1195 | final boolean handled = getDisplayRotation().respectAppRequestedOrientation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1196 | if (config == null) { |
| 1197 | return handled; |
| 1198 | } |
| 1199 | |
| 1200 | if (handled && requestingContainer instanceof ActivityRecord) { |
| 1201 | final ActivityRecord activityRecord = (ActivityRecord) requestingContainer; |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 1202 | final boolean kept = mActivityDisplay.updateDisplayOverrideConfigurationLocked( |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1203 | config, activityRecord, false /* deferResume */, null /* result */); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1204 | activityRecord.frozenBeforeDestroy = true; |
| 1205 | if (!kept) { |
| 1206 | mWmService.mAtmService.mRootActivityContainer.resumeFocusedStacksTopActivities(); |
| 1207 | } |
| 1208 | } else { |
| 1209 | // We have a new configuration to push so we need to update ATMS for now. |
| 1210 | // TODO: Clean up display configuration push between ATMS and WMS after unification. |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 1211 | mActivityDisplay.updateDisplayOverrideConfigurationLocked( |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1212 | config, null /* starting */, false /* deferResume */, null); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1213 | } |
| 1214 | return handled; |
| 1215 | } |
| 1216 | |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1217 | @Override |
| 1218 | boolean handlesOrientationChangeFromDescendant() { |
| 1219 | return getDisplayRotation().respectAppRequestedOrientation(); |
| 1220 | } |
| 1221 | |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1222 | /** |
| 1223 | * Determine the new desired orientation of this display. |
| 1224 | * |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1225 | * @see #getOrientation() |
| 1226 | * @return {@code true} if the orientation is changed and the caller should call |
| 1227 | * {@link #sendNewConfiguration} if the method returns {@code true}. |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1228 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1229 | boolean updateOrientation() { |
| 1230 | return mDisplayRotation.updateOrientation(getOrientation(), false /* forceUpdate */); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1231 | } |
| 1232 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1233 | /** |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1234 | * 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] | 1235 | * changed from the current orientation. If a non-null configuration is returned, someone must |
| 1236 | * call {@link WindowManagerService#setNewDisplayOverrideConfiguration(Configuration, |
| 1237 | * 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] | 1238 | * be done by calling {@link #sendNewConfiguration}. |
| 1239 | * |
| 1240 | * @param currentConfig The current requested override configuration (it is usually set from |
| 1241 | * the last {@link #sendNewConfiguration}) of the display. It is used to |
| 1242 | * check if the configuration container has the latest state. |
| 1243 | * @param freezeDisplayToken Freeze the app window token if the orientation is changed. |
| 1244 | * @param forceUpdate See {@link DisplayRotation#updateRotationUnchecked(boolean)} |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1245 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1246 | Configuration updateOrientation(Configuration currentConfig, IBinder freezeDisplayToken, |
| 1247 | boolean forceUpdate) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1248 | if (!mDisplayReady) { |
| 1249 | return null; |
| 1250 | } |
| 1251 | |
| 1252 | Configuration config = null; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1253 | if (mDisplayRotation.updateOrientation(getOrientation(), forceUpdate)) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1254 | // If we changed the orientation but mOrientationChangeComplete is already true, |
| 1255 | // we used seamless rotation, and we don't need to freeze the screen. |
| 1256 | if (freezeDisplayToken != null && !mWmService.mRoot.mOrientationChangeComplete) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1257 | final ActivityRecord activity = getActivityRecord(freezeDisplayToken); |
| 1258 | if (activity != null) { |
| 1259 | activity.startFreezingScreen(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1260 | } |
| 1261 | } |
| 1262 | config = new Configuration(); |
| 1263 | computeScreenConfiguration(config); |
| 1264 | } else if (currentConfig != null) { |
| 1265 | // No obvious action we need to take, but if our current state mismatches the |
| 1266 | // activity manager's, update it, disregarding font scale, which should remain set |
| 1267 | // to the value of the previous configuration. |
| 1268 | // Here we're calling Configuration#unset() instead of setToDefaults() because we |
| 1269 | // need to keep override configs clear of non-empty values (e.g. fontSize). |
| 1270 | mTmpConfiguration.unset(); |
| 1271 | mTmpConfiguration.updateFrom(currentConfig); |
| 1272 | computeScreenConfiguration(mTmpConfiguration); |
| 1273 | if (currentConfig.diff(mTmpConfiguration) != 0) { |
| 1274 | mWaitingForConfig = true; |
| 1275 | setLayoutNeeded(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1276 | mDisplayRotation.prepareNormalRotationAnimation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1277 | config = new Configuration(mTmpConfiguration); |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | return config; |
| 1282 | } |
| 1283 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1284 | /** |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1285 | * Update rotation of the display. |
| 1286 | * |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1287 | * @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] | 1288 | * {@link #sendNewConfiguration} TO UNFREEZE THE SCREEN. |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1289 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1290 | boolean updateRotationUnchecked() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1291 | return mDisplayRotation.updateRotationUnchecked(false /* forceUpdate */); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | /** |
| 1295 | * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked} |
| 1296 | * (if it returned {@code true}) to actually finish the rotation. |
| 1297 | * |
| 1298 | * @param oldRotation the rotation we are coming from. |
| 1299 | * @param rotation the rotation to apply. |
| 1300 | */ |
| 1301 | void applyRotationLocked(final int oldRotation, final int rotation) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1302 | mDisplayRotation.applyCurrentRotation(rotation); |
| 1303 | final boolean rotateSeamlessly = mDisplayRotation.isRotatingSeamlessly(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1304 | final Transaction transaction = getPendingTransaction(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 1305 | ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly |
| 1306 | ? null : getRotationAnimation(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1307 | // We need to update our screen size information to match the new rotation. If the rotation |
| 1308 | // has actually changed then this method will return true and, according to the comment at |
| 1309 | // the top of the method, the caller is obligated to call computeNewConfigurationLocked(). |
| 1310 | // By updating the Display info here it will be available to |
| 1311 | // #computeScreenConfiguration() later. |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1312 | updateDisplayAndOrientation(getConfiguration().uiMode, null /* outConfig */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1313 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1314 | // NOTE: We disable the rotation in the emulator because |
| 1315 | // it doesn't support hardware OpenGL emulation yet. |
Vadim Caen | ba4fd6c | 2019-08-05 16:45:46 +0200 | [diff] [blame] | 1316 | if (screenRotationAnimation != null && screenRotationAnimation.hasScreenshot()) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1317 | screenRotationAnimation.setRotation(transaction, rotation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1320 | forAllWindows(w -> { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1321 | w.seamlesslyRotateIfAllowed(transaction, oldRotation, rotation, rotateSeamlessly); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1322 | }, true /* traverseTopToBottom */); |
| 1323 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1324 | mWmService.mDisplayManagerInternal.performTraversal(transaction); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1325 | scheduleAnimation(); |
| 1326 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1327 | forAllWindows(w -> { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1328 | if (w.mHasSurface && !rotateSeamlessly) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1329 | ProtoLog.v(WM_DEBUG_ORIENTATION, "Set mOrientationChanging of %s", w); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1330 | w.setOrientationChanging(true); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1331 | mWmService.mRoot.mOrientationChangeComplete = false; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1332 | w.mLastFreezeDuration = 0; |
| 1333 | } |
| 1334 | w.mReportOrientationChanged = true; |
| 1335 | }, true /* traverseTopToBottom */); |
| 1336 | |
| 1337 | if (rotateSeamlessly) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1338 | mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT, |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1339 | this, SEAMLESS_ROTATION_TIMEOUT_DURATION); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1342 | for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1343 | final WindowManagerService.RotationWatcher rotationWatcher |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1344 | = mWmService.mRotationWatchers.get(i); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1345 | if (rotationWatcher.mDisplayId == mDisplayId) { |
| 1346 | try { |
| 1347 | rotationWatcher.mWatcher.onRotationChanged(rotation); |
| 1348 | } catch (RemoteException e) { |
| 1349 | // Ignore |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1354 | // Announce rotation only if we will not animate as we already have the |
| 1355 | // windows in final state. Otherwise, we make this call at the rotation end. |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1356 | if (screenRotationAnimation == null && mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1357 | mWmService.mAccessibilityController.onRotationChangedLocked(this); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1358 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1361 | void configureDisplayPolicy() { |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1362 | final int width = mBaseDisplayWidth; |
| 1363 | final int height = mBaseDisplayHeight; |
| 1364 | final int shortSize; |
| 1365 | final int longSize; |
| 1366 | if (width > height) { |
| 1367 | shortSize = height; |
| 1368 | longSize = width; |
| 1369 | } else { |
| 1370 | shortSize = width; |
| 1371 | longSize = height; |
| 1372 | } |
| 1373 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 1374 | final int shortSizeDp = shortSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
| 1375 | final int longSizeDp = longSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1376 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1377 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 1378 | mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1379 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1380 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 1381 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1382 | |
| 1383 | // Not much of use to rotate the display for apps since it's close to square. |
| 1384 | mIgnoreRotationForApps = isNonDecorDisplayCloseToSquare(Surface.ROTATION_0, width, height); |
| 1385 | } |
| 1386 | |
| 1387 | private boolean isNonDecorDisplayCloseToSquare(int rotation, int width, int height) { |
| 1388 | final DisplayCutout displayCutout = |
| 1389 | calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
| 1390 | final int uiMode = mWmService.mPolicy.getUiMode(); |
| 1391 | final int w = mDisplayPolicy.getNonDecorDisplayWidth( |
| 1392 | width, height, rotation, uiMode, displayCutout); |
| 1393 | final int h = mDisplayPolicy.getNonDecorDisplayHeight( |
| 1394 | width, height, rotation, uiMode, displayCutout); |
| 1395 | final float aspectRatio = Math.max(w, h) / (float) Math.min(w, h); |
| 1396 | return aspectRatio <= mCloseToSquareMaxAspectRatio; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1399 | /** |
| 1400 | * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config |
| 1401 | * changed. |
| 1402 | * Do not call if {@link WindowManagerService#mDisplayReady} == false. |
| 1403 | */ |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1404 | private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1405 | // Use the effective "visual" dimensions based on current rotation |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1406 | final int rotation = getRotation(); |
| 1407 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1408 | final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1409 | final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1410 | |
| 1411 | // Update application display metrics. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1412 | final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(rotation); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1413 | final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout(); |
| 1414 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1415 | final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1416 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1417 | final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1418 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1419 | mDisplayInfo.rotation = rotation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1420 | mDisplayInfo.logicalWidth = dw; |
| 1421 | mDisplayInfo.logicalHeight = dh; |
| 1422 | mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity; |
| 1423 | mDisplayInfo.appWidth = appWidth; |
| 1424 | mDisplayInfo.appHeight = appHeight; |
| 1425 | if (isDefaultDisplay) { |
| 1426 | mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics, |
| 1427 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
| 1428 | } |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1429 | mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1430 | mDisplayInfo.getAppMetrics(mDisplayMetrics); |
| 1431 | if (mDisplayScalingDisabled) { |
| 1432 | mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED; |
| 1433 | } else { |
| 1434 | mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED; |
| 1435 | } |
| 1436 | |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1437 | computeSizeRangesAndScreenLayout(mDisplayInfo, rotated, uiMode, dw, dh, |
| 1438 | mDisplayMetrics.density, outConfig); |
| 1439 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1440 | // We usually set the override info in DisplayManager so that we get consistent display |
| 1441 | // metrics values when displays are changing and don't send out new values until WM is aware |
| 1442 | // of them. However, we don't do this for displays that serve as containers for ActivityView |
| 1443 | // because we don't want letter-/pillar-boxing during resize. |
| 1444 | final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration |
| 1445 | ? mDisplayInfo : null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1446 | mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId, |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1447 | overrideDisplayInfo); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1448 | |
| 1449 | mBaseDisplayRect.set(0, 0, dw, dh); |
| 1450 | |
| 1451 | if (isDefaultDisplay) { |
| 1452 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics, |
| 1453 | mCompatDisplayMetrics); |
| 1454 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1455 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1456 | return mDisplayInfo; |
| 1457 | } |
| 1458 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1459 | WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) { |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1460 | return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation); |
| 1461 | } |
| 1462 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1463 | private WmDisplayCutout calculateDisplayCutoutForRotationUncached( |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1464 | DisplayCutout cutout, int rotation) { |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1465 | if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1466 | return WmDisplayCutout.NO_CUTOUT; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1467 | } |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1468 | if (rotation == ROTATION_0) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1469 | return WmDisplayCutout.computeSafeInsets( |
| 1470 | cutout, mInitialDisplayWidth, mInitialDisplayHeight); |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1471 | } |
Adrian Roos | bed538e | 2018-02-21 17:50:07 +0100 | [diff] [blame] | 1472 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1473 | final Rect[] newBounds = mRotationUtil.getRotatedBounds( |
| 1474 | WmDisplayCutout.computeSafeInsets( |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 1475 | cutout, mInitialDisplayWidth, mInitialDisplayHeight) |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1476 | .getDisplayCutout().getBoundingRectsAll(), |
| 1477 | rotation, mInitialDisplayWidth, mInitialDisplayHeight); |
| 1478 | return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds), |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1479 | rotated ? mInitialDisplayHeight : mInitialDisplayWidth, |
| 1480 | rotated ? mInitialDisplayWidth : mInitialDisplayHeight); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1481 | } |
| 1482 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1483 | /** |
| 1484 | * Compute display configuration based on display properties and policy settings. |
| 1485 | * Do not call if mDisplayReady == false. |
| 1486 | */ |
| 1487 | void computeScreenConfiguration(Configuration config) { |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1488 | final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode, config); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1489 | calculateBounds(displayInfo, mTmpBounds); |
| 1490 | config.windowConfiguration.setBounds(mTmpBounds); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1491 | |
| 1492 | final int dw = displayInfo.logicalWidth; |
| 1493 | final int dh = displayInfo.logicalHeight; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 1494 | config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 1495 | config.windowConfiguration.setWindowingMode(getWindowingMode()); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 1496 | config.windowConfiguration.setDisplayWindowingMode(getWindowingMode()); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1497 | config.windowConfiguration.setRotation(displayInfo.rotation); |
Bryce Lee | c1f2f2a | 2017-06-22 15:29:42 -0700 | [diff] [blame] | 1498 | |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1499 | final float density = mDisplayMetrics.density; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1500 | config.screenWidthDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1501 | (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation, |
| 1502 | config.uiMode, displayInfo.displayCutout) / density); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1503 | config.screenHeightDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1504 | (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation, |
| 1505 | config.uiMode, displayInfo.displayCutout) / density); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1506 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1507 | mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1508 | displayInfo.displayCutout, mTmpRect); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1509 | final int leftInset = mTmpRect.left; |
| 1510 | final int topInset = mTmpRect.top; |
| 1511 | // appBounds at the root level should mirror the app screen size. |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1512 | config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */, |
| 1513 | leftInset + displayInfo.appWidth /* right */, |
| 1514 | topInset + displayInfo.appHeight /* bottom */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1515 | final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90 |
| 1516 | || displayInfo.rotation == Surface.ROTATION_270); |
| 1517 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1518 | config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) |
| 1519 | | ((displayInfo.flags & Display.FLAG_ROUND) != 0 |
| 1520 | ? Configuration.SCREENLAYOUT_ROUND_YES |
| 1521 | : Configuration.SCREENLAYOUT_ROUND_NO); |
| 1522 | |
| 1523 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 1524 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 1525 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1526 | dh, displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1527 | config.densityDpi = displayInfo.logicalDensityDpi; |
| 1528 | |
| 1529 | config.colorMode = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1530 | ((displayInfo.isHdr() && mWmService.hasHdrSupport()) |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1531 | ? Configuration.COLOR_MODE_HDR_YES |
| 1532 | : Configuration.COLOR_MODE_HDR_NO) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1533 | | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1534 | ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES |
| 1535 | : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO); |
| 1536 | |
| 1537 | // Update the configuration based on available input devices, lid switch, |
| 1538 | // and platform configuration. |
| 1539 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1540 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 1541 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 1542 | |
| 1543 | int keyboardPresence = 0; |
| 1544 | int navigationPresence = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1545 | final InputDevice[] devices = mWmService.mInputManager.getInputDevices(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1546 | final int len = devices != null ? devices.length : 0; |
| 1547 | for (int i = 0; i < len; i++) { |
| 1548 | InputDevice device = devices[i]; |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1549 | // Ignore virtual input device. |
| 1550 | if (device.isVirtual()) { |
| 1551 | continue; |
| 1552 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1553 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1554 | // Check if input device can dispatch events to current display. |
| 1555 | // If display type is virtual, will follow the default display. |
| 1556 | if (!mWmService.mInputManager.canDispatchToDisplay(device.getId(), |
| 1557 | displayInfo.type == Display.TYPE_VIRTUAL ? DEFAULT_DISPLAY : mDisplayId)) { |
| 1558 | continue; |
| 1559 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1560 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1561 | final int sources = device.getSources(); |
| 1562 | final int presenceFlag = device.isExternal() |
| 1563 | ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1564 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1565 | if (mWmService.mIsTouchDevice) { |
| 1566 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { |
| 1567 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1568 | } |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1569 | } else { |
| 1570 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1571 | } |
| 1572 | |
| 1573 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
| 1574 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 1575 | navigationPresence |= presenceFlag; |
| 1576 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
| 1577 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 1578 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1579 | navigationPresence |= presenceFlag; |
| 1580 | } |
| 1581 | |
| 1582 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 1583 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 1584 | keyboardPresence |= presenceFlag; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1588 | if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1589 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1590 | navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL; |
| 1591 | } |
| 1592 | |
| 1593 | // Determine whether a hard keyboard is available and enabled. |
| 1594 | // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device? |
| 1595 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1596 | if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) { |
| 1597 | mWmService.mHardKeyboardAvailable = hardKeyboardAvailable; |
| 1598 | mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 1599 | mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1602 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1603 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1604 | // Let the policy update hidden states. |
| 1605 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 1606 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 1607 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1608 | mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1612 | DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1613 | mTmpDisplayMetrics.setTo(mDisplayMetrics); |
| 1614 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 1615 | final int unrotDw, unrotDh; |
| 1616 | if (rotated) { |
| 1617 | unrotDw = dh; |
| 1618 | unrotDh = dw; |
| 1619 | } else { |
| 1620 | unrotDw = dw; |
| 1621 | unrotDh = dh; |
| 1622 | } |
| 1623 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1624 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1625 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1626 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1627 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1628 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1629 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1630 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1631 | return sw; |
| 1632 | } |
| 1633 | |
| 1634 | private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1635 | DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) { |
| 1636 | dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
| 1637 | displayCutout); |
| 1638 | dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
| 1639 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1640 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
| 1641 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
| 1642 | if (curSize == 0 || size < curSize) { |
| 1643 | curSize = size; |
| 1644 | } |
| 1645 | return curSize; |
| 1646 | } |
| 1647 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1648 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 1649 | int uiMode, int dw, int dh, float density, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1650 | |
| 1651 | // We need to determine the smallest width that will occur under normal |
| 1652 | // operation. To this, start with the base screen size and compute the |
| 1653 | // width under the different possible rotations. We need to un-rotate |
| 1654 | // the current screen dimensions before doing this. |
| 1655 | int unrotDw, unrotDh; |
| 1656 | if (rotated) { |
| 1657 | unrotDw = dh; |
| 1658 | unrotDh = dw; |
| 1659 | } else { |
| 1660 | unrotDw = dw; |
| 1661 | unrotDh = dh; |
| 1662 | } |
| 1663 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 1664 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 1665 | displayInfo.largestNominalAppWidth = 0; |
| 1666 | displayInfo.largestNominalAppHeight = 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1667 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh); |
| 1668 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw); |
| 1669 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh); |
| 1670 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw); |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1671 | |
| 1672 | if (outConfig == null) { |
| 1673 | return; |
| 1674 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1675 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
| 1676 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1677 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1678 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1679 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1680 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1681 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1682 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1683 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1684 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
| 1685 | outConfig.screenLayout = sl; |
| 1686 | } |
| 1687 | |
| 1688 | private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1689 | int uiMode, DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1690 | // Get the app screen size at this rotation. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1691 | int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout); |
| 1692 | int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1693 | |
| 1694 | // Compute the screen layout size class for this rotation. |
| 1695 | int longSize = w; |
| 1696 | int shortSize = h; |
| 1697 | if (longSize < shortSize) { |
| 1698 | int tmp = longSize; |
| 1699 | longSize = shortSize; |
| 1700 | shortSize = tmp; |
| 1701 | } |
| 1702 | longSize = (int)(longSize/density); |
| 1703 | shortSize = (int)(shortSize/density); |
| 1704 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
| 1705 | } |
| 1706 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1707 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1708 | int uiMode, int dw, int dh) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1709 | final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( |
| 1710 | rotation).getDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1711 | final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode, |
| 1712 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1713 | if (width < displayInfo.smallestNominalAppWidth) { |
| 1714 | displayInfo.smallestNominalAppWidth = width; |
| 1715 | } |
| 1716 | if (width > displayInfo.largestNominalAppWidth) { |
| 1717 | displayInfo.largestNominalAppWidth = width; |
| 1718 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1719 | final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode, |
| 1720 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1721 | if (height < displayInfo.smallestNominalAppHeight) { |
| 1722 | displayInfo.smallestNominalAppHeight = height; |
| 1723 | } |
| 1724 | if (height > displayInfo.largestNominalAppHeight) { |
| 1725 | displayInfo.largestNominalAppHeight = height; |
| 1726 | } |
| 1727 | } |
| 1728 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 1729 | /** |
| 1730 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 1731 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 1732 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 1733 | * This lowers the travel distance between invoking the menu panel and selecting |
| 1734 | * a menu option. |
| 1735 | * |
| 1736 | * This method helps control where that menu is placed. Its current implementation makes |
| 1737 | * assumptions about the menu key and its relationship to the screen based on whether |
| 1738 | * the device's natural orientation is portrait (width < height) or landscape. |
| 1739 | * |
| 1740 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 1741 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 1742 | * do not hold for the target device, this method should be changed to reflect that. |
| 1743 | * |
| 1744 | * @return A {@link Gravity} value for placing the options menu window. |
| 1745 | */ |
| 1746 | int getPreferredOptionsPanelGravity() { |
| 1747 | final int rotation = getRotation(); |
| 1748 | if (mInitialDisplayWidth < mInitialDisplayHeight) { |
| 1749 | // On devices with a natural orientation of portrait. |
| 1750 | switch (rotation) { |
| 1751 | default: |
| 1752 | case Surface.ROTATION_0: |
| 1753 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1754 | case Surface.ROTATION_90: |
| 1755 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1756 | case Surface.ROTATION_180: |
| 1757 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1758 | case Surface.ROTATION_270: |
| 1759 | return Gravity.START | Gravity.BOTTOM; |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | // On devices with a natural orientation of landscape. |
| 1764 | switch (rotation) { |
| 1765 | default: |
| 1766 | case Surface.ROTATION_0: |
| 1767 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1768 | case Surface.ROTATION_90: |
| 1769 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1770 | case Surface.ROTATION_180: |
| 1771 | return Gravity.START | Gravity.BOTTOM; |
| 1772 | case Surface.ROTATION_270: |
| 1773 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1774 | } |
| 1775 | } |
| 1776 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 1777 | DockedStackDividerController getDockedDividerController() { |
| 1778 | return mDividerControllerLocked; |
| 1779 | } |
| 1780 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1781 | PinnedStackController getPinnedStackController() { |
| 1782 | return mPinnedStackControllerLocked; |
| 1783 | } |
| 1784 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1785 | /** |
| 1786 | * Returns true if the specified UID has access to this display. |
| 1787 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1788 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1789 | return mDisplay.hasAccess(uid); |
| 1790 | } |
| 1791 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1792 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1793 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1796 | ActivityStack getHomeStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1797 | return mTaskStackContainers.getHomeStack(); |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1800 | /** |
| 1801 | * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise. |
| 1802 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1803 | ActivityStack getSplitScreenPrimaryStack() { |
| 1804 | ActivityStack stack = mTaskStackContainers.getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1805 | return (stack != null && stack.isVisible()) ? stack : null; |
| 1806 | } |
| 1807 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1808 | boolean hasSplitScreenPrimaryStack() { |
| 1809 | return getSplitScreenPrimaryStack() != null; |
| 1810 | } |
| 1811 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1812 | /** |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 1813 | * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1814 | * not visible. |
| 1815 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1816 | ActivityStack getSplitScreenPrimaryStackIgnoringVisibility() { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 1817 | return mTaskStackContainers.getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1820 | ActivityStack getPinnedStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1821 | return mTaskStackContainers.getPinnedStack(); |
| 1822 | } |
| 1823 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1824 | boolean hasPinnedStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1825 | return mTaskStackContainers.getPinnedStack() != null; |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1828 | /** |
| 1829 | * Returns the topmost stack on the display that is compatible with the input windowing mode. |
| 1830 | * Null is no compatible stack on the display. |
| 1831 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1832 | ActivityStack getTopStackInWindowingMode(int windowingMode) { |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1833 | return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED); |
| 1834 | } |
| 1835 | |
| 1836 | /** |
| 1837 | * Returns the topmost stack on the display that is compatible with the input windowing mode and |
| 1838 | * activity type. Null is no compatible stack on the display. |
| 1839 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1840 | ActivityStack getStack(int windowingMode, int activityType) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1841 | return mTaskStackContainers.getStack(windowingMode, activityType); |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1844 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1845 | WindowList<ActivityStack> getStacks() { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 1846 | return mTaskStackContainers.mChildren; |
| 1847 | } |
| 1848 | |
| 1849 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1850 | ActivityStack getTopStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1851 | return mTaskStackContainers.getTopStack(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1854 | ArrayList<Task> getVisibleTasks() { |
| 1855 | return mTaskStackContainers.getVisibleTasks(); |
| 1856 | } |
| 1857 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1858 | void onStackWindowingModeChanged(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1859 | mTaskStackContainers.onStackWindowingModeChanged(stack); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1862 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 1863 | public void onConfigurationChanged(Configuration newParentConfig) { |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 1864 | final int lastOrientation = getConfiguration().orientation; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1865 | super.onConfigurationChanged(newParentConfig); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1866 | if (mDisplayPolicy != null) { |
| 1867 | mDisplayPolicy.onConfigurationChanged(); |
| 1868 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1869 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 1870 | if (lastOrientation != getConfiguration().orientation) { |
| 1871 | getMetricsLogger().write( |
| 1872 | new LogMaker(MetricsEvent.ACTION_PHONE_ORIENTATION_CHANGED) |
| 1873 | .setSubtype(getConfiguration().orientation) |
| 1874 | .addTaggedData(MetricsEvent.FIELD_DISPLAY_ID, getDisplayId())); |
| 1875 | } |
| 1876 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1877 | // If there was no pinned stack, we still need to notify the controller of the display info |
| 1878 | // update as a result of the config change. |
| 1879 | if (mPinnedStackControllerLocked != null && !hasPinnedStack()) { |
| 1880 | mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo()); |
| 1881 | } |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | /** |
| 1885 | * Updates the resources used by docked/pinned controllers. This needs to be called at the |
| 1886 | * beginning of a configuration update cascade since the metrics from these resources are used |
| 1887 | * for bounds calculations. Since ActivityDisplay initiates the configuration update, this |
| 1888 | * should be called from there instead of DisplayContent's onConfigurationChanged. |
| 1889 | */ |
| 1890 | void preOnConfigurationChanged() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1891 | final DockedStackDividerController dividerController = getDockedDividerController(); |
| 1892 | |
| 1893 | if (dividerController != null) { |
| 1894 | getDockedDividerController().onConfigurationChanged(); |
| 1895 | } |
| 1896 | |
| 1897 | final PinnedStackController pinnedStackController = getPinnedStackController(); |
| 1898 | |
| 1899 | if (pinnedStackController != null) { |
| 1900 | getPinnedStackController().onConfigurationChanged(); |
| 1901 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1902 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 1903 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1904 | @Override |
| 1905 | boolean fillsParent() { |
| 1906 | return true; |
| 1907 | } |
| 1908 | |
| 1909 | @Override |
| 1910 | boolean isVisible() { |
| 1911 | return true; |
| 1912 | } |
| 1913 | |
| 1914 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1915 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1916 | super.onAppTransitionDone(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1917 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 1920 | @Override |
| 1921 | public void setWindowingMode(int windowingMode) { |
| 1922 | super.setWindowingMode(windowingMode); |
| 1923 | super.setDisplayWindowingMode(windowingMode); |
| 1924 | } |
| 1925 | |
| 1926 | @Override |
| 1927 | void setDisplayWindowingMode(int windowingMode) { |
| 1928 | setWindowingMode(windowingMode); |
| 1929 | } |
| 1930 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1931 | /** |
| 1932 | * In split-screen mode we process the IME containers above the docked divider |
| 1933 | * rather than directly above their target. |
| 1934 | */ |
| 1935 | private boolean skipTraverseChild(WindowContainer child) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 1936 | if (child == mImeWindowsContainers && mInputMethodTarget != null |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1937 | && !hasSplitScreenPrimaryStack()) { |
| 1938 | return true; |
| 1939 | } |
| 1940 | return false; |
| 1941 | } |
| 1942 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1943 | @Override |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1944 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 1945 | // Special handling so we can process IME windows with #forAllImeWindows above their IME |
| 1946 | // target, or here in order if there isn't an IME target. |
| 1947 | if (traverseTopToBottom) { |
| 1948 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1949 | final DisplayChildWindowContainer child = mChildren.get(i); |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1950 | if (skipTraverseChild(child)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1951 | continue; |
| 1952 | } |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1953 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1954 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 1955 | return true; |
| 1956 | } |
| 1957 | } |
| 1958 | } else { |
| 1959 | final int count = mChildren.size(); |
| 1960 | for (int i = 0; i < count; i++) { |
| 1961 | final DisplayChildWindowContainer child = mChildren.get(i); |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1962 | if (skipTraverseChild(child)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1963 | continue; |
| 1964 | } |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1965 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1966 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 1967 | return true; |
| 1968 | } |
| 1969 | } |
| 1970 | } |
| 1971 | return false; |
| 1972 | } |
| 1973 | |
| 1974 | boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 1975 | return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom); |
| 1976 | } |
| 1977 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1978 | /** |
| 1979 | * In the general case, the orientation is computed from the above app windows first. If none of |
| 1980 | * the above app windows specify orientation, the orientation is computed from the child window |
| 1981 | * container, e.g. {@link AppWindowToken#getOrientation(int)}. |
| 1982 | */ |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 1983 | @Override |
| 1984 | int getOrientation() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1985 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1986 | |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1987 | if (mIgnoreRotationForApps) { |
| 1988 | return SCREEN_ORIENTATION_USER; |
| 1989 | } |
| 1990 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1991 | if (mWmService.mDisplayFrozen) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1992 | if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1993 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 1994 | "Display id=%d is frozen, return %d", mDisplayId, |
| 1995 | mLastWindowForcedOrientation); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1996 | // If the display is frozen, some activities may be in the middle of restarting, and |
| 1997 | // thus have removed their old window. If the window has the flag to hide the lock |
| 1998 | // screen, then the lock screen can re-appear and inflict its own orientation on us. |
| 1999 | // Keep the orientation stable until this all settles down. |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2000 | return mLastWindowForcedOrientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2001 | } else if (policy.isKeyguardLocked()) { |
| 2002 | // Use the last orientation the while the display is frozen with the keyguard |
| 2003 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 2004 | // window. We don't want to check the show when locked window directly though as |
| 2005 | // things aren't stable while the display is frozen, for example the window could be |
| 2006 | // momentarily unavailable due to activity relaunch. |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2007 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 2008 | "Display id=%d is frozen while keyguard locked, return %d", |
| 2009 | mDisplayId, getLastOrientation()); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2010 | return getLastOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2011 | } |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2012 | } else { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2013 | final int orientation = mAboveAppWindowsContainers.getOrientation(); |
| 2014 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 2015 | return orientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2016 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 2019 | // Top system windows are not requesting an orientation. Start searching from apps. |
| 2020 | return mTaskStackContainers.getOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2023 | void updateDisplayInfo() { |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2024 | // Check if display metrics changed and update base values if needed. |
| 2025 | updateBaseDisplayMetricsIfNeeded(); |
| 2026 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2027 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 2028 | mDisplay.getMetrics(mDisplayMetrics); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2029 | |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 2030 | onDisplayChanged(this); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2033 | @Override |
| 2034 | void onDisplayChanged(DisplayContent dc) { |
| 2035 | super.onDisplayChanged(dc); |
| 2036 | updateSystemGestureExclusionLimit(); |
| 2037 | } |
| 2038 | |
| 2039 | void updateSystemGestureExclusionLimit() { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 2040 | mSystemGestureExclusionLimit = mWmService.mConstants.mSystemGestureExclusionLimitDp |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2041 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
| 2042 | updateSystemGestureExclusion(); |
| 2043 | } |
| 2044 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2045 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2046 | final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2047 | if (displayManagerInternal != null) { |
| 2048 | // Bootstrap the default logical display from the display manager. |
| 2049 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 2050 | if (newDisplayInfo != null) { |
| 2051 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 2052 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2053 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2054 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2055 | updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight, |
| 2056 | mDisplayInfo.logicalDensityDpi); |
| 2057 | mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 2058 | mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 2059 | mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2060 | mInitialDisplayCutout = mDisplayInfo.displayCutout; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2063 | /** |
| 2064 | * If display metrics changed, overrides are not set and it's not just a rotation - update base |
| 2065 | * values. |
| 2066 | */ |
| 2067 | private void updateBaseDisplayMetricsIfNeeded() { |
| 2068 | // Get real display metrics without overrides from WM. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2069 | mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2070 | final int orientation = mDisplayInfo.rotation; |
| 2071 | final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
| 2072 | final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth; |
| 2073 | final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight; |
| 2074 | final int newDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2075 | final DisplayCutout newCutout = mDisplayInfo.displayCutout; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2076 | |
| 2077 | final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth |
| 2078 | || mInitialDisplayHeight != newHeight |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2079 | || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi |
| 2080 | || !Objects.equals(mInitialDisplayCutout, newCutout); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2081 | |
| 2082 | if (displayMetricsChanged) { |
| 2083 | // Check if display size or density is forced. |
| 2084 | final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth |
| 2085 | || mBaseDisplayHeight != mInitialDisplayHeight; |
| 2086 | final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity; |
| 2087 | |
| 2088 | // If there is an override set for base values - use it, otherwise use new values. |
| 2089 | updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth, |
| 2090 | isDisplaySizeForced ? mBaseDisplayHeight : newHeight, |
| 2091 | isDisplayDensityForced ? mBaseDisplayDensity : newDensity); |
| 2092 | |
| 2093 | // Real display metrics changed, so we should also update initial values. |
| 2094 | mInitialDisplayWidth = newWidth; |
| 2095 | mInitialDisplayHeight = newHeight; |
| 2096 | mInitialDisplayDensity = newDensity; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2097 | mInitialDisplayCutout = newCutout; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2098 | reconfigureDisplayLocked(); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2102 | /** Sets the maximum width the screen resolution can be */ |
| 2103 | void setMaxUiWidth(int width) { |
| 2104 | if (DEBUG_DISPLAY) { |
| 2105 | Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId()); |
| 2106 | } |
| 2107 | |
| 2108 | mMaxUiWidth = width; |
| 2109 | |
| 2110 | // Update existing metrics. |
| 2111 | updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity); |
| 2112 | } |
| 2113 | |
| 2114 | /** Update base (override) display metrics. */ |
| 2115 | void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) { |
| 2116 | mBaseDisplayWidth = baseWidth; |
| 2117 | mBaseDisplayHeight = baseHeight; |
| 2118 | mBaseDisplayDensity = baseDensity; |
| 2119 | |
| 2120 | if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) { |
| 2121 | mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth; |
| 2122 | mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth; |
| 2123 | mBaseDisplayWidth = mMaxUiWidth; |
| 2124 | |
| 2125 | if (DEBUG_DISPLAY) { |
| 2126 | Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x" |
| 2127 | + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity |
| 2128 | + " on display:" + getDisplayId()); |
| 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2133 | |
| 2134 | updateBounds(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2137 | /** |
| 2138 | * Forces this display to use the specified density. |
| 2139 | * |
| 2140 | * @param density The density in DPI to use. If the value equals to initial density, the setting |
| 2141 | * will be cleared. |
| 2142 | * @param userId The target user to apply. Only meaningful when this is default display. If the |
| 2143 | * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings |
| 2144 | * so only need to configure display. |
| 2145 | */ |
| 2146 | void setForcedDensity(int density, int userId) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2147 | final boolean updateCurrent = userId == UserHandle.USER_CURRENT; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2148 | if (mWmService.mCurrentUserId == userId || updateCurrent) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2149 | mBaseDisplayDensity = density; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2150 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2151 | } |
| 2152 | if (updateCurrent) { |
| 2153 | // We are applying existing settings so no need to save it again. |
| 2154 | return; |
| 2155 | } |
| 2156 | |
| 2157 | if (density == mInitialDisplayDensity) { |
| 2158 | density = 0; |
| 2159 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2160 | mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */ |
| 2164 | void setForcedScalingMode(@ForceScalingMode int mode) { |
| 2165 | if (mode != FORCE_SCALING_MODE_DISABLED) { |
| 2166 | mode = FORCE_SCALING_MODE_AUTO; |
| 2167 | } |
| 2168 | |
| 2169 | mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO); |
| 2170 | Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto")); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2171 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2172 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2173 | mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | /** If the given width and height equal to initial size, the setting will be cleared. */ |
| 2177 | void setForcedSize(int width, int height) { |
| 2178 | final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height; |
| 2179 | if (!clear) { |
| 2180 | // Set some sort of reasonable bounds on the size of the display that we will try |
| 2181 | // to emulate. |
| 2182 | final int minSize = 200; |
| 2183 | final int maxScale = 2; |
| 2184 | width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale); |
| 2185 | height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale); |
| 2186 | } |
| 2187 | |
| 2188 | Slog.i(TAG_WM, "Using new display size: " + width + "x" + height); |
| 2189 | updateBaseDisplayMetrics(width, height, mBaseDisplayDensity); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2190 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2191 | |
| 2192 | if (clear) { |
| 2193 | width = height = 0; |
| 2194 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2195 | mWmService.mDisplayWindowSettings.setForcedSize(this, width, height); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2196 | } |
| 2197 | |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 2198 | void getStableRect(Rect out) { |
| 2199 | out.set(mDisplayFrames.mStable); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 2200 | } |
| 2201 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2202 | void setStackOnDisplay(ActivityStack stack, int position) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2203 | if (DEBUG_STACK) Slog.d(TAG_WM, "Set stack=" + stack + " on displayId=" + mDisplayId); |
| 2204 | mTaskStackContainers.addChild(stack, position); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2207 | void moveStackToDisplay(ActivityStack stack, boolean onTop) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2208 | stack.reparent(mTaskStackContainers, onTop ? POSITION_TOP: POSITION_BOTTOM); |
| 2209 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2210 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2211 | // TODO(display-unify): No longer needed then. |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2212 | void removeStackFromDisplay(ActivityStack stack) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2213 | mTaskStackContainers.removeChild(stack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 2214 | } |
| 2215 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2216 | @Override |
| 2217 | protected void addChild(DisplayChildWindowContainer child, |
| 2218 | Comparator<DisplayChildWindowContainer> comparator) { |
| 2219 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2220 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2221 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2222 | @Override |
| 2223 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 2224 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2225 | } |
| 2226 | |
| 2227 | @Override |
| 2228 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2229 | // Only allow removal of direct children from this display if the display is in the process |
| 2230 | // of been removed. |
| 2231 | if (mRemovingDisplay) { |
| 2232 | super.removeChild(child); |
| 2233 | return; |
| 2234 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2235 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2236 | } |
| 2237 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2238 | @Override |
| 2239 | void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) { |
| 2240 | // Children of the display are statically ordered, so the real intention here is to perform |
| 2241 | // the operation on the display and not the static direct children. |
| 2242 | getParent().positionChildAt(position, this, includingParents); |
| 2243 | } |
| 2244 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2245 | void positionStackAt(int position, ActivityStack child, boolean includingParents) { |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 2246 | mTaskStackContainers.positionChildAt(position, child, includingParents); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 2247 | layoutAndAssignWindowLayersIfNeeded(); |
| 2248 | } |
| 2249 | |
Garfield Tan | 4f71c5a | 2018-10-10 10:12:02 -0700 | [diff] [blame] | 2250 | /** |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2251 | * Returns true if the input point is within an app window. |
| 2252 | */ |
| 2253 | boolean pointWithinAppWindow(int x, int y) { |
| 2254 | final int[] targetWindowType = {-1}; |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2255 | final PooledConsumer fn = PooledLambda.obtainConsumer((w, nonArg) -> { |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2256 | if (targetWindowType[0] != -1) { |
| 2257 | return; |
| 2258 | } |
| 2259 | |
| 2260 | if (w.isOnScreen() && w.isVisibleLw() && w.getFrameLw().contains(x, y)) { |
| 2261 | targetWindowType[0] = w.mAttrs.type; |
| 2262 | return; |
| 2263 | } |
| 2264 | }, PooledLambda.__(WindowState.class), mTmpRect); |
| 2265 | forAllWindows(fn, true /* traverseTopToBottom */); |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2266 | fn.recycle(); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2267 | return FIRST_APPLICATION_WINDOW <= targetWindowType[0] |
| 2268 | && targetWindowType[0] <= LAST_APPLICATION_WINDOW; |
| 2269 | } |
| 2270 | |
| 2271 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2272 | * 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] | 2273 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2274 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 2275 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2276 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2277 | mTmpTaskForResizePointSearchResult.reset(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2278 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2279 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2280 | if (!stack.getWindowConfiguration().canResizeTask()) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2281 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2282 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 2283 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2284 | stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult); |
| 2285 | if (mTmpTaskForResizePointSearchResult.searchDone) { |
| 2286 | return mTmpTaskForResizePointSearchResult.taskForResize; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2287 | } |
| 2288 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 2289 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2292 | void updateTouchExcludeRegion() { |
| 2293 | final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2294 | if (focusedTask == null) { |
| 2295 | mTouchExcludeRegion.setEmpty(); |
| 2296 | } else { |
| 2297 | mTouchExcludeRegion.set(mBaseDisplayRect); |
| 2298 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
| 2299 | mTmpRect2.setEmpty(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2300 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; |
| 2301 | --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2302 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2303 | stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion, |
| 2304 | mDisplayFrames.mContent, mTmpRect2); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2305 | } |
| 2306 | // 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] | 2307 | // outside touch area in the exclusion. TapDetector is not interested in |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2308 | // any touch inside the focused task itself. |
| 2309 | if (!mTmpRect2.isEmpty()) { |
| 2310 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 2311 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2312 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2313 | if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) { |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2314 | // If the input method is visible and the user is typing, we don't want these touch |
| 2315 | // events to be intercepted and used to change focus. This would likely cause a |
| 2316 | // disappearance of the input method. |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2317 | mInputMethodWindow.getTouchableRegion(mTmpRegion); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2318 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2319 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2320 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 2321 | final WindowState win = mTapExcludedWindows.get(i); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2322 | win.getTouchableRegion(mTmpRegion); |
| 2323 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 2324 | } |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2325 | amendWindowTapExcludeRegion(mTouchExcludeRegion); |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 2326 | // TODO(multi-display): Support docked stacks on secondary displays. |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2327 | if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) { |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2328 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 2329 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2330 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 2331 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2332 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2335 | /** |
| 2336 | * Union the region with all the tap exclude region provided by windows on this display. |
| 2337 | * |
| 2338 | * @param inOutRegion The region to be amended. |
| 2339 | */ |
| 2340 | void amendWindowTapExcludeRegion(Region inOutRegion) { |
| 2341 | for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) { |
| 2342 | final WindowState win = mTapExcludeProvidingWindows.valueAt(i); |
| 2343 | win.amendTapExcludeRegion(inOutRegion); |
| 2344 | } |
| 2345 | } |
| 2346 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2347 | @Override |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2348 | void switchUser(int userId) { |
| 2349 | super.switchUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2350 | mWmService.mWindowsChanged = true; |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2351 | mDisplayPolicy.switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2354 | @Override |
| 2355 | void removeIfPossible() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2356 | if (isAnimating(TRANSITION | PARENTS)) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2357 | mDeferredRemoval = true; |
| 2358 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2359 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2360 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2363 | @Override |
| 2364 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2365 | mRemovingDisplay = true; |
| 2366 | try { |
Riddle Hsu | 6b76cd3 | 2019-10-08 00:37:19 +0800 | [diff] [blame] | 2367 | if (mActivityDisplay != null) { |
| 2368 | mActivityDisplay.unregisterConfigurationChangeListener(this); |
| 2369 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 2370 | if (mParentWindow != null) { |
| 2371 | mParentWindow.removeEmbeddedDisplayContent(this); |
| 2372 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2373 | // Clear all transitions & screen frozen states when removing display. |
| 2374 | mOpeningApps.clear(); |
| 2375 | mClosingApps.clear(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 2376 | mChangingApps.clear(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2377 | mUnknownAppVisibilityController.clear(); |
| 2378 | mAppTransition.removeAppTransitionTimeoutCallbacks(); |
| 2379 | handleAnimatingStoppedAndTransition(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2380 | mWmService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2381 | super.removeImmediately(); |
| 2382 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2383 | mPointerEventDispatcher.dispose(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2384 | setRotationAnimation(null); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2385 | mWmService.mAnimator.removeDisplayLocked(mDisplayId); |
Louis Chang | 207f911 | 2018-07-30 08:58:54 +0800 | [diff] [blame] | 2386 | mWindowingLayer.release(); |
| 2387 | mOverlayLayer.release(); |
Jorim Jaggi | ae962e6 | 2018-12-27 17:23:48 +0100 | [diff] [blame] | 2388 | mInputMonitor.onDisplayRemoved(); |
Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 2389 | mWmService.mDisplayNotificationController.dispatchDisplayRemoved(mActivityDisplay); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2390 | } finally { |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 2391 | mDisplayReady = false; |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2392 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2393 | } |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 2394 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2395 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2396 | } |
| 2397 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2398 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2399 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2400 | boolean checkCompleteDeferredRemoval() { |
Riddle Hsu | 793442c5 | 2019-11-05 01:04:55 +0800 | [diff] [blame] | 2401 | boolean stillDeferringRemoval = false; |
| 2402 | |
| 2403 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 2404 | final DisplayChildWindowContainer child = getChildAt(i); |
| 2405 | stillDeferringRemoval |= child.checkCompleteDeferredRemoval(); |
| 2406 | if (getChildCount() == 0) { |
| 2407 | // If this display is pending to be removed because it contains an activity with |
| 2408 | // {@link ActivityRecord#mIsExiting} is true, this display may be removed when |
| 2409 | // completing the removal of the last activity from |
| 2410 | // {@link ActivityRecord#checkCompleteDeferredRemoval}. |
| 2411 | return false; |
| 2412 | } |
| 2413 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2414 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2415 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2416 | removeImmediately(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2417 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2418 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2419 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2420 | } |
| 2421 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 2422 | /** @return 'true' if removal of this display content is deferred due to active animation. */ |
| 2423 | boolean isRemovalDeferred() { |
| 2424 | return mDeferredRemoval; |
| 2425 | } |
| 2426 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2427 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 2428 | float dividerAnimationTarget) { |
| 2429 | boolean updated = false; |
| 2430 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2431 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2432 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2433 | if (stack == null || !stack.isAdjustedForIme()) { |
| 2434 | continue; |
| 2435 | } |
| 2436 | |
| 2437 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 2438 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2439 | updated = true; |
| 2440 | } else { |
| 2441 | mDividerControllerLocked.mLastAnimationProgress = |
| 2442 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 2443 | mDividerControllerLocked.mLastDividerProgress = |
| 2444 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 2445 | updated |= stack.updateAdjustForIme( |
| 2446 | mDividerControllerLocked.mLastAnimationProgress, |
| 2447 | mDividerControllerLocked.mLastDividerProgress, |
| 2448 | false /* force */); |
| 2449 | } |
| 2450 | if (interpolatedValue >= 1f) { |
| 2451 | stack.endImeAdjustAnimation(); |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | return updated; |
| 2456 | } |
| 2457 | |
| 2458 | boolean clearImeAdjustAnimation() { |
| 2459 | boolean changed = false; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2460 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2461 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2462 | if (stack != null && stack.isAdjustedForIme()) { |
| 2463 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2464 | changed = true; |
| 2465 | } |
| 2466 | } |
| 2467 | return changed; |
| 2468 | } |
| 2469 | |
| 2470 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2471 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2472 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2473 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 2474 | stack.beginImeAdjustAnimation(); |
| 2475 | } |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | void adjustForImeIfNeeded() { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2480 | final WindowState imeWin = mInputMethodWindow; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2481 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 2482 | && !mDividerControllerLocked.isImeHideRequested(); |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2483 | final ActivityStack dockedStack = getSplitScreenPrimaryStack(); |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2484 | final boolean dockVisible = dockedStack != null; |
| 2485 | final Task topDockedTask = dockVisible ? dockedStack.getTopChild() : null; |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2486 | final ActivityStack imeTargetStack = mWmService.getImeFocusStackLocked(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2487 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 2488 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 2489 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 2490 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2491 | final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2492 | final boolean imeHeightChanged = imeVisible && |
| 2493 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 2494 | |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2495 | // This includes a case where the docked stack is unminimizing and IME is visible for the |
| 2496 | // bottom side stack. The condition prevents adjusting the override task bounds for IME to |
| 2497 | // the minimized docked stack bounds. |
| 2498 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock() |
| 2499 | || (topDockedTask != null && imeOnBottom && !dockedStack.isAdjustedForIme() |
| 2500 | && dockedStack.getBounds().height() < topDockedTask.getBounds().height()); |
| 2501 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2502 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 2503 | // or both. There are three possible cases: |
| 2504 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 2505 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 2506 | // - If IME is not visible, divider is not moved and is normal width. |
| 2507 | |
| 2508 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2509 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2510 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2511 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2512 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom) |
| 2513 | && stack.inSplitScreenWindowingMode()) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2514 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 2515 | } else { |
| 2516 | stack.resetAdjustedForIme(false); |
| 2517 | } |
| 2518 | } |
| 2519 | mDividerControllerLocked.setAdjustedForIme( |
| 2520 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 2521 | } else { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2522 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2523 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2524 | stack.resetAdjustedForIme(!dockVisible); |
| 2525 | } |
| 2526 | mDividerControllerLocked.setAdjustedForIme( |
| 2527 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 2528 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2529 | mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2533 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2534 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2535 | stack.prepareFreezingTaskBounds(); |
| 2536 | } |
| 2537 | } |
| 2538 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2539 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2540 | getBounds(mTmpRect, newRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2541 | rotateBounds(mTmpRect, oldRotation, newRotation, bounds); |
| 2542 | } |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2543 | |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2544 | void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2545 | // Compute a transform matrix to undo the coordinate space transformation, |
| 2546 | // and present the window at the same physical position it previously occupied. |
| 2547 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2548 | createRotationMatrix( |
| 2549 | deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2550 | |
| 2551 | mTmpRectF.set(bounds); |
| 2552 | mTmpMatrix.mapRect(mTmpRectF); |
| 2553 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 2556 | static int deltaRotation(int oldRotation, int newRotation) { |
| 2557 | int delta = newRotation - oldRotation; |
| 2558 | if (delta < 0) delta += 4; |
| 2559 | return delta; |
| 2560 | } |
| 2561 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2562 | public void setRotationAnimation(ScreenRotationAnimation screenRotationAnimation) { |
| 2563 | if (mScreenRotationAnimation != null) { |
| 2564 | mScreenRotationAnimation.kill(); |
| 2565 | } |
| 2566 | mScreenRotationAnimation = screenRotationAnimation; |
| 2567 | } |
| 2568 | |
| 2569 | public ScreenRotationAnimation getRotationAnimation() { |
| 2570 | return mScreenRotationAnimation; |
| 2571 | } |
| 2572 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2573 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2574 | Matrix outMatrix) { |
| 2575 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 2576 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 2577 | displayHeight, outMatrix); |
| 2578 | } |
| 2579 | |
| 2580 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 2581 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 2582 | switch (rotation) { |
| 2583 | case ROTATION_0: |
| 2584 | outMatrix.reset(); |
| 2585 | break; |
| 2586 | case ROTATION_270: |
| 2587 | outMatrix.setRotate(270, 0, 0); |
| 2588 | outMatrix.postTranslate(0, displayHeight); |
| 2589 | outMatrix.postTranslate(rectTop, 0); |
| 2590 | break; |
| 2591 | case ROTATION_180: |
| 2592 | outMatrix.reset(); |
| 2593 | break; |
| 2594 | case ROTATION_90: |
| 2595 | outMatrix.setRotate(90, 0, 0); |
| 2596 | outMatrix.postTranslate(displayWidth, 0); |
| 2597 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 2598 | break; |
| 2599 | } |
| 2600 | } |
| 2601 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 2602 | @CallSuper |
| 2603 | @Override |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2604 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 2605 | @WindowTraceLogLevel int logLevel) { |
| 2606 | // Critical log level logs only visible elements to mitigate performance overheard |
| 2607 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 2608 | return; |
| 2609 | } |
| 2610 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2611 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2612 | super.writeToProto(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2613 | proto.write(ID, mDisplayId); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2614 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2615 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2616 | stack.writeToProtoInnerStackOnly(proto, STACKS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2617 | } |
| 2618 | mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER); |
| 2619 | mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2620 | for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2621 | final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2622 | windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2623 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2624 | for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2625 | final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2626 | windowToken.writeToProto(proto, BELOW_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2627 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2628 | for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2629 | final WindowToken windowToken = mImeWindowsContainers.getChildAt(i); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2630 | windowToken.writeToProto(proto, IME_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2631 | } |
| 2632 | proto.write(DPI, mBaseDisplayDensity); |
| 2633 | mDisplayInfo.writeToProto(proto, DISPLAY_INFO); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2634 | proto.write(ROTATION, getRotation()); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2635 | final ScreenRotationAnimation screenRotationAnimation = getRotationAnimation(); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2636 | if (screenRotationAnimation != null) { |
| 2637 | screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION); |
| 2638 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2639 | mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2640 | mAppTransition.writeToProto(proto, APP_TRANSITION); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2641 | if (mFocusedApp != null) { |
| 2642 | mFocusedApp.writeNameToProto(proto, FOCUSED_APP); |
| 2643 | } |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2644 | for (int i = mOpeningApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2645 | mOpeningApps.valueAt(i).writeIdentifierToProto(proto, OPENING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2646 | } |
| 2647 | for (int i = mClosingApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2648 | mClosingApps.valueAt(i).writeIdentifierToProto(proto, CLOSING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2649 | } |
| 2650 | for (int i = mChangingApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2651 | mChangingApps.valueAt(i).writeIdentifierToProto(proto, CHANGING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2652 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2653 | proto.end(token); |
| 2654 | } |
| 2655 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2656 | @Override |
| 2657 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 2658 | super.dump(pw, prefix, dumpAll); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2659 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 2660 | final String subPrefix = " " + prefix; |
| 2661 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 2662 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 2663 | pw.print("dpi"); |
| 2664 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 2665 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 2666 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 2667 | pw.print(" base="); |
| 2668 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 2669 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 2670 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 2671 | if (mDisplayScalingDisabled) { |
| 2672 | pw.println(" noscale"); |
| 2673 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2674 | pw.print(" cur="); |
| 2675 | pw.print(mDisplayInfo.logicalWidth); |
| 2676 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 2677 | pw.print(" app="); |
| 2678 | pw.print(mDisplayInfo.appWidth); |
| 2679 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 2680 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 2681 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 2682 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 2683 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2684 | pw.print(subPrefix + "deferred=" + mDeferredRemoval |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 2685 | + " mLayoutNeeded=" + mLayoutNeeded); |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2686 | pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2687 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2688 | pw.println(); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2689 | pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq); |
| 2690 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2691 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 2692 | if (mLastFocus != mCurrentFocus) { |
| 2693 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 2694 | } |
| 2695 | if (mLosingFocus.size() > 0) { |
| 2696 | pw.println(); |
| 2697 | pw.println(" Windows losing focus:"); |
| 2698 | for (int i = mLosingFocus.size() - 1; i >= 0; i--) { |
| 2699 | final WindowState w = mLosingFocus.get(i); |
| 2700 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 2701 | pw.print(w); |
| 2702 | if (dumpAll) { |
| 2703 | pw.println(":"); |
| 2704 | w.dump(pw, " ", true); |
| 2705 | } else { |
| 2706 | pw.println(); |
| 2707 | } |
| 2708 | } |
| 2709 | } |
| 2710 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2711 | if (mLastStatusBarVisibility != 0) { |
| 2712 | pw.print(" mLastStatusBarVisibility=0x"); |
| 2713 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 2714 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2715 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2716 | pw.println(); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 2717 | mWallpaperController.dump(pw, " "); |
| 2718 | |
| 2719 | pw.println(); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 2720 | pw.print("mSystemGestureExclusion="); |
| 2721 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() > 0) { |
| 2722 | pw.println(mSystemGestureExclusion); |
| 2723 | } else { |
| 2724 | pw.println("<no lstnrs>"); |
| 2725 | } |
| 2726 | |
| 2727 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2728 | pw.println(prefix + "Application tokens in top down Z order:"); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2729 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2730 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2731 | stack.dump(pw, prefix + " ", dumpAll); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2732 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2733 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2734 | pw.println(); |
| 2735 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2736 | pw.println(); |
| 2737 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2738 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2739 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2740 | pw.print(" Exiting #"); pw.print(i); |
| 2741 | pw.print(' '); pw.print(token); |
| 2742 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2743 | token.dump(pw, " ", dumpAll); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2744 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2745 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 2746 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2747 | final ScreenRotationAnimation rotationAnimation = getRotationAnimation(); |
| 2748 | if (rotationAnimation != null) { |
| 2749 | pw.print(subPrefix); |
| 2750 | pw.println(" mScreenRotationAnimation:"); |
| 2751 | rotationAnimation.printTo(" ", pw); |
| 2752 | } else if (dumpAll) { |
| 2753 | pw.print(subPrefix); |
| 2754 | pw.println(" no ScreenRotationAnimation "); |
| 2755 | } |
| 2756 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 2757 | pw.println(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2758 | |
| 2759 | // Dump stack references |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2760 | final ActivityStack homeStack = getHomeStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2761 | if (homeStack != null) { |
| 2762 | pw.println(prefix + "homeStack=" + homeStack.getName()); |
| 2763 | } |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2764 | final ActivityStack pinnedStack = getPinnedStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2765 | if (pinnedStack != null) { |
| 2766 | pw.println(prefix + "pinnedStack=" + pinnedStack.getName()); |
| 2767 | } |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2768 | final ActivityStack splitScreenPrimaryStack = getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2769 | if (splitScreenPrimaryStack != null) { |
| 2770 | pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName()); |
| 2771 | } |
| 2772 | |
| 2773 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2774 | mDividerControllerLocked.dump(prefix, pw); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2775 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2776 | mPinnedStackControllerLocked.dump(prefix, pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2777 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2778 | pw.println(); |
| 2779 | mDisplayFrames.dump(prefix, pw); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2780 | pw.println(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2781 | mDisplayPolicy.dump(prefix, pw); |
| 2782 | pw.println(); |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2783 | mDisplayRotation.dump(prefix, pw); |
| 2784 | pw.println(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2785 | mInputMonitor.dump(pw, " "); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 2786 | pw.println(); |
| 2787 | mInsetsStateController.dump(prefix, pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2788 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2789 | |
| 2790 | @Override |
| 2791 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2792 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2796 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2797 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2798 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2799 | /** Returns true if the stack in the windowing mode is visible. */ |
| 2800 | boolean isStackVisible(int windowingMode) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2801 | final ActivityStack stack = getTopStackInWindowingMode(windowingMode); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2802 | return stack != null && stack.isVisible(); |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 2803 | } |
| 2804 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2805 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2806 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2807 | final int x = (int) xf; |
| 2808 | final int y = (int) yf; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2809 | final WindowState touchedWin = getWindow(w -> { |
| 2810 | final int flags = w.mAttrs.flags; |
| 2811 | if (!w.isVisibleLw()) { |
| 2812 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2813 | } |
| 2814 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2815 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2816 | } |
| 2817 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2818 | w.getVisibleBounds(mTmpRect); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2819 | if (!mTmpRect.contains(x, y)) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2820 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2821 | } |
| 2822 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2823 | w.getTouchableRegion(mTmpRegion); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2824 | |
| 2825 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2826 | return mTmpRegion.contains(x, y) || touchFlags == 0; |
| 2827 | }); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2828 | |
| 2829 | return touchedWin; |
| 2830 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 2831 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2832 | boolean canAddToastWindowForUid(int uid) { |
| 2833 | // We allow one toast window per UID being shown at a time. |
Svet Ganov | daca8ee | 2017-01-21 17:40:40 -0800 | [diff] [blame] | 2834 | // Also if the app is focused adding more than one toast at |
| 2835 | // a time for better backwards compatibility. |
| 2836 | final WindowState focusedWindowForUid = getWindow(w -> |
| 2837 | w.mOwnerUid == uid && w.isFocused()); |
| 2838 | if (focusedWindowForUid != null) { |
| 2839 | return true; |
| 2840 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2841 | final WindowState win = getWindow(w -> |
| 2842 | w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden |
| 2843 | && !w.mWindowRemovalAllowed); |
| 2844 | return win == null; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2847 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2848 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 2849 | return; |
| 2850 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2851 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2852 | // Used to communicate the old focus to the callback method. |
| 2853 | mTmpWindow = oldFocus; |
| 2854 | |
| 2855 | forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2856 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2857 | |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2858 | /** |
| 2859 | * Looking for the focused window on this display if the top focused display hasn't been |
| 2860 | * found yet (topFocusedDisplayId is INVALID_DISPLAY) or per-display focused was allowed. |
| 2861 | * |
| 2862 | * @param topFocusedDisplayId Id of the top focused display. |
| 2863 | * @return The focused window or null if there isn't any or no need to seek. |
| 2864 | */ |
| 2865 | WindowState findFocusedWindowIfNeeded(int topFocusedDisplayId) { |
| 2866 | return (mWmService.mPerDisplayFocusEnabled || topFocusedDisplayId == INVALID_DISPLAY) |
| 2867 | ? findFocusedWindow() : null; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2868 | } |
| 2869 | |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2870 | WindowState findFocusedWindow() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2871 | mTmpWindow = null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2872 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2873 | forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2874 | |
| 2875 | if (mTmpWindow == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2876 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: No focusable windows."); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2877 | return null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2878 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2879 | return mTmpWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2882 | /** |
| 2883 | * Update the focused window and make some adjustments if the focus has changed. |
| 2884 | * |
| 2885 | * @param mode Indicates the situation we are in. Possible modes are: |
| 2886 | * {@link WindowManagerService#UPDATE_FOCUS_NORMAL}, |
| 2887 | * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES}, |
| 2888 | * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES}, |
| 2889 | * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS} |
| 2890 | * @param updateInputWindows Whether to sync the window information to the input module. |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2891 | * @param topFocusedDisplayId Display id of current top focused display. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2892 | * @return {@code true} if the focused window has changed. |
| 2893 | */ |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2894 | boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, |
| 2895 | int topFocusedDisplayId) { |
| 2896 | WindowState newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2897 | if (mCurrentFocus == newFocus) { |
| 2898 | return false; |
| 2899 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2900 | boolean imWindowChanged = false; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2901 | final WindowState imWindow = mInputMethodWindow; |
| 2902 | if (imWindow != null) { |
| 2903 | final WindowState prevTarget = mInputMethodTarget; |
| 2904 | final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/); |
| 2905 | imWindowChanged = prevTarget != newTarget; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2906 | |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2907 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS |
| 2908 | && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 2909 | assignWindowLayers(false /* setLayoutNeeded */); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | if (imWindowChanged) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2914 | mWmService.mWindowsChanged = true; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2915 | setLayoutNeeded(); |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2916 | newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2917 | } |
| 2918 | if (mCurrentFocus != newFocus) { |
| 2919 | mWmService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2920 | } |
| 2921 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2922 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "Changing focus from %s to %s displayId=%d Callers=%s", |
| 2923 | mCurrentFocus, newFocus, getDisplayId(), Debug.getCallers(4)); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2924 | final WindowState oldFocus = mCurrentFocus; |
| 2925 | mCurrentFocus = newFocus; |
| 2926 | mLosingFocus.remove(newFocus); |
| 2927 | |
| 2928 | if (newFocus != null) { |
| 2929 | mWinAddedSinceNullFocus.clear(); |
| 2930 | mWinRemovedSinceNullFocus.clear(); |
| 2931 | |
| 2932 | if (newFocus.canReceiveKeys()) { |
| 2933 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 2934 | // This is to protect against bugs if someone pauses dispatching but |
| 2935 | // forgets to resume. |
| 2936 | newFocus.mToken.paused = false; |
| 2937 | } |
| 2938 | } |
| 2939 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2940 | int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2941 | |
| 2942 | if (imWindowChanged && oldFocus != mInputMethodWindow) { |
| 2943 | // Focus of the input method window changed. Perform layout if needed. |
| 2944 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 2945 | performLayout(true /*initial*/, updateInputWindows); |
| 2946 | focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT; |
| 2947 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 2948 | // Client will do the layout, but we need to assign layers |
| 2949 | // for handleNewWindowLocked() below. |
| 2950 | assignWindowLayers(false /* setLayoutNeeded */); |
| 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 2955 | // The change in focus caused us to need to do a layout. Okay. |
| 2956 | setLayoutNeeded(); |
| 2957 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 2958 | performLayout(true /*initial*/, updateInputWindows); |
| 2959 | } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2960 | mWmService.mRoot.performSurfacePlacement(false); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 2965 | // If we defer assigning layers, then the caller is responsible for doing this part. |
| 2966 | getInputMonitor().setInputFocusLw(newFocus, updateInputWindows); |
| 2967 | } |
| 2968 | |
| 2969 | adjustForImeIfNeeded(); |
| 2970 | |
| 2971 | // We may need to schedule some toast windows to be removed. The toasts for an app that |
| 2972 | // does not have input focus are removed within a timeout to prevent apps to redress |
| 2973 | // other apps' UI. |
| 2974 | scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus); |
| 2975 | |
| 2976 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 2977 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 2978 | } |
| 2979 | return true; |
| 2980 | } |
| 2981 | |
| 2982 | /** |
| 2983 | * Set the new focused app to this display. |
| 2984 | * |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2985 | * @param newFocus the new focused {@link ActivityRecord}. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2986 | * @return true if the focused app is changed. |
| 2987 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2988 | boolean setFocusedApp(ActivityRecord newFocus) { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2989 | if (newFocus != null) { |
| 2990 | final DisplayContent appDisplay = newFocus.getDisplayContent(); |
| 2991 | if (appDisplay != this) { |
| 2992 | throw new IllegalStateException(newFocus + " is not on " + getName() |
| 2993 | + " but " + ((appDisplay != null) ? appDisplay.getName() : "none")); |
| 2994 | } |
| 2995 | } |
| 2996 | if (mFocusedApp == newFocus) { |
| 2997 | return false; |
| 2998 | } |
| 2999 | mFocusedApp = newFocus; |
| 3000 | getInputMonitor().setFocusedAppLw(newFocus); |
| 3001 | updateTouchExcludeRegion(); |
| 3002 | return true; |
| 3003 | } |
| 3004 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3005 | /** Updates the layer assignment of windows on this display. */ |
| 3006 | void assignWindowLayers(boolean setLayoutNeeded) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3007 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers"); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3008 | assignChildLayers(getPendingTransaction()); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3009 | if (setLayoutNeeded) { |
| 3010 | setLayoutNeeded(); |
| 3011 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3012 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3013 | // We accumlate the layer changes in-to "getPendingTransaction()" but we defer |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3014 | // the application of this transaction until the animation pass triggers |
| 3015 | // prepareSurfaces. This allows us to synchronize Z-ordering changes with |
| 3016 | // the hiding and showing of surfaces. |
| 3017 | scheduleAnimation(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3018 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3021 | // TODO: This should probably be called any time a visual change is made to the hierarchy like |
| 3022 | // moving containers or resizing them. Need to investigate the best way to have it automatically |
| 3023 | // 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] | 3024 | void layoutAndAssignWindowLayersIfNeeded() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3025 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3026 | setLayoutNeeded(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3027 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3028 | if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3029 | false /*updateInputWindows*/)) { |
| 3030 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3031 | } |
| 3032 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3033 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3034 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3035 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3038 | /** Returns true if a leaked surface was destroyed */ |
| 3039 | boolean destroyLeakedSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3040 | // Used to indicate that a surface was leaked. |
| 3041 | mTmpWindow = null; |
| 3042 | forAllWindows(w -> { |
| 3043 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3044 | if (wsa.mSurfaceController == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3045 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3046 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3047 | if (!mWmService.mSessions.contains(wsa.mSession)) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3048 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3049 | + w + " surface=" + wsa.mSurfaceController |
| 3050 | + " token=" + w.mToken |
| 3051 | + " pid=" + w.mSession.mPid |
| 3052 | + " uid=" + w.mSession.mUid); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3053 | wsa.destroySurface(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3054 | mWmService.mForceRemoves.add(w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3055 | mTmpWindow = w; |
Issei Suzuki | e63eac7 | 2019-11-14 15:59:15 +0100 | [diff] [blame] | 3056 | } else if (w.mActivityRecord != null && w.mActivityRecord.isClientHidden()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3057 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3058 | + w + " surface=" + wsa.mSurfaceController |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3059 | + " token=" + w.mActivityRecord); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3060 | ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE LEAK DESTROY: %s", w); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3061 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3062 | mTmpWindow = w; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3063 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3064 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3065 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3066 | return mTmpWindow != null; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3067 | } |
| 3068 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3069 | boolean hasAlertWindowSurfaces() { |
| 3070 | for (int i = mWmService.mSessions.size() - 1; i >= 0; --i) { |
| 3071 | if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces(this)) { |
| 3072 | return true; |
| 3073 | } |
| 3074 | } |
| 3075 | return false; |
| 3076 | } |
| 3077 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3078 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3079 | * Set input method window for the display. |
| 3080 | * @param win Set when window added or Null when destroyed. |
| 3081 | */ |
| 3082 | void setInputMethodWindowLocked(WindowState win) { |
| 3083 | mInputMethodWindow = win; |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3084 | // Update display configuration for IME process. |
| 3085 | if (mInputMethodWindow != null) { |
| 3086 | final int imePid = mInputMethodWindow.mSession.mPid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3087 | mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid, |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3088 | mInputMethodWindow.getDisplayId()); |
| 3089 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3090 | computeImeTarget(true /* updateImeTarget */); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3091 | mInsetsStateController.getSourceProvider(TYPE_IME).setWindow(win, |
| 3092 | null /* frameProvider */); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | /** |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3096 | * Determine and return the window that should be the IME target. |
| 3097 | * @param updateImeTarget If true the system IME target will be updated to match what we found. |
| 3098 | * @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] | 3099 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3100 | WindowState computeImeTarget(boolean updateImeTarget) { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3101 | if (mInputMethodWindow == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3102 | // There isn't an IME so there shouldn't be a target...That was easy! |
| 3103 | if (updateImeTarget) { |
| 3104 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3105 | + mInputMethodTarget + " to null since mInputMethodWindow is null"); |
| 3106 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3107 | } |
| 3108 | return null; |
| 3109 | } |
| 3110 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3111 | final WindowState curTarget = mInputMethodTarget; |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 3112 | if (!canUpdateImeTarget()) { |
| 3113 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target"); |
| 3114 | return curTarget; |
| 3115 | } |
| 3116 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3117 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 3118 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 3119 | // 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] | 3120 | mUpdateImeTarget = updateImeTarget; |
| 3121 | WindowState target = getWindow(mComputeImeTargetPredicate); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3122 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3123 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3124 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 3125 | // to be on top of it, but it is not -really- where input will go. So look down below |
| 3126 | // for a real window to target... |
| 3127 | if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3128 | final ActivityRecord activity = target.mActivityRecord; |
| 3129 | if (activity != null) { |
| 3130 | final WindowState betterTarget = activity.getImeTargetBelowWindow(target); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3131 | if (betterTarget != null) { |
| 3132 | target = betterTarget; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3133 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3134 | } |
| 3135 | } |
| 3136 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3137 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM, |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3138 | "Proposed new IME target: " + target + " for display: " + getDisplayId()); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3139 | |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3140 | // 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] | 3141 | // not removed, keep on the last target to avoid IME flicker. |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3142 | if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw() |
Tarandeep Singh | 2d0aca4 | 2019-03-28 14:08:58 -0700 | [diff] [blame] | 3143 | && curTarget.isClosing()) { |
| 3144 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Not changing target till current window is" |
| 3145 | + " closing and not removed"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3146 | return curTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3149 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target |
| 3150 | + " updateImeTarget=" + updateImeTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3151 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3152 | if (target == null) { |
| 3153 | if (updateImeTarget) { |
| 3154 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 3155 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" |
| 3156 | + Debug.getCallers(4) : "")); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3157 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | return null; |
| 3161 | } |
| 3162 | |
| 3163 | if (updateImeTarget) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3164 | ActivityRecord activity = curTarget == null ? null : curTarget.mActivityRecord; |
| 3165 | if (activity != null) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3166 | |
| 3167 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 3168 | // to look at all windows below the current target that are in this app, finding the |
| 3169 | // highest visible one in layering. |
| 3170 | WindowState highestTarget = null; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3171 | if (activity.isAnimating(TRANSITION)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3172 | highestTarget = activity.getHighestAnimLayerWindow(curTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | if (highestTarget != null) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3176 | if (DEBUG_INPUT_METHOD) { |
| 3177 | Slog.v(TAG_WM, mAppTransition + " " + highestTarget + " animating=" |
| 3178 | + highestTarget.isAnimating(TRANSITION | PARENTS)); |
| 3179 | } |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3180 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3181 | if (mAppTransition.isTransitionSet()) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3182 | // If we are currently setting up for an animation, hold everything until we |
| 3183 | // can find out what will happen. |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3184 | setInputMethodTarget(highestTarget, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3185 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3186 | } |
| 3187 | } |
| 3188 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3189 | |
| 3190 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 3191 | + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3192 | setInputMethodTarget(target, false); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3195 | return target; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3198 | /** |
| 3199 | * Calling {@link #computeImeTarget(boolean)} to update the input method target window in |
| 3200 | * the candidate app window token if needed. |
| 3201 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3202 | void computeImeTargetIfNeeded(ActivityRecord candidate) { |
| 3203 | if (mInputMethodTarget != null && mInputMethodTarget.mActivityRecord == candidate) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3204 | computeImeTarget(true /* updateImeTarget */); |
| 3205 | } |
| 3206 | } |
| 3207 | |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3208 | private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3209 | if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3210 | return; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3213 | mInputMethodTarget = target; |
| 3214 | mInputMethodTargetWaitingAnim = targetWaitingAnim; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3215 | assignWindowLayers(false /* setLayoutNeeded */); |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 3216 | mInsetsStateController.onImeTargetChanged(target); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3217 | updateImeParent(); |
| 3218 | } |
| 3219 | |
| 3220 | private void updateImeParent() { |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 3221 | // Force attaching IME to the display when magnifying, or it would be magnified with |
| 3222 | // target app together. |
| 3223 | final boolean shouldAttachToDisplay = (mMagnificationSpec != null); |
| 3224 | final SurfaceControl newParent = |
| 3225 | shouldAttachToDisplay ? mWindowingLayer : computeImeParent(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3226 | if (newParent != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3227 | getPendingTransaction().reparent(mImeWindowsContainers.mSurfaceControl, newParent); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3228 | scheduleAnimation(); |
| 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | /** |
| 3233 | * Computes the window the IME should be attached to. |
| 3234 | */ |
| 3235 | @VisibleForTesting |
| 3236 | SurfaceControl computeImeParent() { |
| 3237 | |
| 3238 | // Attach it to app if the target is part of an app and such app is covering the entire |
| 3239 | // screen. If it's not covering the entire screen the IME might extend beyond the apps |
| 3240 | // bounds. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3241 | if (mInputMethodTarget != null && mInputMethodTarget.mActivityRecord != null |
Riddle Hsu | 6d6f67c | 2019-03-14 16:54:26 +0800 | [diff] [blame] | 3242 | && mInputMethodTarget.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 3243 | // An activity with override bounds should be letterboxed inside its parent bounds, |
| 3244 | // so it doesn't fill the screen. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3245 | && mInputMethodTarget.mActivityRecord.matchParentBounds()) { |
| 3246 | return mInputMethodTarget.mActivityRecord.getSurfaceControl(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | // Otherwise, we just attach it to the display. |
| 3250 | return mWindowingLayer; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) { |
| 3254 | if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 3255 | return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
| 3256 | } |
| 3257 | |
| 3258 | // Used to indicate we have reached the first window in the range we are interested in. |
| 3259 | mTmpWindow = null; |
| 3260 | |
| 3261 | // TODO: Figure-out a more efficient way to do this. |
| 3262 | final WindowState candidate = getWindow(w -> { |
| 3263 | if (w == top) { |
| 3264 | // Reached the first window in the range we are interested in. |
| 3265 | mTmpWindow = w; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3266 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3267 | if (mTmpWindow == null) { |
| 3268 | return false; |
| 3269 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3270 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3271 | if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 3272 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3273 | } |
| 3274 | // If we reached the bottom of the range of windows we are considering, |
| 3275 | // assume no menu is needed. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3276 | if (w == bottom) { |
| 3277 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3278 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3279 | return false; |
| 3280 | }); |
| 3281 | |
| 3282 | return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3283 | } |
| 3284 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3285 | void setLayoutNeeded() { |
| 3286 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3287 | mLayoutNeeded = true; |
| 3288 | } |
| 3289 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3290 | private void clearLayoutNeeded() { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3291 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3292 | mLayoutNeeded = false; |
| 3293 | } |
| 3294 | |
| 3295 | boolean isLayoutNeeded() { |
| 3296 | return mLayoutNeeded; |
| 3297 | } |
| 3298 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3299 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 3300 | if (mTokenMap.isEmpty()) { |
| 3301 | return; |
| 3302 | } |
| 3303 | pw.println(" Display #" + mDisplayId); |
| 3304 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 3305 | while (it.hasNext()) { |
| 3306 | final WindowToken token = it.next(); |
| 3307 | pw.print(" "); |
| 3308 | pw.print(token); |
| 3309 | if (dumpAll) { |
| 3310 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3311 | token.dump(pw, " ", dumpAll); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3312 | } else { |
| 3313 | pw.println(); |
| 3314 | } |
| 3315 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3316 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3317 | if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty() || !mChangingApps.isEmpty()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3318 | pw.println(); |
| 3319 | if (mOpeningApps.size() > 0) { |
| 3320 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 3321 | } |
| 3322 | if (mClosingApps.size() > 0) { |
| 3323 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 3324 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3325 | if (mChangingApps.size() > 0) { |
| 3326 | pw.print(" mChangingApps="); pw.println(mChangingApps); |
| 3327 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | mUnknownAppVisibilityController.dump(pw, " "); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3333 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3334 | final int[] index = new int[1]; |
| 3335 | forAllWindows(w -> { |
| 3336 | final WindowStateAnimator wAnim = w.mWinAnimator; |
| 3337 | pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim); |
| 3338 | index[0] = index[0] + 1; |
| 3339 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3342 | /** |
| 3343 | * Starts the Keyguard exit animation on all windows that don't belong to an app token. |
| 3344 | */ |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3345 | void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade, |
| 3346 | boolean subtle) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3347 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3348 | forAllWindows(w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3349 | if (w.mActivityRecord == null && policy.canBeHiddenByKeyguardLw(w) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 3350 | && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) { |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3351 | w.startAnimation(policy.createHiddenByKeyguardExit( |
| 3352 | onWallpaper, goingToShade, subtle)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3353 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3354 | }, true /* traverseTopToBottom */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3355 | } |
| 3356 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3357 | /** @return {@code true} if there is window to wait before enabling the screen. */ |
| 3358 | boolean shouldWaitForSystemDecorWindowsOnBoot() { |
| 3359 | if (!isDefaultDisplay && !supportsSystemDecorations()) { |
| 3360 | // Nothing to wait because the secondary display doesn't support system decorations, |
| 3361 | // there is no wallpaper, keyguard (status bar) or application (home) window to show |
| 3362 | // during booting. |
| 3363 | return false; |
| 3364 | } |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3365 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3366 | final SparseBooleanArray drawnWindowTypes = new SparseBooleanArray(); |
| 3367 | // Presuppose keyguard is drawn because if its window isn't attached, we don't know if it |
| 3368 | // wants to be shown or hidden, then it should not delay enabling the screen. |
| 3369 | drawnWindowTypes.put(TYPE_STATUS_BAR, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3370 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3371 | final WindowState visibleNotDrawnWindow = getWindow(w -> { |
| 3372 | if (w.mViewVisibility == View.VISIBLE && !w.mObscured && !w.isDrawnLw()) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3373 | return true; |
| 3374 | } |
| 3375 | if (w.isDrawnLw()) { |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3376 | final int type = w.mAttrs.type; |
| 3377 | if (type == TYPE_BOOT_PROGRESS || type == TYPE_BASE_APPLICATION |
| 3378 | || type == TYPE_WALLPAPER) { |
| 3379 | drawnWindowTypes.put(type, true); |
| 3380 | } else if (type == TYPE_STATUS_BAR) { |
| 3381 | drawnWindowTypes.put(TYPE_STATUS_BAR, mWmService.mPolicy.isKeyguardDrawnLw()); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3382 | } |
| 3383 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3384 | return false; |
| 3385 | }); |
| 3386 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3387 | if (visibleNotDrawnWindow != null) { |
| 3388 | // Wait for the visible window to be drawn. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3389 | return true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3392 | // if the wallpaper service is disabled on the device, we're never going to have |
| 3393 | // wallpaper, don't bother waiting for it |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3394 | boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean( |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3395 | com.android.internal.R.bool.config_enableWallpaperService) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3396 | && mWmService.mContext.getResources().getBoolean( |
Daichi Hirono | c143222 | 2018-03-29 13:06:07 +0900 | [diff] [blame] | 3397 | com.android.internal.R.bool.config_checkWallpaperAtBoot) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3398 | && !mWmService.mOnlyCore; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3399 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3400 | final boolean haveBootMsg = drawnWindowTypes.get(TYPE_BOOT_PROGRESS); |
| 3401 | final boolean haveApp = drawnWindowTypes.get(TYPE_BASE_APPLICATION); |
| 3402 | final boolean haveWallpaper = drawnWindowTypes.get(TYPE_WALLPAPER); |
| 3403 | final boolean haveKeyguard = drawnWindowTypes.get(TYPE_STATUS_BAR); |
| 3404 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3405 | ProtoLog.i(WM_DEBUG_SCREEN_ON, |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3406 | "******** booted=%b msg=%b haveBoot=%b haveApp=%b haveWall=%b " |
| 3407 | + "wallEnabled=%b haveKeyguard=%b", |
| 3408 | mWmService.mSystemBooted, mWmService.mShowingBootMessages, haveBootMsg, |
| 3409 | haveApp, haveWallpaper, wallpaperEnabled, haveKeyguard); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3410 | |
| 3411 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 3412 | // message is actually displayed. |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3413 | if (!mWmService.mSystemBooted && !haveBootMsg) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3414 | return true; |
| 3415 | } |
| 3416 | |
| 3417 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 3418 | // we have the application and wallpaper. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3419 | if (mWmService.mSystemBooted |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3420 | && ((!haveApp && !haveKeyguard) || (wallpaperEnabled && !haveWallpaper))) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3421 | return true; |
| 3422 | } |
| 3423 | |
| 3424 | return false; |
| 3425 | } |
| 3426 | |
Jorim Jaggi | 8f52087 | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3427 | void updateWindowsForAnimator() { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3428 | forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3431 | boolean isInputMethodClientFocus(int uid, int pid) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3432 | final WindowState imFocus = computeImeTarget(false /* updateImeTarget */); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3433 | if (imFocus == null) { |
| 3434 | return false; |
| 3435 | } |
| 3436 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3437 | if (DEBUG_INPUT_METHOD) { |
| 3438 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3439 | Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId); |
| 3440 | Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3441 | } |
| 3442 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3443 | if (DEBUG_INPUT_METHOD) { |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3444 | Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid |
| 3445 | + "/" + imFocus.mSession.mPid); |
| 3446 | Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3449 | return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | boolean hasSecureWindowOnScreen() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3453 | final WindowState win = getWindow( |
| 3454 | w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0); |
| 3455 | return win != null; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3458 | void hideTransientBars() { |
| 3459 | // TODO(b/118118435): Remove this after migration |
| 3460 | final int transientFlags = View.STATUS_BAR_TRANSIENT | View.NAVIGATION_BAR_TRANSIENT; |
| 3461 | statusBarVisibilityChanged(mLastStatusBarVisibility & ~transientFlags); |
| 3462 | |
| 3463 | getInsetsPolicy().hideTransient(); |
| 3464 | } |
| 3465 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3466 | void statusBarVisibilityChanged(int visibility) { |
| 3467 | mLastStatusBarVisibility = visibility; |
| 3468 | visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility); |
| 3469 | updateStatusBarVisibilityLocked(visibility); |
| 3470 | } |
| 3471 | |
| 3472 | private boolean updateStatusBarVisibilityLocked(int visibility) { |
| 3473 | if (mLastDispatchedSystemUiVisibility == visibility) { |
| 3474 | return false; |
| 3475 | } |
| 3476 | final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility) |
| 3477 | // We are only interested in differences of one of the |
| 3478 | // clearable flags... |
| 3479 | & View.SYSTEM_UI_CLEARABLE_FLAGS |
| 3480 | // ...if it has actually been cleared. |
| 3481 | & ~visibility; |
| 3482 | |
| 3483 | mLastDispatchedSystemUiVisibility = visibility; |
| 3484 | if (isDefaultDisplay) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3485 | mWmService.mInputManager.setSystemUiVisibility(visibility); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3486 | } |
| 3487 | updateSystemUiVisibility(visibility, globalDiff); |
| 3488 | return true; |
| 3489 | } |
| 3490 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3491 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3492 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3493 | try { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3494 | final int curValue = w.mSystemUiVisibility; |
| 3495 | final int diff = (curValue ^ visibility) & globalDiff; |
| 3496 | final int newValue = (curValue & ~diff) | (visibility & diff); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3497 | if (newValue != curValue) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3498 | w.mSeq++; |
| 3499 | w.mSystemUiVisibility = newValue; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3500 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3501 | if (newValue != curValue || w.mAttrs.hasSystemUiListeners) { |
| 3502 | w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3503 | visibility, newValue, diff); |
| 3504 | } |
| 3505 | } catch (RemoteException e) { |
| 3506 | // so sorry |
| 3507 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3508 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3511 | void reevaluateStatusBarVisibility() { |
| 3512 | int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 3513 | if (updateStatusBarVisibilityLocked(visibility)) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3514 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3515 | } |
| 3516 | } |
| 3517 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3518 | void onWindowFreezeTimeout() { |
| 3519 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3520 | mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3521 | |
| 3522 | forAllWindows(w -> { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3523 | if (!w.getOrientationChanging()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3524 | return; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3525 | } |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 3526 | w.orientationChangeTimedOut(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3527 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3528 | - mWmService.mDisplayFreezeTime); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3529 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3530 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3531 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3534 | // TODO: Super crazy long method that should be broken down... |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3535 | void applySurfaceChangesTransaction(boolean recoveringMemory) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3536 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3537 | |
| 3538 | mTmpUpdateAllDrawn.clear(); |
| 3539 | |
| 3540 | int repeats = 0; |
| 3541 | do { |
| 3542 | repeats++; |
| 3543 | if (repeats > 6) { |
| 3544 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 3545 | clearLayoutNeeded(); |
| 3546 | break; |
| 3547 | } |
| 3548 | |
| 3549 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner", |
| 3550 | pendingLayoutChanges); |
| 3551 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 3552 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 3553 | mWallpaperController.adjustWallpaperWindows(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 3556 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3557 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3558 | if (updateOrientation()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3559 | setLayoutNeeded(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 3560 | sendNewConfiguration(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3565 | setLayoutNeeded(); |
| 3566 | } |
| 3567 | |
| 3568 | // FIRST LOOP: Perform a layout, if needed. |
| 3569 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 3570 | performLayout(repeats == 1, false /* updateInputWindows */); |
| 3571 | } else { |
| 3572 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 3573 | } |
| 3574 | |
| 3575 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating. |
| 3576 | pendingLayoutChanges = 0; |
| 3577 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3578 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyPostLayoutPolicy"); |
| 3579 | try { |
| 3580 | mDisplayPolicy.beginPostLayoutPolicyLw(); |
| 3581 | forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */); |
| 3582 | pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw(); |
| 3583 | } finally { |
| 3584 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3585 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3586 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 3587 | "after finishPostLayoutPolicyLw", pendingLayoutChanges); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3588 | mInsetsStateController.onPostLayout(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3589 | } while (pendingLayoutChanges != 0); |
| 3590 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3591 | mTmpApplySurfaceChangesTransactionState.reset(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3592 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3593 | mTmpRecoveringMemory = recoveringMemory; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3594 | |
| 3595 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyWindowSurfaceChanges"); |
| 3596 | try { |
| 3597 | forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */); |
| 3598 | } finally { |
| 3599 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3600 | } |
Jorim Jaggi | 6b0f846 | 2018-01-05 17:23:47 +0100 | [diff] [blame] | 3601 | prepareSurfaces(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3602 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3603 | mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3604 | mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId, |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3605 | mLastHasContent, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3606 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate, |
| 3607 | mTmpApplySurfaceChangesTransactionState.preferredModeId, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3608 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 3609 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3610 | final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible(); |
| 3611 | if (wallpaperVisible != mLastWallpaperVisible) { |
| 3612 | mLastWallpaperVisible = wallpaperVisible; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3613 | mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3614 | } |
| 3615 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3616 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3617 | final ActivityRecord activity = mTmpUpdateAllDrawn.removeLast(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3618 | // See if any windows have been drawn, so they (and others associated with them) |
| 3619 | // can now be shown. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3620 | activity.updateAllDrawn(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3621 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3624 | private void updateBounds() { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3625 | calculateBounds(mDisplayInfo, mTmpBounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3626 | setBounds(mTmpBounds); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3627 | if (mPortalWindowHandle != null && mParentSurfaceControl != null) { |
| 3628 | mPortalWindowHandle.touchableRegion.getBounds(mTmpRect); |
| 3629 | if (!mTmpBounds.equals(mTmpRect)) { |
| 3630 | mPortalWindowHandle.touchableRegion.set(mTmpBounds); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3631 | getPendingTransaction().setInputWindowInfo( |
| 3632 | mParentSurfaceControl, mPortalWindowHandle); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3633 | } |
| 3634 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | // Determines the current display bounds based on the current state |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3638 | private void calculateBounds(DisplayInfo displayInfo, Rect out) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3639 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3640 | final int rotation = displayInfo.rotation; |
| 3641 | boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3642 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 3643 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3644 | int width = displayInfo.logicalWidth; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3645 | int left = (physWidth - width) / 2; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3646 | int height = displayInfo.logicalHeight; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3647 | int top = (physHeight - height) / 2; |
| 3648 | out.set(left, top, left + width, top + height); |
| 3649 | } |
| 3650 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3651 | private void getBounds(Rect out, int orientation) { |
| 3652 | getBounds(out); |
| 3653 | |
| 3654 | // Rotate the Rect if needed. |
| 3655 | final int currentRotation = mDisplayInfo.rotation; |
| 3656 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 3657 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 3658 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 3659 | mTmpRectF.set(out); |
| 3660 | mTmpMatrix.mapRect(mTmpRectF); |
| 3661 | mTmpRectF.round(out); |
| 3662 | } |
| 3663 | } |
| 3664 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 3665 | /** @returns the orientation of the display when it's rotation is ROTATION_0. */ |
| 3666 | int getNaturalOrientation() { |
| 3667 | return mBaseDisplayWidth < mBaseDisplayHeight |
| 3668 | ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
| 3669 | } |
| 3670 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3671 | void performLayout(boolean initial, boolean updateInputWindows) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3672 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "performLayout"); |
| 3673 | try { |
| 3674 | performLayoutNoTrace(initial, updateInputWindows); |
| 3675 | } finally { |
| 3676 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | private void performLayoutNoTrace(boolean initial, boolean updateInputWindows) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3681 | if (!isLayoutNeeded()) { |
| 3682 | return; |
| 3683 | } |
| 3684 | clearLayoutNeeded(); |
| 3685 | |
| 3686 | final int dw = mDisplayInfo.logicalWidth; |
| 3687 | final int dh = mDisplayInfo.logicalHeight; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3688 | if (DEBUG_LAYOUT) { |
| 3689 | Slog.v(TAG, "-------------------------------------"); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3690 | Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw |
| 3691 | + " dh=" + dh); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 3694 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 3695 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3696 | // TODO: Not sure if we really need to set the rotation here since we are updating from |
| 3697 | // the display info above... |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3698 | mDisplayFrames.mRotation = getRotation(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3699 | mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3700 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3701 | int seq = mLayoutSeq + 1; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3702 | if (seq < 0) seq = 0; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3703 | mLayoutSeq = seq; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3704 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3705 | // Used to indicate that we have processed the dream window and all additional windows are |
| 3706 | // behind it. |
| 3707 | mTmpWindow = null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3708 | mTmpInitial = initial; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3709 | |
| 3710 | // First perform layout of any root windows (not attached to another window). |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3711 | forAllWindows(mPerformLayout, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3712 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3713 | // Used to indicate that we have processed the dream window and all additional attached |
| 3714 | // windows are behind it. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3715 | mTmpWindow2 = mTmpWindow; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3716 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3717 | |
| 3718 | // Now perform layout of attached windows, which usually depend on the position of the |
| 3719 | // window they are attached to. XXX does not deal with windows that are attached to windows |
| 3720 | // that are themselves attached. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3721 | forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3722 | |
| 3723 | // Window frames may have changed. Tell the input dispatcher about it. |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3724 | mInputMonitor.layoutInputConsumers(dw, dh); |
| 3725 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3726 | if (updateInputWindows) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3727 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3730 | mWmService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | /** |
| 3734 | * Takes a snapshot of the display. In landscape mode this grabs the whole screen. |
| 3735 | * In portrait mode, it grabs the full screenshot. |
| 3736 | * |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3737 | * @param config of the output bitmap |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3738 | */ |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3739 | Bitmap screenshotDisplayLocked(Bitmap.Config config) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3740 | if (!mWmService.mPolicy.isScreenOn()) { |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3741 | if (DEBUG_SCREENSHOT) { |
| 3742 | Slog.i(TAG_WM, "Attempted to take screenshot while display was off."); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3743 | } |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3744 | return null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3745 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3746 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3747 | int dw = mDisplayInfo.logicalWidth; |
| 3748 | int dh = mDisplayInfo.logicalHeight; |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3749 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3750 | if (dw <= 0 || dh <= 0) { |
| 3751 | return null; |
| 3752 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3753 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3754 | final Rect frame = new Rect(0, 0, dw, dh); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3755 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3756 | // The screenshot API does not apply the current screen rotation. |
| 3757 | int rot = mDisplay.getRotation(); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3758 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3759 | if (rot == ROTATION_90 || rot == ROTATION_270) { |
| 3760 | rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 3761 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3762 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3763 | // SurfaceFlinger is not aware of orientation, so convert our logical |
| 3764 | // crop to SurfaceFlinger's portrait orientation. |
| 3765 | convertCropForSurfaceFlinger(frame, rot, dw, dh); |
| 3766 | |
| 3767 | final ScreenRotationAnimation screenRotationAnimation = |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 3768 | mWmService.mRoot.getDisplayContent(DEFAULT_DISPLAY).getRotationAnimation(); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3769 | final boolean inRotation = screenRotationAnimation != null && |
| 3770 | screenRotationAnimation.isAnimating(); |
| 3771 | if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating"); |
| 3772 | |
| 3773 | // TODO(b/68392460): We should screenshot Task controls directly |
| 3774 | // but it's difficult at the moment as the Task doesn't have the |
| 3775 | // correct size set. |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 3776 | final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3777 | if (bitmap == null) { |
| 3778 | Slog.w(TAG_WM, "Failed to take screenshot"); |
| 3779 | return null; |
| 3780 | } |
| 3781 | |
| 3782 | // Create a copy of the screenshot that is immutable and backed in ashmem. |
| 3783 | // This greatly reduces the overhead of passing the bitmap between processes. |
| 3784 | final Bitmap ret = bitmap.createAshmemBitmap(config); |
| 3785 | bitmap.recycle(); |
| 3786 | return ret; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | // TODO: Can this use createRotationMatrix()? |
| 3790 | private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) { |
| 3791 | if (rot == Surface.ROTATION_90) { |
| 3792 | final int tmp = crop.top; |
| 3793 | crop.top = dw - crop.right; |
| 3794 | crop.right = crop.bottom; |
| 3795 | crop.bottom = dw - crop.left; |
| 3796 | crop.left = tmp; |
| 3797 | } else if (rot == Surface.ROTATION_180) { |
| 3798 | int tmp = crop.top; |
| 3799 | crop.top = dh - crop.bottom; |
| 3800 | crop.bottom = dh - tmp; |
| 3801 | tmp = crop.right; |
| 3802 | crop.right = dw - crop.left; |
| 3803 | crop.left = dw - tmp; |
| 3804 | } else if (rot == Surface.ROTATION_270) { |
| 3805 | final int tmp = crop.top; |
| 3806 | crop.top = crop.left; |
| 3807 | crop.left = dh - crop.bottom; |
| 3808 | crop.bottom = crop.right; |
| 3809 | crop.right = dh - tmp; |
| 3810 | } |
| 3811 | } |
| 3812 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3813 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 3814 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 3815 | mExitingTokens.get(i).hasVisible = hasVisible; |
| 3816 | } |
| 3817 | |
| 3818 | // Initialize state of exiting applications. |
| 3819 | mTaskStackContainers.setExitingTokensHasVisible(hasVisible); |
| 3820 | } |
| 3821 | |
| 3822 | void removeExistingTokensIfPossible() { |
| 3823 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 3824 | final WindowToken token = mExitingTokens.get(i); |
| 3825 | if (!token.hasVisible) { |
| 3826 | mExitingTokens.remove(i); |
| 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | // Time to remove any exiting applications? |
| 3831 | mTaskStackContainers.removeExistingAppTokensIfPossible(); |
| 3832 | } |
| 3833 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3834 | @Override |
| 3835 | void onDescendantOverrideConfigurationChanged() { |
| 3836 | setLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3837 | mWmService.requestTraversal(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3838 | } |
| 3839 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3840 | boolean okToDisplay() { |
| 3841 | if (mDisplayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3842 | return !mWmService.mDisplayFrozen |
| 3843 | && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3844 | } |
| 3845 | return mDisplayInfo.state == Display.STATE_ON; |
| 3846 | } |
| 3847 | |
| 3848 | boolean okToAnimate() { |
| 3849 | return okToDisplay() && |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3850 | (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3851 | } |
| 3852 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 3853 | static final class TaskForResizePointSearchResult { |
| 3854 | boolean searchDone; |
| 3855 | Task taskForResize; |
| 3856 | |
| 3857 | void reset() { |
| 3858 | searchDone = false; |
| 3859 | taskForResize = null; |
| 3860 | } |
| 3861 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3862 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3863 | private static final class ApplySurfaceChangesTransactionState { |
| 3864 | boolean displayHasContent; |
| 3865 | boolean obscured; |
| 3866 | boolean syswin; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3867 | float preferredRefreshRate; |
| 3868 | int preferredModeId; |
| 3869 | |
| 3870 | void reset() { |
| 3871 | displayHasContent = false; |
| 3872 | obscured = false; |
| 3873 | syswin = false; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3874 | preferredRefreshRate = 0; |
| 3875 | preferredModeId = 0; |
| 3876 | } |
| 3877 | } |
| 3878 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3879 | /** |
| 3880 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 3881 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 3882 | * homogeneous children type which is currently required by sub-classes of |
| 3883 | * {@link WindowContainer} class. |
| 3884 | */ |
| 3885 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 3886 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 3887 | DisplayChildWindowContainer(WindowManagerService service) { |
| 3888 | super(service); |
| 3889 | } |
| 3890 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3891 | @Override |
| 3892 | boolean fillsParent() { |
| 3893 | return true; |
| 3894 | } |
| 3895 | |
| 3896 | @Override |
| 3897 | boolean isVisible() { |
| 3898 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3899 | } |
| 3900 | } |
| 3901 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3902 | /** |
| 3903 | * Window container class that contains all containers on this display relating to Apps. |
| 3904 | * I.e Activities. |
| 3905 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3906 | private final class TaskStackContainers extends DisplayChildWindowContainer<ActivityStack> { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3907 | /** |
| 3908 | * A control placed at the appropriate level for transitions to occur. |
| 3909 | */ |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 3910 | SurfaceControl mAppAnimationLayer = null; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 3911 | SurfaceControl mBoostedAppAnimationLayer = null; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 3912 | SurfaceControl mHomeAppAnimationLayer = null; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3913 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 3914 | /** |
| 3915 | * Given that the split-screen divider does not have an AppWindowToken, it |
| 3916 | * will have to live inside of a "NonAppWindowContainer", in particular |
| 3917 | * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order |
| 3918 | * it will need to be interleaved with some of our children, appearing on top of |
| 3919 | * both docked stacks but underneath any assistant stacks. |
| 3920 | * |
| 3921 | * To solve this problem we have this anchor control, which will always exist so |
| 3922 | * we can always assign it the correct value in our {@link #assignChildLayers}. |
| 3923 | * Likewise since it always exists, {@link AboveAppWindowContainers} can always |
| 3924 | * assign the divider a layer relative to it. This way we prevent linking lifecycle |
| 3925 | * events between the two containers. |
| 3926 | */ |
| 3927 | SurfaceControl mSplitScreenDividerAnchor = null; |
| 3928 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3929 | // Cached reference to some special stacks we tend to get a lot so we don't need to loop |
| 3930 | // through the list to find them. |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3931 | private ActivityStack mHomeStack = null; |
| 3932 | private ActivityStack mPinnedStack = null; |
| 3933 | private ActivityStack mSplitScreenPrimaryStack = null; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3934 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 3935 | TaskStackContainers(WindowManagerService service) { |
| 3936 | super(service); |
| 3937 | } |
| 3938 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 3939 | @Override |
| 3940 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 3941 | // TODO(display-unify): Remove after unification. |
| 3942 | onConfigurationChanged(newParentConfig, mActivityDisplay == null /*forwardToChildren*/); |
| 3943 | } |
| 3944 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3945 | /** |
| 3946 | * Returns the topmost stack on the display that is compatible with the input windowing mode |
| 3947 | * and activity type. Null is no compatible stack on the display. |
| 3948 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3949 | ActivityStack getStack(int windowingMode, int activityType) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3950 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 3951 | return mHomeStack; |
| 3952 | } |
| 3953 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 3954 | return mPinnedStack; |
| 3955 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 3956 | return mSplitScreenPrimaryStack; |
| 3957 | } |
| 3958 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3959 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3960 | if (activityType == ACTIVITY_TYPE_UNDEFINED |
| 3961 | && windowingMode == stack.getWindowingMode()) { |
| 3962 | // Passing in undefined type means we want to match the topmost stack with the |
| 3963 | // windowing mode. |
| 3964 | return stack; |
| 3965 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3966 | if (stack.isCompatible(windowingMode, activityType)) { |
| 3967 | return stack; |
| 3968 | } |
| 3969 | } |
| 3970 | return null; |
| 3971 | } |
| 3972 | |
| 3973 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3974 | ActivityStack getTopStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3975 | return mTaskStackContainers.getChildCount() > 0 |
| 3976 | ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null; |
| 3977 | } |
| 3978 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3979 | ActivityStack getHomeStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3980 | if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) { |
| 3981 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
| 3982 | } |
| 3983 | return mHomeStack; |
| 3984 | } |
| 3985 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3986 | ActivityStack getPinnedStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3987 | return mPinnedStack; |
| 3988 | } |
| 3989 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3990 | ActivityStack getSplitScreenPrimaryStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3991 | return mSplitScreenPrimaryStack; |
| 3992 | } |
| 3993 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 3994 | ArrayList<Task> getVisibleTasks() { |
| 3995 | final ArrayList<Task> visibleTasks = new ArrayList<>(); |
| 3996 | forAllTasks(task -> { |
| 3997 | if (task.isVisible()) { |
| 3998 | visibleTasks.add(task); |
| 3999 | } |
| 4000 | }); |
| 4001 | return visibleTasks; |
| 4002 | } |
| 4003 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4004 | void onStackWindowingModeChanged(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4005 | removeStackReferenceIfNeeded(stack); |
| 4006 | addStackReferenceIfNeeded(stack); |
| 4007 | if (stack == mPinnedStack && getTopStack() != stack) { |
| 4008 | // Looks like this stack changed windowing mode to pinned. Move it to the top. |
| 4009 | positionChildAt(POSITION_TOP, stack, false /* includingParents */); |
| 4010 | } |
| 4011 | } |
| 4012 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4013 | private void addStackReferenceIfNeeded(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4014 | if (stack.isActivityTypeHome()) { |
| 4015 | if (mHomeStack != null) { |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4016 | throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack=" |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4017 | + mHomeStack + " already exist on display=" + this + " stack=" + stack); |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4018 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4019 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4020 | mHomeStack = stack; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4021 | } |
| 4022 | final int windowingMode = stack.getWindowingMode(); |
| 4023 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 4024 | if (mPinnedStack != null) { |
| 4025 | throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack=" |
| 4026 | + mPinnedStack + " already exist on display=" + this |
| 4027 | + " stack=" + stack); |
| 4028 | } |
| 4029 | mPinnedStack = stack; |
| 4030 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4031 | if (mSplitScreenPrimaryStack != null) { |
| 4032 | throw new IllegalArgumentException("addStackReferenceIfNeeded:" |
| 4033 | + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack |
| 4034 | + " already exist on display=" + this + " stack=" + stack); |
| 4035 | } |
| 4036 | mSplitScreenPrimaryStack = stack; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4037 | mDividerControllerLocked.notifyDockedStackExistsChanged(true); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4038 | } |
| 4039 | } |
| 4040 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4041 | private void removeStackReferenceIfNeeded(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4042 | if (stack == mHomeStack) { |
| 4043 | mHomeStack = null; |
| 4044 | } else if (stack == mPinnedStack) { |
| 4045 | mPinnedStack = null; |
| 4046 | } else if (stack == mSplitScreenPrimaryStack) { |
| 4047 | mSplitScreenPrimaryStack = null; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4048 | // Re-set the split-screen create mode whenever the split-screen stack is removed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4049 | mWmService.setDockedStackCreateStateLocked( |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4050 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 4051 | mDividerControllerLocked.notifyDockedStackExistsChanged(false); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4052 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4055 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4056 | void addChild(ActivityStack stack, int position) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4057 | addStackReferenceIfNeeded(stack); |
| 4058 | position = findPositionForStack(position, stack, true /* adding */); |
| 4059 | |
| 4060 | super.addChild(stack, position); |
| 4061 | if (mActivityDisplay != null) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4062 | mActivityDisplay.addChild(stack, position, true /*fromDc*/); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | // The reparenting case is handled in WindowContainer. |
| 4066 | if (!stack.mReparenting) { |
| 4067 | setLayoutNeeded(); |
| 4068 | stack.onDisplayChanged(DisplayContent.this); |
| 4069 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4072 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4073 | protected void removeChild(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4074 | super.removeChild(stack); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4075 | if (mActivityDisplay != null) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4076 | mActivityDisplay.onChildRemoved(stack); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4077 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4078 | removeStackReferenceIfNeeded(stack); |
| 4079 | } |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 4080 | |
| 4081 | @Override |
| 4082 | boolean isOnTop() { |
| 4083 | // Considered always on top |
| 4084 | return true; |
| 4085 | } |
| 4086 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4087 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4088 | void positionChildAt(int position, ActivityStack child, boolean includingParents) { |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 4089 | if (child.getWindowConfiguration().isAlwaysOnTop() |
| 4090 | && position != POSITION_TOP) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4091 | // This stack is always-on-top, override the default behavior. |
| 4092 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom"); |
| 4093 | |
| 4094 | // Moving to its current position, as we must call super but we don't want to |
| 4095 | // perform any meaningful action. |
| 4096 | final int currentPosition = mChildren.indexOf(child); |
| 4097 | super.positionChildAt(currentPosition, child, false /* includingParents */); |
| 4098 | return; |
| 4099 | } |
| 4100 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4101 | final int targetPosition = findPositionForStack(position, child, false /* adding */); |
| 4102 | super.positionChildAt(targetPosition, child, includingParents); |
| 4103 | |
Riddle Hsu | 2f6e174 | 2018-08-23 22:44:36 +0800 | [diff] [blame] | 4104 | if (includingParents) { |
| 4105 | // We still want to move the display of this stack container to top because even the |
| 4106 | // target position is adjusted to non-top, the intention of the condition is to have |
| 4107 | // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front |
| 4108 | // in a non-top display which is using picture-in-picture mode). |
| 4109 | final int topChildPosition = getChildCount() - 1; |
| 4110 | if (targetPosition < topChildPosition && position >= topChildPosition) { |
| 4111 | getParent().positionChildAt(POSITION_TOP, this /* child */, |
| 4112 | true /* includingParents */); |
| 4113 | } |
| 4114 | } |
| 4115 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4116 | setLayoutNeeded(); |
| 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * When stack is added or repositioned, find a proper position for it. |
| 4121 | * This will make sure that pinned stack always stays on top. |
| 4122 | * @param requestedPosition Position requested by caller. |
| 4123 | * @param stack Stack to be added or positioned. |
| 4124 | * @param adding Flag indicates whether we're adding a new stack or positioning an existing. |
| 4125 | * @return The proper position for the stack. |
| 4126 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4127 | private int findPositionForStack(int requestedPosition, ActivityStack stack, |
| 4128 | boolean adding) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4129 | if (stack.inPinnedWindowingMode()) { |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4130 | return POSITION_TOP; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4131 | } |
| 4132 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4133 | final int topChildPosition = mChildren.size() - 1; |
| 4134 | int belowAlwaysOnTopPosition = POSITION_BOTTOM; |
| 4135 | for (int i = topChildPosition; i >= 0; --i) { |
| 4136 | if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) { |
| 4137 | belowAlwaysOnTopPosition = i; |
| 4138 | break; |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | // The max possible position we can insert the stack at. |
| 4143 | int maxPosition = POSITION_TOP; |
| 4144 | // The min possible position we can insert the stack at. |
| 4145 | int minPosition = POSITION_BOTTOM; |
| 4146 | |
| 4147 | if (stack.isAlwaysOnTop()) { |
| 4148 | if (hasPinnedStack()) { |
| 4149 | // Always-on-top stacks go below the pinned stack. |
| 4150 | maxPosition = getStacks().indexOf(mPinnedStack) - 1; |
| 4151 | } |
| 4152 | // Always-on-top stacks need to be above all other stacks. |
| 4153 | minPosition = belowAlwaysOnTopPosition != |
| 4154 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition; |
| 4155 | } else { |
| 4156 | // Other stacks need to be below the always-on-top stacks. |
| 4157 | maxPosition = belowAlwaysOnTopPosition != |
Arthur Hung | 928d8dc | 2018-07-18 15:38:05 +0800 | [diff] [blame] | 4158 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0; |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | int targetPosition = requestedPosition; |
| 4162 | targetPosition = Math.min(targetPosition, maxPosition); |
| 4163 | targetPosition = Math.max(targetPosition, minPosition); |
| 4164 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4165 | // Cap the requested position to something reasonable for the previous position check |
| 4166 | // below. |
| 4167 | if (requestedPosition == POSITION_TOP) { |
| 4168 | requestedPosition = mChildren.size(); |
| 4169 | } else if (requestedPosition == POSITION_BOTTOM) { |
| 4170 | requestedPosition = 0; |
| 4171 | } |
| 4172 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4173 | int prevPosition = getStacks().indexOf(stack); |
| 4174 | // The positions we calculated above (maxPosition, minPosition) do not take into |
| 4175 | // consideration the following edge cases. |
| 4176 | // 1) We need to adjust the position depending on the value "adding". |
| 4177 | // 2) When we are moving a stack to another position, we also need to adjust the |
| 4178 | // position depending on whether the stack is moving to a higher or lower position. |
| 4179 | if ((targetPosition != requestedPosition) && |
| 4180 | (adding || targetPosition < prevPosition)) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4181 | targetPosition++; |
| 4182 | } |
| 4183 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4184 | return targetPosition; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4188 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 4189 | boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4190 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4191 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4192 | return true; |
| 4193 | } |
| 4194 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4195 | return true; |
| 4196 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4197 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4198 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4199 | return true; |
| 4200 | } |
| 4201 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4202 | return true; |
| 4203 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4204 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4205 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4208 | private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback, |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4209 | boolean traverseTopToBottom) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4210 | // For legacy reasons we process the TaskStack.mExitingActivities first here before the |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4211 | // app tokens. |
| 4212 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 4213 | // in-order. |
| 4214 | if (traverseTopToBottom) { |
| 4215 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4216 | final List<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4217 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4218 | if (activities.get(j).forAllWindowsUnchecked(callback, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4219 | traverseTopToBottom)) { |
| 4220 | return true; |
| 4221 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4222 | } |
| 4223 | } |
| 4224 | } else { |
| 4225 | final int count = mChildren.size(); |
| 4226 | for (int i = 0; i < count; ++i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4227 | final List<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4228 | final int appTokensCount = activities.size(); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4229 | for (int j = 0; j < appTokensCount; j++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4230 | if (activities.get(j).forAllWindowsUnchecked(callback, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4231 | traverseTopToBottom)) { |
| 4232 | return true; |
| 4233 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4234 | } |
| 4235 | } |
| 4236 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4237 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4240 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 4241 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4242 | final ArrayList<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4243 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4244 | activities.get(j).hasVisible = hasVisible; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4245 | } |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | void removeExistingAppTokensIfPossible() { |
| 4250 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4251 | final ArrayList<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4252 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4253 | final ActivityRecord activity = activities.get(j); |
| 4254 | if (!activity.hasVisible && !mClosingApps.contains(activity) |
| 4255 | && (!activity.mIsExiting || activity.isEmpty())) { |
| 4256 | // Make sure there is no animation running on this activity, so any windows |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4257 | // associated with it will be removed as soon as their animations are |
| 4258 | // complete. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 4259 | cancelAnimation(); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4260 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4261 | "performLayout: Activity exiting now removed %s", activity); |
| 4262 | activity.removeIfPossible(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4263 | } |
| 4264 | } |
| 4265 | } |
| 4266 | } |
| 4267 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4268 | @Override |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4269 | int getOrientation() { |
Garfield Tan | 98eead3 | 2019-11-18 13:24:53 -0800 | [diff] [blame] | 4270 | if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4271 | // Apps and their containers are not allowed to specify an orientation while the |
Garfield Tan | 98eead3 | 2019-11-18 13:24:53 -0800 | [diff] [blame] | 4272 | // docked stack is visible...except for the home stack if the docked stack is |
| 4273 | // minimized and it actually set something and the bounds is different from the |
| 4274 | // display. |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4275 | if (mHomeStack != null && mHomeStack.isVisible() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4276 | && mDividerControllerLocked.isMinimizedDock() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4277 | && !(mDividerControllerLocked.isHomeStackResizable() |
| 4278 | && mHomeStack.matchParentBounds())) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4279 | final int orientation = mHomeStack.getOrientation(); |
| 4280 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 4281 | return orientation; |
| 4282 | } |
| 4283 | } |
| 4284 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 4285 | } |
| 4286 | |
| 4287 | final int orientation = super.getOrientation(); |
| 4288 | if (orientation != SCREEN_ORIENTATION_UNSET |
| 4289 | && orientation != SCREEN_ORIENTATION_BEHIND) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4290 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 4291 | "App is requesting an orientation, return %d for display id=%d", |
| 4292 | orientation, mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4293 | return orientation; |
| 4294 | } |
| 4295 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4296 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 4297 | "No app is requesting an orientation, return %d for display id=%d", |
| 4298 | getLastOrientation(), mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4299 | // The next app has not been requested to be visible, so we keep the current orientation |
| 4300 | // to prevent freezing/unfreezing the display too early. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 4301 | return getLastOrientation(); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4302 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4303 | |
| 4304 | @Override |
| 4305 | void assignChildLayers(SurfaceControl.Transaction t) { |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4306 | assignStackOrdering(t); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4307 | |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4308 | for (int i = 0; i < mChildren.size(); i++) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4309 | final ActivityStack s = mChildren.get(i); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4310 | s.assignChildLayers(t); |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | void assignStackOrdering(SurfaceControl.Transaction t) { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4315 | if (getParent() == null) { |
| 4316 | return; |
| 4317 | } |
| 4318 | mTmpAlwaysOnTopStacks.clear(); |
| 4319 | mTmpHomeStacks.clear(); |
| 4320 | mTmpNormalStacks.clear(); |
| 4321 | for (int i = 0; i < mChildren.size(); ++i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4322 | final ActivityStack s = mChildren.get(i); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4323 | if (s.isAlwaysOnTop()) { |
| 4324 | mTmpAlwaysOnTopStacks.add(s); |
| 4325 | } else if (s.isActivityTypeHome()) { |
| 4326 | mTmpHomeStacks.add(s); |
| 4327 | } else { |
| 4328 | mTmpNormalStacks.add(s); |
| 4329 | } |
| 4330 | } |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4331 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4332 | int layer = 0; |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4333 | // Place home stacks to the bottom. |
| 4334 | for (int i = 0; i < mTmpHomeStacks.size(); i++) { |
| 4335 | mTmpHomeStacks.get(i).assignLayer(t, layer++); |
| 4336 | } |
| 4337 | // The home animation layer is between the home stacks and the normal stacks. |
| 4338 | final int layerForHomeAnimationLayer = layer++; |
| 4339 | int layerForSplitScreenDividerAnchor = layer++; |
| 4340 | int layerForAnimationLayer = layer++; |
| 4341 | for (int i = 0; i < mTmpNormalStacks.size(); i++) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4342 | final ActivityStack s = mTmpNormalStacks.get(i); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4343 | s.assignLayer(t, layer++); |
| 4344 | if (s.inSplitScreenWindowingMode()) { |
| 4345 | // The split screen divider anchor is located above the split screen window. |
| 4346 | layerForSplitScreenDividerAnchor = layer++; |
| 4347 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4348 | if (s.isTaskAnimating() || s.isAppTransitioning()) { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4349 | // The animation layer is located above the highest animating stack and no |
| 4350 | // higher. |
| 4351 | layerForAnimationLayer = layer++; |
| 4352 | } |
| 4353 | } |
| 4354 | // The boosted animation layer is between the normal stacks and the always on top |
| 4355 | // stacks. |
| 4356 | final int layerForBoostedAnimationLayer = layer++; |
| 4357 | for (int i = 0; i < mTmpAlwaysOnTopStacks.size(); i++) { |
| 4358 | mTmpAlwaysOnTopStacks.get(i).assignLayer(t, layer++); |
| 4359 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4360 | |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4361 | t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer); |
| 4362 | t.setLayer(mAppAnimationLayer, layerForAnimationLayer); |
| 4363 | t.setLayer(mSplitScreenDividerAnchor, layerForSplitScreenDividerAnchor); |
| 4364 | t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | @Override |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4368 | SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) { |
| 4369 | switch (animationLayer) { |
| 4370 | case ANIMATION_LAYER_BOOSTED: |
| 4371 | return mBoostedAppAnimationLayer; |
| 4372 | case ANIMATION_LAYER_HOME: |
| 4373 | return mHomeAppAnimationLayer; |
| 4374 | case ANIMATION_LAYER_STANDARD: |
| 4375 | default: |
| 4376 | return mAppAnimationLayer; |
| 4377 | } |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4378 | } |
| 4379 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4380 | SurfaceControl getSplitScreenDividerAnchor() { |
| 4381 | return mSplitScreenDividerAnchor; |
| 4382 | } |
| 4383 | |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4384 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4385 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4386 | if (getParent() != null) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4387 | super.onParentChanged(newParent, oldParent, () -> { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4388 | mAppAnimationLayer = makeChildSurface(null) |
| 4389 | .setName("animationLayer") |
| 4390 | .build(); |
| 4391 | mBoostedAppAnimationLayer = makeChildSurface(null) |
| 4392 | .setName("boostedAnimationLayer") |
| 4393 | .build(); |
| 4394 | mHomeAppAnimationLayer = makeChildSurface(null) |
| 4395 | .setName("homeAnimationLayer") |
| 4396 | .build(); |
| 4397 | mSplitScreenDividerAnchor = makeChildSurface(null) |
| 4398 | .setName("splitScreenDividerAnchor") |
| 4399 | .build(); |
| 4400 | getPendingTransaction() |
| 4401 | .show(mAppAnimationLayer) |
| 4402 | .show(mBoostedAppAnimationLayer) |
| 4403 | .show(mHomeAppAnimationLayer) |
| 4404 | .show(mSplitScreenDividerAnchor); |
| 4405 | }); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4406 | } else { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4407 | super.onParentChanged(newParent, oldParent); |
Vishnu Nair | 3319739 | 2019-08-30 10:29:37 -0700 | [diff] [blame] | 4408 | mWmService.mTransactionFactory.get() |
chaviw | 9f6171e | 2019-06-07 16:33:50 -0700 | [diff] [blame] | 4409 | .remove(mAppAnimationLayer) |
| 4410 | .remove(mBoostedAppAnimationLayer) |
| 4411 | .remove(mHomeAppAnimationLayer) |
| 4412 | .remove(mSplitScreenDividerAnchor) |
| 4413 | .apply(); |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4414 | mAppAnimationLayer = null; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4415 | mBoostedAppAnimationLayer = null; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4416 | mHomeAppAnimationLayer = null; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4417 | mSplitScreenDividerAnchor = null; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4418 | } |
| 4419 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4422 | private final class AboveAppWindowContainers extends NonAppWindowContainers { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4423 | AboveAppWindowContainers(String name, WindowManagerService service) { |
| 4424 | super(name, service); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4425 | } |
| 4426 | |
Robert Carr | b950603 | 2018-02-13 13:54:00 -0800 | [diff] [blame] | 4427 | @Override |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 4428 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
| 4429 | final SurfaceControl.Builder builder = super.makeChildSurface(child); |
| 4430 | if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) { |
| 4431 | // To draw above the ColorFade layer during the screen off transition, the |
| 4432 | // rounded corner overlays need to be at the root of the surface hierarchy. |
| 4433 | // TODO: move the ColorLayer into the display overlay layer such that this is not |
| 4434 | // necessary anymore. |
| 4435 | builder.setParent(null); |
| 4436 | } |
| 4437 | return builder; |
| 4438 | } |
| 4439 | |
| 4440 | @Override |
Robert Carr | b950603 | 2018-02-13 13:54:00 -0800 | [diff] [blame] | 4441 | void assignChildLayers(SurfaceControl.Transaction t) { |
| 4442 | assignChildLayers(t, null /* imeContainer */); |
| 4443 | } |
| 4444 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4445 | void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) { |
| 4446 | boolean needAssignIme = imeContainer != null |
| 4447 | && imeContainer.getSurfaceControl() != null; |
| 4448 | for (int j = 0; j < mChildren.size(); ++j) { |
| 4449 | final WindowToken wt = mChildren.get(j); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4450 | |
| 4451 | // See {@link mSplitScreenDividerAnchor} |
| 4452 | if (wt.windowType == TYPE_DOCK_DIVIDER) { |
| 4453 | wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1); |
| 4454 | continue; |
| 4455 | } |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 4456 | if (wt.mRoundedCornerOverlay) { |
| 4457 | wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1); |
| 4458 | continue; |
| 4459 | } |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4460 | wt.assignLayer(t, j); |
| 4461 | wt.assignChildLayers(t); |
| 4462 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4463 | int layer = mWmService.mPolicy.getWindowLayerFromTypeLw( |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4464 | wt.windowType, wt.mOwnerCanManageAppTokens); |
Robert Carr | b8e78fa | 2017-11-28 13:07:58 -0800 | [diff] [blame] | 4465 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4466 | if (needAssignIme && layer >= mWmService.mPolicy.getWindowLayerFromTypeLw( |
Robert Carr | b8e78fa | 2017-11-28 13:07:58 -0800 | [diff] [blame] | 4467 | TYPE_INPUT_METHOD_DIALOG, true)) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4468 | imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4469 | needAssignIme = false; |
| 4470 | } |
| 4471 | } |
| 4472 | if (needAssignIme) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4473 | imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4474 | } |
| 4475 | } |
| 4476 | } |
| 4477 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4478 | /** |
| 4479 | * Window container class that contains all containers on this display that are not related to |
| 4480 | * Apps. E.g. status bar. |
| 4481 | */ |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4482 | private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4483 | /** |
| 4484 | * Compares two child window tokens returns -1 if the first is lesser than the second in |
| 4485 | * terms of z-order and 1 otherwise. |
| 4486 | */ |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4487 | private final Comparator<WindowToken> mWindowComparator = (token1, token2) -> |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4488 | // Tokens with higher base layer are z-ordered on-top. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4489 | mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4490 | token1.mOwnerCanManageAppTokens) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4491 | < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4492 | token2.mOwnerCanManageAppTokens) ? -1 : 1; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4493 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4494 | private final Predicate<WindowState> mGetOrientingWindow = w -> { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 4495 | if (!w.isVisibleLw() || !w.mLegacyPolicyVisibilityAfterAnim) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4496 | return false; |
| 4497 | } |
| 4498 | final int req = w.mAttrs.screenOrientation; |
| 4499 | if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND |
| 4500 | || req == SCREEN_ORIENTATION_UNSET) { |
| 4501 | return false; |
| 4502 | } |
| 4503 | return true; |
| 4504 | }; |
| 4505 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4506 | private final String mName; |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4507 | private final Dimmer mDimmer = new Dimmer(this); |
| 4508 | private final Rect mTmpDimBoundsRect = new Rect(); |
| 4509 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4510 | NonAppWindowContainers(String name, WindowManagerService service) { |
| 4511 | super(service); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4512 | mName = name; |
| 4513 | } |
| 4514 | |
| 4515 | void addChild(WindowToken token) { |
| 4516 | addChild(token, mWindowComparator); |
| 4517 | } |
| 4518 | |
| 4519 | @Override |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4520 | int getOrientation() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4521 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4522 | // Find a window requesting orientation. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4523 | final WindowState win = getWindow(mGetOrientingWindow); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4524 | |
| 4525 | if (win != null) { |
| 4526 | final int req = win.mAttrs.screenOrientation; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4527 | if (policy.isKeyguardHostWindow(win.mAttrs)) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4528 | mLastKeyguardForcedOrientation = req; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4529 | if (mWmService.mKeyguardGoingAway) { |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 4530 | // Keyguard can't affect the orientation if it is going away... |
| 4531 | mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 4532 | return SCREEN_ORIENTATION_UNSET; |
| 4533 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4534 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4535 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 4536 | "%s forcing orientation to %d for display id=%d", win, req, |
| 4537 | mDisplayId); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4538 | return (mLastWindowForcedOrientation = req); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4539 | } |
| 4540 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4541 | mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4542 | |
Jorim Jaggi | 1c53059 | 2018-04-06 15:11:47 +0200 | [diff] [blame] | 4543 | // Only allow force setting the orientation when all unknown visibilities have been |
| 4544 | // resolved, as otherwise we just may be starting another occluding activity. |
| 4545 | final boolean isUnoccluding = |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4546 | mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE |
| 4547 | && mUnknownAppVisibilityController.allResolved(); |
Jorim Jaggi | 1c53059 | 2018-04-06 15:11:47 +0200 | [diff] [blame] | 4548 | if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4549 | return mLastKeyguardForcedOrientation; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | return SCREEN_ORIENTATION_UNSET; |
| 4553 | } |
| 4554 | |
| 4555 | @Override |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4556 | String getName() { |
| 4557 | return mName; |
| 4558 | } |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4559 | |
| 4560 | @Override |
| 4561 | Dimmer getDimmer() { |
| 4562 | return mDimmer; |
| 4563 | } |
| 4564 | |
| 4565 | @Override |
| 4566 | void prepareSurfaces() { |
| 4567 | mDimmer.resetDimStates(); |
| 4568 | super.prepareSurfaces(); |
| 4569 | getBounds(mTmpDimBoundsRect); |
| 4570 | |
| 4571 | if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) { |
| 4572 | scheduleAnimation(); |
| 4573 | } |
| 4574 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4575 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 4576 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4577 | SurfaceControl.Builder makeSurface(SurfaceSession s) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4578 | return mWmService.makeSurfaceBuilder(s) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4579 | .setParent(mWindowingLayer); |
| 4580 | } |
| 4581 | |
| 4582 | @Override |
| 4583 | SurfaceSession getSession() { |
| 4584 | return mSession; |
| 4585 | } |
| 4586 | |
| 4587 | @Override |
| 4588 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4589 | SurfaceSession s = child != null ? child.getSession() : getSession(); |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 4590 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s).setContainerLayer(); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4591 | if (child == null) { |
| 4592 | return b; |
| 4593 | } |
| 4594 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4595 | return b.setName(child.getName()) |
| 4596 | .setParent(mWindowingLayer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | /** |
| 4600 | * The makeSurface variants are for use by the window-container |
| 4601 | * hierarchy. makeOverlay here is a function for various non windowing |
| 4602 | * overlays like the ScreenRotation screenshot, the Strict Mode Flash |
| 4603 | * and other potpourii. |
| 4604 | */ |
| 4605 | SurfaceControl.Builder makeOverlay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4606 | return mWmService.makeSurfaceBuilder(mSession) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4607 | .setParent(mOverlayLayer); |
| 4608 | } |
| 4609 | |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4610 | /** |
| 4611 | * Reparents the given surface to mOverlayLayer. |
| 4612 | */ |
| 4613 | void reparentToOverlay(Transaction transaction, SurfaceControl surface) { |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 4614 | transaction.reparent(surface, mOverlayLayer); |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4615 | } |
| 4616 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4617 | void applyMagnificationSpec(MagnificationSpec spec) { |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4618 | if (spec.scale != 1.0) { |
| 4619 | mMagnificationSpec = spec; |
| 4620 | } else { |
| 4621 | mMagnificationSpec = null; |
| 4622 | } |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 4623 | // Re-parent IME's SurfaceControl when MagnificationSpec changed. |
| 4624 | updateImeParent(); |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4625 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4626 | applyMagnificationSpec(getPendingTransaction(), spec); |
| 4627 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4630 | void reapplyMagnificationSpec() { |
| 4631 | if (mMagnificationSpec != null) { |
| 4632 | applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec); |
| 4633 | } |
| 4634 | } |
| 4635 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4636 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4637 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4638 | // Since we are the top of the SurfaceControl hierarchy here |
| 4639 | // we create the root surfaces explicitly rather than chaining |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 4640 | // up as the default implementation in onParentChanged does. So we |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4641 | // explicitly do NOT call super here. |
| 4642 | } |
| 4643 | |
| 4644 | @Override |
| 4645 | void assignChildLayers(SurfaceControl.Transaction t) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4646 | |
| 4647 | // These are layers as children of "mWindowingLayer" |
| 4648 | mBelowAppWindowsContainers.assignLayer(t, 0); |
| 4649 | mTaskStackContainers.assignLayer(t, 1); |
| 4650 | mAboveAppWindowsContainers.assignLayer(t, 2); |
| 4651 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 4652 | final WindowState imeTarget = mInputMethodTarget; |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4653 | boolean needAssignIme = true; |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4654 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4655 | // In the case where we have an IME target that is not in split-screen |
| 4656 | // mode IME assignment is easy. We just need the IME to go directly above |
| 4657 | // the target. This way children of the target will naturally go above the IME |
| 4658 | // and everyone is happy. |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4659 | // |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4660 | // In the case of split-screen windowing mode, we need to elevate the IME above the |
| 4661 | // docked divider while keeping the app itself below the docked divider, so instead |
| 4662 | // we use relative layering of the IME targets child windows, and place the |
| 4663 | // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}). |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4664 | // |
Robert Carr | 234b633 | 2018-03-20 13:38:16 -0700 | [diff] [blame] | 4665 | // In the case the IME target is animating, the animation Z order may be different |
| 4666 | // than the WindowContainer Z order, so it's difficult to be sure we have the correct |
| 4667 | // IME target. In this case we just layer the IME over all transitions by placing it in the |
| 4668 | // above applications layer. |
| 4669 | // |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4670 | // In the case where we have no IME target we assign it where it's base layer would |
| 4671 | // place it in the AboveAppWindowContainers. |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 4672 | // |
| 4673 | // Keep IME window in mAboveAppWindowsContainers as long as app's starting window exists |
| 4674 | // so it get's layered above the starting window. |
| 4675 | if (imeTarget != null |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4676 | && !(imeTarget.mActivityRecord != null && imeTarget.mActivityRecord.hasStartingWindow()) |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4677 | && (!(imeTarget.inSplitScreenWindowingMode() |
| 4678 | || imeTarget.mToken.isAppTransitioning()) |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 4679 | && (imeTarget.getSurfaceControl() != null))) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4680 | mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(), |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4681 | // TODO: We need to use an extra level on the app surface to ensure |
| 4682 | // this is always above SurfaceView but always below attached window. |
| 4683 | 1); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4684 | needAssignIme = false; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | // Above we have assigned layers to our children, now we ask them to assign |
| 4688 | // layers to their children. |
| 4689 | mBelowAppWindowsContainers.assignChildLayers(t); |
| 4690 | mTaskStackContainers.assignChildLayers(t); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4691 | mAboveAppWindowsContainers.assignChildLayers(t, |
| 4692 | needAssignIme == true ? mImeWindowsContainers : null); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4693 | mImeWindowsContainers.assignChildLayers(t); |
| 4694 | } |
| 4695 | |
| 4696 | /** |
| 4697 | * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine |
| 4698 | * that the IME target is one of the docked applications. We'd like the docked divider to be |
| 4699 | * above both of the applications, and we'd like the IME to be above the docked divider. |
| 4700 | * However we need child windows of the applications to be above the IME (Text drag handles). |
| 4701 | * This is a non-strictly hierarcical layering and we need to break out of the Z ordering |
| 4702 | * 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] | 4703 | * with {@link WindowState#assignLayer} |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4704 | */ |
| 4705 | void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) { |
Robert Carr | bb5de66 | 2018-04-26 13:29:51 -0700 | [diff] [blame] | 4706 | child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | @Override |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4710 | void prepareSurfaces() { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4711 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareSurfaces"); |
| 4712 | try { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4713 | final Transaction transaction = getPendingTransaction(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4714 | super.prepareSurfaces(); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4715 | |
| 4716 | // TODO: Once we totally eliminate global transaction we will pass transaction in here |
| 4717 | // rather than merging to global. |
| 4718 | SurfaceControl.mergeToGlobalTransaction(transaction); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4719 | } finally { |
| 4720 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 4721 | } |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4722 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4723 | |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4724 | void assignStackOrdering() { |
| 4725 | mTaskStackContainers.assignStackOrdering(getPendingTransaction()); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4726 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4727 | |
| 4728 | /** |
| 4729 | * Increment the deferral count to determine whether to update the IME target. |
| 4730 | */ |
| 4731 | void deferUpdateImeTarget() { |
| 4732 | mDeferUpdateImeTargetCount++; |
| 4733 | } |
| 4734 | |
| 4735 | /** |
| 4736 | * Decrement the deferral count to determine whether to update the IME target. If the count |
| 4737 | * reaches 0, a new ime target will get computed. |
| 4738 | */ |
| 4739 | void continueUpdateImeTarget() { |
| 4740 | if (mDeferUpdateImeTargetCount == 0) { |
| 4741 | return; |
| 4742 | } |
| 4743 | |
| 4744 | mDeferUpdateImeTargetCount--; |
| 4745 | if (mDeferUpdateImeTargetCount == 0) { |
| 4746 | computeImeTarget(true /* updateImeTarget */); |
| 4747 | } |
| 4748 | } |
| 4749 | |
| 4750 | /** |
| 4751 | * @return Whether a new IME target should be computed. |
| 4752 | */ |
| 4753 | private boolean canUpdateImeTarget() { |
| 4754 | return mDeferUpdateImeTargetCount == 0; |
| 4755 | } |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 4756 | |
| 4757 | InputMonitor getInputMonitor() { |
| 4758 | return mInputMonitor; |
| 4759 | } |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 4760 | |
| 4761 | /** |
| 4762 | * @return Cached value whether we told display manager that we have content. |
| 4763 | */ |
| 4764 | boolean getLastHasContent() { |
| 4765 | return mLastHasContent; |
| 4766 | } |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4767 | |
| 4768 | void registerPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4769 | mPointerEventDispatcher.registerInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | void unregisterPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4773 | mPointerEventDispatcher.unregisterInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4774 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4775 | |
| 4776 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4777 | boolean alwaysKeepCurrent) { |
| 4778 | prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */); |
| 4779 | } |
| 4780 | |
| 4781 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4782 | boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags, |
| 4783 | boolean forceOverride) { |
| 4784 | final boolean prepared = mAppTransition.prepareAppTransitionLocked( |
| 4785 | transit, alwaysKeepCurrent, flags, forceOverride); |
| 4786 | if (prepared && okToAnimate()) { |
| 4787 | mSkipAppTransitionAnimation = false; |
| 4788 | } |
| 4789 | } |
| 4790 | |
| 4791 | void executeAppTransition() { |
| 4792 | if (mAppTransition.isTransitionSet()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4793 | ProtoLog.w(WM_DEBUG_APP_TRANSITIONS, |
| 4794 | "Execute app transition: %s, displayId: %d Callers=%s", |
| 4795 | mAppTransition, mDisplayId, Debug.getCallers(5)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4796 | mAppTransition.setReady(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4797 | mWmService.mWindowPlacerLocked.requestTraversal(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | /** |
| 4802 | * Update pendingLayoutChanges after app transition has finished. |
| 4803 | */ |
| 4804 | void handleAnimatingStoppedAndTransition() { |
| 4805 | int changes = 0; |
| 4806 | |
| 4807 | mAppTransition.setIdle(); |
| 4808 | |
| 4809 | for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) { |
| 4810 | final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i); |
| 4811 | mAppTransition.notifyAppTransitionFinishedLocked(token); |
| 4812 | } |
| 4813 | mNoAnimationNotifyOnTransitionFinished.clear(); |
| 4814 | |
| 4815 | mWallpaperController.hideDeferredWallpapersIfNeeded(); |
| 4816 | |
| 4817 | onAppTransitionDone(); |
| 4818 | |
| 4819 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4820 | if (DEBUG_WALLPAPER_LIGHT) { |
| 4821 | Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout"); |
| 4822 | } |
| 4823 | computeImeTarget(true /* updateImeTarget */); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 4824 | mWallpaperMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4825 | // Since the window list has been rebuilt, focus might have to be recomputed since the |
| 4826 | // actual order of windows might have changed again. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4827 | mWmService.mFocusMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4828 | |
| 4829 | pendingLayoutChanges |= changes; |
| 4830 | } |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4831 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4832 | /** Check if pending app transition is for activity / task launch. */ |
| 4833 | boolean isNextTransitionForward() { |
| 4834 | final int transit = mAppTransition.getAppTransition(); |
| 4835 | return transit == TRANSIT_ACTIVITY_OPEN |
| 4836 | || transit == TRANSIT_TASK_OPEN |
| 4837 | || transit == TRANSIT_TASK_TO_FRONT; |
| 4838 | } |
| 4839 | |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4840 | /** |
| 4841 | * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS |
| 4842 | */ |
| 4843 | boolean supportsSystemDecorations() { |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 4844 | return (mWmService.mDisplayWindowSettings.shouldShowSystemDecorsLocked(this) |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 4845 | || (mDisplay.getFlags() & FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0 |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 4846 | || (mWmService.mForceDesktopModeOnExternalDisplays && !isUntrustedVirtualDisplay())) |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 4847 | // VR virtual display will be used to run and render 2D app within a VR experience. |
| 4848 | && mDisplayId != mWmService.mVr2dDisplayId; |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4849 | } |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4850 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4851 | /** |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 4852 | * @return {@code true} if the display is non-system created virtual display. |
| 4853 | */ |
| 4854 | boolean isUntrustedVirtualDisplay() { |
| 4855 | return mDisplay.getType() == Display.TYPE_VIRTUAL |
| 4856 | && mDisplay.getOwnerUid() != Process.SYSTEM_UID; |
| 4857 | } |
| 4858 | |
| 4859 | /** |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4860 | * Re-parent the DisplayContent's top surfaces, {@link #mWindowingLayer} and |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4861 | * {@link #mOverlayLayer} to the specified SurfaceControl. |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4862 | * |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4863 | * @param win The window which owns the SurfaceControl. This indicates the z-order of the |
| 4864 | * windows of this display against the windows on the parent display. |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4865 | * @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] | 4866 | */ |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4867 | void reparentDisplayContent(WindowState win, SurfaceControl sc) { |
| 4868 | mParentWindow = win; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4869 | mParentWindow.addEmbeddedDisplayContent(this); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4870 | mParentSurfaceControl = sc; |
| 4871 | if (mPortalWindowHandle == null) { |
| 4872 | mPortalWindowHandle = createPortalWindowHandle(sc.toString()); |
| 4873 | } |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4874 | getPendingTransaction().setInputWindowInfo(sc, mPortalWindowHandle) |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 4875 | .reparent(mSurfaceControl, sc); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4876 | } |
| 4877 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4878 | /** |
| 4879 | * Get the window which owns the surface that this DisplayContent is re-parented to. |
| 4880 | * |
| 4881 | * @return the parent window. |
| 4882 | */ |
| 4883 | WindowState getParentWindow() { |
| 4884 | return mParentWindow; |
| 4885 | } |
| 4886 | |
| 4887 | /** |
| 4888 | * Update the location of this display in the parent window. This enables windows in this |
| 4889 | * display to compute the global transformation matrix. |
| 4890 | * |
| 4891 | * @param win The parent window of this display. |
| 4892 | * @param x The x coordinate in the parent window. |
| 4893 | * @param y The y coordinate in the parent window. |
| 4894 | */ |
| 4895 | void updateLocation(WindowState win, int x, int y) { |
| 4896 | if (mParentWindow != win) { |
| 4897 | throw new IllegalArgumentException( |
| 4898 | "The given window is not the parent window of this display."); |
| 4899 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4900 | if (!mLocationInParentWindow.equals(x, y)) { |
| 4901 | mLocationInParentWindow.set(x, y); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4902 | if (mWmService.mAccessibilityController != null) { |
Jacky Kao | f93252b | 2019-07-18 15:19:52 +0800 | [diff] [blame] | 4903 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(mDisplayId); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4904 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4905 | notifyLocationInParentDisplayChanged(); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | Point getLocationInParentWindow() { |
| 4910 | return mLocationInParentWindow; |
| 4911 | } |
| 4912 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4913 | Point getLocationInParentDisplay() { |
| 4914 | final Point location = new Point(); |
| 4915 | if (mParentWindow != null) { |
| 4916 | // LocationInParentWindow indicates the offset to (0,0) of window, but what we need is |
| 4917 | // the offset to (0,0) of display. |
| 4918 | DisplayContent dc = this; |
| 4919 | do { |
| 4920 | final WindowState displayParent = dc.getParentWindow(); |
| 4921 | location.x += displayParent.getFrameLw().left |
| 4922 | + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f); |
| 4923 | location.y += displayParent.getFrameLw().top |
| 4924 | + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f); |
| 4925 | dc = displayParent.getDisplayContent(); |
| 4926 | } while (dc != null && dc.getParentWindow() != null); |
| 4927 | } |
| 4928 | return location; |
| 4929 | } |
| 4930 | |
| 4931 | void notifyLocationInParentDisplayChanged() { |
| 4932 | forAllWindows(w -> { |
| 4933 | w.updateLocationInParentDisplayIfNeeded(); |
| 4934 | }, false /* traverseTopToBottom */); |
| 4935 | } |
| 4936 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 4937 | @VisibleForTesting |
| 4938 | SurfaceControl getWindowingLayer() { |
| 4939 | return mWindowingLayer; |
| 4940 | } |
| 4941 | |
Vadim Caen | f847426 | 2019-08-12 17:52:01 +0200 | [diff] [blame] | 4942 | SurfaceControl getOverlayLayer() { |
| 4943 | return mOverlayLayer; |
| 4944 | } |
| 4945 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4946 | /** |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4947 | * Updates the display's system gesture exclusion. |
| 4948 | * |
| 4949 | * @return true, if the exclusion changed. |
| 4950 | */ |
| 4951 | boolean updateSystemGestureExclusion() { |
| 4952 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 0) { |
| 4953 | // No one's interested anyways. |
| 4954 | return false; |
| 4955 | } |
| 4956 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4957 | final Region systemGestureExclusion = Region.obtain(); |
| 4958 | mSystemGestureExclusionWasRestricted = calculateSystemGestureExclusion( |
| 4959 | systemGestureExclusion, mSystemGestureExclusionUnrestricted); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4960 | try { |
| 4961 | if (mSystemGestureExclusion.equals(systemGestureExclusion)) { |
| 4962 | return false; |
| 4963 | } |
| 4964 | mSystemGestureExclusion.set(systemGestureExclusion); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4965 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 4966 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4967 | for (int i = mSystemGestureExclusionListeners.beginBroadcast() - 1; i >= 0; --i) { |
| 4968 | try { |
| 4969 | mSystemGestureExclusionListeners.getBroadcastItem(i) |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4970 | .onSystemGestureExclusionChanged(mDisplayId, systemGestureExclusion, |
| 4971 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4972 | } catch (RemoteException e) { |
| 4973 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener", e); |
| 4974 | } |
| 4975 | } |
| 4976 | mSystemGestureExclusionListeners.finishBroadcast(); |
| 4977 | return true; |
| 4978 | } finally { |
| 4979 | systemGestureExclusion.recycle(); |
| 4980 | } |
| 4981 | } |
| 4982 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4983 | /** |
| 4984 | * Calculates the system gesture exclusion. |
| 4985 | * |
| 4986 | * @param outExclusion will be set to the gesture exclusion region |
| 4987 | * @param outExclusionUnrestricted will be set to the gesture exclusion region without |
| 4988 | * any restrictions applied. |
| 4989 | * @return whether any restrictions were applied, i.e. outExclusion and outExclusionUnrestricted |
| 4990 | * differ. |
| 4991 | */ |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 4992 | @VisibleForTesting |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 4993 | boolean calculateSystemGestureExclusion(Region outExclusion, @Nullable |
| 4994 | Region outExclusionUnrestricted) { |
| 4995 | outExclusion.setEmpty(); |
| 4996 | if (outExclusionUnrestricted != null) { |
| 4997 | outExclusionUnrestricted.setEmpty(); |
| 4998 | } |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 4999 | final Region unhandled = Region.obtain(); |
| 5000 | unhandled.set(0, 0, mDisplayFrames.mDisplayWidth, mDisplayFrames.mDisplayHeight); |
| 5001 | |
| 5002 | final Rect leftEdge = mInsetsStateController.getSourceProvider(TYPE_LEFT_GESTURES) |
| 5003 | .getSource().getFrame(); |
| 5004 | final Rect rightEdge = mInsetsStateController.getSourceProvider(TYPE_RIGHT_GESTURES) |
| 5005 | .getSource().getFrame(); |
| 5006 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5007 | final Region touchableRegion = Region.obtain(); |
| 5008 | final Region local = Region.obtain(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5009 | final int[] remainingLeftRight = |
| 5010 | {mSystemGestureExclusionLimit, mSystemGestureExclusionLimit}; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5011 | |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5012 | // Traverse all windows top down to assemble the gesture exclusion rects. |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5013 | // For each window, we only take the rects that fall within its touchable region. |
| 5014 | forAllWindows(w -> { |
| 5015 | if (w.cantReceiveTouchInput() || !w.isVisible() |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5016 | || (w.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 |
| 5017 | || unhandled.isEmpty()) { |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5018 | return; |
| 5019 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5020 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5021 | // Get the touchable region of the window, and intersect with where the screen is still |
| 5022 | // touchable, i.e. touchable regions on top are not covering it yet. |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5023 | w.getEffectiveTouchableRegion(touchableRegion); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5024 | touchableRegion.op(unhandled, Op.INTERSECT); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5025 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5026 | if (w.isImplicitlyExcludingAllSystemGestures()) { |
| 5027 | local.set(touchableRegion); |
| 5028 | } else { |
| 5029 | rectListToRegion(w.getSystemGestureExclusion(), local); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5030 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5031 | // Transform to display coordinates |
| 5032 | local.scale(w.mGlobalScale); |
| 5033 | final Rect frame = w.getWindowFrames().mFrame; |
| 5034 | local.translate(frame.left, frame.top); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5035 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5036 | // A window can only exclude system gestures where it is actually touchable |
| 5037 | local.op(touchableRegion, Op.INTERSECT); |
| 5038 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5039 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5040 | // Apply restriction if necessary. |
| 5041 | if (needsGestureExclusionRestrictions(w, mLastDispatchedSystemUiVisibility)) { |
| 5042 | |
| 5043 | // Processes the region along the left edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5044 | remainingLeftRight[0] = addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5045 | remainingLeftRight[0], w, EXCLUSION_LEFT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5046 | |
| 5047 | // Processes the region along the right edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5048 | remainingLeftRight[1] = addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5049 | remainingLeftRight[1], w, EXCLUSION_RIGHT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5050 | |
| 5051 | // Adds the middle (unrestricted area) |
| 5052 | final Region middle = Region.obtain(local); |
| 5053 | middle.op(leftEdge, Op.DIFFERENCE); |
| 5054 | middle.op(rightEdge, Op.DIFFERENCE); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5055 | outExclusion.op(middle, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5056 | middle.recycle(); |
| 5057 | } else { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5058 | boolean loggable = needsGestureExclusionRestrictions(w, 0 /* lastSysUiVis */); |
| 5059 | if (loggable) { |
| 5060 | addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5061 | Integer.MAX_VALUE, w, EXCLUSION_LEFT); |
| 5062 | addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5063 | Integer.MAX_VALUE, w, EXCLUSION_RIGHT); |
| 5064 | } |
| 5065 | outExclusion.op(local, Op.UNION); |
| 5066 | } |
| 5067 | if (outExclusionUnrestricted != null) { |
| 5068 | outExclusionUnrestricted.op(local, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5069 | } |
| 5070 | unhandled.op(touchableRegion, Op.DIFFERENCE); |
| 5071 | }, true /* topToBottom */); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5072 | local.recycle(); |
| 5073 | touchableRegion.recycle(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5074 | unhandled.recycle(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5075 | return remainingLeftRight[0] < mSystemGestureExclusionLimit |
| 5076 | || remainingLeftRight[1] < mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5077 | } |
| 5078 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5079 | /** |
| 5080 | * @return Whether gesture exclusion area should be restricted from the window depending on the |
| 5081 | * current SystemUI visibility flags. |
| 5082 | */ |
| 5083 | private static boolean needsGestureExclusionRestrictions(WindowState win, int sysUiVisibility) { |
| 5084 | final int type = win.mAttrs.type; |
| 5085 | final int stickyHideNavFlags = |
| 5086 | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 5087 | final boolean stickyHideNav = |
| 5088 | (sysUiVisibility & stickyHideNavFlags) == stickyHideNavFlags; |
| 5089 | return !stickyHideNav && type != TYPE_INPUT_METHOD && type != TYPE_STATUS_BAR |
| 5090 | && win.getActivityType() != ACTIVITY_TYPE_HOME; |
| 5091 | } |
| 5092 | |
| 5093 | /** |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5094 | * @return Whether gesture exclusion area should be logged for the given window |
| 5095 | */ |
| 5096 | static boolean logsGestureExclusionRestrictions(WindowState win) { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 5097 | if (win.mWmService.mConstants.mSystemGestureExclusionLogDebounceTimeoutMillis <= 0) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5098 | return false; |
| 5099 | } |
| 5100 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 5101 | final int type = attrs.type; |
| 5102 | return type != TYPE_WALLPAPER |
| 5103 | && type != TYPE_APPLICATION_STARTING |
| 5104 | && type != TYPE_NAVIGATION_BAR |
| 5105 | && (attrs.flags & FLAG_NOT_TOUCHABLE) == 0 |
| 5106 | && needsGestureExclusionRestrictions(win, 0 /* sysUiVisibility */) |
| 5107 | && win.getDisplayContent().mDisplayPolicy.hasSideGestures(); |
| 5108 | } |
| 5109 | |
| 5110 | /** |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5111 | * Adds a local gesture exclusion area to the global area while applying a limit per edge. |
| 5112 | * |
| 5113 | * @param local The gesture exclusion area to add. |
| 5114 | * @param global The destination. |
| 5115 | * @param edge Only processes the part in that region. |
| 5116 | * @param limit How much limit in pixels we have. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5117 | * @param win The WindowState that is being processed |
| 5118 | * @param side The side that is being processed, either {@link WindowState#EXCLUSION_LEFT} or |
| 5119 | * {@link WindowState#EXCLUSION_RIGHT} |
| 5120 | * @return How much of the limit is remaining. |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5121 | */ |
| 5122 | private static int addToGlobalAndConsumeLimit(Region local, Region global, Rect edge, |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5123 | int limit, WindowState win, int side) { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5124 | final Region r = Region.obtain(local); |
| 5125 | r.op(edge, Op.INTERSECT); |
| 5126 | |
| 5127 | final int[] remaining = {limit}; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5128 | final int[] requestedExclusion = {0}; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5129 | forEachRectReverse(r, rect -> { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5130 | if (remaining[0] <= 0) { |
| 5131 | return; |
| 5132 | } |
| 5133 | final int height = rect.height(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5134 | requestedExclusion[0] += height; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5135 | if (height > remaining[0]) { |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5136 | rect.top = rect.bottom - remaining[0]; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5137 | } |
| 5138 | remaining[0] -= height; |
| 5139 | global.op(rect, Op.UNION); |
| 5140 | }); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5141 | |
| 5142 | final int grantedExclusion = limit - remaining[0]; |
| 5143 | win.setLastExclusionHeights(side, requestedExclusion[0], grantedExclusion); |
| 5144 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5145 | r.recycle(); |
| 5146 | return remaining[0]; |
| 5147 | } |
| 5148 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5149 | void registerSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5150 | mSystemGestureExclusionListeners.register(listener); |
| 5151 | final boolean changed; |
| 5152 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 1) { |
| 5153 | changed = updateSystemGestureExclusion(); |
| 5154 | } else { |
| 5155 | changed = false; |
| 5156 | } |
| 5157 | |
| 5158 | if (!changed) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5159 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5160 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5161 | // If updateSystemGestureExclusion changed the exclusion, it will already have |
| 5162 | // notified the listener. Otherwise, we'll do it here. |
| 5163 | try { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5164 | listener.onSystemGestureExclusionChanged(mDisplayId, mSystemGestureExclusion, |
| 5165 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5166 | } catch (RemoteException e) { |
| 5167 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener during register", e); |
| 5168 | } |
| 5169 | } |
| 5170 | } |
| 5171 | |
| 5172 | void unregisterSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5173 | mSystemGestureExclusionListeners.unregister(listener); |
| 5174 | } |
| 5175 | |
| 5176 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5177 | * Create a portal window handle for input. This window transports any touch to the display |
| 5178 | * indicated by {@link InputWindowHandle#portalToDisplayId} if the touch hits this window. |
| 5179 | * |
| 5180 | * @param name The name of the portal window handle. |
| 5181 | * @return the new portal window handle. |
| 5182 | */ |
| 5183 | private InputWindowHandle createPortalWindowHandle(String name) { |
| 5184 | // Let surface flinger to set the display ID of this input window handle because we don't |
| 5185 | // know which display the parent surface control is on. |
| 5186 | final InputWindowHandle portalWindowHandle = new InputWindowHandle( |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 5187 | null /* inputApplicationHandle */, INVALID_DISPLAY); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5188 | portalWindowHandle.name = name; |
| 5189 | portalWindowHandle.token = new Binder(); |
| 5190 | portalWindowHandle.layoutParamsFlags = |
| 5191 | FLAG_SPLIT_TOUCH | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL; |
| 5192 | getBounds(mTmpBounds); |
| 5193 | portalWindowHandle.touchableRegion.set(mTmpBounds); |
| 5194 | portalWindowHandle.scaleFactor = 1f; |
| 5195 | portalWindowHandle.ownerPid = Process.myPid(); |
| 5196 | portalWindowHandle.ownerUid = Process.myUid(); |
| 5197 | portalWindowHandle.portalToDisplayId = mDisplayId; |
| 5198 | return portalWindowHandle; |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5199 | } |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 5200 | |
| 5201 | /** |
| 5202 | * @see IWindowManager#setForwardedInsets |
| 5203 | */ |
| 5204 | public void setForwardedInsets(Insets insets) { |
| 5205 | if (insets == null) { |
| 5206 | insets = Insets.NONE; |
| 5207 | } |
| 5208 | if (mDisplayPolicy.getForwardedInsets().equals(insets)) { |
| 5209 | return; |
| 5210 | } |
| 5211 | mDisplayPolicy.setForwardedInsets(insets); |
| 5212 | setLayoutNeeded(); |
| 5213 | mWmService.mWindowPlacerLocked.requestTraversal(); |
| 5214 | } |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 5215 | |
| 5216 | protected MetricsLogger getMetricsLogger() { |
| 5217 | if (mMetricsLogger == null) { |
| 5218 | mMetricsLogger = new MetricsLogger(); |
| 5219 | } |
| 5220 | return mMetricsLogger; |
| 5221 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5222 | } |