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