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