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