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