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; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 37 | import static android.view.InsetsState.ITYPE_IME; |
| 38 | import static android.view.InsetsState.ITYPE_LEFT_GESTURES; |
| 39 | import static android.view.InsetsState.ITYPE_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; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 141 | import android.annotation.IntDef; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 142 | import android.annotation.NonNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 143 | import android.annotation.Nullable; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 144 | import android.content.pm.ActivityInfo.ScreenOrientation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 145 | import android.content.res.CompatibilityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 146 | import android.content.res.Configuration; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 147 | import android.graphics.Bitmap; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 148 | import android.graphics.Insets; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 149 | import android.graphics.Matrix; |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 150 | import android.graphics.Point; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 151 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 152 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 153 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 154 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 155 | import android.hardware.display.DisplayManagerInternal; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 156 | import android.metrics.LogMaker; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 157 | import android.os.Binder; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 158 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 159 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 160 | import android.os.IBinder; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 161 | import android.os.Process; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 162 | import android.os.RemoteCallbackList; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 163 | import android.os.RemoteException; |
| 164 | import android.os.SystemClock; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 165 | import android.os.Trace; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 166 | import android.os.UserHandle; |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 167 | import android.util.ArraySet; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 168 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 169 | import android.util.Slog; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 170 | import android.util.SparseBooleanArray; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 171 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 172 | import android.view.Display; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 173 | import android.view.DisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 174 | import android.view.DisplayInfo; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 175 | import android.view.Gravity; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 176 | import android.view.ISystemGestureExclusionListener; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 177 | import android.view.InputChannel; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 178 | import android.view.InputDevice; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 179 | import android.view.InputWindowHandle; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 180 | import android.view.InsetsState.InternalInsetsType; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 181 | import android.view.MagnificationSpec; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 182 | import android.view.RemoteAnimationDefinition; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 183 | import android.view.Surface; |
| 184 | import android.view.SurfaceControl; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 185 | import android.view.SurfaceControl.Transaction; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 186 | import android.view.SurfaceSession; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 187 | import android.view.View; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 188 | import android.view.WindowManager; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 189 | import android.view.WindowManagerPolicyConstants.PointerEventListener; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 190 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 191 | import com.android.internal.annotations.VisibleForTesting; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 192 | import com.android.internal.logging.MetricsLogger; |
| 193 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 194 | import com.android.internal.util.ToBooleanFunction; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 195 | import com.android.internal.util.function.TriConsumer; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 196 | import com.android.internal.util.function.pooled.PooledConsumer; |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 197 | import com.android.internal.util.function.pooled.PooledFunction; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 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> |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 224 | implements WindowManagerPolicy.DisplayContentInfo { |
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 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 239 | ActivityTaskManagerService mAtmService; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 240 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 241 | /** Unique identifier of this display. */ |
| 242 | private final int mDisplayId; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 243 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 244 | /** The containers below are the only child containers the display can have. */ |
| 245 | // Contains all window containers that are related to apps (Activities) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 246 | private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 247 | // Contains all non-app window containers that should be displayed above the app containers |
| 248 | // (e.g. Status bar) |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 249 | private final AboveAppWindowContainers mAboveAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 250 | new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 251 | // Contains all non-app window containers that should be displayed below the app containers |
| 252 | // (e.g. Wallpaper). |
| 253 | private final NonAppWindowContainers mBelowAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 254 | new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 255 | // Contains all IME window containers. Note that the z-ordering of the IME windows will depend |
| 256 | // 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] | 257 | // window containers together and move them in-sync if/when needed. We use a subclass of |
| 258 | // 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] | 259 | private final NonAppWindowContainers mImeWindowsContainers = |
| 260 | new NonAppWindowContainers("mImeWindowsContainers", mWmService); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 261 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 262 | private WindowState mTmpWindow; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 263 | private WindowState mTmpWindow2; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 264 | private boolean mTmpRecoveringMemory; |
| 265 | private boolean mUpdateImeTarget; |
| 266 | private boolean mTmpInitial; |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 267 | private int mMaxUiWidth; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 268 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 269 | final AppTransition mAppTransition; |
| 270 | final AppTransitionController mAppTransitionController; |
| 271 | boolean mSkipAppTransitionAnimation = false; |
| 272 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 273 | final ArraySet<ActivityRecord> mOpeningApps = new ArraySet<>(); |
| 274 | final ArraySet<ActivityRecord> mClosingApps = new ArraySet<>(); |
| 275 | final ArraySet<ActivityRecord> mChangingApps = new ArraySet<>(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 276 | final UnknownAppVisibilityController mUnknownAppVisibilityController; |
| 277 | BoundsAnimationController mBoundsAnimationController; |
| 278 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 279 | private MetricsLogger mMetricsLogger; |
| 280 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 281 | /** |
| 282 | * List of clients without a transtiton animation that we notify once we are done |
| 283 | * transitioning since they won't be notified through the app window animator. |
| 284 | */ |
| 285 | final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>(); |
| 286 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 287 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 288 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 289 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 290 | // Initial display metrics. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 291 | int mInitialDisplayWidth = 0; |
| 292 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 293 | int mInitialDisplayDensity = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 294 | |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 295 | DisplayCutout mInitialDisplayCutout; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 296 | private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 297 | = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 298 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 299 | /** |
| 300 | * Overridden display size. Initialized with {@link #mInitialDisplayWidth} |
| 301 | * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size". |
| 302 | * @see WindowManagerService#setForcedDisplaySize(int, int, int) |
| 303 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 304 | int mBaseDisplayWidth = 0; |
| 305 | int mBaseDisplayHeight = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 306 | /** |
| 307 | * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity} |
| 308 | * but can be set from Settings or via shell command "adb shell wm density". |
| 309 | * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int) |
| 310 | */ |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 311 | int mBaseDisplayDensity = 0; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 312 | |
| 313 | /** |
| 314 | * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling". |
| 315 | * @see WindowManagerService#setForcedDisplayScalingMode(int, int) |
| 316 | */ |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 317 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 318 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 319 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 320 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 321 | private final DisplayPolicy mDisplayPolicy; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 322 | private final DisplayRotation mDisplayRotation; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 323 | DisplayFrames mDisplayFrames; |
| 324 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 325 | private final RemoteCallbackList<ISystemGestureExclusionListener> |
| 326 | mSystemGestureExclusionListeners = new RemoteCallbackList<>(); |
| 327 | private final Region mSystemGestureExclusion = new Region(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 328 | private boolean mSystemGestureExclusionWasRestricted = false; |
| 329 | private final Region mSystemGestureExclusionUnrestricted = new Region(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 330 | private int mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 331 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 332 | /** |
| 333 | * For default display it contains real metrics, empty for others. |
chaviw | 619da69 | 2019-06-10 15:39:40 -0700 | [diff] [blame] | 334 | * @see WindowManagerService#createWatermark() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 335 | */ |
| 336 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 337 | |
| 338 | /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */ |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 339 | private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 340 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 341 | /** |
| 342 | * Compat metrics computed based on {@link #mDisplayMetrics}. |
| 343 | * @see #updateDisplayAndOrientation(int) |
| 344 | */ |
| 345 | private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 346 | |
| 347 | /** The desired scaling factor for compatible apps. */ |
| 348 | float mCompatibleScreenScale; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 349 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 350 | /** |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 351 | * Orientation forced by some window. If there is no visible window that specifies orientation |
| 352 | * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}. |
| 353 | * |
| 354 | * @see NonAppWindowContainers#getOrientation() |
| 355 | */ |
| 356 | private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 357 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 358 | /** |
| 359 | * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not |
| 360 | * occluded. |
| 361 | * |
| 362 | * @see NonAppWindowContainers#getOrientation() |
| 363 | */ |
| 364 | private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 365 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 366 | /** |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 367 | * The maximum aspect ratio (longerSide/shorterSide) that is treated as close-to-square. The |
| 368 | * orientation requests from apps would be ignored if the display is close-to-square. |
| 369 | */ |
| 370 | @VisibleForTesting |
| 371 | final float mCloseToSquareMaxAspectRatio; |
| 372 | |
| 373 | /** |
| 374 | * If this is true, we would not rotate the display for apps. The rotation would be either the |
| 375 | * sensor rotation or the user rotation, controlled by |
| 376 | * {@link WindowManagerPolicy.UserRotationMode}. |
| 377 | */ |
| 378 | private boolean mIgnoreRotationForApps; |
| 379 | |
| 380 | /** |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 381 | * Keep track of wallpaper visibility to notify changes. |
| 382 | */ |
| 383 | private boolean mLastWallpaperVisible = false; |
| 384 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 385 | private Rect mBaseDisplayRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 386 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 387 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 388 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 389 | int pendingLayoutChanges; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 390 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 391 | /** |
| 392 | * Used to gate application window layout until we have sent the complete configuration. |
| 393 | * TODO: There are still scenarios where we may be out of sync with the client. Ideally |
| 394 | * we want to replace this flag with a mechanism that will confirm the configuration |
| 395 | * applied by the client is the one expected by the system server. |
| 396 | */ |
| 397 | boolean mWaitingForConfig; |
| 398 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 399 | // TODO(multi-display): remove some of the usages. |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 400 | @VisibleForTesting |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 401 | boolean isDefaultDisplay; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 402 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 403 | /** |
| 404 | * Flag indicating whether WindowManager should override info for this display in |
| 405 | * DisplayManager. |
| 406 | */ |
| 407 | boolean mShouldOverrideDisplayConfiguration = true; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 408 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 409 | /** 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] | 410 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 411 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 412 | /** Detect user tapping outside of current focused task bounds .*/ |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 413 | @VisibleForTesting |
| 414 | final TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 415 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 416 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 417 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 418 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 419 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 420 | private final Rect mTmpRect = new Rect(); |
| 421 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 422 | private final RectF mTmpRectF = new RectF(); |
| 423 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 424 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 425 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 426 | /** Used for handing back size of display */ |
| 427 | private final Rect mTmpBounds = new Rect(); |
| 428 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 429 | private final Configuration mTmpConfiguration = new Configuration(); |
| 430 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 431 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 432 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 433 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 434 | final DockedStackDividerController mDividerControllerLocked; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 435 | final PinnedStackController mPinnedStackControllerLocked; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 436 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 437 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 438 | /** A collection of windows that provide tap exclude regions inside of them. */ |
| 439 | final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>(); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 440 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 441 | private final LinkedList<ActivityRecord> mTmpUpdateAllDrawn = new LinkedList(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 442 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 443 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 444 | new TaskForResizePointSearchResult(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 445 | private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState = |
| 446 | new ApplySurfaceChangesTransactionState(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 447 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 448 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 449 | // the display's direct children should be allowed. |
| 450 | private boolean mRemovingDisplay = false; |
| 451 | |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 452 | // {@code false} if this display is in the processing of being created. |
| 453 | private boolean mDisplayReady = false; |
| 454 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 455 | WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 456 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 457 | boolean mWallpaperMayChange = false; |
| 458 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 459 | private final SurfaceSession mSession = new SurfaceSession(); |
| 460 | |
| 461 | /** |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 462 | * Window that is currently interacting with the user. This window is responsible for receiving |
| 463 | * key events and pointer events from the user. |
| 464 | */ |
| 465 | WindowState mCurrentFocus = null; |
| 466 | |
| 467 | /** |
| 468 | * The last focused window that we've notified the client that the focus is changed. |
| 469 | */ |
| 470 | WindowState mLastFocus = null; |
| 471 | |
| 472 | /** |
| 473 | * Windows that have lost input focus and are waiting for the new focus window to be displayed |
| 474 | * before they are told about this. |
| 475 | */ |
| 476 | ArrayList<WindowState> mLosingFocus = new ArrayList<>(); |
| 477 | |
| 478 | /** |
| 479 | * The foreground app of this display. Windows below this app cannot be the focused window. If |
| 480 | * the user taps on the area outside of the task of the focused app, we will notify AM about the |
| 481 | * new task the user wants to interact with. |
| 482 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 483 | ActivityRecord mFocusedApp = null; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 484 | |
| 485 | /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 486 | final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>(); |
| 487 | |
| 488 | /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 489 | final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>(); |
| 490 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 491 | private ScreenRotationAnimation mScreenRotationAnimation; |
| 492 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 493 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 494 | * We organize all top-level Surfaces in to the following layers. |
| 495 | * mOverlayLayer contains a few Surfaces which are always on top of others |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 496 | * and omitted from Screen-Magnification, for example the strict mode flash or |
| 497 | * the magnification overlay itself. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 498 | * {@link #mWindowingLayer} contains everything else. |
| 499 | */ |
| 500 | private SurfaceControl mOverlayLayer; |
| 501 | |
| 502 | /** |
| 503 | * See {@link #mOverlayLayer} |
| 504 | */ |
| 505 | private SurfaceControl mWindowingLayer; |
| 506 | |
| 507 | /** |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 508 | * Sequence number for the current layout pass. |
| 509 | */ |
| 510 | int mLayoutSeq = 0; |
| 511 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 512 | /** |
| 513 | * Specifies the count to determine whether to defer updating the IME target until ready. |
| 514 | */ |
| 515 | private int mDeferUpdateImeTargetCount; |
| 516 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 517 | private MagnificationSpec mMagnificationSpec; |
| 518 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 519 | private InputMonitor mInputMonitor; |
| 520 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 521 | /** Caches the value whether told display manager that we have content. */ |
| 522 | private boolean mLastHasContent; |
| 523 | |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 524 | private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil(); |
| 525 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 526 | /** |
| 527 | * The input method window for this display. |
| 528 | */ |
| 529 | WindowState mInputMethodWindow; |
| 530 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 531 | /** |
| 532 | * This just indicates the window the input method is on top of, not |
| 533 | * necessarily the window its input is going to. |
| 534 | */ |
| 535 | WindowState mInputMethodTarget; |
| 536 | |
| 537 | /** If true hold off on modifying the animation layer of mInputMethodTarget */ |
| 538 | boolean mInputMethodTargetWaitingAnim; |
| 539 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 540 | private final PointerEventDispatcher mPointerEventDispatcher; |
| 541 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 542 | private final InsetsStateController mInsetsStateController; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 543 | private final InsetsPolicy mInsetsPolicy; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 544 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 545 | /** @see #getParentWindow() */ |
| 546 | private WindowState mParentWindow; |
| 547 | |
| 548 | private Point mLocationInParentWindow = new Point(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 549 | private SurfaceControl mParentSurfaceControl; |
| 550 | private InputWindowHandle mPortalWindowHandle; |
| 551 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 552 | // Last systemUiVisibility we received from status bar. |
| 553 | private int mLastStatusBarVisibility = 0; |
| 554 | // Last systemUiVisibility we dispatched to windows. |
| 555 | private int mLastDispatchedSystemUiVisibility = 0; |
| 556 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 557 | private final ArrayList<ActivityStack> mTmpAlwaysOnTopStacks = new ArrayList<>(); |
| 558 | private final ArrayList<ActivityStack> mTmpNormalStacks = new ArrayList<>(); |
| 559 | private final ArrayList<ActivityStack> mTmpHomeStacks = new ArrayList<>(); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 560 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 561 | /** Corner radius that windows should have in order to match the display. */ |
| 562 | private final float mWindowCornerRadius; |
| 563 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 564 | private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> { |
| 565 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 566 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 567 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 568 | if (activity == null || activity.canShowWindows()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 569 | if (w.performShowLocked()) { |
| 570 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 571 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 572 | mWmService.mWindowPlacerLocked.debugLayoutRepeats( |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 573 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 578 | }; |
| 579 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 580 | private final Consumer<WindowState> mScheduleToastTimeout = w -> { |
| 581 | final int lostFocusUid = mTmpWindow.mOwnerUid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 582 | final Handler handler = mWmService.mH; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 583 | if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) { |
| 584 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) { |
| 585 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), |
| 586 | w.mAttrs.hideTimeoutMilliseconds); |
| 587 | } |
| 588 | } |
| 589 | }; |
| 590 | |
| 591 | private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 592 | final ActivityRecord focusedApp = mFocusedApp; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 593 | ProtoLog.v(WM_DEBUG_FOCUS, "Looking for focus: %s, flags=%d, canReceive=%b", |
| 594 | w, w.mAttrs.flags, w.canReceiveKeys()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 595 | |
| 596 | if (!w.canReceiveKeys()) { |
| 597 | return false; |
| 598 | } |
| 599 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 600 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 601 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 602 | if (focusedApp == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 603 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 604 | "findFocusedWindow: focusedApp=null using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 605 | mTmpWindow = w; |
| 606 | return true; |
| 607 | } |
| 608 | |
| 609 | if (!focusedApp.windowsAreFocusable()) { |
| 610 | // Current focused app windows aren't focusable... |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 611 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: focusedApp windows not" |
| 612 | + " focusable using new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 613 | mTmpWindow = w; |
| 614 | return true; |
| 615 | } |
| 616 | |
| 617 | // 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] | 618 | // win.mActivityRecord (return win) or mFocusedApp (return null). |
| 619 | if (activity != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 620 | if (focusedApp.compareTo(activity) > 0) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 621 | // App stack below focused app stack. No focus for you!!! |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 622 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, |
| 623 | "findFocusedWindow: Reached focused app=%s", focusedApp); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 624 | mTmpWindow = null; |
| 625 | return true; |
| 626 | } |
| 627 | } |
| 628 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 629 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: Found new focus @ %s", w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 630 | mTmpWindow = w; |
| 631 | return true; |
| 632 | }; |
| 633 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 634 | private final Consumer<WindowState> mPerformLayout = w -> { |
| 635 | // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid |
| 636 | // wasting time and funky changes while a window is animating away. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 637 | final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 638 | || w.isGoneForLayoutLw(); |
| 639 | |
| 640 | if (DEBUG_LAYOUT && !w.mLayoutAttached) { |
| 641 | Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame |
| 642 | + " mLayoutAttached=" + w.mLayoutAttached |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 643 | + " config reported=" + w.isLastConfigReportedToClient()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 644 | final ActivityRecord activity = w.mActivityRecord; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 645 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 646 | + " mRelayoutCalled=" + w.mRelayoutCalled + " visible=" + w.mToken.isVisible() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 647 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 648 | + " parentHidden=" + w.isParentWindowHidden()); |
| 649 | else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 650 | + " mRelayoutCalled=" + w.mRelayoutCalled + " visible=" + w.mToken.isVisible() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 651 | + " visibleRequested=" + (activity != null && activity.mVisibleRequested) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 652 | + " parentHidden=" + w.isParentWindowHidden()); |
| 653 | } |
| 654 | |
| 655 | // If this view is GONE, then skip it -- keep the current frame, and let the caller know |
| 656 | // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows, |
| 657 | // since that means "perform layout as normal, just don't display"). |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 658 | if ((!gone || !w.mHaveFrame || w.mLayoutNeeded) && !w.mLayoutAttached) { |
| 659 | if (mTmpInitial) { |
| 660 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 661 | } |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 662 | if (w.mAttrs.type == TYPE_DREAM) { |
| 663 | // Don't layout windows behind a dream, so that if it does stuff like hide |
| 664 | // the status bar we won't get a bad transition when it goes away. |
| 665 | mTmpWindow = w; |
| 666 | } |
| 667 | w.mLayoutNeeded = false; |
| 668 | w.prelayout(); |
| 669 | final boolean firstLayout = !w.isLaidOut(); |
| 670 | getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames); |
| 671 | w.mLayoutSeq = mLayoutSeq; |
| 672 | |
Riddle Hsu | f64e134 | 2019-12-05 17:38:41 +0800 | [diff] [blame] | 673 | // If this is the first layout, we need to initialize the last frames and inset values, |
| 674 | // as otherwise we'd immediately cause an unnecessary resize. |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 675 | if (firstLayout) { |
Riddle Hsu | f64e134 | 2019-12-05 17:38:41 +0800 | [diff] [blame] | 676 | w.updateLastFrames(); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 677 | w.updateLastInsetValues(); |
Riddle Hsu | f64e134 | 2019-12-05 17:38:41 +0800 | [diff] [blame] | 678 | w.updateLocationInParentDisplayIfNeeded(); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 679 | } |
| 680 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 681 | if (w.mActivityRecord != null) { |
| 682 | w.mActivityRecord.layoutLetterbox(w); |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
| 686 | + " mContainingFrame=" + w.getContainingFrame() |
| 687 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 688 | } |
| 689 | }; |
| 690 | |
| 691 | private final Consumer<WindowState> mPerformLayoutAttached = w -> { |
| 692 | if (w.mLayoutAttached) { |
| 693 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame |
| 694 | + " mViewVisibility=" + w.mViewVisibility |
| 695 | + " mRelayoutCalled=" + w.mRelayoutCalled); |
| 696 | // If this view is GONE, then skip it -- keep the current frame, and let the caller |
| 697 | // know so they can ignore it if they want. (We do the normal layout for INVISIBLE |
| 698 | // windows, since that means "perform layout as normal, just don't display"). |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 699 | if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame |
| 703 | || w.mLayoutNeeded) { |
| 704 | if (mTmpInitial) { |
| 705 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 706 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 707 | } |
| 708 | w.mLayoutNeeded = false; |
| 709 | w.prelayout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 710 | getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 711 | w.mLayoutSeq = mLayoutSeq; |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 712 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 713 | + " mContainingFrame=" + w.getContainingFrame() |
| 714 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 715 | } |
| 716 | } else if (w.mAttrs.type == TYPE_DREAM) { |
| 717 | // Don't layout windows behind a dream, so that if it does stuff like hide the |
| 718 | // status bar we won't get a bad transition when it goes away. |
| 719 | mTmpWindow = mTmpWindow2; |
| 720 | } |
| 721 | }; |
| 722 | |
| 723 | private final Predicate<WindowState> mComputeImeTargetPredicate = w -> { |
| 724 | if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w |
| 725 | + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| 726 | return w.canBeImeTarget(); |
| 727 | }; |
| 728 | |
| 729 | private final Consumer<WindowState> mApplyPostLayoutPolicy = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 730 | w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 731 | mInputMethodTarget); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 732 | |
| 733 | private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 734 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 735 | final boolean obscuredChanged = w.mObscured != |
| 736 | mTmpApplySurfaceChangesTransactionState.obscured; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 737 | final RootWindowContainer root = mWmService.mRoot; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 738 | |
| 739 | // Update effect. |
| 740 | w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured; |
| 741 | if (!mTmpApplySurfaceChangesTransactionState.obscured) { |
| 742 | final boolean isDisplayed = w.isDisplayedLw(); |
| 743 | |
| 744 | if (isDisplayed && w.isObscuringDisplay()) { |
| 745 | // This window completely covers everything behind it, so we want to leave all |
| 746 | // of them as undimmed (for performance reasons). |
| 747 | root.mObscuringWindow = w; |
| 748 | mTmpApplySurfaceChangesTransactionState.obscured = true; |
| 749 | } |
| 750 | |
Arthur Hung | fbc8f41 | 2019-08-01 19:57:54 +0800 | [diff] [blame] | 751 | final boolean displayHasContent = root.handleNotObscuredLocked(w, |
| 752 | mTmpApplySurfaceChangesTransactionState.obscured, |
| 753 | mTmpApplySurfaceChangesTransactionState.syswin); |
| 754 | |
| 755 | if (!mTmpApplySurfaceChangesTransactionState.displayHasContent |
| 756 | && !getDisplayPolicy().isWindowExcludedFromContent(w)) { |
| 757 | mTmpApplySurfaceChangesTransactionState.displayHasContent |= displayHasContent; |
| 758 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 759 | |
| 760 | if (w.mHasSurface && isDisplayed) { |
| 761 | final int type = w.mAttrs.type; |
| 762 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
| 763 | || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 764 | mTmpApplySurfaceChangesTransactionState.syswin = true; |
| 765 | } |
| 766 | if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0 |
| 767 | && w.mAttrs.preferredRefreshRate != 0) { |
| 768 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate |
| 769 | = w.mAttrs.preferredRefreshRate; |
| 770 | } |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 771 | final int preferredModeId = getDisplayPolicy().getRefreshRatePolicy() |
| 772 | .getPreferredModeId(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 773 | if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0 |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 774 | && preferredModeId != 0) { |
| 775 | mTmpApplySurfaceChangesTransactionState.preferredModeId = preferredModeId; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 780 | if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 781 | // This is the wallpaper target and its obscured state changed... make sure the |
| 782 | // current wallpaper's visibility has been updated accordingly. |
| 783 | mWallpaperController.updateWallpaperVisibility(); |
| 784 | } |
| 785 | |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 786 | w.handleWindowMovedIfNeeded(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 787 | |
| 788 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 789 | |
| 790 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 791 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 792 | |
| 793 | // Moved from updateWindowsAndWallpaperLocked(). |
| 794 | if (w.mHasSurface) { |
| 795 | // Take care of the window being ready to display. |
| 796 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 797 | if (isDefaultDisplay && committed) { |
| 798 | if (w.mAttrs.type == TYPE_DREAM) { |
| 799 | // HACK: When a dream is shown, it may at that point hide the lock screen. |
| 800 | // So we need to redo the layout to let the phone window manager make this |
| 801 | // happen. |
| 802 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 803 | if (DEBUG_LAYOUT_REPEATS) { |
| 804 | surfacePlacer.debugLayoutRepeats( |
| 805 | "dream and commitFinishDrawingLocked true", |
| 806 | pendingLayoutChanges); |
| 807 | } |
| 808 | } |
| 809 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 810 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 811 | "First draw done in potential wallpaper target " + w); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 812 | mWallpaperMayChange = true; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 813 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 814 | if (DEBUG_LAYOUT_REPEATS) { |
| 815 | surfacePlacer.debugLayoutRepeats( |
| 816 | "wallpaper and commitFinishDrawingLocked true", |
| 817 | pendingLayoutChanges); |
| 818 | } |
| 819 | } |
| 820 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 821 | } |
| 822 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 823 | final ActivityRecord activity = w.mActivityRecord; |
| 824 | if (activity != null) { |
| 825 | activity.updateLetterboxSurface(w); |
| 826 | final boolean updateAllDrawn = activity.updateDrawnWindowStates(w); |
| 827 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(activity)) { |
| 828 | mTmpUpdateAllDrawn.add(activity); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 832 | if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 833 | mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | w.updateResizingWindowIfNeeded(); |
| 837 | }; |
| 838 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 839 | /** |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 840 | * Create new {@link DisplayContent} instance, add itself to the root window container and |
| 841 | * initialize direct children. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 842 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 843 | * @param service You know. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 844 | * @param activityDisplay The ActivityDisplay for the display container. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 845 | */ |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 846 | DisplayContent(Display display, WindowManagerService service) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 847 | super(service); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 848 | if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) { |
| 849 | throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() |
| 850 | + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId()) |
| 851 | + " new=" + display); |
| 852 | } |
| 853 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 854 | mAtmService = mWmService.mAtmService; |
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 | */ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 1096 | void setInsetProvider(@InternalInsetsType int type, WindowState win, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 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 | |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1128 | void reconfigureDisplayLocked() { |
| 1129 | if (!isReady()) { |
| 1130 | return; |
| 1131 | } |
| 1132 | configureDisplayPolicy(); |
| 1133 | setLayoutNeeded(); |
| 1134 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1135 | boolean configChanged = updateOrientation(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1136 | final Configuration currentDisplayConfig = getConfiguration(); |
| 1137 | mTmpConfiguration.setTo(currentDisplayConfig); |
| 1138 | computeScreenConfiguration(mTmpConfiguration); |
| 1139 | configChanged |= currentDisplayConfig.diff(mTmpConfiguration) != 0; |
| 1140 | |
| 1141 | if (configChanged) { |
| 1142 | mWaitingForConfig = true; |
| 1143 | mWmService.startFreezingDisplayLocked(0 /* exitAnim */, 0 /* enterAnim */, this); |
| 1144 | sendNewConfiguration(); |
| 1145 | } |
| 1146 | |
| 1147 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1148 | } |
| 1149 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1150 | void sendNewConfiguration() { |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1151 | if (!isReady()) { |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1152 | return; |
| 1153 | } |
Evan Rosky | 69cace4 | 2019-09-20 16:28:13 -0700 | [diff] [blame] | 1154 | if (mDisplayRotation.isWaitingForRemoteRotation()) { |
| 1155 | return; |
| 1156 | } |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1157 | // TODO(display-merge): Remove cast |
| 1158 | final boolean configUpdated = |
| 1159 | ((ActivityDisplay) this).updateDisplayOverrideConfigurationLocked(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 1160 | if (configUpdated) { |
| 1161 | return; |
| 1162 | } |
| 1163 | // Something changed (E.g. device rotation), but no configuration update is needed. |
| 1164 | // E.g. changing device rotation by 180 degrees. Go ahead and perform surface placement to |
| 1165 | // unfreeze the display since we froze it when the rotation was updated in |
| 1166 | // DisplayContent#updateRotationUnchecked. |
| 1167 | if (mWaitingForConfig) { |
| 1168 | mWaitingForConfig = false; |
| 1169 | mWmService.mLastFinishedFreezeSource = "config-unchanged"; |
| 1170 | setLayoutNeeded(); |
| 1171 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1175 | @Override |
| 1176 | boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, |
| 1177 | ConfigurationContainer requestingContainer) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1178 | final Configuration config = updateOrientation( |
| 1179 | getRequestedOverrideConfiguration(), freezeDisplayToken, false /* forceUpdate */); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1180 | // If display rotation class tells us that it doesn't consider app requested orientation, |
| 1181 | // this display won't rotate just because of an app changes its requested orientation. Thus |
| 1182 | // it indicates that this display chooses not to handle this request. |
| 1183 | final boolean handled = getDisplayRotation().respectAppRequestedOrientation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1184 | if (config == null) { |
| 1185 | return handled; |
| 1186 | } |
| 1187 | |
| 1188 | if (handled && requestingContainer instanceof ActivityRecord) { |
| 1189 | final ActivityRecord activityRecord = (ActivityRecord) requestingContainer; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1190 | // TODO(display-merge): Remove cast |
| 1191 | final boolean kept = ((ActivityDisplay) this).updateDisplayOverrideConfigurationLocked( |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1192 | config, activityRecord, false /* deferResume */, null /* result */); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1193 | activityRecord.frozenBeforeDestroy = true; |
| 1194 | if (!kept) { |
| 1195 | mWmService.mAtmService.mRootActivityContainer.resumeFocusedStacksTopActivities(); |
| 1196 | } |
| 1197 | } else { |
| 1198 | // We have a new configuration to push so we need to update ATMS for now. |
| 1199 | // TODO: Clean up display configuration push between ATMS and WMS after unification. |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1200 | // TODO(display-merge): Remove cast |
| 1201 | ((ActivityDisplay) this.mDisplayContent).updateDisplayOverrideConfigurationLocked( |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 1202 | config, null /* starting */, false /* deferResume */, null); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1203 | } |
| 1204 | return handled; |
| 1205 | } |
| 1206 | |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1207 | @Override |
| 1208 | boolean handlesOrientationChangeFromDescendant() { |
| 1209 | return getDisplayRotation().respectAppRequestedOrientation(); |
| 1210 | } |
| 1211 | |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1212 | /** |
| 1213 | * Determine the new desired orientation of this display. |
| 1214 | * |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1215 | * @see #getOrientation() |
| 1216 | * @return {@code true} if the orientation is changed and the caller should call |
| 1217 | * {@link #sendNewConfiguration} if the method returns {@code true}. |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1218 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1219 | boolean updateOrientation() { |
| 1220 | return mDisplayRotation.updateOrientation(getOrientation(), false /* forceUpdate */); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1221 | } |
| 1222 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1223 | /** |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1224 | * 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] | 1225 | * changed from the current orientation. If a non-null configuration is returned, someone must |
| 1226 | * call {@link WindowManagerService#setNewDisplayOverrideConfiguration(Configuration, |
| 1227 | * 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] | 1228 | * be done by calling {@link #sendNewConfiguration}. |
| 1229 | * |
| 1230 | * @param currentConfig The current requested override configuration (it is usually set from |
| 1231 | * the last {@link #sendNewConfiguration}) of the display. It is used to |
| 1232 | * check if the configuration container has the latest state. |
| 1233 | * @param freezeDisplayToken Freeze the app window token if the orientation is changed. |
| 1234 | * @param forceUpdate See {@link DisplayRotation#updateRotationUnchecked(boolean)} |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1235 | */ |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1236 | Configuration updateOrientation(Configuration currentConfig, IBinder freezeDisplayToken, |
| 1237 | boolean forceUpdate) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1238 | if (!mDisplayReady) { |
| 1239 | return null; |
| 1240 | } |
| 1241 | |
| 1242 | Configuration config = null; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1243 | if (mDisplayRotation.updateOrientation(getOrientation(), forceUpdate)) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1244 | // If we changed the orientation but mOrientationChangeComplete is already true, |
| 1245 | // we used seamless rotation, and we don't need to freeze the screen. |
| 1246 | if (freezeDisplayToken != null && !mWmService.mRoot.mOrientationChangeComplete) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1247 | final ActivityRecord activity = getActivityRecord(freezeDisplayToken); |
| 1248 | if (activity != null) { |
| 1249 | activity.startFreezingScreen(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | config = new Configuration(); |
| 1253 | computeScreenConfiguration(config); |
| 1254 | } else if (currentConfig != null) { |
| 1255 | // No obvious action we need to take, but if our current state mismatches the |
| 1256 | // activity manager's, update it, disregarding font scale, which should remain set |
| 1257 | // to the value of the previous configuration. |
| 1258 | // Here we're calling Configuration#unset() instead of setToDefaults() because we |
| 1259 | // need to keep override configs clear of non-empty values (e.g. fontSize). |
| 1260 | mTmpConfiguration.unset(); |
| 1261 | mTmpConfiguration.updateFrom(currentConfig); |
| 1262 | computeScreenConfiguration(mTmpConfiguration); |
| 1263 | if (currentConfig.diff(mTmpConfiguration) != 0) { |
| 1264 | mWaitingForConfig = true; |
| 1265 | setLayoutNeeded(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1266 | mDisplayRotation.prepareNormalRotationAnimation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1267 | config = new Configuration(mTmpConfiguration); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | return config; |
| 1272 | } |
| 1273 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1274 | /** |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1275 | * Update rotation of the display. |
| 1276 | * |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1277 | * @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] | 1278 | * {@link #sendNewConfiguration} TO UNFREEZE THE SCREEN. |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1279 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1280 | boolean updateRotationUnchecked() { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1281 | return mDisplayRotation.updateRotationUnchecked(false /* forceUpdate */); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked} |
| 1286 | * (if it returned {@code true}) to actually finish the rotation. |
| 1287 | * |
| 1288 | * @param oldRotation the rotation we are coming from. |
| 1289 | * @param rotation the rotation to apply. |
| 1290 | */ |
| 1291 | void applyRotationLocked(final int oldRotation, final int rotation) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1292 | mDisplayRotation.applyCurrentRotation(rotation); |
| 1293 | final boolean rotateSeamlessly = mDisplayRotation.isRotatingSeamlessly(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1294 | final Transaction transaction = getPendingTransaction(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 1295 | ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly |
| 1296 | ? null : getRotationAnimation(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1297 | // We need to update our screen size information to match the new rotation. If the rotation |
| 1298 | // has actually changed then this method will return true and, according to the comment at |
| 1299 | // the top of the method, the caller is obligated to call computeNewConfigurationLocked(). |
| 1300 | // By updating the Display info here it will be available to |
| 1301 | // #computeScreenConfiguration() later. |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1302 | updateDisplayAndOrientation(getConfiguration().uiMode, null /* outConfig */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1303 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1304 | // NOTE: We disable the rotation in the emulator because |
| 1305 | // it doesn't support hardware OpenGL emulation yet. |
Vadim Caen | ba4fd6c | 2019-08-05 16:45:46 +0200 | [diff] [blame] | 1306 | if (screenRotationAnimation != null && screenRotationAnimation.hasScreenshot()) { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1307 | screenRotationAnimation.setRotation(transaction, rotation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1310 | forAllWindows(w -> { |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1311 | w.seamlesslyRotateIfAllowed(transaction, oldRotation, rotation, rotateSeamlessly); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1312 | }, true /* traverseTopToBottom */); |
| 1313 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1314 | mWmService.mDisplayManagerInternal.performTraversal(transaction); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1315 | scheduleAnimation(); |
| 1316 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1317 | forAllWindows(w -> { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1318 | if (w.mHasSurface && !rotateSeamlessly) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1319 | ProtoLog.v(WM_DEBUG_ORIENTATION, "Set mOrientationChanging of %s", w); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1320 | w.setOrientationChanging(true); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1321 | mWmService.mRoot.mOrientationChangeComplete = false; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1322 | w.mLastFreezeDuration = 0; |
| 1323 | } |
| 1324 | w.mReportOrientationChanged = true; |
| 1325 | }, true /* traverseTopToBottom */); |
| 1326 | |
| 1327 | if (rotateSeamlessly) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1328 | mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT, |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1329 | this, SEAMLESS_ROTATION_TIMEOUT_DURATION); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1332 | for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1333 | final WindowManagerService.RotationWatcher rotationWatcher |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1334 | = mWmService.mRotationWatchers.get(i); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1335 | if (rotationWatcher.mDisplayId == mDisplayId) { |
| 1336 | try { |
| 1337 | rotationWatcher.mWatcher.onRotationChanged(rotation); |
| 1338 | } catch (RemoteException e) { |
| 1339 | // Ignore |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1344 | // Announce rotation only if we will not animate as we already have the |
| 1345 | // 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] | 1346 | if (screenRotationAnimation == null && mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1347 | mWmService.mAccessibilityController.onRotationChangedLocked(this); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1348 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1351 | void configureDisplayPolicy() { |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1352 | final int width = mBaseDisplayWidth; |
| 1353 | final int height = mBaseDisplayHeight; |
| 1354 | final int shortSize; |
| 1355 | final int longSize; |
| 1356 | if (width > height) { |
| 1357 | shortSize = height; |
| 1358 | longSize = width; |
| 1359 | } else { |
| 1360 | shortSize = width; |
| 1361 | longSize = height; |
| 1362 | } |
| 1363 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 1364 | final int shortSizeDp = shortSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
| 1365 | final int longSizeDp = longSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1366 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1367 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 1368 | mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1369 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1370 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 1371 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1372 | |
| 1373 | // Not much of use to rotate the display for apps since it's close to square. |
| 1374 | mIgnoreRotationForApps = isNonDecorDisplayCloseToSquare(Surface.ROTATION_0, width, height); |
| 1375 | } |
| 1376 | |
| 1377 | private boolean isNonDecorDisplayCloseToSquare(int rotation, int width, int height) { |
| 1378 | final DisplayCutout displayCutout = |
| 1379 | calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
| 1380 | final int uiMode = mWmService.mPolicy.getUiMode(); |
| 1381 | final int w = mDisplayPolicy.getNonDecorDisplayWidth( |
| 1382 | width, height, rotation, uiMode, displayCutout); |
| 1383 | final int h = mDisplayPolicy.getNonDecorDisplayHeight( |
| 1384 | width, height, rotation, uiMode, displayCutout); |
| 1385 | final float aspectRatio = Math.max(w, h) / (float) Math.min(w, h); |
| 1386 | return aspectRatio <= mCloseToSquareMaxAspectRatio; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1389 | /** |
| 1390 | * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config |
| 1391 | * changed. |
| 1392 | * Do not call if {@link WindowManagerService#mDisplayReady} == false. |
| 1393 | */ |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1394 | private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1395 | // Use the effective "visual" dimensions based on current rotation |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1396 | final int rotation = getRotation(); |
| 1397 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1398 | final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1399 | final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1400 | |
| 1401 | // Update application display metrics. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1402 | final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(rotation); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1403 | final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout(); |
| 1404 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1405 | final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1406 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1407 | final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1408 | displayCutout); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1409 | mDisplayInfo.rotation = rotation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1410 | mDisplayInfo.logicalWidth = dw; |
| 1411 | mDisplayInfo.logicalHeight = dh; |
| 1412 | mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity; |
| 1413 | mDisplayInfo.appWidth = appWidth; |
| 1414 | mDisplayInfo.appHeight = appHeight; |
| 1415 | if (isDefaultDisplay) { |
| 1416 | mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics, |
| 1417 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
| 1418 | } |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1419 | mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1420 | mDisplayInfo.getAppMetrics(mDisplayMetrics); |
| 1421 | if (mDisplayScalingDisabled) { |
| 1422 | mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED; |
| 1423 | } else { |
| 1424 | mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED; |
| 1425 | } |
| 1426 | |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1427 | computeSizeRangesAndScreenLayout(mDisplayInfo, rotated, uiMode, dw, dh, |
| 1428 | mDisplayMetrics.density, outConfig); |
| 1429 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1430 | // We usually set the override info in DisplayManager so that we get consistent display |
| 1431 | // metrics values when displays are changing and don't send out new values until WM is aware |
| 1432 | // of them. However, we don't do this for displays that serve as containers for ActivityView |
| 1433 | // because we don't want letter-/pillar-boxing during resize. |
| 1434 | final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration |
| 1435 | ? mDisplayInfo : null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1436 | mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId, |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1437 | overrideDisplayInfo); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1438 | |
| 1439 | mBaseDisplayRect.set(0, 0, dw, dh); |
| 1440 | |
| 1441 | if (isDefaultDisplay) { |
| 1442 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics, |
| 1443 | mCompatDisplayMetrics); |
| 1444 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1445 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1446 | return mDisplayInfo; |
| 1447 | } |
| 1448 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1449 | WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) { |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1450 | return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation); |
| 1451 | } |
| 1452 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1453 | private WmDisplayCutout calculateDisplayCutoutForRotationUncached( |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1454 | DisplayCutout cutout, int rotation) { |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1455 | if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1456 | return WmDisplayCutout.NO_CUTOUT; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1457 | } |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1458 | if (rotation == ROTATION_0) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1459 | return WmDisplayCutout.computeSafeInsets( |
| 1460 | cutout, mInitialDisplayWidth, mInitialDisplayHeight); |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1461 | } |
Adrian Roos | bed538e | 2018-02-21 17:50:07 +0100 | [diff] [blame] | 1462 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1463 | final Rect[] newBounds = mRotationUtil.getRotatedBounds( |
| 1464 | WmDisplayCutout.computeSafeInsets( |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 1465 | cutout, mInitialDisplayWidth, mInitialDisplayHeight) |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1466 | .getDisplayCutout().getBoundingRectsAll(), |
| 1467 | rotation, mInitialDisplayWidth, mInitialDisplayHeight); |
| 1468 | return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds), |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1469 | rotated ? mInitialDisplayHeight : mInitialDisplayWidth, |
| 1470 | rotated ? mInitialDisplayWidth : mInitialDisplayHeight); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1473 | /** |
| 1474 | * Compute display configuration based on display properties and policy settings. |
| 1475 | * Do not call if mDisplayReady == false. |
| 1476 | */ |
| 1477 | void computeScreenConfiguration(Configuration config) { |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1478 | final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode, config); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1479 | calculateBounds(displayInfo, mTmpBounds); |
| 1480 | config.windowConfiguration.setBounds(mTmpBounds); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1481 | |
| 1482 | final int dw = displayInfo.logicalWidth; |
| 1483 | final int dh = displayInfo.logicalHeight; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 1484 | config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 1485 | config.windowConfiguration.setWindowingMode(getWindowingMode()); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 1486 | config.windowConfiguration.setDisplayWindowingMode(getWindowingMode()); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1487 | config.windowConfiguration.setRotation(displayInfo.rotation); |
Bryce Lee | c1f2f2a | 2017-06-22 15:29:42 -0700 | [diff] [blame] | 1488 | |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1489 | final float density = mDisplayMetrics.density; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1490 | config.screenWidthDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1491 | (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation, |
| 1492 | config.uiMode, displayInfo.displayCutout) / density); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1493 | config.screenHeightDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1494 | (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation, |
| 1495 | config.uiMode, displayInfo.displayCutout) / density); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1496 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1497 | mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1498 | displayInfo.displayCutout, mTmpRect); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1499 | final int leftInset = mTmpRect.left; |
| 1500 | final int topInset = mTmpRect.top; |
| 1501 | // appBounds at the root level should mirror the app screen size. |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1502 | config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */, |
| 1503 | leftInset + displayInfo.appWidth /* right */, |
| 1504 | topInset + displayInfo.appHeight /* bottom */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1505 | final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90 |
| 1506 | || displayInfo.rotation == Surface.ROTATION_270); |
| 1507 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1508 | config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) |
| 1509 | | ((displayInfo.flags & Display.FLAG_ROUND) != 0 |
| 1510 | ? Configuration.SCREENLAYOUT_ROUND_YES |
| 1511 | : Configuration.SCREENLAYOUT_ROUND_NO); |
| 1512 | |
| 1513 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 1514 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 1515 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1516 | dh, displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1517 | config.densityDpi = displayInfo.logicalDensityDpi; |
| 1518 | |
| 1519 | config.colorMode = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1520 | ((displayInfo.isHdr() && mWmService.hasHdrSupport()) |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1521 | ? Configuration.COLOR_MODE_HDR_YES |
| 1522 | : Configuration.COLOR_MODE_HDR_NO) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1523 | | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1524 | ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES |
| 1525 | : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO); |
| 1526 | |
| 1527 | // Update the configuration based on available input devices, lid switch, |
| 1528 | // and platform configuration. |
| 1529 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1530 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 1531 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 1532 | |
| 1533 | int keyboardPresence = 0; |
| 1534 | int navigationPresence = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1535 | final InputDevice[] devices = mWmService.mInputManager.getInputDevices(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1536 | final int len = devices != null ? devices.length : 0; |
| 1537 | for (int i = 0; i < len; i++) { |
| 1538 | InputDevice device = devices[i]; |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1539 | // Ignore virtual input device. |
| 1540 | if (device.isVirtual()) { |
| 1541 | continue; |
| 1542 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1543 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1544 | // Check if input device can dispatch events to current display. |
| 1545 | // If display type is virtual, will follow the default display. |
| 1546 | if (!mWmService.mInputManager.canDispatchToDisplay(device.getId(), |
| 1547 | displayInfo.type == Display.TYPE_VIRTUAL ? DEFAULT_DISPLAY : mDisplayId)) { |
| 1548 | continue; |
| 1549 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1550 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1551 | final int sources = device.getSources(); |
| 1552 | final int presenceFlag = device.isExternal() |
| 1553 | ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1554 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1555 | if (mWmService.mIsTouchDevice) { |
| 1556 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { |
| 1557 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1558 | } |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1559 | } else { |
| 1560 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1561 | } |
| 1562 | |
| 1563 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
| 1564 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 1565 | navigationPresence |= presenceFlag; |
| 1566 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
| 1567 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 1568 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1569 | navigationPresence |= presenceFlag; |
| 1570 | } |
| 1571 | |
| 1572 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 1573 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 1574 | keyboardPresence |= presenceFlag; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1578 | if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1579 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1580 | navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL; |
| 1581 | } |
| 1582 | |
| 1583 | // Determine whether a hard keyboard is available and enabled. |
| 1584 | // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device? |
| 1585 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1586 | if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) { |
| 1587 | mWmService.mHardKeyboardAvailable = hardKeyboardAvailable; |
| 1588 | mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 1589 | mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1592 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1593 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1594 | // Let the policy update hidden states. |
| 1595 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 1596 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 1597 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1598 | mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1602 | DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1603 | mTmpDisplayMetrics.setTo(mDisplayMetrics); |
| 1604 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 1605 | final int unrotDw, unrotDh; |
| 1606 | if (rotated) { |
| 1607 | unrotDw = dh; |
| 1608 | unrotDh = dw; |
| 1609 | } else { |
| 1610 | unrotDw = dw; |
| 1611 | unrotDh = dh; |
| 1612 | } |
| 1613 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1614 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1615 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1616 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1617 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1618 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1619 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1620 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1621 | return sw; |
| 1622 | } |
| 1623 | |
| 1624 | private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1625 | DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) { |
| 1626 | dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
| 1627 | displayCutout); |
| 1628 | dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
| 1629 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1630 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
| 1631 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
| 1632 | if (curSize == 0 || size < curSize) { |
| 1633 | curSize = size; |
| 1634 | } |
| 1635 | return curSize; |
| 1636 | } |
| 1637 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1638 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 1639 | int uiMode, int dw, int dh, float density, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1640 | |
| 1641 | // We need to determine the smallest width that will occur under normal |
| 1642 | // operation. To this, start with the base screen size and compute the |
| 1643 | // width under the different possible rotations. We need to un-rotate |
| 1644 | // the current screen dimensions before doing this. |
| 1645 | int unrotDw, unrotDh; |
| 1646 | if (rotated) { |
| 1647 | unrotDw = dh; |
| 1648 | unrotDh = dw; |
| 1649 | } else { |
| 1650 | unrotDw = dw; |
| 1651 | unrotDh = dh; |
| 1652 | } |
| 1653 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 1654 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 1655 | displayInfo.largestNominalAppWidth = 0; |
| 1656 | displayInfo.largestNominalAppHeight = 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1657 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh); |
| 1658 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw); |
| 1659 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh); |
| 1660 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw); |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1661 | |
| 1662 | if (outConfig == null) { |
| 1663 | return; |
| 1664 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1665 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
| 1666 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1667 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1668 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1669 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1670 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1671 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1672 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1673 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1674 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
| 1675 | outConfig.screenLayout = sl; |
| 1676 | } |
| 1677 | |
| 1678 | 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] | 1679 | int uiMode, DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1680 | // Get the app screen size at this rotation. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1681 | int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout); |
| 1682 | int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1683 | |
| 1684 | // Compute the screen layout size class for this rotation. |
| 1685 | int longSize = w; |
| 1686 | int shortSize = h; |
| 1687 | if (longSize < shortSize) { |
| 1688 | int tmp = longSize; |
| 1689 | longSize = shortSize; |
| 1690 | shortSize = tmp; |
| 1691 | } |
| 1692 | longSize = (int)(longSize/density); |
| 1693 | shortSize = (int)(shortSize/density); |
| 1694 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
| 1695 | } |
| 1696 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1697 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1698 | int uiMode, int dw, int dh) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1699 | final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( |
| 1700 | rotation).getDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1701 | final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode, |
| 1702 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1703 | if (width < displayInfo.smallestNominalAppWidth) { |
| 1704 | displayInfo.smallestNominalAppWidth = width; |
| 1705 | } |
| 1706 | if (width > displayInfo.largestNominalAppWidth) { |
| 1707 | displayInfo.largestNominalAppWidth = width; |
| 1708 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1709 | final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode, |
| 1710 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1711 | if (height < displayInfo.smallestNominalAppHeight) { |
| 1712 | displayInfo.smallestNominalAppHeight = height; |
| 1713 | } |
| 1714 | if (height > displayInfo.largestNominalAppHeight) { |
| 1715 | displayInfo.largestNominalAppHeight = height; |
| 1716 | } |
| 1717 | } |
| 1718 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 1719 | /** |
| 1720 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 1721 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 1722 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 1723 | * This lowers the travel distance between invoking the menu panel and selecting |
| 1724 | * a menu option. |
| 1725 | * |
| 1726 | * This method helps control where that menu is placed. Its current implementation makes |
| 1727 | * assumptions about the menu key and its relationship to the screen based on whether |
| 1728 | * the device's natural orientation is portrait (width < height) or landscape. |
| 1729 | * |
| 1730 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 1731 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 1732 | * do not hold for the target device, this method should be changed to reflect that. |
| 1733 | * |
| 1734 | * @return A {@link Gravity} value for placing the options menu window. |
| 1735 | */ |
| 1736 | int getPreferredOptionsPanelGravity() { |
| 1737 | final int rotation = getRotation(); |
| 1738 | if (mInitialDisplayWidth < mInitialDisplayHeight) { |
| 1739 | // On devices with a natural orientation of portrait. |
| 1740 | switch (rotation) { |
| 1741 | default: |
| 1742 | case Surface.ROTATION_0: |
| 1743 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1744 | case Surface.ROTATION_90: |
| 1745 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1746 | case Surface.ROTATION_180: |
| 1747 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1748 | case Surface.ROTATION_270: |
| 1749 | return Gravity.START | Gravity.BOTTOM; |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | // On devices with a natural orientation of landscape. |
| 1754 | switch (rotation) { |
| 1755 | default: |
| 1756 | case Surface.ROTATION_0: |
| 1757 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1758 | case Surface.ROTATION_90: |
| 1759 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1760 | case Surface.ROTATION_180: |
| 1761 | return Gravity.START | Gravity.BOTTOM; |
| 1762 | case Surface.ROTATION_270: |
| 1763 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1764 | } |
| 1765 | } |
| 1766 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 1767 | DockedStackDividerController getDockedDividerController() { |
| 1768 | return mDividerControllerLocked; |
| 1769 | } |
| 1770 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1771 | PinnedStackController getPinnedStackController() { |
| 1772 | return mPinnedStackControllerLocked; |
| 1773 | } |
| 1774 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1775 | /** |
| 1776 | * Returns true if the specified UID has access to this display. |
| 1777 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1778 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1779 | return mDisplay.hasAccess(uid); |
| 1780 | } |
| 1781 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1782 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1783 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1786 | ActivityStack getHomeStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1787 | return mTaskStackContainers.getHomeStack(); |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1790 | ActivityStack getRecentsStack() { |
| 1791 | return mTaskStackContainers.getRecentsStack(); |
| 1792 | } |
| 1793 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1794 | /** |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1795 | * @return The primary split-screen stack, and {@code null} otherwise. |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1796 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1797 | ActivityStack getSplitScreenPrimaryStack() { |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1798 | return mTaskStackContainers.getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1801 | boolean hasSplitScreenPrimaryStack() { |
| 1802 | return getSplitScreenPrimaryStack() != null; |
| 1803 | } |
| 1804 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1805 | /** |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 1806 | * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1807 | * not visible. |
| 1808 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1809 | ActivityStack getSplitScreenPrimaryStackIgnoringVisibility() { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 1810 | return mTaskStackContainers.getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1813 | ActivityStack getPinnedStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1814 | return mTaskStackContainers.getPinnedStack(); |
| 1815 | } |
| 1816 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1817 | boolean hasPinnedStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1818 | return mTaskStackContainers.getPinnedStack() != null; |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1821 | /** |
| 1822 | * Returns the topmost stack on the display that is compatible with the input windowing mode. |
| 1823 | * Null is no compatible stack on the display. |
| 1824 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1825 | ActivityStack getTopStackInWindowingMode(int windowingMode) { |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1826 | return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED); |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * Returns the topmost stack on the display that is compatible with the input windowing mode and |
| 1831 | * activity type. Null is no compatible stack on the display. |
| 1832 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1833 | ActivityStack getStack(int windowingMode, int activityType) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1834 | return mTaskStackContainers.getStack(windowingMode, activityType); |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 1837 | protected int getStackCount() { |
| 1838 | return mTaskStackContainers.mChildren.size(); |
| 1839 | } |
| 1840 | |
| 1841 | protected ActivityStack getStackAt(int index) { |
| 1842 | return mTaskStackContainers.mChildren.get(index); |
| 1843 | } |
| 1844 | |
| 1845 | int getIndexOf(ActivityStack stack) { |
| 1846 | return mTaskStackContainers.getIndexOf(stack); |
| 1847 | } |
| 1848 | |
| 1849 | void removeStack(ActivityStack stack) { |
| 1850 | mTaskStackContainers.removeChild(stack); |
| 1851 | } |
| 1852 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1853 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1854 | WindowList<ActivityStack> getStacks() { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 1855 | return mTaskStackContainers.mChildren; |
| 1856 | } |
| 1857 | |
| 1858 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1859 | ActivityStack getTopStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1860 | return mTaskStackContainers.getTopStack(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1863 | ArrayList<Task> getVisibleTasks() { |
| 1864 | return mTaskStackContainers.getVisibleTasks(); |
| 1865 | } |
| 1866 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1867 | void onStackWindowingModeChanged(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1868 | mTaskStackContainers.onStackWindowingModeChanged(stack); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1871 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 1872 | public void onConfigurationChanged(Configuration newParentConfig) { |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 1873 | final int lastOrientation = getConfiguration().orientation; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1874 | super.onConfigurationChanged(newParentConfig); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1875 | if (mDisplayPolicy != null) { |
| 1876 | mDisplayPolicy.onConfigurationChanged(); |
| 1877 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1878 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 1879 | if (lastOrientation != getConfiguration().orientation) { |
| 1880 | getMetricsLogger().write( |
| 1881 | new LogMaker(MetricsEvent.ACTION_PHONE_ORIENTATION_CHANGED) |
| 1882 | .setSubtype(getConfiguration().orientation) |
| 1883 | .addTaggedData(MetricsEvent.FIELD_DISPLAY_ID, getDisplayId())); |
| 1884 | } |
| 1885 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1886 | // If there was no pinned stack, we still need to notify the controller of the display info |
| 1887 | // update as a result of the config change. |
| 1888 | if (mPinnedStackControllerLocked != null && !hasPinnedStack()) { |
| 1889 | mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo()); |
| 1890 | } |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | /** |
| 1894 | * Updates the resources used by docked/pinned controllers. This needs to be called at the |
| 1895 | * beginning of a configuration update cascade since the metrics from these resources are used |
| 1896 | * for bounds calculations. Since ActivityDisplay initiates the configuration update, this |
| 1897 | * should be called from there instead of DisplayContent's onConfigurationChanged. |
| 1898 | */ |
| 1899 | void preOnConfigurationChanged() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1900 | final DockedStackDividerController dividerController = getDockedDividerController(); |
| 1901 | |
| 1902 | if (dividerController != null) { |
| 1903 | getDockedDividerController().onConfigurationChanged(); |
| 1904 | } |
| 1905 | |
| 1906 | final PinnedStackController pinnedStackController = getPinnedStackController(); |
| 1907 | |
| 1908 | if (pinnedStackController != null) { |
| 1909 | getPinnedStackController().onConfigurationChanged(); |
| 1910 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1911 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 1912 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1913 | @Override |
| 1914 | boolean fillsParent() { |
| 1915 | return true; |
| 1916 | } |
| 1917 | |
| 1918 | @Override |
| 1919 | boolean isVisible() { |
| 1920 | return true; |
| 1921 | } |
| 1922 | |
| 1923 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1924 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1925 | super.onAppTransitionDone(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1926 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 1929 | @Override |
| 1930 | public void setWindowingMode(int windowingMode) { |
| 1931 | super.setWindowingMode(windowingMode); |
| 1932 | super.setDisplayWindowingMode(windowingMode); |
| 1933 | } |
| 1934 | |
| 1935 | @Override |
| 1936 | void setDisplayWindowingMode(int windowingMode) { |
| 1937 | setWindowingMode(windowingMode); |
| 1938 | } |
| 1939 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1940 | /** |
| 1941 | * In split-screen mode we process the IME containers above the docked divider |
| 1942 | * rather than directly above their target. |
| 1943 | */ |
| 1944 | private boolean skipTraverseChild(WindowContainer child) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 1945 | if (child == mImeWindowsContainers && mInputMethodTarget != null |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1946 | && !hasSplitScreenPrimaryStack()) { |
| 1947 | return true; |
| 1948 | } |
| 1949 | return false; |
| 1950 | } |
| 1951 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1952 | @Override |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1953 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 1954 | // Special handling so we can process IME windows with #forAllImeWindows above their IME |
| 1955 | // target, or here in order if there isn't an IME target. |
| 1956 | if (traverseTopToBottom) { |
| 1957 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1958 | final DisplayChildWindowContainer child = mChildren.get(i); |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1959 | if (skipTraverseChild(child)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1960 | continue; |
| 1961 | } |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1962 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1963 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 1964 | return true; |
| 1965 | } |
| 1966 | } |
| 1967 | } else { |
| 1968 | final int count = mChildren.size(); |
| 1969 | for (int i = 0; i < count; i++) { |
| 1970 | final DisplayChildWindowContainer child = mChildren.get(i); |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1971 | if (skipTraverseChild(child)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1972 | continue; |
| 1973 | } |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1974 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1975 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 1976 | return true; |
| 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | return false; |
| 1981 | } |
| 1982 | |
| 1983 | boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 1984 | return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom); |
| 1985 | } |
| 1986 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 1987 | /** |
| 1988 | * In the general case, the orientation is computed from the above app windows first. If none of |
| 1989 | * the above app windows specify orientation, the orientation is computed from the child window |
| 1990 | * container, e.g. {@link AppWindowToken#getOrientation(int)}. |
| 1991 | */ |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 1992 | @Override |
| 1993 | int getOrientation() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1994 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1995 | |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1996 | if (mIgnoreRotationForApps) { |
| 1997 | return SCREEN_ORIENTATION_USER; |
| 1998 | } |
| 1999 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2000 | if (mWmService.mDisplayFrozen) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2001 | if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2002 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 2003 | "Display id=%d is frozen, return %d", mDisplayId, |
| 2004 | mLastWindowForcedOrientation); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2005 | // If the display is frozen, some activities may be in the middle of restarting, and |
| 2006 | // thus have removed their old window. If the window has the flag to hide the lock |
| 2007 | // screen, then the lock screen can re-appear and inflict its own orientation on us. |
| 2008 | // Keep the orientation stable until this all settles down. |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2009 | return mLastWindowForcedOrientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2010 | } else if (policy.isKeyguardLocked()) { |
| 2011 | // Use the last orientation the while the display is frozen with the keyguard |
| 2012 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 2013 | // window. We don't want to check the show when locked window directly though as |
| 2014 | // things aren't stable while the display is frozen, for example the window could be |
| 2015 | // momentarily unavailable due to activity relaunch. |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2016 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 2017 | "Display id=%d is frozen while keyguard locked, return %d", |
| 2018 | mDisplayId, getLastOrientation()); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2019 | return getLastOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2020 | } |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2021 | } else { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2022 | final int orientation = mAboveAppWindowsContainers.getOrientation(); |
| 2023 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 2024 | return orientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2025 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 2028 | // Top system windows are not requesting an orientation. Start searching from apps. |
| 2029 | return mTaskStackContainers.getOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2032 | void updateDisplayInfo() { |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2033 | // Check if display metrics changed and update base values if needed. |
| 2034 | updateBaseDisplayMetricsIfNeeded(); |
| 2035 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2036 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 2037 | mDisplay.getMetrics(mDisplayMetrics); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2038 | |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 2039 | onDisplayChanged(this); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2042 | @Override |
| 2043 | void onDisplayChanged(DisplayContent dc) { |
| 2044 | super.onDisplayChanged(dc); |
| 2045 | updateSystemGestureExclusionLimit(); |
| 2046 | } |
| 2047 | |
| 2048 | void updateSystemGestureExclusionLimit() { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 2049 | mSystemGestureExclusionLimit = mWmService.mConstants.mSystemGestureExclusionLimitDp |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2050 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
| 2051 | updateSystemGestureExclusion(); |
| 2052 | } |
| 2053 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2054 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2055 | final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2056 | if (displayManagerInternal != null) { |
| 2057 | // Bootstrap the default logical display from the display manager. |
| 2058 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 2059 | if (newDisplayInfo != null) { |
| 2060 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 2061 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2062 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2063 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2064 | updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight, |
| 2065 | mDisplayInfo.logicalDensityDpi); |
| 2066 | mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 2067 | mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 2068 | mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2069 | mInitialDisplayCutout = mDisplayInfo.displayCutout; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2072 | /** |
| 2073 | * If display metrics changed, overrides are not set and it's not just a rotation - update base |
| 2074 | * values. |
| 2075 | */ |
| 2076 | private void updateBaseDisplayMetricsIfNeeded() { |
| 2077 | // Get real display metrics without overrides from WM. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2078 | mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2079 | final int orientation = mDisplayInfo.rotation; |
| 2080 | final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
| 2081 | final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth; |
| 2082 | final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight; |
| 2083 | final int newDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2084 | final DisplayCutout newCutout = mDisplayInfo.displayCutout; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2085 | |
| 2086 | final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth |
| 2087 | || mInitialDisplayHeight != newHeight |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2088 | || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi |
| 2089 | || !Objects.equals(mInitialDisplayCutout, newCutout); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2090 | |
| 2091 | if (displayMetricsChanged) { |
| 2092 | // Check if display size or density is forced. |
| 2093 | final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth |
| 2094 | || mBaseDisplayHeight != mInitialDisplayHeight; |
| 2095 | final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity; |
| 2096 | |
| 2097 | // If there is an override set for base values - use it, otherwise use new values. |
| 2098 | updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth, |
| 2099 | isDisplaySizeForced ? mBaseDisplayHeight : newHeight, |
| 2100 | isDisplayDensityForced ? mBaseDisplayDensity : newDensity); |
| 2101 | |
| 2102 | // Real display metrics changed, so we should also update initial values. |
| 2103 | mInitialDisplayWidth = newWidth; |
| 2104 | mInitialDisplayHeight = newHeight; |
| 2105 | mInitialDisplayDensity = newDensity; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2106 | mInitialDisplayCutout = newCutout; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2107 | reconfigureDisplayLocked(); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2111 | /** Sets the maximum width the screen resolution can be */ |
| 2112 | void setMaxUiWidth(int width) { |
| 2113 | if (DEBUG_DISPLAY) { |
| 2114 | Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId()); |
| 2115 | } |
| 2116 | |
| 2117 | mMaxUiWidth = width; |
| 2118 | |
| 2119 | // Update existing metrics. |
| 2120 | updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity); |
| 2121 | } |
| 2122 | |
| 2123 | /** Update base (override) display metrics. */ |
| 2124 | void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) { |
| 2125 | mBaseDisplayWidth = baseWidth; |
| 2126 | mBaseDisplayHeight = baseHeight; |
| 2127 | mBaseDisplayDensity = baseDensity; |
| 2128 | |
| 2129 | if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) { |
| 2130 | mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth; |
| 2131 | mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth; |
| 2132 | mBaseDisplayWidth = mMaxUiWidth; |
| 2133 | |
| 2134 | if (DEBUG_DISPLAY) { |
| 2135 | Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x" |
| 2136 | + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity |
| 2137 | + " on display:" + getDisplayId()); |
| 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2142 | |
| 2143 | updateBounds(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2146 | /** |
| 2147 | * Forces this display to use the specified density. |
| 2148 | * |
| 2149 | * @param density The density in DPI to use. If the value equals to initial density, the setting |
| 2150 | * will be cleared. |
| 2151 | * @param userId The target user to apply. Only meaningful when this is default display. If the |
| 2152 | * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings |
| 2153 | * so only need to configure display. |
| 2154 | */ |
| 2155 | void setForcedDensity(int density, int userId) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2156 | final boolean updateCurrent = userId == UserHandle.USER_CURRENT; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2157 | if (mWmService.mCurrentUserId == userId || updateCurrent) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2158 | mBaseDisplayDensity = density; |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2159 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2160 | } |
| 2161 | if (updateCurrent) { |
| 2162 | // We are applying existing settings so no need to save it again. |
| 2163 | return; |
| 2164 | } |
| 2165 | |
| 2166 | if (density == mInitialDisplayDensity) { |
| 2167 | density = 0; |
| 2168 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2169 | mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */ |
| 2173 | void setForcedScalingMode(@ForceScalingMode int mode) { |
| 2174 | if (mode != FORCE_SCALING_MODE_DISABLED) { |
| 2175 | mode = FORCE_SCALING_MODE_AUTO; |
| 2176 | } |
| 2177 | |
| 2178 | mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO); |
| 2179 | Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto")); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2180 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2181 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2182 | mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | /** If the given width and height equal to initial size, the setting will be cleared. */ |
| 2186 | void setForcedSize(int width, int height) { |
| 2187 | final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height; |
| 2188 | if (!clear) { |
| 2189 | // Set some sort of reasonable bounds on the size of the display that we will try |
| 2190 | // to emulate. |
| 2191 | final int minSize = 200; |
| 2192 | final int maxScale = 2; |
| 2193 | width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale); |
| 2194 | height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale); |
| 2195 | } |
| 2196 | |
| 2197 | Slog.i(TAG_WM, "Using new display size: " + width + "x" + height); |
| 2198 | updateBaseDisplayMetrics(width, height, mBaseDisplayDensity); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2199 | reconfigureDisplayLocked(); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2200 | |
| 2201 | if (clear) { |
| 2202 | width = height = 0; |
| 2203 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2204 | mWmService.mDisplayWindowSettings.setForcedSize(this, width, height); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2205 | } |
| 2206 | |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 2207 | void getStableRect(Rect out) { |
| 2208 | out.set(mDisplayFrames.mStable); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2211 | void setStackOnDisplay(ActivityStack stack, int position) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2212 | if (DEBUG_STACK) Slog.d(TAG_WM, "Set stack=" + stack + " on displayId=" + mDisplayId); |
| 2213 | mTaskStackContainers.addChild(stack, position); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2216 | void moveStackToDisplay(ActivityStack stack, boolean onTop) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2217 | stack.reparent(mTaskStackContainers, onTop ? POSITION_TOP: POSITION_BOTTOM); |
| 2218 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2219 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2220 | @Override |
| 2221 | protected void addChild(DisplayChildWindowContainer child, |
| 2222 | Comparator<DisplayChildWindowContainer> comparator) { |
| 2223 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2224 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2225 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2226 | @Override |
| 2227 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 2228 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2229 | } |
| 2230 | |
| 2231 | @Override |
| 2232 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2233 | // Only allow removal of direct children from this display if the display is in the process |
| 2234 | // of been removed. |
| 2235 | if (mRemovingDisplay) { |
| 2236 | super.removeChild(child); |
| 2237 | return; |
| 2238 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2239 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2240 | } |
| 2241 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2242 | @Override |
| 2243 | void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) { |
| 2244 | // Children of the display are statically ordered, so the real intention here is to perform |
| 2245 | // the operation on the display and not the static direct children. |
| 2246 | getParent().positionChildAt(position, this, includingParents); |
| 2247 | } |
| 2248 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2249 | void positionStackAt(int position, ActivityStack child, boolean includingParents) { |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 2250 | mTaskStackContainers.positionChildAt(position, child, includingParents); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 2251 | layoutAndAssignWindowLayersIfNeeded(); |
| 2252 | } |
| 2253 | |
Garfield Tan | 4f71c5a | 2018-10-10 10:12:02 -0700 | [diff] [blame] | 2254 | /** |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2255 | * Returns true if the input point is within an app window. |
| 2256 | */ |
| 2257 | boolean pointWithinAppWindow(int x, int y) { |
| 2258 | final int[] targetWindowType = {-1}; |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2259 | final PooledConsumer fn = PooledLambda.obtainConsumer((w, nonArg) -> { |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2260 | if (targetWindowType[0] != -1) { |
| 2261 | return; |
| 2262 | } |
| 2263 | |
| 2264 | if (w.isOnScreen() && w.isVisibleLw() && w.getFrameLw().contains(x, y)) { |
| 2265 | targetWindowType[0] = w.mAttrs.type; |
| 2266 | return; |
| 2267 | } |
| 2268 | }, PooledLambda.__(WindowState.class), mTmpRect); |
| 2269 | forAllWindows(fn, true /* traverseTopToBottom */); |
Wale Ogunwale | f5f3f1b | 2019-11-12 09:47:30 -0800 | [diff] [blame] | 2270 | fn.recycle(); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2271 | return FIRST_APPLICATION_WINDOW <= targetWindowType[0] |
| 2272 | && targetWindowType[0] <= LAST_APPLICATION_WINDOW; |
| 2273 | } |
| 2274 | |
| 2275 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2276 | * 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] | 2277 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2278 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 2279 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2280 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 2281 | return mTmpTaskForResizePointSearchResult.process(mTaskStackContainers, x, y, delta); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2284 | void updateTouchExcludeRegion() { |
| 2285 | final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2286 | if (focusedTask == null) { |
| 2287 | mTouchExcludeRegion.setEmpty(); |
| 2288 | } else { |
| 2289 | mTouchExcludeRegion.set(mBaseDisplayRect); |
| 2290 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 2291 | mTmpRect.setEmpty(); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2292 | mTmpRect2.setEmpty(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 2293 | |
| 2294 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2295 | DisplayContent::processTaskForTouchExcludeRegion, this, |
| 2296 | PooledLambda.__(Task.class), focusedTask, delta); |
| 2297 | mTaskStackContainers.forAllTasks(c); |
| 2298 | c.recycle(); |
| 2299 | |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2300 | // 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] | 2301 | // outside touch area in the exclusion. TapDetector is not interested in |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2302 | // any touch inside the focused task itself. |
| 2303 | if (!mTmpRect2.isEmpty()) { |
| 2304 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 2305 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2306 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2307 | if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) { |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2308 | // If the input method is visible and the user is typing, we don't want these touch |
| 2309 | // events to be intercepted and used to change focus. This would likely cause a |
| 2310 | // disappearance of the input method. |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2311 | mInputMethodWindow.getTouchableRegion(mTmpRegion); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2312 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2313 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2314 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 2315 | final WindowState win = mTapExcludedWindows.get(i); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2316 | win.getTouchableRegion(mTmpRegion); |
| 2317 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 2318 | } |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2319 | amendWindowTapExcludeRegion(mTouchExcludeRegion); |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 2320 | // TODO(multi-display): Support docked stacks on secondary displays. |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2321 | if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) { |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2322 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 2323 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2324 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 2325 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2326 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 2329 | private void processTaskForTouchExcludeRegion(Task task, Task focusedTask, int delta) { |
| 2330 | final ActivityRecord topVisibleActivity = task.getTopVisibleActivity(); |
| 2331 | |
| 2332 | if (topVisibleActivity == null || !topVisibleActivity.hasContentToDisplay()) { |
| 2333 | return; |
| 2334 | } |
| 2335 | |
| 2336 | // Exclusion region is the region that TapDetector doesn't care about. |
| 2337 | // Here we want to remove all non-focused tasks from the exclusion region. |
| 2338 | // We also remove the outside touch area for resizing for all freeform |
| 2339 | // tasks (including the focused). |
| 2340 | // We save the focused task region once we find it, and add it back at the end. |
| 2341 | // If the task is home stack and it is resizable in the minimized state, we want to |
| 2342 | // exclude the docked stack from touch so we need the entire screen area and not just a |
| 2343 | // small portion which the home stack currently is resized to. |
| 2344 | if (task.isActivityTypeHome() && task.getStack().isMinimizedDockAndHomeStackResizable()) { |
| 2345 | mDisplayContent.getBounds(mTmpRect); |
| 2346 | } else { |
| 2347 | task.getDimBounds(mTmpRect); |
| 2348 | } |
| 2349 | |
| 2350 | if (task == focusedTask) { |
| 2351 | // Add the focused task rect back into the exclude region once we are done |
| 2352 | // processing stacks. |
| 2353 | mTmpRect2.set(mTmpRect); |
| 2354 | } |
| 2355 | |
| 2356 | final boolean isFreeformed = task.inFreeformWindowingMode(); |
| 2357 | if (task != focusedTask || isFreeformed) { |
| 2358 | if (isFreeformed) { |
| 2359 | // If the task is freeformed, enlarge the area to account for outside |
| 2360 | // touch area for resize. |
| 2361 | mTmpRect.inset(-delta, -delta); |
| 2362 | // Intersect with display content rect. If we have system decor (status bar/ |
| 2363 | // navigation bar), we want to exclude that from the tap detection. |
| 2364 | // Otherwise, if the app is partially placed under some system button (eg. |
| 2365 | // Recents, Home), pressing that button would cause a full series of |
| 2366 | // unwanted transfer focus/resume/pause, before we could go home. |
| 2367 | mTmpRect.intersect(mDisplayFrames.mContent); |
| 2368 | } |
| 2369 | mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE); |
| 2370 | } |
| 2371 | } |
| 2372 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2373 | /** |
| 2374 | * Union the region with all the tap exclude region provided by windows on this display. |
| 2375 | * |
| 2376 | * @param inOutRegion The region to be amended. |
| 2377 | */ |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 2378 | private void amendWindowTapExcludeRegion(Region inOutRegion) { |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2379 | for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) { |
| 2380 | final WindowState win = mTapExcludeProvidingWindows.valueAt(i); |
| 2381 | win.amendTapExcludeRegion(inOutRegion); |
| 2382 | } |
| 2383 | } |
| 2384 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2385 | @Override |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2386 | void switchUser(int userId) { |
| 2387 | super.switchUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2388 | mWmService.mWindowsChanged = true; |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2389 | mDisplayPolicy.switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2392 | @Override |
| 2393 | void removeIfPossible() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2394 | if (isAnimating(TRANSITION | PARENTS)) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2395 | mDeferredRemoval = true; |
| 2396 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2397 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2398 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2401 | @Override |
| 2402 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2403 | mRemovingDisplay = true; |
| 2404 | try { |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 2405 | if (mParentWindow != null) { |
| 2406 | mParentWindow.removeEmbeddedDisplayContent(this); |
| 2407 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2408 | // Clear all transitions & screen frozen states when removing display. |
| 2409 | mOpeningApps.clear(); |
| 2410 | mClosingApps.clear(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 2411 | mChangingApps.clear(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2412 | mUnknownAppVisibilityController.clear(); |
| 2413 | mAppTransition.removeAppTransitionTimeoutCallbacks(); |
| 2414 | handleAnimatingStoppedAndTransition(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2415 | mWmService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2416 | super.removeImmediately(); |
| 2417 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2418 | mPointerEventDispatcher.dispose(); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2419 | setRotationAnimation(null); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2420 | mWmService.mAnimator.removeDisplayLocked(mDisplayId); |
Louis Chang | 207f911 | 2018-07-30 08:58:54 +0800 | [diff] [blame] | 2421 | mWindowingLayer.release(); |
| 2422 | mOverlayLayer.release(); |
Jorim Jaggi | ae962e6 | 2018-12-27 17:23:48 +0100 | [diff] [blame] | 2423 | mInputMonitor.onDisplayRemoved(); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 2424 | // TODO(display-merge): Remove cast |
| 2425 | mWmService.mDisplayNotificationController |
| 2426 | .dispatchDisplayRemoved((ActivityDisplay) this); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2427 | } finally { |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 2428 | mDisplayReady = false; |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2429 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2430 | } |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 2431 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2432 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2433 | } |
| 2434 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2435 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2436 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2437 | boolean checkCompleteDeferredRemoval() { |
Riddle Hsu | 793442c5 | 2019-11-05 01:04:55 +0800 | [diff] [blame] | 2438 | boolean stillDeferringRemoval = false; |
| 2439 | |
| 2440 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 2441 | final DisplayChildWindowContainer child = getChildAt(i); |
| 2442 | stillDeferringRemoval |= child.checkCompleteDeferredRemoval(); |
| 2443 | if (getChildCount() == 0) { |
| 2444 | // If this display is pending to be removed because it contains an activity with |
| 2445 | // {@link ActivityRecord#mIsExiting} is true, this display may be removed when |
| 2446 | // completing the removal of the last activity from |
| 2447 | // {@link ActivityRecord#checkCompleteDeferredRemoval}. |
| 2448 | return false; |
| 2449 | } |
| 2450 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2451 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2452 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2453 | removeImmediately(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2454 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2455 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2456 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 2459 | /** @return 'true' if removal of this display content is deferred due to active animation. */ |
| 2460 | boolean isRemovalDeferred() { |
| 2461 | return mDeferredRemoval; |
| 2462 | } |
| 2463 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2464 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 2465 | float dividerAnimationTarget) { |
| 2466 | boolean updated = false; |
| 2467 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2468 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2469 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2470 | if (stack == null || !stack.isAdjustedForIme()) { |
| 2471 | continue; |
| 2472 | } |
| 2473 | |
| 2474 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 2475 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2476 | updated = true; |
| 2477 | } else { |
| 2478 | mDividerControllerLocked.mLastAnimationProgress = |
| 2479 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 2480 | mDividerControllerLocked.mLastDividerProgress = |
| 2481 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 2482 | updated |= stack.updateAdjustForIme( |
| 2483 | mDividerControllerLocked.mLastAnimationProgress, |
| 2484 | mDividerControllerLocked.mLastDividerProgress, |
| 2485 | false /* force */); |
| 2486 | } |
| 2487 | if (interpolatedValue >= 1f) { |
| 2488 | stack.endImeAdjustAnimation(); |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | return updated; |
| 2493 | } |
| 2494 | |
| 2495 | boolean clearImeAdjustAnimation() { |
| 2496 | boolean changed = false; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2497 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2498 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2499 | if (stack != null && stack.isAdjustedForIme()) { |
| 2500 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2501 | changed = true; |
| 2502 | } |
| 2503 | } |
| 2504 | return changed; |
| 2505 | } |
| 2506 | |
| 2507 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2508 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2509 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2510 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 2511 | stack.beginImeAdjustAnimation(); |
| 2512 | } |
| 2513 | } |
| 2514 | } |
| 2515 | |
| 2516 | void adjustForImeIfNeeded() { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2517 | final WindowState imeWin = mInputMethodWindow; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2518 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 2519 | && !mDividerControllerLocked.isImeHideRequested(); |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2520 | final ActivityStack dockedStack = getSplitScreenPrimaryStack(); |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2521 | final boolean dockVisible = dockedStack != null; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2522 | final Task topDockedTask = dockVisible ? dockedStack.getTask((t) -> true): null; |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2523 | final ActivityStack imeTargetStack = mWmService.getImeFocusStackLocked(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2524 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 2525 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 2526 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 2527 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2528 | final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2529 | final boolean imeHeightChanged = imeVisible && |
| 2530 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 2531 | |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2532 | // This includes a case where the docked stack is unminimizing and IME is visible for the |
| 2533 | // bottom side stack. The condition prevents adjusting the override task bounds for IME to |
| 2534 | // the minimized docked stack bounds. |
| 2535 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock() |
| 2536 | || (topDockedTask != null && imeOnBottom && !dockedStack.isAdjustedForIme() |
| 2537 | && dockedStack.getBounds().height() < topDockedTask.getBounds().height()); |
| 2538 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2539 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 2540 | // or both. There are three possible cases: |
| 2541 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 2542 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 2543 | // - If IME is not visible, divider is not moved and is normal width. |
| 2544 | |
| 2545 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2546 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2547 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2548 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2549 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom) |
| 2550 | && stack.inSplitScreenWindowingMode()) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2551 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 2552 | } else { |
| 2553 | stack.resetAdjustedForIme(false); |
| 2554 | } |
| 2555 | } |
| 2556 | mDividerControllerLocked.setAdjustedForIme( |
| 2557 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 2558 | } else { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2559 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2560 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2561 | stack.resetAdjustedForIme(!dockVisible); |
| 2562 | } |
| 2563 | mDividerControllerLocked.setAdjustedForIme( |
| 2564 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 2565 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2566 | mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2570 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2571 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2572 | stack.prepareFreezingTaskBounds(); |
| 2573 | } |
| 2574 | } |
| 2575 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2576 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2577 | getBounds(mTmpRect, newRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2578 | rotateBounds(mTmpRect, oldRotation, newRotation, bounds); |
| 2579 | } |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2580 | |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2581 | void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2582 | // Compute a transform matrix to undo the coordinate space transformation, |
| 2583 | // and present the window at the same physical position it previously occupied. |
| 2584 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2585 | createRotationMatrix( |
| 2586 | deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2587 | |
| 2588 | mTmpRectF.set(bounds); |
| 2589 | mTmpMatrix.mapRect(mTmpRectF); |
| 2590 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 2593 | static int deltaRotation(int oldRotation, int newRotation) { |
| 2594 | int delta = newRotation - oldRotation; |
| 2595 | if (delta < 0) delta += 4; |
| 2596 | return delta; |
| 2597 | } |
| 2598 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2599 | public void setRotationAnimation(ScreenRotationAnimation screenRotationAnimation) { |
| 2600 | if (mScreenRotationAnimation != null) { |
| 2601 | mScreenRotationAnimation.kill(); |
| 2602 | } |
| 2603 | mScreenRotationAnimation = screenRotationAnimation; |
| 2604 | } |
| 2605 | |
| 2606 | public ScreenRotationAnimation getRotationAnimation() { |
| 2607 | return mScreenRotationAnimation; |
| 2608 | } |
| 2609 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2610 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2611 | Matrix outMatrix) { |
| 2612 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 2613 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 2614 | displayHeight, outMatrix); |
| 2615 | } |
| 2616 | |
| 2617 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 2618 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 2619 | switch (rotation) { |
| 2620 | case ROTATION_0: |
| 2621 | outMatrix.reset(); |
| 2622 | break; |
| 2623 | case ROTATION_270: |
| 2624 | outMatrix.setRotate(270, 0, 0); |
| 2625 | outMatrix.postTranslate(0, displayHeight); |
| 2626 | outMatrix.postTranslate(rectTop, 0); |
| 2627 | break; |
| 2628 | case ROTATION_180: |
| 2629 | outMatrix.reset(); |
| 2630 | break; |
| 2631 | case ROTATION_90: |
| 2632 | outMatrix.setRotate(90, 0, 0); |
| 2633 | outMatrix.postTranslate(displayWidth, 0); |
| 2634 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 2635 | break; |
| 2636 | } |
| 2637 | } |
| 2638 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 2639 | // TODO(proto-merge): Remove once protos for ActivityDisplay and DisplayContent are merged. |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2640 | public void dumpDebugInner(ProtoOutputStream proto, long fieldId, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2641 | @WindowTraceLogLevel int logLevel) { |
| 2642 | // Critical log level logs only visible elements to mitigate performance overheard |
| 2643 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 2644 | return; |
| 2645 | } |
| 2646 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2647 | final long token = proto.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2648 | super.dumpDebug(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2649 | proto.write(ID, mDisplayId); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2650 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2651 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2652 | stack.dumpDebugInnerStackOnly(proto, STACKS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2653 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2654 | mDividerControllerLocked.dumpDebug(proto, DOCKED_STACK_DIVIDER_CONTROLLER); |
| 2655 | mPinnedStackControllerLocked.dumpDebug(proto, PINNED_STACK_CONTROLLER); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2656 | for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2657 | final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2658 | windowToken.dumpDebug(proto, ABOVE_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2659 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2660 | for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2661 | final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2662 | windowToken.dumpDebug(proto, BELOW_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2663 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2664 | for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2665 | final WindowToken windowToken = mImeWindowsContainers.getChildAt(i); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2666 | windowToken.dumpDebug(proto, IME_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2667 | } |
| 2668 | proto.write(DPI, mBaseDisplayDensity); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2669 | mDisplayInfo.dumpDebug(proto, DISPLAY_INFO); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2670 | proto.write(ROTATION, getRotation()); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2671 | final ScreenRotationAnimation screenRotationAnimation = getRotationAnimation(); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2672 | if (screenRotationAnimation != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2673 | screenRotationAnimation.dumpDebug(proto, SCREEN_ROTATION_ANIMATION); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2674 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 2675 | mDisplayFrames.dumpDebug(proto, DISPLAY_FRAMES); |
| 2676 | mAppTransition.dumpDebug(proto, APP_TRANSITION); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2677 | if (mFocusedApp != null) { |
| 2678 | mFocusedApp.writeNameToProto(proto, FOCUSED_APP); |
| 2679 | } |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2680 | for (int i = mOpeningApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2681 | mOpeningApps.valueAt(i).writeIdentifierToProto(proto, OPENING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2682 | } |
| 2683 | for (int i = mClosingApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2684 | mClosingApps.valueAt(i).writeIdentifierToProto(proto, CLOSING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2685 | } |
| 2686 | for (int i = mChangingApps.size() - 1; i >= 0; i--) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2687 | mChangingApps.valueAt(i).writeIdentifierToProto(proto, CHANGING_APPS); |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2688 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2689 | proto.end(token); |
| 2690 | } |
| 2691 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2692 | @Override |
| 2693 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 2694 | super.dump(pw, prefix, dumpAll); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2695 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 2696 | final String subPrefix = " " + prefix; |
| 2697 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 2698 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 2699 | pw.print("dpi"); |
| 2700 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 2701 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 2702 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 2703 | pw.print(" base="); |
| 2704 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 2705 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 2706 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 2707 | if (mDisplayScalingDisabled) { |
| 2708 | pw.println(" noscale"); |
| 2709 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2710 | pw.print(" cur="); |
| 2711 | pw.print(mDisplayInfo.logicalWidth); |
| 2712 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 2713 | pw.print(" app="); |
| 2714 | pw.print(mDisplayInfo.appWidth); |
| 2715 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 2716 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 2717 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 2718 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 2719 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2720 | pw.print(subPrefix + "deferred=" + mDeferredRemoval |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 2721 | + " mLayoutNeeded=" + mLayoutNeeded); |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2722 | pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2723 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2724 | pw.println(); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2725 | pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq); |
| 2726 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2727 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 2728 | if (mLastFocus != mCurrentFocus) { |
| 2729 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 2730 | } |
| 2731 | if (mLosingFocus.size() > 0) { |
| 2732 | pw.println(); |
| 2733 | pw.println(" Windows losing focus:"); |
| 2734 | for (int i = mLosingFocus.size() - 1; i >= 0; i--) { |
| 2735 | final WindowState w = mLosingFocus.get(i); |
| 2736 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 2737 | pw.print(w); |
| 2738 | if (dumpAll) { |
| 2739 | pw.println(":"); |
| 2740 | w.dump(pw, " ", true); |
| 2741 | } else { |
| 2742 | pw.println(); |
| 2743 | } |
| 2744 | } |
| 2745 | } |
| 2746 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2747 | if (mLastStatusBarVisibility != 0) { |
| 2748 | pw.print(" mLastStatusBarVisibility=0x"); |
| 2749 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 2750 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2751 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2752 | pw.println(); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 2753 | mWallpaperController.dump(pw, " "); |
| 2754 | |
| 2755 | pw.println(); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 2756 | pw.print("mSystemGestureExclusion="); |
| 2757 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() > 0) { |
| 2758 | pw.println(mSystemGestureExclusion); |
| 2759 | } else { |
| 2760 | pw.println("<no lstnrs>"); |
| 2761 | } |
| 2762 | |
| 2763 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2764 | pw.println(prefix + "Application tokens in top down Z order:"); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2765 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2766 | final ActivityStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2767 | stack.dump(pw, prefix + " ", dumpAll); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2768 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2769 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2770 | pw.println(); |
| 2771 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2772 | pw.println(); |
| 2773 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2774 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2775 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2776 | pw.print(" Exiting #"); pw.print(i); |
| 2777 | pw.print(' '); pw.print(token); |
| 2778 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2779 | token.dump(pw, " ", dumpAll); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2780 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2781 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 2782 | |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 2783 | final ScreenRotationAnimation rotationAnimation = getRotationAnimation(); |
| 2784 | if (rotationAnimation != null) { |
| 2785 | pw.print(subPrefix); |
| 2786 | pw.println(" mScreenRotationAnimation:"); |
| 2787 | rotationAnimation.printTo(" ", pw); |
| 2788 | } else if (dumpAll) { |
| 2789 | pw.print(subPrefix); |
| 2790 | pw.println(" no ScreenRotationAnimation "); |
| 2791 | } |
| 2792 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 2793 | pw.println(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2794 | |
| 2795 | // Dump stack references |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2796 | final ActivityStack homeStack = getHomeStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2797 | if (homeStack != null) { |
| 2798 | pw.println(prefix + "homeStack=" + homeStack.getName()); |
| 2799 | } |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2800 | final ActivityStack pinnedStack = getPinnedStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2801 | if (pinnedStack != null) { |
| 2802 | pw.println(prefix + "pinnedStack=" + pinnedStack.getName()); |
| 2803 | } |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2804 | final ActivityStack splitScreenPrimaryStack = getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2805 | if (splitScreenPrimaryStack != null) { |
| 2806 | pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName()); |
| 2807 | } |
| 2808 | |
| 2809 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2810 | mDividerControllerLocked.dump(prefix, pw); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2811 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2812 | mPinnedStackControllerLocked.dump(prefix, pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2813 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2814 | pw.println(); |
| 2815 | mDisplayFrames.dump(prefix, pw); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2816 | pw.println(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2817 | mDisplayPolicy.dump(prefix, pw); |
| 2818 | pw.println(); |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2819 | mDisplayRotation.dump(prefix, pw); |
| 2820 | pw.println(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2821 | mInputMonitor.dump(pw, " "); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 2822 | pw.println(); |
| 2823 | mInsetsStateController.dump(prefix, pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2824 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2825 | |
| 2826 | @Override |
| 2827 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2828 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2832 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2833 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2834 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2835 | /** Returns true if the stack in the windowing mode is visible. */ |
| 2836 | boolean isStackVisible(int windowingMode) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2837 | final ActivityStack stack = getTopStackInWindowingMode(windowingMode); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2838 | return stack != null && stack.isVisible(); |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 2839 | } |
| 2840 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2841 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2842 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2843 | final int x = (int) xf; |
| 2844 | final int y = (int) yf; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2845 | final WindowState touchedWin = getWindow(w -> { |
| 2846 | final int flags = w.mAttrs.flags; |
| 2847 | if (!w.isVisibleLw()) { |
| 2848 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2849 | } |
| 2850 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2851 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2852 | } |
| 2853 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2854 | w.getVisibleBounds(mTmpRect); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2855 | if (!mTmpRect.contains(x, y)) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2856 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2857 | } |
| 2858 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2859 | w.getTouchableRegion(mTmpRegion); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2860 | |
| 2861 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2862 | return mTmpRegion.contains(x, y) || touchFlags == 0; |
| 2863 | }); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2864 | |
| 2865 | return touchedWin; |
| 2866 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 2867 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2868 | boolean canAddToastWindowForUid(int uid) { |
| 2869 | // We allow one toast window per UID being shown at a time. |
Svet Ganov | daca8ee | 2017-01-21 17:40:40 -0800 | [diff] [blame] | 2870 | // Also if the app is focused adding more than one toast at |
| 2871 | // a time for better backwards compatibility. |
| 2872 | final WindowState focusedWindowForUid = getWindow(w -> |
| 2873 | w.mOwnerUid == uid && w.isFocused()); |
| 2874 | if (focusedWindowForUid != null) { |
| 2875 | return true; |
| 2876 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2877 | final WindowState win = getWindow(w -> |
| 2878 | w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden |
| 2879 | && !w.mWindowRemovalAllowed); |
| 2880 | return win == null; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2883 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2884 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 2885 | return; |
| 2886 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2887 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2888 | // Used to communicate the old focus to the callback method. |
| 2889 | mTmpWindow = oldFocus; |
| 2890 | |
| 2891 | forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2892 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2893 | |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2894 | /** |
| 2895 | * Looking for the focused window on this display if the top focused display hasn't been |
| 2896 | * found yet (topFocusedDisplayId is INVALID_DISPLAY) or per-display focused was allowed. |
| 2897 | * |
| 2898 | * @param topFocusedDisplayId Id of the top focused display. |
| 2899 | * @return The focused window or null if there isn't any or no need to seek. |
| 2900 | */ |
| 2901 | WindowState findFocusedWindowIfNeeded(int topFocusedDisplayId) { |
| 2902 | return (mWmService.mPerDisplayFocusEnabled || topFocusedDisplayId == INVALID_DISPLAY) |
| 2903 | ? findFocusedWindow() : null; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2904 | } |
| 2905 | |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2906 | WindowState findFocusedWindow() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2907 | mTmpWindow = null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2908 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2909 | forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2910 | |
| 2911 | if (mTmpWindow == null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2912 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "findFocusedWindow: No focusable windows."); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2913 | return null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2914 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2915 | return mTmpWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2918 | /** |
| 2919 | * Update the focused window and make some adjustments if the focus has changed. |
| 2920 | * |
| 2921 | * @param mode Indicates the situation we are in. Possible modes are: |
| 2922 | * {@link WindowManagerService#UPDATE_FOCUS_NORMAL}, |
| 2923 | * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES}, |
| 2924 | * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES}, |
| 2925 | * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS} |
| 2926 | * @param updateInputWindows Whether to sync the window information to the input module. |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2927 | * @param topFocusedDisplayId Display id of current top focused display. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2928 | * @return {@code true} if the focused window has changed. |
| 2929 | */ |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2930 | boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, |
| 2931 | int topFocusedDisplayId) { |
| 2932 | WindowState newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2933 | if (mCurrentFocus == newFocus) { |
| 2934 | return false; |
| 2935 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2936 | boolean imWindowChanged = false; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2937 | final WindowState imWindow = mInputMethodWindow; |
| 2938 | if (imWindow != null) { |
| 2939 | final WindowState prevTarget = mInputMethodTarget; |
| 2940 | final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/); |
| 2941 | imWindowChanged = prevTarget != newTarget; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2942 | |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2943 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS |
| 2944 | && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 2945 | assignWindowLayers(false /* setLayoutNeeded */); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | if (imWindowChanged) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2950 | mWmService.mWindowsChanged = true; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2951 | setLayoutNeeded(); |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 2952 | newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2953 | } |
| 2954 | if (mCurrentFocus != newFocus) { |
| 2955 | mWmService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2956 | } |
| 2957 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2958 | ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "Changing focus from %s to %s displayId=%d Callers=%s", |
| 2959 | mCurrentFocus, newFocus, getDisplayId(), Debug.getCallers(4)); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2960 | final WindowState oldFocus = mCurrentFocus; |
| 2961 | mCurrentFocus = newFocus; |
| 2962 | mLosingFocus.remove(newFocus); |
| 2963 | |
| 2964 | if (newFocus != null) { |
| 2965 | mWinAddedSinceNullFocus.clear(); |
| 2966 | mWinRemovedSinceNullFocus.clear(); |
| 2967 | |
| 2968 | if (newFocus.canReceiveKeys()) { |
| 2969 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 2970 | // This is to protect against bugs if someone pauses dispatching but |
| 2971 | // forgets to resume. |
| 2972 | newFocus.mToken.paused = false; |
| 2973 | } |
| 2974 | } |
| 2975 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2976 | int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2977 | |
| 2978 | if (imWindowChanged && oldFocus != mInputMethodWindow) { |
| 2979 | // Focus of the input method window changed. Perform layout if needed. |
| 2980 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 2981 | performLayout(true /*initial*/, updateInputWindows); |
| 2982 | focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT; |
| 2983 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 2984 | // Client will do the layout, but we need to assign layers |
| 2985 | // for handleNewWindowLocked() below. |
| 2986 | assignWindowLayers(false /* setLayoutNeeded */); |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 2991 | // The change in focus caused us to need to do a layout. Okay. |
| 2992 | setLayoutNeeded(); |
| 2993 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 2994 | performLayout(true /*initial*/, updateInputWindows); |
| 2995 | } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2996 | mWmService.mRoot.performSurfacePlacement(false); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 3001 | // If we defer assigning layers, then the caller is responsible for doing this part. |
| 3002 | getInputMonitor().setInputFocusLw(newFocus, updateInputWindows); |
| 3003 | } |
| 3004 | |
| 3005 | adjustForImeIfNeeded(); |
| 3006 | |
| 3007 | // We may need to schedule some toast windows to be removed. The toasts for an app that |
| 3008 | // does not have input focus are removed within a timeout to prevent apps to redress |
| 3009 | // other apps' UI. |
| 3010 | scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus); |
| 3011 | |
| 3012 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3013 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 3014 | } |
| 3015 | return true; |
| 3016 | } |
| 3017 | |
| 3018 | /** |
| 3019 | * Set the new focused app to this display. |
| 3020 | * |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3021 | * @param newFocus the new focused {@link ActivityRecord}. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3022 | * @return true if the focused app is changed. |
| 3023 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3024 | boolean setFocusedApp(ActivityRecord newFocus) { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3025 | if (newFocus != null) { |
| 3026 | final DisplayContent appDisplay = newFocus.getDisplayContent(); |
| 3027 | if (appDisplay != this) { |
| 3028 | throw new IllegalStateException(newFocus + " is not on " + getName() |
| 3029 | + " but " + ((appDisplay != null) ? appDisplay.getName() : "none")); |
| 3030 | } |
| 3031 | } |
| 3032 | if (mFocusedApp == newFocus) { |
| 3033 | return false; |
| 3034 | } |
| 3035 | mFocusedApp = newFocus; |
| 3036 | getInputMonitor().setFocusedAppLw(newFocus); |
| 3037 | updateTouchExcludeRegion(); |
| 3038 | return true; |
| 3039 | } |
| 3040 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3041 | /** Updates the layer assignment of windows on this display. */ |
| 3042 | void assignWindowLayers(boolean setLayoutNeeded) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3043 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers"); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3044 | assignChildLayers(getPendingTransaction()); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3045 | if (setLayoutNeeded) { |
| 3046 | setLayoutNeeded(); |
| 3047 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3048 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3049 | // We accumlate the layer changes in-to "getPendingTransaction()" but we defer |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3050 | // the application of this transaction until the animation pass triggers |
| 3051 | // prepareSurfaces. This allows us to synchronize Z-ordering changes with |
| 3052 | // the hiding and showing of surfaces. |
| 3053 | scheduleAnimation(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3054 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3057 | // TODO: This should probably be called any time a visual change is made to the hierarchy like |
| 3058 | // moving containers or resizing them. Need to investigate the best way to have it automatically |
| 3059 | // 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] | 3060 | void layoutAndAssignWindowLayersIfNeeded() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3061 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3062 | setLayoutNeeded(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3063 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3064 | if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3065 | false /*updateInputWindows*/)) { |
| 3066 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3067 | } |
| 3068 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3069 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3070 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3071 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3074 | /** Returns true if a leaked surface was destroyed */ |
| 3075 | boolean destroyLeakedSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3076 | // Used to indicate that a surface was leaked. |
| 3077 | mTmpWindow = null; |
| 3078 | forAllWindows(w -> { |
| 3079 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3080 | if (wsa.mSurfaceController == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3081 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3082 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3083 | if (!mWmService.mSessions.contains(wsa.mSession)) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3084 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3085 | + w + " surface=" + wsa.mSurfaceController |
| 3086 | + " token=" + w.mToken |
| 3087 | + " pid=" + w.mSession.mPid |
| 3088 | + " uid=" + w.mSession.mUid); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3089 | wsa.destroySurface(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3090 | mWmService.mForceRemoves.add(w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3091 | mTmpWindow = w; |
Issei Suzuki | d4ee1cc | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 3092 | } else if (w.mActivityRecord != null && !w.mActivityRecord.isClientVisible()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3093 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3094 | + w + " surface=" + wsa.mSurfaceController |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3095 | + " token=" + w.mActivityRecord); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3096 | ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE LEAK DESTROY: %s", w); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3097 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3098 | mTmpWindow = w; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3099 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3100 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3101 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3102 | return mTmpWindow != null; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3105 | boolean hasAlertWindowSurfaces() { |
| 3106 | for (int i = mWmService.mSessions.size() - 1; i >= 0; --i) { |
| 3107 | if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces(this)) { |
| 3108 | return true; |
| 3109 | } |
| 3110 | } |
| 3111 | return false; |
| 3112 | } |
| 3113 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3114 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3115 | * Set input method window for the display. |
| 3116 | * @param win Set when window added or Null when destroyed. |
| 3117 | */ |
| 3118 | void setInputMethodWindowLocked(WindowState win) { |
| 3119 | mInputMethodWindow = win; |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3120 | // Update display configuration for IME process. |
| 3121 | if (mInputMethodWindow != null) { |
| 3122 | final int imePid = mInputMethodWindow.mSession.mPid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3123 | mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid, |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3124 | mInputMethodWindow.getDisplayId()); |
| 3125 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3126 | computeImeTarget(true /* updateImeTarget */); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 3127 | mInsetsStateController.getSourceProvider(ITYPE_IME).setWindow(win, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3128 | null /* frameProvider */); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | /** |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3132 | * Determine and return the window that should be the IME target. |
| 3133 | * @param updateImeTarget If true the system IME target will be updated to match what we found. |
| 3134 | * @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] | 3135 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3136 | WindowState computeImeTarget(boolean updateImeTarget) { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3137 | if (mInputMethodWindow == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3138 | // There isn't an IME so there shouldn't be a target...That was easy! |
| 3139 | if (updateImeTarget) { |
| 3140 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3141 | + mInputMethodTarget + " to null since mInputMethodWindow is null"); |
| 3142 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3143 | } |
| 3144 | return null; |
| 3145 | } |
| 3146 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3147 | final WindowState curTarget = mInputMethodTarget; |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 3148 | if (!canUpdateImeTarget()) { |
| 3149 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target"); |
| 3150 | return curTarget; |
| 3151 | } |
| 3152 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3153 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 3154 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 3155 | // 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] | 3156 | mUpdateImeTarget = updateImeTarget; |
| 3157 | WindowState target = getWindow(mComputeImeTargetPredicate); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3158 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3159 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3160 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 3161 | // to be on top of it, but it is not -really- where input will go. So look down below |
| 3162 | // for a real window to target... |
| 3163 | if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3164 | final ActivityRecord activity = target.mActivityRecord; |
| 3165 | if (activity != null) { |
| 3166 | final WindowState betterTarget = activity.getImeTargetBelowWindow(target); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3167 | if (betterTarget != null) { |
| 3168 | target = betterTarget; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3169 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3170 | } |
| 3171 | } |
| 3172 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3173 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM, |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3174 | "Proposed new IME target: " + target + " for display: " + getDisplayId()); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3175 | |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3176 | // 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] | 3177 | // not removed, keep on the last target to avoid IME flicker. |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3178 | if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw() |
Tarandeep Singh | 2d0aca4 | 2019-03-28 14:08:58 -0700 | [diff] [blame] | 3179 | && curTarget.isClosing()) { |
| 3180 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Not changing target till current window is" |
| 3181 | + " closing and not removed"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3182 | return curTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3185 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target |
| 3186 | + " updateImeTarget=" + updateImeTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3187 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3188 | if (target == null) { |
| 3189 | if (updateImeTarget) { |
| 3190 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 3191 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" |
| 3192 | + Debug.getCallers(4) : "")); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3193 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | return null; |
| 3197 | } |
| 3198 | |
| 3199 | if (updateImeTarget) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3200 | ActivityRecord activity = curTarget == null ? null : curTarget.mActivityRecord; |
| 3201 | if (activity != null) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3202 | |
| 3203 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 3204 | // to look at all windows below the current target that are in this app, finding the |
| 3205 | // highest visible one in layering. |
| 3206 | WindowState highestTarget = null; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3207 | if (activity.isAnimating(TRANSITION)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3208 | highestTarget = activity.getHighestAnimLayerWindow(curTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | if (highestTarget != null) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 3212 | if (DEBUG_INPUT_METHOD) { |
| 3213 | Slog.v(TAG_WM, mAppTransition + " " + highestTarget + " animating=" |
| 3214 | + highestTarget.isAnimating(TRANSITION | PARENTS)); |
| 3215 | } |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3216 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3217 | if (mAppTransition.isTransitionSet()) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3218 | // If we are currently setting up for an animation, hold everything until we |
| 3219 | // can find out what will happen. |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3220 | setInputMethodTarget(highestTarget, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3221 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3222 | } |
| 3223 | } |
| 3224 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3225 | |
| 3226 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 3227 | + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3228 | setInputMethodTarget(target, false); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3231 | return target; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3234 | /** |
| 3235 | * Calling {@link #computeImeTarget(boolean)} to update the input method target window in |
| 3236 | * the candidate app window token if needed. |
| 3237 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3238 | void computeImeTargetIfNeeded(ActivityRecord candidate) { |
| 3239 | if (mInputMethodTarget != null && mInputMethodTarget.mActivityRecord == candidate) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3240 | computeImeTarget(true /* updateImeTarget */); |
| 3241 | } |
| 3242 | } |
| 3243 | |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3244 | private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3245 | if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3246 | return; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3249 | mInputMethodTarget = target; |
| 3250 | mInputMethodTargetWaitingAnim = targetWaitingAnim; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3251 | assignWindowLayers(false /* setLayoutNeeded */); |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 3252 | mInsetsStateController.onImeTargetChanged(target); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3253 | updateImeParent(); |
| 3254 | } |
| 3255 | |
| 3256 | private void updateImeParent() { |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 3257 | // Force attaching IME to the display when magnifying, or it would be magnified with |
| 3258 | // target app together. |
| 3259 | final boolean shouldAttachToDisplay = (mMagnificationSpec != null); |
| 3260 | final SurfaceControl newParent = |
| 3261 | shouldAttachToDisplay ? mWindowingLayer : computeImeParent(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3262 | if (newParent != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3263 | getPendingTransaction().reparent(mImeWindowsContainers.mSurfaceControl, newParent); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3264 | scheduleAnimation(); |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | /** |
| 3269 | * Computes the window the IME should be attached to. |
| 3270 | */ |
| 3271 | @VisibleForTesting |
| 3272 | SurfaceControl computeImeParent() { |
| 3273 | |
| 3274 | // Attach it to app if the target is part of an app and such app is covering the entire |
| 3275 | // screen. If it's not covering the entire screen the IME might extend beyond the apps |
| 3276 | // bounds. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3277 | if (mInputMethodTarget != null && mInputMethodTarget.mActivityRecord != null |
Riddle Hsu | 6d6f67c | 2019-03-14 16:54:26 +0800 | [diff] [blame] | 3278 | && mInputMethodTarget.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 3279 | // An activity with override bounds should be letterboxed inside its parent bounds, |
| 3280 | // so it doesn't fill the screen. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3281 | && mInputMethodTarget.mActivityRecord.matchParentBounds()) { |
| 3282 | return mInputMethodTarget.mActivityRecord.getSurfaceControl(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | // Otherwise, we just attach it to the display. |
| 3286 | return mWindowingLayer; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) { |
| 3290 | if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 3291 | return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
| 3292 | } |
| 3293 | |
| 3294 | // Used to indicate we have reached the first window in the range we are interested in. |
| 3295 | mTmpWindow = null; |
| 3296 | |
| 3297 | // TODO: Figure-out a more efficient way to do this. |
| 3298 | final WindowState candidate = getWindow(w -> { |
| 3299 | if (w == top) { |
| 3300 | // Reached the first window in the range we are interested in. |
| 3301 | mTmpWindow = w; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3302 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3303 | if (mTmpWindow == null) { |
| 3304 | return false; |
| 3305 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3306 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3307 | if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 3308 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3309 | } |
| 3310 | // If we reached the bottom of the range of windows we are considering, |
| 3311 | // assume no menu is needed. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3312 | if (w == bottom) { |
| 3313 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3314 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3315 | return false; |
| 3316 | }); |
| 3317 | |
| 3318 | return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3321 | void setLayoutNeeded() { |
| 3322 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3323 | mLayoutNeeded = true; |
| 3324 | } |
| 3325 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3326 | private void clearLayoutNeeded() { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3327 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3328 | mLayoutNeeded = false; |
| 3329 | } |
| 3330 | |
| 3331 | boolean isLayoutNeeded() { |
| 3332 | return mLayoutNeeded; |
| 3333 | } |
| 3334 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3335 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 3336 | if (mTokenMap.isEmpty()) { |
| 3337 | return; |
| 3338 | } |
| 3339 | pw.println(" Display #" + mDisplayId); |
| 3340 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 3341 | while (it.hasNext()) { |
| 3342 | final WindowToken token = it.next(); |
| 3343 | pw.print(" "); |
| 3344 | pw.print(token); |
| 3345 | if (dumpAll) { |
| 3346 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3347 | token.dump(pw, " ", dumpAll); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3348 | } else { |
| 3349 | pw.println(); |
| 3350 | } |
| 3351 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3352 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3353 | if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty() || !mChangingApps.isEmpty()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3354 | pw.println(); |
| 3355 | if (mOpeningApps.size() > 0) { |
| 3356 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 3357 | } |
| 3358 | if (mClosingApps.size() > 0) { |
| 3359 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 3360 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3361 | if (mChangingApps.size() > 0) { |
| 3362 | pw.print(" mChangingApps="); pw.println(mChangingApps); |
| 3363 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | mUnknownAppVisibilityController.dump(pw, " "); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3367 | } |
| 3368 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3369 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3370 | final int[] index = new int[1]; |
| 3371 | forAllWindows(w -> { |
| 3372 | final WindowStateAnimator wAnim = w.mWinAnimator; |
| 3373 | pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim); |
| 3374 | index[0] = index[0] + 1; |
| 3375 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3378 | /** |
| 3379 | * Starts the Keyguard exit animation on all windows that don't belong to an app token. |
| 3380 | */ |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3381 | void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade, |
| 3382 | boolean subtle) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3383 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3384 | forAllWindows(w -> { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3385 | if (w.mActivityRecord == null && policy.canBeHiddenByKeyguardLw(w) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 3386 | && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) { |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3387 | w.startAnimation(policy.createHiddenByKeyguardExit( |
| 3388 | onWallpaper, goingToShade, subtle)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3389 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3390 | }, true /* traverseTopToBottom */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3391 | } |
| 3392 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3393 | /** @return {@code true} if there is window to wait before enabling the screen. */ |
| 3394 | boolean shouldWaitForSystemDecorWindowsOnBoot() { |
| 3395 | if (!isDefaultDisplay && !supportsSystemDecorations()) { |
| 3396 | // Nothing to wait because the secondary display doesn't support system decorations, |
| 3397 | // there is no wallpaper, keyguard (status bar) or application (home) window to show |
| 3398 | // during booting. |
| 3399 | return false; |
| 3400 | } |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3401 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3402 | final SparseBooleanArray drawnWindowTypes = new SparseBooleanArray(); |
| 3403 | // Presuppose keyguard is drawn because if its window isn't attached, we don't know if it |
| 3404 | // wants to be shown or hidden, then it should not delay enabling the screen. |
| 3405 | drawnWindowTypes.put(TYPE_STATUS_BAR, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3406 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3407 | final WindowState visibleNotDrawnWindow = getWindow(w -> { |
| 3408 | if (w.mViewVisibility == View.VISIBLE && !w.mObscured && !w.isDrawnLw()) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3409 | return true; |
| 3410 | } |
| 3411 | if (w.isDrawnLw()) { |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3412 | final int type = w.mAttrs.type; |
| 3413 | if (type == TYPE_BOOT_PROGRESS || type == TYPE_BASE_APPLICATION |
| 3414 | || type == TYPE_WALLPAPER) { |
| 3415 | drawnWindowTypes.put(type, true); |
| 3416 | } else if (type == TYPE_STATUS_BAR) { |
| 3417 | drawnWindowTypes.put(TYPE_STATUS_BAR, mWmService.mPolicy.isKeyguardDrawnLw()); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3418 | } |
| 3419 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3420 | return false; |
| 3421 | }); |
| 3422 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3423 | if (visibleNotDrawnWindow != null) { |
| 3424 | // Wait for the visible window to be drawn. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3425 | return true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3428 | // if the wallpaper service is disabled on the device, we're never going to have |
| 3429 | // wallpaper, don't bother waiting for it |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3430 | boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean( |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3431 | com.android.internal.R.bool.config_enableWallpaperService) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3432 | && mWmService.mContext.getResources().getBoolean( |
Daichi Hirono | c143222 | 2018-03-29 13:06:07 +0900 | [diff] [blame] | 3433 | com.android.internal.R.bool.config_checkWallpaperAtBoot) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3434 | && !mWmService.mOnlyCore; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3435 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3436 | final boolean haveBootMsg = drawnWindowTypes.get(TYPE_BOOT_PROGRESS); |
| 3437 | final boolean haveApp = drawnWindowTypes.get(TYPE_BASE_APPLICATION); |
| 3438 | final boolean haveWallpaper = drawnWindowTypes.get(TYPE_WALLPAPER); |
| 3439 | final boolean haveKeyguard = drawnWindowTypes.get(TYPE_STATUS_BAR); |
| 3440 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3441 | ProtoLog.i(WM_DEBUG_SCREEN_ON, |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3442 | "******** booted=%b msg=%b haveBoot=%b haveApp=%b haveWall=%b " |
| 3443 | + "wallEnabled=%b haveKeyguard=%b", |
| 3444 | mWmService.mSystemBooted, mWmService.mShowingBootMessages, haveBootMsg, |
| 3445 | haveApp, haveWallpaper, wallpaperEnabled, haveKeyguard); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3446 | |
| 3447 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 3448 | // message is actually displayed. |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3449 | if (!mWmService.mSystemBooted && !haveBootMsg) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3450 | return true; |
| 3451 | } |
| 3452 | |
| 3453 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 3454 | // we have the application and wallpaper. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3455 | if (mWmService.mSystemBooted |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 3456 | && ((!haveApp && !haveKeyguard) || (wallpaperEnabled && !haveWallpaper))) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3457 | return true; |
| 3458 | } |
| 3459 | |
| 3460 | return false; |
| 3461 | } |
| 3462 | |
Jorim Jaggi | 8f52087 | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3463 | void updateWindowsForAnimator() { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3464 | forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3467 | boolean isInputMethodClientFocus(int uid, int pid) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3468 | final WindowState imFocus = computeImeTarget(false /* updateImeTarget */); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3469 | if (imFocus == null) { |
| 3470 | return false; |
| 3471 | } |
| 3472 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3473 | if (DEBUG_INPUT_METHOD) { |
| 3474 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3475 | Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId); |
| 3476 | Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3479 | if (DEBUG_INPUT_METHOD) { |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3480 | Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid |
| 3481 | + "/" + imFocus.mSession.mPid); |
| 3482 | Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3485 | return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | boolean hasSecureWindowOnScreen() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3489 | final WindowState win = getWindow( |
| 3490 | w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0); |
| 3491 | return win != null; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3494 | void hideTransientBars() { |
| 3495 | // TODO(b/118118435): Remove this after migration |
| 3496 | final int transientFlags = View.STATUS_BAR_TRANSIENT | View.NAVIGATION_BAR_TRANSIENT; |
| 3497 | statusBarVisibilityChanged(mLastStatusBarVisibility & ~transientFlags); |
| 3498 | |
| 3499 | getInsetsPolicy().hideTransient(); |
| 3500 | } |
| 3501 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3502 | void statusBarVisibilityChanged(int visibility) { |
| 3503 | mLastStatusBarVisibility = visibility; |
| 3504 | visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility); |
| 3505 | updateStatusBarVisibilityLocked(visibility); |
| 3506 | } |
| 3507 | |
| 3508 | private boolean updateStatusBarVisibilityLocked(int visibility) { |
| 3509 | if (mLastDispatchedSystemUiVisibility == visibility) { |
| 3510 | return false; |
| 3511 | } |
| 3512 | final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility) |
| 3513 | // We are only interested in differences of one of the |
| 3514 | // clearable flags... |
| 3515 | & View.SYSTEM_UI_CLEARABLE_FLAGS |
| 3516 | // ...if it has actually been cleared. |
| 3517 | & ~visibility; |
| 3518 | |
| 3519 | mLastDispatchedSystemUiVisibility = visibility; |
| 3520 | if (isDefaultDisplay) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3521 | mWmService.mInputManager.setSystemUiVisibility(visibility); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3522 | } |
| 3523 | updateSystemUiVisibility(visibility, globalDiff); |
| 3524 | return true; |
| 3525 | } |
| 3526 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3527 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3528 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3529 | try { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3530 | final int curValue = w.mSystemUiVisibility; |
| 3531 | final int diff = (curValue ^ visibility) & globalDiff; |
| 3532 | final int newValue = (curValue & ~diff) | (visibility & diff); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3533 | if (newValue != curValue) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3534 | w.mSeq++; |
| 3535 | w.mSystemUiVisibility = newValue; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3536 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3537 | if (newValue != curValue || w.mAttrs.hasSystemUiListeners) { |
| 3538 | w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3539 | visibility, newValue, diff); |
| 3540 | } |
| 3541 | } catch (RemoteException e) { |
| 3542 | // so sorry |
| 3543 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3544 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3547 | void reevaluateStatusBarVisibility() { |
| 3548 | int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 3549 | if (updateStatusBarVisibilityLocked(visibility)) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3550 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3551 | } |
| 3552 | } |
| 3553 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3554 | void onWindowFreezeTimeout() { |
| 3555 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3556 | mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3557 | |
| 3558 | forAllWindows(w -> { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3559 | if (!w.getOrientationChanging()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3560 | return; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3561 | } |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 3562 | w.orientationChangeTimedOut(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3563 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3564 | - mWmService.mDisplayFreezeTime); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3565 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3566 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3567 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3570 | // TODO: Super crazy long method that should be broken down... |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3571 | void applySurfaceChangesTransaction(boolean recoveringMemory) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3572 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3573 | |
| 3574 | mTmpUpdateAllDrawn.clear(); |
| 3575 | |
| 3576 | int repeats = 0; |
| 3577 | do { |
| 3578 | repeats++; |
| 3579 | if (repeats > 6) { |
| 3580 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 3581 | clearLayoutNeeded(); |
| 3582 | break; |
| 3583 | } |
| 3584 | |
| 3585 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner", |
| 3586 | pendingLayoutChanges); |
| 3587 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 3588 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 3589 | mWallpaperController.adjustWallpaperWindows(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 3592 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3593 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3594 | if (updateOrientation()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3595 | setLayoutNeeded(); |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 3596 | sendNewConfiguration(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3601 | setLayoutNeeded(); |
| 3602 | } |
| 3603 | |
| 3604 | // FIRST LOOP: Perform a layout, if needed. |
| 3605 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 3606 | performLayout(repeats == 1, false /* updateInputWindows */); |
| 3607 | } else { |
| 3608 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 3609 | } |
| 3610 | |
| 3611 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating. |
| 3612 | pendingLayoutChanges = 0; |
| 3613 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3614 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyPostLayoutPolicy"); |
| 3615 | try { |
| 3616 | mDisplayPolicy.beginPostLayoutPolicyLw(); |
| 3617 | forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */); |
| 3618 | pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw(); |
| 3619 | } finally { |
| 3620 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3621 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3622 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 3623 | "after finishPostLayoutPolicyLw", pendingLayoutChanges); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3624 | mInsetsStateController.onPostLayout(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3625 | } while (pendingLayoutChanges != 0); |
| 3626 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3627 | mTmpApplySurfaceChangesTransactionState.reset(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3628 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3629 | mTmpRecoveringMemory = recoveringMemory; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3630 | |
| 3631 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyWindowSurfaceChanges"); |
| 3632 | try { |
| 3633 | forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */); |
| 3634 | } finally { |
| 3635 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3636 | } |
Jorim Jaggi | 6b0f846 | 2018-01-05 17:23:47 +0100 | [diff] [blame] | 3637 | prepareSurfaces(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3638 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3639 | mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3640 | mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId, |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3641 | mLastHasContent, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3642 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate, |
| 3643 | mTmpApplySurfaceChangesTransactionState.preferredModeId, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3644 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 3645 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3646 | final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible(); |
| 3647 | if (wallpaperVisible != mLastWallpaperVisible) { |
| 3648 | mLastWallpaperVisible = wallpaperVisible; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3649 | mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3650 | } |
| 3651 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3652 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3653 | final ActivityRecord activity = mTmpUpdateAllDrawn.removeLast(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3654 | // See if any windows have been drawn, so they (and others associated with them) |
| 3655 | // can now be shown. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3656 | activity.updateAllDrawn(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3657 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3660 | private void updateBounds() { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3661 | calculateBounds(mDisplayInfo, mTmpBounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3662 | setBounds(mTmpBounds); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3663 | if (mPortalWindowHandle != null && mParentSurfaceControl != null) { |
| 3664 | mPortalWindowHandle.touchableRegion.getBounds(mTmpRect); |
| 3665 | if (!mTmpBounds.equals(mTmpRect)) { |
| 3666 | mPortalWindowHandle.touchableRegion.set(mTmpBounds); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3667 | getPendingTransaction().setInputWindowInfo( |
| 3668 | mParentSurfaceControl, mPortalWindowHandle); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3669 | } |
| 3670 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | // Determines the current display bounds based on the current state |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3674 | private void calculateBounds(DisplayInfo displayInfo, Rect out) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3675 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3676 | final int rotation = displayInfo.rotation; |
| 3677 | boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3678 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 3679 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3680 | int width = displayInfo.logicalWidth; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3681 | int left = (physWidth - width) / 2; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3682 | int height = displayInfo.logicalHeight; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3683 | int top = (physHeight - height) / 2; |
| 3684 | out.set(left, top, left + width, top + height); |
| 3685 | } |
| 3686 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3687 | private void getBounds(Rect out, int orientation) { |
| 3688 | getBounds(out); |
| 3689 | |
| 3690 | // Rotate the Rect if needed. |
| 3691 | final int currentRotation = mDisplayInfo.rotation; |
| 3692 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 3693 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 3694 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 3695 | mTmpRectF.set(out); |
| 3696 | mTmpMatrix.mapRect(mTmpRectF); |
| 3697 | mTmpRectF.round(out); |
| 3698 | } |
| 3699 | } |
| 3700 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 3701 | /** @returns the orientation of the display when it's rotation is ROTATION_0. */ |
| 3702 | int getNaturalOrientation() { |
| 3703 | return mBaseDisplayWidth < mBaseDisplayHeight |
| 3704 | ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
| 3705 | } |
| 3706 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3707 | void performLayout(boolean initial, boolean updateInputWindows) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3708 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "performLayout"); |
| 3709 | try { |
| 3710 | performLayoutNoTrace(initial, updateInputWindows); |
| 3711 | } finally { |
| 3712 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | private void performLayoutNoTrace(boolean initial, boolean updateInputWindows) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3717 | if (!isLayoutNeeded()) { |
| 3718 | return; |
| 3719 | } |
| 3720 | clearLayoutNeeded(); |
| 3721 | |
| 3722 | final int dw = mDisplayInfo.logicalWidth; |
| 3723 | final int dh = mDisplayInfo.logicalHeight; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3724 | if (DEBUG_LAYOUT) { |
| 3725 | Slog.v(TAG, "-------------------------------------"); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3726 | Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw |
| 3727 | + " dh=" + dh); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 3730 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 3731 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3732 | // TODO: Not sure if we really need to set the rotation here since we are updating from |
| 3733 | // the display info above... |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 3734 | mDisplayFrames.mRotation = getRotation(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3735 | mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3736 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3737 | int seq = mLayoutSeq + 1; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3738 | if (seq < 0) seq = 0; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3739 | mLayoutSeq = seq; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3740 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3741 | // Used to indicate that we have processed the dream window and all additional windows are |
| 3742 | // behind it. |
| 3743 | mTmpWindow = null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3744 | mTmpInitial = initial; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3745 | |
| 3746 | // First perform layout of any root windows (not attached to another window). |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3747 | forAllWindows(mPerformLayout, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3748 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3749 | // Used to indicate that we have processed the dream window and all additional attached |
| 3750 | // windows are behind it. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3751 | mTmpWindow2 = mTmpWindow; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3752 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3753 | |
| 3754 | // Now perform layout of attached windows, which usually depend on the position of the |
| 3755 | // window they are attached to. XXX does not deal with windows that are attached to windows |
| 3756 | // that are themselves attached. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3757 | forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3758 | |
| 3759 | // Window frames may have changed. Tell the input dispatcher about it. |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3760 | mInputMonitor.layoutInputConsumers(dw, dh); |
| 3761 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3762 | if (updateInputWindows) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3763 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3764 | } |
| 3765 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3766 | mWmService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /** |
| 3770 | * Takes a snapshot of the display. In landscape mode this grabs the whole screen. |
| 3771 | * In portrait mode, it grabs the full screenshot. |
| 3772 | * |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3773 | * @param config of the output bitmap |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3774 | */ |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3775 | Bitmap screenshotDisplayLocked(Bitmap.Config config) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3776 | if (!mWmService.mPolicy.isScreenOn()) { |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3777 | if (DEBUG_SCREENSHOT) { |
| 3778 | Slog.i(TAG_WM, "Attempted to take screenshot while display was off."); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3779 | } |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3780 | return null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3781 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3782 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3783 | int dw = mDisplayInfo.logicalWidth; |
| 3784 | int dh = mDisplayInfo.logicalHeight; |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3785 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3786 | if (dw <= 0 || dh <= 0) { |
| 3787 | return null; |
| 3788 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3789 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3790 | final Rect frame = new Rect(0, 0, dw, dh); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3791 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3792 | // The screenshot API does not apply the current screen rotation. |
| 3793 | int rot = mDisplay.getRotation(); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3794 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3795 | if (rot == ROTATION_90 || rot == ROTATION_270) { |
| 3796 | rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 3797 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3798 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3799 | // SurfaceFlinger is not aware of orientation, so convert our logical |
| 3800 | // crop to SurfaceFlinger's portrait orientation. |
| 3801 | convertCropForSurfaceFlinger(frame, rot, dw, dh); |
| 3802 | |
| 3803 | final ScreenRotationAnimation screenRotationAnimation = |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 3804 | mWmService.mRoot.getDisplayContent(DEFAULT_DISPLAY).getRotationAnimation(); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3805 | final boolean inRotation = screenRotationAnimation != null && |
| 3806 | screenRotationAnimation.isAnimating(); |
| 3807 | if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating"); |
| 3808 | |
| 3809 | // TODO(b/68392460): We should screenshot Task controls directly |
| 3810 | // but it's difficult at the moment as the Task doesn't have the |
| 3811 | // correct size set. |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 3812 | final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3813 | if (bitmap == null) { |
| 3814 | Slog.w(TAG_WM, "Failed to take screenshot"); |
| 3815 | return null; |
| 3816 | } |
| 3817 | |
| 3818 | // Create a copy of the screenshot that is immutable and backed in ashmem. |
| 3819 | // This greatly reduces the overhead of passing the bitmap between processes. |
| 3820 | final Bitmap ret = bitmap.createAshmemBitmap(config); |
| 3821 | bitmap.recycle(); |
| 3822 | return ret; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | // TODO: Can this use createRotationMatrix()? |
| 3826 | private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) { |
| 3827 | if (rot == Surface.ROTATION_90) { |
| 3828 | final int tmp = crop.top; |
| 3829 | crop.top = dw - crop.right; |
| 3830 | crop.right = crop.bottom; |
| 3831 | crop.bottom = dw - crop.left; |
| 3832 | crop.left = tmp; |
| 3833 | } else if (rot == Surface.ROTATION_180) { |
| 3834 | int tmp = crop.top; |
| 3835 | crop.top = dh - crop.bottom; |
| 3836 | crop.bottom = dh - tmp; |
| 3837 | tmp = crop.right; |
| 3838 | crop.right = dw - crop.left; |
| 3839 | crop.left = dw - tmp; |
| 3840 | } else if (rot == Surface.ROTATION_270) { |
| 3841 | final int tmp = crop.top; |
| 3842 | crop.top = crop.left; |
| 3843 | crop.left = dh - crop.bottom; |
| 3844 | crop.bottom = crop.right; |
| 3845 | crop.right = dh - tmp; |
| 3846 | } |
| 3847 | } |
| 3848 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3849 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 3850 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 3851 | mExitingTokens.get(i).hasVisible = hasVisible; |
| 3852 | } |
| 3853 | |
| 3854 | // Initialize state of exiting applications. |
| 3855 | mTaskStackContainers.setExitingTokensHasVisible(hasVisible); |
| 3856 | } |
| 3857 | |
| 3858 | void removeExistingTokensIfPossible() { |
| 3859 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 3860 | final WindowToken token = mExitingTokens.get(i); |
| 3861 | if (!token.hasVisible) { |
| 3862 | mExitingTokens.remove(i); |
| 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | // Time to remove any exiting applications? |
| 3867 | mTaskStackContainers.removeExistingAppTokensIfPossible(); |
| 3868 | } |
| 3869 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3870 | @Override |
| 3871 | void onDescendantOverrideConfigurationChanged() { |
| 3872 | setLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3873 | mWmService.requestTraversal(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3876 | boolean okToDisplay() { |
| 3877 | if (mDisplayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3878 | return !mWmService.mDisplayFrozen |
| 3879 | && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3880 | } |
| 3881 | return mDisplayInfo.state == Display.STATE_ON; |
| 3882 | } |
| 3883 | |
| 3884 | boolean okToAnimate() { |
| 3885 | return okToDisplay() && |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3886 | (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3887 | } |
| 3888 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 3889 | static final class TaskForResizePointSearchResult { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 3890 | private Task taskForResize; |
| 3891 | private int x; |
| 3892 | private int y; |
| 3893 | private int delta; |
| 3894 | private Rect mTmpRect = new Rect(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 3895 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 3896 | Task process(WindowContainer root, int x, int y, int delta) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 3897 | taskForResize = null; |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 3898 | this.x = x; |
| 3899 | this.y = y; |
| 3900 | this.delta = delta; |
| 3901 | mTmpRect.setEmpty(); |
| 3902 | |
| 3903 | final PooledFunction f = PooledLambda.obtainFunction( |
| 3904 | TaskForResizePointSearchResult::processTask, this, PooledLambda.__(Task.class)); |
| 3905 | root.forAllTasks(f); |
| 3906 | f.recycle(); |
| 3907 | |
| 3908 | return taskForResize; |
| 3909 | } |
| 3910 | |
| 3911 | private boolean processTask(Task task) { |
| 3912 | if (!task.getStack().getWindowConfiguration().canResizeTask()) { |
| 3913 | return true; |
| 3914 | } |
| 3915 | |
| 3916 | if (task.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { |
| 3917 | return true; |
| 3918 | } |
| 3919 | |
| 3920 | // We need to use the task's dim bounds (which is derived from the visible bounds of |
| 3921 | // its apps windows) for any touch-related tests. Can't use the task's original |
| 3922 | // bounds because it might be adjusted to fit the content frame. One example is when |
| 3923 | // the task is put to top-left quadrant, the actual visible area would not start at |
| 3924 | // (0,0) after it's adjusted for the status bar. |
| 3925 | task.getDimBounds(mTmpRect); |
| 3926 | mTmpRect.inset(-delta, -delta); |
| 3927 | if (mTmpRect.contains(x, y)) { |
| 3928 | mTmpRect.inset(delta, delta); |
| 3929 | |
| 3930 | if (!mTmpRect.contains(x, y)) { |
| 3931 | taskForResize = task; |
| 3932 | return true; |
| 3933 | } |
| 3934 | // User touched inside the task. No need to look further, |
| 3935 | // focus transfer will be handled in ACTION_UP. |
| 3936 | return true; |
| 3937 | } |
| 3938 | |
| 3939 | return false; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 3940 | } |
| 3941 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3942 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3943 | private static final class ApplySurfaceChangesTransactionState { |
| 3944 | boolean displayHasContent; |
| 3945 | boolean obscured; |
| 3946 | boolean syswin; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3947 | float preferredRefreshRate; |
| 3948 | int preferredModeId; |
| 3949 | |
| 3950 | void reset() { |
| 3951 | displayHasContent = false; |
| 3952 | obscured = false; |
| 3953 | syswin = false; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3954 | preferredRefreshRate = 0; |
| 3955 | preferredModeId = 0; |
| 3956 | } |
| 3957 | } |
| 3958 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3959 | /** |
| 3960 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 3961 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 3962 | * homogeneous children type which is currently required by sub-classes of |
| 3963 | * {@link WindowContainer} class. |
| 3964 | */ |
| 3965 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 3966 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 3967 | DisplayChildWindowContainer(WindowManagerService service) { |
| 3968 | super(service); |
| 3969 | } |
| 3970 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3971 | @Override |
| 3972 | boolean fillsParent() { |
| 3973 | return true; |
| 3974 | } |
| 3975 | |
| 3976 | @Override |
| 3977 | boolean isVisible() { |
| 3978 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3979 | } |
| 3980 | } |
| 3981 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3982 | /** |
| 3983 | * Window container class that contains all containers on this display relating to Apps. |
| 3984 | * I.e Activities. |
| 3985 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3986 | private final class TaskStackContainers extends DisplayChildWindowContainer<ActivityStack> { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3987 | /** |
| 3988 | * A control placed at the appropriate level for transitions to occur. |
| 3989 | */ |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 3990 | SurfaceControl mAppAnimationLayer = null; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 3991 | SurfaceControl mBoostedAppAnimationLayer = null; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 3992 | SurfaceControl mHomeAppAnimationLayer = null; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3993 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 3994 | /** |
| 3995 | * Given that the split-screen divider does not have an AppWindowToken, it |
| 3996 | * will have to live inside of a "NonAppWindowContainer", in particular |
| 3997 | * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order |
| 3998 | * it will need to be interleaved with some of our children, appearing on top of |
| 3999 | * both docked stacks but underneath any assistant stacks. |
| 4000 | * |
| 4001 | * To solve this problem we have this anchor control, which will always exist so |
| 4002 | * we can always assign it the correct value in our {@link #assignChildLayers}. |
| 4003 | * Likewise since it always exists, {@link AboveAppWindowContainers} can always |
| 4004 | * assign the divider a layer relative to it. This way we prevent linking lifecycle |
| 4005 | * events between the two containers. |
| 4006 | */ |
| 4007 | SurfaceControl mSplitScreenDividerAnchor = null; |
| 4008 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4009 | // Cached reference to some special stacks we tend to get a lot so we don't need to loop |
| 4010 | // through the list to find them. |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4011 | private ActivityStack mHomeStack = null; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4012 | private ActivityStack mRecentsStack = null; |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4013 | private ActivityStack mPinnedStack = null; |
| 4014 | private ActivityStack mSplitScreenPrimaryStack = null; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4015 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4016 | TaskStackContainers(WindowManagerService service) { |
| 4017 | super(service); |
| 4018 | } |
| 4019 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4020 | /** |
| 4021 | * Returns the topmost stack on the display that is compatible with the input windowing mode |
| 4022 | * and activity type. Null is no compatible stack on the display. |
| 4023 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4024 | ActivityStack getStack(int windowingMode, int activityType) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4025 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 4026 | return mHomeStack; |
| 4027 | } |
| 4028 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 4029 | return mPinnedStack; |
| 4030 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4031 | return mSplitScreenPrimaryStack; |
| 4032 | } |
| 4033 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4034 | final ActivityStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4035 | if (activityType == ACTIVITY_TYPE_UNDEFINED |
| 4036 | && windowingMode == stack.getWindowingMode()) { |
| 4037 | // Passing in undefined type means we want to match the topmost stack with the |
| 4038 | // windowing mode. |
| 4039 | return stack; |
| 4040 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4041 | if (stack.isCompatible(windowingMode, activityType)) { |
| 4042 | return stack; |
| 4043 | } |
| 4044 | } |
| 4045 | return null; |
| 4046 | } |
| 4047 | |
| 4048 | @VisibleForTesting |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4049 | ActivityStack getTopStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4050 | return mTaskStackContainers.getChildCount() > 0 |
| 4051 | ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null; |
| 4052 | } |
| 4053 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4054 | int getIndexOf(ActivityStack stack) { |
| 4055 | return mTaskStackContainers.mChildren.indexOf(stack); |
| 4056 | } |
| 4057 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4058 | ActivityStack getHomeStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4059 | if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) { |
| 4060 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
| 4061 | } |
| 4062 | return mHomeStack; |
| 4063 | } |
| 4064 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4065 | ActivityStack getRecentsStack() { |
| 4066 | return mRecentsStack; |
| 4067 | } |
| 4068 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4069 | ActivityStack getPinnedStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4070 | return mPinnedStack; |
| 4071 | } |
| 4072 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4073 | ActivityStack getSplitScreenPrimaryStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4074 | return mSplitScreenPrimaryStack; |
| 4075 | } |
| 4076 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 4077 | ArrayList<Task> getVisibleTasks() { |
| 4078 | final ArrayList<Task> visibleTasks = new ArrayList<>(); |
| 4079 | forAllTasks(task -> { |
| 4080 | if (task.isVisible()) { |
| 4081 | visibleTasks.add(task); |
| 4082 | } |
| 4083 | }); |
| 4084 | return visibleTasks; |
| 4085 | } |
| 4086 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4087 | void onStackWindowingModeChanged(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4088 | removeStackReferenceIfNeeded(stack); |
| 4089 | addStackReferenceIfNeeded(stack); |
| 4090 | if (stack == mPinnedStack && getTopStack() != stack) { |
| 4091 | // Looks like this stack changed windowing mode to pinned. Move it to the top. |
| 4092 | positionChildAt(POSITION_TOP, stack, false /* includingParents */); |
| 4093 | } |
| 4094 | } |
| 4095 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4096 | private void addStackReferenceIfNeeded(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4097 | if (stack.isActivityTypeHome()) { |
| 4098 | if (mHomeStack != null) { |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4099 | throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack=" |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4100 | + mHomeStack + " already exist on display=" + this + " stack=" + stack); |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4101 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4102 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4103 | mHomeStack = stack; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4104 | } else if (stack.isActivityTypeRecents()) { |
| 4105 | if (mRecentsStack != null && mRecentsStack != stack) { |
| 4106 | throw new IllegalArgumentException( |
| 4107 | "addStackReferenceIfNeeded: recents stack=" + mRecentsStack |
| 4108 | + " already exist on display=" + this + " stack=" + stack); |
| 4109 | } |
| 4110 | mRecentsStack = stack; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4111 | } |
| 4112 | final int windowingMode = stack.getWindowingMode(); |
| 4113 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 4114 | if (mPinnedStack != null) { |
| 4115 | throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack=" |
| 4116 | + mPinnedStack + " already exist on display=" + this |
| 4117 | + " stack=" + stack); |
| 4118 | } |
| 4119 | mPinnedStack = stack; |
| 4120 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4121 | if (mSplitScreenPrimaryStack != null) { |
| 4122 | throw new IllegalArgumentException("addStackReferenceIfNeeded:" |
| 4123 | + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack |
| 4124 | + " already exist on display=" + this + " stack=" + stack); |
| 4125 | } |
| 4126 | mSplitScreenPrimaryStack = stack; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4127 | // TODO(display-merge): Remove cast |
| 4128 | ((ActivityDisplay) this.mDisplayContent).onSplitScreenModeActivated(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4129 | mDividerControllerLocked.notifyDockedStackExistsChanged(true); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4133 | void removeStackReferenceIfNeeded(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4134 | if (stack == mHomeStack) { |
| 4135 | mHomeStack = null; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4136 | } else if (stack == mRecentsStack) { |
| 4137 | mRecentsStack = null; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4138 | } else if (stack == mPinnedStack) { |
| 4139 | mPinnedStack = null; |
| 4140 | } else if (stack == mSplitScreenPrimaryStack) { |
| 4141 | mSplitScreenPrimaryStack = null; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4142 | // TODO(display-merge): Remove cast |
| 4143 | ((ActivityDisplay) this.mDisplayContent).onSplitScreenModeDismissed(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4144 | // 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] | 4145 | mWmService.setDockedStackCreateStateLocked( |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4146 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 4147 | mDividerControllerLocked.notifyDockedStackExistsChanged(false); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4148 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4151 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4152 | void addChild(ActivityStack stack, int position) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4153 | addStackReferenceIfNeeded(stack); |
| 4154 | position = findPositionForStack(position, stack, true /* adding */); |
| 4155 | |
| 4156 | super.addChild(stack, position); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4157 | |
| 4158 | // The reparenting case is handled in WindowContainer. |
| 4159 | if (!stack.mReparenting) { |
| 4160 | setLayoutNeeded(); |
| 4161 | stack.onDisplayChanged(DisplayContent.this); |
| 4162 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4163 | } |
| 4164 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4165 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4166 | protected void removeChild(ActivityStack stack) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4167 | super.removeChild(stack); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4168 | // TODO(display-merge): Remove cast |
| 4169 | ((ActivityDisplay) this.mDisplayContent).onStackRemoved(stack); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4170 | removeStackReferenceIfNeeded(stack); |
| 4171 | } |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 4172 | |
| 4173 | @Override |
| 4174 | boolean isOnTop() { |
| 4175 | // Considered always on top |
| 4176 | return true; |
| 4177 | } |
| 4178 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4179 | @Override |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4180 | void positionChildAt(int position, ActivityStack child, boolean includingParents) { |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 4181 | if (child.getWindowConfiguration().isAlwaysOnTop() |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4182 | && position != POSITION_TOP && position != mChildren.size()) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4183 | // This stack is always-on-top, override the default behavior. |
| 4184 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom"); |
| 4185 | |
| 4186 | // Moving to its current position, as we must call super but we don't want to |
| 4187 | // perform any meaningful action. |
| 4188 | final int currentPosition = mChildren.indexOf(child); |
| 4189 | super.positionChildAt(currentPosition, child, false /* includingParents */); |
| 4190 | return; |
| 4191 | } |
lumark | d0b5c8f | 2019-09-29 11:30:37 +0800 | [diff] [blame] | 4192 | // We don't allow untrusted display to top when task stack moves to top, |
| 4193 | // until user tapping this display to change display position as top intentionally. |
| 4194 | if (isUntrustedVirtualDisplay() && !getParent().isOnTop()) { |
| 4195 | includingParents = false; |
| 4196 | } |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4197 | final int targetPosition = findPositionForStack(position, child, false /* adding */); |
| 4198 | super.positionChildAt(targetPosition, child, includingParents); |
| 4199 | |
Riddle Hsu | 2f6e174 | 2018-08-23 22:44:36 +0800 | [diff] [blame] | 4200 | if (includingParents) { |
| 4201 | // We still want to move the display of this stack container to top because even the |
| 4202 | // target position is adjusted to non-top, the intention of the condition is to have |
| 4203 | // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front |
| 4204 | // in a non-top display which is using picture-in-picture mode). |
| 4205 | final int topChildPosition = getChildCount() - 1; |
| 4206 | if (targetPosition < topChildPosition && position >= topChildPosition) { |
| 4207 | getParent().positionChildAt(POSITION_TOP, this /* child */, |
| 4208 | true /* includingParents */); |
| 4209 | } |
| 4210 | } |
| 4211 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4212 | setLayoutNeeded(); |
| 4213 | } |
| 4214 | |
| 4215 | /** |
| 4216 | * When stack is added or repositioned, find a proper position for it. |
| 4217 | * This will make sure that pinned stack always stays on top. |
| 4218 | * @param requestedPosition Position requested by caller. |
| 4219 | * @param stack Stack to be added or positioned. |
| 4220 | * @param adding Flag indicates whether we're adding a new stack or positioning an existing. |
| 4221 | * @return The proper position for the stack. |
| 4222 | */ |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4223 | private int findPositionForStack(int requestedPosition, ActivityStack stack, |
| 4224 | boolean adding) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4225 | if (stack.inPinnedWindowingMode()) { |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4226 | return POSITION_TOP; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4227 | } |
| 4228 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4229 | final int topChildPosition = mChildren.size() - 1; |
| 4230 | int belowAlwaysOnTopPosition = POSITION_BOTTOM; |
| 4231 | for (int i = topChildPosition; i >= 0; --i) { |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4232 | // Since a stack could be repositioned while being one of the child, return |
| 4233 | // current index if that's the same stack we are positioning and it is always on |
| 4234 | // top. |
| 4235 | final boolean sameStack = getStacks().get(i) == stack; |
| 4236 | if ((sameStack && stack.isAlwaysOnTop()) |
| 4237 | || (!sameStack && !getStacks().get(i).isAlwaysOnTop())) { |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4238 | belowAlwaysOnTopPosition = i; |
| 4239 | break; |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | // The max possible position we can insert the stack at. |
| 4244 | int maxPosition = POSITION_TOP; |
| 4245 | // The min possible position we can insert the stack at. |
| 4246 | int minPosition = POSITION_BOTTOM; |
| 4247 | |
| 4248 | if (stack.isAlwaysOnTop()) { |
| 4249 | if (hasPinnedStack()) { |
| 4250 | // Always-on-top stacks go below the pinned stack. |
| 4251 | maxPosition = getStacks().indexOf(mPinnedStack) - 1; |
| 4252 | } |
| 4253 | // Always-on-top stacks need to be above all other stacks. |
| 4254 | minPosition = belowAlwaysOnTopPosition != |
| 4255 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition; |
| 4256 | } else { |
| 4257 | // Other stacks need to be below the always-on-top stacks. |
| 4258 | maxPosition = belowAlwaysOnTopPosition != |
Arthur Hung | 928d8dc | 2018-07-18 15:38:05 +0800 | [diff] [blame] | 4259 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0; |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4260 | } |
| 4261 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4262 | // Cap the requested position to something reasonable for the previous position check |
| 4263 | // below. |
| 4264 | if (requestedPosition == POSITION_TOP) { |
| 4265 | requestedPosition = mChildren.size(); |
| 4266 | } else if (requestedPosition == POSITION_BOTTOM) { |
| 4267 | requestedPosition = 0; |
| 4268 | } |
| 4269 | |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 4270 | int targetPosition = requestedPosition; |
| 4271 | targetPosition = Math.min(targetPosition, maxPosition); |
| 4272 | targetPosition = Math.max(targetPosition, minPosition); |
| 4273 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4274 | int prevPosition = getStacks().indexOf(stack); |
| 4275 | // The positions we calculated above (maxPosition, minPosition) do not take into |
| 4276 | // consideration the following edge cases. |
| 4277 | // 1) We need to adjust the position depending on the value "adding". |
| 4278 | // 2) When we are moving a stack to another position, we also need to adjust the |
| 4279 | // position depending on whether the stack is moving to a higher or lower position. |
| 4280 | if ((targetPosition != requestedPosition) && |
| 4281 | (adding || targetPosition < prevPosition)) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4282 | targetPosition++; |
| 4283 | } |
| 4284 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4285 | return targetPosition; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4289 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 4290 | boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4291 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4292 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4293 | return true; |
| 4294 | } |
| 4295 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4296 | return true; |
| 4297 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4298 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4299 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4300 | return true; |
| 4301 | } |
| 4302 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4303 | return true; |
| 4304 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4305 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4306 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4307 | } |
| 4308 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4309 | private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback, |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4310 | boolean traverseTopToBottom) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4311 | // For legacy reasons we process the TaskStack.mExitingActivities first here before the |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4312 | // app tokens. |
| 4313 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 4314 | // in-order. |
| 4315 | if (traverseTopToBottom) { |
| 4316 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4317 | final List<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4318 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4319 | if (activities.get(j).forAllWindowsUnchecked(callback, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4320 | traverseTopToBottom)) { |
| 4321 | return true; |
| 4322 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | } else { |
| 4326 | final int count = mChildren.size(); |
| 4327 | for (int i = 0; i < count; ++i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4328 | final List<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4329 | final int appTokensCount = activities.size(); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4330 | for (int j = 0; j < appTokensCount; j++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4331 | if (activities.get(j).forAllWindowsUnchecked(callback, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4332 | traverseTopToBottom)) { |
| 4333 | return true; |
| 4334 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4335 | } |
| 4336 | } |
| 4337 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4338 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4341 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 4342 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4343 | final ArrayList<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4344 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4345 | activities.get(j).hasVisible = hasVisible; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4346 | } |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | void removeExistingAppTokensIfPossible() { |
| 4351 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4352 | final ArrayList<ActivityRecord> activities = mChildren.get(i).mExitingActivities; |
| 4353 | for (int j = activities.size() - 1; j >= 0; --j) { |
| 4354 | final ActivityRecord activity = activities.get(j); |
| 4355 | if (!activity.hasVisible && !mClosingApps.contains(activity) |
| 4356 | && (!activity.mIsExiting || activity.isEmpty())) { |
| 4357 | // 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] | 4358 | // associated with it will be removed as soon as their animations are |
| 4359 | // complete. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 4360 | cancelAnimation(); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4361 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4362 | "performLayout: Activity exiting now removed %s", activity); |
| 4363 | activity.removeIfPossible(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4364 | } |
| 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4369 | @Override |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4370 | int getOrientation() { |
Garfield Tan | 98eead3 | 2019-11-18 13:24:53 -0800 | [diff] [blame] | 4371 | if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4372 | // 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] | 4373 | // docked stack is visible...except for the home stack if the docked stack is |
| 4374 | // minimized and it actually set something and the bounds is different from the |
| 4375 | // display. |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4376 | if (mHomeStack != null && mHomeStack.isVisible() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4377 | && mDividerControllerLocked.isMinimizedDock() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4378 | && !(mDividerControllerLocked.isHomeStackResizable() |
| 4379 | && mHomeStack.matchParentBounds())) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4380 | final int orientation = mHomeStack.getOrientation(); |
| 4381 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 4382 | return orientation; |
| 4383 | } |
| 4384 | } |
| 4385 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 4386 | } |
| 4387 | |
| 4388 | final int orientation = super.getOrientation(); |
| 4389 | if (orientation != SCREEN_ORIENTATION_UNSET |
| 4390 | && orientation != SCREEN_ORIENTATION_BEHIND) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4391 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 4392 | "App is requesting an orientation, return %d for display id=%d", |
| 4393 | orientation, mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4394 | return orientation; |
| 4395 | } |
| 4396 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4397 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 4398 | "No app is requesting an orientation, return %d for display id=%d", |
| 4399 | getLastOrientation(), mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4400 | // The next app has not been requested to be visible, so we keep the current orientation |
| 4401 | // to prevent freezing/unfreezing the display too early. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 4402 | return getLastOrientation(); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4403 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4404 | |
| 4405 | @Override |
| 4406 | void assignChildLayers(SurfaceControl.Transaction t) { |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4407 | assignStackOrdering(t); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4408 | |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4409 | for (int i = 0; i < mChildren.size(); i++) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4410 | final ActivityStack s = mChildren.get(i); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4411 | s.assignChildLayers(t); |
| 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | void assignStackOrdering(SurfaceControl.Transaction t) { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4416 | if (getParent() == null) { |
| 4417 | return; |
| 4418 | } |
| 4419 | mTmpAlwaysOnTopStacks.clear(); |
| 4420 | mTmpHomeStacks.clear(); |
| 4421 | mTmpNormalStacks.clear(); |
| 4422 | for (int i = 0; i < mChildren.size(); ++i) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4423 | final ActivityStack s = mChildren.get(i); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4424 | if (s.isAlwaysOnTop()) { |
| 4425 | mTmpAlwaysOnTopStacks.add(s); |
| 4426 | } else if (s.isActivityTypeHome()) { |
| 4427 | mTmpHomeStacks.add(s); |
| 4428 | } else { |
| 4429 | mTmpNormalStacks.add(s); |
| 4430 | } |
| 4431 | } |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4432 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4433 | int layer = 0; |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4434 | // Place home stacks to the bottom. |
| 4435 | for (int i = 0; i < mTmpHomeStacks.size(); i++) { |
| 4436 | mTmpHomeStacks.get(i).assignLayer(t, layer++); |
| 4437 | } |
| 4438 | // The home animation layer is between the home stacks and the normal stacks. |
| 4439 | final int layerForHomeAnimationLayer = layer++; |
| 4440 | int layerForSplitScreenDividerAnchor = layer++; |
| 4441 | int layerForAnimationLayer = layer++; |
| 4442 | for (int i = 0; i < mTmpNormalStacks.size(); i++) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 4443 | final ActivityStack s = mTmpNormalStacks.get(i); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4444 | s.assignLayer(t, layer++); |
| 4445 | if (s.inSplitScreenWindowingMode()) { |
| 4446 | // The split screen divider anchor is located above the split screen window. |
| 4447 | layerForSplitScreenDividerAnchor = layer++; |
| 4448 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4449 | if (s.isTaskAnimating() || s.isAppTransitioning()) { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4450 | // The animation layer is located above the highest animating stack and no |
| 4451 | // higher. |
| 4452 | layerForAnimationLayer = layer++; |
| 4453 | } |
| 4454 | } |
| 4455 | // The boosted animation layer is between the normal stacks and the always on top |
| 4456 | // stacks. |
| 4457 | final int layerForBoostedAnimationLayer = layer++; |
| 4458 | for (int i = 0; i < mTmpAlwaysOnTopStacks.size(); i++) { |
| 4459 | mTmpAlwaysOnTopStacks.get(i).assignLayer(t, layer++); |
| 4460 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4461 | |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4462 | t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer); |
| 4463 | t.setLayer(mAppAnimationLayer, layerForAnimationLayer); |
| 4464 | t.setLayer(mSplitScreenDividerAnchor, layerForSplitScreenDividerAnchor); |
| 4465 | t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | @Override |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4469 | SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) { |
| 4470 | switch (animationLayer) { |
| 4471 | case ANIMATION_LAYER_BOOSTED: |
| 4472 | return mBoostedAppAnimationLayer; |
| 4473 | case ANIMATION_LAYER_HOME: |
| 4474 | return mHomeAppAnimationLayer; |
| 4475 | case ANIMATION_LAYER_STANDARD: |
| 4476 | default: |
| 4477 | return mAppAnimationLayer; |
| 4478 | } |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4479 | } |
| 4480 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4481 | SurfaceControl getSplitScreenDividerAnchor() { |
| 4482 | return mSplitScreenDividerAnchor; |
| 4483 | } |
| 4484 | |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4485 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4486 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4487 | if (getParent() != null) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4488 | super.onParentChanged(newParent, oldParent, () -> { |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 4489 | mAppAnimationLayer = makeChildSurface(null) |
| 4490 | .setName("animationLayer") |
| 4491 | .build(); |
| 4492 | mBoostedAppAnimationLayer = makeChildSurface(null) |
| 4493 | .setName("boostedAnimationLayer") |
| 4494 | .build(); |
| 4495 | mHomeAppAnimationLayer = makeChildSurface(null) |
| 4496 | .setName("homeAnimationLayer") |
| 4497 | .build(); |
| 4498 | mSplitScreenDividerAnchor = makeChildSurface(null) |
| 4499 | .setName("splitScreenDividerAnchor") |
| 4500 | .build(); |
| 4501 | getPendingTransaction() |
| 4502 | .show(mAppAnimationLayer) |
| 4503 | .show(mBoostedAppAnimationLayer) |
| 4504 | .show(mHomeAppAnimationLayer) |
| 4505 | .show(mSplitScreenDividerAnchor); |
| 4506 | }); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4507 | } else { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4508 | super.onParentChanged(newParent, oldParent); |
Vishnu Nair | 3319739 | 2019-08-30 10:29:37 -0700 | [diff] [blame] | 4509 | mWmService.mTransactionFactory.get() |
chaviw | 9f6171e | 2019-06-07 16:33:50 -0700 | [diff] [blame] | 4510 | .remove(mAppAnimationLayer) |
| 4511 | .remove(mBoostedAppAnimationLayer) |
| 4512 | .remove(mHomeAppAnimationLayer) |
| 4513 | .remove(mSplitScreenDividerAnchor) |
| 4514 | .apply(); |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4515 | mAppAnimationLayer = null; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4516 | mBoostedAppAnimationLayer = null; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4517 | mHomeAppAnimationLayer = null; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4518 | mSplitScreenDividerAnchor = null; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4519 | } |
| 4520 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4523 | private final class AboveAppWindowContainers extends NonAppWindowContainers { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4524 | AboveAppWindowContainers(String name, WindowManagerService service) { |
| 4525 | super(name, service); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4526 | } |
| 4527 | |
Robert Carr | b950603 | 2018-02-13 13:54:00 -0800 | [diff] [blame] | 4528 | @Override |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 4529 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
| 4530 | final SurfaceControl.Builder builder = super.makeChildSurface(child); |
| 4531 | if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) { |
| 4532 | // To draw above the ColorFade layer during the screen off transition, the |
| 4533 | // rounded corner overlays need to be at the root of the surface hierarchy. |
| 4534 | // TODO: move the ColorLayer into the display overlay layer such that this is not |
| 4535 | // necessary anymore. |
| 4536 | builder.setParent(null); |
| 4537 | } |
| 4538 | return builder; |
| 4539 | } |
| 4540 | |
| 4541 | @Override |
Robert Carr | b950603 | 2018-02-13 13:54:00 -0800 | [diff] [blame] | 4542 | void assignChildLayers(SurfaceControl.Transaction t) { |
| 4543 | assignChildLayers(t, null /* imeContainer */); |
| 4544 | } |
| 4545 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4546 | void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) { |
| 4547 | boolean needAssignIme = imeContainer != null |
| 4548 | && imeContainer.getSurfaceControl() != null; |
| 4549 | for (int j = 0; j < mChildren.size(); ++j) { |
| 4550 | final WindowToken wt = mChildren.get(j); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4551 | |
| 4552 | // See {@link mSplitScreenDividerAnchor} |
| 4553 | if (wt.windowType == TYPE_DOCK_DIVIDER) { |
| 4554 | wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1); |
| 4555 | continue; |
| 4556 | } |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 4557 | if (wt.mRoundedCornerOverlay) { |
| 4558 | wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1); |
| 4559 | continue; |
| 4560 | } |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4561 | wt.assignLayer(t, j); |
| 4562 | wt.assignChildLayers(t); |
| 4563 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4564 | int layer = mWmService.mPolicy.getWindowLayerFromTypeLw( |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4565 | wt.windowType, wt.mOwnerCanManageAppTokens); |
Robert Carr | b8e78fa | 2017-11-28 13:07:58 -0800 | [diff] [blame] | 4566 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4567 | if (needAssignIme && layer >= mWmService.mPolicy.getWindowLayerFromTypeLw( |
Robert Carr | b8e78fa | 2017-11-28 13:07:58 -0800 | [diff] [blame] | 4568 | TYPE_INPUT_METHOD_DIALOG, true)) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4569 | imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4570 | needAssignIme = false; |
| 4571 | } |
| 4572 | } |
| 4573 | if (needAssignIme) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4574 | imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4575 | } |
| 4576 | } |
| 4577 | } |
| 4578 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4579 | /** |
| 4580 | * Window container class that contains all containers on this display that are not related to |
| 4581 | * Apps. E.g. status bar. |
| 4582 | */ |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4583 | private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4584 | /** |
| 4585 | * Compares two child window tokens returns -1 if the first is lesser than the second in |
| 4586 | * terms of z-order and 1 otherwise. |
| 4587 | */ |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4588 | private final Comparator<WindowToken> mWindowComparator = (token1, token2) -> |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4589 | // Tokens with higher base layer are z-ordered on-top. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4590 | mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4591 | token1.mOwnerCanManageAppTokens) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4592 | < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4593 | token2.mOwnerCanManageAppTokens) ? -1 : 1; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4594 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4595 | private final Predicate<WindowState> mGetOrientingWindow = w -> { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 4596 | if (!w.isVisibleLw() || !w.mLegacyPolicyVisibilityAfterAnim) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4597 | return false; |
| 4598 | } |
| 4599 | final int req = w.mAttrs.screenOrientation; |
| 4600 | if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND |
| 4601 | || req == SCREEN_ORIENTATION_UNSET) { |
| 4602 | return false; |
| 4603 | } |
| 4604 | return true; |
| 4605 | }; |
| 4606 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4607 | private final String mName; |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4608 | private final Dimmer mDimmer = new Dimmer(this); |
| 4609 | private final Rect mTmpDimBoundsRect = new Rect(); |
| 4610 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4611 | NonAppWindowContainers(String name, WindowManagerService service) { |
| 4612 | super(service); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4613 | mName = name; |
| 4614 | } |
| 4615 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 4616 | @Override |
| 4617 | boolean hasActivity() { |
| 4618 | // I am a non-app-window-container :P |
| 4619 | return false; |
| 4620 | } |
| 4621 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4622 | void addChild(WindowToken token) { |
| 4623 | addChild(token, mWindowComparator); |
| 4624 | } |
| 4625 | |
| 4626 | @Override |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4627 | int getOrientation() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4628 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4629 | // Find a window requesting orientation. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4630 | final WindowState win = getWindow(mGetOrientingWindow); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4631 | |
| 4632 | if (win != null) { |
| 4633 | final int req = win.mAttrs.screenOrientation; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4634 | if (policy.isKeyguardHostWindow(win.mAttrs)) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4635 | mLastKeyguardForcedOrientation = req; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4636 | if (mWmService.mKeyguardGoingAway) { |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 4637 | // Keyguard can't affect the orientation if it is going away... |
| 4638 | mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 4639 | return SCREEN_ORIENTATION_UNSET; |
| 4640 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4641 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4642 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 4643 | "%s forcing orientation to %d for display id=%d", win, req, |
| 4644 | mDisplayId); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4645 | return (mLastWindowForcedOrientation = req); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4648 | mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4649 | |
Jorim Jaggi | 1c53059 | 2018-04-06 15:11:47 +0200 | [diff] [blame] | 4650 | // Only allow force setting the orientation when all unknown visibilities have been |
| 4651 | // resolved, as otherwise we just may be starting another occluding activity. |
| 4652 | final boolean isUnoccluding = |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4653 | mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE |
| 4654 | && mUnknownAppVisibilityController.allResolved(); |
Jorim Jaggi | 1c53059 | 2018-04-06 15:11:47 +0200 | [diff] [blame] | 4655 | if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4656 | return mLastKeyguardForcedOrientation; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | return SCREEN_ORIENTATION_UNSET; |
| 4660 | } |
| 4661 | |
| 4662 | @Override |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4663 | String getName() { |
| 4664 | return mName; |
| 4665 | } |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4666 | |
| 4667 | @Override |
| 4668 | Dimmer getDimmer() { |
| 4669 | return mDimmer; |
| 4670 | } |
| 4671 | |
| 4672 | @Override |
| 4673 | void prepareSurfaces() { |
| 4674 | mDimmer.resetDimStates(); |
| 4675 | super.prepareSurfaces(); |
| 4676 | getBounds(mTmpDimBoundsRect); |
| 4677 | |
| 4678 | if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) { |
| 4679 | scheduleAnimation(); |
| 4680 | } |
| 4681 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4682 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 4683 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4684 | SurfaceControl.Builder makeSurface(SurfaceSession s) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4685 | return mWmService.makeSurfaceBuilder(s) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4686 | .setParent(mWindowingLayer); |
| 4687 | } |
| 4688 | |
| 4689 | @Override |
| 4690 | SurfaceSession getSession() { |
| 4691 | return mSession; |
| 4692 | } |
| 4693 | |
| 4694 | @Override |
| 4695 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4696 | SurfaceSession s = child != null ? child.getSession() : getSession(); |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 4697 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s).setContainerLayer(); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4698 | if (child == null) { |
| 4699 | return b; |
| 4700 | } |
| 4701 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4702 | return b.setName(child.getName()) |
| 4703 | .setParent(mWindowingLayer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | /** |
| 4707 | * The makeSurface variants are for use by the window-container |
| 4708 | * hierarchy. makeOverlay here is a function for various non windowing |
| 4709 | * overlays like the ScreenRotation screenshot, the Strict Mode Flash |
| 4710 | * and other potpourii. |
| 4711 | */ |
| 4712 | SurfaceControl.Builder makeOverlay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4713 | return mWmService.makeSurfaceBuilder(mSession) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4714 | .setParent(mOverlayLayer); |
| 4715 | } |
| 4716 | |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4717 | /** |
| 4718 | * Reparents the given surface to mOverlayLayer. |
| 4719 | */ |
| 4720 | void reparentToOverlay(Transaction transaction, SurfaceControl surface) { |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 4721 | transaction.reparent(surface, mOverlayLayer); |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4722 | } |
| 4723 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4724 | void applyMagnificationSpec(MagnificationSpec spec) { |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4725 | if (spec.scale != 1.0) { |
| 4726 | mMagnificationSpec = spec; |
| 4727 | } else { |
| 4728 | mMagnificationSpec = null; |
| 4729 | } |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 4730 | // Re-parent IME's SurfaceControl when MagnificationSpec changed. |
| 4731 | updateImeParent(); |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4732 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4733 | applyMagnificationSpec(getPendingTransaction(), spec); |
| 4734 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4737 | void reapplyMagnificationSpec() { |
| 4738 | if (mMagnificationSpec != null) { |
| 4739 | applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec); |
| 4740 | } |
| 4741 | } |
| 4742 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4743 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 4744 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4745 | // Since we are the top of the SurfaceControl hierarchy here |
| 4746 | // we create the root surfaces explicitly rather than chaining |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 4747 | // up as the default implementation in onParentChanged does. So we |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4748 | // explicitly do NOT call super here. |
| 4749 | } |
| 4750 | |
| 4751 | @Override |
| 4752 | void assignChildLayers(SurfaceControl.Transaction t) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4753 | |
| 4754 | // These are layers as children of "mWindowingLayer" |
| 4755 | mBelowAppWindowsContainers.assignLayer(t, 0); |
| 4756 | mTaskStackContainers.assignLayer(t, 1); |
| 4757 | mAboveAppWindowsContainers.assignLayer(t, 2); |
| 4758 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 4759 | final WindowState imeTarget = mInputMethodTarget; |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4760 | boolean needAssignIme = true; |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4761 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4762 | // In the case where we have an IME target that is not in split-screen |
| 4763 | // mode IME assignment is easy. We just need the IME to go directly above |
| 4764 | // the target. This way children of the target will naturally go above the IME |
| 4765 | // and everyone is happy. |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4766 | // |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4767 | // In the case of split-screen windowing mode, we need to elevate the IME above the |
| 4768 | // docked divider while keeping the app itself below the docked divider, so instead |
| 4769 | // we use relative layering of the IME targets child windows, and place the |
| 4770 | // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}). |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4771 | // |
Robert Carr | 234b633 | 2018-03-20 13:38:16 -0700 | [diff] [blame] | 4772 | // In the case the IME target is animating, the animation Z order may be different |
| 4773 | // than the WindowContainer Z order, so it's difficult to be sure we have the correct |
| 4774 | // IME target. In this case we just layer the IME over all transitions by placing it in the |
| 4775 | // above applications layer. |
| 4776 | // |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4777 | // In the case where we have no IME target we assign it where it's base layer would |
| 4778 | // place it in the AboveAppWindowContainers. |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 4779 | // |
| 4780 | // Keep IME window in mAboveAppWindowsContainers as long as app's starting window exists |
| 4781 | // so it get's layered above the starting window. |
| 4782 | if (imeTarget != null |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4783 | && !(imeTarget.mActivityRecord != null && imeTarget.mActivityRecord.hasStartingWindow()) |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4784 | && (!(imeTarget.inSplitScreenWindowingMode() |
| 4785 | || imeTarget.mToken.isAppTransitioning()) |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 4786 | && (imeTarget.getSurfaceControl() != null))) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4787 | mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(), |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4788 | // TODO: We need to use an extra level on the app surface to ensure |
| 4789 | // this is always above SurfaceView but always below attached window. |
| 4790 | 1); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4791 | needAssignIme = false; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | // Above we have assigned layers to our children, now we ask them to assign |
| 4795 | // layers to their children. |
| 4796 | mBelowAppWindowsContainers.assignChildLayers(t); |
| 4797 | mTaskStackContainers.assignChildLayers(t); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4798 | mAboveAppWindowsContainers.assignChildLayers(t, |
| 4799 | needAssignIme == true ? mImeWindowsContainers : null); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4800 | mImeWindowsContainers.assignChildLayers(t); |
| 4801 | } |
| 4802 | |
| 4803 | /** |
| 4804 | * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine |
| 4805 | * that the IME target is one of the docked applications. We'd like the docked divider to be |
| 4806 | * above both of the applications, and we'd like the IME to be above the docked divider. |
| 4807 | * However we need child windows of the applications to be above the IME (Text drag handles). |
| 4808 | * This is a non-strictly hierarcical layering and we need to break out of the Z ordering |
| 4809 | * 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] | 4810 | * with {@link WindowState#assignLayer} |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4811 | */ |
| 4812 | void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) { |
Robert Carr | bb5de66 | 2018-04-26 13:29:51 -0700 | [diff] [blame] | 4813 | child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | @Override |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4817 | void prepareSurfaces() { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4818 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareSurfaces"); |
| 4819 | try { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4820 | final Transaction transaction = getPendingTransaction(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4821 | super.prepareSurfaces(); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4822 | |
| 4823 | // TODO: Once we totally eliminate global transaction we will pass transaction in here |
| 4824 | // rather than merging to global. |
| 4825 | SurfaceControl.mergeToGlobalTransaction(transaction); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4826 | } finally { |
| 4827 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 4828 | } |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4829 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4830 | |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4831 | void assignStackOrdering() { |
| 4832 | mTaskStackContainers.assignStackOrdering(getPendingTransaction()); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4833 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4834 | |
| 4835 | /** |
| 4836 | * Increment the deferral count to determine whether to update the IME target. |
| 4837 | */ |
| 4838 | void deferUpdateImeTarget() { |
| 4839 | mDeferUpdateImeTargetCount++; |
| 4840 | } |
| 4841 | |
| 4842 | /** |
| 4843 | * Decrement the deferral count to determine whether to update the IME target. If the count |
| 4844 | * reaches 0, a new ime target will get computed. |
| 4845 | */ |
| 4846 | void continueUpdateImeTarget() { |
| 4847 | if (mDeferUpdateImeTargetCount == 0) { |
| 4848 | return; |
| 4849 | } |
| 4850 | |
| 4851 | mDeferUpdateImeTargetCount--; |
| 4852 | if (mDeferUpdateImeTargetCount == 0) { |
| 4853 | computeImeTarget(true /* updateImeTarget */); |
| 4854 | } |
| 4855 | } |
| 4856 | |
| 4857 | /** |
| 4858 | * @return Whether a new IME target should be computed. |
| 4859 | */ |
| 4860 | private boolean canUpdateImeTarget() { |
| 4861 | return mDeferUpdateImeTargetCount == 0; |
| 4862 | } |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 4863 | |
| 4864 | InputMonitor getInputMonitor() { |
| 4865 | return mInputMonitor; |
| 4866 | } |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 4867 | |
| 4868 | /** |
| 4869 | * @return Cached value whether we told display manager that we have content. |
| 4870 | */ |
| 4871 | boolean getLastHasContent() { |
| 4872 | return mLastHasContent; |
| 4873 | } |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4874 | |
| 4875 | void registerPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4876 | mPointerEventDispatcher.registerInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | void unregisterPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4880 | mPointerEventDispatcher.unregisterInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4881 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4882 | |
| 4883 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4884 | boolean alwaysKeepCurrent) { |
| 4885 | prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */); |
| 4886 | } |
| 4887 | |
| 4888 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4889 | boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags, |
| 4890 | boolean forceOverride) { |
| 4891 | final boolean prepared = mAppTransition.prepareAppTransitionLocked( |
| 4892 | transit, alwaysKeepCurrent, flags, forceOverride); |
| 4893 | if (prepared && okToAnimate()) { |
| 4894 | mSkipAppTransitionAnimation = false; |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | void executeAppTransition() { |
| 4899 | if (mAppTransition.isTransitionSet()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4900 | ProtoLog.w(WM_DEBUG_APP_TRANSITIONS, |
| 4901 | "Execute app transition: %s, displayId: %d Callers=%s", |
| 4902 | mAppTransition, mDisplayId, Debug.getCallers(5)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4903 | mAppTransition.setReady(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4904 | mWmService.mWindowPlacerLocked.requestTraversal(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | |
| 4908 | /** |
| 4909 | * Update pendingLayoutChanges after app transition has finished. |
| 4910 | */ |
| 4911 | void handleAnimatingStoppedAndTransition() { |
| 4912 | int changes = 0; |
| 4913 | |
| 4914 | mAppTransition.setIdle(); |
| 4915 | |
| 4916 | for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) { |
| 4917 | final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i); |
| 4918 | mAppTransition.notifyAppTransitionFinishedLocked(token); |
| 4919 | } |
| 4920 | mNoAnimationNotifyOnTransitionFinished.clear(); |
| 4921 | |
| 4922 | mWallpaperController.hideDeferredWallpapersIfNeeded(); |
| 4923 | |
| 4924 | onAppTransitionDone(); |
| 4925 | |
| 4926 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4927 | if (DEBUG_WALLPAPER_LIGHT) { |
| 4928 | Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout"); |
| 4929 | } |
| 4930 | computeImeTarget(true /* updateImeTarget */); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 4931 | mWallpaperMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4932 | // Since the window list has been rebuilt, focus might have to be recomputed since the |
| 4933 | // actual order of windows might have changed again. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4934 | mWmService.mFocusMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4935 | |
| 4936 | pendingLayoutChanges |= changes; |
| 4937 | } |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4938 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4939 | /** Check if pending app transition is for activity / task launch. */ |
| 4940 | boolean isNextTransitionForward() { |
| 4941 | final int transit = mAppTransition.getAppTransition(); |
| 4942 | return transit == TRANSIT_ACTIVITY_OPEN |
| 4943 | || transit == TRANSIT_TASK_OPEN |
| 4944 | || transit == TRANSIT_TASK_TO_FRONT; |
| 4945 | } |
| 4946 | |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4947 | /** |
| 4948 | * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS |
| 4949 | */ |
| 4950 | boolean supportsSystemDecorations() { |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 4951 | return (mWmService.mDisplayWindowSettings.shouldShowSystemDecorsLocked(this) |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 4952 | || (mDisplay.getFlags() & FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0 |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 4953 | || (mWmService.mForceDesktopModeOnExternalDisplays && !isUntrustedVirtualDisplay())) |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 4954 | // VR virtual display will be used to run and render 2D app within a VR experience. |
| 4955 | && mDisplayId != mWmService.mVr2dDisplayId; |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 4956 | } |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4957 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4958 | /** |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 4959 | * @return {@code true} if the display is non-system created virtual display. |
| 4960 | */ |
| 4961 | boolean isUntrustedVirtualDisplay() { |
| 4962 | return mDisplay.getType() == Display.TYPE_VIRTUAL |
| 4963 | && mDisplay.getOwnerUid() != Process.SYSTEM_UID; |
| 4964 | } |
| 4965 | |
| 4966 | /** |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4967 | * Re-parent the DisplayContent's top surfaces, {@link #mWindowingLayer} and |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4968 | * {@link #mOverlayLayer} to the specified SurfaceControl. |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 4969 | * |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4970 | * @param win The window which owns the SurfaceControl. This indicates the z-order of the |
| 4971 | * windows of this display against the windows on the parent display. |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4972 | * @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] | 4973 | */ |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4974 | void reparentDisplayContent(WindowState win, SurfaceControl sc) { |
| 4975 | mParentWindow = win; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4976 | mParentWindow.addEmbeddedDisplayContent(this); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4977 | mParentSurfaceControl = sc; |
| 4978 | if (mPortalWindowHandle == null) { |
| 4979 | mPortalWindowHandle = createPortalWindowHandle(sc.toString()); |
| 4980 | } |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4981 | getPendingTransaction().setInputWindowInfo(sc, mPortalWindowHandle) |
Vadim Caen | 1812c76 | 2019-08-12 11:38:22 +0200 | [diff] [blame] | 4982 | .reparent(mSurfaceControl, sc); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4983 | } |
| 4984 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4985 | /** |
| 4986 | * Get the window which owns the surface that this DisplayContent is re-parented to. |
| 4987 | * |
| 4988 | * @return the parent window. |
| 4989 | */ |
| 4990 | WindowState getParentWindow() { |
| 4991 | return mParentWindow; |
| 4992 | } |
| 4993 | |
| 4994 | /** |
| 4995 | * Update the location of this display in the parent window. This enables windows in this |
| 4996 | * display to compute the global transformation matrix. |
| 4997 | * |
| 4998 | * @param win The parent window of this display. |
| 4999 | * @param x The x coordinate in the parent window. |
| 5000 | * @param y The y coordinate in the parent window. |
| 5001 | */ |
| 5002 | void updateLocation(WindowState win, int x, int y) { |
| 5003 | if (mParentWindow != win) { |
| 5004 | throw new IllegalArgumentException( |
| 5005 | "The given window is not the parent window of this display."); |
| 5006 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5007 | if (!mLocationInParentWindow.equals(x, y)) { |
| 5008 | mLocationInParentWindow.set(x, y); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5009 | if (mWmService.mAccessibilityController != null) { |
Jacky Kao | f93252b | 2019-07-18 15:19:52 +0800 | [diff] [blame] | 5010 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(mDisplayId); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5011 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5012 | notifyLocationInParentDisplayChanged(); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | |
| 5016 | Point getLocationInParentWindow() { |
| 5017 | return mLocationInParentWindow; |
| 5018 | } |
| 5019 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5020 | Point getLocationInParentDisplay() { |
| 5021 | final Point location = new Point(); |
| 5022 | if (mParentWindow != null) { |
| 5023 | // LocationInParentWindow indicates the offset to (0,0) of window, but what we need is |
| 5024 | // the offset to (0,0) of display. |
| 5025 | DisplayContent dc = this; |
| 5026 | do { |
| 5027 | final WindowState displayParent = dc.getParentWindow(); |
| 5028 | location.x += displayParent.getFrameLw().left |
| 5029 | + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f); |
| 5030 | location.y += displayParent.getFrameLw().top |
| 5031 | + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f); |
| 5032 | dc = displayParent.getDisplayContent(); |
| 5033 | } while (dc != null && dc.getParentWindow() != null); |
| 5034 | } |
| 5035 | return location; |
| 5036 | } |
| 5037 | |
| 5038 | void notifyLocationInParentDisplayChanged() { |
| 5039 | forAllWindows(w -> { |
| 5040 | w.updateLocationInParentDisplayIfNeeded(); |
| 5041 | }, false /* traverseTopToBottom */); |
| 5042 | } |
| 5043 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 5044 | @VisibleForTesting |
| 5045 | SurfaceControl getWindowingLayer() { |
| 5046 | return mWindowingLayer; |
| 5047 | } |
| 5048 | |
Vadim Caen | f847426 | 2019-08-12 17:52:01 +0200 | [diff] [blame] | 5049 | SurfaceControl getOverlayLayer() { |
| 5050 | return mOverlayLayer; |
| 5051 | } |
| 5052 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5053 | /** |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5054 | * Updates the display's system gesture exclusion. |
| 5055 | * |
| 5056 | * @return true, if the exclusion changed. |
| 5057 | */ |
| 5058 | boolean updateSystemGestureExclusion() { |
| 5059 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 0) { |
| 5060 | // No one's interested anyways. |
| 5061 | return false; |
| 5062 | } |
| 5063 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5064 | final Region systemGestureExclusion = Region.obtain(); |
| 5065 | mSystemGestureExclusionWasRestricted = calculateSystemGestureExclusion( |
| 5066 | systemGestureExclusion, mSystemGestureExclusionUnrestricted); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5067 | try { |
| 5068 | if (mSystemGestureExclusion.equals(systemGestureExclusion)) { |
| 5069 | return false; |
| 5070 | } |
| 5071 | mSystemGestureExclusion.set(systemGestureExclusion); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5072 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5073 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5074 | for (int i = mSystemGestureExclusionListeners.beginBroadcast() - 1; i >= 0; --i) { |
| 5075 | try { |
| 5076 | mSystemGestureExclusionListeners.getBroadcastItem(i) |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5077 | .onSystemGestureExclusionChanged(mDisplayId, systemGestureExclusion, |
| 5078 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5079 | } catch (RemoteException e) { |
| 5080 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener", e); |
| 5081 | } |
| 5082 | } |
| 5083 | mSystemGestureExclusionListeners.finishBroadcast(); |
| 5084 | return true; |
| 5085 | } finally { |
| 5086 | systemGestureExclusion.recycle(); |
| 5087 | } |
| 5088 | } |
| 5089 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5090 | /** |
| 5091 | * Calculates the system gesture exclusion. |
| 5092 | * |
| 5093 | * @param outExclusion will be set to the gesture exclusion region |
| 5094 | * @param outExclusionUnrestricted will be set to the gesture exclusion region without |
| 5095 | * any restrictions applied. |
| 5096 | * @return whether any restrictions were applied, i.e. outExclusion and outExclusionUnrestricted |
| 5097 | * differ. |
| 5098 | */ |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5099 | @VisibleForTesting |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5100 | boolean calculateSystemGestureExclusion(Region outExclusion, @Nullable |
| 5101 | Region outExclusionUnrestricted) { |
| 5102 | outExclusion.setEmpty(); |
| 5103 | if (outExclusionUnrestricted != null) { |
| 5104 | outExclusionUnrestricted.setEmpty(); |
| 5105 | } |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5106 | final Region unhandled = Region.obtain(); |
| 5107 | unhandled.set(0, 0, mDisplayFrames.mDisplayWidth, mDisplayFrames.mDisplayHeight); |
| 5108 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 5109 | final Rect leftEdge = mInsetsStateController.getSourceProvider(ITYPE_LEFT_GESTURES) |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5110 | .getSource().getFrame(); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 5111 | final Rect rightEdge = mInsetsStateController.getSourceProvider(ITYPE_RIGHT_GESTURES) |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5112 | .getSource().getFrame(); |
| 5113 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5114 | final Region touchableRegion = Region.obtain(); |
| 5115 | final Region local = Region.obtain(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5116 | final int[] remainingLeftRight = |
| 5117 | {mSystemGestureExclusionLimit, mSystemGestureExclusionLimit}; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5118 | |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5119 | // Traverse all windows top down to assemble the gesture exclusion rects. |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5120 | // For each window, we only take the rects that fall within its touchable region. |
| 5121 | forAllWindows(w -> { |
| 5122 | if (w.cantReceiveTouchInput() || !w.isVisible() |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5123 | || (w.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 |
| 5124 | || unhandled.isEmpty()) { |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5125 | return; |
| 5126 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5127 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5128 | // Get the touchable region of the window, and intersect with where the screen is still |
| 5129 | // touchable, i.e. touchable regions on top are not covering it yet. |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5130 | w.getEffectiveTouchableRegion(touchableRegion); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5131 | touchableRegion.op(unhandled, Op.INTERSECT); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5132 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5133 | if (w.isImplicitlyExcludingAllSystemGestures()) { |
| 5134 | local.set(touchableRegion); |
| 5135 | } else { |
| 5136 | rectListToRegion(w.getSystemGestureExclusion(), local); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5137 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5138 | // Transform to display coordinates |
| 5139 | local.scale(w.mGlobalScale); |
| 5140 | final Rect frame = w.getWindowFrames().mFrame; |
| 5141 | local.translate(frame.left, frame.top); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5142 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5143 | // A window can only exclude system gestures where it is actually touchable |
| 5144 | local.op(touchableRegion, Op.INTERSECT); |
| 5145 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5146 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5147 | // Apply restriction if necessary. |
| 5148 | if (needsGestureExclusionRestrictions(w, mLastDispatchedSystemUiVisibility)) { |
| 5149 | |
| 5150 | // Processes the region along the left edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5151 | remainingLeftRight[0] = addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5152 | remainingLeftRight[0], w, EXCLUSION_LEFT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5153 | |
| 5154 | // Processes the region along the right edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5155 | remainingLeftRight[1] = addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5156 | remainingLeftRight[1], w, EXCLUSION_RIGHT); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5157 | |
| 5158 | // Adds the middle (unrestricted area) |
| 5159 | final Region middle = Region.obtain(local); |
| 5160 | middle.op(leftEdge, Op.DIFFERENCE); |
| 5161 | middle.op(rightEdge, Op.DIFFERENCE); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5162 | outExclusion.op(middle, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5163 | middle.recycle(); |
| 5164 | } else { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5165 | boolean loggable = needsGestureExclusionRestrictions(w, 0 /* lastSysUiVis */); |
| 5166 | if (loggable) { |
| 5167 | addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5168 | Integer.MAX_VALUE, w, EXCLUSION_LEFT); |
| 5169 | addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5170 | Integer.MAX_VALUE, w, EXCLUSION_RIGHT); |
| 5171 | } |
| 5172 | outExclusion.op(local, Op.UNION); |
| 5173 | } |
| 5174 | if (outExclusionUnrestricted != null) { |
| 5175 | outExclusionUnrestricted.op(local, Op.UNION); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5176 | } |
| 5177 | unhandled.op(touchableRegion, Op.DIFFERENCE); |
| 5178 | }, true /* topToBottom */); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5179 | local.recycle(); |
| 5180 | touchableRegion.recycle(); |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5181 | unhandled.recycle(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5182 | return remainingLeftRight[0] < mSystemGestureExclusionLimit |
| 5183 | || remainingLeftRight[1] < mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5184 | } |
| 5185 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5186 | /** |
| 5187 | * @return Whether gesture exclusion area should be restricted from the window depending on the |
| 5188 | * current SystemUI visibility flags. |
| 5189 | */ |
| 5190 | private static boolean needsGestureExclusionRestrictions(WindowState win, int sysUiVisibility) { |
| 5191 | final int type = win.mAttrs.type; |
| 5192 | final int stickyHideNavFlags = |
| 5193 | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 5194 | final boolean stickyHideNav = |
| 5195 | (sysUiVisibility & stickyHideNavFlags) == stickyHideNavFlags; |
| 5196 | return !stickyHideNav && type != TYPE_INPUT_METHOD && type != TYPE_STATUS_BAR |
| 5197 | && win.getActivityType() != ACTIVITY_TYPE_HOME; |
| 5198 | } |
| 5199 | |
| 5200 | /** |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5201 | * @return Whether gesture exclusion area should be logged for the given window |
| 5202 | */ |
| 5203 | static boolean logsGestureExclusionRestrictions(WindowState win) { |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 5204 | if (win.mWmService.mConstants.mSystemGestureExclusionLogDebounceTimeoutMillis <= 0) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5205 | return false; |
| 5206 | } |
| 5207 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 5208 | final int type = attrs.type; |
| 5209 | return type != TYPE_WALLPAPER |
| 5210 | && type != TYPE_APPLICATION_STARTING |
| 5211 | && type != TYPE_NAVIGATION_BAR |
| 5212 | && (attrs.flags & FLAG_NOT_TOUCHABLE) == 0 |
| 5213 | && needsGestureExclusionRestrictions(win, 0 /* sysUiVisibility */) |
| 5214 | && win.getDisplayContent().mDisplayPolicy.hasSideGestures(); |
| 5215 | } |
| 5216 | |
| 5217 | /** |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5218 | * Adds a local gesture exclusion area to the global area while applying a limit per edge. |
| 5219 | * |
| 5220 | * @param local The gesture exclusion area to add. |
| 5221 | * @param global The destination. |
| 5222 | * @param edge Only processes the part in that region. |
| 5223 | * @param limit How much limit in pixels we have. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5224 | * @param win The WindowState that is being processed |
| 5225 | * @param side The side that is being processed, either {@link WindowState#EXCLUSION_LEFT} or |
| 5226 | * {@link WindowState#EXCLUSION_RIGHT} |
| 5227 | * @return How much of the limit is remaining. |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5228 | */ |
| 5229 | private static int addToGlobalAndConsumeLimit(Region local, Region global, Rect edge, |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5230 | int limit, WindowState win, int side) { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5231 | final Region r = Region.obtain(local); |
| 5232 | r.op(edge, Op.INTERSECT); |
| 5233 | |
| 5234 | final int[] remaining = {limit}; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5235 | final int[] requestedExclusion = {0}; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5236 | forEachRectReverse(r, rect -> { |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5237 | if (remaining[0] <= 0) { |
| 5238 | return; |
| 5239 | } |
| 5240 | final int height = rect.height(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5241 | requestedExclusion[0] += height; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5242 | if (height > remaining[0]) { |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5243 | rect.top = rect.bottom - remaining[0]; |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5244 | } |
| 5245 | remaining[0] -= height; |
| 5246 | global.op(rect, Op.UNION); |
| 5247 | }); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5248 | |
| 5249 | final int grantedExclusion = limit - remaining[0]; |
| 5250 | win.setLastExclusionHeights(side, requestedExclusion[0], grantedExclusion); |
| 5251 | |
Adrian Roos | bf3bc1b | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5252 | r.recycle(); |
| 5253 | return remaining[0]; |
| 5254 | } |
| 5255 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5256 | void registerSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5257 | mSystemGestureExclusionListeners.register(listener); |
| 5258 | final boolean changed; |
| 5259 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 1) { |
| 5260 | changed = updateSystemGestureExclusion(); |
| 5261 | } else { |
| 5262 | changed = false; |
| 5263 | } |
| 5264 | |
| 5265 | if (!changed) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5266 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5267 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5268 | // If updateSystemGestureExclusion changed the exclusion, it will already have |
| 5269 | // notified the listener. Otherwise, we'll do it here. |
| 5270 | try { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5271 | listener.onSystemGestureExclusionChanged(mDisplayId, mSystemGestureExclusion, |
| 5272 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5273 | } catch (RemoteException e) { |
| 5274 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener during register", e); |
| 5275 | } |
| 5276 | } |
| 5277 | } |
| 5278 | |
| 5279 | void unregisterSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5280 | mSystemGestureExclusionListeners.unregister(listener); |
| 5281 | } |
| 5282 | |
| 5283 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5284 | * Create a portal window handle for input. This window transports any touch to the display |
| 5285 | * indicated by {@link InputWindowHandle#portalToDisplayId} if the touch hits this window. |
| 5286 | * |
| 5287 | * @param name The name of the portal window handle. |
| 5288 | * @return the new portal window handle. |
| 5289 | */ |
| 5290 | private InputWindowHandle createPortalWindowHandle(String name) { |
| 5291 | // Let surface flinger to set the display ID of this input window handle because we don't |
| 5292 | // know which display the parent surface control is on. |
| 5293 | final InputWindowHandle portalWindowHandle = new InputWindowHandle( |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 5294 | null /* inputApplicationHandle */, INVALID_DISPLAY); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5295 | portalWindowHandle.name = name; |
| 5296 | portalWindowHandle.token = new Binder(); |
| 5297 | portalWindowHandle.layoutParamsFlags = |
| 5298 | FLAG_SPLIT_TOUCH | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL; |
| 5299 | getBounds(mTmpBounds); |
| 5300 | portalWindowHandle.touchableRegion.set(mTmpBounds); |
| 5301 | portalWindowHandle.scaleFactor = 1f; |
| 5302 | portalWindowHandle.ownerPid = Process.myPid(); |
| 5303 | portalWindowHandle.ownerUid = Process.myUid(); |
| 5304 | portalWindowHandle.portalToDisplayId = mDisplayId; |
| 5305 | return portalWindowHandle; |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5306 | } |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 5307 | |
| 5308 | /** |
| 5309 | * @see IWindowManager#setForwardedInsets |
| 5310 | */ |
| 5311 | public void setForwardedInsets(Insets insets) { |
| 5312 | if (insets == null) { |
| 5313 | insets = Insets.NONE; |
| 5314 | } |
| 5315 | if (mDisplayPolicy.getForwardedInsets().equals(insets)) { |
| 5316 | return; |
| 5317 | } |
| 5318 | mDisplayPolicy.setForwardedInsets(insets); |
| 5319 | setLayoutNeeded(); |
| 5320 | mWmService.mWindowPlacerLocked.requestTraversal(); |
| 5321 | } |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 5322 | |
| 5323 | protected MetricsLogger getMetricsLogger() { |
| 5324 | if (mMetricsLogger == null) { |
| 5325 | mMetricsLogger = new MetricsLogger(); |
| 5326 | } |
| 5327 | return mMetricsLogger; |
| 5328 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5329 | } |