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