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