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