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