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