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