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 | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 33 | import static android.view.WindowManager.DOCKED_INVALID; |
| 34 | import static android.view.WindowManager.DOCKED_TOP; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 36 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 38 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 39 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 40 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE; |
| 42 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 43 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 44 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 45 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 46 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 47 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 48 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
| 49 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 50 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 51 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 52 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 53 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 54 | import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS; |
| 55 | import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE; |
| 56 | import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER; |
| 57 | import static com.android.server.wm.WindowAnimator.KEYGUARD_ANIMATING_OUT; |
| 58 | import static com.android.server.wm.WindowAnimator.KEYGUARD_ANIM_TIMEOUT_MS; |
| 59 | import static com.android.server.wm.WindowAnimator.KEYGUARD_NOT_SHOWN; |
| 60 | import static com.android.server.wm.WindowAnimator.KEYGUARD_SHOWN; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 61 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 62 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 63 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 64 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 65 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 66 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 67 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 68 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEYGUARD; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 69 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 70 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 71 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 72 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 73 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 74 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 75 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 76 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 77 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 78 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 79 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 80 | import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 81 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 82 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
| 83 | import static com.android.server.wm.WindowManagerService.localLOGV; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 84 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 85 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 86 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
| 87 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
| 88 | import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED; |
| 89 | import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 90 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 91 | import android.annotation.NonNull; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 92 | import android.app.ActivityManager.StackId; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 93 | import android.content.res.Configuration; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 94 | import android.graphics.Matrix; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 95 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 96 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 97 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 98 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 99 | import android.hardware.display.DisplayManagerInternal; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 100 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 101 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 102 | import android.os.IBinder; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 103 | import android.os.RemoteException; |
| 104 | import android.os.SystemClock; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 105 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 106 | import android.util.Slog; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 107 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 108 | import android.view.DisplayInfo; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 109 | import android.view.IWindow; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 110 | import android.view.WindowManager; |
| 111 | import android.view.WindowManagerPolicy; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 112 | import android.view.animation.AlphaAnimation; |
| 113 | import android.view.animation.Animation; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 114 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 115 | import com.android.internal.util.FastPrintWriter; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 116 | import com.android.internal.view.IInputMethodClient; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 117 | |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 118 | import java.io.FileDescriptor; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 119 | import java.io.PrintWriter; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 120 | import java.io.StringWriter; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 121 | import java.util.ArrayList; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 122 | import java.util.Arrays; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 123 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 124 | import java.util.HashMap; |
| 125 | import java.util.Iterator; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 126 | import java.util.List; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 127 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 128 | /** |
| 129 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 130 | * particular Display. |
| 131 | * |
| 132 | * IMPORTANT: No method from this class should ever be used without holding |
| 133 | * WindowManagerService.mWindowMap. |
| 134 | */ |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 135 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 136 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 137 | |
| 138 | /** Unique identifier of this stack. */ |
| 139 | private final int mDisplayId; |
| 140 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 141 | // The display only has 2 child window containers. mTaskStackContainers which contains all |
| 142 | // window containers that are related to apps (Activities) and mNonAppWindowContainers which |
| 143 | // contains all window containers not related to apps (e.g. Status bar). |
| 144 | private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(); |
| 145 | private final NonAppWindowContainers mNonAppWindowContainers = new NonAppWindowContainers(); |
| 146 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 147 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 148 | * from mDisplayWindows; */ |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 149 | private final WindowList mWindows = new WindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 150 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 151 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 152 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 153 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 154 | int mInitialDisplayWidth = 0; |
| 155 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 156 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 157 | int mBaseDisplayWidth = 0; |
| 158 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 159 | int mBaseDisplayDensity = 0; |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 160 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 161 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 162 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 163 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 164 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 165 | Rect mBaseDisplayRect = new Rect(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 166 | private Rect mContentRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 167 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 168 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 169 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 170 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 171 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 172 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 173 | /** 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] | 174 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 175 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 176 | /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack |
| 177 | * (except a future lockscreen TaskStack) moves to the top. */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 178 | private TaskStack mHomeStack = null; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 179 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 180 | /** Detect user tapping outside of current focused task bounds .*/ |
| 181 | TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 182 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 183 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 184 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 185 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 186 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 187 | private final Rect mTmpRect = new Rect(); |
| 188 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 189 | private final RectF mTmpRectF = new RectF(); |
| 190 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 191 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 192 | |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 193 | final WindowManagerService mService; |
| 194 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 195 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 196 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 197 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 198 | final DockedStackDividerController mDividerControllerLocked; |
| 199 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 200 | final DimLayerController mDimLayerController; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 201 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 202 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
| 203 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 204 | /** Used when rebuilding window list to keep track of windows that have been removed. */ |
| 205 | private WindowState[] mRebuildTmp = new WindowState[20]; |
| 206 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 207 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 208 | new TaskForResizePointSearchResult(); |
| 209 | private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult = |
| 210 | new GetWindowOnDisplaySearchResult(); |
| 211 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 212 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 213 | // the display's direct children should be allowed. |
| 214 | private boolean mRemovingDisplay = false; |
| 215 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 216 | private final WindowLayersController mLayersController; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 217 | final WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 218 | int mInputMethodAnimLayerAdjustment; |
| 219 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 220 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 221 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 222 | * @param service You know. |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 223 | * @param layersController window layer controller used to assign layer to the windows on this |
| 224 | * display. |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 225 | * @param wallpaperController wallpaper windows controller used to adjust the positioning of the |
| 226 | * wallpaper windows in the window list. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 227 | */ |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 228 | DisplayContent(Display display, WindowManagerService service, |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 229 | WindowLayersController layersController, WallpaperController wallpaperController) { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 230 | mDisplay = display; |
| 231 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 232 | mLayersController = layersController; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 233 | mWallpaperController = wallpaperController; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 234 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 235 | display.getMetrics(mDisplayMetrics); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 236 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 237 | mService = service; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 238 | initializeDisplayBaseInfo(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 239 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 240 | mDimLayerController = new DimLayerController(this); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 241 | |
| 242 | // These are the only direct children we should ever have and they are permanent. |
| 243 | super.addChild(mTaskStackContainers, null); |
| 244 | super.addChild(mNonAppWindowContainers, null); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | int getDisplayId() { |
| 248 | return mDisplayId; |
| 249 | } |
| 250 | |
| 251 | WindowList getWindowList() { |
| 252 | return mWindows; |
| 253 | } |
| 254 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 255 | WindowToken getWindowToken(IBinder binder) { |
| 256 | return mTokenMap.get(binder); |
| 257 | } |
| 258 | |
| 259 | AppWindowToken getAppWindowToken(IBinder binder) { |
| 260 | final WindowToken token = getWindowToken(binder); |
| 261 | if (token == null) { |
| 262 | return null; |
| 263 | } |
| 264 | return token.asAppWindowToken(); |
| 265 | } |
| 266 | |
| 267 | void setWindowToken(IBinder binder, WindowToken token) { |
| 268 | final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token); |
| 269 | if (dc != null) { |
| 270 | // We currently don't support adding a window token to the display if the display |
| 271 | // already has the binder mapped to another token. If there is a use case for supporting |
| 272 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 273 | // the binder map to a list of window tokens. |
| 274 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this |
| 275 | + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
| 276 | } |
| 277 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 278 | |
| 279 | if (token.asAppWindowToken() == null) { |
| 280 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 281 | // the parent container managing them (e.g. Tasks). |
| 282 | mNonAppWindowContainers.addChild(token, null); |
| 283 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 287 | final WindowToken token = mTokenMap.remove(binder); |
| 288 | if (token != null && token.asAppWindowToken() == null) { |
| 289 | mNonAppWindowContainers.removeChild(token); |
| 290 | } |
| 291 | return token; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 294 | Display getDisplay() { |
| 295 | return mDisplay; |
| 296 | } |
| 297 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 298 | DisplayInfo getDisplayInfo() { |
| 299 | return mDisplayInfo; |
| 300 | } |
| 301 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 302 | DisplayMetrics getDisplayMetrics() { |
| 303 | return mDisplayMetrics; |
| 304 | } |
| 305 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 306 | DockedStackDividerController getDockedDividerController() { |
| 307 | return mDividerControllerLocked; |
| 308 | } |
| 309 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 310 | /** |
| 311 | * Returns true if the specified UID has access to this display. |
| 312 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 313 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 314 | return mDisplay.hasAccess(uid); |
| 315 | } |
| 316 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 317 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 318 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 321 | TaskStack getHomeStack() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 322 | if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 323 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 324 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 325 | return mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 328 | TaskStack getStackById(int stackId) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 329 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 330 | final TaskStack stack = mTaskStackContainers.get(i); |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 331 | if (stack.mStackId == stackId) { |
| 332 | return stack; |
| 333 | } |
| 334 | } |
| 335 | return null; |
| 336 | } |
| 337 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 338 | @Override |
| 339 | void onConfigurationChanged(Configuration newParentConfig) { |
| 340 | super.onConfigurationChanged(newParentConfig); |
| 341 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 342 | // The display size information is heavily dependent on the resources in the current |
| 343 | // configuration, so we need to reconfigure it every time the configuration changes. |
| 344 | // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh... |
| 345 | mService.reconfigureDisplayLocked(this); |
| 346 | |
| 347 | getDockedDividerController().onConfigurationChanged(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 348 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 349 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 350 | /** |
| 351 | * Callback used to trigger bounds update after configuration change and get ids of stacks whose |
| 352 | * bounds were updated. |
| 353 | */ |
| 354 | void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 355 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 356 | final TaskStack stack = mTaskStackContainers.get(i); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 357 | if (stack.updateBoundsAfterConfigChange()) { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 358 | changedStackList.add(stack.mStackId); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 363 | @Override |
| 364 | boolean fillsParent() { |
| 365 | return true; |
| 366 | } |
| 367 | |
| 368 | @Override |
| 369 | boolean isVisible() { |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 374 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 375 | super.onAppTransitionDone(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 376 | rebuildAppWindowList(); |
| 377 | } |
| 378 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 379 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 380 | int getOrientation() { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 381 | final WindowManagerPolicy policy = mService.mPolicy; |
| 382 | |
| 383 | // TODO: All the logic before the last return statement in this method should really go in |
| 384 | // #NonAppWindowContainer.getOrientation() since it is trying to decide orientation based |
| 385 | // on non-app windows. But, we can not do that until the window list is always correct in |
| 386 | // terms of z-ordering based on layers. |
| 387 | if (mService.mDisplayFrozen) { |
| 388 | if (mService.mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 389 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 390 | "Display is frozen, return " + mService.mLastWindowForcedOrientation); |
| 391 | // If the display is frozen, some activities may be in the middle of restarting, and |
| 392 | // thus have removed their old window. If the window has the flag to hide the lock |
| 393 | // screen, then the lock screen can re-appear and inflict its own orientation on us. |
| 394 | // Keep the orientation stable until this all settles down. |
| 395 | return mService.mLastWindowForcedOrientation; |
| 396 | } else if (policy.isKeyguardLocked()) { |
| 397 | // Use the last orientation the while the display is frozen with the keyguard |
| 398 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 399 | // window. We don't want to check the show when locked window directly though as |
| 400 | // things aren't stable while the display is frozen, for example the window could be |
| 401 | // momentarily unavailable due to activity relaunch. |
| 402 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, " |
| 403 | + "return " + mService.mLastOrientation); |
| 404 | return mService.mLastOrientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 405 | } |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 406 | } else { |
| 407 | for (int pos = mWindows.size() - 1; pos >= 0; --pos) { |
| 408 | final WindowState win = mWindows.get(pos); |
| 409 | if (win.mAppToken != null) { |
| 410 | // We hit an application window. so the orientation will be determined by the |
| 411 | // app window. No point in continuing further. |
| 412 | break; |
| 413 | } |
| 414 | if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) { |
| 415 | continue; |
| 416 | } |
| 417 | int req = win.mAttrs.screenOrientation; |
| 418 | if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND) { |
| 419 | continue; |
| 420 | } |
| 421 | |
| 422 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req); |
| 423 | if (policy.isKeyguardHostWindow(win.mAttrs)) { |
| 424 | mService.mLastKeyguardForcedOrientation = req; |
| 425 | } |
| 426 | return (mService.mLastWindowForcedOrientation = req); |
| 427 | } |
| 428 | mService.mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 429 | |
| 430 | if (policy.isKeyguardLocked()) { |
| 431 | // The screen is locked and no top system window is requesting an orientation. |
| 432 | // Return either the orientation of the show-when-locked app (if there is any) or |
| 433 | // the orientation of the keyguard. No point in searching from the rest of apps. |
| 434 | WindowState winShowWhenLocked = (WindowState) policy.getWinShowWhenLockedLw(); |
| 435 | AppWindowToken appShowWhenLocked = winShowWhenLocked == null |
| 436 | ? null : winShowWhenLocked.mAppToken; |
| 437 | if (appShowWhenLocked != null) { |
| 438 | int req = appShowWhenLocked.getOrientation(); |
| 439 | if (req == SCREEN_ORIENTATION_BEHIND) { |
| 440 | req = mService.mLastKeyguardForcedOrientation; |
| 441 | } |
| 442 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Done at " + appShowWhenLocked |
| 443 | + " -- show when locked, return " + req); |
| 444 | return req; |
| 445 | } |
| 446 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 447 | "No one is requesting an orientation when the screen is locked"); |
| 448 | return mService.mLastKeyguardForcedOrientation; |
| 449 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 452 | // Top system windows are not requesting an orientation. Start searching from apps. |
| 453 | return mTaskStackContainers.getOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 456 | void updateDisplayInfo() { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 457 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 458 | mDisplay.getMetrics(mDisplayMetrics); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 459 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 460 | mTaskStackContainers.get(i).updateDisplayInfo(null); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 461 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 464 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 465 | final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal; |
| 466 | if (displayManagerInternal != null) { |
| 467 | // Bootstrap the default logical display from the display manager. |
| 468 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 469 | if (newDisplayInfo != null) { |
| 470 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 471 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 472 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 473 | |
Filip Gruszczynski | 608797e | 2015-11-12 19:08:20 -0800 | [diff] [blame] | 474 | mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 475 | mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 476 | mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
| 477 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 480 | void getLogicalDisplayRect(Rect out) { |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 481 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 482 | final int orientation = mDisplayInfo.rotation; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 483 | boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 484 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 485 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 486 | int width = mDisplayInfo.logicalWidth; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 487 | int left = (physWidth - width) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 488 | int height = mDisplayInfo.logicalHeight; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 489 | int top = (physHeight - height) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 490 | out.set(left, top, left + width, top + height); |
| 491 | } |
| 492 | |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 493 | private void getLogicalDisplayRect(Rect out, int orientation) { |
| 494 | getLogicalDisplayRect(out); |
| 495 | |
| 496 | // Rotate the Rect if needed. |
| 497 | final int currentRotation = mDisplayInfo.rotation; |
| 498 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 499 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 500 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 501 | mTmpRectF.set(out); |
| 502 | mTmpMatrix.mapRect(mTmpRectF); |
| 503 | mTmpRectF.round(out); |
| 504 | } |
| 505 | } |
| 506 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 507 | void getContentRect(Rect out) { |
| 508 | out.set(mContentRect); |
| 509 | } |
| 510 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 511 | /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */ |
| 512 | void attachStack(TaskStack stack, boolean onTop) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 513 | mTaskStackContainers.attachStack(stack, onTop); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 516 | void moveStack(TaskStack stack, boolean toTop) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 517 | mTaskStackContainers.moveStack(stack, toTop); |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 518 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 519 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 520 | @Override |
| 521 | protected void addChild(DisplayChildWindowContainer child, |
| 522 | Comparator<DisplayChildWindowContainer> comparator) { |
| 523 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 524 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 525 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 526 | @Override |
| 527 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 528 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 533 | // Only allow removal of direct children from this display if the display is in the process |
| 534 | // of been removed. |
| 535 | if (mRemovingDisplay) { |
| 536 | super.removeChild(child); |
| 537 | return; |
| 538 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 539 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /** |
| 543 | * Propagate the new bounds to all child stacks. |
| 544 | * @param contentRect The bounds to apply at the top level. |
| 545 | */ |
| 546 | void resize(Rect contentRect) { |
| 547 | mContentRect.set(contentRect); |
| 548 | } |
| 549 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 550 | int taskIdFromPoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 551 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 552 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 553 | final int taskId = stack.taskIdFromPoint(x, y); |
| 554 | if (taskId != -1) { |
| 555 | return taskId; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 558 | return -1; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 561 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 562 | * 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] | 563 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 564 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 565 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 566 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 567 | mTmpTaskForResizePointSearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 568 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 569 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 570 | if (!StackId.isTaskResizeAllowed(stack.mStackId)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 571 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 572 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 573 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 574 | stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult); |
| 575 | if (mTmpTaskForResizePointSearchResult.searchDone) { |
| 576 | return mTmpTaskForResizePointSearchResult.taskForResize; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 579 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 582 | void setTouchExcludeRegion(Task focusedTask) { |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 583 | mTouchExcludeRegion.set(mBaseDisplayRect); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 584 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 585 | mTmpRect2.setEmpty(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 586 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 587 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 588 | stack.setTouchExcludeRegion( |
| 589 | focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 590 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 591 | // If we removed the focused task above, add it back and only leave its |
| 592 | // outside touch area in the exclusion. TapDectector is not interested in |
| 593 | // any touch inside the focused task itself. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 594 | if (!mTmpRect2.isEmpty()) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 595 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 596 | } |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 597 | final WindowState inputMethod = mService.mInputMethodWindow; |
| 598 | if (inputMethod != null && inputMethod.isVisibleLw()) { |
| 599 | // If the input method is visible and the user is typing, we don't want these touch |
| 600 | // events to be intercepted and used to change focus. This would likely cause a |
| 601 | // disappearance of the input method. |
| 602 | inputMethod.getTouchableRegion(mTmpRegion); |
| 603 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 604 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 605 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
| 606 | WindowState win = mTapExcludedWindows.get(i); |
| 607 | win.getTouchableRegion(mTmpRegion); |
| 608 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 609 | } |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 610 | if (getDockedStackVisibleForUserLocked() != null) { |
| 611 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 612 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 613 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 614 | } |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 615 | if (mTapDetector != null) { |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 616 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 617 | } |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 620 | void switchUser() { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 621 | final WindowList windows = getWindowList(); |
| 622 | for (int i = 0; i < windows.size(); i++) { |
| 623 | final WindowState win = windows.get(i); |
| 624 | if (win.isHiddenFromUserLocked()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 625 | if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 626 | + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 627 | win.hideLw(false); |
| 628 | } |
| 629 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 630 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 631 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 632 | mTaskStackContainers.get(stackNdx).switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 633 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 634 | |
| 635 | rebuildAppWindowList(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 638 | void resetAnimationBackgroundAnimator() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 639 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 640 | mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| 644 | boolean animateDimLayers() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 645 | return mDimLayerController.animateDimLayers(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void resetDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 649 | mDimLayerController.resetDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | boolean isDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 653 | return mDimLayerController.isDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | void stopDimmingIfNeeded() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 657 | mDimLayerController.stopDimmingIfNeeded(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 660 | @Override |
| 661 | void removeIfPossible() { |
| 662 | if (isAnimating()) { |
| 663 | mDeferredRemoval = true; |
| 664 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 665 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 666 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 669 | @Override |
| 670 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 671 | mRemovingDisplay = true; |
| 672 | try { |
| 673 | super.removeImmediately(); |
| 674 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
| 675 | mDimLayerController.close(); |
| 676 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 677 | mService.unregisterPointerEventListener(mTapDetector); |
| 678 | mService.unregisterPointerEventListener(mService.mMousePositionTracker); |
| 679 | } |
| 680 | } finally { |
| 681 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 682 | } |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 683 | } |
| 684 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 685 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 686 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 687 | boolean checkCompleteDeferredRemoval() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 688 | final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval(); |
| 689 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 690 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 691 | removeImmediately(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 692 | mService.onDisplayRemoved(mDisplayId); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 693 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 694 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 695 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 696 | } |
| 697 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 698 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 699 | float dividerAnimationTarget) { |
| 700 | boolean updated = false; |
| 701 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 702 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 703 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 704 | if (stack == null || !stack.isAdjustedForIme()) { |
| 705 | continue; |
| 706 | } |
| 707 | |
| 708 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 709 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 710 | updated = true; |
| 711 | } else { |
| 712 | mDividerControllerLocked.mLastAnimationProgress = |
| 713 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 714 | mDividerControllerLocked.mLastDividerProgress = |
| 715 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 716 | updated |= stack.updateAdjustForIme( |
| 717 | mDividerControllerLocked.mLastAnimationProgress, |
| 718 | mDividerControllerLocked.mLastDividerProgress, |
| 719 | false /* force */); |
| 720 | } |
| 721 | if (interpolatedValue >= 1f) { |
| 722 | stack.endImeAdjustAnimation(); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | return updated; |
| 727 | } |
| 728 | |
| 729 | boolean clearImeAdjustAnimation() { |
| 730 | boolean changed = false; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 731 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 732 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 733 | if (stack != null && stack.isAdjustedForIme()) { |
| 734 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 735 | changed = true; |
| 736 | } |
| 737 | } |
| 738 | return changed; |
| 739 | } |
| 740 | |
| 741 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 742 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 743 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 744 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 745 | stack.beginImeAdjustAnimation(); |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | void adjustForImeIfNeeded() { |
| 751 | final WindowState imeWin = mService.mInputMethodWindow; |
| 752 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 753 | && !mDividerControllerLocked.isImeHideRequested(); |
| 754 | final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID); |
| 755 | final TaskStack imeTargetStack = mService.getImeFocusStackLocked(); |
| 756 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 757 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 758 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 759 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
| 760 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock(); |
| 761 | final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw(); |
| 762 | final boolean imeHeightChanged = imeVisible && |
| 763 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 764 | |
| 765 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 766 | // or both. There are three possible cases: |
| 767 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 768 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 769 | // - If IME is not visible, divider is not moved and is normal width. |
| 770 | |
| 771 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 772 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 773 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 774 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
| 775 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) { |
| 776 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 777 | } else { |
| 778 | stack.resetAdjustedForIme(false); |
| 779 | } |
| 780 | } |
| 781 | mDividerControllerLocked.setAdjustedForIme( |
| 782 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 783 | } else { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 784 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 785 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 786 | stack.resetAdjustedForIme(!dockVisible); |
| 787 | } |
| 788 | mDividerControllerLocked.setAdjustedForIme( |
| 789 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 790 | } |
| 791 | } |
| 792 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 793 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 794 | if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj); |
| 795 | mInputMethodAnimLayerAdjustment = adj; |
| 796 | final WindowState imw = mService.mInputMethodWindow; |
| 797 | if (imw != null) { |
| 798 | imw.adjustAnimLayer(adj); |
| 799 | } |
| 800 | for (int i = mService.mInputMethodDialogs.size() - 1; i >= 0; i--) { |
| 801 | final WindowState dialog = mService.mInputMethodDialogs.get(i); |
| 802 | // TODO: This and other places setting mAnimLayer can probably use WS.adjustAnimLayer, |
| 803 | // but need to make sure we are not setting things twice for child windows that are |
| 804 | // already in the list. |
| 805 | dialog.mWinAnimator.mAnimLayer = dialog.mLayer + adj; |
| 806 | if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw |
| 807 | + " anim layer: " + dialog.mWinAnimator.mAnimLayer); |
| 808 | } |
| 809 | } |
| 810 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 811 | /** |
| 812 | * If a window that has an animation specifying a colored background and the current wallpaper |
| 813 | * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to |
| 814 | * suddenly disappear. |
| 815 | */ |
| 816 | int getLayerForAnimationBackground(WindowStateAnimator winAnimator) { |
| 817 | for (int i = mWindows.size() - 1; i >= 0; --i) { |
| 818 | final WindowState win = mWindows.get(i); |
| 819 | if (win.mIsWallpaper && win.isVisibleNow()) { |
| 820 | return win.mWinAnimator.mAnimLayer; |
| 821 | } |
| 822 | } |
| 823 | return winAnimator.mAnimLayer; |
| 824 | } |
| 825 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 826 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 827 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 828 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 829 | stack.prepareFreezingTaskBounds(); |
| 830 | } |
| 831 | } |
| 832 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 833 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 834 | getLogicalDisplayRect(mTmpRect, newRotation); |
| 835 | |
| 836 | // Compute a transform matrix to undo the coordinate space transformation, |
| 837 | // and present the window at the same physical position it previously occupied. |
| 838 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
| 839 | createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix); |
| 840 | |
| 841 | mTmpRectF.set(bounds); |
| 842 | mTmpMatrix.mapRect(mTmpRectF); |
| 843 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 846 | static int deltaRotation(int oldRotation, int newRotation) { |
| 847 | int delta = newRotation - oldRotation; |
| 848 | if (delta < 0) delta += 4; |
| 849 | return delta; |
| 850 | } |
| 851 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 852 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 853 | Matrix outMatrix) { |
| 854 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 855 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 856 | displayHeight, outMatrix); |
| 857 | } |
| 858 | |
| 859 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 860 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 861 | switch (rotation) { |
| 862 | case ROTATION_0: |
| 863 | outMatrix.reset(); |
| 864 | break; |
| 865 | case ROTATION_270: |
| 866 | outMatrix.setRotate(270, 0, 0); |
| 867 | outMatrix.postTranslate(0, displayHeight); |
| 868 | outMatrix.postTranslate(rectTop, 0); |
| 869 | break; |
| 870 | case ROTATION_180: |
| 871 | outMatrix.reset(); |
| 872 | break; |
| 873 | case ROTATION_90: |
| 874 | outMatrix.setRotate(90, 0, 0); |
| 875 | outMatrix.postTranslate(displayWidth, 0); |
| 876 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 881 | public void dump(String prefix, PrintWriter pw) { |
| 882 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 883 | final String subPrefix = " " + prefix; |
| 884 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 885 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 886 | pw.print("dpi"); |
| 887 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 888 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 889 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 890 | pw.print(" base="); |
| 891 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 892 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 893 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 894 | if (mDisplayScalingDisabled) { |
| 895 | pw.println(" noscale"); |
| 896 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 897 | pw.print(" cur="); |
| 898 | pw.print(mDisplayInfo.logicalWidth); |
| 899 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 900 | pw.print(" app="); |
| 901 | pw.print(mDisplayInfo.appWidth); |
| 902 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 903 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 904 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 905 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 906 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 907 | pw.println(subPrefix + "deferred=" + mDeferredRemoval |
| 908 | + " mLayoutNeeded=" + mLayoutNeeded); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 909 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 910 | pw.println(); |
Craig Mautner | e8b85fd | 2014-10-22 09:23:25 -0700 | [diff] [blame] | 911 | pw.println(" Application tokens in top down Z order:"); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 912 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 913 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 914 | stack.dump(prefix + " ", pw); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 915 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 916 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 917 | pw.println(); |
| 918 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 919 | pw.println(); |
| 920 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 921 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 922 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 923 | pw.print(" Exiting #"); pw.print(i); |
| 924 | pw.print(' '); pw.print(token); |
| 925 | pw.println(':'); |
| 926 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 927 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 928 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 929 | pw.println(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 930 | mDimLayerController.dump(prefix + " ", pw); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 931 | pw.println(); |
| 932 | mDividerControllerLocked.dump(prefix + " ", pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 933 | |
| 934 | if (mInputMethodAnimLayerAdjustment != 0) { |
| 935 | pw.println(subPrefix |
| 936 | + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment); |
| 937 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 938 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 939 | |
| 940 | @Override |
| 941 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 942 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 946 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 947 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 948 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 949 | /** |
| 950 | * @return The docked stack, but only if it is visible, and {@code null} otherwise. |
| 951 | */ |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 952 | TaskStack getDockedStackLocked() { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 953 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 954 | return (stack != null && stack.isVisible()) ? stack : null; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 955 | } |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 956 | |
| 957 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 958 | * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not |
| 959 | * visible, as long as it's not hidden because the current user doesn't have any tasks there. |
| 960 | */ |
| 961 | TaskStack getDockedStackVisibleForUserLocked() { |
| 962 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 963 | return (stack != null && stack.isVisible(true /* ignoreKeyguard */)) ? stack : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 964 | } |
| 965 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 966 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 967 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
| 968 | WindowState touchedWin = null; |
| 969 | final int x = (int) xf; |
| 970 | final int y = (int) yf; |
| 971 | |
| 972 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 973 | WindowState window = mWindows.get(i); |
| 974 | final int flags = window.mAttrs.flags; |
| 975 | if (!window.isVisibleLw()) { |
| 976 | continue; |
| 977 | } |
| 978 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
| 979 | continue; |
| 980 | } |
| 981 | |
| 982 | window.getVisibleBounds(mTmpRect); |
| 983 | if (!mTmpRect.contains(x, y)) { |
| 984 | continue; |
| 985 | } |
| 986 | |
| 987 | window.getTouchableRegion(mTmpRegion); |
| 988 | |
| 989 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
| 990 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
| 991 | touchedWin = window; |
| 992 | break; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | return touchedWin; |
| 997 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 998 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 999 | boolean canAddToastWindowForUid(int uid) { |
| 1000 | // We allow one toast window per UID being shown at a time. |
| 1001 | WindowList windows = getWindowList(); |
| 1002 | final int windowCount = windows.size(); |
| 1003 | for (int i = 0; i < windowCount; i++) { |
| 1004 | WindowState window = windows.get(i); |
| 1005 | if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid |
Svet Ganov | 62a40f8 | 2016-09-29 00:43:51 -0700 | [diff] [blame] | 1006 | && !window.mPermanentlyHidden && !window.mAnimatingExit |
| 1007 | && !window.mRemoveOnExit) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1008 | return false; |
| 1009 | } |
| 1010 | } |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1014 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1015 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 1016 | return; |
| 1017 | } |
| 1018 | final int lostFocusUid = oldFocus.mOwnerUid; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1019 | final WindowList windows = getWindowList(); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1020 | final int windowCount = windows.size(); |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1021 | final Handler handler = mService.mH; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1022 | for (int i = 0; i < windowCount; i++) { |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1023 | final WindowState window = windows.get(i); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1024 | if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) { |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1025 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, window)) { |
| 1026 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, window), |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 1027 | window.mAttrs.hideTimeoutMilliseconds); |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1032 | |
| 1033 | WindowState findFocusedWindow() { |
| 1034 | final AppWindowToken focusedApp = mService.mFocusedApp; |
| 1035 | |
| 1036 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 1037 | final WindowState win = mWindows.get(i); |
| 1038 | |
| 1039 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win |
| 1040 | + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys()); |
| 1041 | |
| 1042 | if (!win.canReceiveKeys()) { |
| 1043 | continue; |
| 1044 | } |
| 1045 | |
| 1046 | final AppWindowToken wtoken = win.mAppToken; |
| 1047 | |
| 1048 | // If this window's application has been removed, just skip it. |
| 1049 | if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) { |
| 1050 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because " |
| 1051 | + (wtoken.removed ? "removed" : "sendingToBottom")); |
| 1052 | continue; |
| 1053 | } |
| 1054 | |
| 1055 | if (focusedApp == null) { |
| 1056 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null" |
| 1057 | + " using new focus @ " + i + " = " + win); |
| 1058 | return win; |
| 1059 | } |
| 1060 | |
| 1061 | if (!focusedApp.windowsAreFocusable()) { |
| 1062 | // Current focused app windows aren't focusable... |
| 1063 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not" |
| 1064 | + " focusable using new focus @ " + i + " = " + win); |
| 1065 | return win; |
| 1066 | } |
| 1067 | |
| 1068 | // Descend through all of the app tokens and find the first that either matches |
| 1069 | // win.mAppToken (return win) or mFocusedApp (return null). |
| 1070 | if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1071 | if (focusedApp.compareTo(wtoken) > 0) { |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1072 | // App stack below focused app stack. No focus for you!!! |
| 1073 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, |
| 1074 | "findFocusedWindow: Reached focused app=" + focusedApp); |
| 1075 | return null; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " |
| 1080 | + i + " = " + win); |
| 1081 | return win; |
| 1082 | } |
| 1083 | |
| 1084 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows."); |
| 1085 | return null; |
| 1086 | } |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1087 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 1088 | void addAppWindowToWindowList(final WindowState win) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1089 | final IWindow client = win.mClient; |
| 1090 | |
| 1091 | WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken); |
| 1092 | if (!tokenWindowList.isEmpty()) { |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 1093 | addAppWindowExisting(win, tokenWindowList); |
| 1094 | return; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | // No windows from this token on this display |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1098 | 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] | 1099 | + client.asBinder() + " (token=" + this + ")"); |
| 1100 | |
| 1101 | final WindowToken wToken = win.mToken; |
| 1102 | |
| 1103 | // 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] | 1104 | mTmpGetWindowOnDisplaySearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1105 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1106 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1107 | stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult); |
| 1108 | if (mTmpGetWindowOnDisplaySearchResult.reachedToken) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1109 | // We have reach the token we are interested in. End search. |
| 1110 | break; |
| 1111 | } |
| 1112 | } |
| 1113 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1114 | WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1115 | |
| 1116 | // We now know the index into the apps. If we found an app window above, that gives us the |
| 1117 | // position; else we need to look some more. |
| 1118 | if (pos != null) { |
| 1119 | // Move behind any windows attached to this one. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1120 | final WindowToken atoken = getWindowToken(pos.mClient.asBinder()); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1121 | if (atoken != null) { |
| 1122 | tokenWindowList = getTokenWindowsOnDisplay(atoken); |
| 1123 | final int NC = tokenWindowList.size(); |
| 1124 | if (NC > 0) { |
| 1125 | WindowState bottom = tokenWindowList.get(0); |
| 1126 | if (bottom.mSubLayer < 0) { |
| 1127 | pos = bottom; |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | addWindowToListBefore(win, pos); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 1132 | return; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | // 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] | 1136 | mTmpGetWindowOnDisplaySearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1137 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1138 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1139 | stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult); |
| 1140 | if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1141 | // We have found a window after the token. End search. |
| 1142 | break; |
| 1143 | } |
| 1144 | } |
| 1145 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1146 | pos = mTmpGetWindowOnDisplaySearchResult.foundWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1147 | |
| 1148 | if (pos != null) { |
| 1149 | // Move in front of any windows attached to this one. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1150 | final WindowToken atoken = getWindowToken(pos.mClient.asBinder()); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1151 | if (atoken != null) { |
| 1152 | final WindowState top = atoken.getTopWindow(); |
| 1153 | if (top != null && top.mSubLayer >= 0) { |
| 1154 | pos = top; |
| 1155 | } |
| 1156 | } |
| 1157 | addWindowToListAfter(win, pos); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 1158 | return; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | // Just search for the start of this layer. |
| 1162 | final int myLayer = win.mBaseLayer; |
| 1163 | int i; |
| 1164 | for (i = mWindows.size() - 1; i >= 0; --i) { |
| 1165 | final WindowState w = mWindows.get(i); |
| 1166 | // Dock divider shares the base layer with application windows, but we want to always |
| 1167 | // keep it above the application windows. The sharing of the base layer is intended |
| 1168 | // for window animations, which need to be above the dock divider for the duration |
| 1169 | // of the animation. |
| 1170 | if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) { |
| 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1175 | "Based on layer: Adding window " + win + " at " + (i + 1) + " of " |
| 1176 | + mWindows.size()); |
| 1177 | mWindows.add(i + 1, win); |
| 1178 | mService.mWindowsChanged = true; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | /** Adds this non-app window to the window list. */ |
| 1182 | void addNonAppWindowToWindowList(WindowState win) { |
| 1183 | // Figure out where window should go, based on layer. |
| 1184 | int i; |
| 1185 | for (i = mWindows.size() - 1; i >= 0; i--) { |
| 1186 | final WindowState otherWin = mWindows.get(i); |
| 1187 | if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) { |
| 1188 | // Wallpaper wanders through the window list, for example to position itself |
| 1189 | // directly behind keyguard. Because of this it will break the ordering based on |
| 1190 | // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and |
| 1191 | // we don't want the new window to appear above them. An example of this is adding |
| 1192 | // of the docked stack divider. Consider a scenario with the following ordering (top |
| 1193 | // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider |
| 1194 | // to land below the assist preview, so the dock divider must ignore the wallpaper, |
| 1195 | // with which it shares the base layer. |
| 1196 | break; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | i++; |
| 1201 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1202 | "Free window: Adding window " + this + " at " + i + " of " + mWindows.size()); |
| 1203 | mWindows.add(i, win); |
| 1204 | mService.mWindowsChanged = true; |
| 1205 | } |
| 1206 | |
Wale Ogunwale | b9a07c3 | 2016-10-12 14:55:56 -0700 | [diff] [blame] | 1207 | void addToWindowList(WindowState win, int index) { |
| 1208 | mWindows.add(index, win); |
| 1209 | } |
| 1210 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1211 | boolean removeFromWindowList(WindowState win) { |
| 1212 | return mWindows.remove(win); |
| 1213 | } |
| 1214 | |
| 1215 | private int removeWindowAndChildrenFromWindowList(WindowState win, int interestingPos) { |
| 1216 | final WindowList windows = getWindowList(); |
| 1217 | int wpos = windows.indexOf(win); |
| 1218 | if (wpos < 0) { |
| 1219 | return interestingPos; |
| 1220 | } |
| 1221 | |
| 1222 | if (wpos < interestingPos) interestingPos--; |
| 1223 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this); |
| 1224 | windows.remove(wpos); |
| 1225 | mService.mWindowsChanged = true; |
| 1226 | int childWinCount = win.mChildren.size(); |
| 1227 | while (childWinCount > 0) { |
| 1228 | childWinCount--; |
| 1229 | final WindowState cw = win.mChildren.get(childWinCount); |
| 1230 | int cpos = windows.indexOf(cw); |
| 1231 | if (cpos >= 0) { |
| 1232 | if (cpos < interestingPos) interestingPos--; |
| 1233 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, |
| 1234 | "Temp removing child at " + cpos + ": " + cw); |
| 1235 | windows.remove(cpos); |
| 1236 | } |
| 1237 | } |
| 1238 | return interestingPos; |
| 1239 | } |
| 1240 | |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1241 | void addChildWindowToWindowList(WindowState win) { |
| 1242 | final WindowState parentWindow = win.getParentWindow(); |
| 1243 | |
| 1244 | WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken); |
| 1245 | |
| 1246 | // Figure out this window's ordering relative to the parent window. |
| 1247 | final int wCount = windowsOnSameDisplay.size(); |
| 1248 | final int sublayer = win.mSubLayer; |
| 1249 | int largestSublayer = Integer.MIN_VALUE; |
| 1250 | WindowState windowWithLargestSublayer = null; |
| 1251 | int i; |
| 1252 | for (i = 0; i < wCount; i++) { |
| 1253 | WindowState w = windowsOnSameDisplay.get(i); |
| 1254 | final int wSublayer = w.mSubLayer; |
| 1255 | if (wSublayer >= largestSublayer) { |
| 1256 | largestSublayer = wSublayer; |
| 1257 | windowWithLargestSublayer = w; |
| 1258 | } |
| 1259 | if (sublayer < 0) { |
| 1260 | // For negative sublayers, we go below all windows in the same sublayer. |
| 1261 | if (wSublayer >= sublayer) { |
| 1262 | addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w); |
| 1263 | break; |
| 1264 | } |
| 1265 | } else { |
| 1266 | // For positive sublayers, we go above all windows in the same sublayer. |
| 1267 | if (wSublayer > sublayer) { |
| 1268 | addWindowToListBefore(win, w); |
| 1269 | break; |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | if (i >= wCount) { |
| 1274 | if (sublayer < 0) { |
| 1275 | addWindowToListBefore(win, parentWindow); |
| 1276 | } else { |
| 1277 | addWindowToListAfter(win, |
| 1278 | largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow); |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 1283 | /** Updates the layer assignment of windows on this display. */ |
| 1284 | void assignWindowLayers(boolean setLayoutNeeded) { |
| 1285 | mLayersController.assignWindowLayers(mWindows); |
| 1286 | if (setLayoutNeeded) { |
| 1287 | setLayoutNeeded(); |
| 1288 | } |
| 1289 | } |
| 1290 | |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 1291 | void adjustWallpaperWindows() { |
| 1292 | if (mWallpaperController.adjustWallpaperWindows(mWindows)) { |
| 1293 | assignWindowLayers(true /*setLayoutNeeded*/); |
| 1294 | } |
| 1295 | } |
| 1296 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1297 | /** |
| 1298 | * Z-orders the display window list so that: |
| 1299 | * <ul> |
| 1300 | * <li>Any windows that are currently below the wallpaper window stay below the wallpaper |
| 1301 | * window. |
| 1302 | * <li>Exiting application windows are at the bottom, but above the wallpaper window. |
| 1303 | * <li>All other application windows are above the exiting application windows and ordered based |
| 1304 | * on the ordering of their stacks and tasks on the display. |
| 1305 | * <li>Non-application windows are at the very top. |
| 1306 | * </ul> |
| 1307 | * <p> |
| 1308 | * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window |
| 1309 | * surface layering is done in {@link WindowLayersController}. |
| 1310 | */ |
| 1311 | void rebuildAppWindowList() { |
| 1312 | int count = mWindows.size(); |
| 1313 | int i; |
| 1314 | int lastBelow = -1; |
| 1315 | int numRemoved = 0; |
| 1316 | |
| 1317 | if (mRebuildTmp.length < count) { |
| 1318 | mRebuildTmp = new WindowState[count + 10]; |
| 1319 | } |
| 1320 | |
| 1321 | // First remove all existing app windows. |
| 1322 | i = 0; |
| 1323 | while (i < count) { |
| 1324 | final WindowState w = mWindows.get(i); |
| 1325 | if (w.mAppToken != null) { |
| 1326 | final WindowState win = mWindows.remove(i); |
| 1327 | win.mRebuilding = true; |
| 1328 | mRebuildTmp[numRemoved] = win; |
| 1329 | mService.mWindowsChanged = true; |
| 1330 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win); |
| 1331 | count--; |
| 1332 | numRemoved++; |
| 1333 | continue; |
| 1334 | } else if (lastBelow == i-1) { |
| 1335 | if (w.mAttrs.type == TYPE_WALLPAPER) { |
| 1336 | lastBelow = i; |
| 1337 | } |
| 1338 | } |
| 1339 | i++; |
| 1340 | } |
| 1341 | |
| 1342 | // Keep whatever windows were below the app windows still below, by skipping them. |
| 1343 | lastBelow++; |
| 1344 | i = lastBelow; |
| 1345 | |
| 1346 | // First add all of the exiting app tokens... these are no longer in the main app list, |
| 1347 | // but still have windows shown. We put them in the back because now that the animation is |
| 1348 | // over we no longer will care about them. |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1349 | final int numStacks = mTaskStackContainers.size(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1350 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1351 | AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1352 | int NT = exitingAppTokens.size(); |
| 1353 | for (int j = 0; j < NT; j++) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1354 | i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | // And add in the still active app tokens in Z order. |
| 1359 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1360 | i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | i -= lastBelow; |
| 1364 | if (i != numRemoved) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1365 | setLayoutNeeded(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1366 | Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved |
| 1367 | + " windows but added " + i + " rebuildAppWindowListLocked() " |
| 1368 | + " callers=" + Debug.getCallers(10)); |
| 1369 | for (i = 0; i < numRemoved; i++) { |
| 1370 | WindowState ws = mRebuildTmp[i]; |
| 1371 | if (ws.mRebuilding) { |
| 1372 | StringWriter sw = new StringWriter(); |
| 1373 | PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 1374 | ws.dump(pw, "", true); |
| 1375 | pw.flush(); |
| 1376 | Slog.w(TAG_WM, "This window was lost: " + ws); |
| 1377 | Slog.w(TAG_WM, sw.toString()); |
| 1378 | ws.mWinAnimator.destroySurfaceLocked(); |
| 1379 | } |
| 1380 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1381 | Slog.w(TAG_WM, "Current window hierarchy:"); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1382 | dumpChildrenNames(); |
| 1383 | Slog.w(TAG_WM, "Final window list:"); |
| 1384 | dumpWindows(); |
| 1385 | } |
| 1386 | Arrays.fill(mRebuildTmp, null); |
| 1387 | } |
| 1388 | |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1389 | /** Return the list of Windows on this display associated with the input token. */ |
| 1390 | WindowList getTokenWindowsOnDisplay(WindowToken token) { |
| 1391 | final WindowList windowList = new WindowList(); |
| 1392 | final int count = mWindows.size(); |
| 1393 | for (int i = 0; i < count; i++) { |
| 1394 | final WindowState win = mWindows.get(i); |
| 1395 | if (win.mToken == token) { |
| 1396 | windowList.add(win); |
| 1397 | } |
| 1398 | } |
| 1399 | return windowList; |
| 1400 | } |
| 1401 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1402 | private void reAddToWindowList(WindowState win) { |
| 1403 | win.mToken.addWindow(win); |
| 1404 | // This is a hack to get all of the child windows added as well at the right position. Child |
| 1405 | // windows should be rare and this case should be rare, so it shouldn't be that big a deal. |
| 1406 | int wpos = mWindows.indexOf(win); |
| 1407 | if (wpos >= 0) { |
| 1408 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win); |
| 1409 | mWindows.remove(wpos); |
| 1410 | mService.mWindowsChanged = true; |
| 1411 | win.reAddWindow(wpos); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | void moveInputMethodDialogs(int pos) { |
| 1416 | ArrayList<WindowState> dialogs = mService.mInputMethodDialogs; |
| 1417 | |
| 1418 | final int N = dialogs.size(); |
| 1419 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Removing " + N + " dialogs w/pos=" + pos); |
| 1420 | for (int i = 0; i < N; i++) { |
| 1421 | pos = removeWindowAndChildrenFromWindowList(dialogs.get(i), pos); |
| 1422 | } |
| 1423 | if (DEBUG_INPUT_METHOD) { |
| 1424 | Slog.v(TAG_WM, "Window list w/pos=" + pos); |
| 1425 | logWindowList(mWindows, " "); |
| 1426 | } |
| 1427 | |
| 1428 | WindowState ime = mService.mInputMethodWindow; |
| 1429 | if (pos >= 0) { |
| 1430 | // Skip windows owned by the input method. |
| 1431 | if (ime != null) { |
| 1432 | while (pos < mWindows.size()) { |
| 1433 | WindowState wp = mWindows.get(pos); |
| 1434 | if (wp == ime || wp.getParentWindow() == ime) { |
| 1435 | pos++; |
| 1436 | continue; |
| 1437 | } |
| 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Adding " + N + " dialogs at pos=" + pos); |
| 1442 | for (int i=0; i<N; i++) { |
| 1443 | WindowState win = dialogs.get(i); |
| 1444 | pos = win.reAddWindow(pos); |
| 1445 | } |
| 1446 | if (DEBUG_INPUT_METHOD) { |
| 1447 | Slog.v(TAG_WM, "Final window list:"); |
| 1448 | logWindowList(mWindows, " "); |
| 1449 | } |
| 1450 | return; |
| 1451 | } |
| 1452 | for (int i=0; i<N; i++) { |
| 1453 | WindowState win = dialogs.get(i); |
| 1454 | reAddToWindowList(win); |
| 1455 | if (DEBUG_INPUT_METHOD) { |
| 1456 | Slog.v(TAG_WM, "No IM target, final list:"); |
| 1457 | logWindowList(mWindows, " "); |
| 1458 | } |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | boolean moveInputMethodWindowsIfNeeded(boolean needAssignLayers) { |
| 1463 | final WindowState imWin = mService.mInputMethodWindow; |
| 1464 | final int DN = mService.mInputMethodDialogs.size(); |
| 1465 | if (imWin == null && DN == 0) { |
| 1466 | return false; |
| 1467 | } |
| 1468 | |
| 1469 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 1470 | WindowList windows = mWindows; |
| 1471 | |
| 1472 | int imPos = findDesiredInputMethodWindowIndex(true); |
| 1473 | if (imPos >= 0) { |
| 1474 | // In this case, the input method windows are to be placed |
| 1475 | // immediately above the window they are targeting. |
| 1476 | |
| 1477 | // First check to see if the input method windows are already |
| 1478 | // located here, and contiguous. |
| 1479 | final int N = windows.size(); |
| 1480 | final WindowState firstImWin = imPos < N ? windows.get(imPos) : null; |
| 1481 | |
| 1482 | // Figure out the actual input method window that should be |
| 1483 | // at the bottom of their stack. |
| 1484 | WindowState baseImWin = imWin != null ? imWin : mService.mInputMethodDialogs.get(0); |
| 1485 | final WindowState cw = baseImWin.getBottomChild(); |
| 1486 | if (cw != null && cw.mSubLayer < 0) { |
| 1487 | baseImWin = cw; |
| 1488 | } |
| 1489 | |
| 1490 | if (firstImWin == baseImWin) { |
| 1491 | // The windows haven't moved... but are they still contiguous? |
| 1492 | // First find the top IM window. |
| 1493 | int pos = imPos+1; |
| 1494 | while (pos < N) { |
| 1495 | if (!(windows.get(pos)).mIsImWindow) { |
| 1496 | break; |
| 1497 | } |
| 1498 | pos++; |
| 1499 | } |
| 1500 | pos++; |
| 1501 | // Now there should be no more input method windows above. |
| 1502 | while (pos < N) { |
| 1503 | if ((windows.get(pos)).mIsImWindow) { |
| 1504 | break; |
| 1505 | } |
| 1506 | pos++; |
| 1507 | } |
| 1508 | if (pos >= N) { |
| 1509 | return false; |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | if (imWin != null) { |
| 1514 | if (DEBUG_INPUT_METHOD) { |
| 1515 | Slog.v(TAG_WM, "Moving IM from " + imPos); |
| 1516 | logWindowList(windows, " "); |
| 1517 | } |
| 1518 | imPos = removeWindowAndChildrenFromWindowList(imWin, imPos); |
| 1519 | if (DEBUG_INPUT_METHOD) { |
| 1520 | Slog.v(TAG_WM, "List after removing with new pos " + imPos + ":"); |
| 1521 | logWindowList(windows, " "); |
| 1522 | } |
| 1523 | imWin.reAddWindow(imPos); |
| 1524 | if (DEBUG_INPUT_METHOD) { |
| 1525 | Slog.v(TAG_WM, "List after moving IM to " + imPos + ":"); |
| 1526 | logWindowList(windows, " "); |
| 1527 | } |
| 1528 | if (DN > 0) moveInputMethodDialogs(imPos+1); |
| 1529 | } else { |
| 1530 | moveInputMethodDialogs(imPos); |
| 1531 | } |
| 1532 | |
| 1533 | } else { |
| 1534 | // In this case, the input method windows go in a fixed layer, |
| 1535 | // because they aren't currently associated with a focus window. |
| 1536 | |
| 1537 | if (imWin != null) { |
| 1538 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Moving IM from " + imPos); |
| 1539 | removeWindowAndChildrenFromWindowList(imWin, 0); |
| 1540 | reAddToWindowList(imWin); |
| 1541 | if (DEBUG_INPUT_METHOD) { |
| 1542 | Slog.v(TAG_WM, "List with no IM target:"); |
| 1543 | logWindowList(windows, " "); |
| 1544 | } |
| 1545 | if (DN > 0) moveInputMethodDialogs(-1); |
| 1546 | } else { |
| 1547 | moveInputMethodDialogs(-1); |
| 1548 | } |
| 1549 | |
| 1550 | } |
| 1551 | |
| 1552 | if (needAssignLayers) { |
| 1553 | assignWindowLayers(false /* setLayoutNeeded */); |
| 1554 | } |
| 1555 | |
| 1556 | return true; |
| 1557 | } |
| 1558 | |
| 1559 | /** |
| 1560 | * Dig through the WindowStates and find the one that the Input Method will target. |
| 1561 | * @param willMove |
| 1562 | * @return The index+1 in mWindows of the discovered target. |
| 1563 | */ |
| 1564 | int findDesiredInputMethodWindowIndex(boolean willMove) { |
| 1565 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 1566 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 1567 | // IME/target. For now only look for input windows on the main screen. |
| 1568 | final WindowList windows = getWindowList(); |
| 1569 | WindowState w = null; |
| 1570 | int i; |
| 1571 | for (i = windows.size() - 1; i >= 0; --i) { |
| 1572 | WindowState win = windows.get(i); |
| 1573 | |
| 1574 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG_WM, "Checking window @" + i |
| 1575 | + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags)); |
| 1576 | if (canBeImeTarget(win)) { |
| 1577 | w = win; |
| 1578 | //Slog.i(TAG_WM, "Putting input method here!"); |
| 1579 | |
| 1580 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 1581 | // to be on top of it, but it is not -really- where input will go. So if the caller |
| 1582 | // is not actually looking to move the IME, look down below for a real window to |
| 1583 | // target... |
| 1584 | if (!willMove && w.mAttrs.type == TYPE_APPLICATION_STARTING && i > 0) { |
| 1585 | WindowState wb = windows.get(i-1); |
| 1586 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1587 | i--; |
| 1588 | w = wb; |
| 1589 | } |
| 1590 | } |
| 1591 | break; |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | // Now w is either mWindows[0] or an IME (or null if mWindows is empty). |
| 1596 | |
| 1597 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG_WM, "Proposed new IME target: " + w); |
| 1598 | |
| 1599 | // Now, a special case -- if the last target's window is in the process of exiting, and is |
| 1600 | // above the new target, keep on the last target to avoid flicker. Consider for example a |
| 1601 | // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it |
| 1602 | // until it is completely gone so it doesn't drop behind the dialog or its full-screen |
| 1603 | // scrim. |
| 1604 | final WindowState curTarget = mService.mInputMethodTarget; |
| 1605 | if (curTarget != null |
| 1606 | && curTarget.isDisplayedLw() |
| 1607 | && curTarget.isClosing() |
| 1608 | && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) { |
| 1609 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing"); |
| 1610 | return windows.indexOf(curTarget) + 1; |
| 1611 | } |
| 1612 | |
| 1613 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" |
| 1614 | + w + " willMove=" + willMove); |
| 1615 | |
| 1616 | if (willMove && w != null) { |
| 1617 | AppWindowToken token = curTarget == null ? null : curTarget.mAppToken; |
| 1618 | if (token != null) { |
| 1619 | |
| 1620 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 1621 | // to look at all windows below the current target that are in this app, finding the |
| 1622 | // highest visible one in layering. |
| 1623 | WindowState highestTarget = null; |
| 1624 | int highestPos = 0; |
| 1625 | if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) { |
| 1626 | WindowList curWindows = token.getDisplayContent().getWindowList(); |
| 1627 | int pos = curWindows.indexOf(curTarget); |
| 1628 | while (pos >= 0) { |
| 1629 | WindowState win = curWindows.get(pos); |
| 1630 | if (win.mAppToken != token) { |
| 1631 | break; |
| 1632 | } |
| 1633 | if (!win.mRemoved) { |
| 1634 | if (highestTarget == null || win.mWinAnimator.mAnimLayer > |
| 1635 | highestTarget.mWinAnimator.mAnimLayer) { |
| 1636 | highestTarget = win; |
| 1637 | highestPos = pos; |
| 1638 | } |
| 1639 | } |
| 1640 | pos--; |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | if (highestTarget != null) { |
| 1645 | final AppTransition appTransition = mService.mAppTransition; |
| 1646 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget |
| 1647 | + " animating=" + highestTarget.mWinAnimator.isAnimationSet() |
| 1648 | + " layer=" + highestTarget.mWinAnimator.mAnimLayer |
| 1649 | + " new layer=" + w.mWinAnimator.mAnimLayer); |
| 1650 | |
| 1651 | if (appTransition.isTransitionSet()) { |
| 1652 | // If we are currently setting up for an animation, hold everything until we |
| 1653 | // can find out what will happen. |
| 1654 | mService.mInputMethodTargetWaitingAnim = true; |
| 1655 | mService.mInputMethodTarget = highestTarget; |
| 1656 | return highestPos + 1; |
| 1657 | } else if (highestTarget.mWinAnimator.isAnimationSet() && |
| 1658 | highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) { |
| 1659 | // If the window we are currently targeting is involved with an animation, |
| 1660 | // and it is on top of the next target we will be over, then hold off on |
| 1661 | // moving until that is done. |
| 1662 | mService.mInputMethodTargetWaitingAnim = true; |
| 1663 | mService.mInputMethodTarget = highestTarget; |
| 1664 | return highestPos + 1; |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | //Slog.i(TAG_WM, "Placing input method @" + (i+1)); |
| 1671 | if (w != null) { |
| 1672 | if (willMove) { |
| 1673 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 1674 | + w + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
| 1675 | mService.mInputMethodTarget = w; |
| 1676 | mService.mInputMethodTargetWaitingAnim = false; |
| 1677 | if (w.mAppToken != null) { |
| 1678 | setInputMethodAnimLayerAdjustment( |
| 1679 | w.mAppToken.mAppAnimator.animLayerAdjustment); |
| 1680 | } else { |
| 1681 | setInputMethodAnimLayerAdjustment(0); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | // If the docked divider is visible, we still need to go through this whole excercise to |
| 1686 | // find the appropriate input method target (used for animations and dialog |
| 1687 | // adjustments), but for purposes of Z ordering we simply wish to place it above the |
| 1688 | // docked divider. Unless it is already above the divider. |
| 1689 | final WindowState dockedDivider = mDividerControllerLocked.getWindow(); |
| 1690 | if (dockedDivider != null && dockedDivider.isVisibleLw()) { |
| 1691 | int dividerIndex = windows.indexOf(dockedDivider); |
| 1692 | if (dividerIndex > 0 && dividerIndex > i) { |
| 1693 | return dividerIndex + 1; |
| 1694 | } |
| 1695 | } |
| 1696 | return i+1; |
| 1697 | } |
| 1698 | if (willMove) { |
| 1699 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 1700 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
| 1701 | mService.mInputMethodTarget = null; |
| 1702 | setInputMethodAnimLayerAdjustment(0); |
| 1703 | } |
| 1704 | return -1; |
| 1705 | } |
| 1706 | |
| 1707 | private static boolean canBeImeTarget(WindowState w) { |
| 1708 | final int fl = w.mAttrs.flags & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1709 | final int type = w.mAttrs.type; |
| 1710 | |
| 1711 | if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM) |
| 1712 | && type != TYPE_APPLICATION_STARTING) { |
| 1713 | return false; |
| 1714 | } |
| 1715 | |
| 1716 | if (DEBUG_INPUT_METHOD) { |
| 1717 | Slog.i(TAG_WM, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1718 | if (!w.isVisibleOrAdding()) { |
| 1719 | Slog.i(TAG_WM, " mSurfaceController=" + w.mWinAnimator.mSurfaceController |
| 1720 | + " relayoutCalled=" + w.mRelayoutCalled |
| 1721 | + " viewVis=" + w.mViewVisibility |
| 1722 | + " policyVis=" + w.mPolicyVisibility |
| 1723 | + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim |
| 1724 | + " parentHidden=" + w.isParentWindowHidden() |
| 1725 | + " exiting=" + w.mAnimatingExit + " destroying=" + w.mDestroying); |
| 1726 | if (w.mAppToken != null) { |
| 1727 | Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | return w.isVisibleOrAdding(); |
| 1732 | } |
| 1733 | |
| 1734 | private void logWindowList(final WindowList windows, String prefix) { |
| 1735 | int N = windows.size(); |
| 1736 | while (N > 0) { |
| 1737 | N--; |
| 1738 | Slog.v(TAG_WM, prefix + "#" + N + ": " + windows.get(N)); |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | boolean getNeedsMenu(WindowState win, WindowManagerPolicy.WindowState bottom) { |
| 1743 | int index = -1; |
| 1744 | WindowList windows = getWindowList(); |
| 1745 | while (true) { |
| 1746 | if (win.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 1747 | return win.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
| 1748 | } |
| 1749 | // If we reached the bottom of the range of windows we are considering, |
| 1750 | // assume no menu is needed. |
| 1751 | if (win == bottom) { |
| 1752 | return false; |
| 1753 | } |
| 1754 | // The current window hasn't specified whether menu key is needed; look behind it. |
| 1755 | // First, we may need to determine the starting position. |
| 1756 | if (index < 0) { |
| 1757 | index = windows.indexOf(win); |
| 1758 | } |
| 1759 | index--; |
| 1760 | if (index < 0) { |
| 1761 | return false; |
| 1762 | } |
| 1763 | win = windows.get(index); |
| 1764 | } |
| 1765 | } |
| 1766 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1767 | void setLayoutNeeded() { |
| 1768 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 1769 | mLayoutNeeded = true; |
| 1770 | } |
| 1771 | |
| 1772 | void clearLayoutNeeded() { |
| 1773 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 1774 | mLayoutNeeded = false; |
| 1775 | } |
| 1776 | |
| 1777 | boolean isLayoutNeeded() { |
| 1778 | return mLayoutNeeded; |
| 1779 | } |
| 1780 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 1781 | private void addAppWindowExisting(WindowState win, WindowList tokenWindowList) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1782 | |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1783 | // If this application has existing windows, we simply place the new window on top of |
| 1784 | // them... but keep the starting window on top. |
| 1785 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1786 | // Base windows go behind everything else. |
| 1787 | final WindowState lowestWindow = tokenWindowList.get(0); |
| 1788 | addWindowToListBefore(win, lowestWindow); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1789 | } else { |
| 1790 | final AppWindowToken atoken = win.mAppToken; |
| 1791 | final int windowListPos = tokenWindowList.size(); |
| 1792 | final WindowState lastWindow = tokenWindowList.get(windowListPos - 1); |
| 1793 | if (atoken != null && lastWindow == atoken.startingWindow) { |
| 1794 | addWindowToListBefore(win, lastWindow); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1795 | } else { |
| 1796 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1797 | // There is a window above this one associated with the same apptoken note that the |
| 1798 | // window could be a floating window that was created later or a window at the top |
| 1799 | // of the list of windows associated with this token. |
| 1800 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1801 | "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of " |
| 1802 | + mWindows.size()); |
| 1803 | mWindows.add(newIdx + 1, win); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1804 | mService.mWindowsChanged = true; |
| 1805 | } |
| 1806 | } |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | /** Places the first input window after the second input window in the window list. */ |
| 1810 | private void addWindowToListAfter(WindowState first, WindowState second) { |
| 1811 | final int i = mWindows.indexOf(second); |
| 1812 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1813 | "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size() |
| 1814 | + " (after " + second + ")"); |
| 1815 | mWindows.add(i + 1, first); |
| 1816 | mService.mWindowsChanged = true; |
| 1817 | } |
| 1818 | |
| 1819 | /** Places the first input window before the second input window in the window list. */ |
| 1820 | private void addWindowToListBefore(WindowState first, WindowState second) { |
| 1821 | int i = mWindows.indexOf(second); |
| 1822 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1823 | "Adding window " + this + " at " + i + " of " + mWindows.size() |
| 1824 | + " (before " + second + ")"); |
| 1825 | if (i < 0) { |
| 1826 | Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows); |
| 1827 | i = 0; |
| 1828 | } |
| 1829 | mWindows.add(i, first); |
| 1830 | mService.mWindowsChanged = true; |
| 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * This method finds out the index of a window that has the same app token as win. used for z |
| 1835 | * ordering the windows in mWindows |
| 1836 | */ |
| 1837 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1838 | for(int j = mWindows.size() - 1; j >= 0; j--) { |
| 1839 | final WindowState wentry = mWindows.get(j); |
| 1840 | if(wentry.mAppToken == win.mAppToken) { |
| 1841 | return j; |
| 1842 | } |
| 1843 | } |
| 1844 | return -1; |
| 1845 | } |
| 1846 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1847 | private void dumpChildrenNames() { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1848 | StringBuilder output = new StringBuilder(); |
| 1849 | dumpChildrenNames(output, " "); |
| 1850 | Slog.v(TAG_WM, output.toString()); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1853 | private void dumpWindows() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1854 | Slog.v(TAG_WM, " Display #" + mDisplayId); |
| 1855 | final WindowList windows = getWindowList(); |
| 1856 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 1857 | Slog.v(TAG_WM, " #" + winNdx + ": " + windows.get(winNdx)); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1858 | } |
| 1859 | } |
| 1860 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1861 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 1862 | if (mTokenMap.isEmpty()) { |
| 1863 | return; |
| 1864 | } |
| 1865 | pw.println(" Display #" + mDisplayId); |
| 1866 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 1867 | while (it.hasNext()) { |
| 1868 | final WindowToken token = it.next(); |
| 1869 | pw.print(" "); |
| 1870 | pw.print(token); |
| 1871 | if (dumpAll) { |
| 1872 | pw.println(':'); |
| 1873 | token.dump(pw, " "); |
| 1874 | } else { |
| 1875 | pw.println(); |
| 1876 | } |
| 1877 | } |
| 1878 | } |
| 1879 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1880 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
| 1881 | final int count = mWindows.size(); |
| 1882 | for (int j = 0; j < count; j++) { |
| 1883 | final WindowStateAnimator wAnim = mWindows.get(j).mWinAnimator; |
| 1884 | pw.println(subPrefix + "Window #" + j + ": " + wAnim); |
| 1885 | } |
| 1886 | } |
| 1887 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1888 | void enableSurfaceTrace(FileDescriptor fd) { |
| 1889 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 1890 | final WindowState win = mWindows.get(i); |
| 1891 | win.mWinAnimator.enableSurfaceTrace(fd); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | void disableSurfaceTrace() { |
| 1896 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 1897 | final WindowState win = mWindows.get(i); |
| 1898 | win.mWinAnimator.disableSurfaceTrace(); |
| 1899 | } |
| 1900 | } |
| 1901 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 1902 | boolean checkWaitingForWindows() { |
| 1903 | |
| 1904 | boolean haveBootMsg = false; |
| 1905 | boolean haveApp = false; |
| 1906 | // if the wallpaper service is disabled on the device, we're never going to have |
| 1907 | // wallpaper, don't bother waiting for it |
| 1908 | boolean haveWallpaper = false; |
| 1909 | boolean wallpaperEnabled = mService.mContext.getResources().getBoolean( |
| 1910 | com.android.internal.R.bool.config_enableWallpaperService) |
| 1911 | && !mService.mOnlyCore; |
| 1912 | boolean haveKeyguard = true; |
| 1913 | final int count = mWindows.size(); |
| 1914 | for (int i = 0; i < count; i++) { |
| 1915 | final WindowState w = mWindows.get(i); |
| 1916 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| 1917 | return true; |
| 1918 | } |
| 1919 | if (w.isDrawnLw()) { |
| 1920 | if (w.mAttrs.type == TYPE_BOOT_PROGRESS) { |
| 1921 | haveBootMsg = true; |
| 1922 | } else if (w.mAttrs.type == TYPE_APPLICATION |
| 1923 | || w.mAttrs.type == TYPE_DRAWN_APPLICATION) { |
| 1924 | haveApp = true; |
| 1925 | } else if (w.mAttrs.type == TYPE_WALLPAPER) { |
| 1926 | haveWallpaper = true; |
| 1927 | } else if (w.mAttrs.type == TYPE_STATUS_BAR) { |
| 1928 | haveKeyguard = mService.mPolicy.isKeyguardDrawnLw(); |
| 1929 | } |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM, |
| 1934 | "******** booted=" + mService.mSystemBooted |
| 1935 | + " msg=" + mService.mShowingBootMessages |
| 1936 | + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp |
| 1937 | + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled |
| 1938 | + " haveKeyguard=" + haveKeyguard); |
| 1939 | |
| 1940 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 1941 | // message is actually displayed. |
| 1942 | if (!mService.mSystemBooted && !haveBootMsg) { |
| 1943 | return true; |
| 1944 | } |
| 1945 | |
| 1946 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 1947 | // we have the application and wallpaper. |
| 1948 | if (mService.mSystemBooted && ((!haveApp && !haveKeyguard) || |
| 1949 | (wallpaperEnabled && !haveWallpaper))) { |
| 1950 | return true; |
| 1951 | } |
| 1952 | |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 1956 | void updateWindowsForAnimator(WindowAnimator animator) { |
| 1957 | final WindowManagerPolicy policy = animator.mPolicy; |
| 1958 | final int keyguardGoingAwayFlags = animator.mKeyguardGoingAwayFlags; |
| 1959 | final boolean keyguardGoingAwayToShade = |
| 1960 | (keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_TO_SHADE) != 0; |
| 1961 | final boolean keyguardGoingAwayNoAnimation = |
| 1962 | (keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS) != 0; |
| 1963 | final boolean keyguardGoingAwayWithWallpaper = |
| 1964 | (keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER) != 0; |
| 1965 | |
| 1966 | if (animator.mKeyguardGoingAway) { |
| 1967 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 1968 | WindowState win = mWindows.get(i); |
| 1969 | if (!policy.isKeyguardHostWindow(win.mAttrs)) { |
| 1970 | continue; |
| 1971 | } |
| 1972 | final WindowStateAnimator winAnimator = win.mWinAnimator; |
| 1973 | if (policy.isKeyguardShowingAndNotOccluded()) { |
| 1974 | if (!winAnimator.mAnimating) { |
| 1975 | if (DEBUG_KEYGUARD) Slog.d(TAG, |
| 1976 | "updateWindowsForAnimator: creating delay animation"); |
| 1977 | |
| 1978 | // Create a new animation to delay until keyguard is gone on its own. |
| 1979 | winAnimator.mAnimation = new AlphaAnimation(1.0f, 1.0f); |
| 1980 | winAnimator.mAnimation.setDuration(KEYGUARD_ANIM_TIMEOUT_MS); |
| 1981 | winAnimator.mAnimationIsEntrance = false; |
| 1982 | winAnimator.mAnimationStartTime = -1; |
| 1983 | winAnimator.mKeyguardGoingAwayAnimation = true; |
| 1984 | winAnimator.mKeyguardGoingAwayWithWallpaper |
| 1985 | = keyguardGoingAwayWithWallpaper; |
| 1986 | } |
| 1987 | } else { |
| 1988 | if (DEBUG_KEYGUARD) Slog.d(TAG, |
| 1989 | "updateWindowsForAnimator: StatusBar is no longer keyguard"); |
| 1990 | animator.mKeyguardGoingAway = false; |
| 1991 | winAnimator.clearAnimation(); |
| 1992 | } |
| 1993 | break; |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | animator.mForceHiding = KEYGUARD_NOT_SHOWN; |
| 1998 | |
| 1999 | boolean wallpaperInUnForceHiding = false; |
| 2000 | boolean startingInUnForceHiding = false; |
| 2001 | ArrayList<WindowStateAnimator> unForceHiding = null; |
| 2002 | WindowState wallpaper = null; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 2003 | final WallpaperController wallpaperController = mWallpaperController; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2004 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 2005 | WindowState win = mWindows.get(i); |
| 2006 | WindowStateAnimator winAnimator = win.mWinAnimator; |
| 2007 | final int flags = win.mAttrs.flags; |
| 2008 | boolean canBeForceHidden = policy.canBeForceHidden(win, win.mAttrs); |
| 2009 | boolean shouldBeForceHidden = animator.shouldForceHide(win); |
| 2010 | if (winAnimator.hasSurface()) { |
| 2011 | final boolean wasAnimating = winAnimator.mWasAnimating; |
| 2012 | final boolean nowAnimating = winAnimator.stepAnimationLocked(animator.mCurrentTime); |
| 2013 | winAnimator.mWasAnimating = nowAnimating; |
| 2014 | animator.orAnimating(nowAnimating); |
| 2015 | |
| 2016 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 2017 | win + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating); |
| 2018 | |
| 2019 | if (wasAnimating && !winAnimator.mAnimating |
| 2020 | && wallpaperController.isWallpaperTarget(win)) { |
| 2021 | animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; |
| 2022 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 2023 | if (DEBUG_LAYOUT_REPEATS) { |
| 2024 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 2025 | "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges); |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | if (policy.isForceHiding(win.mAttrs)) { |
| 2030 | if (!wasAnimating && nowAnimating) { |
| 2031 | if (DEBUG_KEYGUARD || DEBUG_ANIM || DEBUG_VISIBILITY) Slog.v(TAG, |
| 2032 | "Animation started that could impact force hide: " + win); |
| 2033 | animator.mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED; |
| 2034 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 2035 | if (DEBUG_LAYOUT_REPEATS) { |
| 2036 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 2037 | "updateWindowsAndWallpaperLocked 3", pendingLayoutChanges); |
| 2038 | } |
| 2039 | mService.mFocusMayChange = true; |
| 2040 | } else if (animator.mKeyguardGoingAway && !nowAnimating) { |
| 2041 | // Timeout!! |
| 2042 | Slog.e(TAG, "Timeout waiting for animation to startup"); |
| 2043 | policy.startKeyguardExitAnimation(0, 0); |
| 2044 | animator.mKeyguardGoingAway = false; |
| 2045 | } |
| 2046 | if (win.isReadyForDisplay()) { |
| 2047 | if (nowAnimating && win.mWinAnimator.mKeyguardGoingAwayAnimation) { |
| 2048 | animator.mForceHiding = KEYGUARD_ANIMATING_OUT; |
| 2049 | } else { |
| 2050 | animator.mForceHiding = win.isDrawnLw() |
| 2051 | ? KEYGUARD_SHOWN : KEYGUARD_NOT_SHOWN; |
| 2052 | } |
| 2053 | } |
| 2054 | if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG, |
| 2055 | "Force hide " + animator.forceHidingToString() |
| 2056 | + " hasSurface=" + win.mHasSurface |
| 2057 | + " policyVis=" + win.mPolicyVisibility |
| 2058 | + " destroying=" + win.mDestroying |
| 2059 | + " parentHidden=" + win.isParentWindowHidden() |
| 2060 | + " vis=" + win.mViewVisibility |
| 2061 | + " hidden=" + win.mToken.hidden |
| 2062 | + " anim=" + win.mWinAnimator.mAnimation); |
| 2063 | } else if (canBeForceHidden) { |
| 2064 | if (shouldBeForceHidden) { |
| 2065 | if (!win.hideLw(false, false)) { |
| 2066 | // Was already hidden |
| 2067 | continue; |
| 2068 | } |
| 2069 | if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG, |
| 2070 | "Now policy hidden: " + win); |
| 2071 | } else { |
| 2072 | final Animation postKeyguardExitAnimation = |
| 2073 | animator.mPostKeyguardExitAnimation; |
| 2074 | boolean applyExistingExitAnimation = postKeyguardExitAnimation != null |
| 2075 | && !postKeyguardExitAnimation.hasEnded() |
| 2076 | && !winAnimator.mKeyguardGoingAwayAnimation |
| 2077 | && win.hasDrawnLw() |
| 2078 | && !win.isChildWindow() |
| 2079 | && !win.mIsImWindow |
| 2080 | && isDefaultDisplay; |
| 2081 | |
| 2082 | // If the window is already showing and we don't need to apply an existing |
| 2083 | // Keyguard exit animation, skip. |
| 2084 | if (!win.showLw(false, false) && !applyExistingExitAnimation) { |
| 2085 | continue; |
| 2086 | } |
| 2087 | final boolean visibleNow = win.isVisibleNow(); |
| 2088 | if (!visibleNow) { |
| 2089 | // Couldn't really show, must showLw() again when win becomes visible. |
| 2090 | win.hideLw(false, false); |
| 2091 | continue; |
| 2092 | } |
| 2093 | if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG, |
| 2094 | "Now policy shown: " + win); |
| 2095 | if ((animator.mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0 |
| 2096 | && !win.isChildWindow()) { |
| 2097 | if (unForceHiding == null) { |
| 2098 | unForceHiding = new ArrayList<>(); |
| 2099 | } |
| 2100 | unForceHiding.add(winAnimator); |
| 2101 | if ((flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 2102 | wallpaperInUnForceHiding = true; |
| 2103 | } |
| 2104 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2105 | startingInUnForceHiding = true; |
| 2106 | } |
| 2107 | } else if (applyExistingExitAnimation) { |
| 2108 | // We're already in the middle of an animation. Use the existing |
| 2109 | // animation to bring in this window. |
| 2110 | if (DEBUG_KEYGUARD) Slog.v(TAG, |
| 2111 | "Applying existing Keyguard exit animation to new window: win=" |
| 2112 | + win); |
| 2113 | |
| 2114 | final Animation a = policy.createForceHideEnterAnimation(false, |
| 2115 | keyguardGoingAwayToShade); |
| 2116 | winAnimator.setAnimation(a, postKeyguardExitAnimation.getStartTime(), |
| 2117 | STACK_CLIP_BEFORE_ANIM); |
| 2118 | winAnimator.mKeyguardGoingAwayAnimation = true; |
| 2119 | winAnimator.mKeyguardGoingAwayWithWallpaper |
| 2120 | = keyguardGoingAwayWithWallpaper; |
| 2121 | } |
| 2122 | final WindowState currentFocus = mService.mCurrentFocus; |
| 2123 | if (currentFocus == null || currentFocus.mLayer < win.mLayer) { |
| 2124 | // We are showing on top of the current |
| 2125 | // focus, so re-evaluate focus to make |
| 2126 | // sure it is correct. |
| 2127 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, |
| 2128 | "updateWindowsForAnimator: setting mFocusMayChange true"); |
| 2129 | mService.mFocusMayChange = true; |
| 2130 | } |
| 2131 | } |
| 2132 | if ((flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 2133 | animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; |
| 2134 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 2135 | if (DEBUG_LAYOUT_REPEATS) { |
| 2136 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 2137 | "updateWindowsAndWallpaperLocked 4", pendingLayoutChanges); |
| 2138 | } |
| 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | // If the window doesn't have a surface, the only thing we care about is the correct |
| 2144 | // policy visibility. |
| 2145 | else if (canBeForceHidden) { |
| 2146 | if (shouldBeForceHidden) { |
| 2147 | win.hideLw(false, false); |
| 2148 | } else { |
| 2149 | win.showLw(false, false); |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | final AppWindowToken atoken = win.mAppToken; |
| 2154 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
| 2155 | if (atoken == null || atoken.allDrawn) { |
| 2156 | if (win.performShowLocked()) { |
| 2157 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 2158 | if (DEBUG_LAYOUT_REPEATS) { |
| 2159 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 2160 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 2161 | } |
| 2162 | } |
| 2163 | } |
| 2164 | } |
| 2165 | final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; |
| 2166 | if (appAnimator != null && appAnimator.thumbnail != null) { |
| 2167 | if (appAnimator.thumbnailTransactionSeq != animator.mAnimTransactionSequence) { |
| 2168 | appAnimator.thumbnailTransactionSeq = animator.mAnimTransactionSequence; |
| 2169 | appAnimator.thumbnailLayer = 0; |
| 2170 | } |
| 2171 | if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) { |
| 2172 | appAnimator.thumbnailLayer = winAnimator.mAnimLayer; |
| 2173 | } |
| 2174 | } |
| 2175 | if (win.mIsWallpaper) { |
| 2176 | wallpaper = win; |
| 2177 | } |
| 2178 | } // end forall windows |
| 2179 | |
| 2180 | // If we have windows that are being shown due to them no longer being force-hidden, apply |
| 2181 | // the appropriate animation to them if animations are not disabled. |
| 2182 | if (unForceHiding != null) { |
| 2183 | if (!keyguardGoingAwayNoAnimation) { |
| 2184 | boolean first = true; |
| 2185 | for (int i=unForceHiding.size()-1; i>=0; i--) { |
| 2186 | final WindowStateAnimator winAnimator = unForceHiding.get(i); |
| 2187 | final Animation a = policy.createForceHideEnterAnimation( |
| 2188 | wallpaperInUnForceHiding && !startingInUnForceHiding, |
| 2189 | keyguardGoingAwayToShade); |
| 2190 | if (a != null) { |
| 2191 | if (DEBUG_KEYGUARD) Slog.v(TAG, |
| 2192 | "Starting keyguard exit animation on window " + winAnimator.mWin); |
| 2193 | winAnimator.setAnimation(a, STACK_CLIP_BEFORE_ANIM); |
| 2194 | winAnimator.mKeyguardGoingAwayAnimation = true; |
| 2195 | winAnimator.mKeyguardGoingAwayWithWallpaper |
| 2196 | = keyguardGoingAwayWithWallpaper; |
| 2197 | if (first) { |
| 2198 | animator.mPostKeyguardExitAnimation = a; |
| 2199 | animator.mPostKeyguardExitAnimation.setStartTime(animator.mCurrentTime); |
| 2200 | first = false; |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | } else if (animator.mKeyguardGoingAway) { |
| 2205 | policy.startKeyguardExitAnimation(animator.mCurrentTime, 0 /* duration */); |
| 2206 | animator.mKeyguardGoingAway = false; |
| 2207 | } |
| 2208 | |
| 2209 | |
| 2210 | // Wallpaper is going away in un-force-hide motion, animate it as well. |
| 2211 | if (!wallpaperInUnForceHiding && wallpaper != null && !keyguardGoingAwayNoAnimation) { |
| 2212 | if (DEBUG_KEYGUARD) Slog.d(TAG, |
| 2213 | "updateWindowsForAnimator: wallpaper animating away"); |
| 2214 | final Animation a = policy.createForceHideWallpaperExitAnimation( |
| 2215 | keyguardGoingAwayToShade); |
| 2216 | if (a != null) { |
| 2217 | wallpaper.mWinAnimator.setAnimation(a); |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | if (animator.mPostKeyguardExitAnimation != null) { |
| 2223 | // We're in the midst of a keyguard exit animation. |
| 2224 | if (animator.mKeyguardGoingAway) { |
| 2225 | policy.startKeyguardExitAnimation(animator.mCurrentTime + |
| 2226 | animator.mPostKeyguardExitAnimation.getStartOffset(), |
| 2227 | animator.mPostKeyguardExitAnimation.getDuration()); |
| 2228 | animator.mKeyguardGoingAway = false; |
| 2229 | } |
| 2230 | // mPostKeyguardExitAnimation might either be ended normally, cancelled, or "orphaned", |
| 2231 | // meaning that the window it was running on was removed. We check for hasEnded() for |
| 2232 | // ended normally and cancelled case, and check the time for the "orphaned" case. |
| 2233 | else if (animator.mPostKeyguardExitAnimation.hasEnded() |
| 2234 | || animator.mCurrentTime - animator.mPostKeyguardExitAnimation.getStartTime() |
| 2235 | > animator.mPostKeyguardExitAnimation.getDuration()) { |
| 2236 | // Done with the animation, reset. |
| 2237 | if (DEBUG_KEYGUARD) Slog.v(TAG, "Done with Keyguard exit animations."); |
| 2238 | animator.mPostKeyguardExitAnimation = null; |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | final WindowState winShowWhenLocked = (WindowState) policy.getWinShowWhenLockedLw(); |
| 2243 | if (winShowWhenLocked != null) { |
| 2244 | animator.mLastShowWinWhenLocked = winShowWhenLocked; |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | void updateWallpaperForAnimator(WindowAnimator animator) { |
Jorim Jaggi | 7156b65 | 2016-10-25 08:31:58 -0700 | [diff] [blame] | 2249 | resetAnimationBackgroundAnimator(); |
| 2250 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2251 | final WindowList windows = mWindows; |
| 2252 | WindowState detachedWallpaper = null; |
| 2253 | |
| 2254 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 2255 | final WindowState win = windows.get(i); |
| 2256 | final WindowStateAnimator winAnimator = win.mWinAnimator; |
| 2257 | if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) { |
| 2258 | continue; |
| 2259 | } |
| 2260 | |
| 2261 | final int flags = win.mAttrs.flags; |
| 2262 | |
| 2263 | // If this window is animating, make a note that we have an animating window and take |
| 2264 | // care of a request to run a detached wallpaper animation. |
| 2265 | if (winAnimator.mAnimating) { |
| 2266 | if (winAnimator.mAnimation != null) { |
| 2267 | if ((flags & FLAG_SHOW_WALLPAPER) != 0 |
| 2268 | && winAnimator.mAnimation.getDetachWallpaper()) { |
| 2269 | detachedWallpaper = win; |
| 2270 | } |
| 2271 | final int color = winAnimator.mAnimation.getBackgroundColor(); |
| 2272 | if (color != 0) { |
| 2273 | final TaskStack stack = win.getStack(); |
| 2274 | if (stack != null) { |
| 2275 | stack.setAnimationBackground(winAnimator, color); |
| 2276 | } |
| 2277 | } |
| 2278 | } |
| 2279 | animator.setAnimating(true); |
| 2280 | } |
| 2281 | |
| 2282 | // If this window's app token is running a detached wallpaper animation, make a note so |
| 2283 | // we can ensure the wallpaper is displayed behind it. |
| 2284 | final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; |
| 2285 | if (appAnimator != null && appAnimator.animation != null |
| 2286 | && appAnimator.animating) { |
| 2287 | if ((flags & FLAG_SHOW_WALLPAPER) != 0 |
| 2288 | && appAnimator.animation.getDetachWallpaper()) { |
| 2289 | detachedWallpaper = win; |
| 2290 | } |
| 2291 | |
| 2292 | final int color = appAnimator.animation.getBackgroundColor(); |
| 2293 | if (color != 0) { |
| 2294 | final TaskStack stack = win.getStack(); |
| 2295 | if (stack != null) { |
| 2296 | stack.setAnimationBackground(winAnimator, color); |
| 2297 | } |
| 2298 | } |
| 2299 | } |
| 2300 | } // end forall windows |
| 2301 | |
| 2302 | if (animator.mWindowDetachedWallpaper != detachedWallpaper) { |
| 2303 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from " |
| 2304 | + animator.mWindowDetachedWallpaper + " to " + detachedWallpaper); |
| 2305 | animator.mWindowDetachedWallpaper = detachedWallpaper; |
| 2306 | animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | void prepareWindowSurfaces() { |
| 2311 | final int count = mWindows.size(); |
| 2312 | for (int j = 0; j < count; j++) { |
| 2313 | mWindows.get(j).mWinAnimator.prepareSurfaceLocked(true); |
| 2314 | } |
| 2315 | } |
| 2316 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2317 | boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 2318 | // The focus for the client is the window immediately below where we would place the input |
| 2319 | // method window. |
| 2320 | int idx = findDesiredInputMethodWindowIndex(false); |
| 2321 | if (idx <= 0) { |
| 2322 | return false; |
| 2323 | } |
| 2324 | |
| 2325 | WindowState imFocus = mWindows.get(idx - 1); |
| 2326 | if (DEBUG_INPUT_METHOD) { |
| 2327 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
| 2328 | Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus); |
| 2329 | Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus); |
| 2330 | } |
| 2331 | |
| 2332 | if (imFocus == null) { |
| 2333 | return false; |
| 2334 | } |
| 2335 | |
| 2336 | // This may be a starting window, in which case we still want to count it as okay. |
| 2337 | if (imFocus.mAttrs.type == TYPE_APPLICATION_STARTING && imFocus.mAppToken != null) { |
| 2338 | // The client has definitely started, so it really should have a window in this app |
| 2339 | // token. Let's look for it. |
| 2340 | final WindowState w = imFocus.mAppToken.getFirstNonStartingWindow(); |
| 2341 | if (w != null) { |
| 2342 | if (DEBUG_INPUT_METHOD) Slog.i(TAG_WM, "Switching to real app window: " + w); |
| 2343 | imFocus = w; |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | final IInputMethodClient imeClient = imFocus.mSession.mClient; |
| 2348 | |
| 2349 | if (DEBUG_INPUT_METHOD) { |
| 2350 | Slog.i(TAG_WM, "IM target client: " + imeClient); |
| 2351 | if (imeClient != null) { |
| 2352 | Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder()); |
| 2353 | Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder()); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | return imeClient != null && imeClient.asBinder() == client.asBinder(); |
| 2358 | } |
| 2359 | |
| 2360 | boolean hasSecureWindowOnScreen() { |
| 2361 | for (int i = mWindows.size() - 1; i >= 0; --i) { |
| 2362 | final WindowState ws = mWindows.get(i); |
| 2363 | if (ws.isOnScreen() && (ws.mAttrs.flags & FLAG_SECURE) != 0) { |
| 2364 | return true; |
| 2365 | } |
| 2366 | } |
| 2367 | return false; |
| 2368 | } |
| 2369 | |
| 2370 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
| 2371 | for (int i = mWindows.size() - 1; i >= 0; --i) { |
| 2372 | final WindowState ws = mWindows.get(i); |
| 2373 | try { |
| 2374 | int curValue = ws.mSystemUiVisibility; |
| 2375 | int diff = (curValue ^ visibility) & globalDiff; |
| 2376 | int newValue = (curValue & ~diff) | (visibility & diff); |
| 2377 | if (newValue != curValue) { |
| 2378 | ws.mSeq++; |
| 2379 | ws.mSystemUiVisibility = newValue; |
| 2380 | } |
| 2381 | if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) { |
| 2382 | ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq, |
| 2383 | visibility, newValue, diff); |
| 2384 | } |
| 2385 | } catch (RemoteException e) { |
| 2386 | // so sorry |
| 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | void onWindowFreezeTimeout() { |
| 2392 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
| 2393 | mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
| 2394 | for (int i = mWindows.size() - 1; i >= 0; --i) { |
| 2395 | final WindowState w = mWindows.get(i); |
| 2396 | if (!w.mOrientationChanging) { |
| 2397 | continue; |
| 2398 | } |
| 2399 | w.mOrientationChanging = false; |
| 2400 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 2401 | - mService.mDisplayFreezeTime); |
| 2402 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
| 2403 | } |
| 2404 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 2405 | } |
| 2406 | |
| 2407 | void waitForAllWindowsDrawn() { |
| 2408 | final WindowManagerPolicy policy = mService.mPolicy; |
| 2409 | for (int winNdx = mWindows.size() - 1; winNdx >= 0; --winNdx) { |
| 2410 | final WindowState win = mWindows.get(winNdx); |
| 2411 | final boolean isForceHiding = policy.isForceHiding(win.mAttrs); |
| 2412 | final boolean keyguard = policy.isKeyguardHostWindow(win.mAttrs); |
| 2413 | if (win.isVisibleLw() && (win.mAppToken != null || isForceHiding || keyguard)) { |
| 2414 | win.mWinAnimator.mDrawState = DRAW_PENDING; |
| 2415 | // Force add to mResizingWindows. |
| 2416 | win.mLastContentInsets.set(-1, -1, -1, -1); |
| 2417 | mService.mWaitingForDrawn.add(win); |
| 2418 | |
| 2419 | // No need to wait for the windows below Keyguard. |
| 2420 | if (isForceHiding) { |
| 2421 | return; |
| 2422 | } |
| 2423 | } |
| 2424 | } |
| 2425 | } |
| 2426 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2427 | static final class GetWindowOnDisplaySearchResult { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 2428 | boolean reachedToken; |
| 2429 | WindowState foundWindow; |
| 2430 | |
| 2431 | void reset() { |
| 2432 | reachedToken = false; |
| 2433 | foundWindow = null; |
| 2434 | } |
| 2435 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 2436 | |
| 2437 | static final class TaskForResizePointSearchResult { |
| 2438 | boolean searchDone; |
| 2439 | Task taskForResize; |
| 2440 | |
| 2441 | void reset() { |
| 2442 | searchDone = false; |
| 2443 | taskForResize = null; |
| 2444 | } |
| 2445 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2446 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2447 | /** |
| 2448 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 2449 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 2450 | * homogeneous children type which is currently required by sub-classes of |
| 2451 | * {@link WindowContainer} class. |
| 2452 | */ |
| 2453 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 2454 | |
| 2455 | int size() { |
| 2456 | return mChildren.size(); |
| 2457 | } |
| 2458 | |
| 2459 | E get(int index) { |
| 2460 | return mChildren.get(index); |
| 2461 | } |
| 2462 | |
| 2463 | @Override |
| 2464 | boolean fillsParent() { |
| 2465 | return true; |
| 2466 | } |
| 2467 | |
| 2468 | @Override |
| 2469 | boolean isVisible() { |
| 2470 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2474 | /** |
| 2475 | * Window container class that contains all containers on this display relating to Apps. |
| 2476 | * I.e Activities. |
| 2477 | */ |
| 2478 | private class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> { |
| 2479 | |
| 2480 | void attachStack(TaskStack stack, boolean onTop) { |
| 2481 | if (stack.mStackId == HOME_STACK_ID) { |
| 2482 | if (mHomeStack != null) { |
| 2483 | throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first."); |
| 2484 | } |
| 2485 | mHomeStack = stack; |
| 2486 | } |
| 2487 | addChild(stack, onTop); |
| 2488 | stack.onDisplayChanged(DisplayContent.this); |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2489 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2490 | |
| 2491 | void moveStack(TaskStack stack, boolean toTop) { |
| 2492 | if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) { |
| 2493 | // This stack is always-on-top silly... |
| 2494 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom"); |
| 2495 | return; |
| 2496 | } |
| 2497 | |
| 2498 | if (!mChildren.contains(stack)) { |
| 2499 | Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable()); |
| 2500 | } |
| 2501 | removeChild(stack); |
| 2502 | addChild(stack, toTop); |
| 2503 | } |
| 2504 | |
| 2505 | private void addChild(TaskStack stack, boolean toTop) { |
| 2506 | int addIndex = toTop ? mChildren.size() : 0; |
| 2507 | |
| 2508 | if (toTop |
| 2509 | && mService.isStackVisibleLocked(PINNED_STACK_ID) |
| 2510 | && stack.mStackId != PINNED_STACK_ID) { |
| 2511 | // The pinned stack is always the top most stack (always-on-top) when it is visible. |
| 2512 | // So, stack is moved just below the pinned stack. |
| 2513 | addIndex--; |
| 2514 | TaskStack topStack = mChildren.get(addIndex); |
| 2515 | if (topStack.mStackId != PINNED_STACK_ID) { |
| 2516 | throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren); |
| 2517 | } |
| 2518 | } |
| 2519 | addChild(stack, addIndex); |
| 2520 | setLayoutNeeded(); |
| 2521 | } |
| 2522 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 2523 | @Override |
| 2524 | int getOrientation() { |
| 2525 | if (mService.isStackVisibleLocked(DOCKED_STACK_ID) |
| 2526 | || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) { |
| 2527 | // Apps and their containers are not allowed to specify an orientation while the |
| 2528 | // docked or freeform stack is visible...except for the home stack/task if the |
| 2529 | // docked stack is minimized and it actually set something. |
| 2530 | if (mHomeStack != null && mHomeStack.isVisible() |
| 2531 | && mDividerControllerLocked.isMinimizedDock()) { |
| 2532 | final int orientation = mHomeStack.getOrientation(); |
| 2533 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 2534 | return orientation; |
| 2535 | } |
| 2536 | } |
| 2537 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 2538 | } |
| 2539 | |
| 2540 | final int orientation = super.getOrientation(); |
| 2541 | if (orientation != SCREEN_ORIENTATION_UNSET |
| 2542 | && orientation != SCREEN_ORIENTATION_BEHIND) { |
| 2543 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 2544 | "App is requesting an orientation, return " + orientation); |
| 2545 | return orientation; |
| 2546 | } |
| 2547 | |
| 2548 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 2549 | "No app is requesting an orientation, return " + mService.mLastOrientation); |
| 2550 | // The next app has not been requested to be visible, so we keep the current orientation |
| 2551 | // to prevent freezing/unfreezing the display too early. |
| 2552 | return mService.mLastOrientation; |
| 2553 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | /** |
| 2557 | * Window container class that contains all containers on this display that are not related to |
| 2558 | * Apps. E.g. status bar. |
| 2559 | */ |
| 2560 | private static class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
| 2561 | |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 2562 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2563 | } |