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 | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | a77e146 | 2016-09-28 10:09:46 -0700 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 26 | import static android.view.Display.DEFAULT_DISPLAY; |
| 27 | import static android.view.Display.FLAG_PRIVATE; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 28 | import static android.view.Surface.ROTATION_0; |
| 29 | import static android.view.Surface.ROTATION_180; |
| 30 | import static android.view.Surface.ROTATION_270; |
| 31 | import static android.view.Surface.ROTATION_90; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 32 | import static android.view.View.GONE; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 34 | import static android.view.WindowManager.DOCKED_INVALID; |
| 35 | import static android.view.WindowManager.DOCKED_TOP; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 36 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 38 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 39 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 40 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE; |
| 42 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 43 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 44 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 45 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 46 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 47 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 48 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 49 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 50 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 51 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 52 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 53 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 54 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 55 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 56 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 57 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 58 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 59 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 60 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 61 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 62 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 63 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 64 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 65 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 66 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 67 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 68 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 69 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 70 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 71 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 72 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 73 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 74 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 75 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 76 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 77 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 78 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
| 79 | import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 80 | import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 81 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
| 82 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
| 83 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
| 84 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 85 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 86 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 87 | import static com.android.server.wm.WindowManagerService.logSurface; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 88 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 89 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 90 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 91 | import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 92 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 93 | import android.annotation.NonNull; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 94 | import android.app.ActivityManager.StackId; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 95 | import android.content.res.Configuration; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 96 | import android.graphics.Bitmap; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 97 | import android.graphics.Matrix; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 98 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 99 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 100 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 101 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 102 | import android.hardware.display.DisplayManagerInternal; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 103 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 104 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 105 | import android.os.IBinder; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 106 | import android.os.RemoteException; |
| 107 | import android.os.SystemClock; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 108 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 109 | import android.util.Slog; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 110 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 111 | import android.view.DisplayInfo; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 112 | import android.view.Surface; |
| 113 | import android.view.SurfaceControl; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 114 | import android.view.WindowManagerPolicy; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 115 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 116 | import com.android.internal.util.ToBooleanFunction; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 117 | import com.android.internal.view.IInputMethodClient; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 118 | |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 119 | import java.io.FileDescriptor; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 120 | import java.io.PrintWriter; |
| 121 | import java.util.ArrayList; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 122 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 123 | import java.util.HashMap; |
| 124 | import java.util.Iterator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 125 | import java.util.LinkedList; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 126 | import java.util.List; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 127 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 128 | /** |
| 129 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 130 | * particular Display. |
| 131 | * |
| 132 | * IMPORTANT: No method from this class should ever be used without holding |
| 133 | * WindowManagerService.mWindowMap. |
| 134 | */ |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 135 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 136 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 137 | |
| 138 | /** Unique identifier of this stack. */ |
| 139 | private final int mDisplayId; |
| 140 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 141 | /** The containers below are the only child containers the display can have. */ |
| 142 | // Contains all window containers that are related to apps (Activities) |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 143 | private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 144 | // Contains all non-app window containers that should be displayed above the app containers |
| 145 | // (e.g. Status bar) |
| 146 | private final NonAppWindowContainers mAboveAppWindowsContainers = |
| 147 | new NonAppWindowContainers("mAboveAppWindowsContainers"); |
| 148 | // Contains all non-app window containers that should be displayed below the app containers |
| 149 | // (e.g. Wallpaper). |
| 150 | private final NonAppWindowContainers mBelowAppWindowsContainers = |
| 151 | new NonAppWindowContainers("mBelowAppWindowsContainers"); |
| 152 | // Contains all IME window containers. Note that the z-ordering of the IME windows will depend |
| 153 | // on the IME target. We mainly have this container grouping so we can keep track of all the IME |
| 154 | // window containers together and move them in-sync if/when needed. |
| 155 | private final NonAppWindowContainers mImeWindowsContainers = |
| 156 | new NonAppWindowContainers("mImeWindowsContainers"); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 157 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 158 | private WindowState mTmpWindow; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 159 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 160 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 161 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 162 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 163 | int mInitialDisplayWidth = 0; |
| 164 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 165 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 166 | int mBaseDisplayWidth = 0; |
| 167 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 168 | int mBaseDisplayDensity = 0; |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 169 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 170 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 171 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 172 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 173 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 174 | Rect mBaseDisplayRect = new Rect(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 175 | private Rect mContentRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 176 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 177 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 178 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 179 | int pendingLayoutChanges; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 180 | // TODO(multi-display): remove some of the usages. |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 181 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 182 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 183 | /** 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] | 184 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 185 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 186 | /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack |
| 187 | * (except a future lockscreen TaskStack) moves to the top. */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 188 | private TaskStack mHomeStack = null; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 189 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 190 | /** Detect user tapping outside of current focused task bounds .*/ |
| 191 | TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 192 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 193 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 194 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 195 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 196 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 197 | private final Rect mTmpRect = new Rect(); |
| 198 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 199 | private final RectF mTmpRectF = new RectF(); |
| 200 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 201 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 202 | |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 203 | final WindowManagerService mService; |
| 204 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 205 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 206 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 207 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 208 | final DockedStackDividerController mDividerControllerLocked; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 209 | final PinnedStackController mPinnedStackControllerLocked; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 210 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 211 | final DimLayerController mDimLayerController; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 212 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 213 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
| 214 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 215 | private boolean mHaveBootMsg = false; |
| 216 | private boolean mHaveApp = false; |
| 217 | private boolean mHaveWallpaper = false; |
| 218 | private boolean mHaveKeyguard = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 219 | |
| 220 | private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList(); |
| 221 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 222 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 223 | new TaskForResizePointSearchResult(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 224 | private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState = |
| 225 | new ApplySurfaceChangesTransactionState(); |
| 226 | private final ScreenshotApplicationState mScreenshotApplicationState = |
| 227 | new ScreenshotApplicationState(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 228 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 229 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 230 | // the display's direct children should be allowed. |
| 231 | private boolean mRemovingDisplay = false; |
| 232 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 233 | private final WindowLayersController mLayersController; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 234 | final WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 235 | int mInputMethodAnimLayerAdjustment; |
| 236 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 237 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 238 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 239 | * @param service You know. |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 240 | * @param layersController window layer controller used to assign layer to the windows on this |
| 241 | * display. |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 242 | * @param wallpaperController wallpaper windows controller used to adjust the positioning of the |
| 243 | * wallpaper windows in the window list. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 244 | */ |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 245 | DisplayContent(Display display, WindowManagerService service, |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 246 | WindowLayersController layersController, WallpaperController wallpaperController) { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 247 | mDisplay = display; |
| 248 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 249 | mLayersController = layersController; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 250 | mWallpaperController = wallpaperController; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 251 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 252 | display.getMetrics(mDisplayMetrics); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 253 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 254 | mService = service; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 255 | initializeDisplayBaseInfo(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 256 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 257 | mPinnedStackControllerLocked = new PinnedStackController(service, this); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 258 | mDimLayerController = new DimLayerController(this); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 259 | |
| 260 | // 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] | 261 | super.addChild(mBelowAppWindowsContainers, null); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 262 | super.addChild(mTaskStackContainers, null); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 263 | super.addChild(mAboveAppWindowsContainers, null); |
| 264 | super.addChild(mImeWindowsContainers, null); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | int getDisplayId() { |
| 268 | return mDisplayId; |
| 269 | } |
| 270 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 271 | WindowToken getWindowToken(IBinder binder) { |
| 272 | return mTokenMap.get(binder); |
| 273 | } |
| 274 | |
| 275 | AppWindowToken getAppWindowToken(IBinder binder) { |
| 276 | final WindowToken token = getWindowToken(binder); |
| 277 | if (token == null) { |
| 278 | return null; |
| 279 | } |
| 280 | return token.asAppWindowToken(); |
| 281 | } |
| 282 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 283 | void addWindowToken(IBinder binder, WindowToken token) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 284 | final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token); |
| 285 | if (dc != null) { |
| 286 | // We currently don't support adding a window token to the display if the display |
| 287 | // already has the binder mapped to another token. If there is a use case for supporting |
| 288 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 289 | // the binder map to a list of window tokens. |
| 290 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this |
| 291 | + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
| 292 | } |
| 293 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 294 | |
| 295 | if (token.asAppWindowToken() == null) { |
| 296 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 297 | // the parent container managing them (e.g. Tasks). |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 298 | switch (token.windowType) { |
| 299 | case TYPE_WALLPAPER: |
| 300 | mBelowAppWindowsContainers.addChild(token); |
| 301 | break; |
| 302 | case TYPE_INPUT_METHOD: |
| 303 | case TYPE_INPUT_METHOD_DIALOG: |
| 304 | mImeWindowsContainers.addChild(token); |
| 305 | break; |
| 306 | default: |
| 307 | mAboveAppWindowsContainers.addChild(token); |
| 308 | break; |
| 309 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 310 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 314 | final WindowToken token = mTokenMap.remove(binder); |
| 315 | if (token != null && token.asAppWindowToken() == null) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 316 | token.setExiting(); |
| 317 | } |
| 318 | return token; |
| 319 | } |
| 320 | |
| 321 | /** Changes the display the input window token is housed on to this one. */ |
| 322 | void reParentWindowToken(WindowToken token) { |
| 323 | final DisplayContent prevDc = token.getDisplayContent(); |
| 324 | if (prevDc == this) { |
| 325 | return; |
| 326 | } |
| 327 | if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null) { |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 328 | switch (token.windowType) { |
| 329 | case TYPE_WALLPAPER: |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 330 | prevDc.mBelowAppWindowsContainers.removeChild(token); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 331 | break; |
| 332 | case TYPE_INPUT_METHOD: |
| 333 | case TYPE_INPUT_METHOD_DIALOG: |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 334 | prevDc.mImeWindowsContainers.removeChild(token); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 335 | break; |
| 336 | default: |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 337 | prevDc.mAboveAppWindowsContainers.removeChild(token); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 338 | break; |
| 339 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 340 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 341 | |
| 342 | addWindowToken(token.token, token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 345 | void removeAppToken(IBinder binder) { |
| 346 | final WindowToken token = removeWindowToken(binder); |
| 347 | if (token == null) { |
| 348 | Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder); |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | final AppWindowToken appToken = token.asAppWindowToken(); |
| 353 | |
| 354 | if (appToken == null) { |
| 355 | Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token); |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | appToken.onRemovedFromDisplay(); |
| 360 | } |
| 361 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 362 | Display getDisplay() { |
| 363 | return mDisplay; |
| 364 | } |
| 365 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 366 | DisplayInfo getDisplayInfo() { |
| 367 | return mDisplayInfo; |
| 368 | } |
| 369 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 370 | DisplayMetrics getDisplayMetrics() { |
| 371 | return mDisplayMetrics; |
| 372 | } |
| 373 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 374 | DockedStackDividerController getDockedDividerController() { |
| 375 | return mDividerControllerLocked; |
| 376 | } |
| 377 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 378 | PinnedStackController getPinnedStackController() { |
| 379 | return mPinnedStackControllerLocked; |
| 380 | } |
| 381 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 382 | /** |
| 383 | * Returns true if the specified UID has access to this display. |
| 384 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 385 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 386 | return mDisplay.hasAccess(uid); |
| 387 | } |
| 388 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 389 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 390 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 393 | TaskStack getHomeStack() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 394 | if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 395 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 396 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 397 | return mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 400 | TaskStack getStackById(int stackId) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 401 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 402 | final TaskStack stack = mTaskStackContainers.get(i); |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 403 | if (stack.mStackId == stackId) { |
| 404 | return stack; |
| 405 | } |
| 406 | } |
| 407 | return null; |
| 408 | } |
| 409 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 410 | @Override |
| 411 | void onConfigurationChanged(Configuration newParentConfig) { |
| 412 | super.onConfigurationChanged(newParentConfig); |
| 413 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 414 | // The display size information is heavily dependent on the resources in the current |
| 415 | // configuration, so we need to reconfigure it every time the configuration changes. |
| 416 | // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh... |
| 417 | mService.reconfigureDisplayLocked(this); |
| 418 | |
| 419 | getDockedDividerController().onConfigurationChanged(); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 420 | getPinnedStackController().onConfigurationChanged(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 421 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 422 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 423 | /** |
| 424 | * Callback used to trigger bounds update after configuration change and get ids of stacks whose |
| 425 | * bounds were updated. |
| 426 | */ |
| 427 | void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 428 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 429 | final TaskStack stack = mTaskStackContainers.get(i); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 430 | if (stack.updateBoundsAfterConfigChange()) { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 431 | changedStackList.add(stack.mStackId); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 436 | @Override |
| 437 | boolean fillsParent() { |
| 438 | return true; |
| 439 | } |
| 440 | |
| 441 | @Override |
| 442 | boolean isVisible() { |
| 443 | return true; |
| 444 | } |
| 445 | |
| 446 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 447 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 448 | super.onAppTransitionDone(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 449 | mService.mWindowsChanged = true; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 452 | @Override |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 453 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 454 | // Special handling so we can process IME windows with #forAllImeWindows above their IME |
| 455 | // target, or here in order if there isn't an IME target. |
| 456 | if (traverseTopToBottom) { |
| 457 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 458 | final DisplayChildWindowContainer child = mChildren.get(i); |
| 459 | if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) { |
| 460 | // In this case the Ime windows will be processed above their target so we skip |
| 461 | // here. |
| 462 | continue; |
| 463 | } |
| 464 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 465 | return true; |
| 466 | } |
| 467 | } |
| 468 | } else { |
| 469 | final int count = mChildren.size(); |
| 470 | for (int i = 0; i < count; i++) { |
| 471 | final DisplayChildWindowContainer child = mChildren.get(i); |
| 472 | if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) { |
| 473 | // In this case the Ime windows will be processed above their target so we skip |
| 474 | // here. |
| 475 | continue; |
| 476 | } |
| 477 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 478 | return true; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | return false; |
| 483 | } |
| 484 | |
| 485 | boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 486 | return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom); |
| 487 | } |
| 488 | |
| 489 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 490 | int getOrientation() { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 491 | final WindowManagerPolicy policy = mService.mPolicy; |
| 492 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 493 | if (mService.mDisplayFrozen) { |
| 494 | if (mService.mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 495 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 496 | "Display is frozen, return " + mService.mLastWindowForcedOrientation); |
| 497 | // If the display is frozen, some activities may be in the middle of restarting, and |
| 498 | // thus have removed their old window. If the window has the flag to hide the lock |
| 499 | // screen, then the lock screen can re-appear and inflict its own orientation on us. |
| 500 | // Keep the orientation stable until this all settles down. |
| 501 | return mService.mLastWindowForcedOrientation; |
| 502 | } else if (policy.isKeyguardLocked()) { |
| 503 | // Use the last orientation the while the display is frozen with the keyguard |
| 504 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 505 | // window. We don't want to check the show when locked window directly though as |
| 506 | // things aren't stable while the display is frozen, for example the window could be |
| 507 | // momentarily unavailable due to activity relaunch. |
| 508 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, " |
| 509 | + "return " + mService.mLastOrientation); |
| 510 | return mService.mLastOrientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 511 | } |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 512 | } else { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 513 | final int orientation = mAboveAppWindowsContainers.getOrientation(); |
| 514 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 515 | return orientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 516 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 519 | // Top system windows are not requesting an orientation. Start searching from apps. |
| 520 | return mTaskStackContainers.getOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 523 | void updateDisplayInfo() { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 524 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 525 | mDisplay.getMetrics(mDisplayMetrics); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 526 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 527 | mTaskStackContainers.get(i).updateDisplayInfo(null); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 528 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 531 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 532 | final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal; |
| 533 | if (displayManagerInternal != null) { |
| 534 | // Bootstrap the default logical display from the display manager. |
| 535 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 536 | if (newDisplayInfo != null) { |
| 537 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 538 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 539 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 540 | |
Filip Gruszczynski | 608797e | 2015-11-12 19:08:20 -0800 | [diff] [blame] | 541 | mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 542 | mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 543 | mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
| 544 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 547 | void getLogicalDisplayRect(Rect out) { |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 548 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 549 | final int orientation = mDisplayInfo.rotation; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 550 | boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 551 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 552 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 553 | int width = mDisplayInfo.logicalWidth; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 554 | int left = (physWidth - width) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 555 | int height = mDisplayInfo.logicalHeight; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 556 | int top = (physHeight - height) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 557 | out.set(left, top, left + width, top + height); |
| 558 | } |
| 559 | |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 560 | private void getLogicalDisplayRect(Rect out, int orientation) { |
| 561 | getLogicalDisplayRect(out); |
| 562 | |
| 563 | // Rotate the Rect if needed. |
| 564 | final int currentRotation = mDisplayInfo.rotation; |
| 565 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 566 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 567 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 568 | mTmpRectF.set(out); |
| 569 | mTmpMatrix.mapRect(mTmpRectF); |
| 570 | mTmpRectF.round(out); |
| 571 | } |
| 572 | } |
| 573 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 574 | void getContentRect(Rect out) { |
| 575 | out.set(mContentRect); |
| 576 | } |
| 577 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 578 | /** |
| 579 | * Adds the stack to this display. |
| 580 | * @see WindowManagerService#addStackToDisplay(int, int, boolean) |
| 581 | */ |
| 582 | Rect addStackToDisplay(int stackId, boolean onTop) { |
| 583 | boolean attachedToDisplay = false; |
| 584 | TaskStack stack = mService.mStackIdToStack.get(stackId); |
| 585 | if (stack == null) { |
| 586 | if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId=" |
| 587 | + mDisplayId); |
| 588 | |
| 589 | stack = getStackById(stackId); |
| 590 | if (stack != null) { |
| 591 | // It's already attached to the display...clear mDeferRemoval and move stack to |
| 592 | // appropriate z-order on display as needed. |
| 593 | stack.mDeferRemoval = false; |
| 594 | moveStack(stack, onTop); |
| 595 | attachedToDisplay = true; |
| 596 | } else { |
| 597 | stack = new TaskStack(mService, stackId); |
| 598 | } |
| 599 | |
| 600 | mService.mStackIdToStack.put(stackId, stack); |
| 601 | if (stackId == DOCKED_STACK_ID) { |
| 602 | mDividerControllerLocked.notifyDockedStackExistsChanged(true); |
| 603 | } |
| 604 | } else { |
| 605 | final DisplayContent currentDC = stack.getDisplayContent(); |
| 606 | if (currentDC != null) { |
| 607 | throw new IllegalStateException("Trying to add stackId=" + stackId |
| 608 | + "to displayId=" + mDisplayId + ", but it's already attached to displayId=" |
| 609 | + currentDC.getDisplayId()); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | if (!attachedToDisplay) { |
| 614 | mTaskStackContainers.addStackToDisplay(stack, onTop); |
| 615 | } |
| 616 | |
| 617 | if (stack.getRawFullscreen()) { |
| 618 | return null; |
| 619 | } |
| 620 | final Rect bounds = new Rect(); |
| 621 | stack.getRawBounds(bounds); |
| 622 | return bounds; |
| 623 | } |
| 624 | |
| 625 | /** Removes the stack from the display and prepares for changing the parent. */ |
| 626 | private void removeStackFromDisplay(TaskStack stack) { |
| 627 | mTaskStackContainers.removeStackFromDisplay(stack); |
| 628 | } |
| 629 | |
| 630 | /** Moves the stack to this display and returns the updated bounds. */ |
| 631 | Rect moveStackToDisplay(TaskStack stack) { |
| 632 | final DisplayContent currentDisplayContent = stack.getDisplayContent(); |
| 633 | if (currentDisplayContent == null) { |
| 634 | throw new IllegalStateException("Trying to move stackId=" + stack.mStackId |
| 635 | + " which is not currently attached to any display"); |
| 636 | } |
| 637 | if (stack.getDisplayContent().getDisplayId() == mDisplayId) { |
| 638 | throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId |
| 639 | + " to its current displayId=" + mDisplayId); |
| 640 | } |
| 641 | |
| 642 | currentDisplayContent.removeStackFromDisplay(stack); |
| 643 | return addStackToDisplay(stack.mStackId, true /* onTop */); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 646 | void moveStack(TaskStack stack, boolean toTop) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 647 | mTaskStackContainers.moveStack(stack, toTop); |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 648 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 649 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 650 | @Override |
| 651 | protected void addChild(DisplayChildWindowContainer child, |
| 652 | Comparator<DisplayChildWindowContainer> comparator) { |
| 653 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 654 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 655 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 656 | @Override |
| 657 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 658 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 659 | } |
| 660 | |
| 661 | @Override |
| 662 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 663 | // Only allow removal of direct children from this display if the display is in the process |
| 664 | // of been removed. |
| 665 | if (mRemovingDisplay) { |
| 666 | super.removeChild(child); |
| 667 | return; |
| 668 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 669 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 672 | int taskIdFromPoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 673 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 674 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 675 | final int taskId = stack.taskIdFromPoint(x, y); |
| 676 | if (taskId != -1) { |
| 677 | return taskId; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 680 | return -1; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 683 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 684 | * 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] | 685 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 686 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 687 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 688 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 689 | mTmpTaskForResizePointSearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 690 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 691 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 692 | if (!StackId.isTaskResizeAllowed(stack.mStackId)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 693 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 694 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 695 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 696 | stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult); |
| 697 | if (mTmpTaskForResizePointSearchResult.searchDone) { |
| 698 | return mTmpTaskForResizePointSearchResult.taskForResize; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 699 | } |
| 700 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 701 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 704 | void setTouchExcludeRegion(Task focusedTask) { |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 705 | mTouchExcludeRegion.set(mBaseDisplayRect); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 706 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 707 | mTmpRect2.setEmpty(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 708 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 709 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 710 | stack.setTouchExcludeRegion( |
| 711 | focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 712 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 713 | // If we removed the focused task above, add it back and only leave its |
| 714 | // outside touch area in the exclusion. TapDectector is not interested in |
| 715 | // any touch inside the focused task itself. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 716 | if (!mTmpRect2.isEmpty()) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 717 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 718 | } |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 719 | final WindowState inputMethod = mService.mInputMethodWindow; |
| 720 | if (inputMethod != null && inputMethod.isVisibleLw()) { |
| 721 | // If the input method is visible and the user is typing, we don't want these touch |
| 722 | // events to be intercepted and used to change focus. This would likely cause a |
| 723 | // disappearance of the input method. |
| 724 | inputMethod.getTouchableRegion(mTmpRegion); |
| 725 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 726 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 727 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
| 728 | WindowState win = mTapExcludedWindows.get(i); |
| 729 | win.getTouchableRegion(mTmpRegion); |
| 730 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 731 | } |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 732 | // TODO(multi-display): Support docked stacks on secondary displays. |
| 733 | if (mDisplayId == DEFAULT_DISPLAY && getDockedStackLocked() != null) { |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 734 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 735 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 736 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 737 | } |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 738 | if (mTapDetector != null) { |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 739 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 740 | } |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 743 | @Override |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 744 | void switchUser() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 745 | super.switchUser(); |
| 746 | mService.mWindowsChanged = true; |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 749 | private void resetAnimationBackgroundAnimator() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 750 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 751 | mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
| 755 | boolean animateDimLayers() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 756 | return mDimLayerController.animateDimLayers(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 759 | private void resetDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 760 | mDimLayerController.resetDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | boolean isDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 764 | return mDimLayerController.isDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 767 | private void stopDimmingIfNeeded() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 768 | mDimLayerController.stopDimmingIfNeeded(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 771 | @Override |
| 772 | void removeIfPossible() { |
| 773 | if (isAnimating()) { |
| 774 | mDeferredRemoval = true; |
| 775 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 776 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 777 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 780 | @Override |
| 781 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 782 | mRemovingDisplay = true; |
| 783 | try { |
| 784 | super.removeImmediately(); |
| 785 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
| 786 | mDimLayerController.close(); |
| 787 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 788 | mService.unregisterPointerEventListener(mTapDetector); |
| 789 | mService.unregisterPointerEventListener(mService.mMousePositionTracker); |
| 790 | } |
| 791 | } finally { |
| 792 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 793 | } |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 796 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 797 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 798 | boolean checkCompleteDeferredRemoval() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 799 | final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval(); |
| 800 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 801 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 802 | removeImmediately(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 803 | mService.onDisplayRemoved(mDisplayId); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 804 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 805 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 806 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 809 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 810 | float dividerAnimationTarget) { |
| 811 | boolean updated = false; |
| 812 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 813 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 814 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 815 | if (stack == null || !stack.isAdjustedForIme()) { |
| 816 | continue; |
| 817 | } |
| 818 | |
| 819 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 820 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 821 | updated = true; |
| 822 | } else { |
| 823 | mDividerControllerLocked.mLastAnimationProgress = |
| 824 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 825 | mDividerControllerLocked.mLastDividerProgress = |
| 826 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 827 | updated |= stack.updateAdjustForIme( |
| 828 | mDividerControllerLocked.mLastAnimationProgress, |
| 829 | mDividerControllerLocked.mLastDividerProgress, |
| 830 | false /* force */); |
| 831 | } |
| 832 | if (interpolatedValue >= 1f) { |
| 833 | stack.endImeAdjustAnimation(); |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | return updated; |
| 838 | } |
| 839 | |
| 840 | boolean clearImeAdjustAnimation() { |
| 841 | boolean changed = false; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 842 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 843 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 844 | if (stack != null && stack.isAdjustedForIme()) { |
| 845 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 846 | changed = true; |
| 847 | } |
| 848 | } |
| 849 | return changed; |
| 850 | } |
| 851 | |
| 852 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 853 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 854 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 855 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 856 | stack.beginImeAdjustAnimation(); |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | void adjustForImeIfNeeded() { |
| 862 | final WindowState imeWin = mService.mInputMethodWindow; |
| 863 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 864 | && !mDividerControllerLocked.isImeHideRequested(); |
| 865 | final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID); |
| 866 | final TaskStack imeTargetStack = mService.getImeFocusStackLocked(); |
| 867 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 868 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 869 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 870 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
| 871 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock(); |
| 872 | final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw(); |
| 873 | final boolean imeHeightChanged = imeVisible && |
| 874 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 875 | |
| 876 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 877 | // or both. There are three possible cases: |
| 878 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 879 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 880 | // - If IME is not visible, divider is not moved and is normal width. |
| 881 | |
| 882 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 883 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 884 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 885 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
| 886 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) { |
| 887 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 888 | } else { |
| 889 | stack.resetAdjustedForIme(false); |
| 890 | } |
| 891 | } |
| 892 | mDividerControllerLocked.setAdjustedForIme( |
| 893 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 894 | } else { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 895 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 896 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 897 | stack.resetAdjustedForIme(!dockVisible); |
| 898 | } |
| 899 | mDividerControllerLocked.setAdjustedForIme( |
| 900 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 901 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 902 | mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 905 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 906 | if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj); |
| 907 | mInputMethodAnimLayerAdjustment = adj; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 908 | mImeWindowsContainers.forAllWindows(w -> { |
| 909 | w.adjustAnimLayer(adj); |
| 910 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 913 | /** |
| 914 | * If a window that has an animation specifying a colored background and the current wallpaper |
| 915 | * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to |
| 916 | * suddenly disappear. |
| 917 | */ |
| 918 | int getLayerForAnimationBackground(WindowStateAnimator winAnimator) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 919 | final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow( |
| 920 | w -> w.mIsWallpaper && w.isVisibleNow()); |
| 921 | |
| 922 | if (visibleWallpaper != null) { |
| 923 | return visibleWallpaper.mWinAnimator.mAnimLayer; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 924 | } |
| 925 | return winAnimator.mAnimLayer; |
| 926 | } |
| 927 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 928 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 929 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 930 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 931 | stack.prepareFreezingTaskBounds(); |
| 932 | } |
| 933 | } |
| 934 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 935 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 936 | getLogicalDisplayRect(mTmpRect, newRotation); |
| 937 | |
| 938 | // Compute a transform matrix to undo the coordinate space transformation, |
| 939 | // and present the window at the same physical position it previously occupied. |
| 940 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
| 941 | createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix); |
| 942 | |
| 943 | mTmpRectF.set(bounds); |
| 944 | mTmpMatrix.mapRect(mTmpRectF); |
| 945 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 948 | static int deltaRotation(int oldRotation, int newRotation) { |
| 949 | int delta = newRotation - oldRotation; |
| 950 | if (delta < 0) delta += 4; |
| 951 | return delta; |
| 952 | } |
| 953 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 954 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 955 | Matrix outMatrix) { |
| 956 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 957 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 958 | displayHeight, outMatrix); |
| 959 | } |
| 960 | |
| 961 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 962 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 963 | switch (rotation) { |
| 964 | case ROTATION_0: |
| 965 | outMatrix.reset(); |
| 966 | break; |
| 967 | case ROTATION_270: |
| 968 | outMatrix.setRotate(270, 0, 0); |
| 969 | outMatrix.postTranslate(0, displayHeight); |
| 970 | outMatrix.postTranslate(rectTop, 0); |
| 971 | break; |
| 972 | case ROTATION_180: |
| 973 | outMatrix.reset(); |
| 974 | break; |
| 975 | case ROTATION_90: |
| 976 | outMatrix.setRotate(90, 0, 0); |
| 977 | outMatrix.postTranslate(displayWidth, 0); |
| 978 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 979 | break; |
| 980 | } |
| 981 | } |
| 982 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 983 | public void dump(String prefix, PrintWriter pw) { |
| 984 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 985 | final String subPrefix = " " + prefix; |
| 986 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 987 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 988 | pw.print("dpi"); |
| 989 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 990 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 991 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 992 | pw.print(" base="); |
| 993 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 994 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 995 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 996 | if (mDisplayScalingDisabled) { |
| 997 | pw.println(" noscale"); |
| 998 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 999 | pw.print(" cur="); |
| 1000 | pw.print(mDisplayInfo.logicalWidth); |
| 1001 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 1002 | pw.print(" app="); |
| 1003 | pw.print(mDisplayInfo.appWidth); |
| 1004 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 1005 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 1006 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 1007 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 1008 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1009 | pw.println(subPrefix + "deferred=" + mDeferredRemoval |
| 1010 | + " mLayoutNeeded=" + mLayoutNeeded); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1011 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1012 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 1013 | pw.println(prefix + "Application tokens in top down Z order:"); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1014 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1015 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1016 | stack.dump(prefix + " ", pw); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1017 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1018 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1019 | pw.println(); |
| 1020 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1021 | pw.println(); |
| 1022 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1023 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1024 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1025 | pw.print(" Exiting #"); pw.print(i); |
| 1026 | pw.print(' '); pw.print(token); |
| 1027 | pw.println(':'); |
| 1028 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 1029 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1030 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1031 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 1032 | mDimLayerController.dump(prefix, pw); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 1033 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 1034 | mDividerControllerLocked.dump(prefix, pw); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1035 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 1036 | mPinnedStackControllerLocked.dump(prefix, pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (mInputMethodAnimLayerAdjustment != 0) { |
| 1039 | pw.println(subPrefix |
| 1040 | + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment); |
| 1041 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1042 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1043 | |
| 1044 | @Override |
| 1045 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1046 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1050 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1051 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 1052 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1053 | /** |
| 1054 | * @return The docked stack, but only if it is visible, and {@code null} otherwise. |
| 1055 | */ |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 1056 | TaskStack getDockedStackLocked() { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 1057 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1058 | return (stack != null && stack.isVisible()) ? stack : null; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 1059 | } |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1060 | |
| 1061 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1062 | * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1063 | * visible. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1064 | */ |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1065 | TaskStack getDockedStackIgnoringVisibility() { |
| 1066 | return mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1069 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1070 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1071 | final int x = (int) xf; |
| 1072 | final int y = (int) yf; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1073 | final WindowState touchedWin = getWindow(w -> { |
| 1074 | final int flags = w.mAttrs.flags; |
| 1075 | if (!w.isVisibleLw()) { |
| 1076 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1077 | } |
| 1078 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1079 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1082 | w.getVisibleBounds(mTmpRect); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1083 | if (!mTmpRect.contains(x, y)) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1084 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1087 | w.getTouchableRegion(mTmpRegion); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1088 | |
| 1089 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1090 | return mTmpRegion.contains(x, y) || touchFlags == 0; |
| 1091 | }); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 1092 | |
| 1093 | return touchedWin; |
| 1094 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 1095 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1096 | boolean canAddToastWindowForUid(int uid) { |
| 1097 | // We allow one toast window per UID being shown at a time. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1098 | final WindowState win = getWindow(w -> |
| 1099 | w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden |
| 1100 | && !w.mWindowRemovalAllowed); |
| 1101 | return win == null; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1104 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1105 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 1106 | return; |
| 1107 | } |
| 1108 | final int lostFocusUid = oldFocus.mOwnerUid; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1109 | final Handler handler = mService.mH; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1110 | |
| 1111 | forAllWindows(w -> { |
| 1112 | if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) { |
| 1113 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) { |
| 1114 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), |
| 1115 | w.mAttrs.hideTimeoutMilliseconds); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1116 | } |
| 1117 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1118 | }, false /* traverseTopToBottom */); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1119 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1120 | |
| 1121 | WindowState findFocusedWindow() { |
| 1122 | final AppWindowToken focusedApp = mService.mFocusedApp; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1123 | mTmpWindow = null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1124 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1125 | forAllWindows(w -> { |
| 1126 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w |
| 1127 | + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys()); |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1128 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1129 | if (!w.canReceiveKeys()) { |
| 1130 | return false; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1133 | final AppWindowToken wtoken = w.mAppToken; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1134 | |
| 1135 | // If this window's application has been removed, just skip it. |
| 1136 | if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) { |
| 1137 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because " |
| 1138 | + (wtoken.removed ? "removed" : "sendingToBottom")); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1139 | return false; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | if (focusedApp == null) { |
| 1143 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null" |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1144 | + " using new focus @ " + w); |
| 1145 | mTmpWindow = w; |
| 1146 | return true; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | if (!focusedApp.windowsAreFocusable()) { |
| 1150 | // Current focused app windows aren't focusable... |
| 1151 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not" |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1152 | + " focusable using new focus @ " + w); |
| 1153 | mTmpWindow = w; |
| 1154 | return true; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | // Descend through all of the app tokens and find the first that either matches |
| 1158 | // win.mAppToken (return win) or mFocusedApp (return null). |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1159 | if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1160 | if (focusedApp.compareTo(wtoken) > 0) { |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1161 | // App stack below focused app stack. No focus for you!!! |
| 1162 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, |
| 1163 | "findFocusedWindow: Reached focused app=" + focusedApp); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1164 | mTmpWindow = null; |
| 1165 | return true; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1169 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w); |
| 1170 | mTmpWindow = w; |
| 1171 | return true; |
| 1172 | }, true /* traverseTopToBottom */); |
| 1173 | |
| 1174 | if (mTmpWindow == null) { |
| 1175 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows."); |
| 1176 | return null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1177 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1178 | return mTmpWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 1181 | /** Updates the layer assignment of windows on this display. */ |
| 1182 | void assignWindowLayers(boolean setLayoutNeeded) { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 1183 | mLayersController.assignWindowLayers(this); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 1184 | if (setLayoutNeeded) { |
| 1185 | setLayoutNeeded(); |
| 1186 | } |
| 1187 | } |
| 1188 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1189 | void layoutAndAssignWindowLayersIfNeeded() { |
| 1190 | mService.mWindowsChanged = true; |
| 1191 | setLayoutNeeded(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1192 | |
| 1193 | if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 1194 | false /*updateInputWindows*/)) { |
| 1195 | assignWindowLayers(false /* setLayoutNeeded */); |
| 1196 | } |
| 1197 | |
| 1198 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 1199 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 1200 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 1201 | } |
| 1202 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1203 | /** Returns true if a leaked surface was destroyed */ |
| 1204 | boolean destroyLeakedSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1205 | // Used to indicate that a surface was leaked. |
| 1206 | mTmpWindow = null; |
| 1207 | forAllWindows(w -> { |
| 1208 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1209 | if (wsa.mSurfaceController == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1210 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1211 | } |
| 1212 | if (!mService.mSessions.contains(wsa.mSession)) { |
| 1213 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1214 | + w + " surface=" + wsa.mSurfaceController |
| 1215 | + " token=" + w.mToken |
| 1216 | + " pid=" + w.mSession.mPid |
| 1217 | + " uid=" + w.mSession.mUid); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1218 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1219 | mService.mForceRemoves.add(w); |
| 1220 | mTmpWindow = w; |
| 1221 | } else if (w.mAppToken != null && w.mAppToken.clientHidden) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1222 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1223 | + w + " surface=" + wsa.mSurfaceController |
| 1224 | + " token=" + w.mAppToken |
| 1225 | + " saved=" + w.hasSavedSurface()); |
| 1226 | if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1227 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1228 | mTmpWindow = w; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1229 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1230 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1231 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1232 | return mTmpWindow != null; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /** |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1236 | * Determine and return the window that should be the IME target. |
| 1237 | * @param updateImeTarget If true the system IME target will be updated to match what we found. |
| 1238 | * @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] | 1239 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1240 | WindowState computeImeTarget(boolean updateImeTarget) { |
| 1241 | if (mService.mInputMethodWindow == null) { |
| 1242 | // There isn't an IME so there shouldn't be a target...That was easy! |
| 1243 | if (updateImeTarget) { |
| 1244 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " |
| 1245 | + mService.mInputMethodTarget + " to null since mInputMethodWindow is null"); |
| 1246 | setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0); |
| 1247 | } |
| 1248 | return null; |
| 1249 | } |
| 1250 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1251 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 1252 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 1253 | // IME/target. For now only look for input windows on the main screen. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1254 | WindowState target = getWindow(w -> { |
| 1255 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.i(TAG_WM, "Checking window @" |
| 1256 | + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| 1257 | return w.canBeImeTarget(); |
| 1258 | }); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1259 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1260 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1261 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 1262 | // to be on top of it, but it is not -really- where input will go. So look down below |
| 1263 | // for a real window to target... |
| 1264 | if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 1265 | final AppWindowToken token = target.mAppToken; |
| 1266 | if (token != null) { |
| 1267 | final WindowState betterTarget = token.getImeTargetBelowWindow(target); |
| 1268 | if (betterTarget != null) { |
| 1269 | target = betterTarget; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1270 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1274 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM, |
| 1275 | "Proposed new IME target: " + target); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1276 | |
| 1277 | // Now, a special case -- if the last target's window is in the process of exiting, and is |
| 1278 | // above the new target, keep on the last target to avoid flicker. Consider for example a |
| 1279 | // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it |
| 1280 | // until it is completely gone so it doesn't drop behind the dialog or its full-screen |
| 1281 | // scrim. |
| 1282 | final WindowState curTarget = mService.mInputMethodTarget; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1283 | if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing() |
| 1284 | && (target == null |
| 1285 | || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1286 | 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^] | 1287 | return curTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1290 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target |
| 1291 | + " updateImeTarget=" + updateImeTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1292 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1293 | if (target == null) { |
| 1294 | if (updateImeTarget) { |
| 1295 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 1296 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" |
| 1297 | + Debug.getCallers(4) : "")); |
| 1298 | setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0); |
| 1299 | } |
| 1300 | |
| 1301 | return null; |
| 1302 | } |
| 1303 | |
| 1304 | if (updateImeTarget) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1305 | AppWindowToken token = curTarget == null ? null : curTarget.mAppToken; |
| 1306 | if (token != null) { |
| 1307 | |
| 1308 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 1309 | // to look at all windows below the current target that are in this app, finding the |
| 1310 | // highest visible one in layering. |
| 1311 | WindowState highestTarget = null; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1312 | if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1313 | highestTarget = token.getHighestAnimLayerWindow(curTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | if (highestTarget != null) { |
| 1317 | final AppTransition appTransition = mService.mAppTransition; |
| 1318 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget |
| 1319 | + " animating=" + highestTarget.mWinAnimator.isAnimationSet() |
| 1320 | + " layer=" + highestTarget.mWinAnimator.mAnimLayer |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1321 | + " new layer=" + target.mWinAnimator.mAnimLayer); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1322 | |
| 1323 | if (appTransition.isTransitionSet()) { |
| 1324 | // If we are currently setting up for an animation, hold everything until we |
| 1325 | // can find out what will happen. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1326 | setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment); |
| 1327 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1328 | } else if (highestTarget.mWinAnimator.isAnimationSet() && |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1329 | highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1330 | // If the window we are currently targeting is involved with an animation, |
| 1331 | // and it is on top of the next target we will be over, then hold off on |
| 1332 | // moving until that is done. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1333 | setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment); |
| 1334 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1338 | |
| 1339 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 1340 | + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
| 1341 | setInputMethodTarget(target, false, target.mAppToken != null |
| 1342 | ? target.mAppToken.mAppAnimator.animLayerAdjustment : 0); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1345 | return target; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1348 | private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim, int layerAdj) { |
| 1349 | if (target == mService.mInputMethodTarget |
| 1350 | && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim |
| 1351 | && mInputMethodAnimLayerAdjustment == layerAdj) { |
| 1352 | return; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1355 | mService.mInputMethodTarget = target; |
| 1356 | mService.mInputMethodTargetWaitingAnim = targetWaitingAnim; |
| 1357 | setInputMethodAnimLayerAdjustment(layerAdj); |
| 1358 | assignWindowLayers(false /* setLayoutNeeded */); |
| 1359 | } |
| 1360 | |
| 1361 | boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) { |
| 1362 | if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 1363 | return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
| 1364 | } |
| 1365 | |
| 1366 | // Used to indicate we have reached the first window in the range we are interested in. |
| 1367 | mTmpWindow = null; |
| 1368 | |
| 1369 | // TODO: Figure-out a more efficient way to do this. |
| 1370 | final WindowState candidate = getWindow(w -> { |
| 1371 | if (w == top) { |
| 1372 | // Reached the first window in the range we are interested in. |
| 1373 | mTmpWindow = w; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1374 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1375 | if (mTmpWindow == null) { |
| 1376 | return false; |
| 1377 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1378 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1379 | if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 1380 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1381 | } |
| 1382 | // If we reached the bottom of the range of windows we are considering, |
| 1383 | // assume no menu is needed. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1384 | if (w == bottom) { |
| 1385 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1386 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1387 | return false; |
| 1388 | }); |
| 1389 | |
| 1390 | return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1393 | void setLayoutNeeded() { |
| 1394 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 1395 | mLayoutNeeded = true; |
| 1396 | } |
| 1397 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1398 | private void clearLayoutNeeded() { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1399 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 1400 | mLayoutNeeded = false; |
| 1401 | } |
| 1402 | |
| 1403 | boolean isLayoutNeeded() { |
| 1404 | return mLayoutNeeded; |
| 1405 | } |
| 1406 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1407 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 1408 | if (mTokenMap.isEmpty()) { |
| 1409 | return; |
| 1410 | } |
| 1411 | pw.println(" Display #" + mDisplayId); |
| 1412 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 1413 | while (it.hasNext()) { |
| 1414 | final WindowToken token = it.next(); |
| 1415 | pw.print(" "); |
| 1416 | pw.print(token); |
| 1417 | if (dumpAll) { |
| 1418 | pw.println(':'); |
| 1419 | token.dump(pw, " "); |
| 1420 | } else { |
| 1421 | pw.println(); |
| 1422 | } |
| 1423 | } |
| 1424 | } |
| 1425 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1426 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1427 | final int[] index = new int[1]; |
| 1428 | forAllWindows(w -> { |
| 1429 | final WindowStateAnimator wAnim = w.mWinAnimator; |
| 1430 | pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim); |
| 1431 | index[0] = index[0] + 1; |
| 1432 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1435 | void enableSurfaceTrace(FileDescriptor fd) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1436 | forAllWindows(w -> { |
| 1437 | w.mWinAnimator.enableSurfaceTrace(fd); |
| 1438 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | void disableSurfaceTrace() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1442 | forAllWindows(w -> { |
| 1443 | w.mWinAnimator.disableSurfaceTrace(); |
| 1444 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1447 | /** |
| 1448 | * Starts the Keyguard exit animation on all windows that don't belong to an app token. |
| 1449 | */ |
| 1450 | void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) { |
| 1451 | final WindowManagerPolicy policy = mService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1452 | forAllWindows(w -> { |
| 1453 | if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)) { |
| 1454 | w.mWinAnimator.setAnimation( |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1455 | policy.createHiddenByKeyguardExit(onWallpaper, goingToShade)); |
| 1456 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1457 | }, true /* traverseTopToBottom */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1458 | } |
| 1459 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1460 | boolean checkWaitingForWindows() { |
| 1461 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1462 | mHaveBootMsg = false; |
| 1463 | mHaveApp = false; |
| 1464 | mHaveWallpaper = false; |
| 1465 | mHaveKeyguard = true; |
| 1466 | |
| 1467 | final WindowState visibleWindow = getWindow(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1468 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| 1469 | return true; |
| 1470 | } |
| 1471 | if (w.isDrawnLw()) { |
| 1472 | if (w.mAttrs.type == TYPE_BOOT_PROGRESS) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1473 | mHaveBootMsg = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1474 | } else if (w.mAttrs.type == TYPE_APPLICATION |
| 1475 | || w.mAttrs.type == TYPE_DRAWN_APPLICATION) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1476 | mHaveApp = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1477 | } else if (w.mAttrs.type == TYPE_WALLPAPER) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1478 | mHaveWallpaper = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1479 | } else if (w.mAttrs.type == TYPE_STATUS_BAR) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1480 | mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1481 | } |
| 1482 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1483 | return false; |
| 1484 | }); |
| 1485 | |
| 1486 | if (visibleWindow != null) { |
| 1487 | // We have a visible window. |
| 1488 | return true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1491 | // if the wallpaper service is disabled on the device, we're never going to have |
| 1492 | // wallpaper, don't bother waiting for it |
| 1493 | boolean wallpaperEnabled = mService.mContext.getResources().getBoolean( |
| 1494 | com.android.internal.R.bool.config_enableWallpaperService) |
| 1495 | && !mService.mOnlyCore; |
| 1496 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1497 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM, |
| 1498 | "******** booted=" + mService.mSystemBooted |
| 1499 | + " msg=" + mService.mShowingBootMessages |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1500 | + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp |
| 1501 | + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled |
| 1502 | + " haveKeyguard=" + mHaveKeyguard); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1503 | |
| 1504 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 1505 | // message is actually displayed. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1506 | if (!mService.mSystemBooted && !mHaveBootMsg) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1507 | return true; |
| 1508 | } |
| 1509 | |
| 1510 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 1511 | // we have the application and wallpaper. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1512 | if (mService.mSystemBooted |
| 1513 | && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1514 | return true; |
| 1515 | } |
| 1516 | |
| 1517 | return false; |
| 1518 | } |
| 1519 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1520 | void updateWindowsForAnimator(WindowAnimator animator) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1521 | forAllWindows(w -> { |
| 1522 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1523 | if (winAnimator.hasSurface()) { |
| 1524 | final boolean wasAnimating = winAnimator.mWasAnimating; |
| 1525 | final boolean nowAnimating = winAnimator.stepAnimationLocked(animator.mCurrentTime); |
| 1526 | winAnimator.mWasAnimating = nowAnimating; |
| 1527 | animator.orAnimating(nowAnimating); |
| 1528 | |
| 1529 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1530 | w + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1531 | |
| 1532 | if (wasAnimating && !winAnimator.mAnimating |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1533 | && mWallpaperController.isWallpaperTarget(w)) { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1534 | animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; |
| 1535 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 1536 | if (DEBUG_LAYOUT_REPEATS) { |
| 1537 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 1538 | "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges); |
| 1539 | } |
| 1540 | } |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1543 | final AppWindowToken atoken = w.mAppToken; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1544 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
| 1545 | if (atoken == null || atoken.allDrawn) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1546 | if (w.performShowLocked()) { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1547 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 1548 | if (DEBUG_LAYOUT_REPEATS) { |
| 1549 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 1550 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; |
| 1556 | if (appAnimator != null && appAnimator.thumbnail != null) { |
| 1557 | if (appAnimator.thumbnailTransactionSeq != animator.mAnimTransactionSequence) { |
| 1558 | appAnimator.thumbnailTransactionSeq = animator.mAnimTransactionSequence; |
| 1559 | appAnimator.thumbnailLayer = 0; |
| 1560 | } |
| 1561 | if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) { |
| 1562 | appAnimator.thumbnailLayer = winAnimator.mAnimLayer; |
| 1563 | } |
| 1564 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1565 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | void updateWallpaperForAnimator(WindowAnimator animator) { |
Jorim Jaggi | 7156b65 | 2016-10-25 08:31:58 -0700 | [diff] [blame] | 1569 | resetAnimationBackgroundAnimator(); |
| 1570 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1571 | // Used to indicate a detached wallpaper. |
| 1572 | mTmpWindow = null; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1573 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1574 | forAllWindows(w -> { |
| 1575 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1576 | if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1577 | return; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1580 | final int flags = w.mAttrs.flags; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1581 | |
| 1582 | // If this window is animating, make a note that we have an animating window and take |
| 1583 | // care of a request to run a detached wallpaper animation. |
| 1584 | if (winAnimator.mAnimating) { |
| 1585 | if (winAnimator.mAnimation != null) { |
| 1586 | if ((flags & FLAG_SHOW_WALLPAPER) != 0 |
| 1587 | && winAnimator.mAnimation.getDetachWallpaper()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1588 | mTmpWindow = w; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1589 | } |
| 1590 | final int color = winAnimator.mAnimation.getBackgroundColor(); |
| 1591 | if (color != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1592 | final TaskStack stack = w.getStack(); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1593 | if (stack != null) { |
| 1594 | stack.setAnimationBackground(winAnimator, color); |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | animator.setAnimating(true); |
| 1599 | } |
| 1600 | |
| 1601 | // If this window's app token is running a detached wallpaper animation, make a note so |
| 1602 | // we can ensure the wallpaper is displayed behind it. |
| 1603 | final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; |
| 1604 | if (appAnimator != null && appAnimator.animation != null |
| 1605 | && appAnimator.animating) { |
| 1606 | if ((flags & FLAG_SHOW_WALLPAPER) != 0 |
| 1607 | && appAnimator.animation.getDetachWallpaper()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1608 | mTmpWindow = w; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | final int color = appAnimator.animation.getBackgroundColor(); |
| 1612 | if (color != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1613 | final TaskStack stack = w.getStack(); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1614 | if (stack != null) { |
| 1615 | stack.setAnimationBackground(winAnimator, color); |
| 1616 | } |
| 1617 | } |
| 1618 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1619 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1620 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1621 | if (animator.mWindowDetachedWallpaper != mTmpWindow) { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1622 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1623 | + animator.mWindowDetachedWallpaper + " to " + mTmpWindow); |
| 1624 | animator.mWindowDetachedWallpaper = mTmpWindow; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1625 | animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | void prepareWindowSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1630 | forAllWindows(w -> { |
| 1631 | w.mWinAnimator.prepareSurfaceLocked(true); |
| 1632 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1635 | boolean inputMethodClientHasFocus(IInputMethodClient client) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1636 | final WindowState imFocus = computeImeTarget(false /* updateImeTarget */); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1637 | if (imFocus == null) { |
| 1638 | return false; |
| 1639 | } |
| 1640 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1641 | if (DEBUG_INPUT_METHOD) { |
| 1642 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
| 1643 | Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus); |
| 1644 | Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1647 | final IInputMethodClient imeClient = imFocus.mSession.mClient; |
| 1648 | |
| 1649 | if (DEBUG_INPUT_METHOD) { |
| 1650 | Slog.i(TAG_WM, "IM target client: " + imeClient); |
| 1651 | if (imeClient != null) { |
| 1652 | Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder()); |
| 1653 | Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder()); |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | return imeClient != null && imeClient.asBinder() == client.asBinder(); |
| 1658 | } |
| 1659 | |
| 1660 | boolean hasSecureWindowOnScreen() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1661 | final WindowState win = getWindow( |
| 1662 | w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0); |
| 1663 | return win != null; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1667 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1668 | try { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1669 | final int curValue = w.mSystemUiVisibility; |
| 1670 | final int diff = (curValue ^ visibility) & globalDiff; |
| 1671 | final int newValue = (curValue & ~diff) | (visibility & diff); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1672 | if (newValue != curValue) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1673 | w.mSeq++; |
| 1674 | w.mSystemUiVisibility = newValue; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1675 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1676 | if (newValue != curValue || w.mAttrs.hasSystemUiListeners) { |
| 1677 | w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1678 | visibility, newValue, diff); |
| 1679 | } |
| 1680 | } catch (RemoteException e) { |
| 1681 | // so sorry |
| 1682 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1683 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | void onWindowFreezeTimeout() { |
| 1687 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
| 1688 | mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1689 | |
| 1690 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1691 | if (!w.mOrientationChanging) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1692 | return; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1693 | } |
| 1694 | w.mOrientationChanging = false; |
| 1695 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 1696 | - mService.mDisplayFreezeTime); |
| 1697 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1698 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1699 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 1700 | } |
| 1701 | |
| 1702 | void waitForAllWindowsDrawn() { |
| 1703 | final WindowManagerPolicy policy = mService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1704 | forAllWindows(w -> { |
| 1705 | final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs); |
| 1706 | if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) { |
| 1707 | w.mWinAnimator.mDrawState = DRAW_PENDING; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1708 | // Force add to mResizingWindows. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1709 | w.mLastContentInsets.set(-1, -1, -1, -1); |
| 1710 | mService.mWaitingForDrawn.add(w); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1711 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1712 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1715 | // TODO: Super crazy long method that should be broken down... |
| 1716 | boolean applySurfaceChangesTransaction(boolean recoveringMemory) { |
| 1717 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1718 | final int dw = mDisplayInfo.logicalWidth; |
| 1719 | final int dh = mDisplayInfo.logicalHeight; |
| 1720 | final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked; |
| 1721 | |
| 1722 | mTmpUpdateAllDrawn.clear(); |
| 1723 | |
| 1724 | int repeats = 0; |
| 1725 | do { |
| 1726 | repeats++; |
| 1727 | if (repeats > 6) { |
| 1728 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 1729 | clearLayoutNeeded(); |
| 1730 | break; |
| 1731 | } |
| 1732 | |
| 1733 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner", |
| 1734 | pendingLayoutChanges); |
| 1735 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1736 | // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid |
| 1737 | // the wallpaper window jumping across displays. |
| 1738 | // Remove check for default display when there will be support for multiple wallpaper |
| 1739 | // targets (on different displays). |
| 1740 | if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1741 | mWallpaperController.adjustWallpaperWindows(this); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 1745 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 1746 | if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) { |
| 1747 | setLayoutNeeded(); |
Andrii Kulian | b17e869 | 2016-11-01 10:37:22 -0700 | [diff] [blame] | 1748 | mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 1753 | setLayoutNeeded(); |
| 1754 | } |
| 1755 | |
| 1756 | // FIRST LOOP: Perform a layout, if needed. |
| 1757 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 1758 | performLayout(repeats == 1, false /* updateInputWindows */); |
| 1759 | } else { |
| 1760 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 1761 | } |
| 1762 | |
| 1763 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating. |
| 1764 | pendingLayoutChanges = 0; |
| 1765 | |
| 1766 | if (isDefaultDisplay) { |
| 1767 | mService.mPolicy.beginPostLayoutPolicyLw(dw, dh); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1768 | forAllWindows(w -> { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1769 | mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), |
| 1770 | mService.mInputMethodTarget); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1771 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1772 | pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw(); |
| 1773 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 1774 | "after finishPostLayoutPolicyLw", pendingLayoutChanges); |
| 1775 | } |
| 1776 | } while (pendingLayoutChanges != 0); |
| 1777 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1778 | final RootWindowContainer root = mService.mRoot; |
| 1779 | mTmpApplySurfaceChangesTransactionState.reset(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1780 | resetDimming(); |
| 1781 | |
| 1782 | // Only used if default window |
| 1783 | final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty(); |
| 1784 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1785 | forAllWindows(w -> { |
| 1786 | final boolean obscuredChanged = w.mObscured != |
| 1787 | mTmpApplySurfaceChangesTransactionState.obscured; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1788 | |
| 1789 | // Update effect. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1790 | w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured; |
| 1791 | if (!mTmpApplySurfaceChangesTransactionState.obscured) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1792 | final boolean isDisplayed = w.isDisplayedLw(); |
| 1793 | |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1794 | if (isDisplayed && w.isObscuringDisplay()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1795 | // This window completely covers everything behind it, so we want to leave all |
| 1796 | // of them as undimmed (for performance reasons). |
| 1797 | root.mObscuringWindow = w; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1798 | mTmpApplySurfaceChangesTransactionState.obscured = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1801 | mTmpApplySurfaceChangesTransactionState.displayHasContent |= |
| 1802 | root.handleNotObscuredLocked(w, |
| 1803 | mTmpApplySurfaceChangesTransactionState.obscured, |
| 1804 | mTmpApplySurfaceChangesTransactionState.syswin); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1805 | |
| 1806 | if (w.mHasSurface && isDisplayed) { |
| 1807 | final int type = w.mAttrs.type; |
| 1808 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
| 1809 | || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1810 | mTmpApplySurfaceChangesTransactionState.syswin = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1811 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1812 | if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0 |
| 1813 | && w.mAttrs.preferredRefreshRate != 0) { |
| 1814 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate |
| 1815 | = w.mAttrs.preferredRefreshRate; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1816 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1817 | if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0 |
| 1818 | && w.mAttrs.preferredDisplayModeId != 0) { |
| 1819 | mTmpApplySurfaceChangesTransactionState.preferredModeId |
| 1820 | = w.mAttrs.preferredDisplayModeId; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | w.applyDimLayerIfNeeded(); |
| 1826 | |
| 1827 | if (isDefaultDisplay && obscuredChanged && w.isVisibleLw() |
| 1828 | && mWallpaperController.isWallpaperTarget(w)) { |
| 1829 | // This is the wallpaper target and its obscured state changed... make sure the |
| 1830 | // current wallpaper's visibility has been updated accordingly. |
| 1831 | mWallpaperController.updateWallpaperVisibility(); |
| 1832 | } |
| 1833 | |
| 1834 | w.handleWindowMovedIfNeeded(); |
| 1835 | |
| 1836 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 1837 | |
| 1838 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 1839 | w.mContentChanged = false; |
| 1840 | |
| 1841 | // Moved from updateWindowsAndWallpaperLocked(). |
| 1842 | if (w.mHasSurface) { |
| 1843 | // Take care of the window being ready to display. |
| 1844 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 1845 | if (isDefaultDisplay && committed) { |
| 1846 | if (w.mAttrs.type == TYPE_DREAM) { |
| 1847 | // HACK: When a dream is shown, it may at that point hide the lock screen. |
| 1848 | // So we need to redo the layout to let the phone window manager make this |
| 1849 | // happen. |
| 1850 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 1851 | if (DEBUG_LAYOUT_REPEATS) { |
| 1852 | surfacePlacer.debugLayoutRepeats( |
| 1853 | "dream and commitFinishDrawingLocked true", |
| 1854 | pendingLayoutChanges); |
| 1855 | } |
| 1856 | } |
| 1857 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 1858 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 1859 | "First draw done in potential wallpaper target " + w); |
| 1860 | root.mWallpaperMayChange = true; |
| 1861 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 1862 | if (DEBUG_LAYOUT_REPEATS) { |
| 1863 | surfacePlacer.debugLayoutRepeats( |
| 1864 | "wallpaper and commitFinishDrawingLocked true", |
| 1865 | pendingLayoutChanges); |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) { |
| 1870 | // Updates the shown frame before we set up the surface. This is needed |
| 1871 | // because the resizing could change the top-left position (in addition to |
| 1872 | // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to |
| 1873 | // position the surface. |
| 1874 | // |
| 1875 | // If an animation is being started, we can't call this method because the |
| 1876 | // animation hasn't processed its initial transformation yet, but in general |
| 1877 | // we do want to update the position if the window is animating. |
| 1878 | winAnimator.computeShownFrameLocked(); |
| 1879 | } |
| 1880 | winAnimator.setSurfaceBoundariesLocked(recoveringMemory); |
| 1881 | } |
| 1882 | |
| 1883 | final AppWindowToken atoken = w.mAppToken; |
| 1884 | if (atoken != null) { |
| 1885 | final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w); |
| 1886 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) { |
| 1887 | mTmpUpdateAllDrawn.add(atoken); |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus |
| 1892 | && w.isDisplayedLw()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1893 | mTmpApplySurfaceChangesTransactionState.focusDisplayed = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | w.updateResizingWindowIfNeeded(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1897 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1898 | |
| 1899 | mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1900 | mTmpApplySurfaceChangesTransactionState.displayHasContent, |
| 1901 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate, |
| 1902 | mTmpApplySurfaceChangesTransactionState.preferredModeId, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1903 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 1904 | |
| 1905 | stopDimmingIfNeeded(); |
| 1906 | |
| 1907 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
| 1908 | final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast(); |
| 1909 | // See if any windows have been drawn, so they (and others associated with them) |
| 1910 | // can now be shown. |
| 1911 | atoken.updateAllDrawn(this); |
| 1912 | } |
| 1913 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1914 | return mTmpApplySurfaceChangesTransactionState.focusDisplayed; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | void performLayout(boolean initial, boolean updateInputWindows) { |
| 1918 | if (!isLayoutNeeded()) { |
| 1919 | return; |
| 1920 | } |
| 1921 | clearLayoutNeeded(); |
| 1922 | |
| 1923 | final int dw = mDisplayInfo.logicalWidth; |
| 1924 | final int dh = mDisplayInfo.logicalHeight; |
| 1925 | |
| 1926 | int i; |
| 1927 | |
| 1928 | if (DEBUG_LAYOUT) { |
| 1929 | Slog.v(TAG, "-------------------------------------"); |
| 1930 | Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh); |
| 1931 | } |
| 1932 | |
| 1933 | mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation, |
| 1934 | getConfiguration().uiMode); |
| 1935 | if (isDefaultDisplay) { |
| 1936 | // Not needed on non-default displays. |
| 1937 | mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw(); |
| 1938 | mService.mScreenRect.set(0, 0, dw, dh); |
| 1939 | } |
| 1940 | |
| 1941 | mService.mPolicy.getContentRectLw(mContentRect); |
| 1942 | |
| 1943 | int seq = mService.mLayoutSeq + 1; |
| 1944 | if (seq < 0) seq = 0; |
| 1945 | mService.mLayoutSeq = seq; |
| 1946 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1947 | // Used to indicate that we have processed the dream window and all additional windows are |
| 1948 | // behind it. |
| 1949 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1950 | |
| 1951 | // First perform layout of any root windows (not attached to another window). |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1952 | forAllWindows(w -> { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1953 | // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid |
| 1954 | // wasting time and funky changes while a window is animating away. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1955 | final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) |
| 1956 | || w.isGoneForLayoutLw(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1957 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1958 | if (DEBUG_LAYOUT && !w.mLayoutAttached) { |
| 1959 | Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame |
| 1960 | + " mLayoutAttached=" + w.mLayoutAttached |
| 1961 | + " screen changed=" + w.isConfigChanged()); |
| 1962 | final AppWindowToken atoken = w.mAppToken; |
| 1963 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility |
| 1964 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1965 | + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested) |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1966 | + " parentHidden=" + w.isParentWindowHidden()); |
| 1967 | else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility |
| 1968 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1969 | + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested) |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1970 | + " parentHidden=" + w.isParentWindowHidden()); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | // If this view is GONE, then skip it -- keep the current frame, and let the caller know |
| 1974 | // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows, |
| 1975 | // since that means "perform layout as normal, just don't display"). |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1976 | if (!gone || !w.mHaveFrame || w.mLayoutNeeded |
| 1977 | || ((w.isConfigChanged() || w.setReportResizeHints()) |
| 1978 | && !w.isGoneForLayoutLw() && |
| 1979 | ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
| 1980 | (w.mHasSurface && w.mAppToken != null && |
| 1981 | w.mAppToken.layoutConfigChanges)))) { |
| 1982 | if (!w.mLayoutAttached) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1983 | if (initial) { |
| 1984 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1985 | w.mContentChanged = false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1986 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1987 | if (w.mAttrs.type == TYPE_DREAM) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1988 | // Don't layout windows behind a dream, so that if it does stuff like hide |
| 1989 | // the status bar we won't get a bad transition when it goes away. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1990 | mTmpWindow = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1991 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1992 | w.mLayoutNeeded = false; |
| 1993 | w.prelayout(); |
| 1994 | mService.mPolicy.layoutWindowLw(w, null); |
| 1995 | w.mLayoutSeq = mService.mLayoutSeq; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1996 | |
| 1997 | // Window frames may have changed. Update dim layer with the new bounds. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 1998 | final Task task = w.getTask(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1999 | if (task != null) { |
| 2000 | mDimLayerController.updateDimLayer(task); |
| 2001 | } |
| 2002 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2003 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame |
| 2004 | + " mContainingFrame=" + w.mContainingFrame |
| 2005 | + " mDisplayFrame=" + w.mDisplayFrame); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2006 | } |
| 2007 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2008 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2009 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2010 | // Used to indicate that we have processed the dream window and all additional attached |
| 2011 | // windows are behind it. |
| 2012 | final WindowState dreamWin = mTmpWindow; |
| 2013 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2014 | |
| 2015 | // Now perform layout of attached windows, which usually depend on the position of the |
| 2016 | // window they are attached to. XXX does not deal with windows that are attached to windows |
| 2017 | // that are themselves attached. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2018 | forAllWindows(w -> { |
| 2019 | if (w.mLayoutAttached) { |
| 2020 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame |
| 2021 | + " mViewVisibility=" + w.mViewVisibility |
| 2022 | + " mRelayoutCalled=" + w.mRelayoutCalled); |
| 2023 | // If this view is GONE, then skip it -- keep the current frame, and let the |
| 2024 | // caller know so they can ignore it if they want. (We do the normal layout for |
| 2025 | // INVISIBLE windows, since that means "perform layout as normal, just don't |
| 2026 | // display"). |
| 2027 | if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) { |
| 2028 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2029 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2030 | if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame |
| 2031 | || w.mLayoutNeeded) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2032 | if (initial) { |
| 2033 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2034 | w.mContentChanged = false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2035 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2036 | w.mLayoutNeeded = false; |
| 2037 | w.prelayout(); |
| 2038 | mService.mPolicy.layoutWindowLw(w, w.getParentWindow()); |
| 2039 | w.mLayoutSeq = mService.mLayoutSeq; |
| 2040 | if (DEBUG_LAYOUT) |
| 2041 | Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame |
| 2042 | + " mContainingFrame=" + w.mContainingFrame |
| 2043 | + " mDisplayFrame=" + w.mDisplayFrame); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2044 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2045 | } else if (w.mAttrs.type == TYPE_DREAM) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2046 | // Don't layout windows behind a dream, so that if it does stuff like hide the |
| 2047 | // status bar we won't get a bad transition when it goes away. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2048 | mTmpWindow = dreamWin; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2049 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2050 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2051 | |
| 2052 | // Window frames may have changed. Tell the input dispatcher about it. |
| 2053 | mService.mInputMonitor.layoutInputConsumers(dw, dh); |
| 2054 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2055 | if (updateInputWindows) { |
| 2056 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 2057 | } |
| 2058 | |
| 2059 | mService.mPolicy.finishLayoutLw(); |
| 2060 | mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER); |
| 2061 | } |
| 2062 | |
| 2063 | /** |
| 2064 | * Takes a snapshot of the display. In landscape mode this grabs the whole screen. |
| 2065 | * In portrait mode, it grabs the full screenshot. |
| 2066 | * |
| 2067 | * @param width the width of the target bitmap |
| 2068 | * @param height the height of the target bitmap |
| 2069 | * @param includeFullDisplay true if the screen should not be cropped before capture |
| 2070 | * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1 |
| 2071 | * @param config of the output bitmap |
| 2072 | * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot |
| 2073 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2074 | Bitmap screenshotApplications(IBinder appToken, int width, int height, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2075 | boolean includeFullDisplay, float frameScale, Bitmap.Config config, |
| 2076 | boolean wallpaperOnly) { |
| 2077 | int dw = mDisplayInfo.logicalWidth; |
| 2078 | int dh = mDisplayInfo.logicalHeight; |
| 2079 | if (dw == 0 || dh == 0) { |
| 2080 | if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken |
| 2081 | + ": returning null. logical widthxheight=" + dw + "x" + dh); |
| 2082 | return null; |
| 2083 | } |
| 2084 | |
| 2085 | Bitmap bm = null; |
| 2086 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2087 | mScreenshotApplicationState.reset(appToken == null && !wallpaperOnly); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2088 | final Rect frame = new Rect(); |
| 2089 | final Rect stackBounds = new Rect(); |
| 2090 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2091 | boolean includeImeInScreenshot; |
| 2092 | synchronized(mService.mWindowMap) { |
| 2093 | final AppWindowToken imeTargetAppToken = mService.mInputMethodTarget != null |
| 2094 | ? mService.mInputMethodTarget.mAppToken : null; |
| 2095 | // We only include the Ime in the screenshot if the app we are screenshoting is the IME |
| 2096 | // target and isn't in multi-window mode. We don't screenshot the IME in multi-window |
| 2097 | // mode because the frame of the IME might not overlap with that of the app. |
| 2098 | // E.g. IME target app at the top in split-screen mode and the IME at the bottom |
| 2099 | // overlapping with the bottom app. |
| 2100 | includeImeInScreenshot = imeTargetAppToken != null |
| 2101 | && imeTargetAppToken.appToken != null |
| 2102 | && imeTargetAppToken.appToken.asBinder() == appToken |
| 2103 | && !mService.mInputMethodTarget.isInMultiWindowMode(); |
| 2104 | } |
| 2105 | |
| 2106 | final int aboveAppLayer = (mService.mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1) |
| 2107 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
| 2108 | |
| 2109 | synchronized(mService.mWindowMap) { |
| 2110 | // Figure out the part of the screen that is actually the app. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2111 | mScreenshotApplicationState.appWin = null; |
| 2112 | forAllWindows(w -> { |
| 2113 | if (!w.mHasSurface) { |
| 2114 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2115 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2116 | if (w.mLayer >= aboveAppLayer) { |
| 2117 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2118 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2119 | if (wallpaperOnly && !w.mIsWallpaper) { |
| 2120 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2121 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2122 | if (w.mIsImWindow) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2123 | if (!includeImeInScreenshot) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2124 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2125 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2126 | } else if (w.mIsWallpaper) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2127 | // If this is the wallpaper layer and we're only looking for the wallpaper layer |
| 2128 | // then the target window state is this one. |
| 2129 | if (wallpaperOnly) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2130 | mScreenshotApplicationState.appWin = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2133 | if (mScreenshotApplicationState.appWin == null) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2134 | // We have not ran across the target window yet, so it is probably behind |
| 2135 | // the wallpaper. This can happen when the keyguard is up and all windows |
| 2136 | // are moved behind the wallpaper. We don't want to include the wallpaper |
| 2137 | // layer in the screenshot as it will cover-up the layer of the target |
| 2138 | // window. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2139 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2140 | } |
| 2141 | // Fall through. The target window is in front of the wallpaper. For this |
| 2142 | // case we want to include the wallpaper layer in the screenshot because |
| 2143 | // the target window might have some transparent areas. |
| 2144 | } else if (appToken != null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2145 | if (w.mAppToken == null || w.mAppToken.token != appToken) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2146 | // This app window is of no interest if it is not associated with the |
| 2147 | // screenshot app. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2148 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2149 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2150 | mScreenshotApplicationState.appWin = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | // Include this window. |
| 2154 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2155 | final WindowStateAnimator winAnim = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2156 | int layer = winAnim.mSurfaceController.getLayer(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2157 | if (mScreenshotApplicationState.maxLayer < layer) { |
| 2158 | mScreenshotApplicationState.maxLayer = layer; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2159 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2160 | if (mScreenshotApplicationState.minLayer > layer) { |
| 2161 | mScreenshotApplicationState.minLayer = layer; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | // Don't include wallpaper in bounds calculation |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2165 | if (!includeFullDisplay && !w.mIsWallpaper) { |
| 2166 | final Rect wf = w.mFrame; |
| 2167 | final Rect cr = w.mContentInsets; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2168 | int left = wf.left + cr.left; |
| 2169 | int top = wf.top + cr.top; |
| 2170 | int right = wf.right - cr.right; |
| 2171 | int bottom = wf.bottom - cr.bottom; |
| 2172 | frame.union(left, top, right, bottom); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2173 | w.getVisibleBounds(stackBounds); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2174 | if (!Rect.intersects(frame, stackBounds)) { |
| 2175 | // Set frame empty if there's no intersection. |
| 2176 | frame.setEmpty(); |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | final boolean foundTargetWs = |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2181 | (w.mAppToken != null && w.mAppToken.token == appToken) |
| 2182 | || (mScreenshotApplicationState.appWin != null && wallpaperOnly); |
| 2183 | if (foundTargetWs && w.isDisplayedLw() && winAnim.getShown()) { |
| 2184 | mScreenshotApplicationState.screenshotReady = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2187 | if (w.isObscuringDisplay()){ |
| 2188 | return true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2189 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2190 | return false; |
| 2191 | }, true /* traverseTopToBottom */); |
| 2192 | |
| 2193 | final WindowState appWin = mScreenshotApplicationState.appWin; |
| 2194 | final boolean screenshotReady = mScreenshotApplicationState.screenshotReady; |
| 2195 | final int maxLayer = mScreenshotApplicationState.maxLayer; |
| 2196 | final int minLayer = mScreenshotApplicationState.minLayer; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2197 | |
| 2198 | if (appToken != null && appWin == null) { |
| 2199 | // Can't find a window to snapshot. |
| 2200 | if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, |
| 2201 | "Screenshot: Couldn't find a surface matching " + appToken); |
| 2202 | return null; |
| 2203 | } |
| 2204 | |
| 2205 | if (!screenshotReady) { |
| 2206 | Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken + |
| 2207 | " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" + |
| 2208 | appWin.mWinAnimator.mDrawState))); |
| 2209 | return null; |
| 2210 | } |
| 2211 | |
| 2212 | // Screenshot is ready to be taken. Everything from here below will continue |
| 2213 | // through the bottom of the loop and return a value. We only stay in the loop |
| 2214 | // because we don't want to release the mWindowMap lock until the screenshot is |
| 2215 | // taken. |
| 2216 | |
| 2217 | if (maxLayer == 0) { |
| 2218 | if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken |
| 2219 | + ": returning null maxLayer=" + maxLayer); |
| 2220 | return null; |
| 2221 | } |
| 2222 | |
| 2223 | if (!includeFullDisplay) { |
| 2224 | // Constrain frame to the screen size. |
| 2225 | if (!frame.intersect(0, 0, dw, dh)) { |
| 2226 | frame.setEmpty(); |
| 2227 | } |
| 2228 | } else { |
| 2229 | // Caller just wants entire display. |
| 2230 | frame.set(0, 0, dw, dh); |
| 2231 | } |
| 2232 | if (frame.isEmpty()) { |
| 2233 | return null; |
| 2234 | } |
| 2235 | |
| 2236 | if (width < 0) { |
| 2237 | width = (int) (frame.width() * frameScale); |
| 2238 | } |
| 2239 | if (height < 0) { |
| 2240 | height = (int) (frame.height() * frameScale); |
| 2241 | } |
| 2242 | |
| 2243 | // Tell surface flinger what part of the image to crop. Take the top |
| 2244 | // right part of the application, and crop the larger dimension to fit. |
| 2245 | Rect crop = new Rect(frame); |
| 2246 | if (width / (float) frame.width() < height / (float) frame.height()) { |
| 2247 | int cropWidth = (int)((float)width / (float)height * frame.height()); |
| 2248 | crop.right = crop.left + cropWidth; |
| 2249 | } else { |
| 2250 | int cropHeight = (int)((float)height / (float)width * frame.width()); |
| 2251 | crop.bottom = crop.top + cropHeight; |
| 2252 | } |
| 2253 | |
| 2254 | // The screenshot API does not apply the current screen rotation. |
| 2255 | int rot = mDisplay.getRotation(); |
| 2256 | |
| 2257 | if (rot == ROTATION_90 || rot == ROTATION_270) { |
| 2258 | rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 2259 | } |
| 2260 | |
| 2261 | // Surfaceflinger is not aware of orientation, so convert our logical |
| 2262 | // crop to surfaceflinger's portrait orientation. |
| 2263 | convertCropForSurfaceFlinger(crop, rot, dw, dh); |
| 2264 | |
| 2265 | if (DEBUG_SCREENSHOT) { |
| 2266 | Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to " |
| 2267 | + maxLayer + " appToken=" + appToken); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2268 | forAllWindows(w -> { |
| 2269 | final WindowSurfaceController controller = w.mWinAnimator.mSurfaceController; |
| 2270 | Slog.i(TAG_WM, w + ": " + w.mLayer |
| 2271 | + " animLayer=" + w.mWinAnimator.mAnimLayer |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2272 | + " surfaceLayer=" + ((controller == null) |
| 2273 | ? "null" : controller.getLayer())); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2274 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | final ScreenRotationAnimation screenRotationAnimation = |
| 2278 | mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY); |
| 2279 | final boolean inRotation = screenRotationAnimation != null && |
| 2280 | screenRotationAnimation.isAnimating(); |
| 2281 | if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, |
| 2282 | "Taking screenshot while rotating"); |
| 2283 | |
| 2284 | // We force pending transactions to flush before taking |
| 2285 | // the screenshot by pushing an empty synchronous transaction. |
| 2286 | SurfaceControl.openTransaction(); |
| 2287 | SurfaceControl.closeTransactionSync(); |
| 2288 | |
| 2289 | bm = SurfaceControl.screenshot(crop, width, height, minLayer, maxLayer, |
| 2290 | inRotation, rot); |
| 2291 | if (bm == null) { |
| 2292 | Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh |
| 2293 | + ") to layer " + maxLayer); |
| 2294 | return null; |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | if (DEBUG_SCREENSHOT) { |
| 2299 | // TEST IF IT's ALL BLACK |
| 2300 | int[] buffer = new int[bm.getWidth() * bm.getHeight()]; |
| 2301 | bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight()); |
| 2302 | boolean allBlack = true; |
| 2303 | final int firstColor = buffer[0]; |
| 2304 | for (int i = 0; i < buffer.length; i++) { |
| 2305 | if (buffer[i] != firstColor) { |
| 2306 | allBlack = false; |
| 2307 | break; |
| 2308 | } |
| 2309 | } |
| 2310 | if (allBlack) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2311 | final WindowState appWin = mScreenshotApplicationState.appWin; |
| 2312 | final int maxLayer = mScreenshotApplicationState.maxLayer; |
| 2313 | final int minLayer = mScreenshotApplicationState.minLayer; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2314 | Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" + |
| 2315 | Integer.toHexString(firstColor) + ")! mSurfaceLayer=" + |
| 2316 | (appWin != null ? |
| 2317 | appWin.mWinAnimator.mSurfaceController.getLayer() : "null") + |
| 2318 | " minLayer=" + minLayer + " maxLayer=" + maxLayer); |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | // Create a copy of the screenshot that is immutable and backed in ashmem. |
| 2323 | // This greatly reduces the overhead of passing the bitmap between processes. |
| 2324 | Bitmap ret = bm.createAshmemBitmap(config); |
| 2325 | bm.recycle(); |
| 2326 | return ret; |
| 2327 | } |
| 2328 | |
| 2329 | // TODO: Can this use createRotationMatrix()? |
| 2330 | private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) { |
| 2331 | if (rot == Surface.ROTATION_90) { |
| 2332 | final int tmp = crop.top; |
| 2333 | crop.top = dw - crop.right; |
| 2334 | crop.right = crop.bottom; |
| 2335 | crop.bottom = dw - crop.left; |
| 2336 | crop.left = tmp; |
| 2337 | } else if (rot == Surface.ROTATION_180) { |
| 2338 | int tmp = crop.top; |
| 2339 | crop.top = dh - crop.bottom; |
| 2340 | crop.bottom = dh - tmp; |
| 2341 | tmp = crop.right; |
| 2342 | crop.right = dw - crop.left; |
| 2343 | crop.left = dw - tmp; |
| 2344 | } else if (rot == Surface.ROTATION_270) { |
| 2345 | final int tmp = crop.top; |
| 2346 | crop.top = crop.left; |
| 2347 | crop.left = dh - crop.bottom; |
| 2348 | crop.bottom = crop.right; |
| 2349 | crop.right = dh - tmp; |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | void onSeamlessRotationTimeout() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2354 | // Used to indicate the layout is needed. |
| 2355 | mTmpWindow = null; |
| 2356 | |
| 2357 | forAllWindows(w -> { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2358 | if (!w.mSeamlesslyRotated) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2359 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2360 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2361 | mTmpWindow = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2362 | w.setDisplayLayoutNeeded(); |
| 2363 | mService.markForSeamlessRotation(w, false); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2364 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2365 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2366 | if (mTmpWindow != null) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2367 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 2368 | } |
| 2369 | } |
| 2370 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2371 | static final class TaskForResizePointSearchResult { |
| 2372 | boolean searchDone; |
| 2373 | Task taskForResize; |
| 2374 | |
| 2375 | void reset() { |
| 2376 | searchDone = false; |
| 2377 | taskForResize = null; |
| 2378 | } |
| 2379 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2380 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2381 | private static final class ApplySurfaceChangesTransactionState { |
| 2382 | boolean displayHasContent; |
| 2383 | boolean obscured; |
| 2384 | boolean syswin; |
| 2385 | boolean focusDisplayed; |
| 2386 | float preferredRefreshRate; |
| 2387 | int preferredModeId; |
| 2388 | |
| 2389 | void reset() { |
| 2390 | displayHasContent = false; |
| 2391 | obscured = false; |
| 2392 | syswin = false; |
| 2393 | focusDisplayed = false; |
| 2394 | preferredRefreshRate = 0; |
| 2395 | preferredModeId = 0; |
| 2396 | } |
| 2397 | } |
| 2398 | |
| 2399 | private static final class ScreenshotApplicationState { |
| 2400 | WindowState appWin; |
| 2401 | int maxLayer; |
| 2402 | int minLayer; |
| 2403 | boolean screenshotReady; |
| 2404 | |
| 2405 | void reset(boolean screenshotReady) { |
| 2406 | appWin = null; |
| 2407 | maxLayer = 0; |
| 2408 | minLayer = 0; |
| 2409 | this.screenshotReady = screenshotReady; |
| 2410 | minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE; |
| 2411 | } |
| 2412 | } |
| 2413 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2414 | /** |
| 2415 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 2416 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 2417 | * homogeneous children type which is currently required by sub-classes of |
| 2418 | * {@link WindowContainer} class. |
| 2419 | */ |
| 2420 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 2421 | |
| 2422 | int size() { |
| 2423 | return mChildren.size(); |
| 2424 | } |
| 2425 | |
| 2426 | E get(int index) { |
| 2427 | return mChildren.get(index); |
| 2428 | } |
| 2429 | |
| 2430 | @Override |
| 2431 | boolean fillsParent() { |
| 2432 | return true; |
| 2433 | } |
| 2434 | |
| 2435 | @Override |
| 2436 | boolean isVisible() { |
| 2437 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2441 | /** |
| 2442 | * Window container class that contains all containers on this display relating to Apps. |
| 2443 | * I.e Activities. |
| 2444 | */ |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 2445 | private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2446 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2447 | /** |
| 2448 | * Adds the stack to this container. |
| 2449 | * @see WindowManagerService#addStackToDisplay(int, int, boolean) |
| 2450 | */ |
| 2451 | void addStackToDisplay(TaskStack stack, boolean onTop) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2452 | if (stack.mStackId == HOME_STACK_ID) { |
| 2453 | if (mHomeStack != null) { |
| 2454 | throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first."); |
| 2455 | } |
| 2456 | mHomeStack = stack; |
| 2457 | } |
| 2458 | addChild(stack, onTop); |
| 2459 | stack.onDisplayChanged(DisplayContent.this); |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2460 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2461 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2462 | /** Removes the stack from its container and prepare for changing the parent. */ |
| 2463 | void removeStackFromDisplay(TaskStack stack) { |
| 2464 | removeChild(stack); |
| 2465 | stack.onRemovedFromDisplay(); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2468 | void moveStack(TaskStack stack, boolean toTop) { |
| 2469 | if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) { |
| 2470 | // This stack is always-on-top silly... |
| 2471 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom"); |
| 2472 | return; |
| 2473 | } |
| 2474 | |
| 2475 | if (!mChildren.contains(stack)) { |
| 2476 | Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable()); |
| 2477 | } |
| 2478 | removeChild(stack); |
| 2479 | addChild(stack, toTop); |
| 2480 | } |
| 2481 | |
| 2482 | private void addChild(TaskStack stack, boolean toTop) { |
| 2483 | int addIndex = toTop ? mChildren.size() : 0; |
| 2484 | |
| 2485 | if (toTop |
| 2486 | && mService.isStackVisibleLocked(PINNED_STACK_ID) |
| 2487 | && stack.mStackId != PINNED_STACK_ID) { |
| 2488 | // The pinned stack is always the top most stack (always-on-top) when it is visible. |
| 2489 | // So, stack is moved just below the pinned stack. |
| 2490 | addIndex--; |
| 2491 | TaskStack topStack = mChildren.get(addIndex); |
| 2492 | if (topStack.mStackId != PINNED_STACK_ID) { |
| 2493 | throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren); |
| 2494 | } |
| 2495 | } |
| 2496 | addChild(stack, addIndex); |
| 2497 | setLayoutNeeded(); |
| 2498 | } |
| 2499 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2500 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2501 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 2502 | boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2503 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2504 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 2505 | return true; |
| 2506 | } |
| 2507 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 2508 | return true; |
| 2509 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2510 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2511 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 2512 | return true; |
| 2513 | } |
| 2514 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 2515 | return true; |
| 2516 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2517 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2518 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2521 | private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback, |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2522 | boolean traverseTopToBottom) { |
| 2523 | // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the |
| 2524 | // app tokens. |
| 2525 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 2526 | // in-order. |
| 2527 | if (traverseTopToBottom) { |
| 2528 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 2529 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 2530 | for (int j = appTokens.size() - 1; j >= 0; --j) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2531 | if (appTokens.get(j).forAllWindowsUnchecked(callback, |
| 2532 | traverseTopToBottom)) { |
| 2533 | return true; |
| 2534 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | } else { |
| 2538 | final int count = mChildren.size(); |
| 2539 | for (int i = 0; i < count; ++i) { |
| 2540 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 2541 | final int appTokensCount = appTokens.size(); |
| 2542 | for (int j = 0; j < appTokensCount; j++) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2543 | if (appTokens.get(j).forAllWindowsUnchecked(callback, |
| 2544 | traverseTopToBottom)) { |
| 2545 | return true; |
| 2546 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2547 | } |
| 2548 | } |
| 2549 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 2550 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | @Override |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2554 | int getOrientation() { |
| 2555 | if (mService.isStackVisibleLocked(DOCKED_STACK_ID) |
| 2556 | || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) { |
| 2557 | // Apps and their containers are not allowed to specify an orientation while the |
| 2558 | // docked or freeform stack is visible...except for the home stack/task if the |
| 2559 | // docked stack is minimized and it actually set something. |
| 2560 | if (mHomeStack != null && mHomeStack.isVisible() |
| 2561 | && mDividerControllerLocked.isMinimizedDock()) { |
| 2562 | final int orientation = mHomeStack.getOrientation(); |
| 2563 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 2564 | return orientation; |
| 2565 | } |
| 2566 | } |
| 2567 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 2568 | } |
| 2569 | |
| 2570 | final int orientation = super.getOrientation(); |
| 2571 | if (orientation != SCREEN_ORIENTATION_UNSET |
| 2572 | && orientation != SCREEN_ORIENTATION_BEHIND) { |
| 2573 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 2574 | "App is requesting an orientation, return " + orientation); |
| 2575 | return orientation; |
| 2576 | } |
| 2577 | |
| 2578 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 2579 | "No app is requesting an orientation, return " + mService.mLastOrientation); |
| 2580 | // The next app has not been requested to be visible, so we keep the current orientation |
| 2581 | // to prevent freezing/unfreezing the display too early. |
| 2582 | return mService.mLastOrientation; |
| 2583 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | /** |
| 2587 | * Window container class that contains all containers on this display that are not related to |
| 2588 | * Apps. E.g. status bar. |
| 2589 | */ |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 2590 | private final class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
| 2591 | /** |
| 2592 | * Compares two child window tokens returns -1 if the first is lesser than the second in |
| 2593 | * terms of z-order and 1 otherwise. |
| 2594 | */ |
| 2595 | final Comparator<WindowToken> mWindowComparator = (token1, token2) -> |
| 2596 | // Tokens with higher base layer are z-ordered on-top. |
| 2597 | mService.mPolicy.windowTypeToLayerLw(token1.windowType) |
| 2598 | < mService.mPolicy.windowTypeToLayerLw(token2.windowType) ? -1 : 1; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2599 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 2600 | private final String mName; |
| 2601 | NonAppWindowContainers(String name) { |
| 2602 | mName = name; |
| 2603 | } |
| 2604 | |
| 2605 | void addChild(WindowToken token) { |
| 2606 | addChild(token, mWindowComparator); |
| 2607 | } |
| 2608 | |
| 2609 | @Override |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame^] | 2610 | int getOrientation() { |
| 2611 | final WindowManagerPolicy policy = mService.mPolicy; |
| 2612 | // Find a window requesting orientation. |
| 2613 | final WindowState win = getWindow((w) -> { |
| 2614 | if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) { |
| 2615 | return false; |
| 2616 | } |
| 2617 | final int req = w.mAttrs.screenOrientation; |
| 2618 | if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND |
| 2619 | || req == SCREEN_ORIENTATION_UNSET) { |
| 2620 | return false; |
| 2621 | } |
| 2622 | return true; |
| 2623 | }); |
| 2624 | |
| 2625 | if (win != null) { |
| 2626 | final int req = win.mAttrs.screenOrientation; |
| 2627 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req); |
| 2628 | if (policy.isKeyguardHostWindow(win.mAttrs)) { |
| 2629 | mService.mLastKeyguardForcedOrientation = req; |
| 2630 | } |
| 2631 | return (mService.mLastWindowForcedOrientation = req); |
| 2632 | } |
| 2633 | |
| 2634 | mService.mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 2635 | |
| 2636 | if (policy.isKeyguardShowingAndNotOccluded()) { |
| 2637 | return mService.mLastKeyguardForcedOrientation; |
| 2638 | } |
| 2639 | |
| 2640 | return SCREEN_ORIENTATION_UNSET; |
| 2641 | } |
| 2642 | |
| 2643 | @Override |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 2644 | String getName() { |
| 2645 | return mName; |
| 2646 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2647 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2648 | } |