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