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; |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 29 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 30 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 31 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 32 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 33 | import static android.util.DisplayMetrics.DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 34 | import static android.view.Display.DEFAULT_DISPLAY; |
| 35 | import static android.view.Display.FLAG_PRIVATE; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 36 | import static android.view.Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 37 | import static android.view.Display.INVALID_DISPLAY; |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 38 | import static android.view.InsetsState.TYPE_IME; |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 39 | import static android.view.InsetsState.TYPE_LEFT_GESTURES; |
| 40 | import static android.view.InsetsState.TYPE_RIGHT_GESTURES; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 41 | import static android.view.Surface.ROTATION_0; |
| 42 | import static android.view.Surface.ROTATION_180; |
| 43 | import static android.view.Surface.ROTATION_270; |
| 44 | import static android.view.Surface.ROTATION_90; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 45 | import static android.view.View.GONE; |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 46 | import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 47 | import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 48 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 49 | import static android.view.WindowManager.DOCKED_INVALID; |
| 50 | import static android.view.WindowManager.DOCKED_TOP; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 51 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 52 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 53 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 54 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 55 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 56 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 57 | import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 58 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 59 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE; |
| 60 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 61 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 62 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 63 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 64 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 65 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 66 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 67 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 68 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 69 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 71 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 72 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 73 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 74 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 75 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 76 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 77 | import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 78 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 79 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 80 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 81 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 82 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 83 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 84 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 85 | import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 86 | import static com.android.server.wm.DisplayContentProto.APP_TRANSITION; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 87 | import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 88 | import static com.android.server.wm.DisplayContentProto.CHANGING_APPS; |
| 89 | import static com.android.server.wm.DisplayContentProto.CLOSING_APPS; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 90 | import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES; |
| 91 | import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO; |
| 92 | import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER; |
| 93 | import static com.android.server.wm.DisplayContentProto.DPI; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 94 | import static com.android.server.wm.DisplayContentProto.FOCUSED_APP; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 95 | import static com.android.server.wm.DisplayContentProto.ID; |
| 96 | import static com.android.server.wm.DisplayContentProto.IME_WINDOWS; |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 97 | import static com.android.server.wm.DisplayContentProto.OPENING_APPS; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 98 | import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER; |
| 99 | import static com.android.server.wm.DisplayContentProto.ROTATION; |
| 100 | import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION; |
| 101 | import static com.android.server.wm.DisplayContentProto.STACKS; |
| 102 | import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 103 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 104 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 105 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 106 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 107 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 108 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 109 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 110 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 111 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 112 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 113 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 114 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 115 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 116 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 117 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 118 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 119 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 120 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 121 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 122 | import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 123 | import static com.android.server.wm.WindowManagerService.H.REPORT_FOCUS_CHANGE; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 124 | 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] | 125 | import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 126 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
| 127 | import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 128 | import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 129 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 130 | import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION; |
| 131 | import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 132 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
| 133 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS; |
| 134 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 135 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 136 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 137 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 138 | import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 139 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 140 | import static com.android.server.wm.WindowManagerService.logSurface; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 141 | import static com.android.server.wm.WindowState.EXCLUSION_LEFT; |
| 142 | import static com.android.server.wm.WindowState.EXCLUSION_RIGHT; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 143 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 144 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 145 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 146 | import static com.android.server.wm.utils.RegionUtils.forEachRectReverse; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 147 | import static com.android.server.wm.utils.RegionUtils.rectListToRegion; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 148 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 149 | import android.animation.AnimationHandler; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 150 | import android.annotation.CallSuper; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 151 | import android.annotation.IntDef; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 152 | import android.annotation.NonNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 153 | import android.annotation.Nullable; |
Dean Harding | 3e5a152 | 2017-10-06 09:19:01 -0700 | [diff] [blame] | 154 | import android.content.pm.PackageManager; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 155 | import android.content.res.CompatibilityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 156 | import android.content.res.Configuration; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 157 | import android.graphics.Bitmap; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 158 | import android.graphics.Insets; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 159 | import android.graphics.Matrix; |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 160 | import android.graphics.Point; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 161 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 162 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 163 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 164 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 165 | import android.hardware.display.DisplayManagerInternal; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 166 | import android.metrics.LogMaker; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 167 | import android.os.Binder; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 168 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 169 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 170 | import android.os.IBinder; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 171 | import android.os.Process; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 172 | import android.os.RemoteCallbackList; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 173 | import android.os.RemoteException; |
| 174 | import android.os.SystemClock; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 175 | import android.os.Trace; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 176 | import android.os.UserHandle; |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 177 | import android.util.ArraySet; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 178 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 179 | import android.util.Slog; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 180 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 181 | import android.view.Display; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 182 | import android.view.DisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 183 | import android.view.DisplayInfo; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 184 | import android.view.Gravity; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 185 | import android.view.ISystemGestureExclusionListener; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 186 | import android.view.InputChannel; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 187 | import android.view.InputDevice; |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 188 | import android.view.InputWindowHandle; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 189 | import android.view.InsetsState.InternalInsetType; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 190 | import android.view.MagnificationSpec; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 191 | import android.view.RemoteAnimationDefinition; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 192 | import android.view.Surface; |
| 193 | import android.view.SurfaceControl; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 194 | import android.view.SurfaceControl.Transaction; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 195 | import android.view.SurfaceSession; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 196 | import android.view.View; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 197 | import android.view.WindowManager; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 198 | import android.view.WindowManagerPolicyConstants.PointerEventListener; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 199 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 200 | import com.android.internal.annotations.VisibleForTesting; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 201 | import com.android.internal.logging.MetricsLogger; |
| 202 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 203 | import com.android.internal.util.ToBooleanFunction; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 204 | import com.android.internal.util.function.TriConsumer; |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 205 | import com.android.internal.util.function.pooled.PooledConsumer; |
| 206 | import com.android.internal.util.function.pooled.PooledLambda; |
Winson Chung | 6ba767a | 2018-12-13 18:20:11 -0800 | [diff] [blame] | 207 | import com.android.server.AnimationThread; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 208 | import com.android.server.policy.WindowManagerPolicy; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 209 | import com.android.server.wm.utils.DisplayRotationUtil; |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 210 | import com.android.server.wm.utils.RotationCache; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 211 | import com.android.server.wm.utils.WmDisplayCutout; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 212 | |
| 213 | import java.io.PrintWriter; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 214 | import java.lang.annotation.Retention; |
| 215 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 216 | import java.util.ArrayList; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 217 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 218 | import java.util.HashMap; |
| 219 | import java.util.Iterator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 220 | import java.util.LinkedList; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 221 | import java.util.List; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 222 | import java.util.Objects; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 223 | import java.util.function.Consumer; |
| 224 | import java.util.function.Predicate; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 225 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 226 | /** |
| 227 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 228 | * particular Display. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 229 | */ |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 230 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> |
| 231 | implements WindowManagerPolicy.DisplayContentInfo { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 232 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 233 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 234 | /** The default scaling mode that scales content automatically. */ |
| 235 | static final int FORCE_SCALING_MODE_AUTO = 0; |
| 236 | /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */ |
| 237 | static final int FORCE_SCALING_MODE_DISABLED = 1; |
| 238 | |
| 239 | @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = { |
| 240 | FORCE_SCALING_MODE_AUTO, |
| 241 | FORCE_SCALING_MODE_DISABLED |
| 242 | }) |
| 243 | @Retention(RetentionPolicy.SOURCE) |
| 244 | @interface ForceScalingMode {} |
| 245 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 246 | /** Unique identifier of this stack. */ |
| 247 | private final int mDisplayId; |
| 248 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 249 | // TODO: Remove once unification is complete. |
| 250 | ActivityDisplay mAcitvityDisplay; |
| 251 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 252 | /** The containers below are the only child containers the display can have. */ |
| 253 | // Contains all window containers that are related to apps (Activities) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 254 | private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 255 | // Contains all non-app window containers that should be displayed above the app containers |
| 256 | // (e.g. Status bar) |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 257 | private final AboveAppWindowContainers mAboveAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 258 | new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 259 | // Contains all non-app window containers that should be displayed below the app containers |
| 260 | // (e.g. Wallpaper). |
| 261 | private final NonAppWindowContainers mBelowAppWindowsContainers = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 262 | new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 263 | // Contains all IME window containers. Note that the z-ordering of the IME windows will depend |
| 264 | // 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] | 265 | // window containers together and move them in-sync if/when needed. We use a subclass of |
| 266 | // 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] | 267 | private final NonAppWindowContainers mImeWindowsContainers = |
| 268 | new NonAppWindowContainers("mImeWindowsContainers", mWmService); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 269 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 270 | private WindowState mTmpWindow; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 271 | private WindowState mTmpWindow2; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 272 | private boolean mTmpRecoveringMemory; |
| 273 | private boolean mUpdateImeTarget; |
| 274 | private boolean mTmpInitial; |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 275 | private int mMaxUiWidth; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 276 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 277 | final AppTransition mAppTransition; |
| 278 | final AppTransitionController mAppTransitionController; |
| 279 | boolean mSkipAppTransitionAnimation = false; |
| 280 | |
| 281 | final ArraySet<AppWindowToken> mOpeningApps = new ArraySet<>(); |
| 282 | final ArraySet<AppWindowToken> mClosingApps = new ArraySet<>(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 283 | final ArraySet<AppWindowToken> mChangingApps = new ArraySet<>(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 284 | final UnknownAppVisibilityController mUnknownAppVisibilityController; |
| 285 | BoundsAnimationController mBoundsAnimationController; |
| 286 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 287 | private MetricsLogger mMetricsLogger; |
| 288 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 289 | /** |
| 290 | * List of clients without a transtiton animation that we notify once we are done |
| 291 | * transitioning since they won't be notified through the app window animator. |
| 292 | */ |
| 293 | final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>(); |
| 294 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 295 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 296 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 297 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 298 | // Initial display metrics. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 299 | int mInitialDisplayWidth = 0; |
| 300 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 301 | int mInitialDisplayDensity = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 302 | |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 303 | DisplayCutout mInitialDisplayCutout; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 304 | private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 305 | = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 306 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 307 | /** |
| 308 | * Overridden display size. Initialized with {@link #mInitialDisplayWidth} |
| 309 | * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size". |
| 310 | * @see WindowManagerService#setForcedDisplaySize(int, int, int) |
| 311 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 312 | int mBaseDisplayWidth = 0; |
| 313 | int mBaseDisplayHeight = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 314 | /** |
| 315 | * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity} |
| 316 | * but can be set from Settings or via shell command "adb shell wm density". |
| 317 | * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int) |
| 318 | */ |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 319 | int mBaseDisplayDensity = 0; |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 320 | |
| 321 | /** |
| 322 | * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling". |
| 323 | * @see WindowManagerService#setForcedDisplayScalingMode(int, int) |
| 324 | */ |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 325 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 326 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 327 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 328 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 329 | private final DisplayPolicy mDisplayPolicy; |
| 330 | private DisplayRotation mDisplayRotation; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 331 | DisplayFrames mDisplayFrames; |
| 332 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 333 | private final RemoteCallbackList<ISystemGestureExclusionListener> |
| 334 | mSystemGestureExclusionListeners = new RemoteCallbackList<>(); |
| 335 | private final Region mSystemGestureExclusion = new Region(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 336 | private boolean mSystemGestureExclusionWasRestricted = false; |
| 337 | private final Region mSystemGestureExclusionUnrestricted = new Region(); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 338 | private int mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 339 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 340 | /** |
| 341 | * For default display it contains real metrics, empty for others. |
| 342 | * @see WindowManagerService#createWatermarkInTransaction() |
| 343 | */ |
| 344 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 345 | |
| 346 | /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */ |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 347 | private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 348 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 349 | /** |
| 350 | * Compat metrics computed based on {@link #mDisplayMetrics}. |
| 351 | * @see #updateDisplayAndOrientation(int) |
| 352 | */ |
| 353 | private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 354 | |
| 355 | /** The desired scaling factor for compatible apps. */ |
| 356 | float mCompatibleScreenScale; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 357 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 358 | /** |
| 359 | * Current rotation of the display. |
| 360 | * Constants as per {@link android.view.Surface.Rotation}. |
| 361 | * |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 362 | * @see #updateRotationUnchecked() |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 363 | */ |
| 364 | private int mRotation = 0; |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 365 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 366 | /** |
| 367 | * Last applied orientation of the display. |
| 368 | * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}. |
| 369 | * |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 370 | * @see #updateOrientationFromAppTokens() |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 371 | */ |
| 372 | private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 373 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 374 | /** |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 375 | * Orientation forced by some window. If there is no visible window that specifies orientation |
| 376 | * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}. |
| 377 | * |
| 378 | * @see NonAppWindowContainers#getOrientation() |
| 379 | */ |
| 380 | private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 381 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 382 | /** |
| 383 | * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not |
| 384 | * occluded. |
| 385 | * |
| 386 | * @see NonAppWindowContainers#getOrientation() |
| 387 | */ |
| 388 | private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 389 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 390 | /** |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 391 | * The maximum aspect ratio (longerSide/shorterSide) that is treated as close-to-square. The |
| 392 | * orientation requests from apps would be ignored if the display is close-to-square. |
| 393 | */ |
| 394 | @VisibleForTesting |
| 395 | final float mCloseToSquareMaxAspectRatio; |
| 396 | |
| 397 | /** |
| 398 | * If this is true, we would not rotate the display for apps. The rotation would be either the |
| 399 | * sensor rotation or the user rotation, controlled by |
| 400 | * {@link WindowManagerPolicy.UserRotationMode}. |
| 401 | */ |
| 402 | private boolean mIgnoreRotationForApps; |
| 403 | |
| 404 | /** |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 405 | * Keep track of wallpaper visibility to notify changes. |
| 406 | */ |
| 407 | private boolean mLastWallpaperVisible = false; |
| 408 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 409 | private Rect mBaseDisplayRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 410 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 411 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 412 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 413 | int pendingLayoutChanges; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 414 | int mDeferredRotationPauseCount; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 415 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 416 | /** |
| 417 | * Used to gate application window layout until we have sent the complete configuration. |
| 418 | * TODO: There are still scenarios where we may be out of sync with the client. Ideally |
| 419 | * we want to replace this flag with a mechanism that will confirm the configuration |
| 420 | * applied by the client is the one expected by the system server. |
| 421 | */ |
| 422 | boolean mWaitingForConfig; |
| 423 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 424 | // TODO(multi-display): remove some of the usages. |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 425 | @VisibleForTesting |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 426 | boolean isDefaultDisplay; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 427 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 428 | /** |
| 429 | * Flag indicating whether WindowManager should override info for this display in |
| 430 | * DisplayManager. |
| 431 | */ |
| 432 | boolean mShouldOverrideDisplayConfiguration = true; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 433 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 434 | /** 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] | 435 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 436 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 437 | /** Detect user tapping outside of current focused task bounds .*/ |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 438 | @VisibleForTesting |
| 439 | final TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 440 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 441 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 442 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 443 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 444 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 445 | private final Rect mTmpRect = new Rect(); |
| 446 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 447 | private final RectF mTmpRectF = new RectF(); |
| 448 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 449 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 450 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 451 | /** Used for handing back size of display */ |
| 452 | private final Rect mTmpBounds = new Rect(); |
| 453 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 454 | private final Configuration mTmpConfiguration = new Configuration(); |
| 455 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 456 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 457 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 458 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 459 | final DockedStackDividerController mDividerControllerLocked; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 460 | final PinnedStackController mPinnedStackControllerLocked; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 461 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 462 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 463 | /** A collection of windows that provide tap exclude regions inside of them. */ |
| 464 | final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>(); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 465 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 466 | private boolean mHaveBootMsg = false; |
| 467 | private boolean mHaveApp = false; |
| 468 | private boolean mHaveWallpaper = false; |
| 469 | private boolean mHaveKeyguard = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 470 | |
| 471 | private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList(); |
| 472 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 473 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 474 | new TaskForResizePointSearchResult(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 475 | private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState = |
| 476 | new ApplySurfaceChangesTransactionState(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 477 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 478 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 479 | // the display's direct children should be allowed. |
| 480 | private boolean mRemovingDisplay = false; |
| 481 | |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 482 | // {@code false} if this display is in the processing of being created. |
| 483 | private boolean mDisplayReady = false; |
| 484 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 485 | WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 486 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 487 | boolean mWallpaperMayChange = false; |
| 488 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 489 | private final SurfaceSession mSession = new SurfaceSession(); |
| 490 | |
| 491 | /** |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 492 | * Window that is currently interacting with the user. This window is responsible for receiving |
| 493 | * key events and pointer events from the user. |
| 494 | */ |
| 495 | WindowState mCurrentFocus = null; |
| 496 | |
| 497 | /** |
| 498 | * The last focused window that we've notified the client that the focus is changed. |
| 499 | */ |
| 500 | WindowState mLastFocus = null; |
| 501 | |
| 502 | /** |
| 503 | * Windows that have lost input focus and are waiting for the new focus window to be displayed |
| 504 | * before they are told about this. |
| 505 | */ |
| 506 | ArrayList<WindowState> mLosingFocus = new ArrayList<>(); |
| 507 | |
| 508 | /** |
| 509 | * The foreground app of this display. Windows below this app cannot be the focused window. If |
| 510 | * the user taps on the area outside of the task of the focused app, we will notify AM about the |
| 511 | * new task the user wants to interact with. |
| 512 | */ |
| 513 | AppWindowToken mFocusedApp = null; |
| 514 | |
| 515 | /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 516 | final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>(); |
| 517 | |
| 518 | /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */ |
| 519 | final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>(); |
| 520 | |
| 521 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 522 | * We organize all top-level Surfaces in to the following layers. |
| 523 | * mOverlayLayer contains a few Surfaces which are always on top of others |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 524 | * and omitted from Screen-Magnification, for example the strict mode flash or |
| 525 | * the magnification overlay itself. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 526 | * {@link #mWindowingLayer} contains everything else. |
| 527 | */ |
| 528 | private SurfaceControl mOverlayLayer; |
| 529 | |
| 530 | /** |
| 531 | * See {@link #mOverlayLayer} |
| 532 | */ |
| 533 | private SurfaceControl mWindowingLayer; |
| 534 | |
| 535 | /** |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 536 | * Sequence number for the current layout pass. |
| 537 | */ |
| 538 | int mLayoutSeq = 0; |
| 539 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 540 | /** |
| 541 | * Specifies the count to determine whether to defer updating the IME target until ready. |
| 542 | */ |
| 543 | private int mDeferUpdateImeTargetCount; |
| 544 | |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 545 | /** Temporary float array to retrieve 3x3 matrix values. */ |
| 546 | private final float[] mTmpFloats = new float[9]; |
| 547 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 548 | private MagnificationSpec mMagnificationSpec; |
| 549 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 550 | private InputMonitor mInputMonitor; |
| 551 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 552 | /** Caches the value whether told display manager that we have content. */ |
| 553 | private boolean mLastHasContent; |
| 554 | |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 555 | private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil(); |
| 556 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 557 | /** |
| 558 | * The input method window for this display. |
| 559 | */ |
| 560 | WindowState mInputMethodWindow; |
| 561 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 562 | /** |
| 563 | * This just indicates the window the input method is on top of, not |
| 564 | * necessarily the window its input is going to. |
| 565 | */ |
| 566 | WindowState mInputMethodTarget; |
| 567 | |
| 568 | /** If true hold off on modifying the animation layer of mInputMethodTarget */ |
| 569 | boolean mInputMethodTargetWaitingAnim; |
| 570 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 571 | private final PointerEventDispatcher mPointerEventDispatcher; |
| 572 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 573 | private final InsetsStateController mInsetsStateController; |
| 574 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 575 | /** @see #getParentWindow() */ |
| 576 | private WindowState mParentWindow; |
| 577 | |
| 578 | private Point mLocationInParentWindow = new Point(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 579 | private SurfaceControl mParentSurfaceControl; |
| 580 | private InputWindowHandle mPortalWindowHandle; |
| 581 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 582 | // Last systemUiVisibility we received from status bar. |
| 583 | private int mLastStatusBarVisibility = 0; |
| 584 | // Last systemUiVisibility we dispatched to windows. |
| 585 | private int mLastDispatchedSystemUiVisibility = 0; |
| 586 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 587 | /** Corner radius that windows should have in order to match the display. */ |
| 588 | private final float mWindowCornerRadius; |
| 589 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 590 | private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> { |
| 591 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 592 | final AppWindowToken atoken = w.mAppToken; |
| 593 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
Jorim Jaggi | af0d6d2 | 2018-06-08 15:25:35 +0200 | [diff] [blame] | 594 | if (atoken == null || atoken.canShowWindows()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 595 | if (w.performShowLocked()) { |
| 596 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 597 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 598 | mWmService.mWindowPlacerLocked.debugLayoutRepeats( |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 599 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 604 | }; |
| 605 | |
| 606 | private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> { |
| 607 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 608 | if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) { |
| 609 | return; |
| 610 | } |
| 611 | |
Jorim Jaggi | 8f52087 | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 612 | // If this window is animating, ensure the animation background is set. |
| 613 | final AnimationAdapter anim = w.mAppToken != null |
| 614 | ? w.mAppToken.getAnimation() |
| 615 | : w.getAnimation(); |
| 616 | if (anim != null) { |
| 617 | final int color = anim.getBackgroundColor(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 618 | if (color != 0) { |
| 619 | final TaskStack stack = w.getStack(); |
| 620 | if (stack != null) { |
| 621 | stack.setAnimationBackground(winAnimator, color); |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | }; |
| 626 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 627 | private final Consumer<WindowState> mScheduleToastTimeout = w -> { |
| 628 | final int lostFocusUid = mTmpWindow.mOwnerUid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 629 | final Handler handler = mWmService.mH; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 630 | if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) { |
| 631 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) { |
| 632 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), |
| 633 | w.mAttrs.hideTimeoutMilliseconds); |
| 634 | } |
| 635 | } |
| 636 | }; |
| 637 | |
| 638 | private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 639 | final AppWindowToken focusedApp = mFocusedApp; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 640 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w |
| 641 | + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys()); |
| 642 | |
| 643 | if (!w.canReceiveKeys()) { |
| 644 | return false; |
| 645 | } |
| 646 | |
| 647 | final AppWindowToken wtoken = w.mAppToken; |
| 648 | |
| 649 | // If this window's application has been removed, just skip it. |
| 650 | if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) { |
| 651 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because " |
| 652 | + (wtoken.removed ? "removed" : "sendingToBottom")); |
| 653 | return false; |
| 654 | } |
| 655 | |
| 656 | if (focusedApp == null) { |
| 657 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null" |
| 658 | + " using new focus @ " + w); |
| 659 | mTmpWindow = w; |
| 660 | return true; |
| 661 | } |
| 662 | |
| 663 | if (!focusedApp.windowsAreFocusable()) { |
| 664 | // Current focused app windows aren't focusable... |
| 665 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not" |
| 666 | + " focusable using new focus @ " + w); |
| 667 | mTmpWindow = w; |
| 668 | return true; |
| 669 | } |
| 670 | |
| 671 | // Descend through all of the app tokens and find the first that either matches |
| 672 | // win.mAppToken (return win) or mFocusedApp (return null). |
| 673 | if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 674 | if (focusedApp.compareTo(wtoken) > 0) { |
| 675 | // App stack below focused app stack. No focus for you!!! |
| 676 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, |
| 677 | "findFocusedWindow: Reached focused app=" + focusedApp); |
| 678 | mTmpWindow = null; |
| 679 | return true; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w); |
| 684 | mTmpWindow = w; |
| 685 | return true; |
| 686 | }; |
| 687 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 688 | private final Consumer<WindowState> mPerformLayout = w -> { |
| 689 | // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid |
| 690 | // wasting time and funky changes while a window is animating away. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 691 | final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 692 | || w.isGoneForLayoutLw(); |
| 693 | |
| 694 | if (DEBUG_LAYOUT && !w.mLayoutAttached) { |
| 695 | Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame |
| 696 | + " mLayoutAttached=" + w.mLayoutAttached |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 697 | + " config reported=" + w.isLastConfigReportedToClient()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 698 | final AppWindowToken atoken = w.mAppToken; |
| 699 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 700 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden() |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 701 | + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested) |
| 702 | + " parentHidden=" + w.isParentWindowHidden()); |
| 703 | else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 704 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden() |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 705 | + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested) |
| 706 | + " parentHidden=" + w.isParentWindowHidden()); |
| 707 | } |
| 708 | |
| 709 | // If this view is GONE, then skip it -- keep the current frame, and let the caller know |
| 710 | // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows, |
| 711 | // since that means "perform layout as normal, just don't display"). |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 712 | if ((!gone || !w.mHaveFrame || w.mLayoutNeeded) && !w.mLayoutAttached) { |
| 713 | if (mTmpInitial) { |
| 714 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 715 | } |
Jorim Jaggi | 91d382a | 2019-03-27 17:00:48 +0100 | [diff] [blame] | 716 | if (w.mAttrs.type == TYPE_DREAM) { |
| 717 | // Don't layout windows behind a dream, so that if it does stuff like hide |
| 718 | // the status bar we won't get a bad transition when it goes away. |
| 719 | mTmpWindow = w; |
| 720 | } |
| 721 | w.mLayoutNeeded = false; |
| 722 | w.prelayout(); |
| 723 | final boolean firstLayout = !w.isLaidOut(); |
| 724 | getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames); |
| 725 | w.mLayoutSeq = mLayoutSeq; |
| 726 | |
| 727 | // If this is the first layout, we need to initialize the last inset values as |
| 728 | // otherwise we'd immediately cause an unnecessary resize. |
| 729 | if (firstLayout) { |
| 730 | w.updateLastInsetValues(); |
| 731 | } |
| 732 | |
| 733 | if (w.mAppToken != null) { |
| 734 | w.mAppToken.layoutLetterbox(w); |
| 735 | } |
| 736 | |
| 737 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
| 738 | + " mContainingFrame=" + w.getContainingFrame() |
| 739 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 740 | } |
| 741 | }; |
| 742 | |
| 743 | private final Consumer<WindowState> mPerformLayoutAttached = w -> { |
| 744 | if (w.mLayoutAttached) { |
| 745 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame |
| 746 | + " mViewVisibility=" + w.mViewVisibility |
| 747 | + " mRelayoutCalled=" + w.mRelayoutCalled); |
| 748 | // If this view is GONE, then skip it -- keep the current frame, and let the caller |
| 749 | // know so they can ignore it if they want. (We do the normal layout for INVISIBLE |
| 750 | // windows, since that means "perform layout as normal, just don't display"). |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 751 | if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 752 | return; |
| 753 | } |
| 754 | if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame |
| 755 | || w.mLayoutNeeded) { |
| 756 | if (mTmpInitial) { |
| 757 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 758 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 759 | } |
| 760 | w.mLayoutNeeded = false; |
| 761 | w.prelayout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 762 | getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 763 | w.mLayoutSeq = mLayoutSeq; |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 764 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw() |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 765 | + " mContainingFrame=" + w.getContainingFrame() |
| 766 | + " mDisplayFrame=" + w.getDisplayFrameLw()); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 767 | } |
| 768 | } else if (w.mAttrs.type == TYPE_DREAM) { |
| 769 | // Don't layout windows behind a dream, so that if it does stuff like hide the |
| 770 | // status bar we won't get a bad transition when it goes away. |
| 771 | mTmpWindow = mTmpWindow2; |
| 772 | } |
| 773 | }; |
| 774 | |
| 775 | private final Predicate<WindowState> mComputeImeTargetPredicate = w -> { |
| 776 | if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w |
| 777 | + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| 778 | return w.canBeImeTarget(); |
| 779 | }; |
| 780 | |
| 781 | private final Consumer<WindowState> mApplyPostLayoutPolicy = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 782 | w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 783 | mInputMethodTarget); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 784 | |
| 785 | private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 786 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 787 | final boolean obscuredChanged = w.mObscured != |
| 788 | mTmpApplySurfaceChangesTransactionState.obscured; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 789 | final RootWindowContainer root = mWmService.mRoot; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 790 | |
| 791 | // Update effect. |
| 792 | w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured; |
| 793 | if (!mTmpApplySurfaceChangesTransactionState.obscured) { |
| 794 | final boolean isDisplayed = w.isDisplayedLw(); |
| 795 | |
| 796 | if (isDisplayed && w.isObscuringDisplay()) { |
| 797 | // This window completely covers everything behind it, so we want to leave all |
| 798 | // of them as undimmed (for performance reasons). |
| 799 | root.mObscuringWindow = w; |
| 800 | mTmpApplySurfaceChangesTransactionState.obscured = true; |
| 801 | } |
| 802 | |
| 803 | mTmpApplySurfaceChangesTransactionState.displayHasContent |= |
| 804 | root.handleNotObscuredLocked(w, |
| 805 | mTmpApplySurfaceChangesTransactionState.obscured, |
| 806 | mTmpApplySurfaceChangesTransactionState.syswin); |
| 807 | |
| 808 | if (w.mHasSurface && isDisplayed) { |
| 809 | final int type = w.mAttrs.type; |
| 810 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
| 811 | || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 812 | mTmpApplySurfaceChangesTransactionState.syswin = true; |
| 813 | } |
| 814 | if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0 |
| 815 | && w.mAttrs.preferredRefreshRate != 0) { |
| 816 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate |
| 817 | = w.mAttrs.preferredRefreshRate; |
| 818 | } |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 819 | final int preferredModeId = getDisplayPolicy().getRefreshRatePolicy() |
| 820 | .getPreferredModeId(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 821 | if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0 |
Ady Abraham | f3e0531 | 2019-05-13 18:04:59 -0700 | [diff] [blame] | 822 | && preferredModeId != 0) { |
| 823 | mTmpApplySurfaceChangesTransactionState.preferredModeId = preferredModeId; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 828 | if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 829 | // This is the wallpaper target and its obscured state changed... make sure the |
| 830 | // current wallpaper's visibility has been updated accordingly. |
| 831 | mWallpaperController.updateWallpaperVisibility(); |
| 832 | } |
| 833 | |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 834 | w.handleWindowMovedIfNeeded(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 835 | |
| 836 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 837 | |
| 838 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 839 | w.resetContentChanged(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 840 | |
| 841 | // Moved from updateWindowsAndWallpaperLocked(). |
| 842 | if (w.mHasSurface) { |
| 843 | // Take care of the window being ready to display. |
| 844 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 845 | if (isDefaultDisplay && committed) { |
| 846 | if (w.mAttrs.type == TYPE_DREAM) { |
| 847 | // HACK: When a dream is shown, it may at that point hide the lock screen. |
| 848 | // So we need to redo the layout to let the phone window manager make this |
| 849 | // happen. |
| 850 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 851 | if (DEBUG_LAYOUT_REPEATS) { |
| 852 | surfacePlacer.debugLayoutRepeats( |
| 853 | "dream and commitFinishDrawingLocked true", |
| 854 | pendingLayoutChanges); |
| 855 | } |
| 856 | } |
| 857 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 858 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 859 | "First draw done in potential wallpaper target " + w); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 860 | mWallpaperMayChange = true; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 861 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 862 | if (DEBUG_LAYOUT_REPEATS) { |
| 863 | surfacePlacer.debugLayoutRepeats( |
| 864 | "wallpaper and commitFinishDrawingLocked true", |
| 865 | pendingLayoutChanges); |
| 866 | } |
| 867 | } |
| 868 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | final AppWindowToken atoken = w.mAppToken; |
| 872 | if (atoken != null) { |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 873 | atoken.updateLetterboxSurface(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 874 | final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w); |
| 875 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) { |
| 876 | mTmpUpdateAllDrawn.add(atoken); |
| 877 | } |
| 878 | } |
| 879 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 880 | if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 881 | mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | w.updateResizingWindowIfNeeded(); |
| 885 | }; |
| 886 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 887 | /** |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 888 | * Create new {@link DisplayContent} instance, add itself to the root window container and |
| 889 | * initialize direct children. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 890 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 891 | * @param service You know. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 892 | * @param activityDisplay The ActivityDisplay for the display container. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 893 | */ |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 894 | DisplayContent(Display display, WindowManagerService service, |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 895 | ActivityDisplay activityDisplay) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 896 | super(service); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 897 | mAcitvityDisplay = activityDisplay; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 898 | if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) { |
| 899 | throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() |
| 900 | + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId()) |
| 901 | + " new=" + display); |
| 902 | } |
| 903 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 904 | mDisplay = display; |
| 905 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 906 | mWallpaperController = new WallpaperController(mWmService, this); |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 907 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 908 | display.getMetrics(mDisplayMetrics); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 909 | mSystemGestureExclusionLimit = mWmService.mSystemGestureExclusionLimitDp |
| 910 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 911 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 912 | mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo, |
| 913 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 914 | initializeDisplayBaseInfo(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 915 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 916 | mAppTransition = new AppTransition(service.mContext, service, this); |
| 917 | mAppTransition.registerListenerLocked(service.mActivityManagerAppTransitionNotifier); |
| 918 | mAppTransitionController = new AppTransitionController(service, this); |
| 919 | mUnknownAppVisibilityController = new UnknownAppVisibilityController(service, this); |
| 920 | |
| 921 | AnimationHandler animationHandler = new AnimationHandler(); |
| 922 | mBoundsAnimationController = new BoundsAnimationController(service.mContext, |
Winson Chung | 6ba767a | 2018-12-13 18:20:11 -0800 | [diff] [blame] | 923 | mAppTransition, AnimationThread.getHandler(), animationHandler); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 924 | |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 925 | final InputChannel inputChannel = mWmService.mInputManager.monitorInput( |
| 926 | "PointerEventDispatcher" + mDisplayId, mDisplayId); |
| 927 | mPointerEventDispatcher = new PointerEventDispatcher(inputChannel); |
| 928 | |
| 929 | // Tap Listeners are supported for: |
| 930 | // 1. All physical displays (multi-display). |
| 931 | // 2. VirtualDisplays on VR, AA (and everything else). |
| 932 | mTapDetector = new TaskTapPointerEventListener(mWmService, this); |
| 933 | registerPointerEventListener(mTapDetector); |
| 934 | registerPointerEventListener(mWmService.mMousePositionTracker); |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 935 | if (mWmService.mAtmService.getRecentTasks() != null) { |
| 936 | registerPointerEventListener( |
| 937 | mWmService.mAtmService.getRecentTasks().getInputListener()); |
| 938 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 939 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 940 | mDisplayPolicy = new DisplayPolicy(service, this); |
| 941 | mDisplayRotation = new DisplayRotation(service, this); |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 942 | mCloseToSquareMaxAspectRatio = service.mContext.getResources().getFloat( |
| 943 | com.android.internal.R.dimen.config_closeToSquareDisplayMaxAspectRatio); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 944 | if (isDefaultDisplay) { |
| 945 | // The policy may be invoked right after here, so it requires the necessary default |
| 946 | // fields of this display content. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 947 | mWmService.mPolicy.setDefaultDisplay(this); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 948 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 949 | if (mWmService.mDisplayReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 950 | mDisplayPolicy.onConfigurationChanged(); |
| 951 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 952 | if (mWmService.mSystemReady) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 953 | mDisplayPolicy.systemReady(); |
| 954 | } |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 955 | mWindowCornerRadius = mDisplayPolicy.getWindowCornerRadius(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 956 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
| 957 | mPinnedStackControllerLocked = new PinnedStackController(service, this); |
| 958 | |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 959 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(mSession) |
| 960 | .setOpaque(true) |
| 961 | .setContainerLayer(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 962 | mWindowingLayer = b.setName("Display Root").build(); |
| 963 | mOverlayLayer = b.setName("Display Overlays").build(); |
| 964 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 965 | getPendingTransaction().setLayer(mWindowingLayer, 0) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 966 | .setLayerStack(mWindowingLayer, mDisplayId) |
| 967 | .show(mWindowingLayer) |
| 968 | .setLayer(mOverlayLayer, 1) |
| 969 | .setLayerStack(mOverlayLayer, mDisplayId) |
| 970 | .show(mOverlayLayer); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 971 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 972 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 973 | // 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] | 974 | super.addChild(mBelowAppWindowsContainers, null); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 975 | super.addChild(mTaskStackContainers, null); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 976 | super.addChild(mAboveAppWindowsContainers, null); |
| 977 | super.addChild(mImeWindowsContainers, null); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 978 | |
| 979 | // Add itself as a child to the root container. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 980 | mWmService.mRoot.addChild(this, null); |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 981 | |
| 982 | // TODO(b/62541591): evaluate whether this is the best spot to declare the |
| 983 | // {@link DisplayContent} ready for use. |
| 984 | mDisplayReady = true; |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 985 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 986 | mWmService.mAnimator.addDisplayLocked(mDisplayId); |
Arthur Hung | 39134b2 | 2018-08-14 11:58:28 +0800 | [diff] [blame] | 987 | mInputMonitor = new InputMonitor(service, mDisplayId); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 988 | mInsetsStateController = new InsetsStateController(this); |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | boolean isReady() { |
| 992 | // 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] | 993 | return mWmService.mDisplayReady && mDisplayReady; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | int getDisplayId() { |
| 997 | return mDisplayId; |
| 998 | } |
| 999 | |
Tiger Huang | 43b8fc2 | 2019-04-26 11:49:29 +0800 | [diff] [blame] | 1000 | float getWindowCornerRadius() { |
| 1001 | return mWindowCornerRadius; |
| 1002 | } |
| 1003 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1004 | WindowToken getWindowToken(IBinder binder) { |
| 1005 | return mTokenMap.get(binder); |
| 1006 | } |
| 1007 | |
| 1008 | AppWindowToken getAppWindowToken(IBinder binder) { |
| 1009 | final WindowToken token = getWindowToken(binder); |
| 1010 | if (token == null) { |
| 1011 | return null; |
| 1012 | } |
| 1013 | return token.asAppWindowToken(); |
| 1014 | } |
| 1015 | |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 1016 | private void addWindowToken(IBinder binder, WindowToken token) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1017 | final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1018 | if (dc != null) { |
| 1019 | // We currently don't support adding a window token to the display if the display |
| 1020 | // already has the binder mapped to another token. If there is a use case for supporting |
| 1021 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 1022 | // the binder map to a list of window tokens. |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 1023 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 1024 | + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1025 | } |
Wale Ogunwale | 2f569ed | 2017-05-08 09:15:49 -0700 | [diff] [blame] | 1026 | if (binder == null) { |
| 1027 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" |
| 1028 | + getName() + " binder is null"); |
| 1029 | } |
| 1030 | if (token == null) { |
| 1031 | throw new IllegalArgumentException("Can't map null token to display=" |
| 1032 | + getName() + " binder=" + binder); |
| 1033 | } |
| 1034 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1035 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1036 | |
| 1037 | if (token.asAppWindowToken() == null) { |
| 1038 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 1039 | // the parent container managing them (e.g. Tasks). |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 1040 | switch (token.windowType) { |
| 1041 | case TYPE_WALLPAPER: |
| 1042 | mBelowAppWindowsContainers.addChild(token); |
| 1043 | break; |
| 1044 | case TYPE_INPUT_METHOD: |
| 1045 | case TYPE_INPUT_METHOD_DIALOG: |
| 1046 | mImeWindowsContainers.addChild(token); |
| 1047 | break; |
| 1048 | default: |
| 1049 | mAboveAppWindowsContainers.addChild(token); |
| 1050 | break; |
| 1051 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1052 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1056 | final WindowToken token = mTokenMap.remove(binder); |
| 1057 | if (token != null && token.asAppWindowToken() == null) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1058 | token.setExiting(); |
| 1059 | } |
| 1060 | return token; |
| 1061 | } |
| 1062 | |
| 1063 | /** Changes the display the input window token is housed on to this one. */ |
| 1064 | void reParentWindowToken(WindowToken token) { |
| 1065 | final DisplayContent prevDc = token.getDisplayContent(); |
| 1066 | if (prevDc == this) { |
| 1067 | return; |
| 1068 | } |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 1069 | if (prevDc != null) { |
| 1070 | if (prevDc.mTokenMap.remove(token.token) != null && token.asAppWindowToken() == null) { |
| 1071 | // Removed the token from the map, but made sure it's not an app token before |
| 1072 | // removing from parent. |
| 1073 | token.getParent().removeChild(token); |
| 1074 | } |
| 1075 | if (prevDc.mLastFocus == mCurrentFocus) { |
| 1076 | // The window has become the focus of this display, so it should not be notified |
| 1077 | // that it lost focus from the previous display. |
| 1078 | prevDc.mLastFocus = null; |
| 1079 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1080 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 1081 | |
| 1082 | addWindowToken(token.token, token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1085 | void removeAppToken(IBinder binder) { |
| 1086 | final WindowToken token = removeWindowToken(binder); |
| 1087 | if (token == null) { |
| 1088 | Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder); |
| 1089 | return; |
| 1090 | } |
| 1091 | |
| 1092 | final AppWindowToken appToken = token.asAppWindowToken(); |
| 1093 | |
| 1094 | if (appToken == null) { |
| 1095 | Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | appToken.onRemovedFromDisplay(); |
| 1100 | } |
| 1101 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1102 | @Override |
| 1103 | public Display getDisplay() { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 1104 | return mDisplay; |
| 1105 | } |
| 1106 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1107 | DisplayInfo getDisplayInfo() { |
| 1108 | return mDisplayInfo; |
| 1109 | } |
| 1110 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 1111 | DisplayMetrics getDisplayMetrics() { |
| 1112 | return mDisplayMetrics; |
| 1113 | } |
| 1114 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1115 | DisplayPolicy getDisplayPolicy() { |
| 1116 | return mDisplayPolicy; |
| 1117 | } |
| 1118 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1119 | @Override |
| 1120 | public DisplayRotation getDisplayRotation() { |
| 1121 | return mDisplayRotation; |
| 1122 | } |
| 1123 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1124 | /** |
| 1125 | * Marks a window as providing insets for the rest of the windows in the system. |
| 1126 | * |
| 1127 | * @param type The type of inset this window provides. |
| 1128 | * @param win The window. |
| 1129 | * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of |
| 1130 | * the window should be taken. |
| 1131 | */ |
| 1132 | void setInsetProvider(@InternalInsetType int type, WindowState win, |
| 1133 | @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider) { |
| 1134 | mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider); |
| 1135 | } |
| 1136 | |
| 1137 | InsetsStateController getInsetsStateController() { |
| 1138 | return mInsetsStateController; |
| 1139 | } |
| 1140 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1141 | @VisibleForTesting |
| 1142 | void setDisplayRotation(DisplayRotation displayRotation) { |
| 1143 | mDisplayRotation = displayRotation; |
| 1144 | } |
| 1145 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1146 | int getRotation() { |
| 1147 | return mRotation; |
| 1148 | } |
| 1149 | |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 1150 | @VisibleForTesting |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1151 | void setRotation(int newRotation) { |
| 1152 | mRotation = newRotation; |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1153 | mDisplayRotation.setRotation(newRotation); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | int getLastOrientation() { |
| 1157 | return mLastOrientation; |
| 1158 | } |
| 1159 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1160 | int getLastWindowForcedOrientation() { |
| 1161 | return mLastWindowForcedOrientation; |
| 1162 | } |
| 1163 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 1164 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 1165 | mAppTransitionController.registerRemoteAnimations(definition); |
| 1166 | } |
| 1167 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1168 | /** |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1169 | * Temporarily pauses rotation changes until resumed. |
| 1170 | * |
| 1171 | * This can be used to prevent rotation changes from occurring while the user is |
| 1172 | * performing certain operations, such as drag and drop. |
| 1173 | * |
| 1174 | * This call nests and must be matched by an equal number of calls to |
| 1175 | * {@link #resumeRotationLocked}. |
| 1176 | */ |
| 1177 | void pauseRotationLocked() { |
| 1178 | mDeferredRotationPauseCount++; |
| 1179 | } |
| 1180 | |
| 1181 | /** |
| 1182 | * Resumes normal rotation changes after being paused. |
| 1183 | */ |
| 1184 | void resumeRotationLocked() { |
| 1185 | if (mDeferredRotationPauseCount <= 0) { |
| 1186 | return; |
| 1187 | } |
| 1188 | |
| 1189 | mDeferredRotationPauseCount--; |
| 1190 | if (mDeferredRotationPauseCount == 0) { |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1191 | updateRotationAndSendNewConfigIfNeeded(); |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | /** |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1196 | * If this is true we have updated our desired orientation, but not yet changed the real |
| 1197 | * orientation our applied our screen rotation animation. For example, because a previous |
| 1198 | * screen rotation was in progress. |
| 1199 | * |
| 1200 | * @return {@code true} if the there is an ongoing rotation change. |
| 1201 | */ |
| 1202 | boolean rotationNeedsUpdate() { |
| 1203 | final int lastOrientation = getLastOrientation(); |
| 1204 | final int oldRotation = getRotation(); |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1205 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1206 | final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation); |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1207 | return oldRotation != rotation; |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1210 | /** |
| 1211 | * The display content may have configuration set from {@link #DisplayWindowSettings}. This |
| 1212 | * callback let the owner of container know there is existing configuration to prevent the |
| 1213 | * values from being replaced by the initializing {@link #ActivityDisplay}. |
| 1214 | */ |
| 1215 | void initializeDisplayOverrideConfiguration() { |
| 1216 | if (mAcitvityDisplay != null) { |
| 1217 | mAcitvityDisplay.onInitializeOverrideConfiguration(getRequestedOverrideConfiguration()); |
| 1218 | } |
| 1219 | } |
| 1220 | |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1221 | /** Notify the configuration change of this display. */ |
| 1222 | void sendNewConfiguration() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1223 | mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget(); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1224 | } |
| 1225 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1226 | @Override |
| 1227 | boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, |
| 1228 | ConfigurationContainer requestingContainer) { |
| 1229 | final Configuration config = updateOrientationFromAppTokens( |
| 1230 | getRequestedOverrideConfiguration(), freezeDisplayToken, false); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1231 | // If display rotation class tells us that it doesn't consider app requested orientation, |
| 1232 | // this display won't rotate just because of an app changes its requested orientation. Thus |
| 1233 | // it indicates that this display chooses not to handle this request. |
| 1234 | final boolean handled = getDisplayRotation().respectAppRequestedOrientation(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1235 | if (config == null) { |
| 1236 | return handled; |
| 1237 | } |
| 1238 | |
| 1239 | if (handled && requestingContainer instanceof ActivityRecord) { |
| 1240 | final ActivityRecord activityRecord = (ActivityRecord) requestingContainer; |
| 1241 | final boolean kept = mWmService.mAtmService.updateDisplayOverrideConfigurationLocked( |
| 1242 | config, activityRecord, false /* deferResume */, getDisplayId()); |
| 1243 | activityRecord.frozenBeforeDestroy = true; |
| 1244 | if (!kept) { |
| 1245 | mWmService.mAtmService.mRootActivityContainer.resumeFocusedStacksTopActivities(); |
| 1246 | } |
| 1247 | } else { |
| 1248 | // We have a new configuration to push so we need to update ATMS for now. |
| 1249 | // TODO: Clean up display configuration push between ATMS and WMS after unification. |
| 1250 | mWmService.mAtmService.updateDisplayOverrideConfigurationLocked( |
| 1251 | config, null /* starting */, false /* deferResume */, getDisplayId()); |
| 1252 | } |
| 1253 | return handled; |
| 1254 | } |
| 1255 | |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1256 | @Override |
| 1257 | boolean handlesOrientationChangeFromDescendant() { |
| 1258 | return getDisplayRotation().respectAppRequestedOrientation(); |
| 1259 | } |
| 1260 | |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1261 | /** |
| 1262 | * Determine the new desired orientation of this display. |
| 1263 | * |
| 1264 | * The orientation is computed from non-application windows first. If none of the |
| 1265 | * non-application windows specify orientation, the orientation is computed from application |
| 1266 | * tokens. |
| 1267 | * |
| 1268 | * @return {@code true} if the orientation is changed. |
| 1269 | */ |
| 1270 | boolean updateOrientationFromAppTokens() { |
| 1271 | return updateOrientationFromAppTokens(false /* forceUpdate */); |
| 1272 | } |
| 1273 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1274 | /** |
| 1275 | * Update orientation of the target display, returning a non-null new Configuration if it has |
| 1276 | * changed from the current orientation. If a non-null configuration is returned, someone must |
| 1277 | * call {@link WindowManagerService#setNewDisplayOverrideConfiguration(Configuration, |
| 1278 | * DisplayContent)} to tell the window manager it can unfreeze the screen. This will typically |
| 1279 | * be done by calling {@link WindowManagerService#sendNewConfiguration(int)}. |
| 1280 | */ |
| 1281 | Configuration updateOrientationFromAppTokens(Configuration currentConfig, |
| 1282 | IBinder freezeDisplayToken, boolean forceUpdate) { |
| 1283 | if (!mDisplayReady) { |
| 1284 | return null; |
| 1285 | } |
| 1286 | |
| 1287 | Configuration config = null; |
| 1288 | if (updateOrientationFromAppTokens(forceUpdate)) { |
| 1289 | // If we changed the orientation but mOrientationChangeComplete is already true, |
| 1290 | // we used seamless rotation, and we don't need to freeze the screen. |
| 1291 | if (freezeDisplayToken != null && !mWmService.mRoot.mOrientationChangeComplete) { |
| 1292 | final AppWindowToken atoken = getAppWindowToken(freezeDisplayToken); |
| 1293 | if (atoken != null) { |
| 1294 | atoken.startFreezingScreen(); |
| 1295 | } |
| 1296 | } |
| 1297 | config = new Configuration(); |
| 1298 | computeScreenConfiguration(config); |
| 1299 | } else if (currentConfig != null) { |
| 1300 | // No obvious action we need to take, but if our current state mismatches the |
| 1301 | // activity manager's, update it, disregarding font scale, which should remain set |
| 1302 | // to the value of the previous configuration. |
| 1303 | // Here we're calling Configuration#unset() instead of setToDefaults() because we |
| 1304 | // need to keep override configs clear of non-empty values (e.g. fontSize). |
| 1305 | mTmpConfiguration.unset(); |
| 1306 | mTmpConfiguration.updateFrom(currentConfig); |
| 1307 | computeScreenConfiguration(mTmpConfiguration); |
| 1308 | if (currentConfig.diff(mTmpConfiguration) != 0) { |
| 1309 | mWaitingForConfig = true; |
| 1310 | setLayoutNeeded(); |
| 1311 | int[] anim = new int[2]; |
| 1312 | getDisplayPolicy().selectRotationAnimationLw(anim); |
| 1313 | |
| 1314 | mWmService.startFreezingDisplayLocked(anim[0], anim[1], this); |
| 1315 | config = new Configuration(mTmpConfiguration); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | return config; |
| 1320 | } |
| 1321 | |
| 1322 | |
| 1323 | private boolean updateOrientationFromAppTokens(boolean forceUpdate) { |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1324 | final int req = getOrientation(); |
| 1325 | if (req != mLastOrientation || forceUpdate) { |
| 1326 | mLastOrientation = req; |
| 1327 | mDisplayRotation.setCurrentOrientation(req); |
| 1328 | return updateRotationUnchecked(forceUpdate); |
| 1329 | } |
| 1330 | return false; |
| 1331 | } |
| 1332 | |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1333 | /** |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1334 | * Update rotation of the display and send configuration if the rotation is changed. |
| 1335 | * |
| 1336 | * @return {@code true} if the rotation has been changed and the new config is sent. |
| 1337 | */ |
| 1338 | boolean updateRotationAndSendNewConfigIfNeeded() { |
| 1339 | final boolean changed = updateRotationUnchecked(false /* forceUpdate */); |
| 1340 | if (changed) { |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1341 | sendNewConfiguration(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1342 | } |
| 1343 | return changed; |
| 1344 | } |
| 1345 | |
| 1346 | /** |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1347 | * Update rotation of the display. |
| 1348 | * |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1349 | * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL |
| 1350 | * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN. |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1351 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1352 | boolean updateRotationUnchecked() { |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1353 | return updateRotationUnchecked(false /* forceUpdate */); |
| 1354 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1355 | |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1356 | /** |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1357 | * Update rotation of the DisplayContent with an option to force the update. This updates |
| 1358 | * the container's perception of rotation and, depending on the top activities, will freeze |
| 1359 | * the screen or start seamless rotation. The display itself gets rotated in |
| 1360 | * {@link #applyRotationLocked} during {@link WindowManagerService#sendNewConfiguration}. |
| 1361 | * |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1362 | * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating |
| 1363 | * orientation because we're waiting for some rotation to finish or display |
| 1364 | * to unfreeze, which results in configuration of the previously visible |
| 1365 | * activity being applied to a newly visible one. Forcing the rotation |
| 1366 | * update allows to workaround this issue. |
| 1367 | * @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] | 1368 | * {@link WindowManagerService#sendNewConfiguration(int)} TO COMPLETE THE ROTATION AND |
| 1369 | * UNFREEZE THE SCREEN. |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1370 | */ |
| 1371 | boolean updateRotationUnchecked(boolean forceUpdate) { |
| 1372 | ScreenRotationAnimation screenRotationAnimation; |
| 1373 | if (!forceUpdate) { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1374 | if (mDeferredRotationPauseCount > 0) { |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1375 | // Rotation updates have been paused temporarily. Defer the update until |
| 1376 | // updates have been resumed. |
| 1377 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused."); |
| 1378 | return false; |
| 1379 | } |
| 1380 | |
| 1381 | screenRotationAnimation = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1382 | mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId); |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1383 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { |
| 1384 | // Rotation updates cannot be performed while the previous rotation change |
| 1385 | // animation is still in progress. Skip this update. We will try updating |
| 1386 | // again after the animation is finished and the display is unfrozen. |
| 1387 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress."); |
| 1388 | return false; |
| 1389 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1390 | if (mWmService.mDisplayFrozen) { |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1391 | // Even if the screen rotation animation has finished (e.g. isAnimating |
| 1392 | // returns false), there is still some time where we haven't yet unfrozen |
| 1393 | // the display. We also need to abort rotation here. |
| 1394 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 1395 | "Deferring rotation, still finishing previous rotation"); |
| 1396 | return false; |
| 1397 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1400 | if (!mWmService.mDisplayEnabled) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1401 | // No point choosing a rotation if the display is not enabled. |
| 1402 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled."); |
| 1403 | return false; |
| 1404 | } |
| 1405 | |
| 1406 | final int oldRotation = mRotation; |
| 1407 | final int lastOrientation = mLastOrientation; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1408 | final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation); |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 1409 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id=" |
| 1410 | + mDisplayId + " based on lastOrientation=" + lastOrientation |
| 1411 | + " and oldRotation=" + oldRotation); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1412 | boolean mayRotateSeamlessly = mDisplayPolicy.shouldRotateSeamlessly(mDisplayRotation, |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1413 | oldRotation, rotation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1414 | |
Robert Carr | 0e00727 | 2017-10-02 13:00:55 -0700 | [diff] [blame] | 1415 | if (mayRotateSeamlessly) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1416 | final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated); |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1417 | if (seamlessRotated != null && !forceUpdate) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1418 | // We can't rotate (seamlessly or not) while waiting for the last seamless rotation |
| 1419 | // to complete (that is, waiting for windows to redraw). It's tempting to check |
| 1420 | // w.mSeamlessRotationCount but that could be incorrect in the case of |
| 1421 | // window-removal. |
| 1422 | return false; |
| 1423 | } |
Robert Carr | 0e00727 | 2017-10-02 13:00:55 -0700 | [diff] [blame] | 1424 | |
| 1425 | // In the presence of the PINNED stack or System Alert |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1426 | // windows we unfortunately can not seamlessly rotate. |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1427 | if (hasPinnedStack()) { |
Robert Carr | 0e00727 | 2017-10-02 13:00:55 -0700 | [diff] [blame] | 1428 | mayRotateSeamlessly = false; |
| 1429 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1430 | for (int i = 0; i < mWmService.mSessions.size(); i++) { |
| 1431 | if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces()) { |
Robert Carr | 0e00727 | 2017-10-02 13:00:55 -0700 | [diff] [blame] | 1432 | mayRotateSeamlessly = false; |
| 1433 | break; |
| 1434 | } |
| 1435 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1436 | } |
Robert Carr | 0e00727 | 2017-10-02 13:00:55 -0700 | [diff] [blame] | 1437 | final boolean rotateSeamlessly = mayRotateSeamlessly; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1438 | |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 1439 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId |
| 1440 | + " selected orientation " + lastOrientation |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 1441 | + ", got rotation " + rotation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1442 | |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1443 | if (oldRotation == rotation) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1444 | // No change. |
| 1445 | return false; |
| 1446 | } |
| 1447 | |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 1448 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId |
| 1449 | + " rotation changed to " + rotation |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1450 | + " from " + oldRotation |
| 1451 | + ", lastOrientation=" + lastOrientation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1452 | |
| 1453 | if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) { |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 1454 | mWaitingForConfig = true; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1457 | mRotation = rotation; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1458 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1459 | mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE; |
| 1460 | mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT, |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1461 | this, WINDOW_FREEZE_TIMEOUT_DURATION); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1462 | |
| 1463 | setLayoutNeeded(); |
| 1464 | final int[] anim = new int[2]; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1465 | mDisplayPolicy.selectRotationAnimationLw(anim); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1466 | |
| 1467 | if (!rotateSeamlessly) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1468 | mWmService.startFreezingDisplayLocked(anim[0], anim[1], this); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1469 | // startFreezingDisplayLocked can reset the ScreenRotationAnimation. |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1470 | } else { |
| 1471 | // The screen rotation animation uses a screenshot to freeze the screen |
| 1472 | // while windows resize underneath. |
| 1473 | // When we are rotating seamlessly, we allow the elements to transition |
| 1474 | // to their rotated state independently and without a freeze required. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1475 | mWmService.startSeamlessRotation(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1478 | return true; |
| 1479 | } |
| 1480 | |
| 1481 | /** |
| 1482 | * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked} |
| 1483 | * (if it returned {@code true}) to actually finish the rotation. |
| 1484 | * |
| 1485 | * @param oldRotation the rotation we are coming from. |
| 1486 | * @param rotation the rotation to apply. |
| 1487 | */ |
| 1488 | void applyRotationLocked(final int oldRotation, final int rotation) { |
| 1489 | mDisplayRotation.setRotation(rotation); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1490 | final boolean rotateSeamlessly = mWmService.isRotatingSeamlessly(); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1491 | ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1492 | ? null : mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1493 | // We need to update our screen size information to match the new rotation. If the rotation |
| 1494 | // has actually changed then this method will return true and, according to the comment at |
| 1495 | // the top of the method, the caller is obligated to call computeNewConfigurationLocked(). |
| 1496 | // By updating the Display info here it will be available to |
| 1497 | // #computeScreenConfiguration() later. |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1498 | updateDisplayAndOrientation(getConfiguration().uiMode, null /* outConfig */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1499 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1500 | // NOTE: We disable the rotation in the emulator because |
| 1501 | // it doesn't support hardware OpenGL emulation yet. |
| 1502 | if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null |
| 1503 | && screenRotationAnimation.hasScreenshot()) { |
| 1504 | if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1505 | MAX_ANIMATION_DURATION, mWmService.getTransitionAnimationScaleLocked(), |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1506 | mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1507 | mWmService.scheduleAnimationLocked(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1508 | } |
| 1509 | } |
| 1510 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1511 | forAllWindows(w -> { |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 1512 | w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation, |
| 1513 | rotateSeamlessly); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 1514 | }, true /* traverseTopToBottom */); |
| 1515 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1516 | mWmService.mDisplayManagerInternal.performTraversal(getPendingTransaction()); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 1517 | scheduleAnimation(); |
| 1518 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1519 | forAllWindows(w -> { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1520 | if (w.mHasSurface && !rotateSeamlessly) { |
| 1521 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1522 | w.setOrientationChanging(true); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1523 | mWmService.mRoot.mOrientationChangeComplete = false; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1524 | w.mLastFreezeDuration = 0; |
| 1525 | } |
| 1526 | w.mReportOrientationChanged = true; |
| 1527 | }, true /* traverseTopToBottom */); |
| 1528 | |
| 1529 | if (rotateSeamlessly) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1530 | mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT, |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 1531 | this, SEAMLESS_ROTATION_TIMEOUT_DURATION); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1534 | for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1535 | final WindowManagerService.RotationWatcher rotationWatcher |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1536 | = mWmService.mRotationWatchers.get(i); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1537 | if (rotationWatcher.mDisplayId == mDisplayId) { |
| 1538 | try { |
| 1539 | rotationWatcher.mWatcher.onRotationChanged(rotation); |
| 1540 | } catch (RemoteException e) { |
| 1541 | // Ignore |
| 1542 | } |
| 1543 | } |
| 1544 | } |
| 1545 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1546 | // Announce rotation only if we will not animate as we already have the |
| 1547 | // 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] | 1548 | if (screenRotationAnimation == null && mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1549 | mWmService.mAccessibilityController.onRotationChangedLocked(this); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1550 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1553 | void configureDisplayPolicy() { |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1554 | final int width = mBaseDisplayWidth; |
| 1555 | final int height = mBaseDisplayHeight; |
| 1556 | final int shortSize; |
| 1557 | final int longSize; |
| 1558 | if (width > height) { |
| 1559 | shortSize = height; |
| 1560 | longSize = width; |
| 1561 | } else { |
| 1562 | shortSize = width; |
| 1563 | longSize = height; |
| 1564 | } |
| 1565 | |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 1566 | final int shortSizeDp = shortSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
| 1567 | final int longSizeDp = longSize * DENSITY_DEFAULT / mBaseDisplayDensity; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 1568 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1569 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 1570 | mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1571 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1572 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 1573 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 1574 | |
| 1575 | // Not much of use to rotate the display for apps since it's close to square. |
| 1576 | mIgnoreRotationForApps = isNonDecorDisplayCloseToSquare(Surface.ROTATION_0, width, height); |
| 1577 | } |
| 1578 | |
| 1579 | private boolean isNonDecorDisplayCloseToSquare(int rotation, int width, int height) { |
| 1580 | final DisplayCutout displayCutout = |
| 1581 | calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
| 1582 | final int uiMode = mWmService.mPolicy.getUiMode(); |
| 1583 | final int w = mDisplayPolicy.getNonDecorDisplayWidth( |
| 1584 | width, height, rotation, uiMode, displayCutout); |
| 1585 | final int h = mDisplayPolicy.getNonDecorDisplayHeight( |
| 1586 | width, height, rotation, uiMode, displayCutout); |
| 1587 | final float aspectRatio = Math.max(w, h) / (float) Math.min(w, h); |
| 1588 | return aspectRatio <= mCloseToSquareMaxAspectRatio; |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1591 | /** |
| 1592 | * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config |
| 1593 | * changed. |
| 1594 | * Do not call if {@link WindowManagerService#mDisplayReady} == false. |
| 1595 | */ |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1596 | private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1597 | // Use the effective "visual" dimensions based on current rotation |
| 1598 | final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270); |
Garfield Tan | 4bb8347 | 2019-01-16 14:37:04 -0800 | [diff] [blame] | 1599 | final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1600 | final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1601 | |
| 1602 | // Update application display metrics. |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1603 | final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation); |
| 1604 | final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout(); |
| 1605 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1606 | final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode, |
| 1607 | displayCutout); |
| 1608 | final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode, |
| 1609 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1610 | mDisplayInfo.rotation = mRotation; |
| 1611 | mDisplayInfo.logicalWidth = dw; |
| 1612 | mDisplayInfo.logicalHeight = dh; |
| 1613 | mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity; |
| 1614 | mDisplayInfo.appWidth = appWidth; |
| 1615 | mDisplayInfo.appHeight = appHeight; |
| 1616 | if (isDefaultDisplay) { |
| 1617 | mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics, |
| 1618 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
| 1619 | } |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1620 | mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1621 | mDisplayInfo.getAppMetrics(mDisplayMetrics); |
| 1622 | if (mDisplayScalingDisabled) { |
| 1623 | mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED; |
| 1624 | } else { |
| 1625 | mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED; |
| 1626 | } |
| 1627 | |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1628 | computeSizeRangesAndScreenLayout(mDisplayInfo, rotated, uiMode, dw, dh, |
| 1629 | mDisplayMetrics.density, outConfig); |
| 1630 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1631 | // We usually set the override info in DisplayManager so that we get consistent display |
| 1632 | // metrics values when displays are changing and don't send out new values until WM is aware |
| 1633 | // of them. However, we don't do this for displays that serve as containers for ActivityView |
| 1634 | // because we don't want letter-/pillar-boxing during resize. |
| 1635 | final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration |
| 1636 | ? mDisplayInfo : null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1637 | mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId, |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 1638 | overrideDisplayInfo); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1639 | |
| 1640 | mBaseDisplayRect.set(0, 0, dw, dh); |
| 1641 | |
| 1642 | if (isDefaultDisplay) { |
| 1643 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics, |
| 1644 | mCompatDisplayMetrics); |
| 1645 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1646 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1647 | return mDisplayInfo; |
| 1648 | } |
| 1649 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1650 | WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) { |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1651 | return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation); |
| 1652 | } |
| 1653 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1654 | private WmDisplayCutout calculateDisplayCutoutForRotationUncached( |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 1655 | DisplayCutout cutout, int rotation) { |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1656 | if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1657 | return WmDisplayCutout.NO_CUTOUT; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1658 | } |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1659 | if (rotation == ROTATION_0) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1660 | return WmDisplayCutout.computeSafeInsets( |
| 1661 | cutout, mInitialDisplayWidth, mInitialDisplayHeight); |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1662 | } |
Adrian Roos | bed538e | 2018-02-21 17:50:07 +0100 | [diff] [blame] | 1663 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1664 | final Rect[] newBounds = mRotationUtil.getRotatedBounds( |
| 1665 | WmDisplayCutout.computeSafeInsets( |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 1666 | cutout, mInitialDisplayWidth, mInitialDisplayHeight) |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 1667 | .getDisplayCutout().getBoundingRectsAll(), |
| 1668 | rotation, mInitialDisplayWidth, mInitialDisplayHeight); |
| 1669 | return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds), |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 1670 | rotated ? mInitialDisplayHeight : mInitialDisplayWidth, |
| 1671 | rotated ? mInitialDisplayWidth : mInitialDisplayHeight); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1674 | /** |
| 1675 | * Compute display configuration based on display properties and policy settings. |
| 1676 | * Do not call if mDisplayReady == false. |
| 1677 | */ |
| 1678 | void computeScreenConfiguration(Configuration config) { |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1679 | final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode, config); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1680 | calculateBounds(displayInfo, mTmpBounds); |
| 1681 | config.windowConfiguration.setBounds(mTmpBounds); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1682 | |
| 1683 | final int dw = displayInfo.logicalWidth; |
| 1684 | final int dh = displayInfo.logicalHeight; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 1685 | config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 1686 | config.windowConfiguration.setWindowingMode(getWindowingMode()); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 1687 | config.windowConfiguration.setDisplayWindowingMode(getWindowingMode()); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1688 | config.windowConfiguration.setRotation(displayInfo.rotation); |
Bryce Lee | c1f2f2a | 2017-06-22 15:29:42 -0700 | [diff] [blame] | 1689 | |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1690 | final float density = mDisplayMetrics.density; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1691 | config.screenWidthDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1692 | (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation, |
| 1693 | config.uiMode, displayInfo.displayCutout) / density); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1694 | config.screenHeightDp = |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1695 | (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation, |
| 1696 | config.uiMode, displayInfo.displayCutout) / density); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1697 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1698 | mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 1699 | displayInfo.displayCutout, mTmpRect); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1700 | final int leftInset = mTmpRect.left; |
| 1701 | final int topInset = mTmpRect.top; |
| 1702 | // appBounds at the root level should mirror the app screen size. |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1703 | config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */, |
| 1704 | leftInset + displayInfo.appWidth /* right */, |
| 1705 | topInset + displayInfo.appHeight /* bottom */); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1706 | final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90 |
| 1707 | || displayInfo.rotation == Surface.ROTATION_270); |
| 1708 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1709 | config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) |
| 1710 | | ((displayInfo.flags & Display.FLAG_ROUND) != 0 |
| 1711 | ? Configuration.SCREENLAYOUT_ROUND_YES |
| 1712 | : Configuration.SCREENLAYOUT_ROUND_NO); |
| 1713 | |
| 1714 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 1715 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 1716 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1717 | dh, displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1718 | config.densityDpi = displayInfo.logicalDensityDpi; |
| 1719 | |
| 1720 | config.colorMode = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1721 | ((displayInfo.isHdr() && mWmService.hasHdrSupport()) |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1722 | ? Configuration.COLOR_MODE_HDR_YES |
| 1723 | : Configuration.COLOR_MODE_HDR_NO) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1724 | | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport() |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1725 | ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES |
| 1726 | : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO); |
| 1727 | |
| 1728 | // Update the configuration based on available input devices, lid switch, |
| 1729 | // and platform configuration. |
| 1730 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1731 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 1732 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 1733 | |
| 1734 | int keyboardPresence = 0; |
| 1735 | int navigationPresence = 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1736 | final InputDevice[] devices = mWmService.mInputManager.getInputDevices(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1737 | final int len = devices != null ? devices.length : 0; |
| 1738 | for (int i = 0; i < len; i++) { |
| 1739 | InputDevice device = devices[i]; |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1740 | // Ignore virtual input device. |
| 1741 | if (device.isVirtual()) { |
| 1742 | continue; |
| 1743 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1744 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1745 | // Check if input device can dispatch events to current display. |
| 1746 | // If display type is virtual, will follow the default display. |
| 1747 | if (!mWmService.mInputManager.canDispatchToDisplay(device.getId(), |
| 1748 | displayInfo.type == Display.TYPE_VIRTUAL ? DEFAULT_DISPLAY : mDisplayId)) { |
| 1749 | continue; |
| 1750 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1751 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1752 | final int sources = device.getSources(); |
| 1753 | final int presenceFlag = device.isExternal() |
| 1754 | ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1755 | |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1756 | if (mWmService.mIsTouchDevice) { |
| 1757 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { |
| 1758 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1759 | } |
Arthur Hung | 82bbfc3 | 2018-11-29 20:24:51 +0800 | [diff] [blame] | 1760 | } else { |
| 1761 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1762 | } |
| 1763 | |
| 1764 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
| 1765 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 1766 | navigationPresence |= presenceFlag; |
| 1767 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
| 1768 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 1769 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1770 | navigationPresence |= presenceFlag; |
| 1771 | } |
| 1772 | |
| 1773 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 1774 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 1775 | keyboardPresence |= presenceFlag; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1779 | if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1780 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1781 | navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL; |
| 1782 | } |
| 1783 | |
| 1784 | // Determine whether a hard keyboard is available and enabled. |
| 1785 | // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device? |
| 1786 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1787 | if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) { |
| 1788 | mWmService.mHardKeyboardAvailable = hardKeyboardAvailable; |
| 1789 | mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 1790 | mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 1793 | mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1794 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1795 | // Let the policy update hidden states. |
| 1796 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 1797 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 1798 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1799 | mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1803 | DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1804 | mTmpDisplayMetrics.setTo(mDisplayMetrics); |
| 1805 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 1806 | final int unrotDw, unrotDh; |
| 1807 | if (rotated) { |
| 1808 | unrotDw = dh; |
| 1809 | unrotDh = dw; |
| 1810 | } else { |
| 1811 | unrotDw = dw; |
| 1812 | unrotDh = dh; |
| 1813 | } |
| 1814 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1815 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1816 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1817 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1818 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1819 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1820 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1821 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1822 | return sw; |
| 1823 | } |
| 1824 | |
| 1825 | private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1826 | DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) { |
| 1827 | dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
| 1828 | displayCutout); |
| 1829 | dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, |
| 1830 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1831 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
| 1832 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
| 1833 | if (curSize == 0 || size < curSize) { |
| 1834 | curSize = size; |
| 1835 | } |
| 1836 | return curSize; |
| 1837 | } |
| 1838 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1839 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 1840 | int uiMode, int dw, int dh, float density, Configuration outConfig) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1841 | |
| 1842 | // We need to determine the smallest width that will occur under normal |
| 1843 | // operation. To this, start with the base screen size and compute the |
| 1844 | // width under the different possible rotations. We need to un-rotate |
| 1845 | // the current screen dimensions before doing this. |
| 1846 | int unrotDw, unrotDh; |
| 1847 | if (rotated) { |
| 1848 | unrotDw = dh; |
| 1849 | unrotDh = dw; |
| 1850 | } else { |
| 1851 | unrotDw = dw; |
| 1852 | unrotDh = dh; |
| 1853 | } |
| 1854 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 1855 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 1856 | displayInfo.largestNominalAppWidth = 0; |
| 1857 | displayInfo.largestNominalAppHeight = 0; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1858 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh); |
| 1859 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw); |
| 1860 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh); |
| 1861 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw); |
Tiger Huang | a817b1f | 2019-05-09 20:04:17 +0800 | [diff] [blame] | 1862 | |
| 1863 | if (outConfig == null) { |
| 1864 | return; |
| 1865 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1866 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
| 1867 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1868 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1869 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1870 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1871 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1872 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1873 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1874 | displayInfo.displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1875 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
| 1876 | outConfig.screenLayout = sl; |
| 1877 | } |
| 1878 | |
| 1879 | 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] | 1880 | int uiMode, DisplayCutout displayCutout) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1881 | // Get the app screen size at this rotation. |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1882 | int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout); |
| 1883 | int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1884 | |
| 1885 | // Compute the screen layout size class for this rotation. |
| 1886 | int longSize = w; |
| 1887 | int shortSize = h; |
| 1888 | if (longSize < shortSize) { |
| 1889 | int tmp = longSize; |
| 1890 | longSize = shortSize; |
| 1891 | shortSize = tmp; |
| 1892 | } |
| 1893 | longSize = (int)(longSize/density); |
| 1894 | shortSize = (int)(shortSize/density); |
| 1895 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
| 1896 | } |
| 1897 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1898 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1899 | int uiMode, int dw, int dh) { |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 1900 | final DisplayCutout displayCutout = calculateDisplayCutoutForRotation( |
| 1901 | rotation).getDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1902 | final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode, |
| 1903 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1904 | if (width < displayInfo.smallestNominalAppWidth) { |
| 1905 | displayInfo.smallestNominalAppWidth = width; |
| 1906 | } |
| 1907 | if (width > displayInfo.largestNominalAppWidth) { |
| 1908 | displayInfo.largestNominalAppWidth = width; |
| 1909 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1910 | final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode, |
| 1911 | displayCutout); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1912 | if (height < displayInfo.smallestNominalAppHeight) { |
| 1913 | displayInfo.smallestNominalAppHeight = height; |
| 1914 | } |
| 1915 | if (height > displayInfo.largestNominalAppHeight) { |
| 1916 | displayInfo.largestNominalAppHeight = height; |
| 1917 | } |
| 1918 | } |
| 1919 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 1920 | /** |
| 1921 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 1922 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 1923 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 1924 | * This lowers the travel distance between invoking the menu panel and selecting |
| 1925 | * a menu option. |
| 1926 | * |
| 1927 | * This method helps control where that menu is placed. Its current implementation makes |
| 1928 | * assumptions about the menu key and its relationship to the screen based on whether |
| 1929 | * the device's natural orientation is portrait (width < height) or landscape. |
| 1930 | * |
| 1931 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 1932 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 1933 | * do not hold for the target device, this method should be changed to reflect that. |
| 1934 | * |
| 1935 | * @return A {@link Gravity} value for placing the options menu window. |
| 1936 | */ |
| 1937 | int getPreferredOptionsPanelGravity() { |
| 1938 | final int rotation = getRotation(); |
| 1939 | if (mInitialDisplayWidth < mInitialDisplayHeight) { |
| 1940 | // On devices with a natural orientation of portrait. |
| 1941 | switch (rotation) { |
| 1942 | default: |
| 1943 | case Surface.ROTATION_0: |
| 1944 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1945 | case Surface.ROTATION_90: |
| 1946 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1947 | case Surface.ROTATION_180: |
| 1948 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1949 | case Surface.ROTATION_270: |
| 1950 | return Gravity.START | Gravity.BOTTOM; |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | // On devices with a natural orientation of landscape. |
| 1955 | switch (rotation) { |
| 1956 | default: |
| 1957 | case Surface.ROTATION_0: |
| 1958 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 1959 | case Surface.ROTATION_90: |
| 1960 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1961 | case Surface.ROTATION_180: |
| 1962 | return Gravity.START | Gravity.BOTTOM; |
| 1963 | case Surface.ROTATION_270: |
| 1964 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 1965 | } |
| 1966 | } |
| 1967 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 1968 | DockedStackDividerController getDockedDividerController() { |
| 1969 | return mDividerControllerLocked; |
| 1970 | } |
| 1971 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1972 | PinnedStackController getPinnedStackController() { |
| 1973 | return mPinnedStackControllerLocked; |
| 1974 | } |
| 1975 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1976 | /** |
| 1977 | * Returns true if the specified UID has access to this display. |
| 1978 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1979 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1980 | return mDisplay.hasAccess(uid); |
| 1981 | } |
| 1982 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1983 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1984 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 1987 | TaskStack getHomeStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1988 | return mTaskStackContainers.getHomeStack(); |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1991 | /** |
| 1992 | * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise. |
| 1993 | */ |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 1994 | TaskStack getSplitScreenPrimaryStack() { |
| 1995 | TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1996 | return (stack != null && stack.isVisible()) ? stack : null; |
| 1997 | } |
| 1998 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 1999 | boolean hasSplitScreenPrimaryStack() { |
| 2000 | return getSplitScreenPrimaryStack() != null; |
| 2001 | } |
| 2002 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2003 | /** |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2004 | * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2005 | * not visible. |
| 2006 | */ |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2007 | TaskStack getSplitScreenPrimaryStackIgnoringVisibility() { |
| 2008 | return mTaskStackContainers.getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | TaskStack getPinnedStack() { |
| 2012 | return mTaskStackContainers.getPinnedStack(); |
| 2013 | } |
| 2014 | |
| 2015 | private boolean hasPinnedStack() { |
| 2016 | return mTaskStackContainers.getPinnedStack() != null; |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 2019 | /** |
| 2020 | * Returns the topmost stack on the display that is compatible with the input windowing mode. |
| 2021 | * Null is no compatible stack on the display. |
| 2022 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 2023 | TaskStack getTopStackInWindowingMode(int windowingMode) { |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 2024 | return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED); |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * Returns the topmost stack on the display that is compatible with the input windowing mode and |
| 2029 | * activity type. Null is no compatible stack on the display. |
| 2030 | */ |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2031 | TaskStack getStack(int windowingMode, int activityType) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2032 | return mTaskStackContainers.getStack(windowingMode, activityType); |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 2035 | @VisibleForTesting |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 2036 | WindowList<TaskStack> getStacks() { |
| 2037 | return mTaskStackContainers.mChildren; |
| 2038 | } |
| 2039 | |
| 2040 | @VisibleForTesting |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2041 | TaskStack getTopStack() { |
| 2042 | return mTaskStackContainers.getTopStack(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 2045 | ArrayList<Task> getVisibleTasks() { |
| 2046 | return mTaskStackContainers.getVisibleTasks(); |
| 2047 | } |
| 2048 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2049 | void onStackWindowingModeChanged(TaskStack stack) { |
| 2050 | mTaskStackContainers.onStackWindowingModeChanged(stack); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2053 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 2054 | public void onConfigurationChanged(Configuration newParentConfig) { |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2055 | final int lastOrientation = getConfiguration().orientation; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2056 | super.onConfigurationChanged(newParentConfig); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2057 | if (mDisplayPolicy != null) { |
| 2058 | mDisplayPolicy.onConfigurationChanged(); |
| 2059 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2060 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 2061 | if (lastOrientation != getConfiguration().orientation) { |
| 2062 | getMetricsLogger().write( |
| 2063 | new LogMaker(MetricsEvent.ACTION_PHONE_ORIENTATION_CHANGED) |
| 2064 | .setSubtype(getConfiguration().orientation) |
| 2065 | .addTaggedData(MetricsEvent.FIELD_DISPLAY_ID, getDisplayId())); |
| 2066 | } |
| 2067 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2068 | // If there was no pinned stack, we still need to notify the controller of the display info |
| 2069 | // update as a result of the config change. |
| 2070 | if (mPinnedStackControllerLocked != null && !hasPinnedStack()) { |
| 2071 | mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo()); |
| 2072 | } |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | /** |
| 2076 | * Updates the resources used by docked/pinned controllers. This needs to be called at the |
| 2077 | * beginning of a configuration update cascade since the metrics from these resources are used |
| 2078 | * for bounds calculations. Since ActivityDisplay initiates the configuration update, this |
| 2079 | * should be called from there instead of DisplayContent's onConfigurationChanged. |
| 2080 | */ |
| 2081 | void preOnConfigurationChanged() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2082 | final DockedStackDividerController dividerController = getDockedDividerController(); |
| 2083 | |
| 2084 | if (dividerController != null) { |
| 2085 | getDockedDividerController().onConfigurationChanged(); |
| 2086 | } |
| 2087 | |
| 2088 | final PinnedStackController pinnedStackController = getPinnedStackController(); |
| 2089 | |
| 2090 | if (pinnedStackController != null) { |
| 2091 | getPinnedStackController().onConfigurationChanged(); |
| 2092 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 2093 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 2094 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 2095 | @Override |
| 2096 | boolean fillsParent() { |
| 2097 | return true; |
| 2098 | } |
| 2099 | |
| 2100 | @Override |
| 2101 | boolean isVisible() { |
| 2102 | return true; |
| 2103 | } |
| 2104 | |
| 2105 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2106 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2107 | super.onAppTransitionDone(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2108 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 2111 | @Override |
| 2112 | public void setWindowingMode(int windowingMode) { |
| 2113 | super.setWindowingMode(windowingMode); |
| 2114 | super.setDisplayWindowingMode(windowingMode); |
| 2115 | } |
| 2116 | |
| 2117 | @Override |
| 2118 | void setDisplayWindowingMode(int windowingMode) { |
| 2119 | setWindowingMode(windowingMode); |
| 2120 | } |
| 2121 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 2122 | /** |
| 2123 | * In split-screen mode we process the IME containers above the docked divider |
| 2124 | * rather than directly above their target. |
| 2125 | */ |
| 2126 | private boolean skipTraverseChild(WindowContainer child) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 2127 | if (child == mImeWindowsContainers && mInputMethodTarget != null |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 2128 | && !hasSplitScreenPrimaryStack()) { |
| 2129 | return true; |
| 2130 | } |
| 2131 | return false; |
| 2132 | } |
| 2133 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 2134 | @Override |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2135 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 2136 | // Special handling so we can process IME windows with #forAllImeWindows above their IME |
| 2137 | // target, or here in order if there isn't an IME target. |
| 2138 | if (traverseTopToBottom) { |
| 2139 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 2140 | final DisplayChildWindowContainer child = mChildren.get(i); |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 2141 | if (skipTraverseChild(child)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2142 | continue; |
| 2143 | } |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 2144 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2145 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 2146 | return true; |
| 2147 | } |
| 2148 | } |
| 2149 | } else { |
| 2150 | final int count = mChildren.size(); |
| 2151 | for (int i = 0; i < count; i++) { |
| 2152 | final DisplayChildWindowContainer child = mChildren.get(i); |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 2153 | if (skipTraverseChild(child)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2154 | continue; |
| 2155 | } |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 2156 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 2157 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 2158 | return true; |
| 2159 | } |
| 2160 | } |
| 2161 | } |
| 2162 | return false; |
| 2163 | } |
| 2164 | |
| 2165 | boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 2166 | return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom); |
| 2167 | } |
| 2168 | |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 2169 | @Override |
| 2170 | int getOrientation() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2171 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2172 | |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 2173 | if (mIgnoreRotationForApps) { |
| 2174 | return SCREEN_ORIENTATION_USER; |
| 2175 | } |
| 2176 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2177 | if (mWmService.mDisplayFrozen) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2178 | if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 2179 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId |
| 2180 | + " is frozen, return " + mLastWindowForcedOrientation); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2181 | // If the display is frozen, some activities may be in the middle of restarting, and |
| 2182 | // thus have removed their old window. If the window has the flag to hide the lock |
| 2183 | // screen, then the lock screen can re-appear and inflict its own orientation on us. |
| 2184 | // Keep the orientation stable until this all settles down. |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2185 | return mLastWindowForcedOrientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2186 | } else if (policy.isKeyguardLocked()) { |
| 2187 | // Use the last orientation the while the display is frozen with the keyguard |
| 2188 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 2189 | // window. We don't want to check the show when locked window directly though as |
| 2190 | // things aren't stable while the display is frozen, for example the window could be |
| 2191 | // momentarily unavailable due to activity relaunch. |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 2192 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId |
| 2193 | + " is frozen while keyguard locked, return " + mLastOrientation); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2194 | return mLastOrientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2195 | } |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2196 | } else { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2197 | final int orientation = mAboveAppWindowsContainers.getOrientation(); |
| 2198 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 2199 | return orientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2200 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
Wale Ogunwale | 399c869 | 2017-05-08 14:22:42 -0700 | [diff] [blame] | 2203 | // Top system windows are not requesting an orientation. Start searching from apps. |
| 2204 | return mTaskStackContainers.getOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2207 | void updateDisplayInfo() { |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2208 | // Check if display metrics changed and update base values if needed. |
| 2209 | updateBaseDisplayMetricsIfNeeded(); |
| 2210 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2211 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 2212 | mDisplay.getMetrics(mDisplayMetrics); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2213 | |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 2214 | onDisplayChanged(this); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 2217 | @Override |
| 2218 | void onDisplayChanged(DisplayContent dc) { |
| 2219 | super.onDisplayChanged(dc); |
| 2220 | updateSystemGestureExclusionLimit(); |
| 2221 | } |
| 2222 | |
| 2223 | void updateSystemGestureExclusionLimit() { |
| 2224 | mSystemGestureExclusionLimit = mWmService.mSystemGestureExclusionLimitDp |
| 2225 | * mDisplayMetrics.densityDpi / DENSITY_DEFAULT; |
| 2226 | updateSystemGestureExclusion(); |
| 2227 | } |
| 2228 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2229 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2230 | final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2231 | if (displayManagerInternal != null) { |
| 2232 | // Bootstrap the default logical display from the display manager. |
| 2233 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 2234 | if (newDisplayInfo != null) { |
| 2235 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 2236 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2237 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 2238 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2239 | updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight, |
| 2240 | mDisplayInfo.logicalDensityDpi); |
| 2241 | mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 2242 | mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 2243 | mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2244 | mInitialDisplayCutout = mDisplayInfo.displayCutout; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2247 | /** |
| 2248 | * If display metrics changed, overrides are not set and it's not just a rotation - update base |
| 2249 | * values. |
| 2250 | */ |
| 2251 | private void updateBaseDisplayMetricsIfNeeded() { |
| 2252 | // Get real display metrics without overrides from WM. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2253 | mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2254 | final int orientation = mDisplayInfo.rotation; |
| 2255 | final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
| 2256 | final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth; |
| 2257 | final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight; |
| 2258 | final int newDensity = mDisplayInfo.logicalDensityDpi; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2259 | final DisplayCutout newCutout = mDisplayInfo.displayCutout; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2260 | |
| 2261 | final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth |
| 2262 | || mInitialDisplayHeight != newHeight |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2263 | || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi |
| 2264 | || !Objects.equals(mInitialDisplayCutout, newCutout); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2265 | |
| 2266 | if (displayMetricsChanged) { |
| 2267 | // Check if display size or density is forced. |
| 2268 | final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth |
| 2269 | || mBaseDisplayHeight != mInitialDisplayHeight; |
| 2270 | final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity; |
| 2271 | |
| 2272 | // If there is an override set for base values - use it, otherwise use new values. |
| 2273 | updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth, |
| 2274 | isDisplaySizeForced ? mBaseDisplayHeight : newHeight, |
| 2275 | isDisplayDensityForced ? mBaseDisplayDensity : newDensity); |
| 2276 | |
| 2277 | // Real display metrics changed, so we should also update initial values. |
| 2278 | mInitialDisplayWidth = newWidth; |
| 2279 | mInitialDisplayHeight = newHeight; |
| 2280 | mInitialDisplayDensity = newDensity; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 2281 | mInitialDisplayCutout = newCutout; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2282 | mWmService.reconfigureDisplayLocked(this); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 2283 | } |
| 2284 | } |
| 2285 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2286 | /** Sets the maximum width the screen resolution can be */ |
| 2287 | void setMaxUiWidth(int width) { |
| 2288 | if (DEBUG_DISPLAY) { |
| 2289 | Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId()); |
| 2290 | } |
| 2291 | |
| 2292 | mMaxUiWidth = width; |
| 2293 | |
| 2294 | // Update existing metrics. |
| 2295 | updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity); |
| 2296 | } |
| 2297 | |
| 2298 | /** Update base (override) display metrics. */ |
| 2299 | void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) { |
| 2300 | mBaseDisplayWidth = baseWidth; |
| 2301 | mBaseDisplayHeight = baseHeight; |
| 2302 | mBaseDisplayDensity = baseDensity; |
| 2303 | |
| 2304 | if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) { |
| 2305 | mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth; |
| 2306 | mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth; |
| 2307 | mBaseDisplayWidth = mMaxUiWidth; |
| 2308 | |
| 2309 | if (DEBUG_DISPLAY) { |
| 2310 | Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x" |
| 2311 | + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity |
| 2312 | + " on display:" + getDisplayId()); |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2317 | |
| 2318 | updateBounds(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2321 | /** |
| 2322 | * Forces this display to use the specified density. |
| 2323 | * |
| 2324 | * @param density The density in DPI to use. If the value equals to initial density, the setting |
| 2325 | * will be cleared. |
| 2326 | * @param userId The target user to apply. Only meaningful when this is default display. If the |
| 2327 | * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings |
| 2328 | * so only need to configure display. |
| 2329 | */ |
| 2330 | void setForcedDensity(int density, int userId) { |
| 2331 | final boolean clear = density == mInitialDisplayDensity; |
| 2332 | final boolean updateCurrent = userId == UserHandle.USER_CURRENT; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2333 | if (mWmService.mCurrentUserId == userId || updateCurrent) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2334 | mBaseDisplayDensity = density; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2335 | mWmService.reconfigureDisplayLocked(this); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2336 | } |
| 2337 | if (updateCurrent) { |
| 2338 | // We are applying existing settings so no need to save it again. |
| 2339 | return; |
| 2340 | } |
| 2341 | |
| 2342 | if (density == mInitialDisplayDensity) { |
| 2343 | density = 0; |
| 2344 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2345 | mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */ |
| 2349 | void setForcedScalingMode(@ForceScalingMode int mode) { |
| 2350 | if (mode != FORCE_SCALING_MODE_DISABLED) { |
| 2351 | mode = FORCE_SCALING_MODE_AUTO; |
| 2352 | } |
| 2353 | |
| 2354 | mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO); |
| 2355 | Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto")); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2356 | mWmService.reconfigureDisplayLocked(this); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2357 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2358 | mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /** If the given width and height equal to initial size, the setting will be cleared. */ |
| 2362 | void setForcedSize(int width, int height) { |
| 2363 | final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height; |
| 2364 | if (!clear) { |
| 2365 | // Set some sort of reasonable bounds on the size of the display that we will try |
| 2366 | // to emulate. |
| 2367 | final int minSize = 200; |
| 2368 | final int maxScale = 2; |
| 2369 | width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale); |
| 2370 | height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale); |
| 2371 | } |
| 2372 | |
| 2373 | Slog.i(TAG_WM, "Using new display size: " + width + "x" + height); |
| 2374 | updateBaseDisplayMetrics(width, height, mBaseDisplayDensity); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2375 | mWmService.reconfigureDisplayLocked(this); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2376 | |
| 2377 | if (clear) { |
| 2378 | width = height = 0; |
| 2379 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2380 | mWmService.mDisplayWindowSettings.setForcedSize(this, width, height); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 2381 | } |
| 2382 | |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 2383 | void getStableRect(Rect out) { |
| 2384 | out.set(mDisplayFrames.mStable); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 2385 | } |
| 2386 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 2387 | void setStackOnDisplay(int stackId, boolean onTop, TaskStack stack) { |
| 2388 | if (DEBUG_STACK) { |
| 2389 | Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId=" + mDisplayId); |
| 2390 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2391 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2392 | mTaskStackContainers.addStackToDisplay(stack, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2395 | void moveStackToDisplay(TaskStack stack, boolean onTop) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2396 | final DisplayContent prevDc = stack.getDisplayContent(); |
| 2397 | if (prevDc == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2398 | throw new IllegalStateException("Trying to move stackId=" + stack.mStackId |
| 2399 | + " which is not currently attached to any display"); |
| 2400 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2401 | if (prevDc.getDisplayId() == mDisplayId) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2402 | throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId |
| 2403 | + " to its current displayId=" + mDisplayId); |
| 2404 | } |
| 2405 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2406 | prevDc.mTaskStackContainers.removeChild(stack); |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2407 | mTaskStackContainers.addStackToDisplay(stack, onTop); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 2408 | } |
| 2409 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2410 | @Override |
| 2411 | protected void addChild(DisplayChildWindowContainer child, |
| 2412 | Comparator<DisplayChildWindowContainer> comparator) { |
| 2413 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2414 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2415 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2416 | @Override |
| 2417 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 2418 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 2419 | } |
| 2420 | |
| 2421 | @Override |
| 2422 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2423 | // Only allow removal of direct children from this display if the display is in the process |
| 2424 | // of been removed. |
| 2425 | if (mRemovingDisplay) { |
| 2426 | super.removeChild(child); |
| 2427 | return; |
| 2428 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2429 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2430 | } |
| 2431 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2432 | @Override |
| 2433 | void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) { |
| 2434 | // Children of the display are statically ordered, so the real intention here is to perform |
| 2435 | // the operation on the display and not the static direct children. |
| 2436 | getParent().positionChildAt(position, this, includingParents); |
| 2437 | } |
| 2438 | |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 2439 | void positionStackAt(int position, TaskStack child, boolean includingParents) { |
| 2440 | mTaskStackContainers.positionChildAt(position, child, includingParents); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 2441 | layoutAndAssignWindowLayersIfNeeded(); |
| 2442 | } |
| 2443 | |
Garfield Tan | 4f71c5a | 2018-10-10 10:12:02 -0700 | [diff] [blame] | 2444 | /** |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2445 | * Returns true if the input point is within an app window. |
| 2446 | */ |
| 2447 | boolean pointWithinAppWindow(int x, int y) { |
| 2448 | final int[] targetWindowType = {-1}; |
| 2449 | final Consumer fn = PooledLambda.obtainConsumer((w, nonArg) -> { |
| 2450 | if (targetWindowType[0] != -1) { |
| 2451 | return; |
| 2452 | } |
| 2453 | |
| 2454 | if (w.isOnScreen() && w.isVisibleLw() && w.getFrameLw().contains(x, y)) { |
| 2455 | targetWindowType[0] = w.mAttrs.type; |
| 2456 | return; |
| 2457 | } |
| 2458 | }, PooledLambda.__(WindowState.class), mTmpRect); |
| 2459 | forAllWindows(fn, true /* traverseTopToBottom */); |
| 2460 | ((PooledConsumer) fn).recycle(); |
| 2461 | return FIRST_APPLICATION_WINDOW <= targetWindowType[0] |
| 2462 | && targetWindowType[0] <= LAST_APPLICATION_WINDOW; |
| 2463 | } |
| 2464 | |
| 2465 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2466 | * 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] | 2467 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2468 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 2469 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2470 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2471 | mTmpTaskForResizePointSearchResult.reset(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2472 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2473 | final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2474 | if (!stack.getWindowConfiguration().canResizeTask()) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2475 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2476 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 2477 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2478 | stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult); |
| 2479 | if (mTmpTaskForResizePointSearchResult.searchDone) { |
| 2480 | return mTmpTaskForResizePointSearchResult.taskForResize; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2481 | } |
| 2482 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 2483 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2486 | void updateTouchExcludeRegion() { |
| 2487 | final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2488 | if (focusedTask == null) { |
| 2489 | mTouchExcludeRegion.setEmpty(); |
| 2490 | } else { |
| 2491 | mTouchExcludeRegion.set(mBaseDisplayRect); |
| 2492 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
| 2493 | mTmpRect2.setEmpty(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2494 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; |
| 2495 | --stackNdx) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2496 | final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2497 | stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion, |
| 2498 | mDisplayFrames.mContent, mTmpRect2); |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2499 | } |
| 2500 | // 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] | 2501 | // outside touch area in the exclusion. TapDetector is not interested in |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 2502 | // any touch inside the focused task itself. |
| 2503 | if (!mTmpRect2.isEmpty()) { |
| 2504 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 2505 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 2506 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2507 | if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) { |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2508 | // If the input method is visible and the user is typing, we don't want these touch |
| 2509 | // events to be intercepted and used to change focus. This would likely cause a |
| 2510 | // disappearance of the input method. |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2511 | mInputMethodWindow.getTouchableRegion(mTmpRegion); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2512 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 2513 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2514 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 2515 | final WindowState win = mTapExcludedWindows.get(i); |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 2516 | win.getTouchableRegion(mTmpRegion); |
| 2517 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 2518 | } |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2519 | amendWindowTapExcludeRegion(mTouchExcludeRegion); |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 2520 | // TODO(multi-display): Support docked stacks on secondary displays. |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2521 | if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) { |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2522 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 2523 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2524 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 2525 | } |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2526 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2529 | /** |
| 2530 | * Union the region with all the tap exclude region provided by windows on this display. |
| 2531 | * |
| 2532 | * @param inOutRegion The region to be amended. |
| 2533 | */ |
| 2534 | void amendWindowTapExcludeRegion(Region inOutRegion) { |
| 2535 | for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) { |
| 2536 | final WindowState win = mTapExcludeProvidingWindows.valueAt(i); |
| 2537 | win.amendTapExcludeRegion(inOutRegion); |
| 2538 | } |
| 2539 | } |
| 2540 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2541 | @Override |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 2542 | void switchUser() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2543 | super.switchUser(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2544 | mWmService.mWindowsChanged = true; |
Winson Chung | da20fec | 2019-04-10 12:19:59 -0700 | [diff] [blame] | 2545 | mDisplayPolicy.switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 2548 | private void resetAnimationBackgroundAnimator() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2549 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2550 | mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2554 | @Override |
| 2555 | void removeIfPossible() { |
| 2556 | if (isAnimating()) { |
| 2557 | mDeferredRemoval = true; |
| 2558 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2559 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2560 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2563 | @Override |
| 2564 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2565 | mRemovingDisplay = true; |
| 2566 | try { |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 2567 | if (mParentWindow != null) { |
| 2568 | mParentWindow.removeEmbeddedDisplayContent(this); |
| 2569 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2570 | // Clear all transitions & screen frozen states when removing display. |
| 2571 | mOpeningApps.clear(); |
| 2572 | mClosingApps.clear(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 2573 | mChangingApps.clear(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2574 | mUnknownAppVisibilityController.clear(); |
| 2575 | mAppTransition.removeAppTransitionTimeoutCallbacks(); |
| 2576 | handleAnimatingStoppedAndTransition(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2577 | mWmService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2578 | super.removeImmediately(); |
| 2579 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 2580 | mPointerEventDispatcher.dispose(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2581 | mWmService.mAnimator.removeDisplayLocked(mDisplayId); |
Louis Chang | 207f911 | 2018-07-30 08:58:54 +0800 | [diff] [blame] | 2582 | mWindowingLayer.release(); |
| 2583 | mOverlayLayer.release(); |
Jorim Jaggi | ae962e6 | 2018-12-27 17:23:48 +0100 | [diff] [blame] | 2584 | mInputMonitor.onDisplayRemoved(); |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2585 | } finally { |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 2586 | mDisplayReady = false; |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 2587 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2588 | } |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 2589 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2590 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2591 | } |
| 2592 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2593 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2594 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2595 | boolean checkCompleteDeferredRemoval() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2596 | final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval(); |
| 2597 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2598 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2599 | removeImmediately(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2600 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2601 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2602 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2603 | } |
| 2604 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 2605 | /** @return 'true' if removal of this display content is deferred due to active animation. */ |
| 2606 | boolean isRemovalDeferred() { |
| 2607 | return mDeferredRemoval; |
| 2608 | } |
| 2609 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2610 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 2611 | float dividerAnimationTarget) { |
| 2612 | boolean updated = false; |
| 2613 | |
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 | if (stack == null || !stack.isAdjustedForIme()) { |
| 2617 | continue; |
| 2618 | } |
| 2619 | |
| 2620 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 2621 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2622 | updated = true; |
| 2623 | } else { |
| 2624 | mDividerControllerLocked.mLastAnimationProgress = |
| 2625 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 2626 | mDividerControllerLocked.mLastDividerProgress = |
| 2627 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 2628 | updated |= stack.updateAdjustForIme( |
| 2629 | mDividerControllerLocked.mLastAnimationProgress, |
| 2630 | mDividerControllerLocked.mLastDividerProgress, |
| 2631 | false /* force */); |
| 2632 | } |
| 2633 | if (interpolatedValue >= 1f) { |
| 2634 | stack.endImeAdjustAnimation(); |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | return updated; |
| 2639 | } |
| 2640 | |
| 2641 | boolean clearImeAdjustAnimation() { |
| 2642 | boolean changed = false; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2643 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
| 2644 | final TaskStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2645 | if (stack != null && stack.isAdjustedForIme()) { |
| 2646 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 2647 | changed = true; |
| 2648 | } |
| 2649 | } |
| 2650 | return changed; |
| 2651 | } |
| 2652 | |
| 2653 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2654 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
| 2655 | final TaskStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2656 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 2657 | stack.beginImeAdjustAnimation(); |
| 2658 | } |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | void adjustForImeIfNeeded() { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2663 | final WindowState imeWin = mInputMethodWindow; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2664 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 2665 | && !mDividerControllerLocked.isImeHideRequested(); |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2666 | final TaskStack dockedStack = getSplitScreenPrimaryStack(); |
| 2667 | final boolean dockVisible = dockedStack != null; |
| 2668 | final Task topDockedTask = dockVisible ? dockedStack.getTopChild() : null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2669 | final TaskStack imeTargetStack = mWmService.getImeFocusStackLocked(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2670 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 2671 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 2672 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 2673 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2674 | final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2675 | final boolean imeHeightChanged = imeVisible && |
| 2676 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 2677 | |
Riddle Hsu | c681425 | 2019-05-16 17:06:52 +0800 | [diff] [blame] | 2678 | // This includes a case where the docked stack is unminimizing and IME is visible for the |
| 2679 | // bottom side stack. The condition prevents adjusting the override task bounds for IME to |
| 2680 | // the minimized docked stack bounds. |
| 2681 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock() |
| 2682 | || (topDockedTask != null && imeOnBottom && !dockedStack.isAdjustedForIme() |
| 2683 | && dockedStack.getBounds().height() < topDockedTask.getBounds().height()); |
| 2684 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2685 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 2686 | // or both. There are three possible cases: |
| 2687 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 2688 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 2689 | // - If IME is not visible, divider is not moved and is normal width. |
| 2690 | |
| 2691 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2692 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
| 2693 | final TaskStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2694 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2695 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom) |
| 2696 | && stack.inSplitScreenWindowingMode()) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2697 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 2698 | } else { |
| 2699 | stack.resetAdjustedForIme(false); |
| 2700 | } |
| 2701 | } |
| 2702 | mDividerControllerLocked.setAdjustedForIme( |
| 2703 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 2704 | } else { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2705 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
| 2706 | final TaskStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2707 | stack.resetAdjustedForIme(!dockVisible); |
| 2708 | } |
| 2709 | mDividerControllerLocked.setAdjustedForIme( |
| 2710 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 2711 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2712 | mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2716 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2717 | final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2718 | stack.prepareFreezingTaskBounds(); |
| 2719 | } |
| 2720 | } |
| 2721 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2722 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2723 | getBounds(mTmpRect, newRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2724 | rotateBounds(mTmpRect, oldRotation, newRotation, bounds); |
| 2725 | } |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2726 | |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2727 | void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2728 | // Compute a transform matrix to undo the coordinate space transformation, |
| 2729 | // and present the window at the same physical position it previously occupied. |
| 2730 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 2731 | createRotationMatrix( |
| 2732 | deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2733 | |
| 2734 | mTmpRectF.set(bounds); |
| 2735 | mTmpMatrix.mapRect(mTmpRectF); |
| 2736 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 2739 | static int deltaRotation(int oldRotation, int newRotation) { |
| 2740 | int delta = newRotation - oldRotation; |
| 2741 | if (delta < 0) delta += 4; |
| 2742 | return delta; |
| 2743 | } |
| 2744 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2745 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2746 | Matrix outMatrix) { |
| 2747 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 2748 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 2749 | displayHeight, outMatrix); |
| 2750 | } |
| 2751 | |
| 2752 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 2753 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 2754 | switch (rotation) { |
| 2755 | case ROTATION_0: |
| 2756 | outMatrix.reset(); |
| 2757 | break; |
| 2758 | case ROTATION_270: |
| 2759 | outMatrix.setRotate(270, 0, 0); |
| 2760 | outMatrix.postTranslate(0, displayHeight); |
| 2761 | outMatrix.postTranslate(rectTop, 0); |
| 2762 | break; |
| 2763 | case ROTATION_180: |
| 2764 | outMatrix.reset(); |
| 2765 | break; |
| 2766 | case ROTATION_90: |
| 2767 | outMatrix.setRotate(90, 0, 0); |
| 2768 | outMatrix.postTranslate(displayWidth, 0); |
| 2769 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 2770 | break; |
| 2771 | } |
| 2772 | } |
| 2773 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 2774 | @CallSuper |
| 2775 | @Override |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2776 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 2777 | @WindowTraceLogLevel int logLevel) { |
| 2778 | // Critical log level logs only visible elements to mitigate performance overheard |
| 2779 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 2780 | return; |
| 2781 | } |
| 2782 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2783 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2784 | super.writeToProto(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2785 | proto.write(ID, mDisplayId); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2786 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2787 | final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2788 | stack.writeToProto(proto, STACKS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2789 | } |
| 2790 | mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER); |
| 2791 | mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2792 | for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2793 | final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2794 | windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2795 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2796 | for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2797 | final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2798 | windowToken.writeToProto(proto, BELOW_APP_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2799 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2800 | for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) { |
| 2801 | final WindowToken windowToken = mImeWindowsContainers.getChildAt(i); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 2802 | windowToken.writeToProto(proto, IME_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2803 | } |
| 2804 | proto.write(DPI, mBaseDisplayDensity); |
| 2805 | mDisplayInfo.writeToProto(proto, DISPLAY_INFO); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2806 | proto.write(ROTATION, mRotation); |
| 2807 | final ScreenRotationAnimation screenRotationAnimation = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2808 | mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId); |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 2809 | if (screenRotationAnimation != null) { |
| 2810 | screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION); |
| 2811 | } |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2812 | mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2813 | mAppTransition.writeToProto(proto, APP_TRANSITION); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2814 | if (mFocusedApp != null) { |
| 2815 | mFocusedApp.writeNameToProto(proto, FOCUSED_APP); |
| 2816 | } |
Jorim Jaggi | 1112fed | 2019-04-15 13:32:14 +0200 | [diff] [blame] | 2817 | for (int i = mOpeningApps.size() - 1; i >= 0; i--) { |
| 2818 | mOpeningApps.valueAt(i).mActivityRecord.writeIdentifierToProto(proto, OPENING_APPS); |
| 2819 | } |
| 2820 | for (int i = mClosingApps.size() - 1; i >= 0; i--) { |
| 2821 | mClosingApps.valueAt(i).mActivityRecord.writeIdentifierToProto(proto, CLOSING_APPS); |
| 2822 | } |
| 2823 | for (int i = mChangingApps.size() - 1; i >= 0; i--) { |
| 2824 | mChangingApps.valueAt(i).mActivityRecord.writeIdentifierToProto(proto, CHANGING_APPS); |
| 2825 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2826 | proto.end(token); |
| 2827 | } |
| 2828 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2829 | @Override |
| 2830 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 2831 | super.dump(pw, prefix, dumpAll); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2832 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 2833 | final String subPrefix = " " + prefix; |
| 2834 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 2835 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 2836 | pw.print("dpi"); |
| 2837 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 2838 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 2839 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 2840 | pw.print(" base="); |
| 2841 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 2842 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 2843 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 2844 | if (mDisplayScalingDisabled) { |
| 2845 | pw.println(" noscale"); |
| 2846 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2847 | pw.print(" cur="); |
| 2848 | pw.print(mDisplayInfo.logicalWidth); |
| 2849 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 2850 | pw.print(" app="); |
| 2851 | pw.print(mDisplayInfo.appWidth); |
| 2852 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 2853 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 2854 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 2855 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 2856 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2857 | pw.print(subPrefix + "deferred=" + mDeferredRemoval |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 2858 | + " mLayoutNeeded=" + mLayoutNeeded); |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2859 | pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2860 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2861 | pw.println(); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2862 | pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq); |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 2863 | pw.print(prefix); |
| 2864 | pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2865 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2866 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 2867 | if (mLastFocus != mCurrentFocus) { |
| 2868 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 2869 | } |
| 2870 | if (mLosingFocus.size() > 0) { |
| 2871 | pw.println(); |
| 2872 | pw.println(" Windows losing focus:"); |
| 2873 | for (int i = mLosingFocus.size() - 1; i >= 0; i--) { |
| 2874 | final WindowState w = mLosingFocus.get(i); |
| 2875 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 2876 | pw.print(w); |
| 2877 | if (dumpAll) { |
| 2878 | pw.println(":"); |
| 2879 | w.dump(pw, " ", true); |
| 2880 | } else { |
| 2881 | pw.println(); |
| 2882 | } |
| 2883 | } |
| 2884 | } |
| 2885 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 2886 | if (mLastStatusBarVisibility != 0) { |
| 2887 | pw.print(" mLastStatusBarVisibility=0x"); |
| 2888 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 2889 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2890 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 2891 | pw.println(); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 2892 | mWallpaperController.dump(pw, " "); |
| 2893 | |
| 2894 | pw.println(); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 2895 | pw.print("mSystemGestureExclusion="); |
| 2896 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() > 0) { |
| 2897 | pw.println(mSystemGestureExclusion); |
| 2898 | } else { |
| 2899 | pw.println("<no lstnrs>"); |
| 2900 | } |
| 2901 | |
| 2902 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2903 | pw.println(prefix + "Application tokens in top down Z order:"); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2904 | for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2905 | final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2906 | stack.dump(pw, prefix + " ", dumpAll); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2907 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2908 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2909 | pw.println(); |
| 2910 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2911 | pw.println(); |
| 2912 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2913 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2914 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2915 | pw.print(" Exiting #"); pw.print(i); |
| 2916 | pw.print(' '); pw.print(token); |
| 2917 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2918 | token.dump(pw, " ", dumpAll); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2919 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2920 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 2921 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 2922 | pw.println(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2923 | |
| 2924 | // Dump stack references |
| 2925 | final TaskStack homeStack = getHomeStack(); |
| 2926 | if (homeStack != null) { |
| 2927 | pw.println(prefix + "homeStack=" + homeStack.getName()); |
| 2928 | } |
| 2929 | final TaskStack pinnedStack = getPinnedStack(); |
| 2930 | if (pinnedStack != null) { |
| 2931 | pw.println(prefix + "pinnedStack=" + pinnedStack.getName()); |
| 2932 | } |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2933 | final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack(); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2934 | if (splitScreenPrimaryStack != null) { |
| 2935 | pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName()); |
| 2936 | } |
| 2937 | |
| 2938 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2939 | mDividerControllerLocked.dump(prefix, pw); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2940 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2941 | mPinnedStackControllerLocked.dump(prefix, pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2942 | |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 2943 | pw.println(); |
| 2944 | mDisplayFrames.dump(prefix, pw); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2945 | pw.println(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2946 | mDisplayPolicy.dump(prefix, pw); |
| 2947 | pw.println(); |
Riddle Hsu | ad256a1 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 2948 | mDisplayRotation.dump(prefix, pw); |
| 2949 | pw.println(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2950 | mInputMonitor.dump(pw, " "); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 2951 | pw.println(); |
| 2952 | mInsetsStateController.dump(prefix, pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2953 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2954 | |
| 2955 | @Override |
| 2956 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2957 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2961 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2962 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2963 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2964 | /** Returns true if the stack in the windowing mode is visible. */ |
| 2965 | boolean isStackVisible(int windowingMode) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 2966 | final TaskStack stack = getTopStackInWindowingMode(windowingMode); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2967 | return stack != null && stack.isVisible(); |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 2968 | } |
| 2969 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2970 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2971 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2972 | final int x = (int) xf; |
| 2973 | final int y = (int) yf; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2974 | final WindowState touchedWin = getWindow(w -> { |
| 2975 | final int flags = w.mAttrs.flags; |
| 2976 | if (!w.isVisibleLw()) { |
| 2977 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2978 | } |
| 2979 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2980 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2981 | } |
| 2982 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2983 | w.getVisibleBounds(mTmpRect); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2984 | if (!mTmpRect.contains(x, y)) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2985 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2986 | } |
| 2987 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2988 | w.getTouchableRegion(mTmpRegion); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2989 | |
| 2990 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2991 | return mTmpRegion.contains(x, y) || touchFlags == 0; |
| 2992 | }); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2993 | |
| 2994 | return touchedWin; |
| 2995 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 2996 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2997 | boolean canAddToastWindowForUid(int uid) { |
| 2998 | // We allow one toast window per UID being shown at a time. |
Svet Ganov | daca8ee | 2017-01-21 17:40:40 -0800 | [diff] [blame] | 2999 | // Also if the app is focused adding more than one toast at |
| 3000 | // a time for better backwards compatibility. |
| 3001 | final WindowState focusedWindowForUid = getWindow(w -> |
| 3002 | w.mOwnerUid == uid && w.isFocused()); |
| 3003 | if (focusedWindowForUid != null) { |
| 3004 | return true; |
| 3005 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3006 | final WindowState win = getWindow(w -> |
| 3007 | w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden |
| 3008 | && !w.mWindowRemovalAllowed); |
| 3009 | return win == null; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3012 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3013 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 3014 | return; |
| 3015 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3016 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3017 | // Used to communicate the old focus to the callback method. |
| 3018 | mTmpWindow = oldFocus; |
| 3019 | |
| 3020 | forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3021 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3022 | |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3023 | /** |
| 3024 | * Looking for the focused window on this display if the top focused display hasn't been |
| 3025 | * found yet (topFocusedDisplayId is INVALID_DISPLAY) or per-display focused was allowed. |
| 3026 | * |
| 3027 | * @param topFocusedDisplayId Id of the top focused display. |
| 3028 | * @return The focused window or null if there isn't any or no need to seek. |
| 3029 | */ |
| 3030 | WindowState findFocusedWindowIfNeeded(int topFocusedDisplayId) { |
| 3031 | return (mWmService.mPerDisplayFocusEnabled || topFocusedDisplayId == INVALID_DISPLAY) |
| 3032 | ? findFocusedWindow() : null; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3033 | } |
| 3034 | |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3035 | WindowState findFocusedWindow() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3036 | mTmpWindow = null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3037 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3038 | forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3039 | |
| 3040 | if (mTmpWindow == null) { |
| 3041 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows."); |
| 3042 | return null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 3043 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3044 | return mTmpWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3047 | /** |
| 3048 | * Update the focused window and make some adjustments if the focus has changed. |
| 3049 | * |
| 3050 | * @param mode Indicates the situation we are in. Possible modes are: |
| 3051 | * {@link WindowManagerService#UPDATE_FOCUS_NORMAL}, |
| 3052 | * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES}, |
| 3053 | * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES}, |
| 3054 | * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS} |
| 3055 | * @param updateInputWindows Whether to sync the window information to the input module. |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3056 | * @param topFocusedDisplayId Display id of current top focused display. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3057 | * @return {@code true} if the focused window has changed. |
| 3058 | */ |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3059 | boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, |
| 3060 | int topFocusedDisplayId) { |
| 3061 | WindowState newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3062 | if (mCurrentFocus == newFocus) { |
| 3063 | return false; |
| 3064 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3065 | boolean imWindowChanged = false; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3066 | final WindowState imWindow = mInputMethodWindow; |
| 3067 | if (imWindow != null) { |
| 3068 | final WindowState prevTarget = mInputMethodTarget; |
| 3069 | final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/); |
| 3070 | imWindowChanged = prevTarget != newTarget; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3071 | |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3072 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS |
| 3073 | && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 3074 | assignWindowLayers(false /* setLayoutNeeded */); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | if (imWindowChanged) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3079 | mWmService.mWindowsChanged = true; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3080 | setLayoutNeeded(); |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 3081 | newFocus = findFocusedWindowIfNeeded(topFocusedDisplayId); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3082 | } |
| 3083 | if (mCurrentFocus != newFocus) { |
| 3084 | mWmService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3085 | } |
| 3086 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3087 | 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] | 3088 | + mCurrentFocus + " to " + newFocus + " displayId=" + getDisplayId() |
| 3089 | + " Callers=" + Debug.getCallers(4)); |
| 3090 | final WindowState oldFocus = mCurrentFocus; |
| 3091 | mCurrentFocus = newFocus; |
| 3092 | mLosingFocus.remove(newFocus); |
| 3093 | |
| 3094 | if (newFocus != null) { |
| 3095 | mWinAddedSinceNullFocus.clear(); |
| 3096 | mWinRemovedSinceNullFocus.clear(); |
| 3097 | |
| 3098 | if (newFocus.canReceiveKeys()) { |
| 3099 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 3100 | // This is to protect against bugs if someone pauses dispatching but |
| 3101 | // forgets to resume. |
| 3102 | newFocus.mToken.paused = false; |
| 3103 | } |
| 3104 | } |
| 3105 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3106 | int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3107 | |
| 3108 | if (imWindowChanged && oldFocus != mInputMethodWindow) { |
| 3109 | // Focus of the input method window changed. Perform layout if needed. |
| 3110 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3111 | performLayout(true /*initial*/, updateInputWindows); |
| 3112 | focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT; |
| 3113 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 3114 | // Client will do the layout, but we need to assign layers |
| 3115 | // for handleNewWindowLocked() below. |
| 3116 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3121 | // The change in focus caused us to need to do a layout. Okay. |
| 3122 | setLayoutNeeded(); |
| 3123 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3124 | performLayout(true /*initial*/, updateInputWindows); |
| 3125 | } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3126 | mWmService.mRoot.performSurfacePlacement(false); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 3131 | // If we defer assigning layers, then the caller is responsible for doing this part. |
| 3132 | getInputMonitor().setInputFocusLw(newFocus, updateInputWindows); |
| 3133 | } |
| 3134 | |
| 3135 | adjustForImeIfNeeded(); |
| 3136 | |
| 3137 | // We may need to schedule some toast windows to be removed. The toasts for an app that |
| 3138 | // does not have input focus are removed within a timeout to prevent apps to redress |
| 3139 | // other apps' UI. |
| 3140 | scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus); |
| 3141 | |
| 3142 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 3143 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 3144 | } |
| 3145 | return true; |
| 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * Set the new focused app to this display. |
| 3150 | * |
| 3151 | * @param newFocus the new focused AppWindowToken. |
| 3152 | * @return true if the focused app is changed. |
| 3153 | */ |
| 3154 | boolean setFocusedApp(AppWindowToken newFocus) { |
| 3155 | if (newFocus != null) { |
| 3156 | final DisplayContent appDisplay = newFocus.getDisplayContent(); |
| 3157 | if (appDisplay != this) { |
| 3158 | throw new IllegalStateException(newFocus + " is not on " + getName() |
| 3159 | + " but " + ((appDisplay != null) ? appDisplay.getName() : "none")); |
| 3160 | } |
| 3161 | } |
| 3162 | if (mFocusedApp == newFocus) { |
| 3163 | return false; |
| 3164 | } |
| 3165 | mFocusedApp = newFocus; |
| 3166 | getInputMonitor().setFocusedAppLw(newFocus); |
| 3167 | updateTouchExcludeRegion(); |
| 3168 | return true; |
| 3169 | } |
| 3170 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3171 | /** Updates the layer assignment of windows on this display. */ |
| 3172 | void assignWindowLayers(boolean setLayoutNeeded) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3173 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers"); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3174 | assignChildLayers(getPendingTransaction()); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3175 | if (setLayoutNeeded) { |
| 3176 | setLayoutNeeded(); |
| 3177 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3178 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 3179 | // We accumlate the layer changes in-to "getPendingTransaction()" but we defer |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 3180 | // the application of this transaction until the animation pass triggers |
| 3181 | // prepareSurfaces. This allows us to synchronize Z-ordering changes with |
| 3182 | // the hiding and showing of surfaces. |
| 3183 | scheduleAnimation(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3184 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3187 | // TODO: This should probably be called any time a visual change is made to the hierarchy like |
| 3188 | // moving containers or resizing them. Need to investigate the best way to have it automatically |
| 3189 | // 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] | 3190 | void layoutAndAssignWindowLayersIfNeeded() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3191 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3192 | setLayoutNeeded(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3193 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3194 | if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3195 | false /*updateInputWindows*/)) { |
| 3196 | assignWindowLayers(false /* setLayoutNeeded */); |
| 3197 | } |
| 3198 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3199 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3200 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3201 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3204 | /** Returns true if a leaked surface was destroyed */ |
| 3205 | boolean destroyLeakedSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3206 | // Used to indicate that a surface was leaked. |
| 3207 | mTmpWindow = null; |
| 3208 | forAllWindows(w -> { |
| 3209 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3210 | if (wsa.mSurfaceController == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3211 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3212 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3213 | if (!mWmService.mSessions.contains(wsa.mSession)) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3214 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3215 | + w + " surface=" + wsa.mSurfaceController |
| 3216 | + " token=" + w.mToken |
| 3217 | + " pid=" + w.mSession.mPid |
| 3218 | + " uid=" + w.mSession.mUid); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3219 | wsa.destroySurface(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3220 | mWmService.mForceRemoves.add(w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3221 | mTmpWindow = w; |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 3222 | } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3223 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3224 | + w + " surface=" + wsa.mSurfaceController |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 3225 | + " token=" + w.mAppToken); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3226 | if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3227 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3228 | mTmpWindow = w; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3229 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3230 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3231 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3232 | return mTmpWindow != null; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3236 | * Set input method window for the display. |
| 3237 | * @param win Set when window added or Null when destroyed. |
| 3238 | */ |
| 3239 | void setInputMethodWindowLocked(WindowState win) { |
| 3240 | mInputMethodWindow = win; |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3241 | // Update display configuration for IME process. |
| 3242 | if (mInputMethodWindow != null) { |
| 3243 | final int imePid = mInputMethodWindow.mSession.mPid; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3244 | mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid, |
lumark | 70865a8 | 2018-09-17 16:56:26 +0800 | [diff] [blame] | 3245 | mInputMethodWindow.getDisplayId()); |
| 3246 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3247 | computeImeTarget(true /* updateImeTarget */); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3248 | mInsetsStateController.getSourceProvider(TYPE_IME).setWindow(win, |
| 3249 | null /* frameProvider */); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | /** |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3253 | * Determine and return the window that should be the IME target. |
| 3254 | * @param updateImeTarget If true the system IME target will be updated to match what we found. |
| 3255 | * @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] | 3256 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3257 | WindowState computeImeTarget(boolean updateImeTarget) { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3258 | if (mInputMethodWindow == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3259 | // There isn't an IME so there shouldn't be a target...That was easy! |
| 3260 | if (updateImeTarget) { |
| 3261 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3262 | + mInputMethodTarget + " to null since mInputMethodWindow is null"); |
| 3263 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3264 | } |
| 3265 | return null; |
| 3266 | } |
| 3267 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3268 | final WindowState curTarget = mInputMethodTarget; |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 3269 | if (!canUpdateImeTarget()) { |
| 3270 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target"); |
| 3271 | return curTarget; |
| 3272 | } |
| 3273 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3274 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 3275 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 3276 | // 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] | 3277 | mUpdateImeTarget = updateImeTarget; |
| 3278 | WindowState target = getWindow(mComputeImeTargetPredicate); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3279 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3280 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3281 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 3282 | // to be on top of it, but it is not -really- where input will go. So look down below |
| 3283 | // for a real window to target... |
| 3284 | if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 3285 | final AppWindowToken token = target.mAppToken; |
| 3286 | if (token != null) { |
| 3287 | final WindowState betterTarget = token.getImeTargetBelowWindow(target); |
| 3288 | if (betterTarget != null) { |
| 3289 | target = betterTarget; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3290 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3291 | } |
| 3292 | } |
| 3293 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3294 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM, |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3295 | "Proposed new IME target: " + target + " for display: " + getDisplayId()); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3296 | |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3297 | // 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] | 3298 | // not removed, keep on the last target to avoid IME flicker. |
chaviw | 1c13ad3 | 2018-06-12 16:44:23 -0700 | [diff] [blame] | 3299 | if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw() |
Tarandeep Singh | 2d0aca4 | 2019-03-28 14:08:58 -0700 | [diff] [blame] | 3300 | && curTarget.isClosing()) { |
| 3301 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Not changing target till current window is" |
| 3302 | + " closing and not removed"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3303 | return curTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3306 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target |
| 3307 | + " updateImeTarget=" + updateImeTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3308 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3309 | if (target == null) { |
| 3310 | if (updateImeTarget) { |
| 3311 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 3312 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" |
| 3313 | + Debug.getCallers(4) : "")); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3314 | setInputMethodTarget(null, mInputMethodTargetWaitingAnim); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | return null; |
| 3318 | } |
| 3319 | |
| 3320 | if (updateImeTarget) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3321 | AppWindowToken token = curTarget == null ? null : curTarget.mAppToken; |
| 3322 | if (token != null) { |
| 3323 | |
| 3324 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 3325 | // to look at all windows below the current target that are in this app, finding the |
| 3326 | // highest visible one in layering. |
| 3327 | WindowState highestTarget = null; |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3328 | if (token.isSelfAnimating()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3329 | highestTarget = token.getHighestAnimLayerWindow(curTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | if (highestTarget != null) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3333 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, mAppTransition + " " + highestTarget |
Jorim Jaggi | 35d328a | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3334 | + " animating=" + highestTarget.isAnimating()); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3335 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3336 | if (mAppTransition.isTransitionSet()) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3337 | // If we are currently setting up for an animation, hold everything until we |
| 3338 | // can find out what will happen. |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3339 | setInputMethodTarget(highestTarget, true); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3340 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3341 | } |
| 3342 | } |
| 3343 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3344 | |
| 3345 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 3346 | + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3347 | setInputMethodTarget(target, false); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3350 | return target; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3351 | } |
| 3352 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3353 | /** |
| 3354 | * Calling {@link #computeImeTarget(boolean)} to update the input method target window in |
| 3355 | * the candidate app window token if needed. |
| 3356 | */ |
| 3357 | void computeImeTargetIfNeeded(AppWindowToken candidate) { |
| 3358 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == candidate) { |
| 3359 | computeImeTarget(true /* updateImeTarget */); |
| 3360 | } |
| 3361 | } |
| 3362 | |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 3363 | private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3364 | if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3365 | return; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3366 | } |
| 3367 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 3368 | mInputMethodTarget = target; |
| 3369 | mInputMethodTargetWaitingAnim = targetWaitingAnim; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3370 | assignWindowLayers(false /* setLayoutNeeded */); |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 3371 | mInsetsStateController.onImeTargetChanged(target); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3372 | updateImeParent(); |
| 3373 | } |
| 3374 | |
| 3375 | private void updateImeParent() { |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 3376 | // Force attaching IME to the display when magnifying, or it would be magnified with |
| 3377 | // target app together. |
| 3378 | final boolean shouldAttachToDisplay = (mMagnificationSpec != null); |
| 3379 | final SurfaceControl newParent = |
| 3380 | shouldAttachToDisplay ? mWindowingLayer : computeImeParent(); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3381 | if (newParent != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3382 | getPendingTransaction().reparent(mImeWindowsContainers.mSurfaceControl, newParent); |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3383 | scheduleAnimation(); |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | /** |
| 3388 | * Computes the window the IME should be attached to. |
| 3389 | */ |
| 3390 | @VisibleForTesting |
| 3391 | SurfaceControl computeImeParent() { |
| 3392 | |
| 3393 | // Attach it to app if the target is part of an app and such app is covering the entire |
| 3394 | // screen. If it's not covering the entire screen the IME might extend beyond the apps |
| 3395 | // bounds. |
Riddle Hsu | 6d6f67c | 2019-03-14 16:54:26 +0800 | [diff] [blame] | 3396 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken != null |
| 3397 | && mInputMethodTarget.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 3398 | // An activity with override bounds should be letterboxed inside its parent bounds, |
| 3399 | // so it doesn't fill the screen. |
| 3400 | && mInputMethodTarget.mAppToken.matchParentBounds()) { |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 3401 | return mInputMethodTarget.mAppToken.getSurfaceControl(); |
| 3402 | } |
| 3403 | |
| 3404 | // Otherwise, we just attach it to the display. |
| 3405 | return mWindowingLayer; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) { |
| 3409 | if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 3410 | return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
| 3411 | } |
| 3412 | |
| 3413 | // Used to indicate we have reached the first window in the range we are interested in. |
| 3414 | mTmpWindow = null; |
| 3415 | |
| 3416 | // TODO: Figure-out a more efficient way to do this. |
| 3417 | final WindowState candidate = getWindow(w -> { |
| 3418 | if (w == top) { |
| 3419 | // Reached the first window in the range we are interested in. |
| 3420 | mTmpWindow = w; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3421 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3422 | if (mTmpWindow == null) { |
| 3423 | return false; |
| 3424 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3425 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3426 | if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 3427 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3428 | } |
| 3429 | // If we reached the bottom of the range of windows we are considering, |
| 3430 | // assume no menu is needed. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3431 | if (w == bottom) { |
| 3432 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3433 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3434 | return false; |
| 3435 | }); |
| 3436 | |
| 3437 | return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3438 | } |
| 3439 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3440 | void setLayoutNeeded() { |
| 3441 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3442 | mLayoutNeeded = true; |
| 3443 | } |
| 3444 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3445 | private void clearLayoutNeeded() { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3446 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 3447 | mLayoutNeeded = false; |
| 3448 | } |
| 3449 | |
| 3450 | boolean isLayoutNeeded() { |
| 3451 | return mLayoutNeeded; |
| 3452 | } |
| 3453 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3454 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 3455 | if (mTokenMap.isEmpty()) { |
| 3456 | return; |
| 3457 | } |
| 3458 | pw.println(" Display #" + mDisplayId); |
| 3459 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 3460 | while (it.hasNext()) { |
| 3461 | final WindowToken token = it.next(); |
| 3462 | pw.print(" "); |
| 3463 | pw.print(token); |
| 3464 | if (dumpAll) { |
| 3465 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3466 | token.dump(pw, " ", dumpAll); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3467 | } else { |
| 3468 | pw.println(); |
| 3469 | } |
| 3470 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3471 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3472 | if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty() || !mChangingApps.isEmpty()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3473 | pw.println(); |
| 3474 | if (mOpeningApps.size() > 0) { |
| 3475 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 3476 | } |
| 3477 | if (mClosingApps.size() > 0) { |
| 3478 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 3479 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 3480 | if (mChangingApps.size() > 0) { |
| 3481 | pw.print(" mChangingApps="); pw.println(mChangingApps); |
| 3482 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | mUnknownAppVisibilityController.dump(pw, " "); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3488 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3489 | final int[] index = new int[1]; |
| 3490 | forAllWindows(w -> { |
| 3491 | final WindowStateAnimator wAnim = w.mWinAnimator; |
| 3492 | pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim); |
| 3493 | index[0] = index[0] + 1; |
| 3494 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3497 | /** |
| 3498 | * Starts the Keyguard exit animation on all windows that don't belong to an app token. |
| 3499 | */ |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3500 | void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade, |
| 3501 | boolean subtle) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3502 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3503 | forAllWindows(w -> { |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 3504 | if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w) |
| 3505 | && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) { |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 3506 | w.startAnimation(policy.createHiddenByKeyguardExit( |
| 3507 | onWallpaper, goingToShade, subtle)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3508 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3509 | }, true /* traverseTopToBottom */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3510 | } |
| 3511 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3512 | boolean checkWaitingForWindows() { |
| 3513 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3514 | mHaveBootMsg = false; |
| 3515 | mHaveApp = false; |
| 3516 | mHaveWallpaper = false; |
| 3517 | mHaveKeyguard = true; |
| 3518 | |
| 3519 | final WindowState visibleWindow = getWindow(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3520 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| 3521 | return true; |
| 3522 | } |
| 3523 | if (w.isDrawnLw()) { |
| 3524 | if (w.mAttrs.type == TYPE_BOOT_PROGRESS) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3525 | mHaveBootMsg = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3526 | } else if (w.mAttrs.type == TYPE_APPLICATION |
| 3527 | || w.mAttrs.type == TYPE_DRAWN_APPLICATION) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3528 | mHaveApp = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3529 | } else if (w.mAttrs.type == TYPE_WALLPAPER) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3530 | mHaveWallpaper = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3531 | } else if (w.mAttrs.type == TYPE_STATUS_BAR) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3532 | mHaveKeyguard = mWmService.mPolicy.isKeyguardDrawnLw(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3533 | } |
| 3534 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3535 | return false; |
| 3536 | }); |
| 3537 | |
| 3538 | if (visibleWindow != null) { |
| 3539 | // We have a visible window. |
| 3540 | return true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3543 | // if the wallpaper service is disabled on the device, we're never going to have |
| 3544 | // wallpaper, don't bother waiting for it |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3545 | boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean( |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3546 | com.android.internal.R.bool.config_enableWallpaperService) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3547 | && mWmService.mContext.getResources().getBoolean( |
Daichi Hirono | c143222 | 2018-03-29 13:06:07 +0900 | [diff] [blame] | 3548 | com.android.internal.R.bool.config_checkWallpaperAtBoot) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3549 | && !mWmService.mOnlyCore; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3550 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3551 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3552 | "******** booted=" + mWmService.mSystemBooted |
| 3553 | + " msg=" + mWmService.mShowingBootMessages |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3554 | + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp |
| 3555 | + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled |
| 3556 | + " haveKeyguard=" + mHaveKeyguard); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3557 | |
| 3558 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 3559 | // message is actually displayed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3560 | if (!mWmService.mSystemBooted && !mHaveBootMsg) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3561 | return true; |
| 3562 | } |
| 3563 | |
| 3564 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 3565 | // we have the application and wallpaper. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3566 | if (mWmService.mSystemBooted |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3567 | && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3568 | return true; |
| 3569 | } |
| 3570 | |
| 3571 | return false; |
| 3572 | } |
| 3573 | |
Jorim Jaggi | 8f52087 | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3574 | void updateWindowsForAnimator() { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3575 | forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
Jorim Jaggi | 8f52087 | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3578 | /** |
| 3579 | * Updates the {@link TaskStack#setAnimationBackground} for all windows. |
| 3580 | */ |
| 3581 | void updateBackgroundForAnimator() { |
Jorim Jaggi | 7156b65 | 2016-10-25 08:31:58 -0700 | [diff] [blame] | 3582 | resetAnimationBackgroundAnimator(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3583 | forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 3584 | } |
| 3585 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3586 | boolean isInputMethodClientFocus(int uid, int pid) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3587 | final WindowState imFocus = computeImeTarget(false /* updateImeTarget */); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3588 | if (imFocus == null) { |
| 3589 | return false; |
| 3590 | } |
| 3591 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3592 | if (DEBUG_INPUT_METHOD) { |
| 3593 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3594 | Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId); |
| 3595 | Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 3596 | } |
| 3597 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3598 | if (DEBUG_INPUT_METHOD) { |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3599 | Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid |
| 3600 | + "/" + imFocus.mSession.mPid); |
| 3601 | Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3602 | } |
| 3603 | |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3604 | return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | boolean hasSecureWindowOnScreen() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3608 | final WindowState win = getWindow( |
| 3609 | w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0); |
| 3610 | return win != null; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3613 | void statusBarVisibilityChanged(int visibility) { |
| 3614 | mLastStatusBarVisibility = visibility; |
| 3615 | visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility); |
| 3616 | updateStatusBarVisibilityLocked(visibility); |
| 3617 | } |
| 3618 | |
| 3619 | private boolean updateStatusBarVisibilityLocked(int visibility) { |
| 3620 | if (mLastDispatchedSystemUiVisibility == visibility) { |
| 3621 | return false; |
| 3622 | } |
| 3623 | final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility) |
| 3624 | // We are only interested in differences of one of the |
| 3625 | // clearable flags... |
| 3626 | & View.SYSTEM_UI_CLEARABLE_FLAGS |
| 3627 | // ...if it has actually been cleared. |
| 3628 | & ~visibility; |
| 3629 | |
| 3630 | mLastDispatchedSystemUiVisibility = visibility; |
| 3631 | if (isDefaultDisplay) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3632 | mWmService.mInputManager.setSystemUiVisibility(visibility); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3633 | } |
| 3634 | updateSystemUiVisibility(visibility, globalDiff); |
| 3635 | return true; |
| 3636 | } |
| 3637 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3638 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3639 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3640 | try { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3641 | final int curValue = w.mSystemUiVisibility; |
| 3642 | final int diff = (curValue ^ visibility) & globalDiff; |
| 3643 | final int newValue = (curValue & ~diff) | (visibility & diff); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3644 | if (newValue != curValue) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3645 | w.mSeq++; |
| 3646 | w.mSystemUiVisibility = newValue; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3647 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3648 | if (newValue != curValue || w.mAttrs.hasSystemUiListeners) { |
| 3649 | w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3650 | visibility, newValue, diff); |
| 3651 | } |
| 3652 | } catch (RemoteException e) { |
| 3653 | // so sorry |
| 3654 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3655 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3656 | } |
| 3657 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3658 | void reevaluateStatusBarVisibility() { |
| 3659 | int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 3660 | if (updateStatusBarVisibilityLocked(visibility)) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3661 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3665 | void onWindowFreezeTimeout() { |
| 3666 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3667 | mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3668 | |
| 3669 | forAllWindows(w -> { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3670 | if (!w.getOrientationChanging()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3671 | return; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3672 | } |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 3673 | w.orientationChangeTimedOut(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3674 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3675 | - mWmService.mDisplayFreezeTime); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3676 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3677 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3678 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | void waitForAllWindowsDrawn() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3682 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3683 | forAllWindows(w -> { |
| 3684 | final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs); |
| 3685 | if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) { |
| 3686 | w.mWinAnimator.mDrawState = DRAW_PENDING; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3687 | // Force add to mResizingWindows. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3688 | w.resetLastContentInsets(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3689 | mWmService.mWaitingForDrawn.add(w); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3690 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3691 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3694 | // TODO: Super crazy long method that should be broken down... |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3695 | void applySurfaceChangesTransaction(boolean recoveringMemory) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3696 | final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3697 | |
| 3698 | mTmpUpdateAllDrawn.clear(); |
| 3699 | |
| 3700 | int repeats = 0; |
| 3701 | do { |
| 3702 | repeats++; |
| 3703 | if (repeats > 6) { |
| 3704 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 3705 | clearLayoutNeeded(); |
| 3706 | break; |
| 3707 | } |
| 3708 | |
| 3709 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner", |
| 3710 | pendingLayoutChanges); |
| 3711 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 3712 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 3713 | mWallpaperController.adjustWallpaperWindows(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 3716 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3717 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 3718 | if (updateOrientationFromAppTokens()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3719 | setLayoutNeeded(); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 3720 | sendNewConfiguration(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 3725 | setLayoutNeeded(); |
| 3726 | } |
| 3727 | |
| 3728 | // FIRST LOOP: Perform a layout, if needed. |
| 3729 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 3730 | performLayout(repeats == 1, false /* updateInputWindows */); |
| 3731 | } else { |
| 3732 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 3733 | } |
| 3734 | |
| 3735 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating. |
| 3736 | pendingLayoutChanges = 0; |
| 3737 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3738 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyPostLayoutPolicy"); |
| 3739 | try { |
| 3740 | mDisplayPolicy.beginPostLayoutPolicyLw(); |
| 3741 | forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */); |
| 3742 | pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw(); |
| 3743 | } finally { |
| 3744 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3745 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3746 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 3747 | "after finishPostLayoutPolicyLw", pendingLayoutChanges); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3748 | mInsetsStateController.onPostLayout(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3749 | } while (pendingLayoutChanges != 0); |
| 3750 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3751 | mTmpApplySurfaceChangesTransactionState.reset(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3752 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3753 | mTmpRecoveringMemory = recoveringMemory; |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3754 | |
| 3755 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "applyWindowSurfaceChanges"); |
| 3756 | try { |
| 3757 | forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */); |
| 3758 | } finally { |
| 3759 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3760 | } |
Jorim Jaggi | 6b0f846 | 2018-01-05 17:23:47 +0100 | [diff] [blame] | 3761 | prepareSurfaces(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3762 | |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3763 | mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3764 | mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId, |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 3765 | mLastHasContent, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3766 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate, |
| 3767 | mTmpApplySurfaceChangesTransactionState.preferredModeId, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3768 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 3769 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3770 | final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible(); |
| 3771 | if (wallpaperVisible != mLastWallpaperVisible) { |
| 3772 | mLastWallpaperVisible = wallpaperVisible; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3773 | mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3776 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
| 3777 | final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast(); |
| 3778 | // See if any windows have been drawn, so they (and others associated with them) |
| 3779 | // can now be shown. |
Matthew Ng | 498c71d | 2017-04-18 13:55:45 -0700 | [diff] [blame] | 3780 | atoken.updateAllDrawn(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3781 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3784 | private void updateBounds() { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3785 | calculateBounds(mDisplayInfo, mTmpBounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3786 | setBounds(mTmpBounds); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3787 | if (mPortalWindowHandle != null && mParentSurfaceControl != null) { |
| 3788 | mPortalWindowHandle.touchableRegion.getBounds(mTmpRect); |
| 3789 | if (!mTmpBounds.equals(mTmpRect)) { |
| 3790 | mPortalWindowHandle.touchableRegion.set(mTmpBounds); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 3791 | getPendingTransaction().setInputWindowInfo( |
| 3792 | mParentSurfaceControl, mPortalWindowHandle); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3793 | } |
| 3794 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | // Determines the current display bounds based on the current state |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3798 | private void calculateBounds(DisplayInfo displayInfo, Rect out) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3799 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3800 | final int rotation = displayInfo.rotation; |
| 3801 | boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3802 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 3803 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3804 | int width = displayInfo.logicalWidth; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3805 | int left = (physWidth - width) / 2; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 3806 | int height = displayInfo.logicalHeight; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3807 | int top = (physHeight - height) / 2; |
| 3808 | out.set(left, top, left + width, top + height); |
| 3809 | } |
| 3810 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3811 | private void getBounds(Rect out, int orientation) { |
| 3812 | getBounds(out); |
| 3813 | |
| 3814 | // Rotate the Rect if needed. |
| 3815 | final int currentRotation = mDisplayInfo.rotation; |
| 3816 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 3817 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 3818 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 3819 | mTmpRectF.set(out); |
| 3820 | mTmpMatrix.mapRect(mTmpRectF); |
| 3821 | mTmpRectF.round(out); |
| 3822 | } |
| 3823 | } |
| 3824 | |
Evan Rosky | 730f6e8 | 2018-12-03 17:40:11 -0800 | [diff] [blame] | 3825 | /** @returns the orientation of the display when it's rotation is ROTATION_0. */ |
| 3826 | int getNaturalOrientation() { |
| 3827 | return mBaseDisplayWidth < mBaseDisplayHeight |
| 3828 | ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
| 3829 | } |
| 3830 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3831 | void performLayout(boolean initial, boolean updateInputWindows) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3832 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "performLayout"); |
| 3833 | try { |
| 3834 | performLayoutNoTrace(initial, updateInputWindows); |
| 3835 | } finally { |
| 3836 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | private void performLayoutNoTrace(boolean initial, boolean updateInputWindows) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3841 | if (!isLayoutNeeded()) { |
| 3842 | return; |
| 3843 | } |
| 3844 | clearLayoutNeeded(); |
| 3845 | |
| 3846 | final int dw = mDisplayInfo.logicalWidth; |
| 3847 | final int dh = mDisplayInfo.logicalHeight; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3848 | if (DEBUG_LAYOUT) { |
| 3849 | Slog.v(TAG, "-------------------------------------"); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3850 | Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw |
| 3851 | + " dh=" + dh); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3852 | } |
| 3853 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 3854 | mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, |
| 3855 | calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3856 | // TODO: Not sure if we really need to set the rotation here since we are updating from |
| 3857 | // the display info above... |
Wale Ogunwale | 828ff7e | 2017-11-14 01:01:29 +0000 | [diff] [blame] | 3858 | mDisplayFrames.mRotation = mRotation; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3859 | mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3860 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3861 | int seq = mLayoutSeq + 1; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3862 | if (seq < 0) seq = 0; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 3863 | mLayoutSeq = seq; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3864 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3865 | // Used to indicate that we have processed the dream window and all additional windows are |
| 3866 | // behind it. |
| 3867 | mTmpWindow = null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3868 | mTmpInitial = initial; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3869 | |
| 3870 | // First perform layout of any root windows (not attached to another window). |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3871 | forAllWindows(mPerformLayout, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3872 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3873 | // Used to indicate that we have processed the dream window and all additional attached |
| 3874 | // windows are behind it. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3875 | mTmpWindow2 = mTmpWindow; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3876 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3877 | |
| 3878 | // Now perform layout of attached windows, which usually depend on the position of the |
| 3879 | // window they are attached to. XXX does not deal with windows that are attached to windows |
| 3880 | // that are themselves attached. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3881 | forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3882 | |
| 3883 | // Window frames may have changed. Tell the input dispatcher about it. |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3884 | mInputMonitor.layoutInputConsumers(dw, dh); |
| 3885 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3886 | if (updateInputWindows) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 3887 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3888 | } |
| 3889 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3890 | mWmService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | /** |
| 3894 | * Takes a snapshot of the display. In landscape mode this grabs the whole screen. |
| 3895 | * In portrait mode, it grabs the full screenshot. |
| 3896 | * |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3897 | * @param config of the output bitmap |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3898 | */ |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3899 | Bitmap screenshotDisplayLocked(Bitmap.Config config) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3900 | if (!mWmService.mPolicy.isScreenOn()) { |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3901 | if (DEBUG_SCREENSHOT) { |
| 3902 | Slog.i(TAG_WM, "Attempted to take screenshot while display was off."); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3903 | } |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3904 | return null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3905 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3906 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3907 | int dw = mDisplayInfo.logicalWidth; |
| 3908 | int dh = mDisplayInfo.logicalHeight; |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3909 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3910 | if (dw <= 0 || dh <= 0) { |
| 3911 | return null; |
| 3912 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3913 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3914 | final Rect frame = new Rect(0, 0, dw, dh); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3915 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3916 | // The screenshot API does not apply the current screen rotation. |
| 3917 | int rot = mDisplay.getRotation(); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3918 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3919 | if (rot == ROTATION_90 || rot == ROTATION_270) { |
| 3920 | rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 3921 | } |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 3922 | |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3923 | // SurfaceFlinger is not aware of orientation, so convert our logical |
| 3924 | // crop to SurfaceFlinger's portrait orientation. |
| 3925 | convertCropForSurfaceFlinger(frame, rot, dw, dh); |
| 3926 | |
| 3927 | final ScreenRotationAnimation screenRotationAnimation = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3928 | mWmService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3929 | final boolean inRotation = screenRotationAnimation != null && |
| 3930 | screenRotationAnimation.isAnimating(); |
| 3931 | if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating"); |
| 3932 | |
| 3933 | // TODO(b/68392460): We should screenshot Task controls directly |
| 3934 | // but it's difficult at the moment as the Task doesn't have the |
| 3935 | // correct size set. |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 3936 | final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot); |
chaviw | 0315a1a | 2018-03-05 15:28:35 -0800 | [diff] [blame] | 3937 | if (bitmap == null) { |
| 3938 | Slog.w(TAG_WM, "Failed to take screenshot"); |
| 3939 | return null; |
| 3940 | } |
| 3941 | |
| 3942 | // Create a copy of the screenshot that is immutable and backed in ashmem. |
| 3943 | // This greatly reduces the overhead of passing the bitmap between processes. |
| 3944 | final Bitmap ret = bitmap.createAshmemBitmap(config); |
| 3945 | bitmap.recycle(); |
| 3946 | return ret; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | // TODO: Can this use createRotationMatrix()? |
| 3950 | private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) { |
| 3951 | if (rot == Surface.ROTATION_90) { |
| 3952 | final int tmp = crop.top; |
| 3953 | crop.top = dw - crop.right; |
| 3954 | crop.right = crop.bottom; |
| 3955 | crop.bottom = dw - crop.left; |
| 3956 | crop.left = tmp; |
| 3957 | } else if (rot == Surface.ROTATION_180) { |
| 3958 | int tmp = crop.top; |
| 3959 | crop.top = dh - crop.bottom; |
| 3960 | crop.bottom = dh - tmp; |
| 3961 | tmp = crop.right; |
| 3962 | crop.right = dw - crop.left; |
| 3963 | crop.left = dw - tmp; |
| 3964 | } else if (rot == Surface.ROTATION_270) { |
| 3965 | final int tmp = crop.top; |
| 3966 | crop.top = crop.left; |
| 3967 | crop.left = dh - crop.bottom; |
| 3968 | crop.bottom = crop.right; |
| 3969 | crop.right = dh - tmp; |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | void onSeamlessRotationTimeout() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3974 | // Used to indicate the layout is needed. |
| 3975 | mTmpWindow = null; |
| 3976 | |
| 3977 | forAllWindows(w -> { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3978 | if (!w.mSeamlesslyRotated) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3979 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3980 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3981 | mTmpWindow = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3982 | w.setDisplayLayoutNeeded(); |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 3983 | w.finishSeamlessRotation(true /* timeout */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3984 | mWmService.markForSeamlessRotation(w, false); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3985 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3986 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3987 | if (mTmpWindow != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3988 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3992 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 3993 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 3994 | mExitingTokens.get(i).hasVisible = hasVisible; |
| 3995 | } |
| 3996 | |
| 3997 | // Initialize state of exiting applications. |
| 3998 | mTaskStackContainers.setExitingTokensHasVisible(hasVisible); |
| 3999 | } |
| 4000 | |
| 4001 | void removeExistingTokensIfPossible() { |
| 4002 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 4003 | final WindowToken token = mExitingTokens.get(i); |
| 4004 | if (!token.hasVisible) { |
| 4005 | mExitingTokens.remove(i); |
| 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | // Time to remove any exiting applications? |
| 4010 | mTaskStackContainers.removeExistingAppTokensIfPossible(); |
| 4011 | } |
| 4012 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4013 | @Override |
| 4014 | void onDescendantOverrideConfigurationChanged() { |
| 4015 | setLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4016 | mWmService.requestTraversal(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4019 | boolean okToDisplay() { |
| 4020 | if (mDisplayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4021 | return !mWmService.mDisplayFrozen |
| 4022 | && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4023 | } |
| 4024 | return mDisplayInfo.state == Display.STATE_ON; |
| 4025 | } |
| 4026 | |
| 4027 | boolean okToAnimate() { |
| 4028 | return okToDisplay() && |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4029 | (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4030 | } |
| 4031 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 4032 | static final class TaskForResizePointSearchResult { |
| 4033 | boolean searchDone; |
| 4034 | Task taskForResize; |
| 4035 | |
| 4036 | void reset() { |
| 4037 | searchDone = false; |
| 4038 | taskForResize = null; |
| 4039 | } |
| 4040 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4041 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4042 | private static final class ApplySurfaceChangesTransactionState { |
| 4043 | boolean displayHasContent; |
| 4044 | boolean obscured; |
| 4045 | boolean syswin; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4046 | float preferredRefreshRate; |
| 4047 | int preferredModeId; |
| 4048 | |
| 4049 | void reset() { |
| 4050 | displayHasContent = false; |
| 4051 | obscured = false; |
| 4052 | syswin = false; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4053 | preferredRefreshRate = 0; |
| 4054 | preferredModeId = 0; |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | private static final class ScreenshotApplicationState { |
| 4059 | WindowState appWin; |
| 4060 | int maxLayer; |
| 4061 | int minLayer; |
| 4062 | boolean screenshotReady; |
| 4063 | |
| 4064 | void reset(boolean screenshotReady) { |
| 4065 | appWin = null; |
| 4066 | maxLayer = 0; |
| 4067 | minLayer = 0; |
| 4068 | this.screenshotReady = screenshotReady; |
| 4069 | minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE; |
| 4070 | } |
| 4071 | } |
| 4072 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4073 | /** |
| 4074 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 4075 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 4076 | * homogeneous children type which is currently required by sub-classes of |
| 4077 | * {@link WindowContainer} class. |
| 4078 | */ |
| 4079 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 4080 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4081 | DisplayChildWindowContainer(WindowManagerService service) { |
| 4082 | super(service); |
| 4083 | } |
| 4084 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4085 | @Override |
| 4086 | boolean fillsParent() { |
| 4087 | return true; |
| 4088 | } |
| 4089 | |
| 4090 | @Override |
| 4091 | boolean isVisible() { |
| 4092 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4093 | } |
| 4094 | } |
| 4095 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4096 | /** |
| 4097 | * Window container class that contains all containers on this display relating to Apps. |
| 4098 | * I.e Activities. |
| 4099 | */ |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4100 | private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4101 | /** |
| 4102 | * A control placed at the appropriate level for transitions to occur. |
| 4103 | */ |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4104 | SurfaceControl mAppAnimationLayer = null; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4105 | SurfaceControl mBoostedAppAnimationLayer = null; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4106 | SurfaceControl mHomeAppAnimationLayer = null; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4107 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4108 | /** |
| 4109 | * Given that the split-screen divider does not have an AppWindowToken, it |
| 4110 | * will have to live inside of a "NonAppWindowContainer", in particular |
| 4111 | * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order |
| 4112 | * it will need to be interleaved with some of our children, appearing on top of |
| 4113 | * both docked stacks but underneath any assistant stacks. |
| 4114 | * |
| 4115 | * To solve this problem we have this anchor control, which will always exist so |
| 4116 | * we can always assign it the correct value in our {@link #assignChildLayers}. |
| 4117 | * Likewise since it always exists, {@link AboveAppWindowContainers} can always |
| 4118 | * assign the divider a layer relative to it. This way we prevent linking lifecycle |
| 4119 | * events between the two containers. |
| 4120 | */ |
| 4121 | SurfaceControl mSplitScreenDividerAnchor = null; |
| 4122 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4123 | // Cached reference to some special stacks we tend to get a lot so we don't need to loop |
| 4124 | // through the list to find them. |
| 4125 | private TaskStack mHomeStack = null; |
| 4126 | private TaskStack mPinnedStack = null; |
| 4127 | private TaskStack mSplitScreenPrimaryStack = null; |
| 4128 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4129 | TaskStackContainers(WindowManagerService service) { |
| 4130 | super(service); |
| 4131 | } |
| 4132 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4133 | /** |
| 4134 | * Returns the topmost stack on the display that is compatible with the input windowing mode |
| 4135 | * and activity type. Null is no compatible stack on the display. |
| 4136 | */ |
| 4137 | TaskStack getStack(int windowingMode, int activityType) { |
| 4138 | if (activityType == ACTIVITY_TYPE_HOME) { |
| 4139 | return mHomeStack; |
| 4140 | } |
| 4141 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 4142 | return mPinnedStack; |
| 4143 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4144 | return mSplitScreenPrimaryStack; |
| 4145 | } |
| 4146 | for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) { |
| 4147 | final TaskStack stack = mTaskStackContainers.getChildAt(i); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4148 | if (activityType == ACTIVITY_TYPE_UNDEFINED |
| 4149 | && windowingMode == stack.getWindowingMode()) { |
| 4150 | // Passing in undefined type means we want to match the topmost stack with the |
| 4151 | // windowing mode. |
| 4152 | return stack; |
| 4153 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4154 | if (stack.isCompatible(windowingMode, activityType)) { |
| 4155 | return stack; |
| 4156 | } |
| 4157 | } |
| 4158 | return null; |
| 4159 | } |
| 4160 | |
| 4161 | @VisibleForTesting |
| 4162 | TaskStack getTopStack() { |
| 4163 | return mTaskStackContainers.getChildCount() > 0 |
| 4164 | ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null; |
| 4165 | } |
| 4166 | |
| 4167 | TaskStack getHomeStack() { |
| 4168 | if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) { |
| 4169 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
| 4170 | } |
| 4171 | return mHomeStack; |
| 4172 | } |
| 4173 | |
| 4174 | TaskStack getPinnedStack() { |
| 4175 | return mPinnedStack; |
| 4176 | } |
| 4177 | |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 4178 | TaskStack getSplitScreenPrimaryStack() { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4179 | return mSplitScreenPrimaryStack; |
| 4180 | } |
| 4181 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 4182 | ArrayList<Task> getVisibleTasks() { |
| 4183 | final ArrayList<Task> visibleTasks = new ArrayList<>(); |
| 4184 | forAllTasks(task -> { |
| 4185 | if (task.isVisible()) { |
| 4186 | visibleTasks.add(task); |
| 4187 | } |
| 4188 | }); |
| 4189 | return visibleTasks; |
| 4190 | } |
| 4191 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4192 | /** |
| 4193 | * Adds the stack to this container. |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4194 | */ |
| 4195 | void addStackToDisplay(TaskStack stack, boolean onTop) { |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4196 | addStackReferenceIfNeeded(stack); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4197 | addChild(stack, onTop); |
| 4198 | stack.onDisplayChanged(DisplayContent.this); |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4199 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4200 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4201 | void onStackWindowingModeChanged(TaskStack stack) { |
| 4202 | removeStackReferenceIfNeeded(stack); |
| 4203 | addStackReferenceIfNeeded(stack); |
| 4204 | if (stack == mPinnedStack && getTopStack() != stack) { |
| 4205 | // Looks like this stack changed windowing mode to pinned. Move it to the top. |
| 4206 | positionChildAt(POSITION_TOP, stack, false /* includingParents */); |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | private void addStackReferenceIfNeeded(TaskStack stack) { |
| 4211 | if (stack.isActivityTypeHome()) { |
| 4212 | if (mHomeStack != null) { |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4213 | throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack=" |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4214 | + mHomeStack + " already exist on display=" + this + " stack=" + stack); |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4215 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4216 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 4217 | mHomeStack = stack; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4218 | } |
| 4219 | final int windowingMode = stack.getWindowingMode(); |
| 4220 | if (windowingMode == WINDOWING_MODE_PINNED) { |
| 4221 | if (mPinnedStack != null) { |
| 4222 | throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack=" |
| 4223 | + mPinnedStack + " already exist on display=" + this |
| 4224 | + " stack=" + stack); |
| 4225 | } |
| 4226 | mPinnedStack = stack; |
| 4227 | } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4228 | if (mSplitScreenPrimaryStack != null) { |
| 4229 | throw new IllegalArgumentException("addStackReferenceIfNeeded:" |
| 4230 | + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack |
| 4231 | + " already exist on display=" + this + " stack=" + stack); |
| 4232 | } |
| 4233 | mSplitScreenPrimaryStack = stack; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4234 | mDividerControllerLocked.notifyDockedStackExistsChanged(true); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | private void removeStackReferenceIfNeeded(TaskStack stack) { |
| 4239 | if (stack == mHomeStack) { |
| 4240 | mHomeStack = null; |
| 4241 | } else if (stack == mPinnedStack) { |
| 4242 | mPinnedStack = null; |
| 4243 | } else if (stack == mSplitScreenPrimaryStack) { |
| 4244 | mSplitScreenPrimaryStack = null; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4245 | // 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] | 4246 | mWmService.setDockedStackCreateStateLocked( |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4247 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 4248 | mDividerControllerLocked.notifyDockedStackExistsChanged(false); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4249 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4250 | } |
| 4251 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4252 | private void addChild(TaskStack stack, boolean toTop) { |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4253 | final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack, |
| 4254 | true /* adding */); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4255 | addChild(stack, addIndex); |
| 4256 | setLayoutNeeded(); |
| 4257 | } |
| 4258 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4259 | @Override |
| 4260 | protected void removeChild(TaskStack stack) { |
| 4261 | super.removeChild(stack); |
| 4262 | removeStackReferenceIfNeeded(stack); |
| 4263 | } |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 4264 | |
| 4265 | @Override |
| 4266 | boolean isOnTop() { |
| 4267 | // Considered always on top |
| 4268 | return true; |
| 4269 | } |
| 4270 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4271 | @Override |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4272 | void positionChildAt(int position, TaskStack child, boolean includingParents) { |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 4273 | if (child.getWindowConfiguration().isAlwaysOnTop() |
| 4274 | && position != POSITION_TOP) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4275 | // This stack is always-on-top, override the default behavior. |
| 4276 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom"); |
| 4277 | |
| 4278 | // Moving to its current position, as we must call super but we don't want to |
| 4279 | // perform any meaningful action. |
| 4280 | final int currentPosition = mChildren.indexOf(child); |
| 4281 | super.positionChildAt(currentPosition, child, false /* includingParents */); |
| 4282 | return; |
| 4283 | } |
| 4284 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4285 | final int targetPosition = findPositionForStack(position, child, false /* adding */); |
| 4286 | super.positionChildAt(targetPosition, child, includingParents); |
| 4287 | |
Riddle Hsu | 2f6e174 | 2018-08-23 22:44:36 +0800 | [diff] [blame] | 4288 | if (includingParents) { |
| 4289 | // We still want to move the display of this stack container to top because even the |
| 4290 | // target position is adjusted to non-top, the intention of the condition is to have |
| 4291 | // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front |
| 4292 | // in a non-top display which is using picture-in-picture mode). |
| 4293 | final int topChildPosition = getChildCount() - 1; |
| 4294 | if (targetPosition < topChildPosition && position >= topChildPosition) { |
| 4295 | getParent().positionChildAt(POSITION_TOP, this /* child */, |
| 4296 | true /* includingParents */); |
| 4297 | } |
| 4298 | } |
| 4299 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4300 | setLayoutNeeded(); |
| 4301 | } |
| 4302 | |
| 4303 | /** |
| 4304 | * When stack is added or repositioned, find a proper position for it. |
| 4305 | * This will make sure that pinned stack always stays on top. |
| 4306 | * @param requestedPosition Position requested by caller. |
| 4307 | * @param stack Stack to be added or positioned. |
| 4308 | * @param adding Flag indicates whether we're adding a new stack or positioning an existing. |
| 4309 | * @return The proper position for the stack. |
| 4310 | */ |
| 4311 | private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4312 | if (stack.inPinnedWindowingMode()) { |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4313 | return POSITION_TOP; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4314 | } |
| 4315 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4316 | final int topChildPosition = mChildren.size() - 1; |
| 4317 | int belowAlwaysOnTopPosition = POSITION_BOTTOM; |
| 4318 | for (int i = topChildPosition; i >= 0; --i) { |
| 4319 | if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) { |
| 4320 | belowAlwaysOnTopPosition = i; |
| 4321 | break; |
| 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | // The max possible position we can insert the stack at. |
| 4326 | int maxPosition = POSITION_TOP; |
| 4327 | // The min possible position we can insert the stack at. |
| 4328 | int minPosition = POSITION_BOTTOM; |
| 4329 | |
| 4330 | if (stack.isAlwaysOnTop()) { |
| 4331 | if (hasPinnedStack()) { |
| 4332 | // Always-on-top stacks go below the pinned stack. |
| 4333 | maxPosition = getStacks().indexOf(mPinnedStack) - 1; |
| 4334 | } |
| 4335 | // Always-on-top stacks need to be above all other stacks. |
| 4336 | minPosition = belowAlwaysOnTopPosition != |
| 4337 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition; |
| 4338 | } else { |
| 4339 | // Other stacks need to be below the always-on-top stacks. |
| 4340 | maxPosition = belowAlwaysOnTopPosition != |
Arthur Hung | 928d8dc | 2018-07-18 15:38:05 +0800 | [diff] [blame] | 4341 | POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0; |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | int targetPosition = requestedPosition; |
| 4345 | targetPosition = Math.min(targetPosition, maxPosition); |
| 4346 | targetPosition = Math.max(targetPosition, minPosition); |
| 4347 | |
| 4348 | int prevPosition = getStacks().indexOf(stack); |
| 4349 | // The positions we calculated above (maxPosition, minPosition) do not take into |
| 4350 | // consideration the following edge cases. |
| 4351 | // 1) We need to adjust the position depending on the value "adding". |
| 4352 | // 2) When we are moving a stack to another position, we also need to adjust the |
| 4353 | // position depending on whether the stack is moving to a higher or lower position. |
| 4354 | if ((targetPosition != requestedPosition) && |
| 4355 | (adding || targetPosition < prevPosition)) { |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 4356 | targetPosition++; |
| 4357 | } |
| 4358 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 4359 | return targetPosition; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4363 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 4364 | boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4365 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4366 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4367 | return true; |
| 4368 | } |
| 4369 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4370 | return true; |
| 4371 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4372 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4373 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 4374 | return true; |
| 4375 | } |
| 4376 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 4377 | return true; |
| 4378 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4379 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4380 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4383 | private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback, |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4384 | boolean traverseTopToBottom) { |
| 4385 | // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the |
| 4386 | // app tokens. |
| 4387 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 4388 | // in-order. |
| 4389 | if (traverseTopToBottom) { |
| 4390 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 4391 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 4392 | for (int j = appTokens.size() - 1; j >= 0; --j) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4393 | if (appTokens.get(j).forAllWindowsUnchecked(callback, |
| 4394 | traverseTopToBottom)) { |
| 4395 | return true; |
| 4396 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4397 | } |
| 4398 | } |
| 4399 | } else { |
| 4400 | final int count = mChildren.size(); |
| 4401 | for (int i = 0; i < count; ++i) { |
| 4402 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 4403 | final int appTokensCount = appTokens.size(); |
| 4404 | for (int j = 0; j < appTokensCount; j++) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4405 | if (appTokens.get(j).forAllWindowsUnchecked(callback, |
| 4406 | traverseTopToBottom)) { |
| 4407 | return true; |
| 4408 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4409 | } |
| 4410 | } |
| 4411 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4412 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4413 | } |
| 4414 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4415 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 4416 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 4417 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 4418 | for (int j = appTokens.size() - 1; j >= 0; --j) { |
| 4419 | appTokens.get(j).hasVisible = hasVisible; |
| 4420 | } |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | void removeExistingAppTokensIfPossible() { |
| 4425 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 4426 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 4427 | for (int j = appTokens.size() - 1; j >= 0; --j) { |
| 4428 | final AppWindowToken token = appTokens.get(j); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4429 | if (!token.hasVisible && !mClosingApps.contains(token) |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4430 | && (!token.mIsExiting || token.isEmpty())) { |
| 4431 | // Make sure there is no animation running on this token, so any windows |
| 4432 | // associated with it will be removed as soon as their animations are |
| 4433 | // complete. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 4434 | cancelAnimation(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4435 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4436 | "performLayout: App token exiting now removed" + token); |
| 4437 | token.removeIfPossible(); |
| 4438 | } |
| 4439 | } |
| 4440 | } |
| 4441 | } |
| 4442 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4443 | @Override |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4444 | int getOrientation() { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4445 | if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
| 4446 | || isStackVisible(WINDOWING_MODE_FREEFORM)) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4447 | // 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] | 4448 | // docked or freeform stack is visible...except for the home stack if the docked |
| 4449 | // stack is minimized and it actually set something and the bounds is different from |
| 4450 | // the display. |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4451 | if (mHomeStack != null && mHomeStack.isVisible() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4452 | && mDividerControllerLocked.isMinimizedDock() |
Wale Ogunwale | cf2d647 | 2018-06-14 08:55:42 -0700 | [diff] [blame] | 4453 | && !(mDividerControllerLocked.isHomeStackResizable() |
| 4454 | && mHomeStack.matchParentBounds())) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4455 | final int orientation = mHomeStack.getOrientation(); |
| 4456 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 4457 | return orientation; |
| 4458 | } |
| 4459 | } |
| 4460 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 4461 | } |
| 4462 | |
| 4463 | final int orientation = super.getOrientation(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4464 | boolean isCar = mWmService.mContext.getPackageManager().hasSystemFeature( |
Dean Harding | 3e5a152 | 2017-10-06 09:19:01 -0700 | [diff] [blame] | 4465 | PackageManager.FEATURE_AUTOMOTIVE); |
| 4466 | if (isCar) { |
| 4467 | // In a car, you cannot physically rotate the screen, so it doesn't make sense to |
| 4468 | // allow anything but the default orientation. |
| 4469 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 4470 | "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId |
| 4471 | + ". Ignoring " + orientation); |
Dean Harding | 3e5a152 | 2017-10-06 09:19:01 -0700 | [diff] [blame] | 4472 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 4473 | } |
| 4474 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4475 | if (orientation != SCREEN_ORIENTATION_UNSET |
| 4476 | && orientation != SCREEN_ORIENTATION_BEHIND) { |
| 4477 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 4478 | "App is requesting an orientation, return " + orientation |
| 4479 | + " for display id=" + mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4480 | return orientation; |
| 4481 | } |
| 4482 | |
| 4483 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 4484 | "No app is requesting an orientation, return " + mLastOrientation |
| 4485 | + " for display id=" + mDisplayId); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4486 | // The next app has not been requested to be visible, so we keep the current orientation |
| 4487 | // to prevent freezing/unfreezing the display too early. |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4488 | return mLastOrientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 4489 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4490 | |
| 4491 | @Override |
| 4492 | void assignChildLayers(SurfaceControl.Transaction t) { |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4493 | assignStackOrdering(t); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4494 | |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4495 | for (int i = 0; i < mChildren.size(); i++) { |
| 4496 | final TaskStack s = mChildren.get(i); |
| 4497 | s.assignChildLayers(t); |
| 4498 | } |
| 4499 | } |
| 4500 | |
| 4501 | void assignStackOrdering(SurfaceControl.Transaction t) { |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4502 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4503 | final int HOME_STACK_STATE = 0; |
| 4504 | final int NORMAL_STACK_STATE = 1; |
| 4505 | final int ALWAYS_ON_TOP_STATE = 2; |
| 4506 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4507 | int layer = 0; |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4508 | int layerForAnimationLayer = 0; |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4509 | int layerForBoostedAnimationLayer = 0; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4510 | int layerForHomeAnimationLayer = 0; |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4511 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4512 | for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) { |
| 4513 | for (int i = 0; i < mChildren.size(); i++) { |
| 4514 | final TaskStack s = mChildren.get(i); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4515 | if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) { |
| 4516 | continue; |
| 4517 | } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome() |
| 4518 | || s.isAlwaysOnTop())) { |
| 4519 | continue; |
| 4520 | } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) { |
| 4521 | continue; |
| 4522 | } |
| 4523 | s.assignLayer(t, layer++); |
| 4524 | if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) { |
| 4525 | t.setLayer(mSplitScreenDividerAnchor, layer++); |
| 4526 | } |
Winson Chung | d41f71d | 2018-03-16 15:26:07 -0700 | [diff] [blame] | 4527 | if ((s.isTaskAnimating() || s.isAppAnimating()) |
| 4528 | && state != ALWAYS_ON_TOP_STATE) { |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4529 | // Ensure the animation layer ends up above the |
| 4530 | // highest animating stack and no higher. |
| 4531 | layerForAnimationLayer = layer++; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4532 | } |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4533 | if (state != ALWAYS_ON_TOP_STATE) { |
| 4534 | layerForBoostedAnimationLayer = layer++; |
| 4535 | } |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4536 | } |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4537 | if (state == HOME_STACK_STATE) { |
| 4538 | layerForHomeAnimationLayer = layer++; |
| 4539 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4540 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4541 | if (mAppAnimationLayer != null) { |
| 4542 | t.setLayer(mAppAnimationLayer, layerForAnimationLayer); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4543 | } |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4544 | if (mBoostedAppAnimationLayer != null) { |
| 4545 | t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer); |
| 4546 | } |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4547 | if (mHomeAppAnimationLayer != null) { |
| 4548 | t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer); |
| 4549 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | @Override |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4553 | SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) { |
| 4554 | switch (animationLayer) { |
| 4555 | case ANIMATION_LAYER_BOOSTED: |
| 4556 | return mBoostedAppAnimationLayer; |
| 4557 | case ANIMATION_LAYER_HOME: |
| 4558 | return mHomeAppAnimationLayer; |
| 4559 | case ANIMATION_LAYER_STANDARD: |
| 4560 | default: |
| 4561 | return mAppAnimationLayer; |
| 4562 | } |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4563 | } |
| 4564 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4565 | SurfaceControl getSplitScreenDividerAnchor() { |
| 4566 | return mSplitScreenDividerAnchor; |
| 4567 | } |
| 4568 | |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4569 | @Override |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 4570 | void onParentChanged() { |
| 4571 | super.onParentChanged(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4572 | if (getParent() != null) { |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4573 | mAppAnimationLayer = makeChildSurface(null) |
| 4574 | .setName("animationLayer") |
| 4575 | .build(); |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4576 | mBoostedAppAnimationLayer = makeChildSurface(null) |
| 4577 | .setName("boostedAnimationLayer") |
| 4578 | .build(); |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4579 | mHomeAppAnimationLayer = makeChildSurface(null) |
| 4580 | .setName("homeAnimationLayer") |
| 4581 | .build(); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4582 | mSplitScreenDividerAnchor = makeChildSurface(null) |
| 4583 | .setName("splitScreenDividerAnchor") |
| 4584 | .build(); |
| 4585 | getPendingTransaction() |
| 4586 | .show(mAppAnimationLayer) |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4587 | .show(mBoostedAppAnimationLayer) |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4588 | .show(mHomeAppAnimationLayer) |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4589 | .show(mSplitScreenDividerAnchor); |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4590 | scheduleAnimation(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4591 | } else { |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 4592 | mAppAnimationLayer.remove(); |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 4593 | mAppAnimationLayer = null; |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 4594 | mBoostedAppAnimationLayer.remove(); |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4595 | mBoostedAppAnimationLayer = null; |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 4596 | mHomeAppAnimationLayer.remove(); |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 4597 | mHomeAppAnimationLayer = null; |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 4598 | mSplitScreenDividerAnchor.remove(); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4599 | mSplitScreenDividerAnchor = null; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4600 | } |
| 4601 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4602 | } |
| 4603 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4604 | private final class AboveAppWindowContainers extends NonAppWindowContainers { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4605 | AboveAppWindowContainers(String name, WindowManagerService service) { |
| 4606 | super(name, service); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4607 | } |
| 4608 | |
Robert Carr | b950603 | 2018-02-13 13:54:00 -0800 | [diff] [blame] | 4609 | @Override |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 4610 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
| 4611 | final SurfaceControl.Builder builder = super.makeChildSurface(child); |
| 4612 | if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) { |
| 4613 | // To draw above the ColorFade layer during the screen off transition, the |
| 4614 | // rounded corner overlays need to be at the root of the surface hierarchy. |
| 4615 | // TODO: move the ColorLayer into the display overlay layer such that this is not |
| 4616 | // necessary anymore. |
| 4617 | builder.setParent(null); |
| 4618 | } |
| 4619 | return builder; |
| 4620 | } |
| 4621 | |
| 4622 | @Override |
Robert Carr | b950603 | 2018-02-13 13:54:00 -0800 | [diff] [blame] | 4623 | void assignChildLayers(SurfaceControl.Transaction t) { |
| 4624 | assignChildLayers(t, null /* imeContainer */); |
| 4625 | } |
| 4626 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4627 | void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) { |
| 4628 | boolean needAssignIme = imeContainer != null |
| 4629 | && imeContainer.getSurfaceControl() != null; |
| 4630 | for (int j = 0; j < mChildren.size(); ++j) { |
| 4631 | final WindowToken wt = mChildren.get(j); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 4632 | |
| 4633 | // See {@link mSplitScreenDividerAnchor} |
| 4634 | if (wt.windowType == TYPE_DOCK_DIVIDER) { |
| 4635 | wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1); |
| 4636 | continue; |
| 4637 | } |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 4638 | if (wt.mRoundedCornerOverlay) { |
| 4639 | wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1); |
| 4640 | continue; |
| 4641 | } |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4642 | wt.assignLayer(t, j); |
| 4643 | wt.assignChildLayers(t); |
| 4644 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4645 | int layer = mWmService.mPolicy.getWindowLayerFromTypeLw( |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4646 | wt.windowType, wt.mOwnerCanManageAppTokens); |
Robert Carr | b8e78fa | 2017-11-28 13:07:58 -0800 | [diff] [blame] | 4647 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4648 | if (needAssignIme && layer >= mWmService.mPolicy.getWindowLayerFromTypeLw( |
Robert Carr | b8e78fa | 2017-11-28 13:07:58 -0800 | [diff] [blame] | 4649 | TYPE_INPUT_METHOD_DIALOG, true)) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4650 | imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4651 | needAssignIme = false; |
| 4652 | } |
| 4653 | } |
| 4654 | if (needAssignIme) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4655 | imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4656 | } |
| 4657 | } |
| 4658 | } |
| 4659 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4660 | /** |
| 4661 | * Window container class that contains all containers on this display that are not related to |
| 4662 | * Apps. E.g. status bar. |
| 4663 | */ |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4664 | private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4665 | /** |
| 4666 | * Compares two child window tokens returns -1 if the first is lesser than the second in |
| 4667 | * terms of z-order and 1 otherwise. |
| 4668 | */ |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4669 | private final Comparator<WindowToken> mWindowComparator = (token1, token2) -> |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4670 | // Tokens with higher base layer are z-ordered on-top. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4671 | mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4672 | token1.mOwnerCanManageAppTokens) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4673 | < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 4674 | token2.mOwnerCanManageAppTokens) ? -1 : 1; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 4675 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4676 | private final Predicate<WindowState> mGetOrientingWindow = w -> { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 4677 | if (!w.isVisibleLw() || !w.mLegacyPolicyVisibilityAfterAnim) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4678 | return false; |
| 4679 | } |
| 4680 | final int req = w.mAttrs.screenOrientation; |
| 4681 | if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND |
| 4682 | || req == SCREEN_ORIENTATION_UNSET) { |
| 4683 | return false; |
| 4684 | } |
| 4685 | return true; |
| 4686 | }; |
| 4687 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4688 | private final String mName; |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4689 | private final Dimmer mDimmer = new Dimmer(this); |
| 4690 | private final Rect mTmpDimBoundsRect = new Rect(); |
| 4691 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4692 | NonAppWindowContainers(String name, WindowManagerService service) { |
| 4693 | super(service); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4694 | mName = name; |
| 4695 | } |
| 4696 | |
| 4697 | void addChild(WindowToken token) { |
| 4698 | addChild(token, mWindowComparator); |
| 4699 | } |
| 4700 | |
| 4701 | @Override |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4702 | int getOrientation() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4703 | final WindowManagerPolicy policy = mWmService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4704 | // Find a window requesting orientation. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 4705 | final WindowState win = getWindow(mGetOrientingWindow); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4706 | |
| 4707 | if (win != null) { |
| 4708 | final int req = win.mAttrs.screenOrientation; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4709 | if (policy.isKeyguardHostWindow(win.mAttrs)) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4710 | mLastKeyguardForcedOrientation = req; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4711 | if (mWmService.mKeyguardGoingAway) { |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 4712 | // Keyguard can't affect the orientation if it is going away... |
| 4713 | mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 4714 | return SCREEN_ORIENTATION_UNSET; |
| 4715 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4716 | } |
Andrii Kulian | ef5ce1c | 2018-03-20 19:27:24 -0700 | [diff] [blame] | 4717 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req |
| 4718 | + " for display id=" + mDisplayId); |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4719 | return (mLastWindowForcedOrientation = req); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4720 | } |
| 4721 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4722 | mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4723 | |
Jorim Jaggi | 1c53059 | 2018-04-06 15:11:47 +0200 | [diff] [blame] | 4724 | // Only allow force setting the orientation when all unknown visibilities have been |
| 4725 | // resolved, as otherwise we just may be starting another occluding activity. |
| 4726 | final boolean isUnoccluding = |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4727 | mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE |
| 4728 | && mUnknownAppVisibilityController.allResolved(); |
Jorim Jaggi | 1c53059 | 2018-04-06 15:11:47 +0200 | [diff] [blame] | 4729 | if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4730 | return mLastKeyguardForcedOrientation; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | return SCREEN_ORIENTATION_UNSET; |
| 4734 | } |
| 4735 | |
| 4736 | @Override |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4737 | String getName() { |
| 4738 | return mName; |
| 4739 | } |
chaviw | f29223e | 2018-01-31 13:23:51 -0800 | [diff] [blame] | 4740 | |
| 4741 | @Override |
| 4742 | Dimmer getDimmer() { |
| 4743 | return mDimmer; |
| 4744 | } |
| 4745 | |
| 4746 | @Override |
| 4747 | void prepareSurfaces() { |
| 4748 | mDimmer.resetDimStates(); |
| 4749 | super.prepareSurfaces(); |
| 4750 | getBounds(mTmpDimBoundsRect); |
| 4751 | |
| 4752 | if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) { |
| 4753 | scheduleAnimation(); |
| 4754 | } |
| 4755 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 4756 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 4757 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4758 | SurfaceControl.Builder makeSurface(SurfaceSession s) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4759 | return mWmService.makeSurfaceBuilder(s) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4760 | .setParent(mWindowingLayer); |
| 4761 | } |
| 4762 | |
| 4763 | @Override |
| 4764 | SurfaceSession getSession() { |
| 4765 | return mSession; |
| 4766 | } |
| 4767 | |
| 4768 | @Override |
| 4769 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4770 | SurfaceSession s = child != null ? child.getSession() : getSession(); |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 4771 | final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s).setContainerLayer(); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4772 | if (child == null) { |
| 4773 | return b; |
| 4774 | } |
| 4775 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4776 | return b.setName(child.getName()) |
| 4777 | .setParent(mWindowingLayer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | /** |
| 4781 | * The makeSurface variants are for use by the window-container |
| 4782 | * hierarchy. makeOverlay here is a function for various non windowing |
| 4783 | * overlays like the ScreenRotation screenshot, the Strict Mode Flash |
| 4784 | * and other potpourii. |
| 4785 | */ |
| 4786 | SurfaceControl.Builder makeOverlay() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4787 | return mWmService.makeSurfaceBuilder(mSession) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4788 | .setParent(mOverlayLayer); |
| 4789 | } |
| 4790 | |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4791 | /** |
| 4792 | * Reparents the given surface to mOverlayLayer. |
| 4793 | */ |
| 4794 | void reparentToOverlay(Transaction transaction, SurfaceControl surface) { |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 4795 | transaction.reparent(surface, mOverlayLayer); |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [diff] [blame] | 4796 | } |
| 4797 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4798 | void applyMagnificationSpec(MagnificationSpec spec) { |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4799 | if (spec.scale != 1.0) { |
| 4800 | mMagnificationSpec = spec; |
| 4801 | } else { |
| 4802 | mMagnificationSpec = null; |
| 4803 | } |
Jackal Guo | 818c3f1 | 2019-03-08 18:00:39 +0800 | [diff] [blame] | 4804 | // Re-parent IME's SurfaceControl when MagnificationSpec changed. |
| 4805 | updateImeParent(); |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4806 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4807 | applyMagnificationSpec(getPendingTransaction(), spec); |
| 4808 | getPendingTransaction().apply(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4809 | } |
| 4810 | |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 4811 | void reapplyMagnificationSpec() { |
| 4812 | if (mMagnificationSpec != null) { |
| 4813 | applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec); |
| 4814 | } |
| 4815 | } |
| 4816 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4817 | @Override |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 4818 | void onParentChanged() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4819 | // Since we are the top of the SurfaceControl hierarchy here |
| 4820 | // we create the root surfaces explicitly rather than chaining |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 4821 | // up as the default implementation in onParentChanged does. So we |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4822 | // explicitly do NOT call super here. |
| 4823 | } |
| 4824 | |
| 4825 | @Override |
| 4826 | void assignChildLayers(SurfaceControl.Transaction t) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4827 | |
| 4828 | // These are layers as children of "mWindowingLayer" |
| 4829 | mBelowAppWindowsContainers.assignLayer(t, 0); |
| 4830 | mTaskStackContainers.assignLayer(t, 1); |
| 4831 | mAboveAppWindowsContainers.assignLayer(t, 2); |
| 4832 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 4833 | final WindowState imeTarget = mInputMethodTarget; |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4834 | boolean needAssignIme = true; |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4835 | |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4836 | // In the case where we have an IME target that is not in split-screen |
| 4837 | // mode IME assignment is easy. We just need the IME to go directly above |
| 4838 | // the target. This way children of the target will naturally go above the IME |
| 4839 | // and everyone is happy. |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4840 | // |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4841 | // In the case of split-screen windowing mode, we need to elevate the IME above the |
| 4842 | // docked divider while keeping the app itself below the docked divider, so instead |
| 4843 | // we use relative layering of the IME targets child windows, and place the |
| 4844 | // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}). |
Robert Carr | 1cafdf8 | 2017-11-22 13:56:43 -0800 | [diff] [blame] | 4845 | // |
Robert Carr | 234b633 | 2018-03-20 13:38:16 -0700 | [diff] [blame] | 4846 | // In the case the IME target is animating, the animation Z order may be different |
| 4847 | // than the WindowContainer Z order, so it's difficult to be sure we have the correct |
| 4848 | // IME target. In this case we just layer the IME over all transitions by placing it in the |
| 4849 | // above applications layer. |
| 4850 | // |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4851 | // In the case where we have no IME target we assign it where it's base layer would |
| 4852 | // place it in the AboveAppWindowContainers. |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 4853 | // |
| 4854 | // Keep IME window in mAboveAppWindowsContainers as long as app's starting window exists |
| 4855 | // so it get's layered above the starting window. |
| 4856 | if (imeTarget != null |
| 4857 | && !(imeTarget.mAppToken != null && imeTarget.mAppToken.hasStartingWindow()) |
| 4858 | && (!(imeTarget.inSplitScreenWindowingMode() || imeTarget.mToken.isAppAnimating()) |
| 4859 | && (imeTarget.getSurfaceControl() != null))) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 4860 | mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(), |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4861 | // TODO: We need to use an extra level on the app surface to ensure |
| 4862 | // this is always above SurfaceView but always below attached window. |
| 4863 | 1); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4864 | needAssignIme = false; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | // Above we have assigned layers to our children, now we ask them to assign |
| 4868 | // layers to their children. |
| 4869 | mBelowAppWindowsContainers.assignChildLayers(t); |
| 4870 | mTaskStackContainers.assignChildLayers(t); |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4871 | mAboveAppWindowsContainers.assignChildLayers(t, |
| 4872 | needAssignIme == true ? mImeWindowsContainers : null); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4873 | mImeWindowsContainers.assignChildLayers(t); |
| 4874 | } |
| 4875 | |
| 4876 | /** |
| 4877 | * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine |
| 4878 | * that the IME target is one of the docked applications. We'd like the docked divider to be |
| 4879 | * above both of the applications, and we'd like the IME to be above the docked divider. |
| 4880 | * However we need child windows of the applications to be above the IME (Text drag handles). |
| 4881 | * This is a non-strictly hierarcical layering and we need to break out of the Z ordering |
| 4882 | * 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] | 4883 | * with {@link WindowState#assignLayer} |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4884 | */ |
| 4885 | void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) { |
Robert Carr | bb5de66 | 2018-04-26 13:29:51 -0700 | [diff] [blame] | 4886 | child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | @Override |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4890 | void prepareSurfaces() { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4891 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareSurfaces"); |
| 4892 | try { |
| 4893 | final ScreenRotationAnimation screenRotationAnimation = |
| 4894 | mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4895 | final Transaction transaction = getPendingTransaction(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4896 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { |
| 4897 | screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4898 | transaction.setMatrix(mWindowingLayer, |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4899 | mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], |
| 4900 | mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4901 | transaction.setPosition(mWindowingLayer, |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4902 | mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4903 | transaction.setAlpha(mWindowingLayer, |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4904 | screenRotationAnimation.getEnterTransformation().getAlpha()); |
| 4905 | } |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 4906 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4907 | super.prepareSurfaces(); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4908 | |
| 4909 | // TODO: Once we totally eliminate global transaction we will pass transaction in here |
| 4910 | // rather than merging to global. |
| 4911 | SurfaceControl.mergeToGlobalTransaction(transaction); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4912 | } finally { |
| 4913 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 4914 | } |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4915 | } |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4916 | |
Jorim Jaggi | be41829 | 2018-03-26 16:14:12 +0200 | [diff] [blame] | 4917 | void assignStackOrdering() { |
| 4918 | mTaskStackContainers.assignStackOrdering(getPendingTransaction()); |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 4919 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4920 | |
| 4921 | /** |
| 4922 | * Increment the deferral count to determine whether to update the IME target. |
| 4923 | */ |
| 4924 | void deferUpdateImeTarget() { |
| 4925 | mDeferUpdateImeTargetCount++; |
| 4926 | } |
| 4927 | |
| 4928 | /** |
| 4929 | * Decrement the deferral count to determine whether to update the IME target. If the count |
| 4930 | * reaches 0, a new ime target will get computed. |
| 4931 | */ |
| 4932 | void continueUpdateImeTarget() { |
| 4933 | if (mDeferUpdateImeTargetCount == 0) { |
| 4934 | return; |
| 4935 | } |
| 4936 | |
| 4937 | mDeferUpdateImeTargetCount--; |
| 4938 | if (mDeferUpdateImeTargetCount == 0) { |
| 4939 | computeImeTarget(true /* updateImeTarget */); |
| 4940 | } |
| 4941 | } |
| 4942 | |
| 4943 | /** |
| 4944 | * @return Whether a new IME target should be computed. |
| 4945 | */ |
| 4946 | private boolean canUpdateImeTarget() { |
| 4947 | return mDeferUpdateImeTargetCount == 0; |
| 4948 | } |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 4949 | |
| 4950 | InputMonitor getInputMonitor() { |
| 4951 | return mInputMonitor; |
| 4952 | } |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 4953 | |
| 4954 | /** |
| 4955 | * @return Cached value whether we told display manager that we have content. |
| 4956 | */ |
| 4957 | boolean getLastHasContent() { |
| 4958 | return mLastHasContent; |
| 4959 | } |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4960 | |
| 4961 | void registerPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4962 | mPointerEventDispatcher.registerInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | void unregisterPointerEventListener(@NonNull PointerEventListener listener) { |
Riddle Hsu | 2588ab0 | 2019-02-25 14:23:56 +0800 | [diff] [blame] | 4966 | mPointerEventDispatcher.unregisterInputEventListener(listener); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 4967 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4968 | |
| 4969 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4970 | boolean alwaysKeepCurrent) { |
| 4971 | prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */); |
| 4972 | } |
| 4973 | |
| 4974 | void prepareAppTransition(@WindowManager.TransitionType int transit, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4975 | boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags, |
| 4976 | boolean forceOverride) { |
| 4977 | final boolean prepared = mAppTransition.prepareAppTransitionLocked( |
| 4978 | transit, alwaysKeepCurrent, flags, forceOverride); |
| 4979 | if (prepared && okToAnimate()) { |
| 4980 | mSkipAppTransitionAnimation = false; |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | void executeAppTransition() { |
| 4985 | if (mAppTransition.isTransitionSet()) { |
| 4986 | if (DEBUG_APP_TRANSITIONS) { |
| 4987 | Slog.w(TAG_WM, "Execute app transition: " + mAppTransition + ", displayId: " |
| 4988 | + mDisplayId + " Callers=" + Debug.getCallers(5)); |
| 4989 | } |
| 4990 | mAppTransition.setReady(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4991 | mWmService.mWindowPlacerLocked.requestTraversal(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4992 | } |
| 4993 | } |
| 4994 | |
| 4995 | /** |
| 4996 | * Update pendingLayoutChanges after app transition has finished. |
| 4997 | */ |
| 4998 | void handleAnimatingStoppedAndTransition() { |
| 4999 | int changes = 0; |
| 5000 | |
| 5001 | mAppTransition.setIdle(); |
| 5002 | |
| 5003 | for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) { |
| 5004 | final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i); |
| 5005 | mAppTransition.notifyAppTransitionFinishedLocked(token); |
| 5006 | } |
| 5007 | mNoAnimationNotifyOnTransitionFinished.clear(); |
| 5008 | |
| 5009 | mWallpaperController.hideDeferredWallpapersIfNeeded(); |
| 5010 | |
| 5011 | onAppTransitionDone(); |
| 5012 | |
| 5013 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5014 | if (DEBUG_WALLPAPER_LIGHT) { |
| 5015 | Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout"); |
| 5016 | } |
| 5017 | computeImeTarget(true /* updateImeTarget */); |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 5018 | mWallpaperMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5019 | // Since the window list has been rebuilt, focus might have to be recomputed since the |
| 5020 | // actual order of windows might have changed again. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5021 | mWmService.mFocusMayChange = true; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5022 | |
| 5023 | pendingLayoutChanges |= changes; |
| 5024 | } |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 5025 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5026 | /** Check if pending app transition is for activity / task launch. */ |
| 5027 | boolean isNextTransitionForward() { |
| 5028 | final int transit = mAppTransition.getAppTransition(); |
| 5029 | return transit == TRANSIT_ACTIVITY_OPEN |
| 5030 | || transit == TRANSIT_TASK_OPEN |
| 5031 | || transit == TRANSIT_TASK_TO_FRONT; |
| 5032 | } |
| 5033 | |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 5034 | /** |
| 5035 | * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS |
| 5036 | */ |
| 5037 | boolean supportsSystemDecorations() { |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 5038 | return (mWmService.mDisplayWindowSettings.shouldShowSystemDecorsLocked(this) |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 5039 | || (mDisplay.getFlags() & FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0 |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 5040 | || (mWmService.mForceDesktopModeOnExternalDisplays && !isUntrustedVirtualDisplay())) |
Arthur Hung | 879a8ab | 2019-03-13 19:51:10 +0800 | [diff] [blame] | 5041 | // VR virtual display will be used to run and render 2D app within a VR experience. |
| 5042 | && mDisplayId != mWmService.mVr2dDisplayId; |
Andrii Kulian | 15cfb42 | 2018-11-07 13:38:49 -0800 | [diff] [blame] | 5043 | } |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5044 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5045 | /** |
Chilun | 891aed2 | 2019-05-02 18:08:47 +0800 | [diff] [blame] | 5046 | * @return {@code true} if the display is non-system created virtual display. |
| 5047 | */ |
| 5048 | boolean isUntrustedVirtualDisplay() { |
| 5049 | return mDisplay.getType() == Display.TYPE_VIRTUAL |
| 5050 | && mDisplay.getOwnerUid() != Process.SYSTEM_UID; |
| 5051 | } |
| 5052 | |
| 5053 | /** |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5054 | * Re-parent the DisplayContent's top surfaces, {@link #mWindowingLayer} and |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5055 | * {@link #mOverlayLayer} to the specified SurfaceControl. |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5056 | * |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5057 | * @param win The window which owns the SurfaceControl. This indicates the z-order of the |
| 5058 | * windows of this display against the windows on the parent display. |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5059 | * @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] | 5060 | */ |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5061 | void reparentDisplayContent(WindowState win, SurfaceControl sc) { |
| 5062 | mParentWindow = win; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5063 | mParentWindow.addEmbeddedDisplayContent(this); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5064 | mParentSurfaceControl = sc; |
| 5065 | if (mPortalWindowHandle == null) { |
| 5066 | mPortalWindowHandle = createPortalWindowHandle(sc.toString()); |
| 5067 | } |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 5068 | getPendingTransaction().setInputWindowInfo(sc, mPortalWindowHandle) |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5069 | .reparent(mWindowingLayer, sc).reparent(mOverlayLayer, sc); |
| 5070 | } |
| 5071 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5072 | /** |
| 5073 | * Get the window which owns the surface that this DisplayContent is re-parented to. |
| 5074 | * |
| 5075 | * @return the parent window. |
| 5076 | */ |
| 5077 | WindowState getParentWindow() { |
| 5078 | return mParentWindow; |
| 5079 | } |
| 5080 | |
| 5081 | /** |
| 5082 | * Update the location of this display in the parent window. This enables windows in this |
| 5083 | * display to compute the global transformation matrix. |
| 5084 | * |
| 5085 | * @param win The parent window of this display. |
| 5086 | * @param x The x coordinate in the parent window. |
| 5087 | * @param y The y coordinate in the parent window. |
| 5088 | */ |
| 5089 | void updateLocation(WindowState win, int x, int y) { |
| 5090 | if (mParentWindow != win) { |
| 5091 | throw new IllegalArgumentException( |
| 5092 | "The given window is not the parent window of this display."); |
| 5093 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5094 | if (!mLocationInParentWindow.equals(x, y)) { |
| 5095 | mLocationInParentWindow.set(x, y); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5096 | if (mWmService.mAccessibilityController != null) { |
| 5097 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
| 5098 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5099 | notifyLocationInParentDisplayChanged(); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 5100 | } |
| 5101 | } |
| 5102 | |
| 5103 | Point getLocationInParentWindow() { |
| 5104 | return mLocationInParentWindow; |
| 5105 | } |
| 5106 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5107 | Point getLocationInParentDisplay() { |
| 5108 | final Point location = new Point(); |
| 5109 | if (mParentWindow != null) { |
| 5110 | // LocationInParentWindow indicates the offset to (0,0) of window, but what we need is |
| 5111 | // the offset to (0,0) of display. |
| 5112 | DisplayContent dc = this; |
| 5113 | do { |
| 5114 | final WindowState displayParent = dc.getParentWindow(); |
| 5115 | location.x += displayParent.getFrameLw().left |
| 5116 | + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f); |
| 5117 | location.y += displayParent.getFrameLw().top |
| 5118 | + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f); |
| 5119 | dc = displayParent.getDisplayContent(); |
| 5120 | } while (dc != null && dc.getParentWindow() != null); |
| 5121 | } |
| 5122 | return location; |
| 5123 | } |
| 5124 | |
| 5125 | void notifyLocationInParentDisplayChanged() { |
| 5126 | forAllWindows(w -> { |
| 5127 | w.updateLocationInParentDisplayIfNeeded(); |
| 5128 | }, false /* traverseTopToBottom */); |
| 5129 | } |
| 5130 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 5131 | @VisibleForTesting |
| 5132 | SurfaceControl getWindowingLayer() { |
| 5133 | return mWindowingLayer; |
| 5134 | } |
| 5135 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5136 | /** |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5137 | * Updates the display's system gesture exclusion. |
| 5138 | * |
| 5139 | * @return true, if the exclusion changed. |
| 5140 | */ |
| 5141 | boolean updateSystemGestureExclusion() { |
| 5142 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 0) { |
| 5143 | // No one's interested anyways. |
| 5144 | return false; |
| 5145 | } |
| 5146 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5147 | final Region systemGestureExclusion = Region.obtain(); |
| 5148 | mSystemGestureExclusionWasRestricted = calculateSystemGestureExclusion( |
| 5149 | systemGestureExclusion, mSystemGestureExclusionUnrestricted); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5150 | try { |
| 5151 | if (mSystemGestureExclusion.equals(systemGestureExclusion)) { |
| 5152 | return false; |
| 5153 | } |
| 5154 | mSystemGestureExclusion.set(systemGestureExclusion); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5155 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5156 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5157 | for (int i = mSystemGestureExclusionListeners.beginBroadcast() - 1; i >= 0; --i) { |
| 5158 | try { |
| 5159 | mSystemGestureExclusionListeners.getBroadcastItem(i) |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5160 | .onSystemGestureExclusionChanged(mDisplayId, systemGestureExclusion, |
| 5161 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5162 | } catch (RemoteException e) { |
| 5163 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener", e); |
| 5164 | } |
| 5165 | } |
| 5166 | mSystemGestureExclusionListeners.finishBroadcast(); |
| 5167 | return true; |
| 5168 | } finally { |
| 5169 | systemGestureExclusion.recycle(); |
| 5170 | } |
| 5171 | } |
| 5172 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5173 | /** |
| 5174 | * Calculates the system gesture exclusion. |
| 5175 | * |
| 5176 | * @param outExclusion will be set to the gesture exclusion region |
| 5177 | * @param outExclusionUnrestricted will be set to the gesture exclusion region without |
| 5178 | * any restrictions applied. |
| 5179 | * @return whether any restrictions were applied, i.e. outExclusion and outExclusionUnrestricted |
| 5180 | * differ. |
| 5181 | */ |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5182 | @VisibleForTesting |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5183 | boolean calculateSystemGestureExclusion(Region outExclusion, @Nullable |
| 5184 | Region outExclusionUnrestricted) { |
| 5185 | outExclusion.setEmpty(); |
| 5186 | if (outExclusionUnrestricted != null) { |
| 5187 | outExclusionUnrestricted.setEmpty(); |
| 5188 | } |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5189 | final Region unhandled = Region.obtain(); |
| 5190 | unhandled.set(0, 0, mDisplayFrames.mDisplayWidth, mDisplayFrames.mDisplayHeight); |
| 5191 | |
| 5192 | final Rect leftEdge = mInsetsStateController.getSourceProvider(TYPE_LEFT_GESTURES) |
| 5193 | .getSource().getFrame(); |
| 5194 | final Rect rightEdge = mInsetsStateController.getSourceProvider(TYPE_RIGHT_GESTURES) |
| 5195 | .getSource().getFrame(); |
| 5196 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5197 | final Region touchableRegion = Region.obtain(); |
| 5198 | final Region local = Region.obtain(); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5199 | final int[] remainingLeftRight = |
| 5200 | {mSystemGestureExclusionLimit, mSystemGestureExclusionLimit}; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5201 | |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5202 | // Traverse all windows top down to assemble the gesture exclusion rects. |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5203 | // For each window, we only take the rects that fall within its touchable region. |
| 5204 | forAllWindows(w -> { |
| 5205 | if (w.cantReceiveTouchInput() || !w.isVisible() |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5206 | || (w.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 |
| 5207 | || unhandled.isEmpty()) { |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5208 | return; |
| 5209 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5210 | |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5211 | // Get the touchable region of the window, and intersect with where the screen is still |
| 5212 | // touchable, i.e. touchable regions on top are not covering it yet. |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 5213 | w.getEffectiveTouchableRegion(touchableRegion); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5214 | touchableRegion.op(unhandled, Op.INTERSECT); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5215 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5216 | if (w.isImplicitlyExcludingAllSystemGestures()) { |
| 5217 | local.set(touchableRegion); |
| 5218 | } else { |
| 5219 | rectListToRegion(w.getSystemGestureExclusion(), local); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5220 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5221 | // Transform to display coordinates |
| 5222 | local.scale(w.mGlobalScale); |
| 5223 | final Rect frame = w.getWindowFrames().mFrame; |
| 5224 | local.translate(frame.left, frame.top); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5225 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 5226 | // A window can only exclude system gestures where it is actually touchable |
| 5227 | local.op(touchableRegion, Op.INTERSECT); |
| 5228 | } |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5229 | |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5230 | // Apply restriction if necessary. |
| 5231 | if (needsGestureExclusionRestrictions(w, mLastDispatchedSystemUiVisibility)) { |
| 5232 | |
| 5233 | // Processes the region along the left edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5234 | remainingLeftRight[0] = addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5235 | remainingLeftRight[0], w, EXCLUSION_LEFT); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5236 | |
| 5237 | // Processes the region along the right edge. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5238 | remainingLeftRight[1] = addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5239 | remainingLeftRight[1], w, EXCLUSION_RIGHT); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5240 | |
| 5241 | // Adds the middle (unrestricted area) |
| 5242 | final Region middle = Region.obtain(local); |
| 5243 | middle.op(leftEdge, Op.DIFFERENCE); |
| 5244 | middle.op(rightEdge, Op.DIFFERENCE); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5245 | outExclusion.op(middle, Op.UNION); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5246 | middle.recycle(); |
| 5247 | } else { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5248 | boolean loggable = needsGestureExclusionRestrictions(w, 0 /* lastSysUiVis */); |
| 5249 | if (loggable) { |
| 5250 | addToGlobalAndConsumeLimit(local, outExclusion, leftEdge, |
| 5251 | Integer.MAX_VALUE, w, EXCLUSION_LEFT); |
| 5252 | addToGlobalAndConsumeLimit(local, outExclusion, rightEdge, |
| 5253 | Integer.MAX_VALUE, w, EXCLUSION_RIGHT); |
| 5254 | } |
| 5255 | outExclusion.op(local, Op.UNION); |
| 5256 | } |
| 5257 | if (outExclusionUnrestricted != null) { |
| 5258 | outExclusionUnrestricted.op(local, Op.UNION); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5259 | } |
| 5260 | unhandled.op(touchableRegion, Op.DIFFERENCE); |
| 5261 | }, true /* topToBottom */); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5262 | local.recycle(); |
| 5263 | touchableRegion.recycle(); |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5264 | unhandled.recycle(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5265 | return remainingLeftRight[0] < mSystemGestureExclusionLimit |
| 5266 | || remainingLeftRight[1] < mSystemGestureExclusionLimit; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5267 | } |
| 5268 | |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5269 | /** |
| 5270 | * @return Whether gesture exclusion area should be restricted from the window depending on the |
| 5271 | * current SystemUI visibility flags. |
| 5272 | */ |
| 5273 | private static boolean needsGestureExclusionRestrictions(WindowState win, int sysUiVisibility) { |
| 5274 | final int type = win.mAttrs.type; |
| 5275 | final int stickyHideNavFlags = |
| 5276 | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 5277 | final boolean stickyHideNav = |
| 5278 | (sysUiVisibility & stickyHideNavFlags) == stickyHideNavFlags; |
| 5279 | return !stickyHideNav && type != TYPE_INPUT_METHOD && type != TYPE_STATUS_BAR |
| 5280 | && win.getActivityType() != ACTIVITY_TYPE_HOME; |
| 5281 | } |
| 5282 | |
| 5283 | /** |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5284 | * @return Whether gesture exclusion area should be logged for the given window |
| 5285 | */ |
| 5286 | static boolean logsGestureExclusionRestrictions(WindowState win) { |
| 5287 | if (win.mWmService.mSystemGestureExclusionLogDebounceTimeoutMillis <= 0) { |
| 5288 | return false; |
| 5289 | } |
| 5290 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 5291 | final int type = attrs.type; |
| 5292 | return type != TYPE_WALLPAPER |
| 5293 | && type != TYPE_APPLICATION_STARTING |
| 5294 | && type != TYPE_NAVIGATION_BAR |
| 5295 | && (attrs.flags & FLAG_NOT_TOUCHABLE) == 0 |
| 5296 | && needsGestureExclusionRestrictions(win, 0 /* sysUiVisibility */) |
| 5297 | && win.getDisplayContent().mDisplayPolicy.hasSideGestures(); |
| 5298 | } |
| 5299 | |
| 5300 | /** |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5301 | * Adds a local gesture exclusion area to the global area while applying a limit per edge. |
| 5302 | * |
| 5303 | * @param local The gesture exclusion area to add. |
| 5304 | * @param global The destination. |
| 5305 | * @param edge Only processes the part in that region. |
| 5306 | * @param limit How much limit in pixels we have. |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5307 | * @param win The WindowState that is being processed |
| 5308 | * @param side The side that is being processed, either {@link WindowState#EXCLUSION_LEFT} or |
| 5309 | * {@link WindowState#EXCLUSION_RIGHT} |
| 5310 | * @return How much of the limit is remaining. |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5311 | */ |
| 5312 | private static int addToGlobalAndConsumeLimit(Region local, Region global, Rect edge, |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5313 | int limit, WindowState win, int side) { |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5314 | final Region r = Region.obtain(local); |
| 5315 | r.op(edge, Op.INTERSECT); |
| 5316 | |
| 5317 | final int[] remaining = {limit}; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5318 | final int[] requestedExclusion = {0}; |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5319 | forEachRectReverse(r, rect -> { |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5320 | if (remaining[0] <= 0) { |
| 5321 | return; |
| 5322 | } |
| 5323 | final int height = rect.height(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5324 | requestedExclusion[0] += height; |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5325 | if (height > remaining[0]) { |
Adrian Roos | 2351d5f | 2019-07-03 15:35:07 +0200 | [diff] [blame] | 5326 | rect.top = rect.bottom - remaining[0]; |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5327 | } |
| 5328 | remaining[0] -= height; |
| 5329 | global.op(rect, Op.UNION); |
| 5330 | }); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5331 | |
| 5332 | final int grantedExclusion = limit - remaining[0]; |
| 5333 | win.setLastExclusionHeights(side, requestedExclusion[0], grantedExclusion); |
| 5334 | |
Adrian Roos | 506267d | 2019-06-18 16:13:53 +0200 | [diff] [blame] | 5335 | r.recycle(); |
| 5336 | return remaining[0]; |
| 5337 | } |
| 5338 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5339 | void registerSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5340 | mSystemGestureExclusionListeners.register(listener); |
| 5341 | final boolean changed; |
| 5342 | if (mSystemGestureExclusionListeners.getRegisteredCallbackCount() == 1) { |
| 5343 | changed = updateSystemGestureExclusion(); |
| 5344 | } else { |
| 5345 | changed = false; |
| 5346 | } |
| 5347 | |
| 5348 | if (!changed) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5349 | final Region unrestrictedOrNull = mSystemGestureExclusionWasRestricted |
| 5350 | ? mSystemGestureExclusionUnrestricted : null; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5351 | // If updateSystemGestureExclusion changed the exclusion, it will already have |
| 5352 | // notified the listener. Otherwise, we'll do it here. |
| 5353 | try { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 5354 | listener.onSystemGestureExclusionChanged(mDisplayId, mSystemGestureExclusion, |
| 5355 | unrestrictedOrNull); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 5356 | } catch (RemoteException e) { |
| 5357 | Slog.e(TAG, "Failed to notify SystemGestureExclusionListener during register", e); |
| 5358 | } |
| 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | void unregisterSystemGestureExclusionListener(ISystemGestureExclusionListener listener) { |
| 5363 | mSystemGestureExclusionListeners.unregister(listener); |
| 5364 | } |
| 5365 | |
| 5366 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5367 | * Create a portal window handle for input. This window transports any touch to the display |
| 5368 | * indicated by {@link InputWindowHandle#portalToDisplayId} if the touch hits this window. |
| 5369 | * |
| 5370 | * @param name The name of the portal window handle. |
| 5371 | * @return the new portal window handle. |
| 5372 | */ |
| 5373 | private InputWindowHandle createPortalWindowHandle(String name) { |
| 5374 | // Let surface flinger to set the display ID of this input window handle because we don't |
| 5375 | // know which display the parent surface control is on. |
| 5376 | final InputWindowHandle portalWindowHandle = new InputWindowHandle( |
| 5377 | null /* inputApplicationHandle */, null /* clientWindow */, INVALID_DISPLAY); |
| 5378 | portalWindowHandle.name = name; |
| 5379 | portalWindowHandle.token = new Binder(); |
| 5380 | portalWindowHandle.layoutParamsFlags = |
| 5381 | FLAG_SPLIT_TOUCH | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL; |
| 5382 | getBounds(mTmpBounds); |
| 5383 | portalWindowHandle.touchableRegion.set(mTmpBounds); |
| 5384 | portalWindowHandle.scaleFactor = 1f; |
| 5385 | portalWindowHandle.ownerPid = Process.myPid(); |
| 5386 | portalWindowHandle.ownerUid = Process.myUid(); |
| 5387 | portalWindowHandle.portalToDisplayId = mDisplayId; |
| 5388 | return portalWindowHandle; |
chaviw | ff2e7d8 | 2018-11-02 11:11:27 -0700 | [diff] [blame] | 5389 | } |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 5390 | |
| 5391 | /** |
| 5392 | * @see IWindowManager#setForwardedInsets |
| 5393 | */ |
| 5394 | public void setForwardedInsets(Insets insets) { |
| 5395 | if (insets == null) { |
| 5396 | insets = Insets.NONE; |
| 5397 | } |
| 5398 | if (mDisplayPolicy.getForwardedInsets().equals(insets)) { |
| 5399 | return; |
| 5400 | } |
| 5401 | mDisplayPolicy.setForwardedInsets(insets); |
| 5402 | setLayoutNeeded(); |
| 5403 | mWmService.mWindowPlacerLocked.requestTraversal(); |
| 5404 | } |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 5405 | |
| 5406 | protected MetricsLogger getMetricsLogger() { |
| 5407 | if (mMetricsLogger == null) { |
| 5408 | mMetricsLogger = new MetricsLogger(); |
| 5409 | } |
| 5410 | return mMetricsLogger; |
| 5411 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5412 | } |