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