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