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