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