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