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